This commit is contained in:
BuildTools 2023-11-28 16:54:07 +05:00
parent 962dc81bec
commit ce7ca98351
13 changed files with 159 additions and 33 deletions

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.6.2</version> <version>3.6.3</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -72,27 +72,27 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.6.2</version> <version>3.6.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_18_R2</artifactId> <artifactId>V1_18_R2</artifactId>
<version>3.6.2</version> <version>3.6.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R3</artifactId> <artifactId>V1_19_R3</artifactId>
<version>3.6.2</version> <version>3.6.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R1</artifactId> <artifactId>V1_20_R1</artifactId>
<version>3.6.2</version> <version>3.6.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R2</artifactId> <artifactId>V1_20_R2</artifactId>
<version>3.6.2</version> <version>3.6.3</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -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 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_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_AMOUNT = "%amount%";
public static final String GENERIC_DESCRIPTION = "%description%"; public static final String GENERIC_DESCRIPTION = "%description%";
public static final String GENERIC_ENCHANT = "%enchant%"; public static final String GENERIC_ENCHANT = "%enchant%";

View File

@ -4,13 +4,17 @@ import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.command.AbstractCommand; import su.nexmedia.engine.api.command.AbstractCommand;
import su.nexmedia.engine.api.command.CommandResult; 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.nexmedia.engine.utils.random.Rnd;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Perms; import su.nightexpress.excellentenchants.Perms;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.config.Lang; import su.nightexpress.excellentenchants.config.Lang;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
@ -23,7 +27,6 @@ public class EnchantCommand extends AbstractCommand<ExcellentEnchants> {
super(plugin, new String[]{"enchant"}, Perms.COMMAND_ENCHANT); super(plugin, new String[]{"enchant"}, Perms.COMMAND_ENCHANT);
this.setDescription(plugin.getMessage(Lang.COMMAND_ENCHANT_DESC)); this.setDescription(plugin.getMessage(Lang.COMMAND_ENCHANT_DESC));
this.setUsage(plugin.getMessage(Lang.COMMAND_ENCHANT_USAGE)); this.setUsage(plugin.getMessage(Lang.COMMAND_ENCHANT_USAGE));
this.setPlayerOnly(true);
} }
@Override @Override
@ -35,6 +38,12 @@ public class EnchantCommand extends AbstractCommand<ExcellentEnchants> {
if (arg == 2) { if (arg == 2) {
return Arrays.asList("-1", "1", "5", "10"); 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); return super.getTab(player, arg, args);
} }
@ -45,19 +54,26 @@ public class EnchantCommand extends AbstractCommand<ExcellentEnchants> {
return; 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())); Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(result.getArg(1).toLowerCase()));
if (enchantment == null) { if (enchantment == null) {
plugin.getMessage(Lang.ERROR_NO_ENCHANT).send(sender); plugin.getMessage(Lang.ERROR_NO_ENCHANT).send(sender);
return; 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); int level = result.getInt(2, -1);
if (level < 0) { if (level < 0) {
level = Rnd.get(enchantment.getStartLevel(), enchantment.getMaxLevel()); level = Rnd.get(enchantment.getStartLevel(), enchantment.getMaxLevel());
@ -69,6 +85,13 @@ public class EnchantCommand extends AbstractCommand<ExcellentEnchants> {
else EnchantUtils.remove(item, enchantment); else EnchantUtils.remove(item, enchantment);
EnchantUtils.updateDisplay(item); 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);
} }
} }

View File

@ -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_LIST_DESC = LangKey.of("Command.List.Desc", "List of all custom enchantments.");
public static final LangKey COMMAND_ENCHANT_USAGE = LangKey.of("Command.Enchant.Usage", "<enchant> <level>"); public static final LangKey COMMAND_ENCHANT_USAGE = LangKey.of("Command.Enchant.Usage", "<enchant> <level> [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_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_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_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_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", "<player> <enchant> <level>"); public static final LangKey COMMAND_BOOK_USAGE = LangKey.of("Command.Book.Usage", "<player> <enchant> <level>");
public static final LangKey COMMAND_BOOK_DESC = LangKey.of("Command.Book.Desc", "Gives custom enchanted book."); public static final LangKey COMMAND_BOOK_DESC = LangKey.of("Command.Book.Desc", "Gives custom enchanted book.");

