diff --git a/core/pom.xml b/core/pom.xml index f4a195f..9362b40 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -5,7 +5,7 @@ EpicEnchants-Parent com.songoda - 1.0.5-ALPHA + 1.0.8-ALPHA 4.0.0 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 83e76d2..1b2deb2 100644 --- a/core/src/main/java/com/songoda/epicenchants/commands/EnchantCommand.java +++ b/core/src/main/java/com/songoda/epicenchants/commands/EnchantCommand.java @@ -28,8 +28,8 @@ public class EnchantCommand extends BaseCommand { @Description("Give enchant books to players") @CommandPermission("epicenchants.give.book") public void onGiveBook(CommandSender sender, @Flags("other") Player target, Enchant enchant, @Optional Integer level, @Optional Integer successRate, @Optional Integer destroyRate) { - if (level != null && level > enchant.getMaxLevel()) { - instance.getAction().perform(sender, "command.book.max-level", + if (level != null && (level > enchant.getMaxLevel() || level < 1)) { + instance.getAction().perform(sender, "command.book." + (level > enchant.getMaxLevel() ? "max-level" : "min-level"), of("enchant", enchant.getIdentifier()), of("max-level", enchant.getMaxLevel())); return; @@ -67,6 +67,7 @@ public class EnchantCommand extends BaseCommand { target.getInventory().addItem(instance.getSpecialItems().getBlackScroll(amount, successRate)); break; default: + instance.getAction().perform(target, "command.give-unknown", of("unknown", giveType)); return; } @@ -81,8 +82,9 @@ public class EnchantCommand extends BaseCommand { @Description("Apply enchant to item in hand") @CommandPermission("epicenchants.apply") public void onApply(Player player, Enchant enchant, int level, @Optional Integer successRate, @Optional Integer destroyRate) { - if (player.getItemInHand() == null) { - instance.getAction().perform(player, "command.apply.noitem", of("enchant", enchant.getIdentifier())); + if (player.getItemInHand() == null || !enchant.getItemWhitelist().contains(player.getItemInHand().getType())) { + System.out.println("List = " + enchant.getItemWhitelist()); + instance.getAction().perform(player, "command.apply.invalid-item", of("enchant", enchant.getIdentifier())); return; } 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 fbaf268..40a0df1 100644 --- a/core/src/main/java/com/songoda/epicenchants/listeners/EntityListener.java +++ b/core/src/main/java/com/songoda/epicenchants/listeners/EntityListener.java @@ -3,10 +3,7 @@ package com.songoda.epicenchants.listeners; import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.enums.TriggerType; 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; @@ -127,7 +124,7 @@ public class EntityListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onEntityExplode(EntityExplodeEvent event) { - if (event.getEntity().getCustomName().equals("ee")) { + if (event.getEntity().getCustomName() != null && event.getEntity().getCustomName().equals("ee")) { event.blockList().clear(); } } diff --git a/core/src/main/java/com/songoda/epicenchants/managers/CommandManager.java b/core/src/main/java/com/songoda/epicenchants/managers/CommandManager.java index cde0f17..f887a21 100644 --- a/core/src/main/java/com/songoda/epicenchants/managers/CommandManager.java +++ b/core/src/main/java/com/songoda/epicenchants/managers/CommandManager.java @@ -28,7 +28,7 @@ public class CommandManager extends BukkitCommandManager { instance.getEnchantManager().getKeys().stream().map(s -> s.replaceAll("\\s", "_")).collect(Collectors.toList())); getCommandCompletions().registerCompletion("giveType", c -> - Arrays.stream(GiveType.values()).map(s -> s.toString().replace("_", "").toLowerCase()).collect(Collectors.toList())); + Arrays.stream(GiveType.values()).map(s -> s.toString().replace("_", "-").toLowerCase()).collect(Collectors.toList())); getCommandCompletions().registerCompletion("levels", c -> IntStream.rangeClosed(1, c.getContextValue(Enchant.class).getMaxLevel()).boxed().map(Objects::toString).collect(Collectors.toList())); @@ -49,7 +49,7 @@ public class CommandManager extends BukkitCommandManager { new InvalidCommandArgument("No enchant exists by that name", false))); getCommandContexts().registerContext(GiveType.class, c -> Arrays.stream(GiveType.values()) - .filter(s -> s.toString().toLowerCase().replace("_", "").equalsIgnoreCase(c.popFirstArg())) + .filter(s -> s.toString().toLowerCase().replace("_", "-").equalsIgnoreCase(c.popFirstArg())) .findFirst() .orElseThrow(() -> new InvalidCommandArgument("No item by that type.", false))); diff --git a/core/src/main/java/com/songoda/epicenchants/menus/AlchemistMenu.java b/core/src/main/java/com/songoda/epicenchants/menus/AlchemistMenu.java index 694dc21..cab4725 100644 --- a/core/src/main/java/com/songoda/epicenchants/menus/AlchemistMenu.java +++ b/core/src/main/java/com/songoda/epicenchants/menus/AlchemistMenu.java @@ -283,6 +283,6 @@ public class AlchemistMenu extends FastInv { for (Placeholder placeholder : placeholders) toTest = toTest.replace(placeholder.getPlaceholder(), placeholder.getToReplace().toString()); - return (int) GeneralUtils.parseJS(toTest, "alchemist expression", 0); + return (int) Double.parseDouble(GeneralUtils.parseJS(toTest, "alchemist expression", 0).toString()); } } \ No newline at end of file diff --git a/core/src/main/java/com/songoda/epicenchants/menus/EnchanterMenu.java b/core/src/main/java/com/songoda/epicenchants/menus/EnchanterMenu.java index 0a67d26..7cd9cda 100644 --- a/core/src/main/java/com/songoda/epicenchants/menus/EnchanterMenu.java +++ b/core/src/main/java/com/songoda/epicenchants/menus/EnchanterMenu.java @@ -8,11 +8,17 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + import static com.songoda.epicenchants.objects.Placeholder.of; import static com.songoda.epicenchants.utils.single.Experience.*; import static com.songoda.epicenchants.utils.single.GeneralUtils.*; public class EnchanterMenu extends FastInv { + private final Map DELAY = new HashMap<>(); + public EnchanterMenu(EpicEnchants instance, FileConfiguration config, Player player) { super(config.getInt("rows") * 9, color(config.getString("title"))); @@ -38,6 +44,11 @@ public class EnchanterMenu extends FastInv { of("eco_left", ecoLeft)).build(); addItem(getSlots(section.getString("slot")), itemStack, event -> { + // Todo: wanna change this + if (DELAY.getOrDefault(player.getUniqueId(), 0L) > System.currentTimeMillis()) { + return; + } + if (!instance.getEconomy().has((player), ecoCost) || getExp(player) < expCost) { instance.getAction().perform(player, "enchanter.cannot-afford"); return; @@ -52,6 +63,7 @@ public class EnchanterMenu extends FastInv { changeExp(player, -expCost); player.getInventory().addItem(instance.getSpecialItems().getMysteryBook(group)); + DELAY.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + 120); }); }); } 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 e10aca6..adb4fa7 100644 --- a/core/src/main/java/com/songoda/epicenchants/menus/InfoMenu.java +++ b/core/src/main/java/com/songoda/epicenchants/menus/InfoMenu.java @@ -6,7 +6,6 @@ import com.songoda.epicenchants.objects.Group; import com.songoda.epicenchants.utils.objects.FastInv; import com.songoda.epicenchants.utils.objects.ItemBuilder; import org.apache.commons.lang.StringUtils; -import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; import java.util.Iterator; @@ -37,9 +36,10 @@ public class InfoMenu extends FastInv { slots.stream().filter(slot -> enchantIterator.hasNext()).forEach(slot -> { Enchant enchant = enchantIterator.next(); - String whitelist = instance.getItemGroup().getGroup(enchant.getItemWhitelist()) - .map(s -> StringUtils.capitalize(s.getName().toLowerCase())) - .orElse(String.join(", ", enchant.getItemWhitelist().stream().map(Material::toString).collect(Collectors.toSet()))); + String whitelist = instance.getItemGroup().getGroups(enchant.getItemWhitelist()) + .stream() + .map(s -> StringUtils.capitalize(s.toLowerCase())) + .collect(Collectors.joining(", ")); addItem(slot, new ItemBuilder(config.getConfigurationSection("enchant-item"), of("group_color", enchant.getGroup().getColor()), diff --git a/core/src/main/java/com/songoda/epicenchants/objects/Enchant.java b/core/src/main/java/com/songoda/epicenchants/objects/Enchant.java index d7638df..55afe1b 100644 --- a/core/src/main/java/com/songoda/epicenchants/objects/Enchant.java +++ b/core/src/main/java/com/songoda/epicenchants/objects/Enchant.java @@ -25,6 +25,7 @@ public class Enchant { private Group group; private int maxLevel; private Set conflict; + //TODO: ISSUES private Set itemWhitelist; private Set effectExecutors; private List description; diff --git a/core/src/main/java/com/songoda/epicenchants/utils/EnchantUtils.java b/core/src/main/java/com/songoda/epicenchants/utils/EnchantUtils.java index 3d83250..567d82b 100644 --- a/core/src/main/java/com/songoda/epicenchants/utils/EnchantUtils.java +++ b/core/src/main/java/com/songoda/epicenchants/utils/EnchantUtils.java @@ -39,7 +39,6 @@ public class EnchantUtils { Set currentIds = currentEnchantMap.keySet().stream().map(Enchant::getIdentifier).collect(Collectors.toSet()); Set currentConflicts = currentEnchantMap.keySet().stream().map(Enchant::getConflict).flatMap(Collection::stream).collect(Collectors.toSet()); - if (enchant.getConflict().stream().anyMatch(currentIds::contains) || currentConflicts.contains(enchant.getIdentifier())) { return Pair.of(itemStack, CONFLICT); } @@ -70,7 +69,7 @@ public class EnchantUtils { itemBuilder.removeLore(instance.getSpecialItems().getWhiteScrollLore()); } - itemBuilder.removeLore(enchant.getFormat().replace("{level}", "").trim()); + itemBuilder.removeLore(enchant.getFormat(-1, instance.getFileManager().getConfiguration("config").getBoolean("roman-numbers")).replace("-1", "").trim()); itemBuilder.addLore(enchant.getFormat(level, instance.getFileManager().getConfiguration("config").getBoolean("roman-numbers"))); if (hasProtection) { diff --git a/core/src/main/java/com/songoda/epicenchants/utils/objects/FileLocation.java b/core/src/main/java/com/songoda/epicenchants/utils/objects/FileLocation.java index 2ebfc09..a6eb289 100644 --- a/core/src/main/java/com/songoda/epicenchants/utils/objects/FileLocation.java +++ b/core/src/main/java/com/songoda/epicenchants/utils/objects/FileLocation.java @@ -23,4 +23,8 @@ public class FileLocation { public String getResourcePath(String dir) { return (versionDependent ? "version-dependent/" + dir + "/" : "") + path; } + + public boolean isDirectory() { + return path.endsWith("/"); + } } diff --git a/core/src/main/java/com/songoda/epicenchants/utils/objects/ItemBuilder.java b/core/src/main/java/com/songoda/epicenchants/utils/objects/ItemBuilder.java index 18c8a1a..eb2626b 100644 --- a/core/src/main/java/com/songoda/epicenchants/utils/objects/ItemBuilder.java +++ b/core/src/main/java/com/songoda/epicenchants/utils/objects/ItemBuilder.java @@ -151,7 +151,7 @@ public class ItemBuilder { } public ItemBuilder removeLore(String string) { - if (!meta.hasLore()) { + if (meta == null || !meta.hasLore()) { return this; } diff --git a/core/src/main/java/com/songoda/epicenchants/utils/single/ItemGroup.java b/core/src/main/java/com/songoda/epicenchants/utils/single/ItemGroup.java index dd9b64a..5dd12be 100644 --- a/core/src/main/java/com/songoda/epicenchants/utils/single/ItemGroup.java +++ b/core/src/main/java/com/songoda/epicenchants/utils/single/ItemGroup.java @@ -63,10 +63,7 @@ public class ItemGroup { Optional optionalGroup = Group.from(key); Set output = new HashSet<>(); - optionalGroup.ifPresent(group -> { - output.addAll(groupMap.get(group)); - output.addAll(group.getChildren().stream().map(groupMap::get).flatMap(Collection::stream).collect(Collectors.toSet())); - }); + optionalGroup.ifPresent(group -> output.addAll(getMaterials(group))); if (Material.matchMaterial(key) != null) { output.add(Material.matchMaterial(key)); @@ -75,6 +72,20 @@ public class ItemGroup { return output; } + public Set getGroups(Set materials) { + Set groups = new HashSet<>(); + + for (int i = 0; i < 5; i++) { + getGroup(materials).ifPresent(group -> { + groups.add(group.getName()); + materials.removeAll(getMaterials(group)); + }); + } + + groups.addAll(materials.stream().map(Material::toString).collect(Collectors.toSet())); + return groups; + } + public Optional getGroup(Set materials) { Optional group = Arrays.stream(Group.values()) .filter(s -> !s.getChildren().isEmpty() && s.getChildren().stream().allMatch(child -> materials.containsAll(groupMap.get(child)))) @@ -84,7 +95,20 @@ public class ItemGroup { return group; } - return groupMap.asMap().entrySet().stream().filter(s -> s.getValue().equals(materials)).map(Map.Entry::getKey).findFirst(); + return groupMap.asMap().entrySet().stream().filter(s -> materials.containsAll(s.getValue())).map(Map.Entry::getKey).findFirst(); + } + + public Set getMaterials(Group group) { + Set out = new HashSet<>(); + + for (int i = 0; i < 5; i++) { + if (group.getChildren().isEmpty()) + out.addAll(groupMap.get(group)); + else + out.addAll(group.getChildren().stream().map(this::getMaterials).flatMap(Collection::stream).collect(Collectors.toSet())); + } + + return out; } diff --git a/core/src/main/java/com/songoda/epicenchants/utils/single/RomanNumber.java b/core/src/main/java/com/songoda/epicenchants/utils/single/RomanNumber.java index c57e5b4..58a04e9 100644 --- a/core/src/main/java/com/songoda/epicenchants/utils/single/RomanNumber.java +++ b/core/src/main/java/com/songoda/epicenchants/utils/single/RomanNumber.java @@ -3,7 +3,7 @@ package com.songoda.epicenchants.utils.single; import java.util.TreeMap; public class RomanNumber { - private final static TreeMap map = new TreeMap() {{ + private final static TreeMap TREE_MAP = new TreeMap() {{ put(1000, "M"); put(900, "CM"); put(500, "D"); @@ -17,15 +17,14 @@ public class RomanNumber { put(5, "V"); put(4, "IV"); put(1, "I"); + put(-1, "-1"); }}; public static String toRoman(int number) { - int l = map.floorKey(number); + int l = TREE_MAP.floorKey(number); if (number == l) { - return map.get(number); + return TREE_MAP.get(number); } - return map.get(l) + toRoman(number - l); - + return TREE_MAP.get(l) + toRoman(number - l); } - } diff --git a/core/src/main/resources/actions.yml b/core/src/main/resources/actions.yml index 5af110b..6f80790 100644 --- a/core/src/main/resources/actions.yml +++ b/core/src/main/resources/actions.yml @@ -6,12 +6,17 @@ command: received: "&7You have been given a &6{enchant} &7book." gave: "&7You gave {player} a &6{enchant} &7book." max-level: "&cThe max level for {enchant} is {max-level}." + min-level: "&cThe min level for {enchant} is 1." white-scroll: received: "&7You have been given a whitescroll." gave: "&7You gave {player} a whitescroll." + apply: + invalid-item: "&cYou cannot apply {enchant} to this item." + reload: "&6Configuration files reload" + give-unknown: "&cUnknown item to give: &f{unknown}." black-scroll: success: "&aSuccessfully blackscrolled: {group_color}{enchant} {level}&a." @@ -46,8 +51,9 @@ alchemist: enchants: invalid-material: "&cYou can not apply &6{enchant} &cto that item." + failure: "&6{enchant} &cfailed to apply..." broken-failure: "&6{enchant} &cfailed to apply and broke your item..." - success: "&aYou have success fully applied &6{enchant}." + success: "&aYou have successfully applied &6{enchant}." conflict: "&cYou cannot apply this enchant as it conflicts with another enchant." maxed-out: "&cYou already have that enchant maxed on this item." already-applied: "&cYou already have that enchant applied on this item." diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index d01c751..d79aa33 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -1,5 +1,3 @@ -#MASTER CONFIG - first-load: true language: "en_US" diff --git a/core/src/main/resources/enchants/example-enchant.yml b/core/src/main/resources/enchants/example-enchant.yml index 471a9d9..e7033db 100644 --- a/core/src/main/resources/enchants/example-enchant.yml +++ b/core/src/main/resources/enchants/example-enchant.yml @@ -7,7 +7,7 @@ max-level: 3 # The group of this enchant. Configure the groups in the groups.yml file. group: SIMPLE -# The item that the enchantment book is. +# The item that the enchantment book is. This will override it's group setting. book-item: material: BOOK display-name: "&b&lExampleEnchant {level}" @@ -17,14 +17,13 @@ book-item: - "&a{success_rate}% Success Rate" - "&c{destroy_rate}% Destroy Rate" -# How the enchant should be formatted on the enchanted item. +# How the enchant should be formatted on the enchanted item. This will override it's group setting. applied-format: "&cExampleEnchant {level}" # What items this enchant can be applied too. +# For a full list of item groups, please visit: https://wiki.songoda.com/display/SON/EpicEnchants item-whitelist: - - "DIAMOND_HELMET" - - "IRON_HELMET" - - "LEATHER_HELMET" + - "HELMETS" # This enchantment can not be applied if then enchantment below is already on the item. conflicting-enchants: @@ -36,13 +35,13 @@ effects: POTION-1: # The trigger that will fire this effect trigger: DEFENSE_PLAYER_MELEE - # What player should the effect be ran on: WEARER/OPPONENT. - who: WEARER + # What player should the effect be ran on: USER/OPPONENT. + who: USER # Potion Effect that should be applied. potion-type: SPEED # Duration of the Potion Effect in seconds. duration: "10 * {level}" - # Chance that the Effect gets activated. + # Chance that the effect gets activated. chance: "20 * {level}" # Amplifier of 0 = SPEED 1 a Amplifier of 1 = SPEED 2, etc. amplifier: "{level} - 1" @@ -51,17 +50,15 @@ effects: who: WEARER potion-type: INCREASE_DAMAGE amplifier: "{level} - 1" - -# Chance of spawning when damaged by another player. -mobs: - # Type of Mob - ZOMBIE: + SPAWN_MOB: + # The mob type + mob-type: CREEPER # Trigger event that spawns the mob. trigger: DEFENSE_PLAYER_MELEE # Max amount mobs that will be spawned. - max-amount: "{level}" - # Chance of trigger the mob spawning. - spawn-percentage: "20 * {level}" + amount: "{random(low=0, up={level})}" + # Chance that the effect gets activated. + chance: "20 * {level}" # Drop chance of the mob its equipment upon death. equipment-drop-chance: "10 * {level}" # Health of the mob. diff --git a/core/src/main/resources/version-dependent/legacy/items/special-items.yml b/core/src/main/resources/version-dependent/legacy/items/special-items.yml index 0e95f02..7948300 100644 --- a/core/src/main/resources/version-dependent/legacy/items/special-items.yml +++ b/core/src/main/resources/version-dependent/legacy/items/special-items.yml @@ -8,7 +8,7 @@ white-scroll: - "&ePlace scroll on item to apply." black-scroll: - material: INC_SAC + material: INC_SACK display-name: "&f&lBlack Scroll" lore: - "&7Removes a random enchantment" diff --git a/core/src/main/resources/version-dependent/legacy/menus/alchemist-menu.yml b/core/src/main/resources/version-dependent/legacy/menus/alchemist-menu.yml index 38d25b5..10b9b01 100644 --- a/core/src/main/resources/version-dependent/legacy/menus/alchemist-menu.yml +++ b/core/src/main/resources/version-dependent/legacy/menus/alchemist-menu.yml @@ -35,12 +35,17 @@ contents: data: 14 display-name: "&8[&eThe Alchemist&8]" lore: - - "&7You will exchange" + - "&7The alchemist will exchange:" - "" - "&8- &f2x enchantment books" - "&7(of the same type and level) &ffor" - "&fthe same enchantment book" - - "&7(with a higher success rate)" + - "&7(of a higher level)" + - "" + - "&8- &f2x magic dust" + - "&7(of the same rarity) &ffor" + - "&fthe same dust" + - "&7(of a higher percentage)" accept-after: material: STAINED_GLASS_PANE data: 5 diff --git a/core/src/main/resources/version-dependent/master/items/special-items.yml b/core/src/main/resources/version-dependent/master/items/special-items.yml index 5b0d15c..b0ba8ce 100644 --- a/core/src/main/resources/version-dependent/master/items/special-items.yml +++ b/core/src/main/resources/version-dependent/master/items/special-items.yml @@ -8,7 +8,7 @@ white-scroll: - "&ePlace scroll on item to apply." black-scroll: - material: INK_SACK + material: INK_SAC display-name: "&f&lBlack Scroll" lore: - "&7Removes a random enchantment" diff --git a/core/src/main/resources/version-dependent/master/menus/alchemist-menu.yml b/core/src/main/resources/version-dependent/master/menus/alchemist-menu.yml index df7c805..9de5925 100644 --- a/core/src/main/resources/version-dependent/master/menus/alchemist-menu.yml +++ b/core/src/main/resources/version-dependent/master/menus/alchemist-menu.yml @@ -33,12 +33,17 @@ contents: material: RED_STAINED_GLASS_PANE display-name: "&8[&eThe Alchemist&8]" lore: - - "&7You will exchange" + - "&7The alchemist will exchange:" - "" - "&8- &f2x enchantment books" - "&7(of the same type and level) &ffor" - "&fthe same enchantment book" - - "&7(with a higher success rate)" + - "&7(of a higher level)" + - "" + - "&8- &f2x magic dust" + - "&7(of the same rarity) &ffor" + - "&fthe same dust" + - "&7(of a higher percentage)" accept-after: material: LIME_STAINED_GLASS_PANE display-name: "&eClick to confirm" diff --git a/pom.xml b/pom.xml index c89c663..96134ec 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.songoda EpicEnchants-Parent pom - 1.0.5-ALPHA + 1.0.8-ALPHA core