From eff885270e15f864f82f337788e4aed59f4ddca5 Mon Sep 17 00:00:00 2001 From: GB6 Date: Fri, 8 Feb 2019 13:08:13 +0100 Subject: [PATCH] More bug fixes --- core/pom.xml | 2 +- .../com/songoda/epicenchants/EpicEnchants.java | 17 +++-------------- .../epicenchants/commands/EnchantCommand.java | 14 ++++++++++---- .../epicenchants/effect/EffectManager.java | 5 ++--- .../effect/effects/CancelEvent.java | 6 ++---- .../epicenchants/effect/effects/Message.java | 2 +- .../epicenchants/effect/effects/ModifyExp.java | 5 ++--- .../effect/effects/ModifyHealth.java | 2 ++ .../epicenchants/listeners/BookListener.java | 9 +++++++-- .../epicenchants/listeners/EntityListener.java | 14 ++++---------- .../songoda/epicenchants/menus/InfoMenu.java | 3 +-- .../epicenchants/menus/MainInfoMenu.java | 3 +-- .../epicenchants/utils/VersionDependent.java | 4 ++-- core/src/main/resources/en_US.lang | 14 ++++++-------- .../main/resources/enchants/example-enchant.yml | 2 +- .../src/main/resources/menus/main-info-menu.yml | 15 +++++---------- 16 files changed, 50 insertions(+), 67 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 6eee0a0..e080165 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -77,7 +77,7 @@ org.projectlombok lombok - 1.18.4 + 1.18.2 diff --git a/core/src/main/java/com/songoda/epicenchants/EpicEnchants.java b/core/src/main/java/com/songoda/epicenchants/EpicEnchants.java index 379a2bc..898fa8e 100644 --- a/core/src/main/java/com/songoda/epicenchants/EpicEnchants.java +++ b/core/src/main/java/com/songoda/epicenchants/EpicEnchants.java @@ -5,15 +5,9 @@ import co.aikar.commands.InvalidCommandArgument; import com.songoda.epicenchants.commands.EnchantCommand; import com.songoda.epicenchants.enums.GiveType; import com.songoda.epicenchants.listeners.*; -import com.songoda.epicenchants.managers.EnchantManager; -import com.songoda.epicenchants.managers.FileManager; -import com.songoda.epicenchants.managers.GroupManager; -import com.songoda.epicenchants.managers.InfoManager; +import com.songoda.epicenchants.managers.*; import com.songoda.epicenchants.objects.Enchant; -import com.songoda.epicenchants.utils.EnchantUtils; -import com.songoda.epicenchants.utils.FastInv; -import com.songoda.epicenchants.utils.SpecialItems; -import com.songoda.epicenchants.utils.VersionDependent; +import com.songoda.epicenchants.utils.*; import lombok.Getter; import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; @@ -117,12 +111,7 @@ public class EpicEnchants extends JavaPlugin { private void setupVersion() { int currentVersion = Integer.parseInt(getServer().getClass().getPackage().getName().split("\\.")[3].split("_")[1]); - - if (currentVersion >= 13) { - VersionDependent.initDefault(currentVersion); - } else { - VersionDependent.initLegacy(currentVersion); - } + VersionDependent.initLegacy(currentVersion); } public void reload() { diff --git a/core/src/main/java/com/songoda/epicenchants/commands/EnchantCommand.java b/core/src/main/java/com/songoda/epicenchants/commands/EnchantCommand.java index af39a46..ef5c86d 100644 --- a/core/src/main/java/com/songoda/epicenchants/commands/EnchantCommand.java +++ b/core/src/main/java/com/songoda/epicenchants/commands/EnchantCommand.java @@ -33,10 +33,16 @@ public class EnchantCommand extends BaseCommand { //ee give book {player} {enchant} {group} @Subcommand("give book") - @CommandCompletion("@giveType @players @enchants @nothing @nothing @nothing") + @CommandCompletion("@players @enchants @nothing @nothing @nothing") @Description("Give enchant books to players") @CommandPermission("epicenchants.give") - public void onGive(CommandSender sender, @Flags("other") Player target, Enchant enchant, @Optional Integer level, @Optional Integer successRate, @Optional Integer destroyRate) { + public void onGiveBook(CommandSender sender, @Flags("other") Player target, Enchant enchant, @Optional Integer level, @Optional Integer successRate, @Optional Integer destroyRate) { + if (level > enchant.getMaxLevel()) { + sender.sendMessage(instance.getLocale().getMessageWithPrefix("command.book.maxlevel", + of("enchant", enchant.getIdentifier()), + of("max-level", enchant.getMaxLevel()))); + return; + } target.getInventory().addItem(enchant.getBookItem().get(enchant, level, successRate, destroyRate)); target.sendMessage(instance.getLocale().getMessageWithPrefix("command.book.received", of("enchant", enchant.getIdentifier()))); sender.sendMessage(instance.getLocale().getMessageWithPrefix("command.book.gave", of("player", target.getName()), of("enchant", enchant.getIdentifier()))); @@ -44,10 +50,10 @@ public class EnchantCommand extends BaseCommand { //ee give item {player} {giveType} {group} @Subcommand("give item") - @CommandCompletion("@giveType @players @enchants @nothing @nothing @nothing") + @CommandCompletion("@players @giveType @nothing @nothing") @Description("Give enchant books to players") @CommandPermission("epicenchants.give") - public void onGive(CommandSender sender, @Flags("other") Player target, String giveType, @Optional Integer amount, @Optional Integer successRate) { + public void onGiveItem(CommandSender sender, @Flags("other") Player target, String giveType, @Optional Integer amount, @Optional Integer successRate) { String messageKey; switch (giveType.toLowerCase()) { diff --git a/core/src/main/java/com/songoda/epicenchants/effect/EffectManager.java b/core/src/main/java/com/songoda/epicenchants/effect/EffectManager.java index 61473f7..f94688f 100644 --- a/core/src/main/java/com/songoda/epicenchants/effect/EffectManager.java +++ b/core/src/main/java/com/songoda/epicenchants/effect/EffectManager.java @@ -7,8 +7,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Optional; -import static com.google.common.base.CaseFormat.UPPER_CAMEL; -import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; +import static com.google.common.base.CaseFormat.*; public class EffectManager { @@ -24,7 +23,7 @@ public class EffectManager { Object object = constructor.newInstance(section); return Optional.of((EffectExecutor) object); } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassCastException e) { - Bukkit.getLogger().severe("Invalid effect:" + section.getName()); + Bukkit.getLogger().severe("Invalid effect: " + section.getName()); } return Optional.empty(); diff --git a/core/src/main/java/com/songoda/epicenchants/effect/effects/CancelEvent.java b/core/src/main/java/com/songoda/epicenchants/effect/effects/CancelEvent.java index a0e0459..a1dee92 100644 --- a/core/src/main/java/com/songoda/epicenchants/effect/effects/CancelEvent.java +++ b/core/src/main/java/com/songoda/epicenchants/effect/effects/CancelEvent.java @@ -15,10 +15,8 @@ public class CancelEvent extends EffectEventExecutor { @Override public void execute(Player player, LivingEntity opponent, int level, Event event, EventType eventType) { - if (!(event instanceof Cancellable)) { - return; + if (event instanceof Cancellable) { + ((Cancellable) event).setCancelled(true); } - - ((Cancellable) event).setCancelled(true); } } diff --git a/core/src/main/java/com/songoda/epicenchants/effect/effects/Message.java b/core/src/main/java/com/songoda/epicenchants/effect/effects/Message.java index 2105ba3..9bd505a 100644 --- a/core/src/main/java/com/songoda/epicenchants/effect/effects/Message.java +++ b/core/src/main/java/com/songoda/epicenchants/effect/effects/Message.java @@ -20,6 +20,6 @@ public class Message extends EffectExecutor { consume(entity -> entity.sendMessage(color(getSection().getString("message")) .replace("{level}", "" + level) .replace("{wearer}", wearer.getName()) - .replace("{opponent}", opponent.getName())), wearer, opponent); + .replace("{opponent}", opponent == null ? "" : opponent.getName())), wearer, opponent); } } diff --git a/core/src/main/java/com/songoda/epicenchants/effect/effects/ModifyExp.java b/core/src/main/java/com/songoda/epicenchants/effect/effects/ModifyExp.java index 0eb29ee..e13e069 100644 --- a/core/src/main/java/com/songoda/epicenchants/effect/effects/ModifyExp.java +++ b/core/src/main/java/com/songoda/epicenchants/effect/effects/ModifyExp.java @@ -1,7 +1,6 @@ package com.songoda.epicenchants.effect.effects; import com.songoda.epicenchants.effect.EffectExecutor; -import com.songoda.epicenchants.enums.EffectType; import com.songoda.epicenchants.enums.EventType; import com.songoda.epicenchants.utils.Experience; import org.bukkit.configuration.ConfigurationSection; @@ -11,8 +10,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class ModifyExp extends EffectExecutor { - public ModifyExp(ConfigurationSection section, EffectType... allowedEffects) { - super(section, allowedEffects); + public ModifyExp(ConfigurationSection section) { + super(section); } @Override diff --git a/core/src/main/java/com/songoda/epicenchants/effect/effects/ModifyHealth.java b/core/src/main/java/com/songoda/epicenchants/effect/effects/ModifyHealth.java index 3d8214c..94ed309 100644 --- a/core/src/main/java/com/songoda/epicenchants/effect/effects/ModifyHealth.java +++ b/core/src/main/java/com/songoda/epicenchants/effect/effects/ModifyHealth.java @@ -19,6 +19,8 @@ public class ModifyHealth extends EffectExecutor { double amount = getAmount().get(level, 0); if (entity.getHealth() + amount > entity.getMaxHealth()) { entity.setHealth(entity.getMaxHealth()); + } else if (entity.getHealth() + amount < 0) { + entity.setHealth(0); } else { entity.setHealth(entity.getHealth() + amount); } diff --git a/core/src/main/java/com/songoda/epicenchants/listeners/BookListener.java b/core/src/main/java/com/songoda/epicenchants/listeners/BookListener.java index ab467c5..1877cdd 100644 --- a/core/src/main/java/com/songoda/epicenchants/listeners/BookListener.java +++ b/core/src/main/java/com/songoda/epicenchants/listeners/BookListener.java @@ -15,6 +15,7 @@ import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; import static com.songoda.epicenchants.enums.EnchantResult.*; import static com.songoda.epicenchants.objects.Placeholder.of; @@ -32,9 +33,13 @@ public class BookListener implements Listener { return; } - NBTItem nbtItem = new NBTItem(event.getCursor()); + @Nullable NBTItem nbtItem = new NBTItem(event.getCursor()); ItemStack toApplyTo = event.getCurrentItem(); + if (nbtItem == null) { + return; + } + if (!nbtItem.getBoolean("book-item")) { return; } @@ -67,7 +72,7 @@ public class BookListener implements Listener { event.getClickedInventory().clear(event.getSlot()); } - if (result.getRight() != CONFLICT && result.getRight() != MAXED_OUT) { + if (result.getRight() != CONFLICT && result.getRight() != MAXED_OUT && result.getRight() != ALREADY_APPLIED) { if (event.getCursor().getAmount() > 1) { ItemStack toSet = event.getCursor(); toSet.setAmount(toSet.getAmount() - 1); diff --git a/core/src/main/java/com/songoda/epicenchants/listeners/EntityListener.java b/core/src/main/java/com/songoda/epicenchants/listeners/EntityListener.java index 5b12341..1f4f936 100644 --- a/core/src/main/java/com/songoda/epicenchants/listeners/EntityListener.java +++ b/core/src/main/java/com/songoda/epicenchants/listeners/EntityListener.java @@ -3,17 +3,11 @@ package com.songoda.epicenchants.listeners; import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.enums.EffectType; import de.tr7zw.itemnbtapi.NBTEntity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Monster; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityTargetLivingEntityEvent; +import org.bukkit.event.entity.*; import org.bukkit.projectiles.ProjectileSource; import static com.songoda.epicenchants.enums.EffectType.*; @@ -66,7 +60,7 @@ public class EntityListener implements Listener { if (event.getDamager() instanceof Player) { opponent = ((LivingEntity) event.getDamager()); effectType = DEFENSE_PLAYER_MELEE; - } else if (event.getDamager() instanceof Monster) { + } else if (event.getDamager() instanceof LivingEntity && !(event.getDamager() instanceof Player)) { opponent = ((LivingEntity) event.getDamager()); effectType = DEFENSE_MOB_MELEE; } @@ -83,7 +77,7 @@ public class EntityListener implements Listener { if (event.getEntity() instanceof Player) { effectType = ATTACK_PLAYER_MELEE; - } else if (event.getEntity() instanceof Monster) { + } else if (event.getEntity() instanceof LivingEntity) { effectType = ATTACK_MOB_MELEE; } diff --git a/core/src/main/java/com/songoda/epicenchants/menus/InfoMenu.java b/core/src/main/java/com/songoda/epicenchants/menus/InfoMenu.java index 23ba742..977ad91 100644 --- a/core/src/main/java/com/songoda/epicenchants/menus/InfoMenu.java +++ b/core/src/main/java/com/songoda/epicenchants/menus/InfoMenu.java @@ -14,7 +14,6 @@ import java.util.stream.Collectors; import static com.songoda.epicenchants.objects.Placeholder.of; import static com.songoda.epicenchants.utils.GeneralUtils.color; -import static com.songoda.epicenchants.utils.GeneralUtils.getSlot; import static java.util.Arrays.stream; public class InfoMenu extends FastInv { @@ -43,6 +42,6 @@ public class InfoMenu extends FastInv { .stream() .map(s -> "contents." + s) .map(config::getConfigurationSection) - .forEach(section -> addItem(getSlot(section.getInt("row"), section.getInt("column")), new ItemBuilder(section).build())); + .forEach(section -> addItem(section.getInt("slot"), new ItemBuilder(section).build())); } } diff --git a/core/src/main/java/com/songoda/epicenchants/menus/MainInfoMenu.java b/core/src/main/java/com/songoda/epicenchants/menus/MainInfoMenu.java index ce5b1c2..7bab700 100644 --- a/core/src/main/java/com/songoda/epicenchants/menus/MainInfoMenu.java +++ b/core/src/main/java/com/songoda/epicenchants/menus/MainInfoMenu.java @@ -3,7 +3,6 @@ package com.songoda.epicenchants.menus; import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.objects.Group; import com.songoda.epicenchants.utils.FastInv; -import com.songoda.epicenchants.utils.GeneralUtils; import com.songoda.epicenchants.utils.ItemBuilder; import org.bukkit.configuration.file.FileConfiguration; @@ -18,7 +17,7 @@ public class MainInfoMenu extends FastInv { .map(s -> "contents." + s) .map(config::getConfigurationSection) .forEach(section -> { - addItem(GeneralUtils.getSlot(section.getInt("row"), section.getInt("column")), new ItemBuilder(section).build(), event -> { + addItem(section.getInt("slot"), new ItemBuilder(section).build(), event -> { Group group = instance.getGroupManager().getGroup(section.getString("group")) .orElseThrow(() -> new IllegalArgumentException("Invalid group: " + section.getString("group"))); instance.getInfoManager().getMenu(group).ifPresent(menu -> menu.open(event.getPlayer())); diff --git a/core/src/main/java/com/songoda/epicenchants/utils/VersionDependent.java b/core/src/main/java/com/songoda/epicenchants/utils/VersionDependent.java index 3747f09..819bc1d 100644 --- a/core/src/main/java/com/songoda/epicenchants/utils/VersionDependent.java +++ b/core/src/main/java/com/songoda/epicenchants/utils/VersionDependent.java @@ -67,7 +67,7 @@ public class VersionDependent { }; } - public static void initDefault(int serverVersion) { + /*public static void initDefault(int serverVersion) { version = serverVersion; blacklist = new HashSet() { { @@ -167,7 +167,7 @@ public class VersionDependent { add(valueOf("YELLOW_SHULKER_BOX")); } }; - } + }*/ public static Set getBlackList() { return blacklist; diff --git a/core/src/main/resources/en_US.lang b/core/src/main/resources/en_US.lang index ca9bcb9..9b8865c 100644 --- a/core/src/main/resources/en_US.lang +++ b/core/src/main/resources/en_US.lang @@ -1,11 +1,10 @@ -#General Messages - +#General general.nametag.prefix= "&8[&6EpicEnchants&8]" -#Command Messages - +#Command command.book.received= "&7You have been given a &6{enchant} &7book." command.book.gave= "&7You gave {player} a &6{enchant} &7book." +command.book.maxlevel= "&cThe max level for {enchant} is {max-level}." command.whitescroll;.received= "&7You have been given a whitescroll." command.whitescroll.gave= "&7You gave {player} a whitescroll." @@ -17,14 +16,13 @@ command.reload= "&6Configuration files reload" command.filereload.success= "&6{file-name} has been successfully reloaded." command.filereload.failed= "&c{file-name} failed to be reloaded. &7Please check console for errors." -#Event Messages - +#Event event.general.nopermission= "&cYou do not have permission to do that." event.purchase.noenchant= "&cThere is no enchant available for &6{group-name}&7." event.purchase.cannotafford= "&cYou cannot afford this purchase." event.purchase.success= "&7You successfully purchased a &6{group-name} &7Book." -#Enchant Messages +#Enchant enchant.invalidmaterial= "&cYou can not apply &6{enchant} &cto that item." enchant.failure= "&cYou failed to apply &6{enchant}." enchant.brokenfailure= "&6{enchant} &cfailed to apply and broke your item..." @@ -33,7 +31,7 @@ enchant.conflict= "&cYou cannot apply this enchant as it conflicts with another enchant.maxedout= "&cYou already have that enchant maxed on this item." enchant.alreadyapplied= "&cYou already have that enchant with that level applied on this item." -#Item Messages +#Item whitescroll.applied="&aThis item is now protected." whitescroll.alreadyapplied= "&cThis item is already protected." blackscroll.success= "&aYou have successfully extracted an enchant from this item." diff --git a/core/src/main/resources/enchants/example-enchant.yml b/core/src/main/resources/enchants/example-enchant.yml index d71290e..fdc8fc1 100644 --- a/core/src/main/resources/enchants/example-enchant.yml +++ b/core/src/main/resources/enchants/example-enchant.yml @@ -9,7 +9,7 @@ group: SIMPLE # The item that the enchantment book is. book-item: - material: STONE + material: BOOK display-name: "&b&lExampleEnchant {level}" # The lore on the enchantments books. lore: diff --git a/core/src/main/resources/menus/main-info-menu.yml b/core/src/main/resources/menus/main-info-menu.yml index 338cbcb..0f12cc6 100644 --- a/core/src/main/resources/menus/main-info-menu.yml +++ b/core/src/main/resources/menus/main-info-menu.yml @@ -6,29 +6,24 @@ contents: material: "PAPER" display-name: "&f&lSimple Enchantments" group: SIMPLE - row: 1 - column: 1 + slot: 0 2: material: "PAPER" display-name: "&a&lUnique Enchantments" group: UNIQUE - row: 1 - column: 2 + slot: 1 3: material: "PAPER" display-name: "&b&lElite Enchantments" group: ELITE - row: 1 - column: 3 + slot: 2 4: material: "PAPER" display-name: "&e&lUltimate Enchantments" group: ULTIMATE - row: 1 - column: 4 + slot: 3 5: material: "PAPER" display-name: "&6&lLegendary Enchantments" group: LEGENDARY - row: 1 - column: 5 + slot: 4