mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-27 02:49:22 +00:00
Finished kotlin conversion
This commit is contained in:
@@ -61,8 +61,8 @@ allprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.willfp:eco:6.15.0'
|
||||
implementation 'com.willfp:libreforge:2.2.0'
|
||||
compileOnly 'com.willfp:eco:6.17.1'
|
||||
implementation 'com.willfp:libreforge:2.2.1'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:23.0.0'
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.willfp.ecoarmor.sets;
|
||||
|
||||
public class ArmorSetHolder {
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.willfp.ecoarmor.upgrades;
|
||||
|
||||
public record TierProperties(int armor,
|
||||
int toughness,
|
||||
int knockback,
|
||||
int speed,
|
||||
int attackSpeed,
|
||||
int attackDamage,
|
||||
int attackKnockback) {
|
||||
}
|
||||
@@ -1,113 +1,91 @@
|
||||
package com.willfp.ecoarmor;
|
||||
package com.willfp.ecoarmor
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.impl.PluginCommand;
|
||||
import com.willfp.eco.core.display.DisplayModule;
|
||||
import com.willfp.eco.core.integrations.IntegrationLoader;
|
||||
import com.willfp.ecoarmor.commands.CommandEcoarmor;
|
||||
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.EffectiveDurabilityListener;
|
||||
import com.willfp.ecoarmor.sets.PreventSkullPlaceListener;
|
||||
import com.willfp.ecoarmor.upgrades.Tiers;
|
||||
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;
|
||||
import com.willfp.libreforge.LibReforge;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.impl.PluginCommand
|
||||
import com.willfp.eco.core.display.DisplayModule
|
||||
import com.willfp.eco.core.integrations.IntegrationLoader
|
||||
import com.willfp.ecoarmor.commands.CommandEcoarmor
|
||||
import com.willfp.ecoarmor.config.EcoArmorYml
|
||||
import com.willfp.ecoarmor.display.ArmorDisplay
|
||||
import com.willfp.ecoarmor.sets.ArmorSets
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils
|
||||
import com.willfp.ecoarmor.sets.EffectiveDurabilityListener
|
||||
import com.willfp.ecoarmor.sets.PreventSkullPlaceListener
|
||||
import com.willfp.ecoarmor.upgrades.AdvancementShardListener
|
||||
import com.willfp.ecoarmor.upgrades.CrystalListener
|
||||
import com.willfp.ecoarmor.upgrades.Tiers
|
||||
import com.willfp.ecoarmor.util.DiscoverRecipeListener
|
||||
import com.willfp.ecoarmor.util.EffectListener
|
||||
import com.willfp.libreforge.LibReforge.disable
|
||||
import com.willfp.libreforge.LibReforge.enable
|
||||
import com.willfp.libreforge.LibReforge.getIntegrationLoaders
|
||||
import com.willfp.libreforge.LibReforge.init
|
||||
import com.willfp.libreforge.LibReforge.registerHolderProvider
|
||||
import com.willfp.libreforge.LibReforge.reload
|
||||
import org.bukkit.event.Listener
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
class EcoArmorPlugin : EcoPlugin(687, 10002, "&c") {
|
||||
val ecoArmorYml: EcoArmorYml
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class EcoArmorPlugin extends EcoPlugin {
|
||||
/**
|
||||
* Instance of EcoArmor.
|
||||
*/
|
||||
@Getter
|
||||
private static EcoArmorPlugin instance;
|
||||
|
||||
/**
|
||||
* ecoarmor.yml.
|
||||
*/
|
||||
@Getter
|
||||
private final EcoArmorYml ecoArmorYml;
|
||||
|
||||
/**
|
||||
* Internal constructor called by bukkit on plugin load.
|
||||
*/
|
||||
public EcoArmorPlugin() {
|
||||
super(687, 10002, "&c");
|
||||
instance = this;
|
||||
|
||||
this.ecoArmorYml = new EcoArmorYml(this);
|
||||
|
||||
LibReforge.init(this);
|
||||
LibReforge.registerHolderProvider(player -> {
|
||||
Holder active = ArmorUtils.getActiveSet(player);
|
||||
init {
|
||||
instance = this
|
||||
ecoArmorYml = EcoArmorYml(this)
|
||||
init(this)
|
||||
registerHolderProvider { player ->
|
||||
val active = ArmorUtils.getActiveSet(player)
|
||||
if (active == null) {
|
||||
return Collections.emptyList();
|
||||
emptyList()
|
||||
} else {
|
||||
return Collections.singletonList(active);
|
||||
listOf(active)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleEnable() {
|
||||
LibReforge.enable(this);
|
||||
override fun handleEnable() {
|
||||
enable(this)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleDisable() {
|
||||
LibReforge.disable(this);
|
||||
override fun handleDisable() {
|
||||
disable(this)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleReload() {
|
||||
this.getLogger().info(Tiers.values().size() + " Tiers Loaded");
|
||||
this.getLogger().info(ArmorSets.values().size() + " Sets Loaded");
|
||||
LibReforge.reload(this);
|
||||
override fun handleReload() {
|
||||
logger.info(Tiers.values().size.toString() + " Tiers Loaded")
|
||||
logger.info(ArmorSets.values().size.toString() + " Sets Loaded")
|
||||
reload(this)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PluginCommand> loadPluginCommands() {
|
||||
return Arrays.asList(
|
||||
new CommandEcoarmor(this)
|
||||
);
|
||||
override fun loadPluginCommands(): List<PluginCommand> {
|
||||
return listOf(
|
||||
CommandEcoarmor(this)
|
||||
)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Listener> loadListeners() {
|
||||
return Arrays.asList(
|
||||
new CrystalListener(this),
|
||||
new AdvancementShardListener(this),
|
||||
new EffectiveDurabilityListener(this),
|
||||
new DiscoverRecipeListener(this),
|
||||
new PreventSkullPlaceListener(),
|
||||
new EffectListener()
|
||||
);
|
||||
override fun loadListeners(): List<Listener> {
|
||||
return listOf(
|
||||
CrystalListener(this),
|
||||
AdvancementShardListener(this),
|
||||
EffectiveDurabilityListener(this),
|
||||
DiscoverRecipeListener(this),
|
||||
PreventSkullPlaceListener(),
|
||||
EffectListener()
|
||||
)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<IntegrationLoader> loadIntegrationLoaders() {
|
||||
return LibReforge.getIntegrationLoaders();
|
||||
override fun loadIntegrationLoaders(): List<IntegrationLoader> {
|
||||
return getIntegrationLoaders()
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable DisplayModule createDisplayModule() {
|
||||
return new ArmorDisplay(this);
|
||||
override fun createDisplayModule(): DisplayModule {
|
||||
return ArmorDisplay(this)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMinimumEcoVersion() {
|
||||
return "6.15.0";
|
||||
override fun getMinimumEcoVersion(): String {
|
||||
return "6.17.0"
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
lateinit var instance: EcoArmorPlugin
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ 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.sets.ArmorUtils
|
||||
import com.willfp.ecoarmor.upgrades.Tier
|
||||
import com.willfp.ecoarmor.upgrades.Tiers
|
||||
import org.bukkit.Bukkit
|
||||
|
||||
@@ -5,7 +5,7 @@ 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.ArmorSlot
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta
|
||||
|
||||
|
||||
@@ -1,263 +1,235 @@
|
||||
package com.willfp.ecoarmor.sets;
|
||||
package com.willfp.ecoarmor.sets
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import com.willfp.eco.core.items.CustomItem;
|
||||
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.util.ArmorUtils;
|
||||
import com.willfp.ecoarmor.upgrades.Tier;
|
||||
import com.willfp.ecoarmor.upgrades.Tiers;
|
||||
import com.willfp.libreforge.Holder;
|
||||
import com.willfp.libreforge.conditions.Conditions;
|
||||
import com.willfp.libreforge.conditions.ConfiguredCondition;
|
||||
import com.willfp.libreforge.effects.ConfiguredEffect;
|
||||
import com.willfp.libreforge.effects.Effects;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ArmorSet {
|
||||
/**
|
||||
* Instance of EcoArmor.
|
||||
*/
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* The config of the set.
|
||||
*/
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private final Config config;
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.eco.core.display.Display
|
||||
import com.willfp.eco.core.items.CustomItem
|
||||
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.ArmorSlot.Companion.getSlot
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils.getSetOnItem
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils.getShardSet
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils.isAdvanced
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils.setAdvanced
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils.setTier
|
||||
import com.willfp.ecoarmor.upgrades.Tier
|
||||
import com.willfp.ecoarmor.upgrades.Tiers
|
||||
import com.willfp.libreforge.Holder
|
||||
import com.willfp.libreforge.conditions.Conditions
|
||||
import com.willfp.libreforge.conditions.ConfiguredCondition
|
||||
import com.willfp.libreforge.effects.ConfiguredEffect
|
||||
import com.willfp.libreforge.effects.Effects
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.inventory.ItemFlag
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import java.util.*
|
||||
import java.util.stream.Collectors
|
||||
|
||||
class ArmorSet(
|
||||
private val config: Config,
|
||||
private val plugin: EcoPlugin
|
||||
) {
|
||||
/**
|
||||
* The name of the set.
|
||||
*/
|
||||
@Getter
|
||||
private final String id;
|
||||
val id: String = config.getString("id")
|
||||
|
||||
/**
|
||||
* The advanced holder.
|
||||
*/
|
||||
@Getter
|
||||
private final Holder advancedHoler;
|
||||
val advancedHolder: Holder
|
||||
|
||||
/**
|
||||
* The regular holder.
|
||||
*/
|
||||
@Getter
|
||||
private final Holder regularHolder;
|
||||
val regularHolder: Holder
|
||||
|
||||
/**
|
||||
* Items in set.
|
||||
*/
|
||||
private final Map<ArmorSlot, ItemStack> items = new HashMap<>();
|
||||
private val items: MutableMap<ArmorSlot, ItemStack> = EnumMap(ArmorSlot::class.java)
|
||||
|
||||
/**
|
||||
* Items in advanced set.
|
||||
*/
|
||||
private final Map<ArmorSlot, ItemStack> advancedItems = new HashMap<>();
|
||||
private val advancedItems: MutableMap<ArmorSlot, ItemStack> = EnumMap(ArmorSlot::class.java)
|
||||
|
||||
/**
|
||||
* Advancement shard item.
|
||||
*/
|
||||
@Getter
|
||||
private final ItemStack advancementShardItem;
|
||||
val advancementShardItem: ItemStack
|
||||
|
||||
/**
|
||||
* Create a new Armor Set.
|
||||
*
|
||||
* @param config The set's config.
|
||||
* @param plugin Instance of EcoArmor.
|
||||
*/
|
||||
public ArmorSet(@NotNull final Config config,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
this.config = config;
|
||||
this.plugin = plugin;
|
||||
this.id = config.getString("id");
|
||||
|
||||
Set<ConfiguredCondition> conditions = new HashSet<>();
|
||||
for (Config cfg : this.getConfig().getSubsections("conditions")) {
|
||||
ConfiguredCondition conf = Conditions.compile(cfg, "Armor Set " + this.id);
|
||||
init {
|
||||
val conditions: MutableSet<ConfiguredCondition> = HashSet()
|
||||
for (cfg in config.getSubsections("conditions")) {
|
||||
val conf = Conditions.compile(cfg, "Armor Set $id")
|
||||
if (conf != null) {
|
||||
conditions.add(conf);
|
||||
conditions.add(conf)
|
||||
}
|
||||
}
|
||||
|
||||
Set<ConfiguredEffect> effects = new HashSet<>();
|
||||
for (Config cfg : this.getConfig().getSubsections("effects")) {
|
||||
ConfiguredEffect conf = Effects.compile(cfg, "Armor Set " + this.id);
|
||||
val effects: MutableSet<ConfiguredEffect> = HashSet()
|
||||
for (cfg in config.getSubsections("effects")) {
|
||||
val conf = Effects.compile(cfg, "Armor Set $id")
|
||||
if (conf != null) {
|
||||
effects.add(conf);
|
||||
effects.add(conf)
|
||||
}
|
||||
}
|
||||
|
||||
Set<ConfiguredEffect> advancedEffects = new HashSet<>();
|
||||
for (Config cfg : this.getConfig().getSubsections("advancedEffects")) {
|
||||
ConfiguredEffect conf = Effects.compile(cfg, "Armor Set " + this.id + " (Advanced)");
|
||||
val advancedEffects: MutableSet<ConfiguredEffect> = HashSet()
|
||||
for (cfg in config.getSubsections("advancedEffects")) {
|
||||
val conf = Effects.compile(cfg, "Armor Set $id (Advanced)")
|
||||
if (conf != null) {
|
||||
advancedEffects.add(conf);
|
||||
advancedEffects.add(conf)
|
||||
}
|
||||
}
|
||||
|
||||
this.regularHolder = new RegularHolder(conditions, effects);
|
||||
this.advancedHoler = new AdvancedHolder(conditions, advancedEffects);
|
||||
|
||||
ArmorSets.addNewSet(this);
|
||||
|
||||
for (ArmorSlot slot : ArmorSlot.values()) {
|
||||
ItemStack item = construct(slot, this.getConfig().getSubsection(slot.name().toLowerCase()), false);
|
||||
items.put(slot, item);
|
||||
constructRecipe(slot, this.getConfig().getSubsection(slot.name().toLowerCase()), item);
|
||||
|
||||
ItemStack advancedItem = construct(slot, this.getConfig().getSubsection(slot.name().toLowerCase()), true);
|
||||
advancedItems.put(slot, advancedItem);
|
||||
regularHolder = RegularHolder(conditions, effects)
|
||||
advancedHolder = AdvancedHolder(conditions, advancedEffects)
|
||||
ArmorSets.addNewSet(this)
|
||||
for (slot in ArmorSlot.values()) {
|
||||
val item = construct(slot, config.getSubsection(slot.name.lowercase(Locale.getDefault())), false)
|
||||
items[slot] = item
|
||||
constructRecipe(slot, config.getSubsection(slot.name.lowercase(Locale.getDefault())), item)
|
||||
val advancedItem = construct(slot, config.getSubsection(slot.name.lowercase(Locale.getDefault())), true)
|
||||
advancedItems[slot] = advancedItem
|
||||
}
|
||||
|
||||
this.advancementShardItem = constructShard();
|
||||
advancementShardItem = constructShard()
|
||||
}
|
||||
|
||||
private ItemStack constructShard() {
|
||||
List<String> shardLore = this.getConfig().getStrings("advancementShardLore");
|
||||
shardLore.replaceAll(s -> Display.PREFIX + s);
|
||||
|
||||
ItemStack shard = new ItemStackBuilder(Items.lookup(this.getPlugin().getConfigYml().getString("advancement-shard-material").toLowerCase()).getItem())
|
||||
.setDisplayName(this.getConfig().getString("advancementShardName"))
|
||||
.addEnchantment(Enchantment.DURABILITY, 3)
|
||||
.addItemFlag(ItemFlag.HIDE_ENCHANTS)
|
||||
.addLoreLines(shardLore)
|
||||
.writeMetaKey(this.getPlugin().getNamespacedKeyFactory().create("advancement-shard"), PersistentDataType.STRING, id)
|
||||
.build();
|
||||
|
||||
if (this.getConfig().getBool("shardCraftable")) {
|
||||
Recipes.createAndRegisterRecipe(this.getPlugin(),
|
||||
this.getId() + "_shard",
|
||||
shard,
|
||||
this.getConfig().getStrings("shardRecipe"));
|
||||
}
|
||||
|
||||
new CustomItem(
|
||||
this.getPlugin().getNamespacedKeyFactory().create("shard_" + id.toLowerCase()),
|
||||
test -> this.equals(ArmorUtils.getShardSet(test)),
|
||||
shard
|
||||
).register();
|
||||
|
||||
return shard;
|
||||
}
|
||||
|
||||
private ItemStack construct(@NotNull final ArmorSlot slot,
|
||||
@NotNull final Config slotConfig,
|
||||
final boolean advanced) {
|
||||
ItemBuilder builder = new ItemStackBuilder(Items.lookup(slotConfig.getString("item")).getItem())
|
||||
.setDisplayName(advanced ? slotConfig.getString("advancedName") : slotConfig.getString("name"))
|
||||
.addLoreLines(slotConfig.getStrings("lore").stream().map(s -> Display.PREFIX + s).collect(Collectors.toList()))
|
||||
.addLoreLines(() -> {
|
||||
if (advanced) {
|
||||
return this.getConfig().getStrings("advancedLore").stream().map(s -> Display.PREFIX + s).collect(Collectors.toList());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.setDisplayName(() -> advanced ? slotConfig.getString("advancedName") : slotConfig.getString("name"));
|
||||
|
||||
builder.writeMetaKey(
|
||||
this.getPlugin().getNamespacedKeyFactory().create("set"),
|
||||
PersistentDataType.STRING,
|
||||
id
|
||||
).writeMetaKey(
|
||||
this.getPlugin().getNamespacedKeyFactory().create("effective-durability"),
|
||||
PersistentDataType.INTEGER,
|
||||
slotConfig.getInt("effectiveDurability")
|
||||
);
|
||||
|
||||
ItemStack itemStack = builder.build();
|
||||
|
||||
ArmorUtils.setAdvanced(itemStack, advanced);
|
||||
Tier defaultTier = Tiers.getByID(slotConfig.getString("defaultTier"));
|
||||
if (defaultTier == null) {
|
||||
Bukkit.getLogger().warning("Default tier specified in " + this.id + " " + slot.name().toLowerCase() + " is invalid! Defaulting to 'default'");
|
||||
ArmorUtils.setTier(itemStack, Tiers.getDefaultTier());
|
||||
} else {
|
||||
ArmorUtils.setTier(itemStack, defaultTier);
|
||||
}
|
||||
|
||||
if (advanced) {
|
||||
new CustomItem(this.getPlugin().getNamespacedKeyFactory().create("set_" + id.toLowerCase() + "_" + slot.name().toLowerCase() + "_advanced"), test -> {
|
||||
if (ArmorSlot.getSlot(test) != ArmorSlot.getSlot(itemStack)) {
|
||||
return false;
|
||||
}
|
||||
if (!ArmorUtils.isAdvanced(itemStack)) {
|
||||
return false;
|
||||
}
|
||||
if (ArmorUtils.getSetOnItem(test) == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(this, ArmorUtils.getSetOnItem(test));
|
||||
}, itemStack).register();
|
||||
} else {
|
||||
new CustomItem(this.getPlugin().getNamespacedKeyFactory().create("set_" + id.toLowerCase() + "_" + slot.name().toLowerCase()), test -> {
|
||||
if (ArmorSlot.getSlot(test) != ArmorSlot.getSlot(itemStack)) {
|
||||
return false;
|
||||
}
|
||||
if (ArmorUtils.isAdvanced(itemStack)) {
|
||||
return false;
|
||||
}
|
||||
if (ArmorUtils.getSetOnItem(test) == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(this, ArmorUtils.getSetOnItem(test));
|
||||
}, itemStack).register();
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private void constructRecipe(@NotNull final ArmorSlot slot,
|
||||
@NotNull final Config slotConfig,
|
||||
@NotNull final ItemStack out) {
|
||||
if (slotConfig.getBool("craftable")) {
|
||||
ItemStack formattedOut = out.clone();
|
||||
ItemMeta meta = formattedOut.getItemMeta();
|
||||
assert meta != null;
|
||||
assert meta.getLore() != null;
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
for (String s : meta.getLore()) {
|
||||
s = s.replace("%tier%", Tiers.getDefaultTier().getDisplayName());
|
||||
lore.add(s);
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
formattedOut.setItemMeta(meta);
|
||||
|
||||
private fun constructShard(): ItemStack {
|
||||
val shardLore = config.getStrings("advancementShardLore")
|
||||
shardLore.replaceAll { Display.PREFIX + it }
|
||||
val shard = ItemStackBuilder(
|
||||
Items.lookup(
|
||||
plugin.configYml.getString("advancement-shard-material").lowercase(Locale.getDefault())
|
||||
).item
|
||||
)
|
||||
.setDisplayName(config.getString("advancementShardName"))
|
||||
.addEnchantment(Enchantment.DURABILITY, 3)
|
||||
.addItemFlag(ItemFlag.HIDE_ENCHANTS)
|
||||
.addLoreLines(shardLore)
|
||||
.writeMetaKey(plugin.namespacedKeyFactory.create("advancement-shard"), PersistentDataType.STRING, id)
|
||||
.build()
|
||||
if (config.getBool("shardCraftable")) {
|
||||
Recipes.createAndRegisterRecipe(
|
||||
this.getPlugin(),
|
||||
this.getId() + "_" + slot.name().toLowerCase(),
|
||||
formattedOut,
|
||||
slotConfig.getStrings("recipe")
|
||||
);
|
||||
plugin,
|
||||
id + "_shard",
|
||||
shard,
|
||||
config.getStrings("shardRecipe")
|
||||
)
|
||||
}
|
||||
CustomItem(
|
||||
plugin.namespacedKeyFactory.create("shard_" + id.lowercase(Locale.getDefault())),
|
||||
{ test: ItemStack? -> this == getShardSet(test!!) },
|
||||
shard
|
||||
).register()
|
||||
return shard
|
||||
}
|
||||
|
||||
private fun construct(
|
||||
slot: ArmorSlot,
|
||||
slotConfig: Config,
|
||||
advanced: Boolean
|
||||
): ItemStack {
|
||||
val builder: ItemBuilder = ItemStackBuilder(Items.lookup(slotConfig.getString("item")).item)
|
||||
.setDisplayName(if (advanced) slotConfig.getString("advancedName") else slotConfig.getString("name"))
|
||||
.addLoreLines(slotConfig.getStrings("lore").stream().map { s: String -> Display.PREFIX + s }
|
||||
.collect(Collectors.toList()))
|
||||
.addLoreLines {
|
||||
if (advanced) {
|
||||
return@addLoreLines config.getStrings("advancedLore").stream()
|
||||
.map { s: String -> Display.PREFIX + s }
|
||||
.collect(Collectors.toList())
|
||||
} else {
|
||||
return@addLoreLines null
|
||||
}
|
||||
}
|
||||
.setDisplayName { if (advanced) slotConfig.getString("advancedName") else slotConfig.getString("name") }
|
||||
builder.writeMetaKey(
|
||||
plugin.namespacedKeyFactory.create("set"),
|
||||
PersistentDataType.STRING,
|
||||
id
|
||||
).writeMetaKey(
|
||||
plugin.namespacedKeyFactory.create("effective-durability"),
|
||||
PersistentDataType.INTEGER,
|
||||
slotConfig.getInt("effectiveDurability")
|
||||
)
|
||||
val itemStack = builder.build()
|
||||
setAdvanced(itemStack, advanced)
|
||||
val defaultTier = Tiers.getByID(slotConfig.getString("defaultTier"))
|
||||
if (defaultTier == null) {
|
||||
Bukkit.getLogger()
|
||||
.warning("Default tier specified in " + id + " " + slot.name.lowercase(Locale.getDefault()) + " is invalid! Defaulting to 'default'")
|
||||
setTier(itemStack, Tiers.getDefaultTier())
|
||||
} else {
|
||||
setTier(itemStack, defaultTier)
|
||||
}
|
||||
if (advanced) {
|
||||
CustomItem(
|
||||
plugin.namespacedKeyFactory.create(
|
||||
"set_" + id.lowercase(Locale.getDefault()) + "_" + slot.name.lowercase(
|
||||
Locale.getDefault()
|
||||
) + "_advanced"
|
||||
), { test ->
|
||||
if (getSlot(test) !== getSlot(itemStack)) {
|
||||
return@CustomItem false
|
||||
}
|
||||
if (!isAdvanced(itemStack)) {
|
||||
return@CustomItem false
|
||||
}
|
||||
if (getSetOnItem(test) == null) {
|
||||
return@CustomItem false
|
||||
}
|
||||
this == getSetOnItem(test)
|
||||
}, itemStack
|
||||
).register()
|
||||
} else {
|
||||
CustomItem(
|
||||
plugin.namespacedKeyFactory.create(
|
||||
"set_" + id.lowercase(Locale.getDefault()) + "_" + slot.name.lowercase(
|
||||
Locale.getDefault()
|
||||
)
|
||||
),
|
||||
{ test ->
|
||||
if (getSlot(test) !== getSlot(itemStack)) {
|
||||
return@CustomItem false
|
||||
}
|
||||
if (isAdvanced(itemStack)) {
|
||||
return@CustomItem false
|
||||
}
|
||||
if (getSetOnItem(test) == null) {
|
||||
return@CustomItem false
|
||||
}
|
||||
this == getSetOnItem(test)
|
||||
}, itemStack
|
||||
).register()
|
||||
}
|
||||
return itemStack
|
||||
}
|
||||
|
||||
private fun constructRecipe(
|
||||
slot: ArmorSlot,
|
||||
slotConfig: Config,
|
||||
out: ItemStack
|
||||
) {
|
||||
if (slotConfig.getBool("craftable")) {
|
||||
val formattedOut = out.clone()
|
||||
val meta = formattedOut.itemMeta!!
|
||||
assert(meta.lore != null)
|
||||
val lore = meta.lore.map { it.replace("%tier%", Tiers.getDefaultTier().displayName) }
|
||||
meta.lore = lore
|
||||
formattedOut.itemMeta = meta
|
||||
Recipes.createAndRegisterRecipe(
|
||||
plugin,
|
||||
id + "_" + slot.name.lowercase(Locale.getDefault()),
|
||||
formattedOut,
|
||||
slotConfig.getStrings("recipe")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,8 +239,8 @@ public class ArmorSet {
|
||||
* @param slot The slot.
|
||||
* @return The item.
|
||||
*/
|
||||
public ItemStack getItemStack(@NotNull final ArmorSlot slot) {
|
||||
return items.get(slot);
|
||||
fun getItemStack(slot: ArmorSlot): ItemStack? {
|
||||
return items[slot]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,8 +249,8 @@ public class ArmorSet {
|
||||
* @param slot The slot.
|
||||
* @return The item.
|
||||
*/
|
||||
public ItemStack getAdvancedItemStack(@NotNull final ArmorSlot slot) {
|
||||
return advancedItems.get(slot);
|
||||
fun getAdvancedItemStack(slot: ArmorSlot): ItemStack? {
|
||||
return advancedItems[slot]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,34 +259,31 @@ public class ArmorSet {
|
||||
* @param slot The slot.
|
||||
* @return The tier.
|
||||
*/
|
||||
public Tier getDefaultTier(@Nullable final ArmorSlot slot) {
|
||||
if (slot == null) return Tiers.getDefaultTier();
|
||||
Tier tier = Tiers.getByID(this.config.getSubsection(slot.name().toLowerCase()).getString("defaultTier"));
|
||||
return tier != null ? tier : Tiers.getDefaultTier();
|
||||
fun getDefaultTier(slot: ArmorSlot?): Tier {
|
||||
if (slot == null) return Tiers.getDefaultTier()
|
||||
val tier = Tiers.getByID(config.getSubsection(slot.name.lowercase()).getString("defaultTier"))
|
||||
return tier ?: Tiers.getDefaultTier()
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (!(o instanceof ArmorSet set)) {
|
||||
return false;
|
||||
if (other !is ArmorSet) {
|
||||
return false
|
||||
}
|
||||
|
||||
return this.id.equals(set.id);
|
||||
return id == other.id
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.id);
|
||||
override fun hashCode(): Int {
|
||||
return Objects.hash(id)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ArmorSet{"
|
||||
+ this.id
|
||||
+ "}";
|
||||
override fun toString(): String {
|
||||
return ("ArmorSet{"
|
||||
+ id
|
||||
+ "}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +1,72 @@
|
||||
package com.willfp.ecoarmor.sets;
|
||||
package com.willfp.ecoarmor.sets
|
||||
|
||||
import com.google.common.collect.BiMap
|
||||
import com.google.common.collect.HashBiMap
|
||||
import com.google.common.collect.ImmutableList
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater;
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
public class ArmorSets {
|
||||
object ArmorSets {
|
||||
/**
|
||||
* Registered armor sets.
|
||||
*/
|
||||
private static final BiMap<String, ArmorSet> BY_ID = HashBiMap.create();
|
||||
private val BY_ID: BiMap<String, ArmorSet> = HashBiMap.create()
|
||||
|
||||
/**
|
||||
* Get all registered {@link ArmorSet}s.
|
||||
* Get all registered [ArmorSet]s.
|
||||
*
|
||||
* @return A list of all {@link ArmorSet}s.
|
||||
* @return A list of all [ArmorSet]s.
|
||||
*/
|
||||
public static List<ArmorSet> values() {
|
||||
return ImmutableList.copyOf(BY_ID.values());
|
||||
@JvmStatic
|
||||
fun values(): List<ArmorSet> {
|
||||
return ImmutableList.copyOf(BY_ID.values)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link ArmorSet} matching ID.
|
||||
* Get [ArmorSet] matching ID.
|
||||
*
|
||||
* @param name The name to search for.
|
||||
* @return The matching {@link ArmorSet}, or null if not found.
|
||||
* @return The matching [ArmorSet], or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public static ArmorSet getByID(@NotNull final String name) {
|
||||
return BY_ID.get(name);
|
||||
@JvmStatic
|
||||
fun getByID(name: String): ArmorSet? {
|
||||
return BY_ID[name]
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all {@link ArmorSet}s.
|
||||
* Update all [ArmorSet]s.
|
||||
*
|
||||
* @param plugin Instance of EcoArmor.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update(@NotNull final EcoArmorPlugin plugin) {
|
||||
for (ArmorSet set : values()) {
|
||||
removeSet(set);
|
||||
@JvmStatic
|
||||
fun update(plugin: EcoArmorPlugin) {
|
||||
for (set in values()) {
|
||||
removeSet(set)
|
||||
}
|
||||
|
||||
for (Config setConfig : plugin.getEcoArmorYml().getSubsections("sets")) {
|
||||
new ArmorSet(setConfig, plugin);
|
||||
for (setConfig in plugin.ecoArmorYml.getSubsections("sets")) {
|
||||
ArmorSet(setConfig!!, plugin)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new {@link ArmorSet} to EcoArmor.
|
||||
* Add new [ArmorSet] to EcoArmor.
|
||||
*
|
||||
* @param set The {@link ArmorSet} to add.
|
||||
* @param set The [ArmorSet] to add.
|
||||
*/
|
||||
public static void addNewSet(@NotNull final ArmorSet set) {
|
||||
BY_ID.remove(set.getId());
|
||||
BY_ID.put(set.getId(), set);
|
||||
@JvmStatic
|
||||
fun addNewSet(set: ArmorSet) {
|
||||
BY_ID.remove(set.id)
|
||||
BY_ID[set.id] = set
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove {@link ArmorSet} from EcoArmor.
|
||||
* Remove [ArmorSet] from EcoArmor.
|
||||
*
|
||||
* @param set The {@link ArmorSet} to remove.
|
||||
* @param set The [ArmorSet] to remove.
|
||||
*/
|
||||
public static void removeSet(@NotNull final ArmorSet set) {
|
||||
BY_ID.remove(set.getId());
|
||||
@JvmStatic
|
||||
fun removeSet(set: ArmorSet) {
|
||||
BY_ID.remove(set.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,23 @@
|
||||
package com.willfp.ecoarmor.sets.util;
|
||||
package com.willfp.ecoarmor.sets
|
||||
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
import com.willfp.ecoarmor.sets.ArmorSet;
|
||||
import com.willfp.ecoarmor.sets.ArmorSets;
|
||||
import com.willfp.ecoarmor.sets.ArmorSlot;
|
||||
import com.willfp.ecoarmor.upgrades.Tier;
|
||||
import com.willfp.ecoarmor.upgrades.Tiers;
|
||||
import com.willfp.libreforge.Holder;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.entity.Player;
|
||||
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 org.jetbrains.annotations.Nullable;
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin.Companion.instance
|
||||
import com.willfp.ecoarmor.sets.ArmorSlot.Companion.getSlot
|
||||
import com.willfp.ecoarmor.upgrades.Tier
|
||||
import com.willfp.ecoarmor.upgrades.Tiers
|
||||
import com.willfp.libreforge.Holder
|
||||
import org.bukkit.attribute.Attribute
|
||||
import org.bukkit.attribute.AttributeModifier
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import java.util.*
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@UtilityClass
|
||||
public class ArmorUtils {
|
||||
object ArmorUtils {
|
||||
/**
|
||||
* Instance of EcoArmor.
|
||||
*/
|
||||
private static final EcoArmorPlugin PLUGIN = EcoArmorPlugin.getInstance();
|
||||
private val PLUGIN = instance
|
||||
|
||||
/**
|
||||
* Get armor set on an item.
|
||||
@@ -35,15 +25,10 @@ public class ArmorUtils {
|
||||
* @param itemStack The itemStack to check.
|
||||
* @return The set, or null if no set is found.
|
||||
*/
|
||||
@Nullable
|
||||
public ArmorSet getSetOnItem(@NotNull final ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getSetOnItem(meta);
|
||||
@JvmStatic
|
||||
fun getSetOnItem(itemStack: ItemStack): ArmorSet? {
|
||||
val meta = itemStack.itemMeta ?: return null
|
||||
return getSetOnItem(meta)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,16 +37,15 @@ public class ArmorUtils {
|
||||
* @param meta The itemStack to check.
|
||||
* @return The set, or null if no set is found.
|
||||
*/
|
||||
@Nullable
|
||||
public ArmorSet getSetOnItem(@NotNull final ItemMeta meta) {
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
String setName = container.get(PLUGIN.getNamespacedKeyFactory().create("set"), PersistentDataType.STRING);
|
||||
|
||||
if (setName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ArmorSets.getByID(setName);
|
||||
@JvmStatic
|
||||
fun getSetOnItem(meta: ItemMeta): ArmorSet? {
|
||||
val container = meta.persistentDataContainer
|
||||
val setName = container.get(
|
||||
PLUGIN.namespacedKeyFactory.create("set"),
|
||||
PersistentDataType.STRING
|
||||
)
|
||||
?: return null
|
||||
return ArmorSets.getByID(setName)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,15 +54,14 @@ public class ArmorUtils {
|
||||
* @param player The player to check.
|
||||
* @return The holder, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public Holder getActiveSet(@NotNull final Player player) {
|
||||
ArmorSet armorSet = getSetOnPlayer(player);
|
||||
boolean advanced = isWearingAdvanced(player);
|
||||
|
||||
if (armorSet != null) {
|
||||
return advanced ? armorSet.getAdvancedHoler() : armorSet.getRegularHolder();
|
||||
@JvmStatic
|
||||
fun getActiveSet(player: Player): Holder? {
|
||||
val armorSet = getSetOnPlayer(player)
|
||||
val advanced = isWearingAdvanced(player)
|
||||
return if (armorSet != null) {
|
||||
if (advanced) armorSet.advancedHolder else armorSet.regularHolder
|
||||
} else {
|
||||
return null;
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,41 +71,29 @@ public class ArmorUtils {
|
||||
* @param player The player to check.
|
||||
* @return The set, or null if no full set is worn.
|
||||
*/
|
||||
@Nullable
|
||||
public ArmorSet getSetOnPlayer(@NotNull final Player player) {
|
||||
List<ArmorSet> found = new ArrayList<>();
|
||||
|
||||
for (ItemStack itemStack : player.getInventory().getArmorContents()) {
|
||||
@JvmStatic
|
||||
fun getSetOnPlayer(player: Player): ArmorSet? {
|
||||
val found: MutableList<ArmorSet> = ArrayList()
|
||||
for (itemStack in player.inventory.armorContents) {
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
|
||||
ArmorSet set = getSetOnItem(itemStack);
|
||||
|
||||
if (set == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
found.add(set);
|
||||
val set = getSetOnItem(itemStack) ?: continue
|
||||
found.add(set)
|
||||
}
|
||||
|
||||
if (found.size() < 4) {
|
||||
return null;
|
||||
if (found.size < 4) {
|
||||
return null
|
||||
}
|
||||
|
||||
boolean allEqual = true;
|
||||
for (ArmorSet set : found) {
|
||||
if (!set.equals(found.get(0))) {
|
||||
allEqual = false;
|
||||
break;
|
||||
var allEqual = true
|
||||
for (set in found) {
|
||||
if (set != found[0]) {
|
||||
allEqual = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (allEqual) {
|
||||
return found.get(0);
|
||||
}
|
||||
|
||||
return null;
|
||||
return if (allEqual) {
|
||||
found[0]
|
||||
} else null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,15 +102,10 @@ public class ArmorUtils {
|
||||
* @param itemStack The item to check.
|
||||
* @return The found tier, or null.
|
||||
*/
|
||||
@Nullable
|
||||
public static Tier getCrystalTier(@NotNull final ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getCrystalTier(meta);
|
||||
@JvmStatic
|
||||
fun getCrystalTier(itemStack: ItemStack): Tier? {
|
||||
val meta = itemStack.itemMeta ?: return null
|
||||
return getCrystalTier(meta)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,13 +114,22 @@ public class ArmorUtils {
|
||||
* @param meta The item to check.
|
||||
* @return The found tier, or null.
|
||||
*/
|
||||
@Nullable
|
||||
public static Tier getCrystalTier(@NotNull final ItemMeta meta) {
|
||||
if (meta.getPersistentDataContainer().has(PLUGIN.getNamespacedKeyFactory().create("upgrade_crystal"), PersistentDataType.STRING)) {
|
||||
return Tiers.getByID(meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("upgrade_crystal"), PersistentDataType.STRING));
|
||||
}
|
||||
|
||||
return null;
|
||||
@JvmStatic
|
||||
fun getCrystalTier(meta: ItemMeta): Tier? {
|
||||
return if (meta.persistentDataContainer.has(
|
||||
PLUGIN.namespacedKeyFactory.create(
|
||||
"upgrade_crystal"
|
||||
), PersistentDataType.STRING
|
||||
)
|
||||
) {
|
||||
Tiers.getByID(
|
||||
meta.persistentDataContainer.get(
|
||||
PLUGIN.namespacedKeyFactory.create(
|
||||
"upgrade_crystal"
|
||||
), PersistentDataType.STRING
|
||||
)
|
||||
)
|
||||
} else null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,21 +138,15 @@ public class ArmorUtils {
|
||||
* @param itemStack The item to check.
|
||||
* @return The found tier, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public static Tier getTier(@NotNull final ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Tier tier = getTier(meta);
|
||||
|
||||
if (getSetOnItem(meta) != null && tier == null) {
|
||||
setTier(itemStack, Tiers.getDefaultTier());
|
||||
return Tiers.getDefaultTier();
|
||||
@JvmStatic
|
||||
fun getTier(itemStack: ItemStack): Tier? {
|
||||
val meta = itemStack.itemMeta ?: return null
|
||||
val tier = getTier(meta)
|
||||
return if (getSetOnItem(meta) != null && tier == null) {
|
||||
setTier(itemStack, Tiers.getDefaultTier())
|
||||
Tiers.getDefaultTier()
|
||||
} else {
|
||||
return tier;
|
||||
tier
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,17 +156,25 @@ public class ArmorUtils {
|
||||
* @param meta The item to check.
|
||||
* @return The found tier, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public static Tier getTier(@NotNull final ItemMeta meta) {
|
||||
@JvmStatic
|
||||
fun getTier(meta: ItemMeta): Tier? {
|
||||
if (getSetOnItem(meta) == null) {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
if (meta.getPersistentDataContainer().has(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING)) {
|
||||
return Tiers.getByID(meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING));
|
||||
}
|
||||
|
||||
return null;
|
||||
return if (meta.persistentDataContainer.has(
|
||||
PLUGIN.namespacedKeyFactory.create(
|
||||
"tier"
|
||||
), PersistentDataType.STRING
|
||||
)
|
||||
) {
|
||||
Tiers.getByID(
|
||||
meta.persistentDataContainer.get(
|
||||
PLUGIN.namespacedKeyFactory.create(
|
||||
"tier"
|
||||
), PersistentDataType.STRING
|
||||
)
|
||||
)
|
||||
} else null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,85 +183,124 @@ public class ArmorUtils {
|
||||
* @param itemStack The item to check.
|
||||
* @param tier The tier to set.
|
||||
*/
|
||||
public static void setTier(@NotNull final ItemStack itemStack,
|
||||
@NotNull final Tier tier) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return;
|
||||
@JvmStatic
|
||||
fun setTier(
|
||||
itemStack: ItemStack,
|
||||
tier: Tier
|
||||
) {
|
||||
val meta = itemStack.itemMeta ?: return
|
||||
if (!meta.persistentDataContainer.has(
|
||||
PLUGIN.namespacedKeyFactory.create("set"),
|
||||
PersistentDataType.STRING
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!meta.getPersistentDataContainer().has(PLUGIN.getNamespacedKeyFactory().create("set"), PersistentDataType.STRING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
meta.getPersistentDataContainer().set(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING, tier.getId());
|
||||
|
||||
ArmorSlot slot = ArmorSlot.getSlot(itemStack);
|
||||
|
||||
if (slot == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int armor = tier.getProperties().get(slot).armor();
|
||||
int toughness = tier.getProperties().get(slot).toughness();
|
||||
int knockback = tier.getProperties().get(slot).knockback();
|
||||
int speed = tier.getProperties().get(slot).speed();
|
||||
int attackSpeed = tier.getProperties().get(slot).attackSpeed();
|
||||
int attackDamage = tier.getProperties().get(slot).attackDamage();
|
||||
int attackKnockback = tier.getProperties().get(slot).attackKnockback();
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_ARMOR);
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS);
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED);
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_ATTACK_SPEED);
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE);
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_ATTACK_KNOCKBACK);
|
||||
|
||||
meta.persistentDataContainer.set(
|
||||
PLUGIN.namespacedKeyFactory.create("tier"),
|
||||
PersistentDataType.STRING,
|
||||
tier.id
|
||||
)
|
||||
val slot = getSlot(itemStack) ?: return
|
||||
val armor = tier.properties[slot]!!.armor()
|
||||
val toughness = tier.properties[slot]!!.toughness()
|
||||
val knockback = tier.properties[slot]!!.knockback()
|
||||
val speed = tier.properties[slot]!!.speed()
|
||||
val attackSpeed = tier.properties[slot]!!.attackSpeed()
|
||||
val attackDamage = tier.properties[slot]!!.attackDamage()
|
||||
val attackKnockback = tier.properties[slot]!!.attackKnockback()
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_ARMOR)
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS)
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_KNOCKBACK_RESISTANCE)
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED)
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_ATTACK_SPEED)
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE)
|
||||
meta.removeAttributeModifier(Attribute.GENERIC_ATTACK_KNOCKBACK)
|
||||
if (armor > 0) {
|
||||
meta.addAttributeModifier(
|
||||
Attribute.GENERIC_ARMOR,
|
||||
new AttributeModifier(UUID.randomUUID(), "ecoarmor-armor", armor, AttributeModifier.Operation.ADD_NUMBER, slot.getSlot())
|
||||
);
|
||||
Attribute.GENERIC_ARMOR,
|
||||
AttributeModifier(
|
||||
UUID.randomUUID(),
|
||||
"ecoarmor-armor",
|
||||
armor.toDouble(),
|
||||
AttributeModifier.Operation.ADD_NUMBER,
|
||||
slot.slot
|
||||
)
|
||||
)
|
||||
}
|
||||
if (toughness > 0) {
|
||||
meta.addAttributeModifier(
|
||||
Attribute.GENERIC_ARMOR_TOUGHNESS,
|
||||
new AttributeModifier(UUID.randomUUID(), "ecoarmor-toughness", toughness, AttributeModifier.Operation.ADD_NUMBER, slot.getSlot())
|
||||
);
|
||||
Attribute.GENERIC_ARMOR_TOUGHNESS,
|
||||
AttributeModifier(
|
||||
UUID.randomUUID(),
|
||||
"ecoarmor-toughness",
|
||||
toughness.toDouble(),
|
||||
AttributeModifier.Operation.ADD_NUMBER,
|
||||
slot.slot
|
||||
)
|
||||
)
|
||||
}
|
||||
if (knockback > 0) {
|
||||
meta.addAttributeModifier(
|
||||
Attribute.GENERIC_KNOCKBACK_RESISTANCE,
|
||||
new AttributeModifier(UUID.randomUUID(), "ecoarmor-knockback", (double) knockback / 10, AttributeModifier.Operation.ADD_NUMBER, slot.getSlot())
|
||||
);
|
||||
Attribute.GENERIC_KNOCKBACK_RESISTANCE,
|
||||
AttributeModifier(
|
||||
UUID.randomUUID(),
|
||||
"ecoarmor-knockback",
|
||||
knockback.toDouble() / 10,
|
||||
AttributeModifier.Operation.ADD_NUMBER,
|
||||
slot.slot
|
||||
)
|
||||
)
|
||||
}
|
||||
if (speed != 0) {
|
||||
meta.addAttributeModifier(
|
||||
Attribute.GENERIC_MOVEMENT_SPEED,
|
||||
new AttributeModifier(UUID.randomUUID(), "ecoarmor-speed", (double) speed / 100, AttributeModifier.Operation.ADD_SCALAR, slot.getSlot())
|
||||
);
|
||||
Attribute.GENERIC_MOVEMENT_SPEED,
|
||||
AttributeModifier(
|
||||
UUID.randomUUID(),
|
||||
"ecoarmor-speed",
|
||||
speed.toDouble() / 100,
|
||||
AttributeModifier.Operation.ADD_SCALAR,
|
||||
slot.slot
|
||||
)
|
||||
)
|
||||
}
|
||||
if (attackSpeed != 0) {
|
||||
meta.addAttributeModifier(
|
||||
Attribute.GENERIC_ATTACK_SPEED,
|
||||
new AttributeModifier(UUID.randomUUID(), "ecoarmor-attackspeed", (double) attackSpeed / 100, AttributeModifier.Operation.ADD_SCALAR, slot.getSlot())
|
||||
);
|
||||
Attribute.GENERIC_ATTACK_SPEED,
|
||||
AttributeModifier(
|
||||
UUID.randomUUID(),
|
||||
"ecoarmor-attackspeed",
|
||||
attackSpeed.toDouble() / 100,
|
||||
AttributeModifier.Operation.ADD_SCALAR,
|
||||
slot.slot
|
||||
)
|
||||
)
|
||||
}
|
||||
if (attackDamage != 0) {
|
||||
meta.addAttributeModifier(
|
||||
Attribute.GENERIC_ATTACK_DAMAGE,
|
||||
new AttributeModifier(UUID.randomUUID(), "ecoarmor-attackdamage", (double) attackDamage / 100, AttributeModifier.Operation.ADD_SCALAR, slot.getSlot())
|
||||
);
|
||||
Attribute.GENERIC_ATTACK_DAMAGE,
|
||||
AttributeModifier(
|
||||
UUID.randomUUID(),
|
||||
"ecoarmor-attackdamage",
|
||||
attackDamage.toDouble() / 100,
|
||||
AttributeModifier.Operation.ADD_SCALAR,
|
||||
slot.slot
|
||||
)
|
||||
)
|
||||
}
|
||||
if (attackKnockback != 0) {
|
||||
meta.addAttributeModifier(
|
||||
Attribute.GENERIC_ATTACK_KNOCKBACK,
|
||||
new AttributeModifier(UUID.randomUUID(), "ecoarmor-attackknockback", (double) attackKnockback / 100, AttributeModifier.Operation.ADD_SCALAR, slot.getSlot())
|
||||
);
|
||||
Attribute.GENERIC_ATTACK_KNOCKBACK,
|
||||
AttributeModifier(
|
||||
UUID.randomUUID(),
|
||||
"ecoarmor-attackknockback",
|
||||
attackKnockback.toDouble() / 100,
|
||||
AttributeModifier.Operation.ADD_SCALAR,
|
||||
slot.slot
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
itemStack.itemMeta = meta
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,22 +309,20 @@ public class ArmorUtils {
|
||||
* @param player The player to check.
|
||||
* @return If advanced.
|
||||
*/
|
||||
public static boolean isWearingAdvanced(@NotNull final Player player) {
|
||||
@JvmStatic
|
||||
fun isWearingAdvanced(player: Player): Boolean {
|
||||
if (getSetOnPlayer(player) == null) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
for (ItemStack itemStack : player.getInventory().getArmorContents()) {
|
||||
for (itemStack in player.inventory.armorContents) {
|
||||
if (itemStack == null) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
if (!isAdvanced(itemStack)) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,14 +331,10 @@ public class ArmorUtils {
|
||||
* @param itemStack The item to check.
|
||||
* @return If advanced.
|
||||
*/
|
||||
public static boolean isAdvanced(@NotNull final ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isAdvanced(meta);
|
||||
@JvmStatic
|
||||
fun isAdvanced(itemStack: ItemStack): Boolean {
|
||||
val meta = itemStack.itemMeta ?: return false
|
||||
return isAdvanced(meta)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,12 +343,18 @@ public class ArmorUtils {
|
||||
* @param meta The item to check.
|
||||
* @return If advanced.
|
||||
*/
|
||||
public static boolean isAdvanced(@NotNull final ItemMeta meta) {
|
||||
if (meta.getPersistentDataContainer().has(PLUGIN.getNamespacedKeyFactory().create("advanced"), PersistentDataType.INTEGER)) {
|
||||
return meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("advanced"), PersistentDataType.INTEGER) == 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
@JvmStatic
|
||||
fun isAdvanced(meta: ItemMeta): Boolean {
|
||||
return if (meta.persistentDataContainer.has(
|
||||
PLUGIN.namespacedKeyFactory.create("advanced"),
|
||||
PersistentDataType.INTEGER
|
||||
)
|
||||
) {
|
||||
meta.persistentDataContainer.get(
|
||||
PLUGIN.namespacedKeyFactory.create("advanced"),
|
||||
PersistentDataType.INTEGER
|
||||
) == 1
|
||||
} else false
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,17 +363,18 @@ public class ArmorUtils {
|
||||
* @param itemStack The item to set.
|
||||
* @param advanced If the item should be advanced.
|
||||
*/
|
||||
public static void setAdvanced(@NotNull final ItemStack itemStack,
|
||||
final boolean advanced) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
meta.getPersistentDataContainer().set(PLUGIN.getNamespacedKeyFactory().create("advanced"), PersistentDataType.INTEGER, advanced ? 1 : 0);
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
@JvmStatic
|
||||
fun setAdvanced(
|
||||
itemStack: ItemStack,
|
||||
advanced: Boolean
|
||||
) {
|
||||
val meta = itemStack.itemMeta ?: return
|
||||
meta.persistentDataContainer.set(
|
||||
PLUGIN.namespacedKeyFactory.create("advanced"),
|
||||
PersistentDataType.INTEGER,
|
||||
if (advanced) 1 else 0
|
||||
)
|
||||
itemStack.itemMeta = meta
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -366,15 +383,10 @@ public class ArmorUtils {
|
||||
* @param itemStack The item to check.
|
||||
* @return The set, or null if not a shard.
|
||||
*/
|
||||
@Nullable
|
||||
public static ArmorSet getShardSet(@NotNull final ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getShardSet(meta);
|
||||
@JvmStatic
|
||||
fun getShardSet(itemStack: ItemStack): ArmorSet? {
|
||||
val meta = itemStack.itemMeta ?: return null
|
||||
return getShardSet(meta)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -383,14 +395,14 @@ public class ArmorUtils {
|
||||
* @param meta The item to check.
|
||||
* @return The set, or null if not a shard.
|
||||
*/
|
||||
@Nullable
|
||||
public static ArmorSet getShardSet(@NotNull final ItemMeta meta) {
|
||||
String shardSet = meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("advancement-shard"), PersistentDataType.STRING);
|
||||
|
||||
if (shardSet == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ArmorSets.getByID(shardSet);
|
||||
@JvmStatic
|
||||
fun getShardSet(meta: ItemMeta): ArmorSet? {
|
||||
val shardSet = meta.persistentDataContainer.get(
|
||||
PLUGIN.namespacedKeyFactory.create(
|
||||
"advancement-shard"
|
||||
), PersistentDataType.STRING
|
||||
)
|
||||
?: return null
|
||||
return ArmorSets.getByID(shardSet)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.willfp.ecoarmor.sets
|
||||
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
import org.bukkit.event.Listener
|
||||
|
||||
@@ -2,7 +2,7 @@ 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 com.willfp.ecoarmor.sets.ArmorUtils
|
||||
import org.bukkit.GameMode
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.event.EventHandler
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.willfp.ecoarmor.upgrades
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils
|
||||
import org.bukkit.GameMode
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.event.EventHandler
|
||||
|
||||
@@ -1,192 +1,153 @@
|
||||
package com.willfp.ecoarmor.upgrades;
|
||||
package com.willfp.ecoarmor.upgrades
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
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.ArmorSlot;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.NamespacedKey;
|
||||
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 org.jetbrains.annotations.Nullable;
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.PluginDependent
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.eco.core.display.Display
|
||||
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.ArmorSlot
|
||||
import com.willfp.ecoarmor.sets.ArmorUtils.getCrystalTier
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import java.util.*
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Tier extends PluginDependent<EcoPlugin> {
|
||||
class Tier(
|
||||
config: Config,
|
||||
plugin: EcoPlugin
|
||||
) : PluginDependent<EcoPlugin?>(plugin) {
|
||||
/**
|
||||
* The tier name.
|
||||
*/
|
||||
@Getter
|
||||
private final String id;
|
||||
val id: String
|
||||
|
||||
/**
|
||||
* The config of the crystal.
|
||||
*/
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private final Config config;
|
||||
val config: Config
|
||||
|
||||
/**
|
||||
* The display name of the crystal.
|
||||
*/
|
||||
@Getter
|
||||
private String displayName;
|
||||
val displayName: String
|
||||
|
||||
/**
|
||||
* The names of the tiers required for application.
|
||||
*/
|
||||
private List<String> requiredTiersForApplication;
|
||||
private val requiredTiersForApplication: List<String>
|
||||
|
||||
/**
|
||||
* If the crafting recipe is enabled.
|
||||
*/
|
||||
@Getter
|
||||
private boolean craftable;
|
||||
val craftable: Boolean
|
||||
|
||||
/**
|
||||
* The ItemStack of the crystal.
|
||||
*/
|
||||
@Getter
|
||||
private ItemStack crystal;
|
||||
val crystal: ItemStack
|
||||
|
||||
/**
|
||||
* The crafting recipe to make the crystal.
|
||||
*/
|
||||
@Getter
|
||||
private ShapedCraftingRecipe crystalRecipe;
|
||||
val crystalRecipe: ShapedCraftingRecipe?
|
||||
|
||||
/**
|
||||
* Item properties.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<ArmorSlot, TierProperties> properties = new HashMap<>();
|
||||
val properties: MutableMap<ArmorSlot, TierProperties> = EnumMap(ArmorSlot::class.java)
|
||||
|
||||
/**
|
||||
* Create a new Tier.
|
||||
*
|
||||
* @param config The config of the tier.
|
||||
* @param plugin Instance of EcoArmor.
|
||||
*/
|
||||
public Tier(@NotNull final Config config,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
this.id = config.getString("id");
|
||||
this.config = config;
|
||||
|
||||
Tiers.addNewTier(this);
|
||||
this.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the tracker's crafting recipe.
|
||||
*/
|
||||
public void update() {
|
||||
this.craftable = this.getConfig().getBool("crystal.craftable");
|
||||
this.displayName = this.getConfig().getString("display");
|
||||
this.requiredTiersForApplication = this.getConfig().getStrings("requiresTiers");
|
||||
NamespacedKey key = this.getPlugin().getNamespacedKeyFactory().create("upgrade_crystal");
|
||||
|
||||
ItemStack out = Items.lookup(this.getPlugin().getConfigYml().getString("upgrade-crystal-material").toLowerCase()).getItem();
|
||||
ItemMeta outMeta = out.getItemMeta();
|
||||
assert outMeta != null;
|
||||
PersistentDataContainer container = outMeta.getPersistentDataContainer();
|
||||
container.set(key, PersistentDataType.STRING, id);
|
||||
|
||||
outMeta.setDisplayName(this.getConfig().getString("crystal.name"));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String loreLine : this.getConfig().getStrings("crystal.lore")) {
|
||||
lore.add(Display.PREFIX + StringUtils.format(loreLine));
|
||||
init {
|
||||
id = config.getString("id")
|
||||
this.config = config
|
||||
Tiers.addNewTier(this)
|
||||
|
||||
craftable = this.config.getBool("crystal.craftable")
|
||||
displayName = this.config.getString("display")
|
||||
requiredTiersForApplication = this.config.getStrings("requiresTiers")
|
||||
val key = plugin.namespacedKeyFactory.create("upgrade_crystal")
|
||||
val out =
|
||||
Items.lookup(plugin.configYml.getString("upgrade-crystal-material").lowercase(Locale.getDefault())).item
|
||||
val outMeta = out.itemMeta!!
|
||||
val container = outMeta.persistentDataContainer
|
||||
container.set(key, PersistentDataType.STRING, id)
|
||||
outMeta.displayName = this.config.getString("crystal.name")
|
||||
val lore: MutableList<String> = ArrayList()
|
||||
for (loreLine in this.config.getStrings("crystal.lore")) {
|
||||
lore.add(Display.PREFIX + StringUtils.format(loreLine!!))
|
||||
}
|
||||
outMeta.setLore(lore);
|
||||
|
||||
out.setItemMeta(outMeta);
|
||||
out.setAmount(1); // who knows
|
||||
this.crystal = out;
|
||||
|
||||
for (ArmorSlot slot : ArmorSlot.values()) {
|
||||
properties.put(slot, new TierProperties(
|
||||
this.getConfig().getInt("properties." + slot.name().toLowerCase() + ".armor"),
|
||||
this.getConfig().getInt("properties." + slot.name().toLowerCase() + ".toughness"),
|
||||
this.getConfig().getInt("properties." + slot.name().toLowerCase() + ".knockbackResistance"),
|
||||
this.getConfig().getInt("properties." + slot.name().toLowerCase() + ".speedPercentage"),
|
||||
this.getConfig().getInt("properties." + slot.name().toLowerCase() + ".attackSpeedPercentage"),
|
||||
this.getConfig().getInt("properties." + slot.name().toLowerCase() + ".attackDamagePercentage"),
|
||||
this.getConfig().getInt("properties." + slot.name().toLowerCase() + ".attackKnockbackPercentage")
|
||||
));
|
||||
outMeta.lore = lore
|
||||
out.itemMeta = outMeta
|
||||
out.amount = 1 // who knows
|
||||
crystal = out
|
||||
for (slot in ArmorSlot.values()) {
|
||||
properties[slot] = TierProperties(
|
||||
this.config.getInt("properties." + slot.name.lowercase(Locale.getDefault()) + ".armor"),
|
||||
this.config.getInt("properties." + slot.name.lowercase(Locale.getDefault()) + ".toughness"),
|
||||
this.config
|
||||
.getInt("properties." + slot.name.lowercase(Locale.getDefault()) + ".knockbackResistance"),
|
||||
this.config.getInt("properties." + slot.name.lowercase(Locale.getDefault()) + ".speedPercentage"),
|
||||
this.config
|
||||
.getInt("properties." + slot.name.lowercase(Locale.getDefault()) + ".attackSpeedPercentage"),
|
||||
this.config
|
||||
.getInt("properties." + slot.name.lowercase(Locale.getDefault()) + ".attackDamagePercentage"),
|
||||
this.config
|
||||
.getInt("properties." + slot.name.lowercase(Locale.getDefault()) + ".attackKnockbackPercentage")
|
||||
)
|
||||
}
|
||||
|
||||
new CustomItem(
|
||||
this.getPlugin().getNamespacedKeyFactory().create("crystal_" + id.toLowerCase()),
|
||||
test -> this.equals(ArmorUtils.getCrystalTier(test)),
|
||||
out
|
||||
).register();
|
||||
|
||||
if (this.isCraftable()) {
|
||||
ItemStack recipeOut = out.clone();
|
||||
recipeOut.setAmount(this.getConfig().getInt("crystal.giveAmount"));
|
||||
ShapedCraftingRecipe.Builder builder = ShapedCraftingRecipe.builder(this.getPlugin(), "upgrade_crystal_" + id)
|
||||
.setOutput(recipeOut);
|
||||
|
||||
List<String> recipeStrings = this.getConfig().getStrings("crystal.recipe");
|
||||
|
||||
new CustomItem(this.getPlugin().getNamespacedKeyFactory().create("upgrade_crystal_" + id), test -> {
|
||||
CustomItem(
|
||||
plugin.namespacedKeyFactory.create("crystal_" + id.lowercase(Locale.getDefault())),
|
||||
{ test: ItemStack? -> this == getCrystalTier(test!!) },
|
||||
out
|
||||
).register()
|
||||
if (this.craftable) {
|
||||
val recipeOut = out.clone()
|
||||
recipeOut.amount = this.config.getInt("crystal.giveAmount")
|
||||
val builder = ShapedCraftingRecipe.builder(plugin, "upgrade_crystal_$id")
|
||||
.setOutput(recipeOut)
|
||||
val recipeStrings: List<String> = this.config.getStrings("crystal.recipe")
|
||||
CustomItem(plugin.namespacedKeyFactory.create("upgrade_crystal_$id"), { test: ItemStack? ->
|
||||
if (test == null) {
|
||||
return false;
|
||||
return@CustomItem false
|
||||
}
|
||||
if (ArmorUtils.getCrystalTier(test) == null) {
|
||||
return false;
|
||||
if (getCrystalTier(test) == null) {
|
||||
return@CustomItem false
|
||||
}
|
||||
return this.equals(ArmorUtils.getCrystalTier(test));
|
||||
}, out).register();
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
builder.setRecipePart(i, Items.lookup(recipeStrings.get(i)));
|
||||
this == getCrystalTier(test)
|
||||
}, out).register()
|
||||
for (i in 0..8) {
|
||||
builder.setRecipePart(i, Items.lookup(recipeStrings[i]))
|
||||
}
|
||||
|
||||
this.crystalRecipe = builder.build();
|
||||
this.crystalRecipe.register();
|
||||
crystalRecipe = builder.build()
|
||||
crystalRecipe.register()
|
||||
} else {
|
||||
crystalRecipe = null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the required tiers for application.
|
||||
*
|
||||
* @return The tiers, or a blank list if always available.
|
||||
*/
|
||||
public List<Tier> getRequiredTiersForApplication() {
|
||||
return requiredTiersForApplication.stream().map(Tiers::getByID).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
fun getRequiredTiersForApplication(): List<Tier> {
|
||||
return requiredTiersForApplication.mapNotNull { Tiers.getByID(it) }
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) {
|
||||
return true
|
||||
}
|
||||
if (!(o instanceof Tier)) {
|
||||
return false;
|
||||
if (other !is Tier) {
|
||||
return false
|
||||
}
|
||||
|
||||
Tier tier = (Tier) o;
|
||||
return Objects.equals(this.getId(), tier.getId());
|
||||
return this.id == other.id
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.getId());
|
||||
override fun hashCode(): Int {
|
||||
return Objects.hash(this.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.ecoarmor.upgrades
|
||||
|
||||
data class TierProperties(
|
||||
val armor: Int,
|
||||
val toughness: Int,
|
||||
val knockback: Int,
|
||||
val speed: Int,
|
||||
val attackSpeed: Int,
|
||||
val attackDamage: Int,
|
||||
val attackKnockback: Int
|
||||
)
|
||||
@@ -1,59 +1,53 @@
|
||||
package com.willfp.ecoarmor.upgrades;
|
||||
package com.willfp.ecoarmor.upgrades
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater;
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.google.common.collect.BiMap
|
||||
import com.google.common.collect.HashBiMap
|
||||
import com.google.common.collect.ImmutableList
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin.Companion.instance
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
public class Tiers {
|
||||
object Tiers {
|
||||
/**
|
||||
* Registered tiers.
|
||||
*/
|
||||
private static final BiMap<String, Tier> BY_ID = HashBiMap.create();
|
||||
private val BY_ID: BiMap<String?, Tier> = HashBiMap.create()
|
||||
|
||||
/**
|
||||
* Default tier.
|
||||
*/
|
||||
@Getter
|
||||
private static Tier defaultTier;
|
||||
lateinit var defaultTier: Tier
|
||||
|
||||
/**
|
||||
* Get {@link Tiers} matching ID.
|
||||
* Get [Tiers] matching ID.
|
||||
*
|
||||
* @param name The name to search for.
|
||||
* @return The matching {@link Tiers}, or null if not found.
|
||||
* @return The matching [Tiers], or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public static Tier getByID(@Nullable final String name) {
|
||||
return BY_ID.get(name);
|
||||
@JvmStatic
|
||||
fun getByID(name: String?): Tier? {
|
||||
return BY_ID[name]
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all registered {@link Tiers}s.
|
||||
* Get all registered [Tiers]s.
|
||||
*
|
||||
* @return A list of all {@link Tiers}s.
|
||||
* @return A list of all [Tiers]s.
|
||||
*/
|
||||
public static List<Tier> values() {
|
||||
return ImmutableList.copyOf(BY_ID.values());
|
||||
@JvmStatic
|
||||
fun values(): List<Tier> {
|
||||
return ImmutableList.copyOf(BY_ID.values)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new {@link Tier} to EcoArmor.
|
||||
* Add new [Tier] to EcoArmor.
|
||||
*
|
||||
* @param tier The {@link Tier} to add.
|
||||
* @param tier The [Tier] to add.
|
||||
*/
|
||||
public static void addNewTier(@NotNull final Tier tier) {
|
||||
BY_ID.remove(tier.getId());
|
||||
BY_ID.put(tier.getId(), tier);
|
||||
@JvmStatic
|
||||
fun addNewTier(tier: Tier) {
|
||||
BY_ID.remove(tier.id)
|
||||
BY_ID[tier.id] = tier
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,17 +56,16 @@ public class Tiers {
|
||||
* @param plugin Instance of EcoArmor.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void reload(@NotNull final EcoArmorPlugin plugin) {
|
||||
BY_ID.clear();
|
||||
|
||||
for (Config tierConfig : plugin.getEcoArmorYml().getSubsections("tiers")) {
|
||||
new Tier(tierConfig, plugin);
|
||||
@JvmStatic
|
||||
fun reload(plugin: EcoArmorPlugin) {
|
||||
BY_ID.clear()
|
||||
for (tierConfig in plugin.ecoArmorYml.getSubsections("tiers")) {
|
||||
Tier(tierConfig, plugin)
|
||||
}
|
||||
|
||||
defaultTier = Tiers.getByID("default");
|
||||
defaultTier = getByID("default")!!
|
||||
}
|
||||
|
||||
static {
|
||||
reload(EcoArmorPlugin.getInstance());
|
||||
init {
|
||||
reload(instance)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user