diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java index 836a518..8175610 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java @@ -9,11 +9,11 @@ import com.willfp.ecoarmor.config.EcoArmorYml; import com.willfp.ecoarmor.display.ArmorDisplay; import com.willfp.ecoarmor.sets.ArmorSets; import com.willfp.ecoarmor.sets.util.ArmorUtils; -import com.willfp.ecoarmor.sets.util.EffectiveDurabilityListener; -import com.willfp.ecoarmor.sets.util.PreventSkullPlaceListener; +import com.willfp.ecoarmor.sets.EffectiveDurabilityListener; +import com.willfp.ecoarmor.sets.PreventSkullPlaceListener; import com.willfp.ecoarmor.upgrades.Tiers; -import com.willfp.ecoarmor.upgrades.listeners.AdvancementShardListener; -import com.willfp.ecoarmor.upgrades.listeners.CrystalListener; +import com.willfp.ecoarmor.upgrades.AdvancementShardListener; +import com.willfp.ecoarmor.upgrades.CrystalListener; import com.willfp.ecoarmor.util.DiscoverRecipeListener; import com.willfp.ecoarmor.util.EffectListener; import com.willfp.libreforge.Holder; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java index bdc5371..4b3c4a5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java @@ -8,7 +8,6 @@ import com.willfp.eco.core.items.Items; import com.willfp.eco.core.items.builder.ItemBuilder; import com.willfp.eco.core.items.builder.ItemStackBuilder; import com.willfp.eco.core.recipe.Recipes; -import com.willfp.ecoarmor.sets.meta.ArmorSlot; import com.willfp.ecoarmor.sets.util.ArmorUtils; import com.willfp.ecoarmor.upgrades.Tier; import com.willfp.ecoarmor.upgrades.Tiers; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/meta/ArmorSlot.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/meta/ArmorSlot.java deleted file mode 100644 index 16e0bff..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/meta/ArmorSlot.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.willfp.ecoarmor.sets.meta; - -import lombok.Getter; -import org.bukkit.Material; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public enum ArmorSlot { - /** - * Helmet. - */ - HELMET(EquipmentSlot.HEAD), - - /** - * Chestplate. - */ - CHESTPLATE(EquipmentSlot.CHEST), - - /** - * Elytra. - */ - ELYTRA(EquipmentSlot.CHEST), - - /** - * Leggings. - */ - LEGGINGS(EquipmentSlot.LEGS), - - /** - * Boots. - */ - BOOTS(EquipmentSlot.FEET); - - /** - * The equipment slot. - */ - @Getter - private final EquipmentSlot slot; - - ArmorSlot(@NotNull final EquipmentSlot slot) { - this.slot = slot; - } - - /** - * Get ArmorSlot from item. - * - * @param itemStack The item. - * @return The slot, or null. - */ - @Nullable - public static ArmorSlot getSlot(@Nullable final ItemStack itemStack) { - if (itemStack == null) { - return null; - } - - Material material = itemStack.getType(); - String[] split = material.name().toLowerCase().split("_"); - String name = split[split.length - 1]; - - return switch (name) { - case "helmet", "head" -> HELMET; - case "chestplate" -> CHESTPLATE; - case "elytra" -> ELYTRA; - case "leggings" -> LEGGINGS; - case "boots" -> BOOTS; - default -> null; - }; - } - - /** - * Get ArmorSlot from name. - * - * @param name The name. - * @return The slot, or null. - */ - @Nullable - public static ArmorSlot getSlot(@NotNull final String name) { - return switch (name.toLowerCase()) { - case "helmet" -> HELMET; - case "chestplate" -> CHESTPLATE; - case "elytra" -> ELYTRA; - case "leggings" -> LEGGINGS; - case "boots" -> BOOTS; - default -> null; - }; - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java index a3b3f6a..b5cc47c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java @@ -3,7 +3,7 @@ package com.willfp.ecoarmor.sets.util; import com.willfp.ecoarmor.EcoArmorPlugin; import com.willfp.ecoarmor.sets.ArmorSet; import com.willfp.ecoarmor.sets.ArmorSets; -import com.willfp.ecoarmor.sets.meta.ArmorSlot; +import com.willfp.ecoarmor.sets.ArmorSlot; import com.willfp.ecoarmor.upgrades.Tier; import com.willfp.ecoarmor.upgrades.Tiers; import com.willfp.libreforge.Holder; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/Tier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/Tier.java index 614b6e7..b436826 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/Tier.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/Tier.java @@ -8,7 +8,7 @@ import com.willfp.eco.core.items.CustomItem; import com.willfp.eco.core.items.Items; import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe; import com.willfp.eco.util.StringUtils; -import com.willfp.ecoarmor.sets.meta.ArmorSlot; +import com.willfp.ecoarmor.sets.ArmorSlot; import com.willfp.ecoarmor.sets.util.ArmorUtils; import lombok.AccessLevel; import lombok.Getter; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/util/DiscoverRecipeListener.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/util/DiscoverRecipeListener.java deleted file mode 100644 index a3a6923..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/util/DiscoverRecipeListener.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.willfp.ecoarmor.util; - -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.PluginDependent; -import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.inventory.ShapedRecipe; -import org.jetbrains.annotations.NotNull; - -public class DiscoverRecipeListener extends PluginDependent implements Listener { - /** - * Register listener. - * - * @param plugin Talismans. - */ - public DiscoverRecipeListener(@NotNull final EcoPlugin plugin) { - super(plugin); - } - - /** - * Unlock all recipes on player join. - * - * @param event The event to listen for. - */ - @EventHandler - public void onJoin(@NotNull final PlayerJoinEvent event) { - Player player = event.getPlayer(); - - if (this.getPlugin().getConfigYml().getBool("discover-recipes")) { - Bukkit.getServer().recipeIterator().forEachRemaining(recipe -> { - if (recipe instanceof ShapedRecipe) { - NamespacedKey key = ((ShapedRecipe) recipe).getKey(); - if (key.getNamespace().equals("ecoarmor")) { - if (!key.getKey().contains("displayed")) { - player.discoverRecipe(key); - } - } - } - }); - } - } -} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandEcoarmor.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandEcoarmor.kt index 361c50b..a869f4b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandEcoarmor.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandEcoarmor.kt @@ -1,28 +1,20 @@ -package com.willfp.ecoarmor.commands; +package com.willfp.ecoarmor.commands +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.CommandHandler +import com.willfp.eco.core.command.impl.PluginCommand -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.command.CommandHandler; -import com.willfp.eco.core.command.impl.PluginCommand; -import org.jetbrains.annotations.NotNull; - -public class CommandEcoarmor extends PluginCommand { - /** - * Instantiate a new command handler. - * - * @param plugin The plugin for the commands to listen for. - */ - public CommandEcoarmor(@NotNull final EcoPlugin plugin) { - super(plugin, "ecoarmor", "ecoarmor.command.ecoarmor", false); - - this.addSubcommand(new CommandReload(plugin)) - .addSubcommand(new CommandGive(plugin)); +class CommandEcoarmor(plugin: EcoPlugin) : PluginCommand(plugin, "ecoarmor", "ecoarmor.command.ecoarmor", false) { + init { + addSubcommand(CommandReload(plugin)) + .addSubcommand(CommandGive(plugin)) } - @Override - public CommandHandler getHandler() { - return (sender, args) -> { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-command")); - }; + override fun getHandler(): CommandHandler { + return CommandHandler { sender, _ -> + sender.sendMessage( + plugin.langYml.getMessage("invalid-command") + ) + } } -} +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandGive.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandGive.kt index 040ebaf..555ae04 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandGive.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandGive.kt @@ -1,298 +1,223 @@ -package com.willfp.ecoarmor.commands; +package com.willfp.ecoarmor.commands -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.command.CommandHandler; -import com.willfp.eco.core.command.TabCompleteHandler; -import com.willfp.eco.core.command.impl.Subcommand; -import com.willfp.eco.core.config.updating.ConfigUpdater; -import com.willfp.ecoarmor.sets.ArmorSet; -import com.willfp.ecoarmor.sets.ArmorSets; -import com.willfp.ecoarmor.sets.meta.ArmorSlot; -import com.willfp.ecoarmor.sets.util.ArmorUtils; -import com.willfp.ecoarmor.upgrades.Tier; -import com.willfp.ecoarmor.upgrades.Tiers; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.StringUtil; -import org.jetbrains.annotations.NotNull; +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.CommandHandler +import com.willfp.eco.core.command.TabCompleteHandler +import com.willfp.eco.core.command.impl.Subcommand +import com.willfp.ecoarmor.sets.ArmorSets +import com.willfp.ecoarmor.sets.ArmorSlot +import com.willfp.ecoarmor.sets.ArmorSlot.Companion.getSlot +import com.willfp.ecoarmor.sets.util.ArmorUtils +import com.willfp.ecoarmor.upgrades.Tier +import com.willfp.ecoarmor.upgrades.Tiers +import org.bukkit.Bukkit +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import org.bukkit.util.StringUtil +import java.util.stream.Collectors -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; +class CommandGive(plugin: EcoPlugin) : Subcommand(plugin, "give", "ecoarmor.command.give", false) { + private val items: Collection + get() = ArmorSets.values().map { "set:${it.id}" } union ArmorSets.values() + .map { "shard:${it.id}" } union Tiers.values().map { "crystal:${it.id}" } -public class CommandGive extends Subcommand { - /** - * The cached names. - */ - private static final List ITEM_NAMES = new ArrayList<>(); + private val slots: Collection + get() = ArmorSlot.values().map { it.name.lowercase() }.toMutableList().apply { add("full") } - /** - * The cached slots. - */ - private static final List SLOTS = new ArrayList<>(); + private val tiers: Collection + get() = Tiers.values().map { it.id } - /** - * The cached tiers. - */ - private static final List TIERS = new ArrayList<>(); - - /** - * The cached numbers. - */ - private static final List NUMBERS = Arrays.asList( - "1", - "2", - "3", - "4", - "5", - "10", - "32", - "64" - ); - - /** - * Instantiate a new /eagive command handler. - * - * @param plugin The plugin for the commands to listen for. - */ - public CommandGive(@NotNull final EcoPlugin plugin) { - super(plugin, "give", "ecoarmor.command.give", false); - reload(); - } - - /** - * Called on reload. - */ - @ConfigUpdater - public static void reload() { - ITEM_NAMES.clear(); - ITEM_NAMES.addAll(ArmorSets.values().stream().map(armorSet -> "set:" + armorSet.getId()).collect(Collectors.toList())); - ITEM_NAMES.addAll(ArmorSets.values().stream().map(armorSet -> "shard:" + armorSet.getId()).collect(Collectors.toList())); - ITEM_NAMES.addAll(Tiers.values().stream().map(crystal -> "crystal:" + crystal.getId()).collect(Collectors.toList())); - SLOTS.addAll(Arrays.stream(ArmorSlot.values()).map(slot -> slot.name().toLowerCase()).collect(Collectors.toList())); - SLOTS.add("full"); - TIERS.addAll(Tiers.values().stream().map(Tier::getId).collect(Collectors.toList())); - } - - @Override - public CommandHandler getHandler() { - return (sender, args) -> { + private val numbers = listOf( + "1", + "2", + "3", + "4", + "5", + "10", + "32", + "64" + ) + override fun getHandler(): CommandHandler { + return CommandHandler { sender: CommandSender, args: List -> if (args.isEmpty()) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player")); - return; + sender.sendMessage(plugin.langYml.getMessage("needs-player")) + return@CommandHandler } - if (args.size() == 1) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-item")); - return; + if (args.size == 1) { + sender.sendMessage(plugin.langYml.getMessage("needs-item")) + return@CommandHandler } - String recieverName = args.get(0); - Player reciever = Bukkit.getPlayer(recieverName); + val recieverName = args[0] + val reciever = Bukkit.getPlayer(recieverName) if (reciever == null) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player")); - return; + sender.sendMessage(plugin.langYml.getMessage("invalid-player")) + return@CommandHandler } - String fullItemKey = args.get(1); + val fullItemKey = args[1] if (!fullItemKey.contains(":")) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item")); - return; + sender.sendMessage(plugin.langYml.getMessage("invalid-item")) + return@CommandHandler } - String[] fullItemSplit = fullItemKey.split(":"); - if (fullItemSplit.length == 1) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item")); - return; + + val fullItemSplit = fullItemKey.split(":").toTypedArray() + + if (fullItemSplit.size == 1) { + sender.sendMessage(plugin.langYml.getMessage("invalid-item")) + return@CommandHandler } - String itemNamespace = fullItemSplit[0]; - String itemKey = fullItemSplit[1]; - List items = new ArrayList<>(); - int amount = 1; + val itemNamespace = fullItemSplit[0] + val itemKey = fullItemSplit[1] + val toGive = mutableListOf() + var amount = 1 + + if (itemNamespace.equals("set", ignoreCase = true)) { + val set = ArmorSets.getByID(itemKey) - if (itemNamespace.equalsIgnoreCase("set")) { - ArmorSet set = ArmorSets.getByID(itemKey); if (set == null) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item")); - return; + sender.sendMessage(plugin.langYml.getMessage("invalid-item")) + return@CommandHandler } - String message = this.getPlugin().getLangYml().getMessage("give-success"); - message = message.replace("%item%", set.getId() + " Set").replace("%recipient%", reciever.getName()); - sender.sendMessage(message); + var message = plugin.langYml.getMessage("give-success") - boolean advanced = false; + message = message.replace("%item%", set.id + " Set").replace("%recipient%", reciever.name) - Tier tier = null; - - List slots = new ArrayList<>(); - - if (args.size() >= 3) { - ArmorSlot slot = ArmorSlot.getSlot(args.get(2)); + sender.sendMessage(message) + var advanced = false + var tier: Tier? = null + val slots = mutableListOf() + if (args.size >= 3) { + val slot = getSlot(args[2]) if (slot == null) { - if (!args.get(2).equalsIgnoreCase("full")) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item")); - return; + if (!args[2].equals("full", ignoreCase = true)) { + sender.sendMessage(plugin.langYml.getMessage("invalid-item")) + return@CommandHandler } } - if (slot == null) { - slots.addAll(Arrays.asList(ArmorSlot.values())); + slots.addAll(ArmorSlot.values()) } else { - slots.add(slot); + slots.add(slot) } } else { - slots.addAll(Arrays.asList(ArmorSlot.values())); + slots.addAll(ArmorSlot.values()) } - - if (args.size() >= 4) { - advanced = Boolean.parseBoolean(args.get(3)); + if (args.size >= 4) { + advanced = args[3].toBoolean() } - - if (args.size() >= 5) { - tier = Tiers.getByID(args.get(4)); + if (args.size >= 5) { + tier = Tiers.getByID(args[4]) } - - if (args.size() >= 6) { - try { - amount = Integer.parseInt(args.get(5)); - } catch (NumberFormatException ignored) { - // do nothing - } + if (args.size >= 6) { + amount = args[5].toIntOrNull() ?: amount } - - for (ArmorSlot slot : slots) { - items.add(advanced ? set.getAdvancedItemStack(slot) : set.getItemStack(slot)); + for (slot in slots) { + toGive.add(if (advanced) set.getAdvancedItemStack(slot) else set.getItemStack(slot)) } - - for (ItemStack item : new ArrayList<>(items)) { - Tier currTear = tier != null ? tier: set.getDefaultTier(ArmorSlot.getSlot(item)); - items.remove(item); - ArmorUtils.setTier(item, currTear); - items.add(item); + for (item in ArrayList(toGive)) { + val currTear = tier ?: set.getDefaultTier(getSlot(item)) + toGive.remove(item) + ArmorUtils.setTier(item, currTear) + toGive.add(item) } } - - if (itemNamespace.equalsIgnoreCase("crystal")) { - Tier tier = Tiers.getByID(itemKey); + if (itemNamespace.equals("crystal", ignoreCase = true)) { + val tier = Tiers.getByID(itemKey) if (tier == null) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item")); - return; + sender.sendMessage(plugin.langYml.getMessage("invalid-item")) + return@CommandHandler } - - String message = this.getPlugin().getLangYml().getMessage("give-success"); - message = message.replace("%item%", tier.getCrystal().getItemMeta().getDisplayName()).replace("%recipient%", reciever.getName()); - sender.sendMessage(message); - items.add(tier.getCrystal()); - - if (args.size() >= 3) { - try { - amount = Integer.parseInt(args.get(2)); - } catch (NumberFormatException ignored) { - // do nothing - } + var message = plugin.langYml.getMessage("give-success") + message = + message.replace("%item%", tier.crystal.itemMeta!!.displayName).replace("%recipient%", reciever.name) + sender.sendMessage(message) + toGive.add(tier.crystal) + if (args.size >= 3) { + amount = args[2].toIntOrNull() ?: amount } } - - if (itemNamespace.equalsIgnoreCase("shard")) { - ArmorSet set = ArmorSets.getByID(itemKey); + if (itemNamespace.equals("shard", ignoreCase = true)) { + val set = ArmorSets.getByID(itemKey) if (set == null) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item")); - return; + sender.sendMessage(plugin.langYml.getMessage("invalid-item")) + return@CommandHandler } - - String message = this.getPlugin().getLangYml().getMessage("give-success"); - message = message.replace("%item%", set.getAdvancementShardItem().getItemMeta().getDisplayName()).replace("%recipient%", reciever.getName()); - sender.sendMessage(message); - items.add(set.getAdvancementShardItem()); - - if (args.size() >= 3) { - try { - amount = Integer.parseInt(args.get(2)); - } catch (NumberFormatException ignored) { - // do nothing - } + var message = plugin.langYml.getMessage("give-success") + message = message.replace("%item%", set.advancementShardItem.itemMeta!!.displayName) + .replace("%recipient%", reciever.name) + sender.sendMessage(message) + toGive.add(set.advancementShardItem) + if (args.size >= 3) { + amount = args[2].toIntOrNull() ?: amount } } - - if (items.isEmpty()) { - sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item")); - return; + if (toGive.isEmpty()) { + sender.sendMessage(plugin.langYml.getMessage("invalid-item")) + return@CommandHandler } - - for (ItemStack item : items) { - item.setAmount(amount); - reciever.getInventory().addItem(item); + for (item in toGive) { + item.amount = amount + reciever.inventory.addItem(item) } - }; + } } - @Override - public TabCompleteHandler getTabCompleter() { - return (sender, args) -> { - - List completions = new ArrayList<>(); - + override fun getTabCompleter(): TabCompleteHandler { + return TabCompleteHandler { _, args -> + val completions = mutableListOf() if (args.isEmpty()) { // Currently, this case is not ever reached - return ITEM_NAMES; + return@TabCompleteHandler items.toList() } - - if (args.size() == 1) { - StringUtil.copyPartialMatches(args.get(0), Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()), completions); - return completions; + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Bukkit.getOnlinePlayers().stream().map { obj: Player -> obj.name } + .collect(Collectors.toList()), + completions) + return@TabCompleteHandler completions } - - if (args.size() == 2) { - StringUtil.copyPartialMatches(args.get(1), ITEM_NAMES, completions); - - Collections.sort(completions); - return completions; + if (args.size == 2) { + StringUtil.copyPartialMatches(args[1], items, completions) + completions.sort() + return@TabCompleteHandler completions } - - if (args.get(1).startsWith("set:")) { - if (args.size() == 3) { - StringUtil.copyPartialMatches(args.get(2), SLOTS, completions); - - Collections.sort(completions); - return completions; + if (args[1].startsWith("set:")) { + if (args.size == 3) { + StringUtil.copyPartialMatches(args[2], slots, completions) + completions.sort() + return@TabCompleteHandler completions } - - if (args.size() == 4) { - StringUtil.copyPartialMatches(args.get(3), Arrays.asList("true", "false"), completions); - - Collections.sort(completions); - return completions; + if (args.size == 4) { + StringUtil.copyPartialMatches(args[3], listOf("true", "false"), completions) + completions.sort() + return@TabCompleteHandler completions } - - if (args.size() == 5) { - StringUtil.copyPartialMatches(args.get(4), TIERS, completions); - - Collections.sort(completions); - return completions; + if (args.size == 5) { + StringUtil.copyPartialMatches(args[4], tiers, completions) + completions.sort() + return@TabCompleteHandler completions } - - if (args.size() == 6) { - StringUtil.copyPartialMatches(args.get(5), NUMBERS, completions); - - return completions; + if (args.size == 6) { + StringUtil.copyPartialMatches(args[5], numbers, completions) + return@TabCompleteHandler completions } } else { - if (args.size() == 3) { - StringUtil.copyPartialMatches(args.get(2), NUMBERS, completions); - - return completions; + if (args.size == 3) { + StringUtil.copyPartialMatches(args[2], numbers, completions) + return@TabCompleteHandler completions } } - - return new ArrayList<>(0); - }; + ArrayList(0) + } } -} +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandReload.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandReload.kt index 8ce3885..9a015be 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandReload.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/commands/CommandReload.kt @@ -1,26 +1,14 @@ -package com.willfp.ecoarmor.commands; +package com.willfp.ecoarmor.commands +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.CommandHandler +import com.willfp.eco.core.command.impl.Subcommand -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.command.CommandHandler; -import com.willfp.eco.core.command.impl.Subcommand; -import org.jetbrains.annotations.NotNull; - -public class CommandReload extends Subcommand { - /** - * Instantiate a new command handler. - * - * @param plugin The plugin for the commands to listen for. - */ - public CommandReload(@NotNull final EcoPlugin plugin) { - super(plugin, "reload", "ecoarmor.command.reload", false); +class CommandReload(plugin: EcoPlugin) : Subcommand(plugin, "reload", "ecoarmor.command.reload", false) { + override fun getHandler(): CommandHandler { + return CommandHandler { sender, _ -> + plugin.reload() + sender.sendMessage(plugin.langYml.getMessage("reloaded")) + } } - - @Override - public CommandHandler getHandler() { - return (sender, args) -> { - this.getPlugin().reload(); - sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded")); - }; - } -} +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/display/ArmorDisplay.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/display/ArmorDisplay.kt index 6fec552..687f4d5 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/display/ArmorDisplay.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/display/ArmorDisplay.kt @@ -4,7 +4,7 @@ import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.display.DisplayModule import com.willfp.eco.core.display.DisplayPriority import com.willfp.eco.core.fast.FastItemStack -import com.willfp.ecoarmor.sets.meta.ArmorSlot +import com.willfp.ecoarmor.sets.ArmorSlot import com.willfp.ecoarmor.sets.util.ArmorUtils import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.LeatherArmorMeta diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorSlot.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorSlot.kt new file mode 100644 index 0000000..b251cab --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/ArmorSlot.kt @@ -0,0 +1,47 @@ +package com.willfp.ecoarmor.sets + +import org.bukkit.inventory.EquipmentSlot +import org.bukkit.inventory.ItemStack +import java.util.* + +enum class ArmorSlot( + val slot: EquipmentSlot +) { + HELMET(EquipmentSlot.HEAD), + CHESTPLATE(EquipmentSlot.CHEST), + ELYTRA(EquipmentSlot.CHEST), + LEGGINGS(EquipmentSlot.LEGS), + BOOTS(EquipmentSlot.FEET); + + companion object { + @JvmStatic + fun getSlot(itemStack: ItemStack?): ArmorSlot? { + if (itemStack == null) { + return null + } + val material = itemStack.type + val split = material.name.lowercase(Locale.getDefault()).split("_").toTypedArray() + val name = split[split.size - 1] + return when (name) { + "helmet", "head" -> HELMET + "chestplate" -> CHESTPLATE + "elytra" -> ELYTRA + "leggings" -> LEGGINGS + "boots" -> BOOTS + else -> null + } + } + + @JvmStatic + fun getSlot(name: String): ArmorSlot? { + return when (name.lowercase(Locale.getDefault())) { + "helmet" -> HELMET + "chestplate" -> CHESTPLATE + "elytra" -> ELYTRA + "leggings" -> LEGGINGS + "boots" -> BOOTS + else -> null + } + } + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/EffectiveDurabilityListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/EffectiveDurabilityListener.kt index 0e662cd..42039b3 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/EffectiveDurabilityListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/EffectiveDurabilityListener.kt @@ -1,57 +1,26 @@ -package com.willfp.ecoarmor.sets.util; +package com.willfp.ecoarmor.sets -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.PluginDependent; -import com.willfp.eco.util.NumberUtils; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerItemDamageEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; -import org.jetbrains.annotations.NotNull; +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.util.NumberUtils +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerItemDamageEvent +import org.bukkit.persistence.PersistentDataType -public class EffectiveDurabilityListener extends PluginDependent implements Listener { - /** - * Create new effective durability listeners. - * - * @param plugin The plugin. - */ - public EffectiveDurabilityListener(@NotNull final EcoPlugin plugin) { - super(plugin); - } - - /** - * Make durability act as effective. - * - * @param event The event to listen for. - */ +class EffectiveDurabilityListener(private val plugin: EcoPlugin) : Listener { @EventHandler - public void listener(@NotNull final PlayerItemDamageEvent event) { - ItemStack itemStack = event.getItem(); - ItemMeta meta = itemStack.getItemMeta(); - - if (meta == null) { - return; - } - - PersistentDataContainer container = meta.getPersistentDataContainer(); - - Integer effectiveDurability = container.get(this.getPlugin().getNamespacedKeyFactory().create("effective-durability"), PersistentDataType.INTEGER); - - if (effectiveDurability == null) { - return; - } - - int maxDurability = itemStack.getType().getMaxDurability(); - - double ratio = (double) effectiveDurability / maxDurability; - - double chance = 1 / ratio; - - if (NumberUtils.randFloat(0, 1) > chance) { - event.setCancelled(true); + fun listener(event: PlayerItemDamageEvent) { + val itemStack = event.item + val meta = itemStack.itemMeta ?: return + val container = meta.persistentDataContainer + val effectiveDurability = + container.get(plugin.namespacedKeyFactory.create("effective-durability"), PersistentDataType.INTEGER) + ?: return + val maxDurability = itemStack.type.maxDurability.toInt() + val ratio = effectiveDurability.toDouble() / maxDurability + val chance = 1 / ratio + if (NumberUtils.randFloat(0.0, 1.0) > chance) { + event.isCancelled = true } } -} +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/PreventSkullPlaceListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/PreventSkullPlaceListener.kt index 5a7e7e1..70aeb30 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/PreventSkullPlaceListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/sets/PreventSkullPlaceListener.kt @@ -1,21 +1,16 @@ -package com.willfp.ecoarmor.sets.util; +package com.willfp.ecoarmor.sets -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPlaceEvent; -import org.jetbrains.annotations.NotNull; +import com.willfp.ecoarmor.sets.util.ArmorUtils +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockPlaceEvent -public class PreventSkullPlaceListener implements Listener { - /** - * Prevents placing skulls. - * - * @param event The event to listen for. - */ +class PreventSkullPlaceListener : Listener { @EventHandler(priority = EventPriority.HIGHEST) - public void onPlace(@NotNull final BlockPlaceEvent event) { - if (ArmorUtils.getSetOnItem(event.getItemInHand()) != null) { - event.setCancelled(true); + fun onPlace(event: BlockPlaceEvent) { + if (ArmorUtils.getSetOnItem(event.itemInHand) != null) { + event.isCancelled = true } } -} +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/AdvancementShardListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/AdvancementShardListener.kt index 48b0680..80a4156 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/AdvancementShardListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/AdvancementShardListener.kt @@ -1,87 +1,55 @@ -package com.willfp.ecoarmor.upgrades.listeners; +package com.willfp.ecoarmor.upgrades +import com.willfp.eco.core.EcoPlugin +import com.willfp.ecoarmor.sets.ArmorSets +import com.willfp.ecoarmor.sets.util.ArmorUtils +import org.bukkit.GameMode +import org.bukkit.Material +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.persistence.PersistentDataType -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.PluginDependent; -import com.willfp.ecoarmor.sets.ArmorSet; -import com.willfp.ecoarmor.sets.ArmorSets; -import com.willfp.ecoarmor.sets.util.ArmorUtils; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataType; -import org.jetbrains.annotations.NotNull; - -public class AdvancementShardListener extends PluginDependent implements Listener { - /** - * Create new listeners for dragging crystals onto items. - * - * @param plugin The plugin to listen for. - */ - public AdvancementShardListener(@NotNull final EcoPlugin plugin) { - super(plugin); - } - - /** - * Listen for inventory click event. - * - * @param event The event to handle. - */ +class AdvancementShardListener(private val plugin: EcoPlugin) : Listener { @EventHandler - public void onDrag(@NotNull final InventoryClickEvent event) { - if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE) { - return; + fun onDrag(event: InventoryClickEvent) { + if (event.whoClicked.gameMode == GameMode.CREATIVE) { + return + } + val current = event.currentItem ?: return + val cursor = event.cursor ?: return + + val cursorMeta = cursor.itemMeta ?: return + + val shardSet = cursorMeta.persistentDataContainer.get( + plugin.namespacedKeyFactory.create("advancement-shard"), + PersistentDataType.STRING + ) ?: return + + val set = ArmorUtils.getSetOnItem(current) ?: return + + if (ArmorSets.getByID(shardSet)?.id != set.id) { + return } - ItemStack current = event.getCurrentItem(); - ItemStack cursor = event.getCursor(); - - if (current == null || cursor == null) { - return; - } - - ItemMeta cursorMeta = cursor.getItemMeta(); - - if (cursorMeta == null) { - return; - } - - String shardSet = cursorMeta.getPersistentDataContainer().get(this.getPlugin().getNamespacedKeyFactory().create("advancement-shard"), PersistentDataType.STRING); - - if (shardSet == null) { - return; - } - - ArmorSet set = ArmorUtils.getSetOnItem(current); - - if (set == null) { - return; - } - - if (!ArmorSets.getByID(shardSet).getId().equals(set.getId())) { - return; - } - - if (current.getType() == Material.AIR) { - return; + if (current.type == Material.AIR) { + return } if (ArmorUtils.isAdvanced(current)) { - return; + return } - ArmorUtils.setAdvanced(current, true); + ArmorUtils.setAdvanced(current, true) - if (cursor.getAmount() > 1) { - cursor.setAmount(cursor.getAmount() - 1); - event.getWhoClicked().setItemOnCursor(cursor); + if (cursor.amount > 1) { + cursor.amount -= 1 + event.whoClicked.setItemOnCursor(cursor) } else { - event.getWhoClicked().setItemOnCursor(new ItemStack(Material.AIR)); + event.whoClicked.setItemOnCursor(ItemStack(Material.AIR)) } - event.setCancelled(true); + + event.isCancelled = true } -} +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/CrystalListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/CrystalListener.kt index 3719bcb..f19799a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/CrystalListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/upgrades/CrystalListener.kt @@ -1,97 +1,57 @@ -package com.willfp.ecoarmor.upgrades.listeners; +package com.willfp.ecoarmor.upgrades -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.PluginDependent; -import com.willfp.ecoarmor.sets.util.ArmorUtils; -import com.willfp.ecoarmor.upgrades.Tier; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; +import com.willfp.eco.core.EcoPlugin +import com.willfp.ecoarmor.sets.util.ArmorUtils +import org.bukkit.GameMode +import org.bukkit.Material +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack -import java.util.List; - -public class CrystalListener extends PluginDependent implements Listener { - /** - * Create new listeners for dragging crystals onto items. - * - * @param plugin The plugin to listen for. - */ - public CrystalListener(@NotNull final EcoPlugin plugin) { - super(plugin); - } - - /** - * Listen for inventory click event. - * - * @param event The event to handle. - */ +class CrystalListener(private val plugin: EcoPlugin) : Listener { @EventHandler - public void onDrag(@NotNull final InventoryClickEvent event) { - if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE) { - return; + fun onDrag(event: InventoryClickEvent) { + if (event.whoClicked.gameMode == GameMode.CREATIVE) { + return } + val current = event.currentItem ?: return + val cursor = event.cursor ?: return - ItemStack current = event.getCurrentItem(); - ItemStack cursor = event.getCursor(); - - if (current == null || cursor == null) { - return; - } - - Tier crystalTier = ArmorUtils.getCrystalTier(cursor); - - if (crystalTier == null) { - return; - } + val crystalTier = ArmorUtils.getCrystalTier(cursor) ?: return if (ArmorUtils.getSetOnItem(current) == null) { - return; + return } - if (current.getType() == Material.AIR) { - return; + if (current.type == Material.AIR) { + return } - - Tier previousTier = ArmorUtils.getTier(current); - boolean allowed = false; - List prereq = crystalTier.getRequiredTiersForApplication(); - + val previousTier = ArmorUtils.getTier(current) + var allowed = false + val prereq = crystalTier.requiredTiersForApplication if (prereq.isEmpty() || prereq.contains(previousTier)) { - allowed = true; + allowed = true } - if (!allowed) { - return; + return } - - ArmorUtils.setTier(current, crystalTier); - - if (cursor.getAmount() > 1) { - cursor.setAmount(cursor.getAmount() - 1); - event.getWhoClicked().setItemOnCursor(cursor); + ArmorUtils.setTier(current, crystalTier) + if (cursor.amount > 1) { + cursor.amount = cursor.amount - 1 + event.whoClicked.setItemOnCursor(cursor) } else { - event.getWhoClicked().setItemOnCursor(new ItemStack(Material.AIR)); + event.whoClicked.setItemOnCursor(ItemStack(Material.AIR)) } - - event.setCancelled(true); + event.isCancelled = true } - /** - * Prevents placing upgrade crystals. - * - * @param event The event to listen for. - */ @EventHandler - public void onPlaceCrystal(@NotNull final BlockPlaceEvent event) { - ItemStack item = event.getItemInHand(); - + fun onPlaceCrystal(event: BlockPlaceEvent) { + val item = event.itemInHand if (ArmorUtils.getCrystalTier(item) != null) { - event.setCancelled(true); + event.isCancelled = true } } -} +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/util/DiscoverRecipeListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/util/DiscoverRecipeListener.kt new file mode 100644 index 0000000..0c29433 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoarmor/util/DiscoverRecipeListener.kt @@ -0,0 +1,24 @@ +package com.willfp.ecoarmor.util + +import com.willfp.eco.core.EcoPlugin +import org.bukkit.Bukkit +import org.bukkit.Keyed +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerJoinEvent +import org.bukkit.inventory.Recipe + +class DiscoverRecipeListener(private val plugin: EcoPlugin) : Listener { + @EventHandler + fun onJoin(event: PlayerJoinEvent) { + if (!plugin.configYml.getBool("discover-recipes")) { + return + } + mutableListOf() + .apply { Bukkit.getServer().recipeIterator().forEachRemaining(this::add) } + .filterIsInstance().map { it.key } + .filter { it.namespace == plugin.name.lowercase() } + .filter { !it.key.contains("displayed") } + .forEach { event.player.discoverRecipe(it) } + } +} \ No newline at end of file