diff --git a/src/main/java/adhdmc/villagerinfo/Commands/CommandHandler.java b/src/main/java/adhdmc/villagerinfo/Commands/CommandHandler.java index 972d051..a5d8c22 100644 --- a/src/main/java/adhdmc/villagerinfo/Commands/CommandHandler.java +++ b/src/main/java/adhdmc/villagerinfo/Commands/CommandHandler.java @@ -13,14 +13,14 @@ public class CommandHandler implements CommandExecutor, TabExecutor { - public static HashMap subcommandList = new HashMap(); + public static HashMap subcommandList = new HashMap<>(); Map msgs = ConfigValidator.getLocaleMap(); MiniMessage mM = MiniMessage.miniMessage(); //TY Peashooter101 @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { - ArrayList subCommands1 = new ArrayList(Arrays.asList("help", "toggle", "reload")); + ArrayList subCommands1 = new ArrayList<>(Arrays.asList("help", "toggle", "reload")); if (args.length == 1) { return subCommands1; } @@ -32,13 +32,26 @@ public List onTabComplete(CommandSender sender, Command command, String public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { //Checking for arguments if (args.length == 0) { - sender.sendMessage(mM.deserialize("Click here to visit the GitHub!'>VillagerInfo | Version: \nAuthors: Rhythmic | Peashooter101", Placeholder.parsed("version", String.valueOf(VillagerInfo.version)))); + String url = VillagerInfo.plugin.getDescription().getWebsite(); + String version = VillagerInfo.plugin.getDescription().getVersion(); + List authors = new ArrayList<>(); + for (String authorName : VillagerInfo.plugin.getDescription().getAuthors()) { + authors.add(String.format(" %s ", authorName)); + } + String authorsString = String.join(" | ", authors); + sender.sendMessage(mM.deserialize( + "'>Click here to visit the GitHub!'>VillagerInfo | Version: \nAuthors: ", + Placeholder.parsed("version", version), + Placeholder.parsed("authors", authorsString), + Placeholder.unparsed("url", url) + ) + ); return true; } //if has an argument, check to see if it's contained in the list of arguments String command = args[0].toLowerCase(); if (subcommandList.containsKey(command)) { - subcommandList.get(command).doThing(sender, Arrays.copyOfRange(args, 1, args.length)); + subcommandList.get(command).execute(sender, Arrays.copyOfRange(args, 1, args.length)); } else { sender.sendMessage(mM.deserialize(msgs.get(ConfigValidator.Message.NO_COMMAND))); } diff --git a/src/main/java/adhdmc/villagerinfo/Commands/SubCommand.java b/src/main/java/adhdmc/villagerinfo/Commands/SubCommand.java index 4b26708..327d37b 100644 --- a/src/main/java/adhdmc/villagerinfo/Commands/SubCommand.java +++ b/src/main/java/adhdmc/villagerinfo/Commands/SubCommand.java @@ -6,9 +6,9 @@ public abstract class SubCommand { - private String name; - private String description; - private String syntax; + private final String name; + private final String description; + private final String syntax; public SubCommand(String name, String description, String syntax) { this.name = name; @@ -28,7 +28,7 @@ public String getSyntax() { return syntax; } - public abstract void doThing(CommandSender sender, String[] args); + public abstract void execute(CommandSender sender, String[] args); public abstract List getSubcommandArguments(CommandSender sender, String[] args); diff --git a/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/HelpCommand.java b/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/HelpCommand.java index c7f6250..49e886c 100644 --- a/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/HelpCommand.java +++ b/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/HelpCommand.java @@ -17,7 +17,7 @@ public HelpCommand() { } @Override - public void doThing(CommandSender sender, String[] args) { + public void execute(CommandSender sender, String[] args) { Map msgs = ConfigValidator.getLocaleMap(); MiniMessage mM = MiniMessage.miniMessage(); diff --git a/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/ReloadCommand.java b/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/ReloadCommand.java index 8a6ca0c..9fb6033 100644 --- a/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/ReloadCommand.java +++ b/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/ReloadCommand.java @@ -19,7 +19,7 @@ public ReloadCommand() { @Override - public void doThing(CommandSender sender, String[] args) { + public void execute(CommandSender sender, String[] args) { Map msgs = ConfigValidator.getLocaleMap(); MiniMessage mM = MiniMessage.miniMessage(); if (!(sender instanceof Player) || sender.hasPermission(VillagerInfo.reloadCommandPermission)) { diff --git a/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/ToggleCommand.java b/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/ToggleCommand.java index 760ba3c..a5a05ab 100644 --- a/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/ToggleCommand.java +++ b/src/main/java/adhdmc/villagerinfo/Commands/SubCommands/ToggleCommand.java @@ -5,7 +5,6 @@ import adhdmc.villagerinfo.Config.ConfigValidator.Message; import adhdmc.villagerinfo.VillagerInfo; import net.kyori.adventure.text.minimessage.MiniMessage; -import org.bukkit.NamespacedKey; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.persistence.PersistentDataContainer; @@ -15,17 +14,14 @@ import java.util.Map; public class ToggleCommand extends SubCommand { - NamespacedKey infoToggle = new NamespacedKey(VillagerInfo.plugin, "infoToggle"); Map msgs = ConfigValidator.getLocaleMap(); - String infoOn = VillagerInfo.toggleInfoOn; - String infoOff = VillagerInfo.toggleInfoOff; public ToggleCommand() { super("toggle", "Toggles villager info on and off", "/vill toggle"); } @Override - public void doThing(CommandSender sender, String[] args) { + public void execute(CommandSender sender, String[] args) { MiniMessage mM = MiniMessage.miniMessage(); if (!(sender instanceof Player)) { sender.sendMessage(mM.deserialize(msgs.get(Message.NOT_A_PLAYER))); @@ -44,14 +40,14 @@ public void doThing(CommandSender sender, String[] args) { .append(mM.deserialize(msgs.get(Message.TOGGLE_OFF)))); } - private boolean toggleSetting(Player p) { - PersistentDataContainer playerPDC = p.getPersistentDataContainer(); - String togglePDC = playerPDC.get(infoToggle, PersistentDataType.STRING); - if (togglePDC == null || togglePDC.equals(infoOn)) { - playerPDC.set(infoToggle, PersistentDataType.STRING, infoOff); + private boolean toggleSetting(Player player) { + PersistentDataContainer playerPDC = player.getPersistentDataContainer(); + byte togglePDC = playerPDC.getOrDefault(VillagerInfo.getInfoEnabledKey(), PersistentDataType.BYTE, (byte)0); + if (togglePDC == 1) { + playerPDC.set(VillagerInfo.getInfoEnabledKey(), PersistentDataType.BYTE, (byte)0); return false; } - playerPDC.set(infoToggle, PersistentDataType.STRING, infoOn); + playerPDC.set(VillagerInfo.getInfoEnabledKey(), PersistentDataType.BYTE, (byte)1); return true; } diff --git a/src/main/java/adhdmc/villagerinfo/VillagerHandling/HighlightHandling.java b/src/main/java/adhdmc/villagerinfo/VillagerHandling/HighlightHandling.java index 8b3299a..e487dab 100644 --- a/src/main/java/adhdmc/villagerinfo/VillagerHandling/HighlightHandling.java +++ b/src/main/java/adhdmc/villagerinfo/VillagerHandling/HighlightHandling.java @@ -2,46 +2,40 @@ import adhdmc.villagerinfo.Config.ConfigValidator; import adhdmc.villagerinfo.VillagerInfo; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.NamespacedKey; import org.bukkit.entity.Shulker; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import org.bukkit.scheduler.BukkitRunnable; import java.util.HashMap; import java.util.UUID; import static org.bukkit.entity.EntityType.SHULKER; -public class HighlightHandling{ - static NamespacedKey highlightStatus = new NamespacedKey(VillagerInfo.plugin, "highlightStatus"); - static String currentlyHighlighted = VillagerInfo.isCurrentlyHighlighted; - static String notHighlighted = VillagerInfo.isNotCurrentlyHighlighted; +public class HighlightHandling { + static NamespacedKey highlightStatus = new NamespacedKey(VillagerInfo.plugin, "highlighted"); public static HashMap workstationShulker = new HashMap<>(); public static HashMap villagerPDC = new HashMap<>(); - public static void villagerJobsiteHighlight(PersistentDataContainer villPDC, UUID villUUID, Location villPOI) { - if (villPDC.getOrDefault(highlightStatus, PersistentDataType.STRING, notHighlighted).equals(currentlyHighlighted)) return; - villPDC.set(highlightStatus, PersistentDataType.STRING, currentlyHighlighted); + if (villPDC.getOrDefault(highlightStatus, PersistentDataType.BYTE, (byte)0) == 1) return; + villPDC.set(highlightStatus, PersistentDataType.BYTE, (byte)1); + villagerPDC.put(villUUID, villPDC); + spawnShulker(villUUID, villPOI); + Bukkit.getScheduler().runTaskLater(VillagerInfo.plugin, () -> { + killShulker(villUUID); + villPDC.set(highlightStatus, PersistentDataType.BYTE, (byte)0); villagerPDC.put(villUUID, villPDC); - spawnShulker(villUUID, villPOI); - new BukkitRunnable() { - @Override - public void run() { - killShulker(villUUID); - villPDC.set(highlightStatus, PersistentDataType.STRING, notHighlighted); - villagerPDC.put(villUUID, villPDC); - } - }.runTaskLater(VillagerInfo.plugin, 20L * ConfigValidator.configTime); + }, 20L * ConfigValidator.configTime); } private static void spawnShulker(UUID villUUID, Location location) { - Shulker spawnedShulker = (Shulker) location.getWorld().spawnEntity(location, SHULKER, CreatureSpawnEvent.SpawnReason.CUSTOM, (Entity) -> { - Shulker highlightbox = (Shulker) Entity; + Shulker spawnedShulker = (Shulker) location.getWorld().spawnEntity(location, SHULKER, CreatureSpawnEvent.SpawnReason.CUSTOM, (entity) -> { + Shulker highlightbox = (Shulker) entity; highlightbox.setAI(false); highlightbox.setAware(false); highlightbox.setCollidable(false); diff --git a/src/main/java/adhdmc/villagerinfo/VillagerHandling/VillagerHandler.java b/src/main/java/adhdmc/villagerinfo/VillagerHandling/VillagerHandler.java index 55ba083..25caa10 100644 --- a/src/main/java/adhdmc/villagerinfo/VillagerHandling/VillagerHandler.java +++ b/src/main/java/adhdmc/villagerinfo/VillagerHandling/VillagerHandler.java @@ -9,7 +9,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Location; -import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.entity.Villager; import org.bukkit.entity.memory.MemoryKey; @@ -30,14 +29,10 @@ public class VillagerHandler implements Listener { MiniMessage mM = MiniMessage.miniMessage(); Map messages = ConfigValidator.getLocaleMap(); Map toggleSettings = ConfigValidator.getToggleSettings(); - NamespacedKey infoToggle = new NamespacedKey(VillagerInfo.plugin, "infoToggle"); - String toggleOff = VillagerInfo.toggleInfoOff; - @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) public void onVillagerClick(PlayerInteractEntityEvent event) { Player player = event.getPlayer(); - PersistentDataContainer playerPDC = player.getPersistentDataContainer(); if (event.getHand().equals(EquipmentSlot.OFF_HAND)) { return; } @@ -47,8 +42,9 @@ public void onVillagerClick(PlayerInteractEntityEvent event) { if (!(event.getRightClicked() instanceof Villager villager)) { return; } - String togglePDC = playerPDC.get(infoToggle, PersistentDataType.STRING); - if (togglePDC != null && togglePDC.equals(toggleOff)) { + PersistentDataContainer playerPDC = player.getPersistentDataContainer(); + byte togglePDC = playerPDC.getOrDefault(VillagerInfo.getInfoEnabledKey(), PersistentDataType.BYTE, (byte)0); + if (togglePDC == 0) { return; } if (!player.hasPermission("villagerinfo.use")) { diff --git a/src/main/java/adhdmc/villagerinfo/VillagerInfo.java b/src/main/java/adhdmc/villagerinfo/VillagerInfo.java index 73873dc..1a52238 100644 --- a/src/main/java/adhdmc/villagerinfo/VillagerInfo.java +++ b/src/main/java/adhdmc/villagerinfo/VillagerInfo.java @@ -16,17 +16,15 @@ public final class VillagerInfo extends JavaPlugin { public static VillagerInfo plugin; public static LocaleConfig localeConfig; - //These are for the PDC stuff because I manage to not be able to keep '0' and '1' straight in my head, for which is true or false - public static final String toggleInfoOn = "toggleInfoOn"; - public static final String toggleInfoOff = "toggleInfoOff"; public static final String isCurrentlyHighlighted = "isCurrentlyHighlighted"; public static final String isNotCurrentlyHighlighted = "isNotCurrentlyHighlighted"; - public static final double version = 2.0; //Permissions public static final String toggleCommandPermission = "villagerinfo.toggle"; public static final String reloadCommandPermission = "villagerinfo.reload"; public static final String usePermission = "villagerinfo.use"; + private static NamespacedKey infoEnabledKey; + @Override public void onEnable() { plugin = this; @@ -37,6 +35,7 @@ public void onEnable() { this.getLogger().severe("VillagerInfo relies on methods in classes not present on your server. Disabling plugin"); this.getServer().getPluginManager().disablePlugin(this); } + infoEnabledKey = new NamespacedKey(VillagerInfo.plugin, "infoEnabled"); localeConfig = new LocaleConfig(this); localeConfig.getlocaleConfig(); Metrics metrics = new Metrics(this, 13653); @@ -61,4 +60,8 @@ private void registerCommands() { CommandHandler.subcommandList.put("toggle", new ToggleCommand()); CommandHandler.subcommandList.put("reload", new ReloadCommand()); } + + public static NamespacedKey getInfoEnabledKey() { + return infoEnabledKey; + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7dd03df..38888ed 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,12 @@ name: VillagerInfo -author: Rhythmic, Peashooter101 +authors: + - Rhythmic + - Peashooter101 description: Easier access to information from villager's brains generally only accessable through the /data command. version: '${project.version}' main: adhdmc.villagerinfo.VillagerInfo api-version: 1.19 +website: https://github.com/RhythmicSys/VillagerInfo commands: vill: description: base command for VillagerInfo