mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-30 20:39:13 +00:00
Continued rework to kotlin
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<EcoPlugin> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<String>
|
||||
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<String> ITEM_NAMES = new ArrayList<>();
|
||||
private val slots: Collection<String>
|
||||
get() = ArmorSlot.values().map { it.name.lowercase() }.toMutableList().apply { add("full") }
|
||||
|
||||
/**
|
||||
* The cached slots.
|
||||
*/
|
||||
private static final List<String> SLOTS = new ArrayList<>();
|
||||
private val tiers: Collection<String>
|
||||
get() = Tiers.values().map { it.id }
|
||||
|
||||
/**
|
||||
* The cached tiers.
|
||||
*/
|
||||
private static final List<String> TIERS = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The cached numbers.
|
||||
*/
|
||||
private static final List<String> 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<String> ->
|
||||
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<ItemStack> items = new ArrayList<>();
|
||||
int amount = 1;
|
||||
val itemNamespace = fullItemSplit[0]
|
||||
val itemKey = fullItemSplit[1]
|
||||
val toGive = mutableListOf<ItemStack>()
|
||||
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<ArmorSlot> 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<ArmorSlot>()
|
||||
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<String> completions = new ArrayList<>();
|
||||
|
||||
override fun getTabCompleter(): TabCompleteHandler {
|
||||
return TabCompleteHandler { _, args ->
|
||||
val completions = mutableListOf<String>()
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<EcoPlugin> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<EcoPlugin> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<EcoPlugin> 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<Tier> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Recipe>()
|
||||
.apply { Bukkit.getServer().recipeIterator().forEachRemaining(this::add) }
|
||||
.filterIsInstance<Keyed>().map { it.key }
|
||||
.filter { it.namespace == plugin.name.lowercase() }
|
||||
.filter { !it.key.contains("displayed") }
|
||||
.forEach { event.player.discoverRecipe(it) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user