mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-19 15:09:26 +00:00
Added upgrade crystals
This commit is contained in:
@@ -14,6 +14,7 @@ import com.willfp.ecoarmor.display.packets.PacketSetSlot;
|
||||
import com.willfp.ecoarmor.display.packets.PacketWindowItems;
|
||||
import com.willfp.ecoarmor.effects.Effects;
|
||||
import com.willfp.ecoarmor.sets.ArmorSets;
|
||||
import com.willfp.ecoarmor.tiers.CrystalListener;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -116,7 +117,7 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
|
||||
@Override
|
||||
public List<Listener> getListeners() {
|
||||
return Arrays.asList(
|
||||
|
||||
new CrystalListener(this)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.willfp.ecoarmor.display;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.ecoarmor.sets.ArmorSet;
|
||||
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import com.willfp.ecoarmor.tiers.UpgradeCrystal;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
@@ -60,12 +61,11 @@ public class ArmorDisplay {
|
||||
* @return The itemStack, updated.
|
||||
*/
|
||||
public static ItemStack display(@Nullable final ItemStack itemStack) {
|
||||
if (itemStack == null || itemStack.getItemMeta() == null || itemStack.getType() != Material.PLAYER_HEAD) {
|
||||
if (itemStack == null || itemStack.getItemMeta() == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
ArmorSlot slot = ArmorSlot.getSlot(itemStack);
|
||||
|
||||
if (slot == null) {
|
||||
return itemStack;
|
||||
}
|
||||
@@ -80,6 +80,15 @@ public class ArmorDisplay {
|
||||
ArmorSet set = ArmorUtils.getSetOnItem(itemStack);
|
||||
|
||||
if (set == null) {
|
||||
String crystalTier = ArmorUtils.getCrystalTier(itemStack);
|
||||
UpgradeCrystal crystal = UpgradeCrystal.getByName(crystalTier);
|
||||
|
||||
if (crystalTier == null || crystal == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
meta.setLore(UpgradeCrystal.getByName(crystalTier).getItemStack().getItemMeta().getLore());
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@@ -87,7 +96,15 @@ public class ArmorDisplay {
|
||||
ItemMeta slotMeta = slotStack.getItemMeta();
|
||||
assert slotMeta != null;
|
||||
|
||||
meta.setLore(slotMeta.getLore());
|
||||
String tier = ArmorUtils.getTier(itemStack);
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
for (String s : slotMeta.getLore()) {
|
||||
lore.add(s.replace("%tier%", Configs.CONFIG.getString("tier." + tier + ".display")));
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(slotMeta.getDisplayName());
|
||||
|
||||
if (meta instanceof SkullMeta && slotMeta instanceof SkullMeta) {
|
||||
@@ -99,6 +116,7 @@ public class ArmorDisplay {
|
||||
}
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.effects.Effects;
|
||||
import com.willfp.ecoarmor.proxy.proxies.SkullProxy;
|
||||
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
|
||||
import com.willfp.ecoarmor.sets.meta.ArmorTier;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
@@ -129,7 +128,7 @@ public class ArmorSet {
|
||||
enchants.forEach((enchantment, integer) -> meta.addEnchant(enchantment, integer, true));
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(PLUGIN.getNamespacedKeyFactory().create("set"), PersistentDataType.STRING, name);
|
||||
container.set(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING, ArmorTier.DEFAULT);
|
||||
container.set(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING, "default");
|
||||
itemStack.setItemMeta(meta);
|
||||
|
||||
constructRecipe(slot, itemStack);
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.willfp.ecoarmor.sets.meta;
|
||||
|
||||
public class ArmorTier {
|
||||
/**
|
||||
* Default tier.
|
||||
*/
|
||||
public static final String DEFAULT = "default";
|
||||
|
||||
/**
|
||||
* Iron tier.
|
||||
*/
|
||||
public static final String IRON = "iron";
|
||||
|
||||
/**
|
||||
* Diamond tier.
|
||||
*/
|
||||
public static final String DIAMOND = "diamond";
|
||||
|
||||
/**
|
||||
* Netherite tier.
|
||||
*/
|
||||
public static final String NETHERITE = "netherite";
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.sets.ArmorSet;
|
||||
import com.willfp.ecoarmor.sets.ArmorSets;
|
||||
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -122,4 +123,74 @@ public class ArmorUtils {
|
||||
@NotNull final Effect effect) {
|
||||
return getEffectStrength(player, effect) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tier on upgrade crystal.
|
||||
*
|
||||
* @param itemStack The item to check.
|
||||
* @return The found tier, or null.
|
||||
*/
|
||||
@Nullable
|
||||
public static String getCrystalTier(@NotNull final ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (meta.getPersistentDataContainer().has(PLUGIN.getNamespacedKeyFactory().create("upgrade_crystal"), PersistentDataType.STRING)) {
|
||||
return meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("upgrade_crystal"), PersistentDataType.STRING);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tier on item.
|
||||
*
|
||||
* @param itemStack The item to check.
|
||||
* @return The found tier.
|
||||
*/
|
||||
public static String getTier(@NotNull final ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return "default";
|
||||
}
|
||||
|
||||
if (meta.getPersistentDataContainer().has(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING)) {
|
||||
return meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING);
|
||||
}
|
||||
|
||||
return "default";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tier on item.
|
||||
*
|
||||
* @param itemStack The item to check.
|
||||
* @param tier The tier to set.
|
||||
*/
|
||||
public static void setTier(@NotNull final ItemStack itemStack,
|
||||
@NotNull final String tier) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getSetOnItem(itemStack) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
meta.getPersistentDataContainer().set(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING, tier);
|
||||
|
||||
ArmorSlot slot = ArmorSlot.getSlot(itemStack);
|
||||
|
||||
if (slot == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.willfp.ecoarmor.tiers;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
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.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CrystalListener extends PluginDependent implements Listener {
|
||||
/**
|
||||
* Create new listeners for dragging crystals onto items.
|
||||
*
|
||||
* @param plugin The plugin to listen for.
|
||||
*/
|
||||
public CrystalListener(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for inventory click event.
|
||||
*
|
||||
* @param event The event to handle.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onDrag(@NotNull final InventoryClickEvent event) {
|
||||
ItemStack current = event.getCurrentItem();
|
||||
ItemStack cursor = event.getCursor();
|
||||
|
||||
if (current == null || cursor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cursor.getType() != Material.END_CRYSTAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
String tier = ArmorUtils.getCrystalTier(cursor);
|
||||
|
||||
if (tier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (current.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArmorUtils.setTier(current, tier);
|
||||
|
||||
event.getWhoClicked().setItemOnCursor(null);
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.willfp.ecoarmor.tiers;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.common.recipes.lookup.RecipePartUtils;
|
||||
import com.willfp.eco.common.recipes.parts.ComplexRecipePart;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.recipe.EcoShapedRecipe;
|
||||
import com.willfp.ecoarmor.display.ArmorDisplay;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class UpgradeCrystal {
|
||||
/**
|
||||
* Iron crystal.
|
||||
*/
|
||||
public static final UpgradeCrystal IRON = new UpgradeCrystal("iron");
|
||||
|
||||
/**
|
||||
* Diamond crystal.
|
||||
*/
|
||||
public static final UpgradeCrystal DIAMOND = new UpgradeCrystal("diamond");
|
||||
|
||||
/**
|
||||
* Netherite crystal.
|
||||
*/
|
||||
public static final UpgradeCrystal NETHERITE = new UpgradeCrystal("netherite");
|
||||
|
||||
/**
|
||||
* Registered crystals.
|
||||
*/
|
||||
private static final BiMap<String, UpgradeCrystal> BY_NAME = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* Instance of ItemStats to create keys for.
|
||||
*/
|
||||
@Getter
|
||||
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* The tier of the crystal.
|
||||
*/
|
||||
@Getter
|
||||
private final String tier;
|
||||
|
||||
/**
|
||||
* The ItemStack of the crystal.
|
||||
*/
|
||||
@Getter
|
||||
private ItemStack itemStack;
|
||||
|
||||
/**
|
||||
* The crafting recipe to make the crystal.
|
||||
*/
|
||||
@Getter
|
||||
private EcoShapedRecipe recipe;
|
||||
|
||||
/**
|
||||
* Create a new Upgrade Crystal.
|
||||
*
|
||||
* @param tier The tier to upgrade to.
|
||||
*/
|
||||
public UpgradeCrystal(@NotNull final String tier) {
|
||||
this.tier = tier;
|
||||
this.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the tracker's crafting recipe.
|
||||
*/
|
||||
public void update() {
|
||||
NamespacedKey key = this.getPlugin().getNamespacedKeyFactory().create("upgrade_crystal");
|
||||
|
||||
ItemStack out = new ItemStack(Material.END_CRYSTAL);
|
||||
ItemMeta outMeta = out.getItemMeta();
|
||||
assert outMeta != null;
|
||||
PersistentDataContainer container = outMeta.getPersistentDataContainer();
|
||||
container.set(key, PersistentDataType.STRING, tier);
|
||||
|
||||
outMeta.setDisplayName(Configs.CONFIG.getString("tier." + tier + ".crystal-name"));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String loreLine : Configs.CONFIG.getStrings("tier." + tier + ".crystal-lore")) {
|
||||
lore.add(ArmorDisplay.PREFIX + StringUtils.translate(loreLine));
|
||||
}
|
||||
outMeta.setLore(lore);
|
||||
|
||||
out.setItemMeta(outMeta);
|
||||
this.itemStack = out;
|
||||
|
||||
EcoShapedRecipe.Builder builder = EcoShapedRecipe.builder(this.getPlugin(), "upgrade_crystal_" + tier)
|
||||
.setOutput(out);
|
||||
|
||||
List<String> recipeStrings = Configs.CONFIG.getStrings("tier." + tier + ".crystal-recipe");
|
||||
|
||||
RecipePartUtils.registerLookup("ecoarmor:upgrade_crystal_" + tier, s -> new ComplexRecipePart(test -> Objects.equals(tier, ArmorUtils.getCrystalTier(test)), out));
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
builder.setRecipePart(i, RecipePartUtils.lookup(recipeStrings.get(i)));
|
||||
}
|
||||
|
||||
this.recipe = builder.build();
|
||||
this.recipe.register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link UpgradeCrystal} matching name.
|
||||
*
|
||||
* @param name The name to search for.
|
||||
* @return The matching {@link UpgradeCrystal}, or null if not found.
|
||||
*/
|
||||
public static UpgradeCrystal getByName(@Nullable final String name) {
|
||||
return BY_NAME.get(name);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,66 @@
|
||||
#
|
||||
# EcoArmor
|
||||
# by Auxilor
|
||||
#
|
||||
#
|
||||
|
||||
tier:
|
||||
default:
|
||||
display: "&8&lDEFAULT"
|
||||
# No crystal for default
|
||||
|
||||
iron:
|
||||
display: "&7&lIRON"
|
||||
crystal-name: "&7Iron Upgrade Crystal"
|
||||
crystal-recipe:
|
||||
- air
|
||||
- iron_block
|
||||
- air
|
||||
|
||||
- iron_block
|
||||
- leather_chestplate
|
||||
- iron_block
|
||||
|
||||
- air
|
||||
- iron_block
|
||||
- air
|
||||
crystal-lore:
|
||||
- "&8Drop this onto an item to set its tier to"
|
||||
- "&7&lIRON"
|
||||
|
||||
diamond:
|
||||
display: "&b&lDIAMOND"
|
||||
crystal-name: "&bDiamond Upgrade Crystal"
|
||||
crystal-recipe:
|
||||
- air
|
||||
- diamond_block
|
||||
- air
|
||||
|
||||
- diamond_block
|
||||
- ecoarmor:upgrade_crystal_iron
|
||||
- diamond_block
|
||||
|
||||
- air
|
||||
- diamond_block
|
||||
- air
|
||||
crystal-lore:
|
||||
- "&8Drop this onto an item to set its tier to"
|
||||
- "&b&lDIAMOND"
|
||||
|
||||
netherite:
|
||||
display: "&c&lNETHERITE"
|
||||
crystal-name: "&cNetherite Upgrade Crystal"
|
||||
crystal-recipe:
|
||||
- air
|
||||
- netherite_block
|
||||
- air
|
||||
|
||||
- netherite_block
|
||||
- ecoarmor:upgrade_crystal_diamond
|
||||
- netherite_block
|
||||
|
||||
- air
|
||||
- netherite_block
|
||||
- air
|
||||
crystal-lore:
|
||||
- "&8Drop this onto an item to set its tier to"
|
||||
- "&c&lNETHERITE"
|
||||
|
||||
@@ -16,7 +16,7 @@ Reaper:
|
||||
- "&8&oRequires full set to be worn"
|
||||
- ""
|
||||
- "&fTier: %tier%"
|
||||
- "&8&oUpgrade with a Tier Upgrader"
|
||||
- "&8&oUpgrade with an Upgrade Crystal"
|
||||
recipe:
|
||||
- air
|
||||
- nether_star
|
||||
@@ -44,7 +44,7 @@ Reaper:
|
||||
- "&8&oRequires full set to be worn"
|
||||
- ""
|
||||
- "&fTier: %tier%"
|
||||
- "&8&oUpgrade with a Tier Upgrader"
|
||||
- "&8&oUpgrade with a Upgrade Crystal"
|
||||
recipe:
|
||||
- air
|
||||
- nether_star
|
||||
@@ -71,7 +71,7 @@ Reaper:
|
||||
- "&8&oRequires full set to be worn"
|
||||
- ""
|
||||
- "&fTier: %tier%"
|
||||
- "&8&oUpgrade with a Tier Upgrader"
|
||||
- "&8&oUpgrade with a Upgrade Crystal"
|
||||
recipe:
|
||||
- air
|
||||
- nether_star
|
||||
@@ -99,7 +99,7 @@ Reaper:
|
||||
- "&8&oRequires full set to be worn"
|
||||
- ""
|
||||
- "&fTier: %tier%"
|
||||
- "&8&oUpgrade with a Tier Upgrader"
|
||||
- "&8&oUpgrade with a Upgrade Crystal"
|
||||
recipe:
|
||||
- air
|
||||
- nether_star
|
||||
@@ -127,7 +127,7 @@ Reaper:
|
||||
- "&8&oRequires full set to be worn"
|
||||
- ""
|
||||
- "&fTier: %tier%"
|
||||
- "&8&oUpgrade with a Tier Upgrader"
|
||||
- "&8&oUpgrade with a Upgrade Crystal"
|
||||
recipe:
|
||||
- air
|
||||
- nether_star
|
||||
|
||||
Reference in New Issue
Block a user