View File

@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption; import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.api.manager.EventListener; import su.nexmedia.engine.api.manager.EventListener;
import su.nexmedia.engine.utils.EngineUtils;
import su.nexmedia.engine.utils.PDCUtil; import su.nexmedia.engine.utils.PDCUtil;
import su.nexmedia.engine.utils.StringUtil; import su.nexmedia.engine.utils.StringUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; 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.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; 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.Objects;
import java.util.Set; import java.util.Set;
@ -30,9 +33,11 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn
public static final String ID = "thrifty"; public static final String ID = "thrifty";
private final NamespacedKey keyEntityIgnored;
private Set<EntityType> ignoredEntityTypes; private Set<EntityType> ignoredEntityTypes;
private Set<CreatureSpawnEvent.SpawnReason> ignoredSpawnReasons; private Set<CreatureSpawnEvent.SpawnReason> ignoredSpawnReasons;
private final NamespacedKey keyEntityIgnored; private boolean ignoreMythicMobs;
private ChanceImplementation chanceImplementation; private ChanceImplementation chanceImplementation;
@ -54,8 +59,8 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn
this.ignoredEntityTypes = JOption.create("Settings.Ignored_Entity_Types", this.ignoredEntityTypes = JOption.create("Settings.Ignored_Entity_Types",
Set.of(EntityType.WITHER.name(), EntityType.ENDER_DRAGON.name()), Set.of(EntityType.WITHER.name(), EntityType.ENDER_DRAGON.name()),
"List of entity types, that will not drop spawn eggs.", "List of entity types, that will not drop spawn eggs.",
"https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html") "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html"
.read(cfg).stream().map(e -> StringUtil.getEnum(e, EntityType.class).orElse(null)) ).read(cfg).stream().map(e -> StringUtil.getEnum(e, EntityType.class).orElse(null))
.filter(Objects::nonNull).collect(Collectors.toSet()); .filter(Objects::nonNull).collect(Collectors.toSet());
this.ignoredSpawnReasons = JOption.create("Settings.Ignored_Spawn_Reasons", 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.SPAWNER.name(),
CreatureSpawnEvent.SpawnReason.DISPENSE_EGG.name()), CreatureSpawnEvent.SpawnReason.DISPENSE_EGG.name()),
"Entities will not drop spawn eggs if they were spawned by one of the reasons below.", "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") "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)) ).read(cfg).stream().map(e -> StringUtil.getEnum(e, CreatureSpawnEvent.SpawnReason.class).orElse(null))
.filter(Objects::nonNull).collect(Collectors.toSet()); .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 @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) { 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 (this.ignoredEntityTypes.contains(entity.getType())) return false;
if (PDCUtil.getBoolean(entity, this.keyEntityIgnored).orElse(false)) 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; if (!this.checkTriggerChance(level)) return false;
ItemStack eggItem = plugin.getEnchantNMS().getSpawnEgg(entity); ItemStack eggItem = plugin.getEnchantNMS().getSpawnEgg(entity);

View File

@ -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;
}
}

View File

@ -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<Double, Double, Double> function;
ModifierAction(@NotNull BiFunction<Double, Double, Double> function) {
this.function = function;
}
public double math(double origin, double target) {
return this.function.apply(origin, target);
}
}

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.6.2</version> <version>3.6.3</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.6.2</version> <version>3.6.3</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.6.2</version> <version>3.6.3</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.6.2</version> <version>3.6.3</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.6.2</version> <version>3.6.3</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.6.2</version> <version>3.6.3</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.6.2</version> <version>3.6.3</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.6.2</version> <version>3.6.3</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.6.2</version> <version>3.6.3</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -7,7 +7,7 @@
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>3.6.2</version> <version>3.6.3</version>
<modules> <modules>
<module>Core</module> <module>Core</module>
<module>NMS</module> <module>NMS</module>