From a543d1b2782564f82cf8b6b51b29c3862d7513db Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Mon, 16 Dec 2024 22:05:05 -0500 Subject: [PATCH 1/8] Re-add silencing mobs feature under PU's roof --- .../modules/bitsandbobs/BitsAndBobs.java | 1 + .../bitsandbobs/minimodules/SilenceMobs.java | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java index cdfbcb16..8c6429b7 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java @@ -61,6 +61,7 @@ public void onEnable() { manager.registerEvents(new ShardLotto(), plugin); manager.registerEvents(new ChickenFeatherDrops(), plugin); manager.registerEvents(new EntityTweaks(), plugin); + manager.registerEvents(new SilenceMobs(), plugin); if (config.getBoolean("speedy-minecarts", false)) { manager.registerEvents(new SpeedyMinecarts(), plugin); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java new file mode 100644 index 00000000..e4828346 --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java @@ -0,0 +1,65 @@ +package parallelmc.parallelutils.modules.bitsandbobs.minimodules; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import parallelmc.parallelutils.Constants; +import parallelmc.parallelutils.ParallelUtils; + +import java.util.Objects; +import java.util.logging.Level; + +public class SilenceMobs implements Listener { + + NamespacedKey silencedKey; + + public SilenceMobs() { + PluginManager manager = Bukkit.getPluginManager(); + Plugin plugin = manager.getPlugin(Constants.PLUGIN_NAME); + if (plugin == null) { + ParallelUtils.log(Level.SEVERE, "Unable to enable SilenceMobs. Plugin " + Constants.PLUGIN_NAME + + " does not exist!"); + return; + } + + silencedKey = new NamespacedKey(plugin, "silencedByNametag"); + } + + @EventHandler + public void useSilenceNametag(PlayerInteractEntityEvent event) { + EquipmentSlot slot = event.getHand(); + Player player = event.getPlayer(); + if (!player.getEquipment().getItem(slot).getType().equals(Material.NAME_TAG)) { + return; + } + if (!(event.getRightClicked() instanceof LivingEntity entity)) { + return; + } + TextComponent nametagName = (TextComponent) player.getEquipment().getItem(slot).getItemMeta().displayName(); + // If name tag is "silence me", silence the mob. If the name tag contents are different and the entity was + // previously silenced by a "silence me" name tag, un-silence the mob + if (nametagName != null && nametagName.content().equalsIgnoreCase("silence me")) { + entity.setSilent(true); + entity.customName(Component.text("Silenced")); + if (!player.getGameMode().equals(GameMode.CREATIVE)) { + player.getEquipment().getItem(slot).subtract(); + } + event.setCancelled(true); + } else { + if (Objects.equals(entity.customName(), Component.text("Silenced"))) { + entity.setSilent(false); + } + } + } +} From fcb5edbfd1c1c5104f07974cd39f52f12ee51ffb Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Mon, 16 Dec 2024 22:11:43 -0500 Subject: [PATCH 2/8] Remove useless NamespacedKey stuff --- .../bitsandbobs/minimodules/SilenceMobs.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java index e4828346..f29ffe94 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java @@ -22,20 +22,6 @@ public class SilenceMobs implements Listener { - NamespacedKey silencedKey; - - public SilenceMobs() { - PluginManager manager = Bukkit.getPluginManager(); - Plugin plugin = manager.getPlugin(Constants.PLUGIN_NAME); - if (plugin == null) { - ParallelUtils.log(Level.SEVERE, "Unable to enable SilenceMobs. Plugin " + Constants.PLUGIN_NAME - + " does not exist!"); - return; - } - - silencedKey = new NamespacedKey(plugin, "silencedByNametag"); - } - @EventHandler public void useSilenceNametag(PlayerInteractEntityEvent event) { EquipmentSlot slot = event.getHand(); From 071d82dd4cb208741298263957ecbe4bd3d287a5 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Mon, 16 Dec 2024 22:12:17 -0500 Subject: [PATCH 3/8] Remove useless NamespacedKey stuff --- .../modules/bitsandbobs/minimodules/SilenceMobs.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java index f29ffe94..9c25c775 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SilenceMobs.java @@ -2,23 +2,16 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; -import parallelmc.parallelutils.Constants; -import parallelmc.parallelutils.ParallelUtils; import java.util.Objects; -import java.util.logging.Level; public class SilenceMobs implements Listener { From b50e707f9bcaf4fd59ed7da3cda7b5c44c44ca4e Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:47:41 -0500 Subject: [PATCH 4/8] Add /hat command and hat slot clicking functionality --- api/build.gradle | 10 +++ .../parallelmc/parallelutils/Constants.java | 5 +- .../parallelutils/util/MessageTools.java | 66 +++++++++++++++++++ .../parallelutils/util/MessageType.java | 10 +++ .../modules/bitsandbobs/BitsAndBobs.java | 3 + .../modules/bitsandbobs/commands/Hat.java | 43 ++++++++++++ .../bitsandbobs/minimodules/HatSlotStuff.java | 39 +++++++++++ 7 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 api/src/main/java/parallelmc/parallelutils/util/MessageTools.java create mode 100644 api/src/main/java/parallelmc/parallelutils/util/MessageType.java create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/commands/Hat.java create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/HatSlotStuff.java diff --git a/api/build.gradle b/api/build.gradle index f3da1161..22587f10 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -303,6 +303,12 @@ bukkit { description = 'Opens the point redemption shop for a player' usage = '/openpointsredemption (player)' } + hat { + description = 'Allows you to wear the item in your main hand as a hat' + usage = '/hat' + permissionMessage = 'You do not have permission.' + permission = 'parallelutils.hat.*' + } } permissions { @@ -502,5 +508,9 @@ bukkit { 'parallelutils.recalculatepoints' { description = 'Gives access to the /recalculatepoints dev command' } + 'parallelutils.hat.*' { + description = 'Allows you to wear any item as a hat' + setDefault('FALSE') + } } } \ No newline at end of file diff --git a/api/src/main/java/parallelmc/parallelutils/Constants.java b/api/src/main/java/parallelmc/parallelutils/Constants.java index ec72b3c4..a0453c31 100644 --- a/api/src/main/java/parallelmc/parallelutils/Constants.java +++ b/api/src/main/java/parallelmc/parallelutils/Constants.java @@ -1,11 +1,14 @@ package parallelmc.parallelutils; -import java.util.ArrayList; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; public class Constants { public static final Version VERSION = new Version(4, 4, 0); public static final String PLUGIN_NAME = "ParallelUtils"; + public static final Component PLUGIN_PREFIX = MiniMessage.miniMessage() + .deserialize("[P] "); public static final String DEFAULT_WORLD = "world2"; public static final String[] OVERWORLD_TYPE_WORLDS = {"world", "world2", "world_skyteaser"}; diff --git a/api/src/main/java/parallelmc/parallelutils/util/MessageTools.java b/api/src/main/java/parallelmc/parallelutils/util/MessageTools.java new file mode 100644 index 00000000..f095a0d7 --- /dev/null +++ b/api/src/main/java/parallelmc/parallelutils/util/MessageTools.java @@ -0,0 +1,66 @@ +package parallelmc.parallelutils.util; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import parallelmc.parallelutils.Constants; + +/** + * A set of utilities to make sending messages easier + */ +public class MessageTools { + + /** + * Sends a message to a player with the Parallel prefix prepended to it + * (This version of the method sends an "INFO" style message) + * @param player The player to send the message to + * @param message The message without the prefix + */ + public static void sendMessage(Player player, String message) { + TextComponent finalMessage = (TextComponent) Constants.PLUGIN_PREFIX + .append(Component.text(message, NamedTextColor.AQUA)); + player.sendMessage(finalMessage); + } + + /** + * Sends a message to a player with the Parallel prefix prepended to it + * @param player The player to send the message to + * @param message The message without the prefix + * @param messageType The type of message; this determines the message color + */ + public static void sendMessage(Player player, String message, MessageType messageType) { + TextComponent finalMessage = switch (messageType) { + case INFO -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.AQUA)); + case SUCCESS -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.GREEN)); + case ERROR -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.RED)); + }; + player.sendMessage(finalMessage); + } + + /** + * Sends a message to console with the Parallel prefix prepended to it + * (This version of the method sends an "INFO" style message) + * @param message The message without the prefix + */ + public static void sendConsoleMessage(String message) { + TextComponent finalMessage = (TextComponent) Constants.PLUGIN_PREFIX + .append(Component.text(message, NamedTextColor.AQUA)); + Bukkit.getConsoleSender().sendMessage(finalMessage); + } + + /** + * Sends a message to console with the Parallel prefix prepended to it + * @param message The message without the prefix + * @param messageType The type of message; this determines the message color + */ + public static void sendConsoleMessage(String message, MessageType messageType) { + TextComponent finalMessage = switch (messageType) { + case INFO -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.AQUA)); + case SUCCESS -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.GREEN)); + case ERROR -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.RED)); + }; + Bukkit.getConsoleSender().sendMessage(finalMessage); + } +} diff --git a/api/src/main/java/parallelmc/parallelutils/util/MessageType.java b/api/src/main/java/parallelmc/parallelutils/util/MessageType.java new file mode 100644 index 00000000..dbde15d6 --- /dev/null +++ b/api/src/main/java/parallelmc/parallelutils/util/MessageType.java @@ -0,0 +1,10 @@ +package parallelmc.parallelutils.util; + +/** + * An enum to allow sending a different color of Parallel message depending on the message type + */ +public enum MessageType { + INFO, + SUCCESS, + ERROR +} diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java index cdfbcb16..64ac92a9 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java @@ -9,6 +9,7 @@ import parallelmc.parallelutils.ParallelClassLoader; import parallelmc.parallelutils.ParallelModule; import parallelmc.parallelutils.ParallelUtils; +import parallelmc.parallelutils.modules.bitsandbobs.commands.Hat; import parallelmc.parallelutils.modules.bitsandbobs.minimodules.*; import parallelmc.parallelutils.modules.bitsandbobs.minimodules.togglepvp.OnPvp; import parallelmc.parallelutils.modules.bitsandbobs.minimodules.togglepvp.TogglePvpCommand; @@ -54,6 +55,7 @@ public void onEnable() { FileConfiguration config = puPlugin.getConfig(); puPlugin.getCommand("togglepvp").setExecutor(new TogglePvpCommand()); + puPlugin.getCommand("hat").setExecutor(new Hat()); manager.registerEvents(new DoorKnocker(), plugin); manager.registerEvents(new SpecialItems(), plugin); @@ -61,6 +63,7 @@ public void onEnable() { manager.registerEvents(new ShardLotto(), plugin); manager.registerEvents(new ChickenFeatherDrops(), plugin); manager.registerEvents(new EntityTweaks(), plugin); + manager.registerEvents(new HatSlotStuff(), plugin); if (config.getBoolean("speedy-minecarts", false)) { manager.registerEvents(new SpeedyMinecarts(), plugin); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/commands/Hat.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/commands/Hat.java new file mode 100644 index 00000000..cc47b966 --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/commands/Hat.java @@ -0,0 +1,43 @@ +package parallelmc.parallelutils.modules.bitsandbobs.commands; + +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.jetbrains.annotations.NotNull; +import parallelmc.parallelutils.util.MessageTools; +import parallelmc.parallelutils.util.MessageType; + +public class Hat implements CommandExecutor { + @Override + public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (commandSender instanceof Player player) { + PlayerInventory inventory = player.getInventory(); + ItemStack heldItem = inventory.getItemInMainHand(); + if (heldItem.getType() == Material.AIR) { + MessageTools.sendMessage(player, "You aren't holding anything in your hand!", MessageType.ERROR); + return true; + } + // If the player has permission to wear all hats, or they're holding paper/leather horse armor with + // custom model data, swap their hand and hat slots + if (player.hasPermission("parallelutils.hat.*") || + ((heldItem.getType() == Material.PAPER || heldItem.getType() == Material.LEATHER_HORSE_ARMOR) + && heldItem.getItemMeta().hasCustomModelData())) { + + ItemStack helmetItem = inventory.getHelmet(); + inventory.setItemInMainHand(helmetItem); + inventory.setHelmet(heldItem); + MessageTools.sendMessage(player, "Item set as hat!", MessageType.SUCCESS); + } else { + MessageTools.sendMessage(player, "You don't have permission to set this item as your hat!", MessageType.ERROR); + } + return true; + } else { + MessageTools.sendConsoleMessage("You must be a player to run this command!", MessageType.ERROR); + } + return true; + } +} diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/HatSlotStuff.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/HatSlotStuff.java new file mode 100644 index 00000000..3f5b09c3 --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/HatSlotStuff.java @@ -0,0 +1,39 @@ +package parallelmc.parallelutils.modules.bitsandbobs.minimodules; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import parallelmc.parallelutils.util.MessageTools; +import parallelmc.parallelutils.util.MessageType; + +public class HatSlotStuff implements Listener { + + @EventHandler + public void onHelmetSlotClick(InventoryClickEvent event) { + // Make sure the player is clicking on the helmet slot with an actual item that isn't already supposed to go + // in the head slot + if (event.getInventory().getType() == InventoryType.PLAYER && + event.getRawSlot() == 5 && + event.getWhoClicked().getItemOnCursor().getType() != Material.AIR && + event.getWhoClicked().getItemOnCursor().getType().getEquipmentSlot() != EquipmentSlot.HEAD) { + + // Swap the cursor and helmet items + Player player = (Player) event.getWhoClicked(); + ItemStack cursorItem = player.getItemOnCursor(); + if (player.hasPermission("parallelutils.hat.*") || + ((cursorItem.getType() == Material.PAPER || cursorItem.getType() == Material.LEATHER_HORSE_ARMOR) + && cursorItem.getItemMeta().hasCustomModelData())) { + + ItemStack helmetItem = player.getInventory().getHelmet(); + player.getInventory().setHelmet(cursorItem); + player.setItemOnCursor(helmetItem); + MessageTools.sendMessage(player, "Item set as hat!", MessageType.SUCCESS); + } + } + } +} From e87e4c577364c60496a3f00190ee7edc0e319a51 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:01:55 -0500 Subject: [PATCH 5/8] Bug fixes --- api/build.gradle | 1 - .../bitsandbobs/minimodules/HatSlotStuff.java | 32 ++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 22587f10..1fcadf8d 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -510,7 +510,6 @@ bukkit { } 'parallelutils.hat.*' { description = 'Allows you to wear any item as a hat' - setDefault('FALSE') } } } \ No newline at end of file diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/HatSlotStuff.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/HatSlotStuff.java index 3f5b09c3..adc22cf0 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/HatSlotStuff.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/HatSlotStuff.java @@ -1,5 +1,6 @@ package parallelmc.parallelutils.modules.bitsandbobs.minimodules; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -8,21 +9,30 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import parallelmc.parallelutils.util.BukkitTools; import parallelmc.parallelutils.util.MessageTools; import parallelmc.parallelutils.util.MessageType; public class HatSlotStuff implements Listener { + Plugin plugin; + + public HatSlotStuff() { + plugin = BukkitTools.getPlugin(); + } + @EventHandler public void onHelmetSlotClick(InventoryClickEvent event) { // Make sure the player is clicking on the helmet slot with an actual item that isn't already supposed to go // in the head slot - if (event.getInventory().getType() == InventoryType.PLAYER && + if (event.getClickedInventory() != null && + event.getClickedInventory().getType() == InventoryType.PLAYER && event.getRawSlot() == 5 && event.getWhoClicked().getItemOnCursor().getType() != Material.AIR && event.getWhoClicked().getItemOnCursor().getType().getEquipmentSlot() != EquipmentSlot.HEAD) { - // Swap the cursor and helmet items + // Get the cursor and helmet items Player player = (Player) event.getWhoClicked(); ItemStack cursorItem = player.getItemOnCursor(); if (player.hasPermission("parallelutils.hat.*") || @@ -30,10 +40,22 @@ public void onHelmetSlotClick(InventoryClickEvent event) { && cursorItem.getItemMeta().hasCustomModelData())) { ItemStack helmetItem = player.getInventory().getHelmet(); - player.getInventory().setHelmet(cursorItem); - player.setItemOnCursor(helmetItem); - MessageTools.sendMessage(player, "Item set as hat!", MessageType.SUCCESS); + player.getInventory().setHelmet(null); + player.setItemOnCursor(null); + + // Swap the cursor and helmet items + // Delay hat placement by one tick (ty Mojang) + Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { + @Override + public void run() { + player.getInventory().setHelmet(cursorItem); + player.setItemOnCursor(helmetItem); + MessageTools.sendMessage(player, "Item set as hat!", MessageType.SUCCESS); + } + },1L); } } } + + } From 012450d3a5eb1de429b11d3815d1aa921bac503b Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:22:46 -0500 Subject: [PATCH 6/8] Fix some msgs --- .../parallelutils/modules/points/commands/ViewPoints.java | 3 ++- .../modules/points/events/OnAdvancementDone.java | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/ViewPoints.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/ViewPoints.java index 898c4157..58c050b8 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/ViewPoints.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/ViewPoints.java @@ -13,7 +13,8 @@ public class ViewPoints implements CommandExecutor { public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (commandSender instanceof Player player) { int points = Points.get().getPlayerPoints(player); - ParallelChat.sendParallelMessageTo(player, "You currently have " + points + " advancement points!"); + ParallelChat.sendParallelMessageTo(player, + "You currently have " + points + " advancement " + ((points == 1) ? "point!" : "points!")); } return true; } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java index 19e369ec..43f95cfd 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java @@ -23,10 +23,7 @@ public void onAdvancementDone(PlayerAdvancementDoneEvent event) { } Points.get().awardPoints(player, points); // wait 1 tick to send the message so it shows after the advancement - if (points == 1) { - ParallelChat.sendDelayedParallelMessageTo(player, 1, "You've received " + points + " advancement point!"); - } else { - ParallelChat.sendDelayedParallelMessageTo(player, 1, "You've received " + points + " advancement points!"); - } + ParallelChat.sendDelayedParallelMessageTo(player, 1, + "You currently have " + points + " advancement " + ((points == 1) ? "point!" : "points!")); } } From d495b45bd4bcaf0113a0e31bf4bbb36e295ef864 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:26:26 -0500 Subject: [PATCH 7/8] Get rid of root and recipe advancements spamming console --- .../modules/points/events/OnAdvancementDone.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java index 43f95cfd..e22babb1 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java @@ -16,14 +16,21 @@ public class OnAdvancementDone implements Listener { public void onAdvancementDone(PlayerAdvancementDoneEvent event) { Advancement advancement = event.getAdvancement(); Player player = event.getPlayer(); + int points = Points.get().getPointsForAdvancement(advancement); if (points == -1) { - ParallelUtils.log(Level.WARNING, "Advancement " + advancement.getKey().asString() + " has no associated point value! Skipping..."); + // If the advancement is a root advancement or recipes advancement, don't print an error message. + // We can assume that advancements without displays are recipe advancements + // ParallelUtils.log(Level.WARNING, advancementTitle.toString()); + if (!(advancement.getRoot() == advancement) && !(advancement.getDisplay() == null)) { + ParallelUtils.log(Level.WARNING, "Advancement " + advancement.getKey().asString() + " has no associated point value! Skipping..."); + } return; } + Points.get().awardPoints(player, points); // wait 1 tick to send the message so it shows after the advancement ParallelChat.sendDelayedParallelMessageTo(player, 1, - "You currently have " + points + " advancement " + ((points == 1) ? "point!" : "points!")); + "You've received " + points + " advancement " + ((points == 1) ? "point!" : "points!")); } } From c5a791b56c361e2c2a04bbd81cf663ded5f01c5a Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:30:19 -0500 Subject: [PATCH 8/8] Make not equals checks not stupidly formatted --- .../parallelutils/modules/points/events/OnAdvancementDone.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java index e22babb1..d309c22e 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java @@ -22,7 +22,7 @@ public void onAdvancementDone(PlayerAdvancementDoneEvent event) { // If the advancement is a root advancement or recipes advancement, don't print an error message. // We can assume that advancements without displays are recipe advancements // ParallelUtils.log(Level.WARNING, advancementTitle.toString()); - if (!(advancement.getRoot() == advancement) && !(advancement.getDisplay() == null)) { + if (advancement.getRoot() != advancement && advancement.getDisplay() != null) { ParallelUtils.log(Level.WARNING, "Advancement " + advancement.getKey().asString() + " has no associated point value! Skipping..."); } return;