Skip to content

Commit eed7685

Browse files
committed
back to things sorta
1 parent 6adea0b commit eed7685

File tree

11 files changed

+348
-131
lines changed

11 files changed

+348
-131
lines changed

‎src/main/java/simplexity/villagerinfo/commands/villagerinfo/subcommands/toggle/subcommands/HighlightToggle.java‎

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,35 @@
11
package simplexity.villagerinfo.commands.villagerinfo.subcommands.toggle.subcommands;
22

3+
import org.bukkit.NamespacedKey;
34
import org.bukkit.command.CommandSender;
45
import simplexity.villagerinfo.commands.util.SubCommand;
56
import simplexity.villagerinfo.configurations.locale.ServerMessage;
7+
import simplexity.villagerinfo.interaction.logic.PlayerToggle;
68
import simplexity.villagerinfo.util.Perm;
9+
import simplexity.villagerinfo.util.Resolvers;
710

811
import java.util.List;
912

1013
public class HighlightToggle extends SubCommand {
1114
public HighlightToggle() {
1215
super(Perm.VILL_COMMAND_TOGGLE_HIGHLIGHT.getPerm(), ServerMessage.HELP_TOGGLE_HIGHLIGHT.getMessage());
1316
}
14-
17+
public static final NamespacedKey highlightEnabledKey = new NamespacedKey("vill-info", "vill-highlight-enabled");
1518

1619
@Override
1720
public void execute(CommandSender sender, String[] args) {
18-
/*if (!(sender instanceof org.bukkit.entity.Player player)) {
21+
if (!(sender instanceof org.bukkit.entity.Player player)) {
1922
sender.sendMessage(Resolvers.getInstance().prefixResolver(ServerMessage.NOT_A_PLAYER.getMessage()));
2023
return;
2124
}
22-
PlayerToggleEvent toggleHighlightEvent = callHighlightToggleEvent(player);
23-
if (toggleHighlightEvent == null) return;
24-
byte toggleState = toggleHighlightEvent.getCurrentToggleState();
25-
if (toggleState == (byte) 0) {
26-
toggleHighlightEvent.setDisabled();
27-
return;
28-
}
29-
if (toggleState == (byte) 1) {
30-
toggleHighlightEvent.setEnabled();
25+
boolean isToggleEnabled = PlayerToggle.isPdcToggleEnabled(player, highlightEnabledKey);
26+
if (isToggleEnabled) {
27+
PlayerToggle.setPdcToggleDisabled(player, highlightEnabledKey);
28+
} else {
29+
PlayerToggle.setPdcToggleEnabled(player, highlightEnabledKey);
3130
}
3231
}
3332

34-
public PlayerToggleEvent callHighlightToggleEvent(org.bukkit.entity.Player player) {
35-
PlayerToggleEvent toggleHighlightEvent = new PlayerToggleEvent(player, PDCTag.PLAYER_TOGGLE_HIGHLIGHT_ENABLED.getPdcTag(), MessageInsert.TOGGLE_TYPE_HIGHLIGHT.getMessage());
36-
Bukkit.getServer().getPluginManager().callEvent(toggleHighlightEvent);
37-
if (toggleHighlightEvent.isCancelled()) return null;
38-
return toggleHighlightEvent;
39-
}
40-
41-
*/
42-
}
4333

4434
@Override
4535
public List<String> subCommandTabCompletions(CommandSender sender) {

‎src/main/java/simplexity/villagerinfo/commands/villagerinfo/subcommands/toggle/subcommands/OutputToggle.java‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package simplexity.villagerinfo.commands.villagerinfo.subcommands.toggle.subcommands;
22

3+
import org.bukkit.NamespacedKey;
34
import org.bukkit.command.CommandSender;
5+
import org.bukkit.entity.Player;
46
import simplexity.villagerinfo.commands.util.SubCommand;
57
import simplexity.villagerinfo.configurations.locale.ServerMessage;
8+
import simplexity.villagerinfo.interaction.logic.PlayerToggle;
69
import simplexity.villagerinfo.util.Perm;
10+
import simplexity.villagerinfo.util.Resolvers;
711

812
import java.util.List;
913

@@ -13,32 +17,22 @@ public OutputToggle() {
1317
}
1418

1519

20+
public static NamespacedKey outputEnabledKey = new NamespacedKey("vill-info", "vill-info-enabled");
21+
1622
@Override
1723
public void execute(CommandSender sender, String[] args) {
18-
/*if (!(sender instanceof org.bukkit.entity.Player player)) {
24+
if (!(sender instanceof Player player)) {
1925
sender.sendMessage(Resolvers.getInstance().prefixResolver(ServerMessage.NOT_A_PLAYER.getMessage()));
2026
return;
2127
}
22-
PlayerToggleEvent toggleOutputEvent = callOutputToggleEvent(player);
23-
if (toggleOutputEvent == null) return;
24-
byte toggleState = toggleOutputEvent.getCurrentToggleState();
25-
if (toggleState == (byte) 0) {
26-
toggleOutputEvent.setDisabled();
27-
return;
28-
}
29-
if (toggleState == (byte) 1) {
30-
toggleOutputEvent.setEnabled();
28+
boolean isToggleEnabled = PlayerToggle.isPdcToggleEnabled(player, outputEnabledKey);
29+
if (isToggleEnabled) {
30+
PlayerToggle.setPdcToggleDisabled(player, outputEnabledKey);
31+
} else {
32+
PlayerToggle.setPdcToggleEnabled(player, outputEnabledKey);
3133
}
3234
}
3335

34-
public PlayerToggleEvent callOutputToggleEvent(org.bukkit.entity.Player player) {
35-
PlayerToggleEvent toggleOutputEvent = new PlayerToggleEvent(player, PDCTag.PLAYER_TOGGLE_OUTPUT_ENABLED.getPdcTag(), MessageInsert.TOGGLE_TYPE_OUTPUT.getMessage());
36-
Bukkit.getServer().getPluginManager().callEvent(toggleOutputEvent);
37-
if (toggleOutputEvent.isCancelled()) return null;
38-
return toggleOutputEvent;
39-
}
40-
*/
41-
}
4236

4337
@Override
4438
public List<String> subCommandTabCompletions(CommandSender sender) {

‎src/main/java/simplexity/villagerinfo/commands/villagerinfo/subcommands/toggle/subcommands/SoundToggle.java‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package simplexity.villagerinfo.commands.villagerinfo.subcommands.toggle.subcommands;
22

3+
import org.bukkit.NamespacedKey;
34
import org.bukkit.command.CommandSender;
5+
import org.bukkit.entity.Player;
46
import simplexity.villagerinfo.commands.util.SubCommand;
57
import simplexity.villagerinfo.configurations.locale.ServerMessage;
8+
import simplexity.villagerinfo.interaction.logic.PlayerToggle;
69
import simplexity.villagerinfo.util.Perm;
10+
import simplexity.villagerinfo.util.Resolvers;
711

812
import java.util.List;
913

@@ -12,31 +16,22 @@ public SoundToggle() {
1216
super(Perm.VILL_COMMAND_TOGGLE_SOUND.getPerm(), ServerMessage.HELP_TOGGLE_SOUND.getMessage());
1317
}
1418

19+
public static NamespacedKey soundEnabledKey = new NamespacedKey("vill-info", "vill-output-sound-enabled");
20+
1521
@Override
16-
public void execute(CommandSender sender, String[] args) {}
17-
/*
18-
if (!(sender instanceof org.bukkit.entity.Player player)) {
22+
public void execute(CommandSender sender, String[] args) {
23+
if (!(sender instanceof Player player)) {
1924
sender.sendMessage(Resolvers.getInstance().prefixResolver(ServerMessage.NOT_A_PLAYER.getMessage()));
2025
return;
2126
}
22-
PlayerToggleEvent toggleSoundEvent = callToggleSoundEvent(player);
23-
if (toggleSoundEvent == null) return;
24-
byte toggleState = toggleSoundEvent.getCurrentToggleState();
25-
if (toggleState == (byte) 0) {
26-
toggleSoundEvent.setDisabled();
27-
return;
28-
}
29-
if (toggleState == (byte) 1) {
30-
toggleSoundEvent.setEnabled();
27+
boolean isToggleEnabled = PlayerToggle.isPdcToggleEnabled(player, soundEnabledKey);
28+
if (isToggleEnabled) {
29+
PlayerToggle.setPdcToggleDisabled(player, soundEnabledKey);
30+
} else {
31+
PlayerToggle.setPdcToggleEnabled(player, soundEnabledKey);
3132
}
3233
}
3334

34-
public PlayerToggleEvent callToggleSoundEvent(org.bukkit.entity.Player player) {
35-
PlayerToggleEvent toggleSoundEvent = new PlayerToggleEvent(player, PDCTag.PLAYER_TOGGLE_SOUND_ENABLED.getPdcTag(), MessageInsert.TOGGLE_TYPE_SOUND.getMessage());
36-
Bukkit.getServer().getPluginManager().callEvent(toggleSoundEvent);
37-
if (toggleSoundEvent.isCancelled()) return null;
38-
return toggleSoundEvent;
39-
}*/
4035

4136
@Override
4237
public List<String> subCommandTabCompletions(CommandSender sender) {

‎src/main/java/simplexity/villagerinfo/events/SoundEffectEvent.java‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package simplexity.villagerinfo.events;
22

3+
import org.bukkit.Location;
34
import org.bukkit.Sound;
45
import org.bukkit.entity.Player;
56
import org.bukkit.event.Cancellable;
@@ -18,8 +19,9 @@ public class SoundEffectEvent extends Event implements Cancellable {
1819
private Player player;
1920
private float volume;
2021
private float pitch;
22+
private Location location;
2123

22-
public SoundEffectEvent(Player player, Sound sound, float volume, float pitch) {
24+
public SoundEffectEvent(Player player, Sound sound, float volume, float pitch, Location location) {
2325
this.sound = sound;
2426
this.player = player;
2527
this.volume = volume;
@@ -101,6 +103,25 @@ public void setPlayer(Player player) {
101103
this.player = player;
102104
}
103105

106+
/**
107+
* Get the location this sound will be played at.
108+
*
109+
* @return Location the sound will be played at
110+
*/
111+
public Location getLocation() {
112+
return location;
113+
}
114+
115+
116+
/**
117+
* Set the location for this sound to be played at
118+
*
119+
* @param location Location the sound will be played at
120+
*/
121+
public void setLocation(Location location) {
122+
this.location = location;
123+
}
124+
104125
/**
105126
* Gets whether the event has been cancelled
106127
*

‎src/main/java/simplexity/villagerinfo/interaction/listeners/PlayerInteractEntityListener.java‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@ public void onVillagerInteract(PlayerInteractEntityEvent interactEntityEvent) {
2727
Player player = interactEntityEvent.getPlayer();
2828
if (!passPlayerChecks(player)) return;
2929
interactEntityEvent.setCancelled(true);
30-
if (entity instanceof Villager villager) OutputManager.VillagerOutput(player, player, villager);
31-
if (entity instanceof ZombieVillager zombieVillager) OutputManager.zombieVillagerOutput(player, zombieVillager);
30+
if (entity instanceof Villager villager) OutputManager.handleVillagerOutput(player, player, villager);
31+
if (entity instanceof ZombieVillager zombieVillager) OutputManager.handleZombieVillagerOutput(player, zombieVillager);
3232
}
3333

3434
private boolean passPlayerChecks(Player player) {
3535
Material material = player.getEquipment().getItemInMainHand().getType();
3636
if (!player.isSneaking()) return false;
3737
if (!VillConfig.getInstance().isValidItem(material)) return false;
38-
if (!player.hasPermission(Perm.VILL_INFO_OUTPUT.getPerm())) return false;
39-
//todo get player's currently toggled settings
40-
return true;
38+
return player.hasPermission(Perm.VILL_INFO_OUTPUT.getPerm());
4139
}
4240

4341
private boolean passEntityChecks(Entity entity) {

0 commit comments

Comments
 (0)