diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java index a20c403..a749cc4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java @@ -13,9 +13,7 @@ import com.willfp.ecoarmor.display.ArmorDisplay; import com.willfp.ecoarmor.effects.Effect; import com.willfp.ecoarmor.effects.Effects; import com.willfp.ecoarmor.effects.util.EffectWatcher; -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.EffectiveDurabilityListener; import com.willfp.ecoarmor.sets.util.PreventSkullPlaceListener; import com.willfp.ecoarmor.upgrades.Tiers; @@ -23,7 +21,6 @@ import com.willfp.ecoarmor.upgrades.listeners.AdvancementShardListener; import com.willfp.ecoarmor.upgrades.listeners.CrystalListener; import com.willfp.ecoarmor.util.DiscoverRecipeListener; import lombok.Getter; -import org.bukkit.Bukkit; import org.bukkit.event.Listener; import org.jetbrains.annotations.Nullable; @@ -63,6 +60,7 @@ public class EcoArmorPlugin extends EcoPlugin { Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect)); Conditions.values().forEach(condition -> this.getEventManager().registerListener(condition)); + this.getScheduler().runTimer((Runnable) Conditions.HAS_PERMISSION, 100, 100); } /** diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java index e607f5e..a36ad5d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java @@ -11,6 +11,7 @@ import com.willfp.ecoarmor.conditions.conditions.ConditionBelowHealthPercent; import com.willfp.ecoarmor.conditions.conditions.ConditionBelowHungerPercent; import com.willfp.ecoarmor.conditions.conditions.ConditionBelowXPLevel; import com.willfp.ecoarmor.conditions.conditions.ConditionBelowY; +import com.willfp.ecoarmor.conditions.conditions.ConditionHasPermission; import com.willfp.ecoarmor.conditions.conditions.ConditionInBiome; import com.willfp.ecoarmor.conditions.conditions.ConditionInWater; import com.willfp.ecoarmor.conditions.conditions.ConditionInWorld; @@ -38,6 +39,7 @@ public class Conditions { public static final Condition ABOVE_HUNGER_PERCENT = new ConditionAboveHungerPercent(); public static final Condition BELOW_HUNGER_PERCENT = new ConditionBelowHungerPercent(); public static final Condition IN_BIOME = new ConditionInBiome(); + public static final Condition HAS_PERMISSION = new ConditionHasPermission(); /** * Get condition matching name.s diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionHasPermission.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionHasPermission.java new file mode 100644 index 0000000..5581a23 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionHasPermission.java @@ -0,0 +1,39 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class ConditionHasPermission extends Condition implements Runnable { + public ConditionHasPermission() { + super("has-permission", String.class); + } + + @Override + public void run() { + for (Player player : Bukkit.getOnlinePlayers()) { + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + String value = set.getConditionValue(this); + + if (value == null) { + return; + } + + evaluateEffects(player, value, set); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final String value) { + return player.hasPermission(value); + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/display/ArmorDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/display/ArmorDisplay.java index ef2157f..6009912 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/display/ArmorDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/display/ArmorDisplay.java @@ -35,17 +35,17 @@ public class ArmorDisplay extends DisplayModule { return; } - ArmorSet set = ArmorUtils.getSetOnItem(itemStack); + ArmorSet set = ArmorUtils.getSetOnItem(meta); if (set == null) { - Tier crystalTier = ArmorUtils.getCrystalTier(itemStack); + Tier crystalTier = ArmorUtils.getCrystalTier(meta); if (crystalTier != null) { meta.setLore(crystalTier.getCrystal().getItemMeta().getLore()); itemStack.setItemMeta(meta); } - ArmorSet shardSet = ArmorUtils.getShardSet(itemStack); + ArmorSet shardSet = ArmorUtils.getShardSet(meta); if (shardSet != null) { itemStack.setItemMeta(shardSet.getAdvancementShardItem().getItemMeta()); @@ -61,7 +61,7 @@ public class ArmorDisplay extends DisplayModule { ItemStack slotStack; - if (ArmorUtils.isAdvanced(itemStack)) { + if (ArmorUtils.isAdvanced(meta)) { slotStack = set.getAdvancedItemStack(slot); } else { slotStack = set.getItemStack(slot); @@ -69,7 +69,7 @@ public class ArmorDisplay extends DisplayModule { ItemMeta slotMeta = slotStack.getItemMeta(); assert slotMeta != null; - Tier tier = ArmorUtils.getTier(itemStack); + Tier tier = ArmorUtils.getTier(meta); List lore = new ArrayList<>(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java index ddb8acc..cdd03e4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java @@ -17,6 +17,10 @@ public class Flight extends Effect { @Override protected void onDisable(@NotNull final Player player) { + if (player.hasPermission("ecoarmor.noflydisable")) { + return; + } + if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) { player.setAllowFlight(false); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java index d9a25e0..c3cf7df 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java @@ -358,7 +358,22 @@ public class ArmorSet { @NotNull final Config slotConfig, @NotNull final ItemStack out) { if (slotConfig.getBool("craftable")) { - ShapedCraftingRecipe.Builder builder = ShapedCraftingRecipe.builder(PLUGIN, this.getName() + "_" + slot.name().toLowerCase()).setOutput(out); + ItemStack formattedOut = out.clone(); + ItemMeta meta = formattedOut.getItemMeta(); + assert meta != null; + assert meta.getLore() != null; + + List lore = new ArrayList<>(); + + for (String s : meta.getLore()) { + s = s.replace("%tier%", Tiers.DEFAULT.getDisplayName()); + lore.add(s); + } + + meta.setLore(lore); + formattedOut.setItemMeta(meta); + + ShapedCraftingRecipe.Builder builder = ShapedCraftingRecipe.builder(PLUGIN, this.getName() + "_" + slot.name().toLowerCase()).setOutput(formattedOut); List recipeStrings = slotConfig.getStrings("recipe"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/meta/ArmorSlot.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/meta/ArmorSlot.java index 4097d3a..0efa279 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/meta/ArmorSlot.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/meta/ArmorSlot.java @@ -56,29 +56,24 @@ public enum ArmorSlot { } Material material = itemStack.getType(); - String name = material.name().toLowerCase(); + String[] split = material.name().toLowerCase().split("_"); + String name = split[split.length - 1]; - if (name.endsWith("helmet") || name.endsWith("head")) { - return HELMET; + switch (name) { + case "helmet": + case "head": + return HELMET; + case "chestplate": + return CHESTPLATE; + case "elytra": + return ELYTRA; + case "leggings": + return LEGGINGS; + case "boots": + return BOOTS; + default: + return null; } - - if (name.endsWith("chestplate")) { - return CHESTPLATE; - } - - if (name.endsWith("elytra")) { - return ELYTRA; - } - - if (name.endsWith("leggings")) { - return LEGGINGS; - } - - if (name.endsWith("boots")) { - return BOOTS; - } - - return null; } /** diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java index 06029f2..c5070ae 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java @@ -19,6 +19,7 @@ import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.xml.bind.annotation.XmlType; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -45,6 +46,17 @@ public class ArmorUtils { return null; } + return getSetOnItem(meta); + } + + /** + * Get armor set on an item. + * + * @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); @@ -133,6 +145,17 @@ public class ArmorUtils { return null; } + return getCrystalTier(meta); + } + + /** + * Get tier on upgrade crystal. + * + * @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.getByName(meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("upgrade_crystal"), PersistentDataType.STRING)); } @@ -154,7 +177,25 @@ public class ArmorUtils { return null; } - if (getSetOnItem(itemStack) == null) { + Tier tier = getTier(meta); + + if (getSetOnItem(meta) != null && tier == null) { + setTier(itemStack, Tiers.DEFAULT); + return Tiers.DEFAULT; + } else { + return tier; + } + } + + /** + * Get tier on item. + * + * @param meta The item to check. + * @return The found tier, or null if not found. + */ + @Nullable + public static Tier getTier(@NotNull final ItemMeta meta) { + if (getSetOnItem(meta) == null) { return null; } @@ -162,8 +203,7 @@ public class ArmorUtils { return Tiers.getByName(meta.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("tier"), PersistentDataType.STRING)); } - setTier(itemStack, Tiers.DEFAULT); - return getTier(itemStack); + return null; } /** @@ -290,6 +330,16 @@ public class ArmorUtils { return false; } + return isAdvanced(meta); + } + + /** + * Get if item is advanced. + * + * @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; } @@ -334,6 +384,17 @@ public class ArmorUtils { return null; } + return getShardSet(meta); + } + + /** + * Get the set from a shard. + * + * @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) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/listeners/AdvancementShardListener.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/listeners/AdvancementShardListener.java index 3811ccd..80834fc 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/listeners/AdvancementShardListener.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/listeners/AdvancementShardListener.java @@ -6,6 +6,7 @@ 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; @@ -32,6 +33,10 @@ public class AdvancementShardListener extends PluginDependent implements Listene */ @EventHandler public void onDrag(@NotNull final InventoryClickEvent event) { + if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE) { + return; + } + ItemStack current = event.getCurrentItem(); ItemStack cursor = event.getCursor(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/listeners/CrystalListener.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/listeners/CrystalListener.java index d0ae58b..98c73e6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/listeners/CrystalListener.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/upgrades/listeners/CrystalListener.java @@ -4,6 +4,7 @@ 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; @@ -31,6 +32,10 @@ public class CrystalListener extends PluginDependent implements Listener { */ @EventHandler public void onDrag(@NotNull final InventoryClickEvent event) { + if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE) { + return; + } + ItemStack current = event.getCurrentItem(); ItemStack cursor = event.getCursor(); @@ -52,9 +57,7 @@ public class CrystalListener extends PluginDependent implements Listener { boolean allowed = false; List prereq = crystalTier.getRequiredTiersForApplication(); - if (prereq.isEmpty()) { - allowed = true; - } else if (prereq.contains(previousTier)) { + if (prereq.isEmpty() || prereq.contains(previousTier)) { allowed = true; } diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index db267e0..3709680 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -37,6 +37,7 @@ permissions: children: ecoarmor.reload: true ecoarmor.give: true + ecoarmor.noflydisable: true ecoarmor.reload: description: Allows reloading the config @@ -44,3 +45,6 @@ permissions: ecoarmor.give: description: Allows the use of /eagive default: op + ecoarmor.noflydisable: + description: Prevents losing fly. + default: op diff --git a/eco-core/core-plugin/src/main/resources/tiers/cobalt.yml b/eco-core/core-plugin/src/main/resources/tiers/cobalt.yml index a348203..9d82028 100644 --- a/eco-core/core-plugin/src/main/resources/tiers/cobalt.yml +++ b/eco-core/core-plugin/src/main/resources/tiers/cobalt.yml @@ -21,6 +21,8 @@ crystal-lore: - "&8Drop this onto an armor piece" - "&8to set its tier to:" - "/ab&lCOBALT" + - "" + - "&8&oRequires the armor to already have Iron tier" properties: helmet: armor: 3 diff --git a/eco-core/core-plugin/src/main/resources/tiers/diamond.yml b/eco-core/core-plugin/src/main/resources/tiers/diamond.yml index def3793..aaf7933 100644 --- a/eco-core/core-plugin/src/main/resources/tiers/diamond.yml +++ b/eco-core/core-plugin/src/main/resources/tiers/diamond.yml @@ -21,6 +21,8 @@ crystal-lore: - "&8Drop this onto an armor piece" - "&8to set its tier to:" - "&b&lDIAMOND" + - "" + - "&8&oRequires the armor to already have Iron tier" properties: helmet: armor: 3 diff --git a/eco-core/core-plugin/src/main/resources/tiers/exotic.yml b/eco-core/core-plugin/src/main/resources/tiers/exotic.yml index 754127f..e315000 100644 --- a/eco-core/core-plugin/src/main/resources/tiers/exotic.yml +++ b/eco-core/core-plugin/src/main/resources/tiers/exotic.yml @@ -21,6 +21,8 @@ crystal-lore: - "&8Drop this onto an armor piece" - "&8to set its tier to:" - "&6&k!!&r &lEXOTIC&r &6&k!!&r" + - "" + - "&8&oRequires the armor to already have Netherite tier" properties: helmet: armor: 3 diff --git a/eco-core/core-plugin/src/main/resources/tiers/iron.yml b/eco-core/core-plugin/src/main/resources/tiers/iron.yml index 52a2398..36fc5a2 100644 --- a/eco-core/core-plugin/src/main/resources/tiers/iron.yml +++ b/eco-core/core-plugin/src/main/resources/tiers/iron.yml @@ -21,6 +21,8 @@ crystal-lore: - "&8Drop this onto an armor piece" - "&8to set its tier to:" - "&7&lIRON" + - "" + - "&8&oRequires the armor to already have default tier" properties: helmet: armor: 2 diff --git a/eco-core/core-plugin/src/main/resources/tiers/manyullyn.yml b/eco-core/core-plugin/src/main/resources/tiers/manyullyn.yml index f7b8ead..0276abe 100644 --- a/eco-core/core-plugin/src/main/resources/tiers/manyullyn.yml +++ b/eco-core/core-plugin/src/main/resources/tiers/manyullyn.yml @@ -21,6 +21,8 @@ crystal-lore: - "&8Drop this onto an armor piece" - "&8to set its tier to:" - "&d&k!!&r &lMANYULLYN&r &d&k!!&r" + - "" + - "&8&oRequires the armor to already have Netherite tier" properties: helmet: armor: 3 diff --git a/eco-core/core-plugin/src/main/resources/tiers/netherite.yml b/eco-core/core-plugin/src/main/resources/tiers/netherite.yml index cbcfa47..8782729 100644 --- a/eco-core/core-plugin/src/main/resources/tiers/netherite.yml +++ b/eco-core/core-plugin/src/main/resources/tiers/netherite.yml @@ -21,6 +21,8 @@ crystal-lore: - "&8Drop this onto an armor piece" - "&8to set its tier to:" - "&c&lNETHERITE" + - "" + - "&8&oRequires the armor to already have Diamond tier" properties: helmet: armor: 3 diff --git a/eco-core/core-plugin/src/main/resources/tiers/osmium.yml b/eco-core/core-plugin/src/main/resources/tiers/osmium.yml index 3de34eb..10b0a6c 100644 --- a/eco-core/core-plugin/src/main/resources/tiers/osmium.yml +++ b/eco-core/core-plugin/src/main/resources/tiers/osmium.yml @@ -21,6 +21,8 @@ crystal-lore: - "&8Drop this onto an armor piece" - "&8to set its tier to:" - "&b&k!!&r &lOSMIUM&r &b&k!!" + - "" + - "&8&oRequires the armor to already have Cobalt tier" properties: helmet: armor: 3 diff --git a/gradle.properties b/gradle.properties index e1b3818..a5bc400 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 4.1.1 +version = 4.2.3 plugin-name = EcoArmor \ No newline at end of file