From ce7ca983510ee30e4957fba86d14b852fde59367 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 28 Nov 2023 16:54:07 +0500 Subject: [PATCH] v3.6.4 --- Core/pom.xml | 12 ++-- .../excellentenchants/Placeholders.java | 2 + .../command/EnchantCommand.java | 41 ++++++++--- .../excellentenchants/config/Lang.java | 7 +- .../impl/weapon/EnchantThrifty.java | 20 ++++-- .../enchantment/util/Modifier.java | 69 +++++++++++++++++++ .../enchantment/util/ModifierAction.java | 21 ++++++ NMS/pom.xml | 2 +- V1_18_R2/pom.xml | 4 +- V1_19_R3/pom.xml | 4 +- V1_20_R1/pom.xml | 4 +- V1_20_R2/pom.xml | 4 +- pom.xml | 2 +- 13 files changed, 159 insertions(+), 33 deletions(-) create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/Modifier.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/ModifierAction.java diff --git a/Core/pom.xml b/Core/pom.xml index 7a22cea..23e546e 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.6.2 + 3.6.3 4.0.0 @@ -72,27 +72,27 @@ su.nightexpress.excellentenchants NMS - 3.6.2 + 3.6.3 su.nightexpress.excellentenchants V1_18_R2 - 3.6.2 + 3.6.3 su.nightexpress.excellentenchants V1_19_R3 - 3.6.2 + 3.6.3 su.nightexpress.excellentenchants V1_20_R1 - 3.6.2 + 3.6.3 su.nightexpress.excellentenchants V1_20_R2 - 3.6.2 + 3.6.3 diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/Placeholders.java b/Core/src/main/java/su/nightexpress/excellentenchants/Placeholders.java index 087a5b5..63095d5 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/Placeholders.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/Placeholders.java @@ -8,6 +8,8 @@ public class Placeholders extends su.nexmedia.engine.utils.Placeholders { public static final String URL_ENGINE_ITEMS = "https://github.com/nulli0n/NexEngine-spigot/wiki/Configuration-Tips#item-sections"; public static final String GENERIC_TYPE = "%type%"; + public static final String GENERIC_ITEM = "%item%"; + public static final String GENERIC_LEVEL = "%level%"; public static final String GENERIC_AMOUNT = "%amount%"; public static final String GENERIC_DESCRIPTION = "%description%"; public static final String GENERIC_ENCHANT = "%enchant%"; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/command/EnchantCommand.java b/Core/src/main/java/su/nightexpress/excellentenchants/command/EnchantCommand.java index 94ff2fb..879d3aa 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/command/EnchantCommand.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/command/EnchantCommand.java @@ -4,13 +4,17 @@ import org.bukkit.NamespacedKey; import org.bukkit.command.CommandSender; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.command.AbstractCommand; import su.nexmedia.engine.api.command.CommandResult; +import su.nexmedia.engine.lang.LangManager; +import su.nexmedia.engine.utils.*; import su.nexmedia.engine.utils.random.Rnd; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Perms; +import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.config.Lang; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; @@ -23,7 +27,6 @@ public class EnchantCommand extends AbstractCommand { super(plugin, new String[]{"enchant"}, Perms.COMMAND_ENCHANT); this.setDescription(plugin.getMessage(Lang.COMMAND_ENCHANT_DESC)); this.setUsage(plugin.getMessage(Lang.COMMAND_ENCHANT_USAGE)); - this.setPlayerOnly(true); } @Override @@ -35,6 +38,12 @@ public class EnchantCommand extends AbstractCommand { if (arg == 2) { return Arrays.asList("-1", "1", "5", "10"); } + if (arg == 3) { + return CollectionsUtil.playerNames(player); + } + if (arg == 4) { + return CollectionsUtil.getEnumsList(EquipmentSlot.class); + } return super.getTab(player, arg, args); } @@ -45,19 +54,26 @@ public class EnchantCommand extends AbstractCommand { return; } - Player player = (Player) sender; - ItemStack item = player.getInventory().getItemInMainHand(); - if (item.getType().isAir()) { - this.plugin.getMessage(Lang.COMMAND_ENCHANT_ERROR_NO_ITEM).send(sender); - return; - } - Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(result.getArg(1).toLowerCase())); if (enchantment == null) { plugin.getMessage(Lang.ERROR_NO_ENCHANT).send(sender); return; } + Player player = PlayerUtil.getPlayer(result.getArg(3, sender.getName())); + if (player == null) { + this.errorPlayer(sender); + return; + } + + EquipmentSlot slot = StringUtil.getEnum(result.getArg(4, ""), EquipmentSlot.class).orElse(EquipmentSlot.HAND); + + ItemStack item = player.getInventory().getItem(slot); + if (item == null || item.getType().isAir()) { + this.plugin.getMessage(Lang.COMMAND_ENCHANT_ERROR_NO_ITEM).send(sender); + return; + } + int level = result.getInt(2, -1); if (level < 0) { level = Rnd.get(enchantment.getStartLevel(), enchantment.getMaxLevel()); @@ -69,6 +85,13 @@ public class EnchantCommand extends AbstractCommand { else EnchantUtils.remove(item, enchantment); EnchantUtils.updateDisplay(item); - plugin.getMessage(Lang.COMMAND_ENCHANT_DONE).send(sender); + player.getInventory().setItem(slot, item); + + plugin.getMessage(sender == player ? Lang.COMMAND_ENCHANT_DONE_SELF : Lang.COMMAND_ENCHANT_DONE_OTHERS) + .replace(Placeholders.forPlayer(player)) + .replace(Placeholders.GENERIC_ITEM, ItemUtil.getItemName(item)) + .replace(Placeholders.GENERIC_ENCHANT, LangManager.getEnchantment(enchantment)) + .replace(Placeholders.GENERIC_LEVEL, NumberUtil.toRoman(level)) + .send(sender); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java b/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java index 8ec49c7..f6e7dc8 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java @@ -10,10 +10,11 @@ public class Lang extends EngineLang { public static final LangKey COMMAND_LIST_DESC = LangKey.of("Command.List.Desc", "List of all custom enchantments."); - public static final LangKey COMMAND_ENCHANT_USAGE = LangKey.of("Command.Enchant.Usage", " "); + public static final LangKey COMMAND_ENCHANT_USAGE = LangKey.of("Command.Enchant.Usage", " [player] [slot]"); public static final LangKey COMMAND_ENCHANT_DESC = LangKey.of("Command.Enchant.Desc", "Enchants the item in your hand."); - public static final LangKey COMMAND_ENCHANT_DONE = LangKey.of("Command.Enchant.Done", LIGHT_YELLOW + "Successfully enchanted!"); - public static final LangKey COMMAND_ENCHANT_ERROR_NO_ITEM = LangKey.of("Command.Enchant.Error.NoItem", RED + "You must hold an item to enchant it!"); + public static final LangKey COMMAND_ENCHANT_DONE_SELF = LangKey.of("Command.Enchant.Done.Self", ORANGE + GENERIC_ITEM + LIGHT_YELLOW + " enchanted with " + GENERIC_ENCHANT + " " + GENERIC_LEVEL + LIGHT_YELLOW + "!"); + public static final LangKey COMMAND_ENCHANT_DONE_OTHERS = LangKey.of("Command.Enchant.Done.Others", ORANGE + PLAYER_NAME + LIGHT_YELLOW + "'s " + ORANGE + GENERIC_ITEM + LIGHT_YELLOW + " enchanted with " + GENERIC_ENCHANT + " " + GENERIC_LEVEL + LIGHT_YELLOW + "!"); + public static final LangKey COMMAND_ENCHANT_ERROR_NO_ITEM = LangKey.of("Command.Enchant.Error.NoItem", RED + "There is no item to enchant!"); public static final LangKey COMMAND_BOOK_USAGE = LangKey.of("Command.Book.Usage", " "); public static final LangKey COMMAND_BOOK_DESC = LangKey.of("Command.Book.Desc", "Gives custom enchanted book."); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java index 247ba4c..5db0914 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java @@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; import su.nexmedia.engine.api.manager.EventListener; +import su.nexmedia.engine.utils.EngineUtils; import su.nexmedia.engine.utils.PDCUtil; import su.nexmedia.engine.utils.StringUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; @@ -21,6 +22,8 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; +import su.nightexpress.excellentenchants.hook.HookId; +import su.nightexpress.excellentenchants.hook.impl.MythicMobsHook; import java.util.Objects; import java.util.Set; @@ -30,9 +33,11 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn public static final String ID = "thrifty"; + private final NamespacedKey keyEntityIgnored; + private Set ignoredEntityTypes; private Set ignoredSpawnReasons; - private final NamespacedKey keyEntityIgnored; + private boolean ignoreMythicMobs; private ChanceImplementation chanceImplementation; @@ -54,8 +59,8 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn this.ignoredEntityTypes = JOption.create("Settings.Ignored_Entity_Types", Set.of(EntityType.WITHER.name(), EntityType.ENDER_DRAGON.name()), "List of entity types, that will not drop spawn eggs.", - "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html") - .read(cfg).stream().map(e -> StringUtil.getEnum(e, EntityType.class).orElse(null)) + "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html" + ).read(cfg).stream().map(e -> StringUtil.getEnum(e, EntityType.class).orElse(null)) .filter(Objects::nonNull).collect(Collectors.toSet()); this.ignoredSpawnReasons = JOption.create("Settings.Ignored_Spawn_Reasons", @@ -63,9 +68,13 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn CreatureSpawnEvent.SpawnReason.SPAWNER.name(), CreatureSpawnEvent.SpawnReason.DISPENSE_EGG.name()), "Entities will not drop spawn eggs if they were spawned by one of the reasons below.", - "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/entity/CreatureSpawnEvent.SpawnReason.html") - .read(cfg).stream().map(e -> StringUtil.getEnum(e, CreatureSpawnEvent.SpawnReason.class).orElse(null)) + "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/entity/CreatureSpawnEvent.SpawnReason.html" + ).read(cfg).stream().map(e -> StringUtil.getEnum(e, CreatureSpawnEvent.SpawnReason.class).orElse(null)) .filter(Objects::nonNull).collect(Collectors.toSet()); + + this.ignoreMythicMobs = JOption.create("Settings.Ignore_MythicMobs", true, + "Sets whether or not MythicMobs should be immune to enchantment effect." + ).read(cfg); } @NotNull @@ -84,6 +93,7 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) { if (this.ignoredEntityTypes.contains(entity.getType())) return false; if (PDCUtil.getBoolean(entity, this.keyEntityIgnored).orElse(false)) return false; + if (this.ignoreMythicMobs && EngineUtils.hasPlugin(HookId.MYTHIC_MOBS) && MythicMobsHook.isMythicMob(entity)) return false; if (!this.checkTriggerChance(level)) return false; ItemStack eggItem = plugin.getEnchantNMS().getSpawnEgg(entity); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/Modifier.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/Modifier.java new file mode 100644 index 0000000..5353180 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/Modifier.java @@ -0,0 +1,69 @@ +package su.nightexpress.excellentenchants.enchantment.util; + +import org.jetbrains.annotations.NotNull; +import su.nexmedia.engine.api.config.JOption; +import su.nexmedia.engine.api.config.JYML; + +public class Modifier { + + private final double base; + private final double perLevel; + private final ModifierAction action; + + public Modifier(double base, double perLevel, @NotNull ModifierAction action) { + this.base = base; + this.perLevel = perLevel; + this.action = action; + } + + @NotNull + public static Modifier add(double base, double perLevel) { + return new Modifier(base, perLevel, ModifierAction.ADD); + } + + @NotNull + public static Modifier multiply(double base, double perLevel) { + return new Modifier(base, perLevel, ModifierAction.MULTIPLY); + } + + @NotNull + public static Modifier read(@NotNull JYML cfg, @NotNull String path, @NotNull Modifier def, @NotNull String... comments) { + return new JOption<>(path, + (cfg2, path2, def2) -> read(cfg2, path2), + def, + comments + ).setWriter((cfg2, path2, mod) -> mod.write(cfg2, path2)).read(cfg); + } + + @NotNull + public static Modifier read(@NotNull JYML cfg, @NotNull String path) { + double base = JOption.create(path + ".Base", 0D).read(cfg); + double perLevel = JOption.create(path + ".Per_Level", 0D).read(cfg); + ModifierAction action = JOption.create(path + ".Action", ModifierAction.class, ModifierAction.ADD).read(cfg); + + return new Modifier(base, perLevel, action); + } + + public void write(@NotNull JYML cfg, @NotNull String path) { + cfg.set(path + ".Base", this.getBase()); + cfg.set(path + ".Per_Level", this.getPerLevel()); + cfg.set(path + ".Action", this.getAction().name()); + } + + public double getValue(int level) { + return this.action.math(this.getBase(), this.getPerLevel() * level); + } + + public double getBase() { + return base; + } + + public double getPerLevel() { + return perLevel; + } + + @NotNull + public ModifierAction getAction() { + return action; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/ModifierAction.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/ModifierAction.java new file mode 100644 index 0000000..06b719d --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/ModifierAction.java @@ -0,0 +1,21 @@ +package su.nightexpress.excellentenchants.enchantment.util; + +import org.jetbrains.annotations.NotNull; + +import java.util.function.BiFunction; + +public enum ModifierAction { + + ADD(Double::sum), + MULTIPLY((origin, target) -> origin * target); + + private final BiFunction function; + + ModifierAction(@NotNull BiFunction function) { + this.function = function; + } + + public double math(double origin, double target) { + return this.function.apply(origin, target); + } +} diff --git a/NMS/pom.xml b/NMS/pom.xml index 9bf13cf..d4be4ab 100644 --- a/NMS/pom.xml +++ b/NMS/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.6.2 + 3.6.3 4.0.0 diff --git a/V1_18_R2/pom.xml b/V1_18_R2/pom.xml index c94731d..c3cf53a 100644 --- a/V1_18_R2/pom.xml +++ b/V1_18_R2/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.6.2 + 3.6.3 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.6.2 + 3.6.3 diff --git a/V1_19_R3/pom.xml b/V1_19_R3/pom.xml index bbc2704..6a56530 100644 --- a/V1_19_R3/pom.xml +++ b/V1_19_R3/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.6.2 + 3.6.3 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.6.2 + 3.6.3 diff --git a/V1_20_R1/pom.xml b/V1_20_R1/pom.xml index 276ae4c..b578b14 100644 --- a/V1_20_R1/pom.xml +++ b/V1_20_R1/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.6.2 + 3.6.3 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.6.2 + 3.6.3 diff --git a/V1_20_R2/pom.xml b/V1_20_R2/pom.xml index a6f89c4..62dcce1 100644 --- a/V1_20_R2/pom.xml +++ b/V1_20_R2/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.6.2 + 3.6.3 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.6.2 + 3.6.3 diff --git a/pom.xml b/pom.xml index 576e24a..f61087e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ su.nightexpress.excellentenchants ExcellentEnchants pom - 3.6.2 + 3.6.3 Core NMS