From 0fa4ab4355e36aa9ea0840dd678bad727d033f76 Mon Sep 17 00:00:00 2001 From: byteful Date: Thu, 11 May 2023 20:03:10 -0500 Subject: [PATCH] v1.3.3 fix --- .../plugin/leveltools/LevelToolsCommand.java | 84 +++++++-------- .../leveltools/LevelToolsPlaceholders.java | 5 +- .../plugin/leveltools/LevelToolsPlugin.java | 59 +++++----- .../leveltools/api/AnvilCombineMode.java | 101 +++++++++--------- .../plugin/leveltools/api/RewardType.java | 47 ++++---- .../event/LevelToolsLevelIncreaseEvent.java | 19 +--- .../api/event/LevelToolsXPIncreaseEvent.java | 8 +- .../leveltools/api/item/LevelToolsItem.java | 26 ++--- .../api/item/impl/NBTLevelToolsItem.java | 36 +++---- .../api/item/impl/PDCLevelToolsItem.java | 36 ++----- .../leveltools/listeners/AnvilListener.java | 19 +--- .../listeners/BlockEventListener.java | 26 ++--- .../listeners/EntityEventListener.java | 31 +++--- .../leveltools/listeners/XPListener.java | 26 ++--- .../leveltools/util/LevelToolsUtil.java | 91 ++++------------ src/main/resources/config.yml | 3 + 16 files changed, 232 insertions(+), 385 deletions(-) diff --git a/src/main/java/me/byteful/plugin/leveltools/LevelToolsCommand.java b/src/main/java/me/byteful/plugin/leveltools/LevelToolsCommand.java index 4431878..0193ab6 100644 --- a/src/main/java/me/byteful/plugin/leveltools/LevelToolsCommand.java +++ b/src/main/java/me/byteful/plugin/leveltools/LevelToolsCommand.java @@ -15,21 +15,21 @@ @Command("leveltools") public class LevelToolsCommand { - @Dependency - private LevelToolsPlugin plugin; - - @DefaultFor("leveltools") - @Subcommand("help") - @Description("Shows the list of LevelTools commands.") - public void onHelp(CommandSender sender, CommandHelp help, @Default("1") int page) { - sender.sendMessage(colorize("&6&lLevelTools Command Help:")); - for (String entry : help.paginate(page, 7)) { - sender.sendMessage(colorize(entry)); - } + @Dependency + private LevelToolsPlugin plugin; + + @DefaultFor("leveltools") + @Subcommand("help") + @Description("Shows the list of LevelTools commands.") + public void onHelp(CommandSender sender, CommandHelp help, @Default("1") int page) { + sender.sendMessage(colorize("&6&lLevelTools Command Help:")); + for (String entry : help.paginate(page, 7)) { + sender.sendMessage(colorize(entry)); } + } - @Subcommand("reload") - @Description("Reloads LevelTools' plugin configuration.") + @Subcommand("reload") + @Description("Reloads LevelTools' plugin configuration.") public void onReload(CommandSender sender) { if (!checkPerm(sender)) { return; @@ -40,38 +40,38 @@ public void onReload(CommandSender sender) { sender.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.successful_reload")))); } - @Subcommand("reset") - @Description("Resets all XP/Levels for all the items in the target player.") - public void onReset(CommandSender sender, Player target, @Switch("all") boolean all) { - if (!all) { - if (!LevelToolsUtil.isSupportedTool(target.getInventory().getItemInMainHand().getType())) { - sender.sendMessage(colorize(plugin.getConfig().getString("messages.item_not_tool"))); - - return; - } - - final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(target.getInventory().getItemInMainHand()); - tool.setLevel(0); - tool.setXp(0); - target.getInventory().setItemInMainHand(tool.getItemStack()); - sender.sendMessage(colorize(plugin.getConfig().getString("messages.successfully_reset_hand_tool", "&aSuccessfully reset tool in hand's XP/Levels for {player}.").replace("{player}", target.getName()))); - - return; - } - - final PlayerInventory inv = target.getInventory(); - final ItemStack[] contents = inv.getContents(); - for (int i = 0; i < contents.length; i++) { - final ItemStack item = contents[i]; - if (item == null || !LevelToolsUtil.isSupportedTool(item.getType())) { - continue; - } - final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item); - tool.setLevel(0); + @Subcommand("reset") + @Description("Resets all XP/Levels for all the items in the target player.") + public void onReset(CommandSender sender, Player target, @Switch("all") boolean all) { + if (!all) { + if (!LevelToolsUtil.isSupportedTool(target.getInventory().getItemInMainHand().getType())) { + sender.sendMessage(colorize(plugin.getConfig().getString("messages.item_not_tool"))); + + return; + } + + final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(target.getInventory().getItemInMainHand()); + tool.setLevel(0); + tool.setXp(0); + target.getInventory().setItemInMainHand(tool.getItemStack()); + sender.sendMessage(colorize(plugin.getConfig().getString("messages.successfully_reset_hand_tool", "&aSuccessfully reset tool in hand's XP/Levels for {player}.").replace("{player}", target.getName()))); + + return; + } + + final PlayerInventory inv = target.getInventory(); + final ItemStack[] contents = inv.getContents(); + for (int i = 0; i < contents.length; i++) { + final ItemStack item = contents[i]; + if (item == null || !LevelToolsUtil.isSupportedTool(item.getType())) { + continue; + } + final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item); + tool.setLevel(0); tool.setXp(0); inv.setItem(i, tool.getItemStack()); } - sender.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.successfully_reset_tools")).replace("{player}", target.getName()))); + sender.sendMessage(colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.successfully_reset_tools")).replace("{player}", target.getName()))); } @Subcommand("xp") diff --git a/src/main/java/me/byteful/plugin/leveltools/LevelToolsPlaceholders.java b/src/main/java/me/byteful/plugin/leveltools/LevelToolsPlaceholders.java index 9d863a9..22e7282 100644 --- a/src/main/java/me/byteful/plugin/leveltools/LevelToolsPlaceholders.java +++ b/src/main/java/me/byteful/plugin/leveltools/LevelToolsPlaceholders.java @@ -43,10 +43,7 @@ public boolean persist() { return null; } - final ItemStack hand = - RedLib.MID_VERSION <= 8 - ? player.getItemInHand() - : player.getInventory().getItemInMainHand(); + final ItemStack hand = RedLib.MID_VERSION <= 8 ? player.getItemInHand() : player.getInventory().getItemInMainHand(); if (!LevelToolsUtil.isSupportedTool(hand.getType())) { return "N/A"; diff --git a/src/main/java/me/byteful/plugin/leveltools/LevelToolsPlugin.java b/src/main/java/me/byteful/plugin/leveltools/LevelToolsPlugin.java index eb923ed..ce871a3 100644 --- a/src/main/java/me/byteful/plugin/leveltools/LevelToolsPlugin.java +++ b/src/main/java/me/byteful/plugin/leveltools/LevelToolsPlugin.java @@ -22,9 +22,9 @@ public final class LevelToolsPlugin extends JavaPlugin { private static LevelToolsPlugin instance; - private BlockDataManager blockDataManager; - private BukkitCommandHandler commandManager; - private AnvilCombineMode anvilCombineMode; + private BlockDataManager blockDataManager; + private BukkitCommandHandler commandManager; + private AnvilCombineMode anvilCombineMode; private UpdateChecker updateChecker; public static LevelToolsPlugin getInstance() { @@ -45,15 +45,11 @@ public void onEnable() { final Path oldFile = getDataFolder().toPath().resolve("blocks.db"); if (Files.exists(oldFile)) { if (Files.exists(blocksFile)) { - getLogger() - .warning( - "Found old 'blocks.db' file, but ignored it because a newer 'player_placed_blocks.db' file exists!"); + getLogger().warning("Found old 'blocks.db' file, but ignored it because a newer 'player_placed_blocks.db' file exists!"); } else { try { Files.move(oldFile, blocksFile, StandardCopyOption.COPY_ATTRIBUTES); - getLogger() - .warning( - "Found old 'blocks.db' file... Renamed to newer 'player_placed_blocks.db' file."); + getLogger().warning("Found old 'blocks.db' file... Renamed to newer 'player_placed_blocks.db' file."); } catch (IOException e) { e.printStackTrace(); } @@ -72,34 +68,34 @@ public void onEnable() { blockDataManager.migrate(); getLogger().info("Loaded BlockDataManager..."); - saveDefaultConfig(); - getConfig().options().copyDefaults(); - setAnvilCombineMode(); + saveDefaultConfig(); + getConfig().options().copyDefaults(); + setAnvilCombineMode(); getLogger().info("Loaded configuration..."); if (getConfig().getBoolean("update.start")) { updateChecker.check(); } - if (getConfig().getBoolean("update.periodically")) { - final long delay = 20L * TimeUnit.DAYS.toSeconds(1); - Task.syncRepeating(() -> updateChecker.check(), delay, delay); - } + if (getConfig().getBoolean("update.periodically")) { + final long delay = 20L * TimeUnit.DAYS.toSeconds(1); + Task.syncRepeating(() -> updateChecker.check(), delay, delay); + } - registerListeners(); - getLogger().info("Registered listeners..."); + registerListeners(); + getLogger().info("Registered listeners..."); - commandManager = BukkitCommandHandler.create(this); - commandManager.setHelpWriter((command, actor) -> String.format("&7- &b/%s %s&7: &e%s", command.getPath().toRealString(), command.getUsage(), command.getDescription())); - commandManager.register(new LevelToolsCommand()); - commandManager.registerBrigadier(); - getLogger().info("Registered commands..."); + commandManager = BukkitCommandHandler.create(this); + commandManager.setHelpWriter((command, actor) -> String.format("&7- &b/%s %s&7: &e%s", command.getPath().toRealString(), command.getUsage(), command.getDescription())); + commandManager.register(new LevelToolsCommand()); + commandManager.registerBrigadier(); + getLogger().info("Registered commands..."); - if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) { - new LevelToolsPlaceholders().register(); - } + if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) { + new LevelToolsPlaceholders().register(); + } - getLogger().info("Successfully started " + getDescription().getFullName() + "!"); + getLogger().info("Successfully started " + getDescription().getFullName() + "!"); } @Override @@ -122,8 +118,7 @@ private void registerListeners() { } public void setAnvilCombineMode() { - anvilCombineMode = - AnvilCombineMode.fromName(Objects.requireNonNull(getConfig().getString("anvil_combine"))); + anvilCombineMode = AnvilCombineMode.fromName(Objects.requireNonNull(getConfig().getString("anvil_combine"))); } public BlockDataManager getBlockDataManager() { @@ -134,7 +129,7 @@ public AnvilCombineMode getAnvilCombineMode() { return anvilCombineMode; } - public BukkitCommandHandler getCommandManager() { - return commandManager; - } + public BukkitCommandHandler getCommandManager() { + return commandManager; + } } diff --git a/src/main/java/me/byteful/plugin/leveltools/api/AnvilCombineMode.java b/src/main/java/me/byteful/plugin/leveltools/api/AnvilCombineMode.java index 6ef2399..97b1350 100644 --- a/src/main/java/me/byteful/plugin/leveltools/api/AnvilCombineMode.java +++ b/src/main/java/me/byteful/plugin/leveltools/api/AnvilCombineMode.java @@ -6,66 +6,63 @@ import java.util.function.BinaryOperator; public enum AnvilCombineMode { - HIGHER_OF_BOTH( - (item1, item2) -> { - final int level1 = item1.getLevel(); - final int level2 = item2.getLevel(); - - final double xp1 = item1.getXp(); - final double xp2 = item2.getXp(); - - int level; - double xp; - - if (level1 == level2) { - level = level1; - xp = Math.max(xp1, xp2); + HIGHER_OF_BOTH((item1, item2) -> { + final int level1 = item1.getLevel(); + final int level2 = item2.getLevel(); + + final double xp1 = item1.getXp(); + final double xp2 = item2.getXp(); + + int level; + double xp; + + if (level1 == level2) { + level = level1; + xp = Math.max(xp1, xp2); + } else { + level = Math.max(level1, level2); + if (level == level1) { + xp = xp1; } else { - level = Math.max(level1, level2); - if (level == level1) { - xp = xp1; - } else { - xp = xp2; - } + xp = xp2; } + } - return new LevelAndXPModel(level, xp); - }), - LOWER_OF_BOTH( - (item1, item2) -> { - final int level1 = item1.getLevel(); - final int level2 = item2.getLevel(); - - final double xp1 = item1.getXp(); - final double xp2 = item2.getXp(); - - int level; - double xp; - - if (level1 == level2) { - level = level1; - xp = Math.min(xp1, xp2); + return new LevelAndXPModel(level, xp); + }), + LOWER_OF_BOTH((item1, item2) -> { + final int level1 = item1.getLevel(); + final int level2 = item2.getLevel(); + + final double xp1 = item1.getXp(); + final double xp2 = item2.getXp(); + + int level; + double xp; + + if (level1 == level2) { + level = level1; + xp = Math.min(xp1, xp2); + } else { + level = Math.min(level1, level2); + if (level == level1) { + xp = xp1; } else { - level = Math.min(level1, level2); - if (level == level1) { - xp = xp1; - } else { - xp = xp2; - } + xp = xp2; } + } - return new LevelAndXPModel(level, xp); - }), - ADD_BOTH( - (item1, item2) -> { - final int level1 = item1.getLevel(); - final int level2 = item2.getLevel(); + return new LevelAndXPModel(level, xp); + }), + ADD_BOTH((item1, item2) -> { + final int level1 = item1.getLevel(); + final int level2 = item2.getLevel(); - final double xp1 = item1.getXp(); - final double xp2 = item2.getXp(); + final double xp1 = item1.getXp(); + final double xp2 = item2.getXp(); - return new LevelAndXPModel(level1 + level2, xp1 + xp2); - }); + return new LevelAndXPModel(level1 + level2, xp1 + xp2); + }); @NotNull private final BinaryOperator handler; diff --git a/src/main/java/me/byteful/plugin/leveltools/api/RewardType.java b/src/main/java/me/byteful/plugin/leveltools/api/RewardType.java index aa84734..71eb098 100644 --- a/src/main/java/me/byteful/plugin/leveltools/api/RewardType.java +++ b/src/main/java/me/byteful/plugin/leveltools/api/RewardType.java @@ -16,28 +16,30 @@ public enum RewardType { COMMAND("command") { @Override - public void apply( - @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { - Bukkit.dispatchCommand( - Bukkit.getConsoleSender(), - String.join(" ", Arrays.copyOfRange(split, 1, split.length)) - .replace("{player}", player.getName()).replace("%player%", player.getName())); + public void apply(@NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), String.join(" ", Arrays.copyOfRange(split, 1, split.length)).replace("{player}", player.getName()).replace("%player%", player.getName())); } }, PLAYER_COMMAND("player-command") { @Override - public void apply( - @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { - player.chat( - "/" - + String.join(" ", Arrays.copyOfRange(split, 1, split.length)) - .replace("{player}", player.getName()).replace("%player%", player.getName())); + public void apply(@NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { + player.chat("/" + String.join(" ", Arrays.copyOfRange(split, 1, split.length)).replace("{player}", player.getName()).replace("%player%", player.getName())); + } + }, + PLAYER_OPCOMMAND("player-opcommand") { + @Override + public void apply(@NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { + final boolean isOP = player.isOp(); + if (!isOP) { + player.setOp(true); + } + PLAYER_COMMAND.apply(tool, split, player); + player.setOp(isOP); } }, ENCHANT("enchant") { @Override - public void apply( - @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { + public void apply(@NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { if (split.length < 3) { return; } @@ -51,8 +53,7 @@ public void apply( }, ENCHANT_2("enchant2") { @Override - public void apply( - @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { + public void apply(@NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { if (split.length < 3) { return; } @@ -62,10 +63,7 @@ public void apply( if (NumberUtils.isNumber(split[2])) { final int level = Integer.parseInt(split[2]); - if (enchant.isPresent() - && tool.getItemStack() - .getEnchantmentLevel(Objects.requireNonNull(enchant.get().getEnchant())) - < level) { + if (enchant.isPresent() && tool.getItemStack().getEnchantmentLevel(Objects.requireNonNull(enchant.get().getEnchant())) < level) { tool.enchant(enchant.get().getEnchant(), level); } } @@ -73,8 +71,7 @@ public void apply( }, ENCHANT_3("enchant3") { @Override - public void apply( - @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { + public void apply(@NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { if (split.length < 3) { return; } @@ -93,8 +90,7 @@ public void apply( }, ATTRIBUTE("attribute") { @Override - public void apply( - @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { + public void apply(@NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) { if (split.length < 3) { return; } @@ -131,8 +127,7 @@ public static Optional fromConfigKey(@NotNull String configKey) { return Optional.empty(); } - public abstract void apply( - @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player); + public abstract void apply(@NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player); @NotNull public String getConfigKey() { diff --git a/src/main/java/me/byteful/plugin/leveltools/api/event/LevelToolsLevelIncreaseEvent.java b/src/main/java/me/byteful/plugin/leveltools/api/event/LevelToolsLevelIncreaseEvent.java index d40f3f5..121ea90 100644 --- a/src/main/java/me/byteful/plugin/leveltools/api/event/LevelToolsLevelIncreaseEvent.java +++ b/src/main/java/me/byteful/plugin/leveltools/api/event/LevelToolsLevelIncreaseEvent.java @@ -23,8 +23,7 @@ public LevelToolsLevelIncreaseEvent(@NotNull LevelToolsItem item, @NotNull Playe this.player = player; } - public LevelToolsLevelIncreaseEvent( - @NotNull LevelToolsItem item, @NotNull Player player, int newLevel, boolean isCancelled) { + public LevelToolsLevelIncreaseEvent(@NotNull LevelToolsItem item, @NotNull Player player, int newLevel, boolean isCancelled) { this.item = item; this.player = player; this.newLevel = newLevel; @@ -69,10 +68,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LevelToolsLevelIncreaseEvent that = (LevelToolsLevelIncreaseEvent) o; - return newLevel == that.newLevel - && isCancelled == that.isCancelled - && item.equals(that.item) - && player.equals(that.player); + return newLevel == that.newLevel && isCancelled == that.isCancelled && item.equals(that.item) && player.equals(that.player); } @Override @@ -88,15 +84,6 @@ public HandlerList getHandlers() { @Override public String toString() { - return "LevelToolsLevelIncreaseEvent{" - + "item=" - + item - + ", player=" - + player - + ", newLevel=" - + newLevel - + ", isCancelled=" - + isCancelled - + '}'; + return "LevelToolsLevelIncreaseEvent{" + "item=" + item + ", player=" + player + ", newLevel=" + newLevel + ", isCancelled=" + isCancelled + '}'; } } diff --git a/src/main/java/me/byteful/plugin/leveltools/api/event/LevelToolsXPIncreaseEvent.java b/src/main/java/me/byteful/plugin/leveltools/api/event/LevelToolsXPIncreaseEvent.java index cf18716..b11643f 100644 --- a/src/main/java/me/byteful/plugin/leveltools/api/event/LevelToolsXPIncreaseEvent.java +++ b/src/main/java/me/byteful/plugin/leveltools/api/event/LevelToolsXPIncreaseEvent.java @@ -23,8 +23,7 @@ public LevelToolsXPIncreaseEvent(@NotNull LevelToolsItem item, @NotNull Player p this.player = player; } - public LevelToolsXPIncreaseEvent( - @NotNull LevelToolsItem item, @NotNull Player player, double newXp, boolean isCancelled) { + public LevelToolsXPIncreaseEvent(@NotNull LevelToolsItem item, @NotNull Player player, double newXp, boolean isCancelled) { this.item = item; this.player = player; this.newXp = newXp; @@ -75,10 +74,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LevelToolsXPIncreaseEvent that = (LevelToolsXPIncreaseEvent) o; - return Double.compare(that.newXp, newXp) == 0 - && isCancelled == that.isCancelled - && item.equals(that.item) - && player.equals(that.player); + return Double.compare(that.newXp, newXp) == 0 && isCancelled == that.isCancelled && item.equals(that.item) && player.equals(that.player); } @Override diff --git a/src/main/java/me/byteful/plugin/leveltools/api/item/LevelToolsItem.java b/src/main/java/me/byteful/plugin/leveltools/api/item/LevelToolsItem.java index f24dd26..55018d9 100644 --- a/src/main/java/me/byteful/plugin/leveltools/api/item/LevelToolsItem.java +++ b/src/main/java/me/byteful/plugin/leveltools/api/item/LevelToolsItem.java @@ -7,8 +7,7 @@ import org.jetbrains.annotations.NotNull; public interface LevelToolsItem { - @NotNull - ItemStack getItemStack(); + @NotNull ItemStack getItemStack(); int getLevel(); @@ -20,24 +19,19 @@ public interface LevelToolsItem { default double getMaxXp() { final double xpStart = LevelToolsPlugin.getInstance().getConfig().getDouble("level_xp_start"); - double increaseAmount = - LevelToolsPlugin.getInstance().getConfig().getDouble("level_xp_increase.amount"); - final String mode = - LevelToolsPlugin.getInstance().getConfig().getString("level_xp_increase.mode"); + double increaseAmount = LevelToolsPlugin.getInstance().getConfig().getDouble("level_xp_increase.amount"); + final String mode = LevelToolsPlugin.getInstance().getConfig().getString("level_xp_increase.mode"); if (xpStart < 1.0) { - throw new RuntimeException( - "Failed to find valid value for 'level_xp_start'. Please make sure it is equal to or over 1.0. Check your configuration!"); + throw new RuntimeException("Failed to find valid value for 'level_xp_start'. Please make sure it is equal to or over 1.0. Check your configuration!"); } if (increaseAmount < 1.0) { - throw new RuntimeException( - "Failed to find valid value for 'level_xp_increase -> amount'. Please make sure it is equal to or over 1.0. Check your configuration!"); + throw new RuntimeException("Failed to find valid value for 'level_xp_increase -> amount'. Please make sure it is equal to or over 1.0. Check your configuration!"); } if (mode == null) { - throw new RuntimeException( - "Failed to find valid value for 'level_xp_increase -> mode'. Please check your configuration!"); + throw new RuntimeException("Failed to find valid value for 'level_xp_increase -> mode'. Please check your configuration!"); } double nextXp = xpStart; @@ -48,18 +42,14 @@ default double getMaxXp() { } else if (mode.equalsIgnoreCase("MULTIPLY")) { nextXp = xpStart * (Math.pow(increaseAmount, getLevel() * 1.0)); } else { - throw new RuntimeException( - "Mode for 'level_xp_increase' is not 'ADD' or 'MULTIPLY'. Please check your configuration!"); + throw new RuntimeException("Mode for 'level_xp_increase' is not 'ADD' or 'MULTIPLY'. Please check your configuration!"); } } final double rounded = LevelToolsUtil.round(nextXp, 1); if (rounded <= 0.0) { - throw new RuntimeException( - "Failed to round " - + nextXp - + " to the first place. Please modify your values to get a better result! Check your configuration!"); + throw new RuntimeException("Failed to round " + nextXp + " to the first place. Please modify your values to get a better result! Check your configuration!"); } return rounded; diff --git a/src/main/java/me/byteful/plugin/leveltools/api/item/impl/NBTLevelToolsItem.java b/src/main/java/me/byteful/plugin/leveltools/api/item/impl/NBTLevelToolsItem.java index 32d9590..5530d61 100644 --- a/src/main/java/me/byteful/plugin/leveltools/api/item/impl/NBTLevelToolsItem.java +++ b/src/main/java/me/byteful/plugin/leveltools/api/item/impl/NBTLevelToolsItem.java @@ -33,22 +33,19 @@ public NBTLevelToolsItem(@NotNull ItemStack stack) { @NotNull @Override public ItemStack getItemStack() { - final ItemStack stack = - LevelToolsUtil.buildItemStack( - nbt.getItem().clone(), enchantments, getLevel(), getXp(), getMaxXp()); + final ItemStack stack = LevelToolsUtil.buildItemStack(nbt.getItem().clone(), enchantments, getLevel(), getXp(), getMaxXp()); nbt = new NBTItem(stack); final NBTCompoundList attr = nbt.getCompoundList("AttributeModifiers"); - attributes.forEach( - (attribute, modifier) -> { - final NBTListCompound list = attr.addCompound(); - list.setDouble("Amount", modifier); - list.setString("AttributeName", attribute); - list.setString("Name", attribute); - list.setInteger("Operation", 0); - list.setInteger("UUIDLeast", 59664); - list.setInteger("UUIDMost", 31453); - }); + attributes.forEach((attribute, modifier) -> { + final NBTListCompound list = attr.addCompound(); + list.setDouble("Amount", modifier); + list.setString("AttributeName", attribute); + list.setString("Name", attribute); + list.setInteger("Operation", 0); + list.setInteger("UUIDLeast", 59664); + list.setInteger("UUIDMost", 31453); + }); return nbt.getItem(); } @@ -142,9 +139,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; NBTLevelToolsItem that = (NBTLevelToolsItem) o; - return nbt.equals(that.nbt) - && enchantments.equals(that.enchantments) - && attributes.equals(that.attributes); + return nbt.equals(that.nbt) && enchantments.equals(that.enchantments) && attributes.equals(that.attributes); } @Override @@ -154,13 +149,6 @@ public int hashCode() { @Override public String toString() { - return "NBTLevelToolsItem{" - + "nbt=" - + nbt - + ", enchantments=" - + enchantments - + ", attributes=" - + attributes - + '}'; + return "NBTLevelToolsItem{" + "nbt=" + nbt + ", enchantments=" + enchantments + ", attributes=" + attributes + '}'; } } diff --git a/src/main/java/me/byteful/plugin/leveltools/api/item/impl/PDCLevelToolsItem.java b/src/main/java/me/byteful/plugin/leveltools/api/item/impl/PDCLevelToolsItem.java index c20de85..b3bf319 100644 --- a/src/main/java/me/byteful/plugin/leveltools/api/item/impl/PDCLevelToolsItem.java +++ b/src/main/java/me/byteful/plugin/leveltools/api/item/impl/PDCLevelToolsItem.java @@ -21,9 +21,7 @@ public class PDCLevelToolsItem implements LevelToolsItem { @NotNull - public static final NamespacedKey - LEVEL_KEY = new NamespacedKey(LevelToolsPlugin.getInstance(), "levelToolsLevel"), - XP_KEY = new NamespacedKey(LevelToolsPlugin.getInstance(), "levelToolsXp"); + public static final NamespacedKey LEVEL_KEY = new NamespacedKey(LevelToolsPlugin.getInstance(), "levelToolsLevel"), XP_KEY = new NamespacedKey(LevelToolsPlugin.getInstance(), "levelToolsXp"); @NotNull private ItemStack stack; @@ -42,18 +40,15 @@ public PDCLevelToolsItem(@NotNull ItemStack stack) { public @NotNull ItemStack getItemStack() { final ItemStack stack = LevelToolsUtil.buildItemStack(this.stack, enchantments, getLevel(), getXp(), getMaxXp()); - attributes.forEach( - (attribute, modifier) -> { - final ItemMeta meta = stack.getItemMeta(); - assert meta != null : "ItemMeta is null! Should not happen."; + attributes.forEach((attribute, modifier) -> { + final ItemMeta meta = stack.getItemMeta(); + assert meta != null : "ItemMeta is null! Should not happen."; - final Attribute attr = - Attribute.valueOf(attribute.replace(".", "_").toUpperCase(Locale.ROOT).trim()); - final AttributeModifier mod = - new AttributeModifier(attribute, modifier, AttributeModifier.Operation.ADD_NUMBER); - meta.addAttributeModifier(attr, mod); - stack.setItemMeta(meta); - }); + final Attribute attr = Attribute.valueOf(attribute.replace(".", "_").toUpperCase(Locale.ROOT).trim()); + final AttributeModifier mod = new AttributeModifier(attribute, modifier, AttributeModifier.Operation.ADD_NUMBER); + meta.addAttributeModifier(attr, mod); + stack.setItemMeta(meta); + }); return stack; } @@ -151,9 +146,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PDCLevelToolsItem that = (PDCLevelToolsItem) o; - return stack.equals(that.stack) - && enchantments.equals(that.enchantments) - && attributes.equals(that.attributes); + return stack.equals(that.stack) && enchantments.equals(that.enchantments) && attributes.equals(that.attributes); } @Override @@ -163,13 +156,6 @@ public int hashCode() { @Override public String toString() { - return "PDCLevelToolsItem{" - + "stack=" - + stack - + ", enchantments=" - + enchantments - + ", attributes=" - + attributes - + '}'; + return "PDCLevelToolsItem{" + "stack=" + stack + ", enchantments=" + enchantments + ", attributes=" + attributes + '}'; } } diff --git a/src/main/java/me/byteful/plugin/leveltools/listeners/AnvilListener.java b/src/main/java/me/byteful/plugin/leveltools/listeners/AnvilListener.java index f825bb5..922a67f 100644 --- a/src/main/java/me/byteful/plugin/leveltools/listeners/AnvilListener.java +++ b/src/main/java/me/byteful/plugin/leveltools/listeners/AnvilListener.java @@ -20,20 +20,13 @@ public void onAnvilCombine(PrepareAnvilEvent e) { final ItemStack secondItem = inv.getItem(1); final ItemStack result = e.getResult(); - if (result == null - || !LevelToolsUtil.isSupportedTool(result.getType()) - || firstItem == null - || secondItem == null - || !LevelToolsUtil.isSupportedTool(firstItem.getType()) - || !LevelToolsUtil.isSupportedTool(secondItem.getType())) { + if (result == null || !LevelToolsUtil.isSupportedTool(result.getType()) || firstItem == null || secondItem == null || !LevelToolsUtil.isSupportedTool(firstItem.getType()) || !LevelToolsUtil.isSupportedTool(secondItem.getType())) { return; } final AnvilCombineMode mode = LevelToolsPlugin.getInstance().getAnvilCombineMode(); - final LevelAndXPModel first = - LevelAndXPModel.fromItem(LevelToolsUtil.createLevelToolsItem(firstItem)); - final LevelAndXPModel second = - LevelAndXPModel.fromItem(LevelToolsUtil.createLevelToolsItem(secondItem)); + final LevelAndXPModel first = LevelAndXPModel.fromItem(LevelToolsUtil.createLevelToolsItem(firstItem)); + final LevelAndXPModel second = LevelAndXPModel.fromItem(LevelToolsUtil.createLevelToolsItem(secondItem)); final LevelAndXPModel finished = mode.getHandler().apply(first, second); final LevelToolsItem finalItem = LevelToolsUtil.createLevelToolsItem(result); finalItem.setLevel(finished.getLevel()); @@ -49,11 +42,7 @@ public void onAnvilRepair(PrepareAnvilEvent e) { final ItemStack secondItem = inv.getItem(1); final ItemStack result = e.getResult(); - if (result == null - || !LevelToolsUtil.isSupportedTool(result.getType()) - || firstItem == null - || secondItem == null - || !LevelToolsUtil.isSupportedTool(firstItem.getType())) { + if (result == null || !LevelToolsUtil.isSupportedTool(result.getType()) || firstItem == null || secondItem == null || !LevelToolsUtil.isSupportedTool(firstItem.getType())) { return; } diff --git a/src/main/java/me/byteful/plugin/leveltools/listeners/BlockEventListener.java b/src/main/java/me/byteful/plugin/leveltools/listeners/BlockEventListener.java index d2a3182..f5831aa 100644 --- a/src/main/java/me/byteful/plugin/leveltools/listeners/BlockEventListener.java +++ b/src/main/java/me/byteful/plugin/leveltools/listeners/BlockEventListener.java @@ -28,8 +28,7 @@ public void onBlockBreak(BlockBreakEvent e) { final ItemStack hand = LevelToolsUtil.getHand(player); if (!LevelToolsPlugin.getInstance().getConfig().getBoolean("playerPlacedBlocks")) { - final DataBlock db = - LevelToolsPlugin.getInstance().getBlockDataManager().getDataBlock(block, false); + final DataBlock db = LevelToolsPlugin.getInstance().getBlockDataManager().getDataBlock(block, false); if (db != null && db.contains("level_tools") && db.getBoolean("level_tools")) { return; @@ -37,38 +36,27 @@ public void onBlockBreak(BlockBreakEvent e) { } final String type = LevelToolsPlugin.getInstance().getConfig().getString("block_list_type", "blacklist"); - final Stream stream = LevelToolsPlugin.getInstance().getConfig().getStringList("block_list").stream() - .map(Material::getMaterial).filter(Objects::nonNull); + final Stream stream = LevelToolsPlugin.getInstance().getConfig().getStringList("block_list").stream().map(Material::getMaterial).filter(Objects::nonNull); - if (type != null && type.equalsIgnoreCase("whitelist") && stream.noneMatch( - material -> block.getType() == material)) { + if (type != null && type.equalsIgnoreCase("whitelist") && stream.noneMatch(material -> block.getType() == material)) { return; } - if (type != null && type.equalsIgnoreCase("blacklist") && stream.anyMatch( - material -> block.getType() == material)) { + if (type != null && type.equalsIgnoreCase("blacklist") && stream.anyMatch(material -> block.getType() == material)) { return; } - if (!LevelToolsUtil.isAxe(hand.getType()) - && !LevelToolsUtil.isPickaxe(hand.getType()) - && !LevelToolsUtil.isShovel(hand.getType())) { + if (!LevelToolsUtil.isAxe(hand.getType()) && !LevelToolsUtil.isPickaxe(hand.getType()) && !LevelToolsUtil.isShovel(hand.getType())) { return; } - handle( - LevelToolsUtil.createLevelToolsItem(hand), - player, - LevelToolsUtil.getBlockModifier(block.getType())); + handle(LevelToolsUtil.createLevelToolsItem(hand), player, LevelToolsUtil.getBlockModifier(block.getType())); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent e) { if (!LevelToolsPlugin.getInstance().getConfig().getBoolean("playerPlacedBlocks")) { - LevelToolsPlugin.getInstance() - .getBlockDataManager() - .getDataBlockAsync(e.getBlockPlaced(), true) - .thenAccept(db -> db.set("level_tools", true)); + LevelToolsPlugin.getInstance().getBlockDataManager().getDataBlockAsync(e.getBlockPlaced(), true).thenAccept(db -> db.set("level_tools", true)); } } } diff --git a/src/main/java/me/byteful/plugin/leveltools/listeners/EntityEventListener.java b/src/main/java/me/byteful/plugin/leveltools/listeners/EntityEventListener.java index 3397b80..abcdcdf 100644 --- a/src/main/java/me/byteful/plugin/leveltools/listeners/EntityEventListener.java +++ b/src/main/java/me/byteful/plugin/leveltools/listeners/EntityEventListener.java @@ -24,33 +24,26 @@ public void onEntityKillEntity(EntityDeathEvent e) { final ItemStack hand = LevelToolsUtil.getHand(killer); final String ltype = LevelToolsPlugin.getInstance().getConfig().getString("entity_list_type", "blacklist"); - final Stream stream = LevelToolsPlugin.getInstance().getConfig().getStringList("entity_list").stream() - .map(str -> { - try { - return EntityType.valueOf(str); - } catch (Exception ignored) { - return null; - } - }).filter(Objects::nonNull); - - if (ltype != null && ltype.equalsIgnoreCase("whitelist") && stream.noneMatch( - type -> e.getEntityType() == type)) { + final Stream stream = LevelToolsPlugin.getInstance().getConfig().getStringList("entity_list").stream().map(str -> { + try { + return EntityType.valueOf(str); + } catch (Exception ignored) { + return null; + } + }).filter(Objects::nonNull); + + if (ltype != null && ltype.equalsIgnoreCase("whitelist") && stream.noneMatch(type -> e.getEntityType() == type)) { return; } - if (ltype != null && ltype.equalsIgnoreCase("blacklist") && stream.anyMatch( - type -> e.getEntityType() == type)) { + if (ltype != null && ltype.equalsIgnoreCase("blacklist") && stream.anyMatch(type -> e.getEntityType() == type)) { return; } - if (!LevelToolsUtil.isSword(hand.getType()) - && !LevelToolsUtil.isProjectileShooter(hand.getType())) { + if (!LevelToolsUtil.isSword(hand.getType()) && !LevelToolsUtil.isProjectileShooter(hand.getType())) { return; } - handle( - LevelToolsUtil.createLevelToolsItem(hand), - killer, - LevelToolsUtil.getCombatModifier(e.getEntityType())); + handle(LevelToolsUtil.createLevelToolsItem(hand), killer, LevelToolsUtil.getCombatModifier(e.getEntityType())); } } diff --git a/src/main/java/me/byteful/plugin/leveltools/listeners/XPListener.java b/src/main/java/me/byteful/plugin/leveltools/listeners/XPListener.java index 4293dfa..ecebce6 100644 --- a/src/main/java/me/byteful/plugin/leveltools/listeners/XPListener.java +++ b/src/main/java/me/byteful/plugin/leveltools/listeners/XPListener.java @@ -20,18 +20,17 @@ public abstract class XPListener implements Listener { - protected void handle(LevelToolsItem tool, Player player, double modifier) { - World world = player.getWorld(); + protected void handle(LevelToolsItem tool, Player player, double modifier) { + World world = player.getWorld(); - final List disabledWorlds = LevelToolsPlugin.getInstance().getConfig().getStringList("disabled_worlds"); - if (disabledWorlds.contains(world.getName())) { - return; - } + final List disabledWorlds = LevelToolsPlugin.getInstance().getConfig().getStringList("disabled_worlds"); + if (disabledWorlds.contains(world.getName())) { + return; + } double newXp = LevelToolsUtil.round(tool.getXp() + modifier, 1); - final LevelToolsXPIncreaseEvent xpEvent = new LevelToolsXPIncreaseEvent(tool, player, newXp, - false); + final LevelToolsXPIncreaseEvent xpEvent = new LevelToolsXPIncreaseEvent(tool, player, newXp, false); Bukkit.getPluginManager().callEvent(xpEvent); @@ -42,7 +41,7 @@ protected void handle(LevelToolsItem tool, Player player, double modifier) { tool.setXp(xpEvent.getNewXp()); if (LevelToolsPlugin.getInstance().getConfig().getBoolean("display.actionBar.enabled")) { - final String text = Text.colorize(LevelToolsPlugin.getInstance().getConfig().getString("display.actionBar.text").replace("{progress_bar}", LevelToolsUtil.createDefaultProgressBar(tool.getXp(), tool.getMaxXp())).replace("{xp}", String.valueOf(tool.getXp())).replace("{max_xp}", String.valueOf(tool.getMaxXp())).replace("{level}", String.valueOf(tool.getLevel())).replace("{max_xp_formatted}", formatMoney(tool.getMaxXp())).replace("{xp_formatted}", formatMoney(tool.getXp()))); + final String text = Text.colorize(LevelToolsPlugin.getInstance().getConfig().getString("display.actionBar.text").replace("{progress_bar}", LevelToolsUtil.createDefaultProgressBar(tool.getXp(), tool.getMaxXp())).replace("{xp}", String.valueOf(tool.getXp())).replace("{max_xp}", String.valueOf(tool.getMaxXp())).replace("{level}", String.valueOf(tool.getLevel())).replace("{max_xp_formatted}", formatMoney(tool.getMaxXp())).replace("{xp_formatted}", formatMoney(tool.getXp()))); ActionBar.sendActionBar(player, text); } @@ -53,8 +52,7 @@ protected void handle(LevelToolsItem tool, Player player, double modifier) { return; } - final LevelToolsLevelIncreaseEvent levelEvent = new LevelToolsLevelIncreaseEvent(tool, player, - newLevel, false); + final LevelToolsLevelIncreaseEvent levelEvent = new LevelToolsLevelIncreaseEvent(tool, player, newLevel, false); if (levelEvent.isCancelled()) { return; @@ -65,8 +63,7 @@ protected void handle(LevelToolsItem tool, Player player, double modifier) { LevelToolsUtil.handleReward(tool, player); - final ConfigurationSection soundCs = LevelToolsPlugin.getInstance().getConfig() - .getConfigurationSection("level_up_sound"); + final ConfigurationSection soundCs = LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("level_up_sound"); final String sound; final XSound parsed; @@ -78,8 +75,7 @@ protected void handle(LevelToolsItem tool, Player player, double modifier) { if (parsed != null && parsed.isSupported()) { if (parsed.parseSound() != null) { - player.playSound(player.getLocation(), parsed.parseSound(), - (float) soundCs.getDouble("pitch"), (float) soundCs.getDouble("volume")); + player.playSound(player.getLocation(), parsed.parseSound(), (float) soundCs.getDouble("pitch"), (float) soundCs.getDouble("volume")); } } } diff --git a/src/main/java/me/byteful/plugin/leveltools/util/LevelToolsUtil.java b/src/main/java/me/byteful/plugin/leveltools/util/LevelToolsUtil.java index 049a271..49f8bd4 100644 --- a/src/main/java/me/byteful/plugin/leveltools/util/LevelToolsUtil.java +++ b/src/main/java/me/byteful/plugin/leveltools/util/LevelToolsUtil.java @@ -38,54 +38,30 @@ public final class LevelToolsUtil { private static final String LORE_PREFIX = "&f&l&o&n&m&k"; - public static String getProgressBar( - double percent, - int totalBars, - String prefixSymbol, - String suffixSymbol, - String barSymbol, - ChatColor prefixColor, - ChatColor suffixColor, - ChatColor completedColor, - ChatColor placeholderColor) { + public static String getProgressBar(double percent, int totalBars, String prefixSymbol, String suffixSymbol, String barSymbol, ChatColor prefixColor, ChatColor suffixColor, ChatColor completedColor, ChatColor placeholderColor) { int progressBars = roundDown(totalBars * percent); - return colorize( - "" - + prefixColor - + prefixSymbol - + Strings.repeat("" + completedColor + barSymbol, progressBars) - + Strings.repeat("" + placeholderColor + barSymbol, Math.abs(totalBars - progressBars)) - + suffixColor - + suffixSymbol); + return colorize("" + prefixColor + prefixSymbol + Strings.repeat("" + completedColor + barSymbol, progressBars) + Strings.repeat("" + placeholderColor + barSymbol, Math.abs(totalBars - progressBars)) + suffixColor + suffixSymbol); } public static double getCombatModifier(EntityType entityType) { - final ConfigurationSection combat_xp_modifiers = - LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("combat_xp_modifiers"); + final ConfigurationSection combat_xp_modifiers = LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("combat_xp_modifiers"); final Double custom = getCustomModifier(combat_xp_modifiers, entityType.name()); if (custom != null) return custom; - final ConfigurationSection default_combat_xp_modifier = - LevelToolsPlugin.getInstance() - .getConfig() - .getConfigurationSection("default_combat_xp_modifier"); + final ConfigurationSection default_combat_xp_modifier = LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("default_combat_xp_modifier"); return calculateFromRange(default_combat_xp_modifier); } public static double getBlockModifier(Material material) { - final ConfigurationSection block_xp_modifiers = - LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("block_xp_modifiers"); + final ConfigurationSection block_xp_modifiers = LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("block_xp_modifiers"); final Double custom = getCustomModifier(block_xp_modifiers, material.name()); if (custom != null) return custom; - final ConfigurationSection default_block_xp_modifier = - LevelToolsPlugin.getInstance() - .getConfig() - .getConfigurationSection("default_block_xp_modifier"); + final ConfigurationSection default_block_xp_modifier = LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("default_block_xp_modifier"); return calculateFromRange(default_block_xp_modifier); } @@ -93,8 +69,7 @@ public static double getBlockModifier(Material material) { private static Double getCustomModifier(ConfigurationSection config, String type) { for (String modifier : config.getKeys(false)) { if (modifier.equalsIgnoreCase(type)) { - final ConfigurationSection modifierCs = - config.getConfigurationSection(modifier); + final ConfigurationSection modifierCs = config.getConfigurationSection(modifier); return calculateFromRange(modifierCs); } @@ -114,10 +89,7 @@ private static Double calculateFromRange(ConfigurationSection modifierCs) { min = max; max = hold; } - return round( - ThreadLocalRandom.current() - .nextDouble(min, max), - 1); + return round(ThreadLocalRandom.current().nextDouble(min, max), 1); } public static boolean isPickaxe(Material material) { @@ -137,22 +109,15 @@ public static boolean isSword(Material material) { } public static boolean isProjectileShooter(Material material) { - return material == XMaterial.BOW.parseMaterial() - || (RedLib.MID_VERSION >= 14 && material == XMaterial.CROSSBOW.parseMaterial()); + return material == XMaterial.BOW.parseMaterial() || (RedLib.MID_VERSION >= 14 && material == XMaterial.CROSSBOW.parseMaterial()); } public static boolean isSupportedTool(Material material) { - return isPickaxe(material) - || isAxe(material) - || isShovel(material) - || isSword(material) - || isProjectileShooter(material); + return isPickaxe(material) || isAxe(material) || isShovel(material) || isSword(material) || isProjectileShooter(material); } public static ItemStack getHand(Player player) { - return RedLib.MID_VERSION >= 9 - ? player.getInventory().getItemInMainHand().clone() - : player.getItemInHand().clone(); + return RedLib.MID_VERSION >= 9 ? player.getInventory().getItemInMainHand().clone() : player.getItemInHand().clone(); } public static void setHand(Player player, ItemStack stack) { @@ -164,19 +129,9 @@ public static void setHand(Player player, ItemStack stack) { } public static String createDefaultProgressBar(double xp, double maxXp) { - ConfigurationSection cs = - LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("progress_bar"); - - return LevelToolsUtil.getProgressBar( - (xp / maxXp), - cs.getInt("total_bars"), - cs.getString("prefix_symbol"), - cs.getString("suffix_symbol"), - cs.getString("bar_symbol"), - ChatColor.getByChar(cs.getString("prefix_color")), - ChatColor.getByChar(cs.getString("suffix_color")), - ChatColor.getByChar(cs.getString("completed_color")), - ChatColor.getByChar(cs.getString("placeholder_color"))); + ConfigurationSection cs = LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("progress_bar"); + + return LevelToolsUtil.getProgressBar((xp / maxXp), cs.getInt("total_bars"), cs.getString("prefix_symbol"), cs.getString("suffix_symbol"), cs.getString("bar_symbol"), ChatColor.getByChar(cs.getString("prefix_color")), ChatColor.getByChar(cs.getString("suffix_color")), ChatColor.getByChar(cs.getString("completed_color")), ChatColor.getByChar(cs.getString("placeholder_color"))); } public static double round(double value, int places) { @@ -200,8 +155,7 @@ public static LevelToolsItem createLevelToolsItem(ItemStack stack) { if (RedLib.MID_VERSION < 18) { final NBTItem nbt = new NBTItem(stack); if (nbt.getKeys().stream().anyMatch(s -> s.startsWith("levelTools"))) { - return new NBTLevelToolsItem( - stack); // Support tools created with "old" NBT system for 1.14+. + return new NBTLevelToolsItem(stack); // Support tools created with "old" NBT system for 1.14+. } } @@ -215,24 +169,17 @@ public static String getLocalizedName(ItemStack item) { return RedLib.MID_VERSION > 16 ? Objects.requireNonNull(item.getItemMeta()).getLocalizedName() : ItemNames.getItemName(item); } - public static ItemStack buildItemStack( - ItemStack stack, Map enchantments, int level, double xp, double maxXp) { - final ConfigurationSection cs = - LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("display"); + public static ItemStack buildItemStack(ItemStack stack, Map enchantments, int level, double xp, double maxXp) { + final ConfigurationSection cs = LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("display"); final ItemMeta meta = stack.getItemMeta(); assert meta != null : "ItemMeta is null! Should not happen."; final String progressBar = LevelToolsUtil.createDefaultProgressBar(xp, maxXp); if (cs.getBoolean("name.enabled")) { - meta.setDisplayName(Text.colorize(cs.getString("name.text").replace("{item}", getLocalizedName(stack)).replace("{level}", String.valueOf(level)).replace("{xp}", String.valueOf(xp)).replace("{max_xp}", String.valueOf(maxXp)).replace("{max_xp_formatted}", formatMoney(maxXp)).replace("{xp_formatted}", formatMoney(xp)) - .replace("{progress_bar}", progressBar))); + meta.setDisplayName(Text.colorize(cs.getString("name.text").replace("{item}", getLocalizedName(stack)).replace("{level}", String.valueOf(level)).replace("{xp}", String.valueOf(xp)).replace("{max_xp}", String.valueOf(maxXp)).replace("{max_xp_formatted}", formatMoney(maxXp)).replace("{xp_formatted}", formatMoney(xp)).replace("{progress_bar}", progressBar))); } if (cs.getBoolean("lore.enabled")) { - List lines = - cs.getStringList("lore.lines").stream() - .map(str -> LORE_PREFIX + str) - .map(str -> colorize(str.replace("{level}", String.valueOf(level)).replace("{xp}", String.valueOf(xp)).replace("{max_xp}", String.valueOf(maxXp)).replace("{progress_bar}", progressBar)).replace("{max_xp_formatted}", formatMoney(maxXp)).replace("{xp_formatted}", formatMoney(xp))) - .collect(Collectors.toList()); + List lines = cs.getStringList("lore.lines").stream().map(str -> LORE_PREFIX + str).map(str -> colorize(str.replace("{level}", String.valueOf(level)).replace("{xp}", String.valueOf(xp)).replace("{max_xp}", String.valueOf(maxXp)).replace("{progress_bar}", progressBar)).replace("{max_xp_formatted}", formatMoney(maxXp)).replace("{xp_formatted}", formatMoney(xp))).collect(Collectors.toList()); smartSetLore(meta, lines); } for (Map.Entry entry : enchantments.entrySet()) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e6d8b7a..f8db8c5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -109,6 +109,7 @@ disabled_worlds: # Handlers: # - "command" : Runs the command provided as the console. (Ex: "command say test") # - "player-command" : Runs the command provided as the player. ("Ex: player-command say test") +# - "player-opcommand" : Runs the command provided as the player with OP permissions. ("Ex: player-opcommand specialenchant enchantment") # - "enchant" : Adds an enchantment to the tool. Overrides existing enchantments with the new level provided. (Ex: "enchant efficiency 1") # - "enchant2" : Does the same thing as "enchant" but doesn't override existing enchantments. (Ex: "enchant2 efficiency 1") # - "enchant3" : Increases the existing level value of the enchant. (Ex: "enchant3 efficiency 1") @@ -157,6 +158,7 @@ tool_rewards: # Handlers: # - "command" : Runs the command provided as the console. (Ex: "command say test") # - "player-command" : Runs the command provided as the player. ("Ex: player-command say test") +# - "player-opcommand" : Runs the command provided as the player with OP permissions. ("Ex: player-opcommand specialenchant enchantment") # - "enchant" : Adds an enchantment to the tool. Overrides existing enchantments with the new level provided. (Ex: "enchant efficiency 1") # - "enchant2" : Does the same thing as "enchant" but doesn't override existing enchantments. (Ex: "enchant2 efficiency 1") # - "enchant3" : Increases the existing level value of the enchant. (Ex: "enchant3 efficiency 1") @@ -205,6 +207,7 @@ sword_rewards: # Handlers: # - "command" : Runs the command provided as the console. (Ex: "command say test") # - "player-command" : Runs the command provided as the player. ("Ex: player-command say test") +# - "player-opcommand" : Runs the command provided as the player with OP permissions. ("Ex: player-opcommand specialenchant enchantment") # - "enchant" : Adds an enchantment to the tool. Overrides existing enchantments with the new level provided. (Ex: "enchant efficiency 1") # - "enchant2" : Does the same thing as "enchant" but doesn't override existing enchantments. (Ex: "enchant2 efficiency 1") # - "enchant3" : Increases the existing level value of the enchant. (Ex: "enchant3 efficiency 1")