From 7165e9be6e8ab9c0fae358a166d3eb4b40321868 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 15 Jan 2021 18:51:29 +0000 Subject: [PATCH 01/19] Added error detection to sorter implementation --- .../implementations/AlphabeticSorter.java | 2 +- .../sorting/implementations/LengthSorter.java | 2 +- .../RarityAlphabeticSorter.java | 13 +++++++--- .../implementations/RarityLengthSorter.java | 12 ++++++--- .../RarityTypeAlphabeticSorter.java | 25 +++++++++++------- .../RarityTypeLengthSorter.java | 26 ++++++++++++------- .../implementations/TypeAlphabeticSorter.java | 19 +++++++++----- .../implementations/TypeLengthSorter.java | 19 +++++++++----- .../ecoenchants/special/Soulbound.java | 3 +-- .../enchantments/meta/EnchantmentRarity.java | 18 +++++++++++++ .../enchantments/meta/EnchantmentType.java | 18 +++++++++++++ 11 files changed, 114 insertions(+), 43 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/AlphabeticSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/AlphabeticSorter.java index 25a88a8b..48e7005c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/AlphabeticSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/AlphabeticSorter.java @@ -10,7 +10,7 @@ import java.util.List; public class AlphabeticSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { toSort.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()))); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/LengthSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/LengthSorter.java index 9e01e55d..81372897 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/LengthSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/LengthSorter.java @@ -11,7 +11,7 @@ import java.util.List; public class LengthSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { toSort.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityAlphabeticSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityAlphabeticSorter.java index c45b7258..5f91b225 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityAlphabeticSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityAlphabeticSorter.java @@ -12,15 +12,20 @@ import java.util.List; public class RarityAlphabeticSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); + EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { List rarityEnchants = new ArrayList<>(); - toSort.forEach(enchantment -> { - if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) { rarityEnchants.add(enchantment); } - }); + } rarityEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())); sorted.addAll(rarityEnchants); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityLengthSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityLengthSorter.java index 21c256d5..600d4071 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityLengthSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityLengthSorter.java @@ -13,15 +13,19 @@ import java.util.List; public class RarityLengthSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { List rarityEnchants = new ArrayList<>(); - toSort.forEach(enchantment -> { - if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) { rarityEnchants.add(enchantment); } - }); + } rarityEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())); sorted.addAll(rarityEnchants); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeAlphabeticSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeAlphabeticSorter.java index 925ccd6a..b1097f27 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeAlphabeticSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeAlphabeticSorter.java @@ -9,24 +9,31 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; public class RarityTypeAlphabeticSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> { - List typeEnchants = toSort.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) - .sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())) - .collect(Collectors.toList()); + List typeEnchants = new ArrayList<>(); + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) { + typeEnchants.add(enchantment); + } + } + typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())); + EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { List rarityEnchants = new ArrayList<>(); - typeEnchants.forEach(enchantment -> { - if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + for (Enchantment enchantment : typeEnchants) { + if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) { rarityEnchants.add(enchantment); } - }); + } rarityEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())); sorted.addAll(rarityEnchants); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java index f49a3fce..ecc7a71e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java @@ -10,24 +10,32 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; public class RarityTypeLengthSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> { - List typeEnchants = toSort.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) - .sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())) - .collect(Collectors.toList()); + List typeEnchants = new ArrayList<>(); + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) { + typeEnchants.add(enchantment); + } + } + + typeEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())); + EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { List rarityEnchants = new ArrayList<>(); - typeEnchants.forEach(enchantment -> { - if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + for (Enchantment enchantment : typeEnchants) { + if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) { rarityEnchants.add(enchantment); } - }); + } rarityEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())); }); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeAlphabeticSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeAlphabeticSorter.java index e6150d15..f002b8cd 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeAlphabeticSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeAlphabeticSorter.java @@ -9,17 +9,24 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; public class TypeAlphabeticSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> { - List typeEnchants = toSort.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) - .sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())) - .collect(Collectors.toList()); + List typeEnchants = new ArrayList<>(); + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) { + typeEnchants.add(enchantment); + } + } + + typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())); sorted.addAll(typeEnchants); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeLengthSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeLengthSorter.java index 5ef087d0..2811a789 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeLengthSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeLengthSorter.java @@ -8,19 +8,24 @@ import org.bukkit.enchantments.Enchantment; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; public class TypeLengthSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> { - List typeEnchants = toSort.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) - .sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())) - .collect(Collectors.toList()); + List typeEnchants = new ArrayList<>(); + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) { + typeEnchants.add(enchantment); + } + } + sorted.addAll(typeEnchants); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java index 7a750305..a7e2de54 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java @@ -5,7 +5,6 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.inventory.ItemStack; @@ -97,7 +96,7 @@ public class Soulbound extends EcoEnchant { } @EventHandler(priority = EventPriority.HIGHEST) - public void onDeath(@NotNull final EntityDeathEvent event) { + public void onDeath(@NotNull final PlayerDeathEvent event) { event.getDrops().removeIf(itemStack -> itemStack.getItemMeta().getPersistentDataContainer().has(this.getPlugin().getNamespacedKeyFactory().create("soulbound"), PersistentDataType.INTEGER)); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java index f035eaad..8ab2cc4c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.HashSet; +import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -119,6 +120,23 @@ public class EnchantmentRarity implements Registerable { return this.customColor != null; } + @Override + public boolean equals(@NotNull final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof EnchantmentRarity)) { + return false; + } + EnchantmentRarity that = (EnchantmentRarity) o; + return Objects.equals(getName(), that.getName()); + } + + @Override + public int hashCode() { + return Objects.hash(getName()); + } + /** * Get EnchantmentRarity matching name. * diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java index 6679f522..7091fc4d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.function.Supplier; public class EnchantmentType { @@ -200,6 +201,23 @@ public class EnchantmentType { this.singular = singularSupplier.get(); } + @Override + public boolean equals(@NotNull final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof EnchantmentType)) { + return false; + } + EnchantmentType that = (EnchantmentType) o; + return Objects.equals(getName(), that.getName()); + } + + @Override + public int hashCode() { + return Objects.hash(getName()); + } + /** * Update suppliers of all types. */ From 73dc90a6f3bc3f7bd0e4ccee929d14d12a6f63d0 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 15 Jan 2021 18:56:28 +0000 Subject: [PATCH 02/19] Updated to 6.1.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 05127221..9c7ae0b6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 6.1.0 +version = 6.1.1 plugin-name = EcoEnchants \ No newline at end of file From 348c4161ee85434bda1e4856c81012bae8c4f9c4 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 15 Jan 2021 19:01:27 +0000 Subject: [PATCH 03/19] Fixed RarityTypeLengthSorter --- .../options/sorting/implementations/RarityTypeLengthSorter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java index ecc7a71e..7a1efb87 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java @@ -37,6 +37,7 @@ public class RarityTypeLengthSorter implements EnchantmentSorter { } } rarityEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())); + sorted.addAll(rarityEnchants); }); }); From e1c0c28a0011a7ea2a628e9d649d6a1243906643 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 16 Jan 2021 13:14:30 +0000 Subject: [PATCH 04/19] Fixed shockwave --- .../enchantments/ecoenchants/normal/Shockwave.java | 2 +- .../enchantments/ecoenchants/special/Soulbound.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java index 64fd3b4f..a112682b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java @@ -63,7 +63,7 @@ public class Shockwave extends EcoEnchant { .filter(entity1 -> entity1 != player) .filter(entity1 -> !entity1.hasMetadata("shockwaved")) .forEach((mob -> { - ((LivingEntity) mob).damage(finalDamage, player); + ((LivingEntity) mob).damage(finalDamage, entity); mob.setMetadata("shockwaved", this.getPlugin().getMetadataValueFactory().create(true)); this.getPlugin().getScheduler().runLater(() -> mob.removeMetadata("shockwaved", this.getPlugin()), 10); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java index a7e2de54..27b53cdf 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java @@ -88,7 +88,10 @@ public class Soulbound extends EcoEnchant { assert meta != null; meta.getPersistentDataContainer().remove(this.getPlugin().getNamespacedKeyFactory().create("soulbound")); soulboundItem.setItemMeta(meta); - player.getInventory().addItem(soulboundItem); + + if (!player.getInventory().contains(soulboundItem)) { + player.getInventory().addItem(soulboundItem); + } } player.removeMetadata("soulbound-items", this.getPlugin()); From f0a6077ad4e989456530b4dcc8b2515da8cf534a Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 16 Jan 2021 13:14:49 +0000 Subject: [PATCH 05/19] Updated to 6.1.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9c7ae0b6..231a6284 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 6.1.1 +version = 6.1.2 plugin-name = EcoEnchants \ No newline at end of file From bd4d65f2c53b6f2b1069aad4ec3fd89a87e31059 Mon Sep 17 00:00:00 2001 From: kireevm96 Date: Sat, 16 Jan 2021 17:35:54 +0300 Subject: [PATCH 06/19] Fix dupa at tKeepInventory --- .../ecoenchants/special/Soulbound.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java index 27b53cdf..d47b08e5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java @@ -65,11 +65,24 @@ public class Soulbound extends EcoEnchant { player.setMetadata("soulbound-items", this.getPlugin().getMetadataValueFactory().create(soulboundItems)); } + public boolean hasEmptyInventory(Player p) { + for(ItemStack it : p.getInventory().getContents()) + { + if(it != null) return false; + } + return true; + } + @EventHandler(priority = EventPriority.HIGHEST) public void onSoulboundRespawn(@NotNull final PlayerRespawnEvent event) { Player player = event.getPlayer(); - + this.getPlugin().getScheduler().runLater(() -> { + + if (!hasEmptyInventory(player)) { + return; + } + if (!player.hasMetadata("soulbound-items")) { return; } @@ -88,10 +101,8 @@ public class Soulbound extends EcoEnchant { assert meta != null; meta.getPersistentDataContainer().remove(this.getPlugin().getNamespacedKeyFactory().create("soulbound")); soulboundItem.setItemMeta(meta); - - if (!player.getInventory().contains(soulboundItem)) { - player.getInventory().addItem(soulboundItem); - } + player.getInventory().addItem(soulboundItem); + } player.removeMetadata("soulbound-items", this.getPlugin()); From 152d12a97ec22843af55a246235a0f2c75e55c7e Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 16 Jan 2021 18:00:47 +0000 Subject: [PATCH 07/19] Improved pull request codestyle --- .../ecoenchants/special/Soulbound.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java index d47b08e5..a27f84da 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -65,24 +66,24 @@ public class Soulbound extends EcoEnchant { player.setMetadata("soulbound-items", this.getPlugin().getMetadataValueFactory().create(soulboundItems)); } - public boolean hasEmptyInventory(Player p) { - for(ItemStack it : p.getInventory().getContents()) - { - if(it != null) return false; + public boolean hasEmptyInventory(@NotNull final Player player) { + for (ItemStack itemStack : player.getInventory().getContents()) { + if (itemStack != null && itemStack.getType() != Material.AIR) { + return false; + } } return true; } - + @EventHandler(priority = EventPriority.HIGHEST) public void onSoulboundRespawn(@NotNull final PlayerRespawnEvent event) { Player player = event.getPlayer(); - + this.getPlugin().getScheduler().runLater(() -> { - - if (!hasEmptyInventory(player)) { - return; - } - + if (!hasEmptyInventory(player)) { + return; + } + if (!player.hasMetadata("soulbound-items")) { return; } @@ -102,7 +103,6 @@ public class Soulbound extends EcoEnchant { meta.getPersistentDataContainer().remove(this.getPlugin().getNamespacedKeyFactory().create("soulbound")); soulboundItem.setItemMeta(meta); player.getInventory().addItem(soulboundItem); - } player.removeMetadata("soulbound-items", this.getPlugin()); From 00346013fa08bff63bb8295de0bf3e78cc694fdc Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 17 Jan 2021 11:04:40 +0000 Subject: [PATCH 08/19] Updated to 6.2.0, using new eco jar system --- build.gradle | 9 +-------- eco-core/core-plugin/src/main/resources/plugin.yml | 1 + eco-extensions/alchemy/build.gradle | 2 +- eco-extensions/biomes/build.gradle | 2 +- eco-extensions/build.gradle | 2 -- eco-extensions/effects/build.gradle | 2 +- eco-extensions/endershot/build.gradle | 2 +- eco-extensions/firewand/build.gradle | 2 +- eco-extensions/precision/build.gradle | 2 +- eco-extensions/sprint-artifacts/build.gradle | 2 +- eco-extensions/summoning/build.gradle | 2 +- eco-extensions/xray/build.gradle | 2 +- gradle.properties | 2 +- 13 files changed, 12 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index e2c83d85..2b548040 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,6 @@ plugins { dependencies { implementation project(":eco-core").getSubprojects() - implementation 'com.willfp:eco:1.1.3' } allprojects { @@ -50,7 +49,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:1.1.3' + compileOnly 'com.willfp:eco:2.0.0' compileOnly 'org.jetbrains:annotations:19.0.0' @@ -72,10 +71,6 @@ allprojects { } } - shadowJar { - relocate('com.willfp.eco.', 'com.willfp.ecoenchants.eco.') // Dot is to prevent plugin being shaded into itself - } - compileJava.options.encoding = 'UTF-8' compileJava.dependsOn clean @@ -91,8 +86,6 @@ clean.doLast { } shadowJar { - relocate('org.apache.maven', 'com.willfp.ecoenchants.eco.shaded.maven') - relocate('org.bstats', 'com.willfp.ecoenchants.eco.shaded.bstats') archiveFileName = findProperty("plugin-name") + " v" + findProperty("version") + ".jar" } diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index ed90e195..0c097f75 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -6,6 +6,7 @@ authors: [Auxilor] website: willfp.com load: STARTUP depend: + - eco - ProtocolLib softdepend: - WorldGuard diff --git a/eco-extensions/alchemy/build.gradle b/eco-extensions/alchemy/build.gradle index 1579a7be..176951ae 100644 --- a/eco-extensions/alchemy/build.gradle +++ b/eco-extensions/alchemy/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Alchemy Extension' -shadowJar { +jar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/biomes/build.gradle b/eco-extensions/biomes/build.gradle index b8f44f55..898989f8 100644 --- a/eco-extensions/biomes/build.gradle +++ b/eco-extensions/biomes/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Biomes Extension' -shadowJar { +jar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/build.gradle b/eco-extensions/build.gradle index 8437aeaf..7e7a5ff2 100644 --- a/eco-extensions/build.gradle +++ b/eco-extensions/build.gradle @@ -11,6 +11,4 @@ subprojects { tasks.withType(Jar) { destinationDirectory = file("$rootDir/bin/") } - - tasks.jar.enabled = false } \ No newline at end of file diff --git a/eco-extensions/effects/build.gradle b/eco-extensions/effects/build.gradle index 1793c990..d41beab4 100644 --- a/eco-extensions/effects/build.gradle +++ b/eco-extensions/effects/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Effects Extension' -shadowJar { +jar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/endershot/build.gradle b/eco-extensions/endershot/build.gradle index d7cfa250..1217a8cc 100644 --- a/eco-extensions/endershot/build.gradle +++ b/eco-extensions/endershot/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Endershot Extension' -shadowJar { +jar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/firewand/build.gradle b/eco-extensions/firewand/build.gradle index c415db80..f7a2666f 100644 --- a/eco-extensions/firewand/build.gradle +++ b/eco-extensions/firewand/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Firewand Extension' -shadowJar { +jar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/precision/build.gradle b/eco-extensions/precision/build.gradle index fbbe3894..c4533054 100644 --- a/eco-extensions/precision/build.gradle +++ b/eco-extensions/precision/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Precision Extension' -shadowJar { +jar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/sprint-artifacts/build.gradle b/eco-extensions/sprint-artifacts/build.gradle index b4eb5d37..7104881c 100644 --- a/eco-extensions/sprint-artifacts/build.gradle +++ b/eco-extensions/sprint-artifacts/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Sprint Artifacts Extension' -shadowJar { +jar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/summoning/build.gradle b/eco-extensions/summoning/build.gradle index feae2c7e..8c698dab 100644 --- a/eco-extensions/summoning/build.gradle +++ b/eco-extensions/summoning/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Summoning Extension' -shadowJar { +jar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/xray/build.gradle b/eco-extensions/xray/build.gradle index 53d216be..a8e45310 100644 --- a/eco-extensions/xray/build.gradle +++ b/eco-extensions/xray/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '1.0.2' description = 'Xray Extension' -shadowJar { +jar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 231a6284..56c7bd15 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 6.1.2 +version = 6.2.0 plugin-name = EcoEnchants \ No newline at end of file From bb502e7d0d71b2a0184d50157371fc48c8628392 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 17 Jan 2021 11:07:51 +0000 Subject: [PATCH 09/19] Fixed extension descriptions --- eco-extensions/alchemy/build.gradle | 2 +- eco-extensions/biomes/build.gradle | 2 +- eco-extensions/build.gradle | 2 ++ eco-extensions/effects/build.gradle | 2 +- eco-extensions/endershot/build.gradle | 2 +- eco-extensions/firewand/build.gradle | 2 +- eco-extensions/precision/build.gradle | 2 +- eco-extensions/sprint-artifacts/build.gradle | 2 +- eco-extensions/summoning/build.gradle | 2 +- eco-extensions/xray/build.gradle | 2 +- 10 files changed, 11 insertions(+), 9 deletions(-) diff --git a/eco-extensions/alchemy/build.gradle b/eco-extensions/alchemy/build.gradle index 176951ae..1579a7be 100644 --- a/eco-extensions/alchemy/build.gradle +++ b/eco-extensions/alchemy/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Alchemy Extension' -jar { +shadowJar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/biomes/build.gradle b/eco-extensions/biomes/build.gradle index 898989f8..b8f44f55 100644 --- a/eco-extensions/biomes/build.gradle +++ b/eco-extensions/biomes/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Biomes Extension' -jar { +shadowJar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/build.gradle b/eco-extensions/build.gradle index 7e7a5ff2..8437aeaf 100644 --- a/eco-extensions/build.gradle +++ b/eco-extensions/build.gradle @@ -11,4 +11,6 @@ subprojects { tasks.withType(Jar) { destinationDirectory = file("$rootDir/bin/") } + + tasks.jar.enabled = false } \ No newline at end of file diff --git a/eco-extensions/effects/build.gradle b/eco-extensions/effects/build.gradle index d41beab4..1793c990 100644 --- a/eco-extensions/effects/build.gradle +++ b/eco-extensions/effects/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Effects Extension' -jar { +shadowJar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/endershot/build.gradle b/eco-extensions/endershot/build.gradle index 1217a8cc..d7cfa250 100644 --- a/eco-extensions/endershot/build.gradle +++ b/eco-extensions/endershot/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Endershot Extension' -jar { +shadowJar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/firewand/build.gradle b/eco-extensions/firewand/build.gradle index f7a2666f..c415db80 100644 --- a/eco-extensions/firewand/build.gradle +++ b/eco-extensions/firewand/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Firewand Extension' -jar { +shadowJar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/precision/build.gradle b/eco-extensions/precision/build.gradle index c4533054..fbbe3894 100644 --- a/eco-extensions/precision/build.gradle +++ b/eco-extensions/precision/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Precision Extension' -jar { +shadowJar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/sprint-artifacts/build.gradle b/eco-extensions/sprint-artifacts/build.gradle index 7104881c..b4eb5d37 100644 --- a/eco-extensions/sprint-artifacts/build.gradle +++ b/eco-extensions/sprint-artifacts/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Sprint Artifacts Extension' -jar { +shadowJar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/summoning/build.gradle b/eco-extensions/summoning/build.gradle index 8c698dab..feae2c7e 100644 --- a/eco-extensions/summoning/build.gradle +++ b/eco-extensions/summoning/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '3.0.1' description = 'Summoning Extension' -jar { +shadowJar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/xray/build.gradle b/eco-extensions/xray/build.gradle index a8e45310..53d216be 100644 --- a/eco-extensions/xray/build.gradle +++ b/eco-extensions/xray/build.gradle @@ -2,6 +2,6 @@ group 'com.willfp' version '1.0.2' description = 'Xray Extension' -jar { +shadowJar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file From 15d5afd74bbaf03dd1461f5c29f311ae3d9ee2ea Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 17 Jan 2021 16:22:04 +0000 Subject: [PATCH 10/19] Updated to eco 3 --- build.gradle | 2 +- .../willfp/ecoenchants/EcoEnchantsPlugin.java | 14 +++- .../command/commands/CommandEcoreload.java | 3 +- .../command/commands/CommandEnchantinfo.java | 15 ++-- .../config/EnchantmentYamlConfig.java | 4 +- .../config/configs/EnchantmentConfig.java | 7 +- .../ecoenchants/config/configs/Rarity.java | 4 +- .../ecoenchants/config/configs/Target.java | 4 +- .../ecoenchants/display/EnchantDisplay.java | 3 +- .../ecoenchants/display/EnchantmentCache.java | 20 +++-- .../display/options/DescriptionOptions.java | 14 +++- .../display/options/DisplayOptions.java | 20 +++-- .../display/options/NumbersOptions.java | 12 ++- .../display/options/ShrinkOptions.java | 14 +++- .../display/packets/PacketChat.java | 3 +- .../packets/PacketOpenWindowMerchant.java | 2 +- .../ecoenchants/enchantments/EcoEnchant.java | 6 +- .../ecoenchants/normal/Abrasion.java | 4 +- .../ecoenchants/normal/BlastMining.java | 4 +- .../ecoenchants/normal/Bleed.java | 4 +- .../ecoenchants/normal/Cleave.java | 4 +- .../ecoenchants/normal/Disable.java | 4 +- .../ecoenchants/normal/Drill.java | 4 +- .../ecoenchants/normal/Dullness.java | 4 +- .../ecoenchants/normal/Famine.java | 4 +- .../enchantments/ecoenchants/normal/Fury.java | 4 +- .../ecoenchants/normal/IllusionAspect.java | 4 +- .../ecoenchants/normal/Lumberjack.java | 4 +- .../ecoenchants/normal/Shockwave.java | 4 +- .../ecoenchants/normal/Spearfishing.java | 5 +- .../ecoenchants/normal/Splash.java | 4 +- .../ecoenchants/normal/StrayAspect.java | 4 +- .../ecoenchants/normal/Supercritical.java | 4 +- .../ecoenchants/normal/Telekinesis.java | 8 +- .../enchantments/ecoenchants/normal/Thor.java | 4 +- .../ecoenchants/normal/Toxic.java | 4 +- .../ecoenchants/normal/VampireAspect.java | 4 +- .../enchantments/ecoenchants/normal/Vein.java | 4 +- .../ecoenchants/special/Bolt.java | 4 +- .../ecoenchants/special/Carve.java | 4 +- .../ecoenchants/special/Confusion.java | 4 +- .../ecoenchants/special/Razor.java | 4 +- .../ecoenchants/special/Volatile.java | 4 +- .../ecoenchants/spell/Dynamite.java | 4 +- .../enchantments/itemtypes/Artifact.java | 4 +- .../enchantments/itemtypes/Spell.java | 5 +- .../enchantments/meta/EnchantmentType.java | 22 ++++-- .../support/merging/anvil/AnvilListeners.java | 5 +- .../support/merging/anvil/AnvilMerge.java | 22 ++++-- .../obtaining/EnchantingListeners.java | 25 +++---- .../support/obtaining/LootPopulator.java | 31 +++++--- .../support/obtaining/VillagerListeners.java | 28 ++++--- .../enchantments/util/EnchantChecks.java | 5 +- .../enchantments/util/WatcherTriggers.java | 6 +- .../willfp/ecoenchants/util/ProxyUtils.java | 21 ++++++ .../ecoenchants/proxy/util/ProxyFactory.java | 75 +++++++++++++++++++ eco-extensions/alchemy/build.gradle | 2 +- .../ecoenchants/alchemy/AlchemyMain.java | 6 ++ eco-extensions/biomes/build.gradle | 2 +- .../willfp/ecoenchants/biomes/BiomesMain.java | 6 ++ eco-extensions/effects/build.gradle | 2 +- .../ecoenchants/effects/EffectsMain.java | 6 ++ eco-extensions/endershot/build.gradle | 2 +- .../ecoenchants/endershot/EndershotMain.java | 6 ++ eco-extensions/firewand/build.gradle | 2 +- .../ecoenchants/firewand/FirewandMain.java | 6 ++ eco-extensions/mmo/build.gradle | 6 +- .../com/willfp/ecoenchants/mmo/MMOMain.java | 20 ++--- .../ecoenchants/mmo/MMOPrerequisites.java | 1 - .../ecoenchants/mmo/enchants/mana/Elixir.java | 2 - .../mmo/enchants/misc/Strengthening.java | 6 -- .../mmo/enchants/stamina/Motivate.java | 2 - .../mmo/structure/MMOEnchantment.java | 2 - eco-extensions/precision/build.gradle | 2 +- .../ecoenchants/precision/Precision.java | 4 +- .../ecoenchants/precision/PrecisionMain.java | 6 ++ eco-extensions/sprint-artifacts/build.gradle | 2 +- .../sprintartifacts/SprintArtifactsMain.java | 6 ++ eco-extensions/summoning/build.gradle | 2 +- .../summoning/SummoningEnchantment.java | 4 +- .../ecoenchants/summoning/SummoningMain.java | 6 ++ eco-extensions/xray/build.gradle | 2 +- .../com/willfp/ecoenchants/xray/XrayMain.java | 6 ++ 83 files changed, 417 insertions(+), 211 deletions(-) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/util/ProxyUtils.java create mode 100644 eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/util/ProxyFactory.java diff --git a/build.gradle b/build.gradle index 2b548040..dd1a20e0 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:2.0.0' + compileOnly 'com.willfp:eco:3.0.0' compileOnly 'org.jetbrains:annotations:19.0.0' diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java index 2884d24a..8da1b0fd 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java @@ -1,6 +1,5 @@ package com.willfp.ecoenchants; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.command.AbstractCommand; import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils; import com.willfp.eco.util.integrations.IntegrationLoader; @@ -37,6 +36,8 @@ import com.willfp.ecoenchants.integrations.mcmmo.plugins.McmmoIntegrationImpl; import com.willfp.ecoenchants.integrations.worldguard.WorldguardManager; import com.willfp.ecoenchants.integrations.worldguard.plugins.WorldguardIntegrationImpl; import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; +import com.willfp.ecoenchants.util.ProxyUtils; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; @@ -48,11 +49,18 @@ import java.util.List; @SuppressWarnings("unused") public class EcoEnchantsPlugin extends AbstractEcoPlugin { + /** + * Instance of the plugin. + */ + @Getter + private static EcoEnchantsPlugin instance; + /** * Internal constructor called by bukkit on plugin load. */ public EcoEnchantsPlugin() { super("EcoEnchants", 79573, 7666, "com.willfp.ecoenchants.proxy", "&a"); + instance = this; } /** @@ -126,7 +134,7 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin { @Override public void postLoad() { Bukkit.getServer().getWorlds().forEach(world -> { - world.getPopulators().add(new LootPopulator()); + world.getPopulators().add(new LootPopulator(this)); }); EssentialsManager.registerEnchantments(); } @@ -189,7 +197,7 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin { new GrindstoneListeners(this), new AnvilListeners(this), new WatcherTriggers(this), - new VillagerListeners(), + new VillagerListeners(this), new HoldItemListener() ); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java index 05aa99e2..9c5d2039 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java @@ -1,7 +1,6 @@ package com.willfp.ecoenchants.command.commands; import com.willfp.eco.util.command.AbstractCommand; -import com.willfp.eco.util.config.Configs; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -22,6 +21,6 @@ public class CommandEcoreload extends AbstractCommand { public void onExecute(@NotNull final CommandSender sender, @NotNull final List args) { this.getPlugin().reload(); - sender.sendMessage(Configs.LANG.getMessage("reloaded")); + sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded")); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java index a6438d4c..6814eba0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java @@ -3,7 +3,6 @@ package com.willfp.ecoenchants.command.commands; import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.command.AbstractCommand; import com.willfp.eco.util.command.AbstractTabCompleter; -import com.willfp.eco.util.config.Configs; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo; import com.willfp.ecoenchants.display.EnchantmentCache; @@ -39,7 +38,7 @@ public class CommandEnchantinfo extends AbstractCommand { public void onExecute(@NotNull final CommandSender sender, @NotNull final List args) { if (args.isEmpty()) { - sender.sendMessage(Configs.LANG.getMessage("missing-enchant")); + sender.sendMessage(this.getPlugin().getLangYml().getMessage("missing-enchant")); return; } StringBuilder nameBuilder = new StringBuilder(); @@ -51,7 +50,7 @@ public class CommandEnchantinfo extends AbstractCommand { EcoEnchant enchantment = EcoEnchants.getByName(searchName); if (enchantment == null || !enchantment.isEnabled()) { - String message = Configs.LANG.getMessage("not-found").replace("%name%", searchName); + String message = this.getPlugin().getLangYml().getMessage("not-found").replace("%name%", searchName); sender.sendMessage(message); return; } @@ -71,7 +70,7 @@ public class CommandEnchantinfo extends AbstractCommand { if (EcoEnchants.getFromEnchantment(enchantment1) != null) { conflictNames.add(EcoEnchants.getFromEnchantment(enchantment1).getName()); } else { - conflictNames.add(Configs.LANG.getString("enchantments." + enchantment1.getKey().getKey() + ".name")); + conflictNames.add(this.getPlugin().getLangYml().getString("enchantments." + enchantment1.getKey().getKey() + ".name")); } })); @@ -81,14 +80,14 @@ public class CommandEnchantinfo extends AbstractCommand { if (allConflicts.length() >= 2) { allConflicts = allConflicts.substring(0, allConflicts.length() - 2); } else { - allConflicts = StringUtils.translate(Configs.LANG.getString("no-conflicts")); + allConflicts = StringUtils.translate(this.getPlugin().getLangYml().getString("no-conflicts")); } Set targets = enchantment.getTargetMaterials(); Set applicableItemsSet = new HashSet<>(); - if (Configs.CONFIG.getBool("commands.enchantinfo.show-target-group")) { + if (this.getPlugin().getConfigYml().getBool("commands.enchantinfo.show-target-group")) { enchantment.getTargets().forEach(target -> { String targetName = target.getName(); targetName = targetName.toLowerCase(); @@ -112,7 +111,7 @@ public class CommandEnchantinfo extends AbstractCommand { if (allTargets.length() >= 2) { allTargets = allTargets.substring(0, allTargets.length() - 2); } else { - allTargets = StringUtils.translate(Configs.LANG.getString("no-targets")); + allTargets = StringUtils.translate(this.getPlugin().getLangYml().getString("no-targets")); } String maxLevel = String.valueOf(enchantment.getMaxLevel()); @@ -122,7 +121,7 @@ public class CommandEnchantinfo extends AbstractCommand { final String finalTargets = allTargets; final String finalConflicts = allConflicts; final String finalMaxLevel = maxLevel; - Arrays.asList(Configs.LANG.getMessage("enchantinfo").split("\\r?\\n")).forEach((string -> { + Arrays.asList(this.getPlugin().getLangYml().getMessage("enchantinfo").split("\\r?\\n")).forEach((string -> { string = string.replace("%name%", finalName) .replace("%description%", finalDescription) .replace("%target%", finalTargets) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java index 5ef2bb34..27d8588f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java @@ -2,7 +2,7 @@ package com.willfp.ecoenchants.config; import com.willfp.eco.util.config.ValueGetter; import com.willfp.eco.util.internal.PluginDependent; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import lombok.AccessLevel; import lombok.Getter; @@ -64,7 +64,7 @@ public abstract class EnchantmentYamlConfig extends PluginDependent implements V protected EnchantmentYamlConfig(@NotNull final String name, @NotNull final Class source, @NotNull final EnchantmentType type) { - super(AbstractEcoPlugin.getInstance()); + super(EcoEnchantsPlugin.getInstance()); this.name = name; this.source = source; this.type = type; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/EnchantmentConfig.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/EnchantmentConfig.java index 00d77fc9..05f58fe4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/EnchantmentConfig.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/EnchantmentConfig.java @@ -1,6 +1,5 @@ package com.willfp.ecoenchants.config.configs; -import com.willfp.eco.util.config.Configs; import com.willfp.ecoenchants.config.EnchantmentYamlConfig; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; @@ -86,12 +85,12 @@ public class EnchantmentConfig extends EnchantmentYamlConfig { * Load config values from lang.yml. */ public void loadFromLang() { - if (!Configs.LANG.getConfig().contains("enchantments." + this.getName())) { + if (!this.getPlugin().getLangYml().getConfig().contains("enchantments." + this.getName())) { return; } - this.getConfig().set("name", Configs.LANG.getString("enchantments." + this.getName() + ".name")); - this.getConfig().set("description", Configs.LANG.getString("enchantments." + this.getName() + ".description")); + this.getConfig().set("name", this.getPlugin().getLangYml().getString("enchantments." + this.getName() + ".name")); + this.getConfig().set("description", this.getPlugin().getLangYml().getString("enchantments." + this.getName() + ".description")); try { this.getConfig().save(this.getConfigFile()); } catch (IOException e) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Rarity.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Rarity.java index 2eab541a..d838ed7e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Rarity.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Rarity.java @@ -1,6 +1,8 @@ package com.willfp.ecoenchants.config.configs; import com.willfp.eco.util.config.BaseConfig; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import java.util.Set; @@ -9,7 +11,7 @@ public class Rarity extends BaseConfig { * Instantiate rarity.yml. */ public Rarity() { - super("rarity", false); + super("rarity", false, EcoEnchantsPlugin.getInstance()); } /** diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Target.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Target.java index 4eddb327..11f0db82 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Target.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Target.java @@ -1,6 +1,8 @@ package com.willfp.ecoenchants.config.configs; import com.willfp.eco.util.config.BaseConfig; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; @@ -12,7 +14,7 @@ public class Target extends BaseConfig { * Instantiate target.yml. */ public Target() { - super("target", false); + super("target", false, EcoEnchantsPlugin.getInstance()); } /** diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index d02cdaff..abaf2b96 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -4,6 +4,7 @@ import com.google.common.collect.Lists; import com.willfp.eco.util.NumberUtils; import com.willfp.eco.util.config.updating.annotations.ConfigUpdater; import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.display.options.DisplayOptions; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; @@ -31,7 +32,7 @@ public class EnchantDisplay { /** * Instance of EcoEnchants. */ - private static final AbstractEcoPlugin PLUGIN = AbstractEcoPlugin.getInstance(); + private static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); /** * The meta key to hide enchantments in lore. diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java index b4d4641c..23822fa2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java @@ -1,8 +1,9 @@ package com.willfp.ecoenchants.display; import com.google.common.collect.ImmutableMap; -import com.willfp.eco.util.config.Configs; import com.willfp.eco.util.config.updating.annotations.ConfigUpdater; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; @@ -24,6 +25,11 @@ import java.util.Map; @UtilityClass @SuppressWarnings("deprecation") public class EnchantmentCache { + /** + * Instance of EcoEnchants. + */ + public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); + /** * The physical cache. */ @@ -82,17 +88,17 @@ public class EnchantmentCache { } else { description = Arrays.asList( WordUtils.wrap( - String.valueOf(Configs.LANG.getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".description")), - Configs.CONFIG.getInt("lore.describe.wrap"), + String.valueOf(PLUGIN.getLangYml().getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".description")), + PLUGIN.getConfigYml().getInt("lore.describe.wrap"), "\n", false ).split("\\r?\\n") ); - name = String.valueOf(Configs.LANG.getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".name")); + name = String.valueOf(PLUGIN.getLangYml().getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".name")); type = enchantment.isCursed() ? EnchantmentType.CURSE : EnchantmentType.NORMAL; if (enchantment.isTreasure()) { - rarity = EnchantmentRarity.getByName(Configs.CONFIG.getString("rarity.vanilla-treasure-rarity")); + rarity = EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-treasure-rarity")); } else { - rarity = EnchantmentRarity.getByName(Configs.CONFIG.getString("rarity.vanilla-rarity")); + rarity = EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-rarity")); } } @@ -103,7 +109,7 @@ public class EnchantmentCache { } if (rarity == null) { - rarity = EnchantmentRarity.getByName(Configs.CONFIG.getString("rarity.vanilla-rarity")); + rarity = EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-rarity")); } String rawName = name; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java index 3588afba..2394138f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java @@ -1,10 +1,16 @@ package com.willfp.ecoenchants.display.options; import com.willfp.eco.util.StringUtils; -import com.willfp.eco.util.config.Configs; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import lombok.Getter; public class DescriptionOptions { + /** + * Instance of EcoEnchants. + */ + public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); + /** * The threshold below which to describe enchantments. */ @@ -27,8 +33,8 @@ public class DescriptionOptions { * Update the options. */ public void update() { - threshold = Configs.CONFIG.getInt("lore.describe.before-lines"); - enabled = Configs.CONFIG.getBool("lore.describe.enabled"); - color = StringUtils.translate(Configs.LANG.getString("description-color")); + threshold = PLUGIN.getConfigYml().getInt("lore.describe.before-lines"); + enabled = PLUGIN.getConfigYml().getBool("lore.describe.enabled"); + color = StringUtils.translate(PLUGIN.getLangYml().getString("description-color")); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java index ea55a6f7..d7ba80dd 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java @@ -1,6 +1,7 @@ package com.willfp.ecoenchants.display.options; -import com.willfp.eco.util.config.Configs; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter; import com.willfp.ecoenchants.display.options.sorting.SortParameters; import com.willfp.ecoenchants.display.options.sorting.SorterManager; @@ -17,6 +18,11 @@ import java.util.Set; import java.util.stream.Collectors; public class DisplayOptions { + /** + * Instance of EcoEnchants. + */ + public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); + /** * The enchantment sorter being used. */ @@ -76,24 +82,24 @@ public class DisplayOptions { shrinkOptions.update(); sortedTypes.clear(); - sortedTypes.addAll(Configs.CONFIG.getStrings("lore.type-ordering").stream() + sortedTypes.addAll(PLUGIN.getConfigYml().getStrings("lore.type-ordering").stream() .map(typeName -> EnchantmentType.values().stream().filter(type -> type.getName().equalsIgnoreCase(typeName)).findFirst().orElse(null)) .filter(Objects::nonNull) .collect(Collectors.toList())); sortedTypes.addAll(EnchantmentType.values().stream().filter(enchantmentType -> !sortedTypes.contains(enchantmentType)).collect(Collectors.toList())); sortedRarities.clear(); - sortedRarities.addAll(Configs.CONFIG.getStrings("lore.rarity-ordering").stream() + sortedRarities.addAll(PLUGIN.getConfigYml().getStrings("lore.rarity-ordering").stream() .map(rarityName -> EnchantmentRarity.values().stream().filter(rarity -> rarity.getName().equalsIgnoreCase(rarityName)).findFirst().orElse(null)) .filter(Objects::nonNull) .collect(Collectors.toList())); sortedRarities.addAll(EnchantmentRarity.values().stream().filter(enchantmentRarity -> !sortedRarities.contains(enchantmentRarity)).collect(Collectors.toList())); - useLoreGetter = Configs.CONFIG.getBool("advanced.lore-getter"); + useLoreGetter = PLUGIN.getConfigYml().getBool("advanced.lore-getter"); - boolean byType = Configs.CONFIG.getBool("lore.sort-by-type"); - boolean byLength = Configs.CONFIG.getBool("lore.sort-by-length"); - boolean byRarity = Configs.CONFIG.getBool("lore.sort-by-rarity"); + boolean byType = PLUGIN.getConfigYml().getBool("lore.sort-by-type"); + boolean byLength = PLUGIN.getConfigYml().getBool("lore.sort-by-length"); + boolean byRarity = PLUGIN.getConfigYml().getBool("lore.sort-by-rarity"); Set params = new HashSet<>(); if (byType) { params.add(SortParameters.TYPE); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java index 073724e7..24625af0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java @@ -1,9 +1,15 @@ package com.willfp.ecoenchants.display.options; -import com.willfp.eco.util.config.Configs; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import lombok.Getter; public class NumbersOptions { + /** + * Instance of EcoEnchants. + */ + public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); + /** * If numerals should be used. *

@@ -22,7 +28,7 @@ public class NumbersOptions { * Update the options. */ public void update() { - useNumerals = Configs.CONFIG.getBool("lore.use-numerals"); - threshold = Configs.CONFIG.getInt("lore.use-numbers-above-threshold"); + useNumerals = PLUGIN.getConfigYml().getBool("lore.use-numerals"); + threshold = PLUGIN.getConfigYml().getInt("lore.use-numbers-above-threshold"); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java index 2c4a634b..b9fb6194 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java @@ -1,9 +1,15 @@ package com.willfp.ecoenchants.display.options; -import com.willfp.eco.util.config.Configs; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import lombok.Getter; public class ShrinkOptions { + /** + * Instance of EcoEnchants. + */ + public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); + /** * The threshold above which enchantments will be shrunk. */ @@ -26,8 +32,8 @@ public class ShrinkOptions { * Update the options. */ public void update() { - threshold = Configs.CONFIG.getInt("lore.shrink.after-lines"); - enabled = Configs.CONFIG.getBool("lore.shrink.enabled"); - shrinkPerLine = Configs.CONFIG.getInt("lore.shrink.maximum-per-line"); + threshold = PLUGIN.getConfigYml().getInt("lore.shrink.after-lines"); + enabled = PLUGIN.getConfigYml().getBool("lore.shrink.enabled"); + shrinkPerLine = PLUGIN.getConfigYml().getInt("lore.shrink.maximum-per-line"); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketChat.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketChat.java index 3903acbf..89213ad1 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketChat.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketChat.java @@ -4,10 +4,10 @@ import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedChatComponent; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.protocollib.AbstractPacketAdapter; import com.willfp.ecoenchants.proxy.proxies.ChatComponentProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -33,6 +33,7 @@ public class PacketChat extends AbstractPacketAdapter { if (component.getHandle() == null) { return; } + WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(ProxyUtils.getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle())); packet.getChatComponents().write(i, newComponent); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketOpenWindowMerchant.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketOpenWindowMerchant.java index 2342a0e5..2fecf3cb 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketOpenWindowMerchant.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketOpenWindowMerchant.java @@ -2,11 +2,11 @@ package com.willfp.ecoenchants.display.packets; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.protocollib.AbstractPacketAdapter; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.Player; import org.bukkit.inventory.MerchantRecipe; import org.jetbrains.annotations.NotNull; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index 0ced5434..8df4824c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -2,10 +2,10 @@ package com.willfp.ecoenchants.enchantments; import com.willfp.eco.util.StringUtils; -import com.willfp.eco.util.config.Configs; import com.willfp.eco.util.interfaces.Registerable; import com.willfp.eco.util.optional.Prerequisite; import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.config.EcoEnchantsConfigs; import com.willfp.ecoenchants.config.configs.EnchantmentConfig; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; @@ -44,7 +44,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist * Instance of EcoEnchants for enchantments to be able to access. */ @Getter(AccessLevel.PROTECTED) - private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance(); + private final AbstractEcoPlugin plugin = EcoEnchantsPlugin.getInstance(); /** * The display name of the enchantment. @@ -262,7 +262,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist * @return The description. */ public List getWrappedDescription() { - return Arrays.asList(WordUtils.wrap(description, Configs.CONFIG.getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n")); + return Arrays.asList(WordUtils.wrap(description, this.getPlugin().getConfigYml().getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n")); } /** diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java index fdef9340..3a5a92e1 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; import com.willfp.eco.util.DurabilityUtils; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlastMining.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlastMining.java index 9a3bb6ba..30b7c711 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlastMining.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlastMining.java @@ -1,12 +1,12 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.integrations.anticheat.AnticheatManager; import com.willfp.eco.util.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Particle; import org.bukkit.block.Block; import org.bukkit.entity.Player; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java index 12de6a3f..8968707b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Cleave.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Cleave.java index 5896557a..4806a082 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Cleave.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Cleave.java @@ -1,10 +1,10 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disable.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disable.java index 34ac616e..0e03aaa5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disable.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disable.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Drill.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Drill.java index 7ceabec1..65b85f87 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Drill.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Drill.java @@ -1,13 +1,13 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.VectorUtils; import com.willfp.eco.util.integrations.anticheat.AnticheatManager; import com.willfp.eco.util.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Dullness.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Dullness.java index 08bf698c..db2c79d7 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Dullness.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Dullness.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Famine.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Famine.java index 847f39fd..b87528e7 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Famine.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Famine.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Fury.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Fury.java index 857103f6..e1766831 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Fury.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Fury.java @@ -1,12 +1,12 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.VectorUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Monster; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IllusionAspect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IllusionAspect.java index a2940eee..7522c6b2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IllusionAspect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IllusionAspect.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lumberjack.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lumberjack.java index 952e5987..fac923b5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lumberjack.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lumberjack.java @@ -1,13 +1,13 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy; import com.willfp.eco.util.BlockUtils; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.integrations.anticheat.AnticheatManager; import com.willfp.eco.util.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java index a112682b..fd501ca3 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java index c8c31220..584e8ff2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java @@ -1,14 +1,14 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.drops.DropQueue; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; + public class Spearfishing extends EcoEnchant { public Spearfishing() { super( diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Splash.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Splash.java index a05b4e24..34dbd5d8 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Splash.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Splash.java @@ -1,12 +1,12 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java index 00cd8c4b..3eb4bc30 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java index bcd788e7..eb6fce74 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java index ead9d137..a64046c6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java @@ -1,7 +1,5 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.eco.util.ProxyUtils; -import com.willfp.eco.util.config.Configs; import com.willfp.eco.util.drops.DropQueue; import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityEvent; import com.willfp.eco.util.integrations.antigrief.AntigriefManager; @@ -10,6 +8,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.block.Block; @@ -38,9 +37,10 @@ public class Telekinesis extends EcoEnchant { "telekinesis", EnchantmentType.NORMAL ); } + @Override protected void postUpdate() { - always = Configs.CONFIG.getBool("drops.force-dropqueue"); + always = this.getPlugin().getConfigYml().getBool("drops.force-dropqueue"); } // For block drops @@ -149,7 +149,7 @@ public class Telekinesis extends EcoEnchant { } else if (event.getKiller() instanceof Trident) { if (((Trident) event.getKiller()).getShooter() instanceof Player) { player = (Player) ((Trident) event.getKiller()).getShooter(); - item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack((Trident) event.getKiller()); + item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack((Trident) event.getKiller()); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java index 781c4aed..b5bd4f3b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java @@ -1,12 +1,12 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; import com.willfp.eco.util.LightningUtils; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java index aa27bbb4..07e2ad09 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java index 47207dce..5b70f3a6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java index dabb4712..6211744b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java @@ -1,13 +1,13 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; -import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy; import com.willfp.eco.util.BlockUtils; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.integrations.anticheat.AnticheatManager; import com.willfp.eco.util.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Bolt.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Bolt.java index fe144bc8..b25de246 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Bolt.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Bolt.java @@ -1,12 +1,12 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; import com.willfp.eco.util.LightningUtils; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Carve.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Carve.java index fcd05f8a..b34e2cc1 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Carve.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Carve.java @@ -1,10 +1,10 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Confusion.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Confusion.java index 63cd7656..922af1d6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Confusion.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Confusion.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Razor.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Razor.java index e003d2b8..63f4b675 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Razor.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Razor.java @@ -1,10 +1,10 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java index 83ff1cf8..1712487c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java @@ -1,12 +1,12 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Dynamite.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Dynamite.java index 3a5ab372..31397ad7 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Dynamite.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Dynamite.java @@ -1,11 +1,11 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.spell; -import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.integrations.anticheat.AnticheatManager; import com.willfp.eco.util.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.itemtypes.Spell; +import com.willfp.ecoenchants.proxy.proxies.BlockBreakProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Particle; import org.bukkit.block.Block; import org.bukkit.entity.Player; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java index fe9753c2..fd9bef47 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java @@ -1,14 +1,14 @@ package com.willfp.ecoenchants.enchantments.itemtypes; import com.google.common.util.concurrent.AtomicDouble; -import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.optional.Prerequisite; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.block.Block; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java index f33062c2..c3e788e0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java @@ -1,6 +1,5 @@ package com.willfp.ecoenchants.enchantments.itemtypes; -import com.willfp.eco.util.config.Configs; import com.willfp.eco.util.optional.Prerequisite; import com.willfp.ecoenchants.display.EnchantmentCache; import com.willfp.ecoenchants.enchantments.EcoEnchant; @@ -129,13 +128,13 @@ public abstract class Spell extends EcoEnchant { } if (cooldown > 0) { - String message = Configs.LANG.getMessage("on-cooldown").replace("%seconds%", String.valueOf(cooldown)).replace("%name%", EnchantmentCache.getEntry(this).getRawName()); + String message = this.getPlugin().getLangYml().getMessage("on-cooldown").replace("%seconds%", String.valueOf(cooldown)).replace("%name%", EnchantmentCache.getEntry(this).getRawName()); player.sendMessage(message); player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 0.5f); return; } - String message = Configs.LANG.getMessage("used-spell").replace("%name%", EnchantmentCache.getEntry(this).getRawName()); + String message = this.getPlugin().getLangYml().getMessage("used-spell").replace("%name%", EnchantmentCache.getEntry(this).getRawName()); player.sendMessage(message); player.playSound(player.getLocation(), this.getActivationSound(), SoundCategory.PLAYERS, 1, 1); runnable.run(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java index 7091fc4d..aca757f8 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java @@ -1,8 +1,9 @@ package com.willfp.ecoenchants.enchantments.meta; import com.google.common.collect.ImmutableList; -import com.willfp.eco.util.config.Configs; import com.willfp.eco.util.config.updating.annotations.ConfigUpdater; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import com.willfp.ecoenchants.enchantments.itemtypes.Spell; @@ -16,6 +17,11 @@ import java.util.Objects; import java.util.function.Supplier; public class EnchantmentType { + /** + * Instance of EcoEnchants. + */ + private static final EcoEnchantsPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); + /** * All registered types. */ @@ -29,7 +35,7 @@ public class EnchantmentType { public static final EnchantmentType NORMAL = new EnchantmentType( "normal", false, - () -> Configs.LANG.getString("not-curse-color") + () -> PLUGIN.getLangYml().getString("not-curse-color") ); /** @@ -40,7 +46,7 @@ public class EnchantmentType { public static final EnchantmentType CURSE = new EnchantmentType( "curse", false, - () -> Configs.LANG.getString("curse-color") + () -> PLUGIN.getLangYml().getString("curse-color") ); /** @@ -50,8 +56,8 @@ public class EnchantmentType { */ public static final EnchantmentType SPECIAL = new EnchantmentType( "special", - () -> !Configs.CONFIG.getBool("types.special.allow-multiple"), - () -> Configs.LANG.getString("special-color") + () -> !PLUGIN.getConfigYml().getBool("types.special.allow-multiple"), + () -> PLUGIN.getLangYml().getString("special-color") ); /** @@ -61,8 +67,8 @@ public class EnchantmentType { */ public static final EnchantmentType ARTIFACT = new EnchantmentType( "artifact", - () -> !Configs.CONFIG.getBool("types.artifact.allow-multiple"), - () -> Configs.LANG.getString("artifact-color"), + () -> !PLUGIN.getConfigYml().getBool("types.artifact.allow-multiple"), + () -> PLUGIN.getLangYml().getString("artifact-color"), Artifact.class ); @@ -74,7 +80,7 @@ public class EnchantmentType { public static final EnchantmentType SPELL = new EnchantmentType( "spell", true, - () -> Configs.LANG.getString("spell-color"), + () -> PLUGIN.getLangYml().getString("spell-color"), Spell.class ); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java index 560cd583..32de8b03 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java @@ -1,14 +1,13 @@ package com.willfp.ecoenchants.enchantments.support.merging.anvil; import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.ProxyUtils; -import com.willfp.eco.util.config.Configs; import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.proxy.ProxyConstants; import com.willfp.eco.util.tuplets.Pair; import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy; import com.willfp.ecoenchants.proxy.proxies.RepairCostProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -110,7 +109,7 @@ public class AnvilListeners extends PluginDependent implements Listener { return; } - if (Configs.CONFIG.getBool("anvil.rework-cost")) { + if (this.getPlugin().getConfigYml().getBool("anvil.rework-cost")) { int repairCost = ProxyUtils.getProxy(RepairCostProxy.class).getRepairCost(item); int reworkCount = NumberUtils.log2(repairCost + 1); if (repairCost == 0) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java index 871dc8fd..0fd6b51c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java @@ -1,7 +1,8 @@ package com.willfp.ecoenchants.enchantments.support.merging.anvil; -import com.willfp.eco.util.config.Configs; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.tuplets.Pair; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; @@ -23,6 +24,11 @@ import java.util.concurrent.atomic.AtomicInteger; @UtilityClass public class AnvilMerge { + /** + * Instance of EcoEnchants. + */ + private static final EcoEnchantsPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); + /** * Config key for allowing unsafe levels. */ @@ -126,8 +132,8 @@ public class AnvilMerge { if (rightLevel > level) { level = rightLevel; } else if (rightLevel == level - && ((rightLevel > enchantment.getMaxLevel() && Configs.CONFIG.getBool("anvil.allow-combining-unsafe")) - || ((rightLevel + 1) <= enchantment.getMaxLevel() || Configs.CONFIG.getBool(ALLOW_UNSAFE_KEY)))) { + && ((rightLevel > enchantment.getMaxLevel() && PLUGIN.getConfigYml().getBool("anvil.allow-combining-unsafe")) + || ((rightLevel + 1) <= enchantment.getMaxLevel() || PLUGIN.getConfigYml().getBool(ALLOW_UNSAFE_KEY)))) { level++; } rightEnchants.remove(enchantment); @@ -164,7 +170,7 @@ public class AnvilMerge { } if (canEnchantItem && !doesConflict.get()) { - if (Configs.CONFIG.getBool("anvil.hard-cap.enabled") && !player.hasPermission("ecoenchants.anvil.bypasshardcap") && outEnchants.size() >= Configs.CONFIG.getInt("anvil.hard-cap.cap")) { + if (PLUGIN.getConfigYml().getBool("anvil.hard-cap.enabled") && !player.hasPermission("ecoenchants.anvil.bypasshardcap") && outEnchants.size() >= PLUGIN.getConfigYml().getInt("anvil.hard-cap.cap")) { return; } outEnchants.put(enchantment, integer); @@ -189,7 +195,7 @@ public class AnvilMerge { })); outEnchants.forEach(((enchantment, integer) -> { - meta.addStoredEnchant(enchantment, integer, Configs.CONFIG.getBool("anvil.allow-existing-unsafe-levels") || Configs.CONFIG.getBool(ALLOW_UNSAFE_KEY)); + meta.addStoredEnchant(enchantment, integer, PLUGIN.getConfigYml().getBool("anvil.allow-existing-unsafe-levels") || PLUGIN.getConfigYml().getBool(ALLOW_UNSAFE_KEY)); })); meta.setDisplayName(name); @@ -202,7 +208,7 @@ public class AnvilMerge { })); outEnchants.forEach(((enchantment, integer) -> { - meta.addEnchant(enchantment, integer, Configs.CONFIG.getBool("anvil.allow-existing-unsafe-levels") || Configs.CONFIG.getBool(ALLOW_UNSAFE_KEY)); + meta.addEnchant(enchantment, integer, PLUGIN.getConfigYml().getBool("anvil.allow-existing-unsafe-levels") || PLUGIN.getConfigYml().getBool(ALLOW_UNSAFE_KEY)); })); if (output.getItemMeta() instanceof Damageable) { @@ -237,8 +243,8 @@ public class AnvilMerge { return new Pair<>(null, null); } - if (Configs.CONFIG.getBool("anvil.cost-exponent.enabled")) { - double exponent = Configs.CONFIG.getDouble("anvil.cost-exponent.exponent"); + if (PLUGIN.getConfigYml().getBool("anvil.cost-exponent.enabled")) { + double exponent = PLUGIN.getConfigYml().getDouble("anvil.cost-exponent.exponent"); int prevDelta = totalEnchantLevelDelta; double costMultiplier = Math.pow(exponent, totalEnchantLevelDelta); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java index aa72665e..6c439ba0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java @@ -2,7 +2,6 @@ package com.willfp.ecoenchants.enchantments.support.obtaining; import com.google.common.collect.ImmutableSet; import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.config.Configs; import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; @@ -76,7 +75,7 @@ public class EnchantingListeners extends PluginDependent implements Listener { int cost = event.getExpLevelCost(); Map toAdd = event.getEnchantsToAdd(); - if (!Configs.CONFIG.getBool("enchanting-table.enabled")) { + if (!this.getPlugin().getConfigYml().getBool("enchanting-table.enabled")) { this.getPlugin().getScheduler().runLater(() -> { ItemStack item0 = event.getInventory().getItem(0); event.getInventory().setItem(0, item0); @@ -105,11 +104,11 @@ public class EnchantingListeners extends PluginDependent implements Listener { double multiplier = 0.01; if (item.getType().equals(Material.BOOK) || item.getType().equals(Material.ENCHANTED_BOOK)) { - multiplier /= Configs.CONFIG.getInt("enchanting-table.book-times-less-likely"); + multiplier /= this.getPlugin().getConfigYml().getInt("enchanting-table.book-times-less-likely"); } - if (Configs.CONFIG.getBool("enchanting-table.reduce-probability.enabled")) { - multiplier /= Configs.CONFIG.getDouble("enchanting-table.reduce-probability.factor"); + if (this.getPlugin().getConfigYml().getBool("enchanting-table.reduce-probability.enabled")) { + multiplier /= this.getPlugin().getConfigYml().getDouble("enchanting-table.reduce-probability.factor"); } ArrayList enchantments = new ArrayList<>(EcoEnchants.values()); @@ -164,11 +163,11 @@ public class EnchantingListeners extends PluginDependent implements Listener { if (enchantment.getType().equals(EnchantmentType.SPECIAL)) { double enchantlevel1 = NumberUtils.randFloat(0, 1); - double enchantlevel2 = NumberUtils.bias(enchantlevel1, Configs.CONFIG.getDouble("enchanting-table.special-bias")); + double enchantlevel2 = NumberUtils.bias(enchantlevel1, this.getPlugin().getConfigYml().getDouble("enchanting-table.special-bias")); double enchantlevel3 = 1 / maxLevelDouble; level = (int) Math.ceil(enchantlevel2 / enchantlevel3); } else { - int maxLevel = Configs.CONFIG.getInt("enchanting-table.maximum-obtainable-level"); + int maxLevel = this.getPlugin().getConfigYml().getInt("enchanting-table.maximum-obtainable-level"); double enchantlevel1 = (cost / (double) enchantment.getRarity().getMinimumLevel()) / (maxLevel / (double) enchantment.getRarity().getMinimumLevel()); double enchantlevel2 = NumberUtils.triangularDistribution(0, 1, enchantlevel1); double enchantlevel3 = 1 / maxLevelDouble; @@ -178,7 +177,7 @@ public class EnchantingListeners extends PluginDependent implements Listener { level = NumberUtils.equalIfOver(level, enchantment.getMaxLevel()); toAdd.put(enchantment, level); - if (Configs.CONFIG.getBool("enchanting-table.cap-amount.enabled") && toAdd.size() >= Configs.CONFIG.getInt("enchanting-table.cap-amount.limit")) { + if (this.getPlugin().getConfigYml().getBool("enchanting-table.cap-amount.enabled") && toAdd.size() >= this.getPlugin().getConfigYml().getInt("enchanting-table.cap-amount.limit")) { break; } @@ -186,8 +185,8 @@ public class EnchantingListeners extends PluginDependent implements Listener { gotSpecial = true; } - if (Configs.CONFIG.getBool("enchanting-table.reduce-probability.enabled")) { - multiplier /= Configs.CONFIG.getDouble("enchanting-table.reduce-probability.factor"); + if (this.getPlugin().getConfigYml().getBool("enchanting-table.reduce-probability.enabled")) { + multiplier /= this.getPlugin().getConfigYml().getDouble("enchanting-table.reduce-probability.factor"); } } toAdd.forEach(event.getEnchantsToAdd()::putIfAbsent); @@ -197,8 +196,8 @@ public class EnchantingListeners extends PluginDependent implements Listener { CURRENTLY_ENCHANTING_SECONDARY.remove(player); } - if (gotSpecial && Configs.CONFIG.getBool("enchanting-table.notify-on-special")) { - player.sendMessage(Configs.LANG.getMessage("got-special")); + if (gotSpecial && this.getPlugin().getConfigYml().getBool("enchanting-table.notify-on-special")) { + player.sendMessage(this.getPlugin().getLangYml().getMessage("got-special")); } // Ew @@ -227,7 +226,7 @@ public class EnchantingListeners extends PluginDependent implements Listener { */ @EventHandler public void secondaryEnchant(@NotNull final PrepareItemEnchantEvent event) { - int maxLevel = Configs.CONFIG.getInt("enchanting-table.maximum-obtainable-level"); + int maxLevel = this.getPlugin().getConfigYml().getInt("enchanting-table.maximum-obtainable-level"); try { event.getOffers()[2].setCost(NumberUtils.equalIfOver(event.getOffers()[2].getCost(), maxLevel)); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java index c7d252f7..96206f93 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java @@ -1,8 +1,7 @@ package com.willfp.ecoenchants.enchantments.support.obtaining; - import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.config.Configs; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; @@ -28,6 +27,20 @@ import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; public class LootPopulator extends BlockPopulator { + /** + * Instance of ecoenchants. + */ + private final EcoEnchantsPlugin plugin; + + /** + * Create a new loot populator. + * + * @param plugin The plugin. + */ + public LootPopulator(@NotNull final EcoEnchantsPlugin plugin) { + this.plugin = plugin; + } + /** * Populate a chunk's loot chests. * @@ -38,7 +51,7 @@ public class LootPopulator extends BlockPopulator { public void populate(@NotNull final World world, @NotNull final Random random, @NotNull final Chunk chunk) { - if (!Configs.CONFIG.getBool("loot.enabled")) { + if (!plugin.getConfigYml().getBool("loot.enabled")) { return; } @@ -69,11 +82,11 @@ public class LootPopulator extends BlockPopulator { double multiplier = 0.01; if (item.getType().equals(Material.BOOK) || item.getType().equals(Material.ENCHANTED_BOOK)) { - multiplier /= Configs.CONFIG.getInt("loot.book-times-less-likely"); + multiplier /= plugin.getConfigYml().getInt("loot.book-times-less-likely"); } - if (Configs.CONFIG.getBool("loot.reduce-probability.enabled")) { - multiplier /= Configs.CONFIG.getDouble("loot.reduce-probability.factor"); + if (plugin.getConfigYml().getBool("loot.reduce-probability.enabled")) { + multiplier /= plugin.getConfigYml().getDouble("loot.reduce-probability.factor"); } for (EcoEnchant enchantment : enchantments) { @@ -119,7 +132,7 @@ public class LootPopulator extends BlockPopulator { if (enchantment.getType().equals(EnchantmentType.SPECIAL)) { double enchantlevel1 = NumberUtils.randFloat(0, 1); - double enchantlevel2 = NumberUtils.bias(enchantlevel1, Configs.CONFIG.getDouble("enchanting-table.special-bias")); + double enchantlevel2 = NumberUtils.bias(enchantlevel1, plugin.getConfigYml().getDouble("enchanting-table.special-bias")); double enchantlevel3 = 1 / (double) enchantment.getMaxLevel(); level = (int) Math.ceil(enchantlevel2 / enchantlevel3); } else { @@ -130,8 +143,8 @@ public class LootPopulator extends BlockPopulator { toAdd.put(enchantment, level); - if (Configs.CONFIG.getBool("loot.reduce-probability.enabled")) { - multiplier /= Configs.CONFIG.getDouble("loot.reduce-probability.factor"); + if (plugin.getConfigYml().getBool("loot.reduce-probability.enabled")) { + multiplier /= plugin.getConfigYml().getDouble("loot.reduce-probability.factor"); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java index 5f26e959..2a6180da 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java @@ -2,7 +2,8 @@ package com.willfp.ecoenchants.enchantments.support.obtaining; import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.config.Configs; +import com.willfp.eco.util.internal.PluginDependent; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; @@ -24,7 +25,16 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; -public class VillagerListeners implements Listener { +public class VillagerListeners extends PluginDependent implements Listener { + /** + * Create new villager listeners. + * + * @param plugin The plugin. + */ + public VillagerListeners(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + /** * Called on villager gain trade. * @@ -36,7 +46,7 @@ public class VillagerListeners implements Listener { return; } - if (!Configs.CONFIG.getBool("villager.enabled")) { + if (!this.getPlugin().getConfigYml().getBool("villager.enabled")) { return; } @@ -57,7 +67,7 @@ public class VillagerListeners implements Listener { ArrayList enchantments = new ArrayList<>(EcoEnchants.values()); Collections.shuffle(enchantments); // Prevent list bias towards early enchantments like telekinesis - double multiplier = 0.01 / Configs.CONFIG.getDouble("villager.book-times-less-likely"); + double multiplier = 0.01 / this.getPlugin().getConfigYml().getDouble("villager.book-times-less-likely"); for (EcoEnchant enchantment : enchantments) { if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) { @@ -76,7 +86,7 @@ public class VillagerListeners implements Listener { if (enchantment.getType().equals(EnchantmentType.SPECIAL)) { double enchantlevel1 = NumberUtils.randFloat(0, 1); - double enchantlevel2 = NumberUtils.bias(enchantlevel1, Configs.CONFIG.getDouble("enchanting-table.special-bias")); + double enchantlevel2 = NumberUtils.bias(enchantlevel1, this.getPlugin().getConfigYml().getDouble("enchanting-table.special-bias")); double enchantlevel3 = 1 / (double) enchantment.getMaxLevel(); level = (int) Math.ceil(enchantlevel2 / enchantlevel3); } else { @@ -116,7 +126,7 @@ public class VillagerListeners implements Listener { return; } - if (!Configs.CONFIG.getBool("villager.enabled")) { + if (!this.getPlugin().getConfigYml().getBool("villager.enabled")) { return; } @@ -183,7 +193,7 @@ public class VillagerListeners implements Listener { if (enchantment.getType().equals(EnchantmentType.SPECIAL)) { double enchantlevel1 = NumberUtils.randFloat(0, 1); - double enchantlevel2 = NumberUtils.bias(enchantlevel1, Configs.CONFIG.getDouble("enchanting-table.special-bias")); + double enchantlevel2 = NumberUtils.bias(enchantlevel1, this.getPlugin().getConfigYml().getDouble("enchanting-table.special-bias")); double enchantlevel3 = 1 / (double) enchantment.getMaxLevel(); level = (int) Math.ceil(enchantlevel2 / enchantlevel3); } else { @@ -196,8 +206,8 @@ public class VillagerListeners implements Listener { toAdd.put(enchantment, level); - if (Configs.CONFIG.getBool("villager.reduce-probability.enabled")) { - multiplier /= Configs.CONFIG.getDouble("villager.reduce-probability.factor"); + if (this.getPlugin().getConfigYml().getBool("villager.reduce-probability.enabled")) { + multiplier /= this.getPlugin().getConfigYml().getDouble("villager.reduce-probability.factor"); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java index 693d133c..dd6b200a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java @@ -1,11 +1,12 @@ package com.willfp.ecoenchants.enchantments.util; -import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; import com.willfp.eco.util.DurabilityUtils; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; +import com.willfp.ecoenchants.proxy.proxies.RepairCostProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import lombok.experimental.UtilityClass; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java index 8f3d040a..ed7ee6c2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java @@ -1,14 +1,14 @@ package com.willfp.ecoenchants.enchantments.util; import com.google.common.collect.Sets; -import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.events.armorequip.ArmorEquipEvent; -import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.integrations.antigrief.AntigriefManager; +import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.integrations.mcmmo.McmmoManager; +import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Arrow; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/util/ProxyUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/util/ProxyUtils.java new file mode 100644 index 00000000..bd016bc1 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/util/ProxyUtils.java @@ -0,0 +1,21 @@ +package com.willfp.ecoenchants.util; + +import com.willfp.eco.util.proxy.AbstractProxy; +import com.willfp.ecoenchants.EcoEnchantsPlugin; +import com.willfp.ecoenchants.proxy.util.ProxyFactory; +import lombok.experimental.UtilityClass; +import org.jetbrains.annotations.NotNull; + +@UtilityClass +public class ProxyUtils { + /** + * Get the implementation of a specified proxy. + * + * @param proxyClass The proxy interface. + * @param The type of the proxy. + * @return The proxy implementation. + */ + public @NotNull T getProxy(@NotNull final Class proxyClass) { + return new ProxyFactory<>(EcoEnchantsPlugin.getInstance(), proxyClass).getProxy(); + } +} diff --git a/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/util/ProxyFactory.java b/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/util/ProxyFactory.java new file mode 100644 index 00000000..017baa37 --- /dev/null +++ b/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/util/ProxyFactory.java @@ -0,0 +1,75 @@ +package com.willfp.ecoenchants.proxy.util; + +import com.willfp.eco.util.internal.PluginDependent; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.eco.util.proxy.AbstractProxy; +import com.willfp.eco.util.proxy.ProxyConstants; +import com.willfp.eco.util.proxy.UnsupportedVersionException; +import org.jetbrains.annotations.NotNull; + +import java.util.IdentityHashMap; +import java.util.Map; + +public class ProxyFactory extends PluginDependent { + /** + * Cached proxy implementations in order to not perform expensive reflective class-finding. + */ + private static final Map, AbstractProxy> CACHE = new IdentityHashMap<>(); + + /** + * The class of the proxy interface. + */ + private final Class proxyClass; + + /** + * Create a new Proxy Factory for a specific type. + * + * @param plugin The plugin to create proxies for. + * @param proxyClass The class of the proxy interface. + */ + public ProxyFactory(@NotNull final AbstractEcoPlugin plugin, + @NotNull final Class proxyClass) { + super(plugin); + this.proxyClass = proxyClass; + } + + /** + * Get the implementation of a proxy. + * + * @return The proxy implementation. + */ + public @NotNull T getProxy() { + try { + T cachedProxy = attemptCache(); + if (cachedProxy != null) { + return cachedProxy; + } + + String className = this.getPlugin().getProxyPackage() + "." + ProxyConstants.NMS_VERSION + "." + proxyClass.getSimpleName().replace("Proxy", ""); + final Class class2 = Class.forName(className); + Object instance = class2.getConstructor().newInstance(); + if (proxyClass.isAssignableFrom(class2) && proxyClass.isInstance(instance)) { + T proxy = proxyClass.cast(instance); + CACHE.put(proxyClass, proxy); + return proxy; + } + } catch (Exception e) { + // If not returned, then throw error + } + + throw new UnsupportedVersionException("You're running an unsupported server version: " + ProxyConstants.NMS_VERSION); + } + + private T attemptCache() { + Object proxy = CACHE.get(proxyClass); + if (proxy == null) { + return null; + } + + if (proxyClass.isInstance(proxy)) { + return proxyClass.cast(proxy); + } + + return null; + } +} diff --git a/eco-extensions/alchemy/build.gradle b/eco-extensions/alchemy/build.gradle index 1579a7be..3bc7a3ec 100644 --- a/eco-extensions/alchemy/build.gradle +++ b/eco-extensions/alchemy/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '3.0.1' +version '4.0.0' description = 'Alchemy Extension' shadowJar { diff --git a/eco-extensions/alchemy/src/main/java/com/willfp/ecoenchants/alchemy/AlchemyMain.java b/eco-extensions/alchemy/src/main/java/com/willfp/ecoenchants/alchemy/AlchemyMain.java index 5db66515..b547d357 100644 --- a/eco-extensions/alchemy/src/main/java/com/willfp/ecoenchants/alchemy/AlchemyMain.java +++ b/eco-extensions/alchemy/src/main/java/com/willfp/ecoenchants/alchemy/AlchemyMain.java @@ -1,7 +1,9 @@ package com.willfp.ecoenchants.alchemy; import com.willfp.eco.util.extensions.Extension; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; +import org.jetbrains.annotations.NotNull; public class AlchemyMain extends Extension { /** @@ -9,6 +11,10 @@ public class AlchemyMain extends Extension { */ public static final EcoEnchant ALCHEMY = new Alchemy(); + public AlchemyMain(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + @Override public void onEnable() { // Handled by super diff --git a/eco-extensions/biomes/build.gradle b/eco-extensions/biomes/build.gradle index b8f44f55..8a9fe71c 100644 --- a/eco-extensions/biomes/build.gradle +++ b/eco-extensions/biomes/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '3.0.1' +version '4.0.0' description = 'Biomes Extension' shadowJar { diff --git a/eco-extensions/biomes/src/main/java/com/willfp/ecoenchants/biomes/BiomesMain.java b/eco-extensions/biomes/src/main/java/com/willfp/ecoenchants/biomes/BiomesMain.java index ef64826d..86468d8e 100644 --- a/eco-extensions/biomes/src/main/java/com/willfp/ecoenchants/biomes/BiomesMain.java +++ b/eco-extensions/biomes/src/main/java/com/willfp/ecoenchants/biomes/BiomesMain.java @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.biomes; import com.willfp.eco.util.extensions.Extension; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.biomes.enchants.defensive.Elevation; import com.willfp.ecoenchants.biomes.enchants.defensive.Glacial; import com.willfp.ecoenchants.biomes.enchants.defensive.HeatTreated; @@ -13,6 +14,7 @@ import com.willfp.ecoenchants.biomes.enchants.offensive.Dehydration; import com.willfp.ecoenchants.biomes.enchants.offensive.Icelord; import com.willfp.ecoenchants.biomes.enchants.offensive.Rainforest; import com.willfp.ecoenchants.enchantments.EcoEnchant; +import org.jetbrains.annotations.NotNull; public class BiomesMain extends Extension { public static final EcoEnchant ELEVATION = new Elevation(); @@ -26,6 +28,10 @@ public class BiomesMain extends Extension { public static final EcoEnchant ICELORD = new Icelord(); public static final EcoEnchant RAINFOREST = new Rainforest(); + public BiomesMain(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + @Override public void onEnable() { // Handled by super diff --git a/eco-extensions/effects/build.gradle b/eco-extensions/effects/build.gradle index 1793c990..78e1557f 100644 --- a/eco-extensions/effects/build.gradle +++ b/eco-extensions/effects/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '3.0.1' +version '4.0.0' description = 'Effects Extension' shadowJar { diff --git a/eco-extensions/effects/src/main/java/com/willfp/ecoenchants/effects/EffectsMain.java b/eco-extensions/effects/src/main/java/com/willfp/ecoenchants/effects/EffectsMain.java index 527b4179..cdb07f25 100644 --- a/eco-extensions/effects/src/main/java/com/willfp/ecoenchants/effects/EffectsMain.java +++ b/eco-extensions/effects/src/main/java/com/willfp/ecoenchants/effects/EffectsMain.java @@ -2,12 +2,14 @@ package com.willfp.ecoenchants.effects; import com.willfp.eco.util.extensions.Extension; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.effects.enchants.JumpBoost; import com.willfp.ecoenchants.effects.enchants.NightVision; import com.willfp.ecoenchants.effects.enchants.Regeneration; import com.willfp.ecoenchants.effects.enchants.Speed; import com.willfp.ecoenchants.effects.enchants.WaterBreathing; import com.willfp.ecoenchants.enchantments.EcoEnchant; +import org.jetbrains.annotations.NotNull; public class EffectsMain extends Extension { public static final EcoEnchant JUMP_BOOST = new JumpBoost(); @@ -16,6 +18,10 @@ public class EffectsMain extends Extension { public static final EcoEnchant SPEED = new Speed(); public static final EcoEnchant WATER_BREATHING = new WaterBreathing(); + public EffectsMain(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + @Override public void onEnable() { // Handled by super diff --git a/eco-extensions/endershot/build.gradle b/eco-extensions/endershot/build.gradle index d7cfa250..176fd9dc 100644 --- a/eco-extensions/endershot/build.gradle +++ b/eco-extensions/endershot/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '3.0.1' +version '4.0.0' description = 'Endershot Extension' shadowJar { diff --git a/eco-extensions/endershot/src/main/java/com/willfp/ecoenchants/endershot/EndershotMain.java b/eco-extensions/endershot/src/main/java/com/willfp/ecoenchants/endershot/EndershotMain.java index 93e9cff9..3ed5f945 100644 --- a/eco-extensions/endershot/src/main/java/com/willfp/ecoenchants/endershot/EndershotMain.java +++ b/eco-extensions/endershot/src/main/java/com/willfp/ecoenchants/endershot/EndershotMain.java @@ -2,11 +2,17 @@ package com.willfp.ecoenchants.endershot; import com.willfp.eco.util.extensions.Extension; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; +import org.jetbrains.annotations.NotNull; public class EndershotMain extends Extension { public static final EcoEnchant ENDERSHOT = new Endershot(); + public EndershotMain(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + @Override public void onEnable() { // Handled by super diff --git a/eco-extensions/firewand/build.gradle b/eco-extensions/firewand/build.gradle index c415db80..6e067633 100644 --- a/eco-extensions/firewand/build.gradle +++ b/eco-extensions/firewand/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '3.0.1' +version '4.0.0' description = 'Firewand Extension' shadowJar { diff --git a/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/FirewandMain.java b/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/FirewandMain.java index f9f0feb5..12b07d0a 100644 --- a/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/FirewandMain.java +++ b/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/FirewandMain.java @@ -1,11 +1,17 @@ package com.willfp.ecoenchants.firewand; import com.willfp.eco.util.extensions.Extension; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; +import org.jetbrains.annotations.NotNull; public class FirewandMain extends Extension { public static final EcoEnchant FIREWAND = new Firewand(); + public FirewandMain(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + @Override public void onEnable() { // Handled by super diff --git a/eco-extensions/mmo/build.gradle b/eco-extensions/mmo/build.gradle index 48d6692c..dbb9631f 100644 --- a/eco-extensions/mmo/build.gradle +++ b/eco-extensions/mmo/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '3.0.1' +version '4.0.0' description = 'MMO Extension' repositories { @@ -9,7 +9,7 @@ repositories { } dependencies { - compileOnly 'net.Indyuce:MMOCore:1.6' + compileOnly 'net.Indyuce:MMOCore:1.6.2' compileOnly 'net.Indyuce:MMOItems:6.5' compileOnly 'net.Indyuce:MMOLib:1.7.3' } @@ -18,6 +18,6 @@ configurations.all { exclude group: 'com.mojang', module: 'authlib' } -jar { +shadowJar { archiveFileName = project.getDescription() + " v" + project.version + ".jar" } \ No newline at end of file diff --git a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/MMOMain.java b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/MMOMain.java index c0a83b03..7dbeee6d 100644 --- a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/MMOMain.java +++ b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/MMOMain.java @@ -1,20 +1,10 @@ package com.willfp.ecoenchants.mmo; import com.willfp.eco.util.extensions.Extension; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; -import com.willfp.ecoenchants.mmo.enchants.abilities.Discounted; -import com.willfp.ecoenchants.mmo.enchants.abilities.Recover; -import com.willfp.ecoenchants.mmo.enchants.mana.Augment; -import com.willfp.ecoenchants.mmo.enchants.mana.Drain; -import com.willfp.ecoenchants.mmo.enchants.mana.Elixir; -import com.willfp.ecoenchants.mmo.enchants.mana.Siphon; -import com.willfp.ecoenchants.mmo.enchants.mana.Spirituality; -import com.willfp.ecoenchants.mmo.enchants.misc.Strengthening; -import com.willfp.ecoenchants.mmo.enchants.stamina.Athletic; -import com.willfp.ecoenchants.mmo.enchants.stamina.Endurance; -import com.willfp.ecoenchants.mmo.enchants.stamina.Fortitude; -import com.willfp.ecoenchants.mmo.enchants.stamina.Motivate; import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; public class MMOMain extends Extension { public static final EcoEnchant ELIXIR = new Elixir(); @@ -30,9 +20,13 @@ public class MMOMain extends Extension { public static final EcoEnchant ATHLETIC = new Athletic(); public static final EcoEnchant STRENGTHENING = new Strengthening(); + public MMOMain(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + @Override protected void onEnable() { - if(!MMOPrerequisites.HAS_MMOCORE.isMet()) { + if (!MMOPrerequisites.HAS_MMOCORE.isMet()) { Bukkit.getLogger().severe("MMO Extension requires MMOCore to be installed!"); Bukkit.getLogger().severe("Disabling..."); this.disable(); diff --git a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/MMOPrerequisites.java b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/MMOPrerequisites.java index a577f514..119b7b8e 100644 --- a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/MMOPrerequisites.java +++ b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/MMOPrerequisites.java @@ -1,6 +1,5 @@ package com.willfp.ecoenchants.mmo; - import com.willfp.eco.util.optional.Prerequisite; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; diff --git a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/mana/Elixir.java b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/mana/Elixir.java index f08267e2..052a5ed4 100644 --- a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/mana/Elixir.java +++ b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/mana/Elixir.java @@ -1,7 +1,5 @@ package com.willfp.ecoenchants.mmo.enchants.mana; - -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.mmo.integrations.mmo.MMOManager; diff --git a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/misc/Strengthening.java b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/misc/Strengthening.java index c6fdd9c0..91e93328 100644 --- a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/misc/Strengthening.java +++ b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/misc/Strengthening.java @@ -1,14 +1,8 @@ package com.willfp.ecoenchants.mmo.enchants.misc; - import com.willfp.eco.util.events.armorequip.ArmorEquipEvent; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; -import com.willfp.ecoenchants.mmo.structure.MMOEnchantment; -import net.mmogroup.mmolib.MMOLib; -import net.mmogroup.mmolib.api.player.MMOPlayerData; -import net.mmogroup.mmolib.api.stat.SharedStat; -import net.mmogroup.mmolib.api.stat.modifier.StatModifier; import org.bukkit.entity.Player; public class Strengthening extends MMOEnchantment { diff --git a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/stamina/Motivate.java b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/stamina/Motivate.java index fe0ac4ae..0efcdf78 100644 --- a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/stamina/Motivate.java +++ b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/enchants/stamina/Motivate.java @@ -1,7 +1,5 @@ package com.willfp.ecoenchants.mmo.enchants.stamina; - -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.mmo.integrations.mmo.MMOManager; diff --git a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/structure/MMOEnchantment.java b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/structure/MMOEnchantment.java index 4c2a77e1..148ce21c 100644 --- a/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/structure/MMOEnchantment.java +++ b/eco-extensions/mmo/src/main/java/com/willfp/ecoenchants/mmo/structure/MMOEnchantment.java @@ -1,10 +1,8 @@ package com.willfp.ecoenchants.mmo.structure; - import com.willfp.eco.util.optional.Prerequisite; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; -import com.willfp.ecoenchants.mmo.MMOPrerequisites; public abstract class MMOEnchantment extends EcoEnchant implements MMOEnchant { protected MMOEnchantment(String key, EnchantmentType type, Prerequisite... prerequisites) { diff --git a/eco-extensions/precision/build.gradle b/eco-extensions/precision/build.gradle index fbbe3894..e797fe32 100644 --- a/eco-extensions/precision/build.gradle +++ b/eco-extensions/precision/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '3.0.1' +version '4.0.0' description = 'Precision Extension' shadowJar { diff --git a/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/Precision.java b/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/Precision.java index 861868a3..7fc0823c 100644 --- a/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/Precision.java +++ b/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/Precision.java @@ -1,12 +1,12 @@ package com.willfp.ecoenchants.precision; -import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; -import com.willfp.eco.util.ProxyUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.proxy.proxies.TridentStackProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.GameMode; import org.bukkit.entity.Enderman; import org.bukkit.entity.LivingEntity; diff --git a/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/PrecisionMain.java b/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/PrecisionMain.java index f76269c2..09610e29 100644 --- a/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/PrecisionMain.java +++ b/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/PrecisionMain.java @@ -1,11 +1,17 @@ package com.willfp.ecoenchants.precision; import com.willfp.eco.util.extensions.Extension; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; +import org.jetbrains.annotations.NotNull; public class PrecisionMain extends Extension { public static final EcoEnchant PRECISION = new Precision(); + public PrecisionMain(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + @Override public void onEnable() { // Handled by super diff --git a/eco-extensions/sprint-artifacts/build.gradle b/eco-extensions/sprint-artifacts/build.gradle index b4eb5d37..9d6e3cc9 100644 --- a/eco-extensions/sprint-artifacts/build.gradle +++ b/eco-extensions/sprint-artifacts/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '3.0.1' +version '4.0.0' description = 'Sprint Artifacts Extension' shadowJar { diff --git a/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsMain.java b/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsMain.java index ad44422a..8863a922 100644 --- a/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsMain.java +++ b/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsMain.java @@ -1,9 +1,15 @@ package com.willfp.ecoenchants.sprintartifacts; import com.willfp.eco.util.extensions.Extension; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; public class SprintArtifactsMain extends Extension { + public SprintArtifactsMain(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + @Override public void onEnable() { Bukkit.getPluginManager().registerEvents(new SprintArtifactsListener(), this.getPlugin()); diff --git a/eco-extensions/summoning/build.gradle b/eco-extensions/summoning/build.gradle index feae2c7e..bcea1a36 100644 --- a/eco-extensions/summoning/build.gradle +++ b/eco-extensions/summoning/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '3.0.1' +version '4.0.0' description = 'Summoning Extension' shadowJar { diff --git a/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java b/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java index 46b576ec..913b7ef8 100644 --- a/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java +++ b/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java @@ -1,13 +1,13 @@ package com.willfp.ecoenchants.summoning; -import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.optional.Prerequisite; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; +import com.willfp.ecoenchants.proxy.proxies.CooldownProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.attribute.Attribute; diff --git a/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningMain.java b/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningMain.java index 75c8eea2..a1d5cf23 100644 --- a/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningMain.java +++ b/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningMain.java @@ -1,12 +1,14 @@ package com.willfp.ecoenchants.summoning; import com.willfp.eco.util.extensions.Extension; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.summoning.enchants.Crawler; import com.willfp.ecoenchants.summoning.enchants.Firestorm; import com.willfp.ecoenchants.summoning.enchants.Ghoul; import com.willfp.ecoenchants.summoning.enchants.Metallic; import com.willfp.ecoenchants.summoning.enchants.Mortality; +import org.jetbrains.annotations.NotNull; public class SummoningMain extends Extension { public static final EcoEnchant METALLIC = new Metallic(); @@ -15,6 +17,10 @@ public class SummoningMain extends Extension { public static final EcoEnchant GHOUL = new Ghoul(); public static final EcoEnchant CRAWLER = new Crawler(); + public SummoningMain(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + @Override public void onEnable() { // Handled by super diff --git a/eco-extensions/xray/build.gradle b/eco-extensions/xray/build.gradle index 53d216be..ce853c2e 100644 --- a/eco-extensions/xray/build.gradle +++ b/eco-extensions/xray/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '1.0.2' +version '2.0.0' description = 'Xray Extension' shadowJar { diff --git a/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/XrayMain.java b/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/XrayMain.java index e406bd6d..a8565424 100644 --- a/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/XrayMain.java +++ b/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/XrayMain.java @@ -1,11 +1,17 @@ package com.willfp.ecoenchants.xray; import com.willfp.eco.util.extensions.Extension; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; +import org.jetbrains.annotations.NotNull; public class XrayMain extends Extension { public static final EcoEnchant XRAY = new Xray(); + public XrayMain(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + @Override public void onEnable() { // Handled by super From cd33d28b32cd1e2768ea4f44e96c7ca11f69fa8d Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 18 Jan 2021 18:28:22 +0000 Subject: [PATCH 11/19] Removed unneeded getInstance calls --- .../ecoenchants/display/EnchantDisplay.java | 2 +- .../display/options/DescriptionOptions.java | 25 ++++++++------ .../display/options/DisplayOptions.java | 33 +++++++++---------- .../display/options/NumbersOptions.java | 23 ++++++++----- .../display/options/ShrinkOptions.java | 25 ++++++++------ .../support/merging/anvil/AnvilMerge.java | 1 - 6 files changed, 61 insertions(+), 48 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index abaf2b96..f8c9a9c8 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -56,7 +56,7 @@ public class EnchantDisplay { /** * The configurable options for displaying enchantments. */ - public static final DisplayOptions OPTIONS = new DisplayOptions(); + public static final DisplayOptions OPTIONS = new DisplayOptions(PLUGIN); /** * Update config values. diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java index 2394138f..f53b843c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java @@ -1,16 +1,12 @@ package com.willfp.ecoenchants.display.options; import com.willfp.eco.util.StringUtils; +import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.ecoenchants.EcoEnchantsPlugin; import lombok.Getter; +import org.jetbrains.annotations.NotNull; -public class DescriptionOptions { - /** - * Instance of EcoEnchants. - */ - public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); - +public class DescriptionOptions extends PluginDependent { /** * The threshold below which to describe enchantments. */ @@ -29,12 +25,21 @@ public class DescriptionOptions { @Getter private String color; + /** + * Create new description options. + * + * @param plugin EcoEnchants. + */ + public DescriptionOptions(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + /** * Update the options. */ public void update() { - threshold = PLUGIN.getConfigYml().getInt("lore.describe.before-lines"); - enabled = PLUGIN.getConfigYml().getBool("lore.describe.enabled"); - color = StringUtils.translate(PLUGIN.getLangYml().getString("description-color")); + threshold = this.getPlugin().getConfigYml().getInt("lore.describe.before-lines"); + enabled = this.getPlugin().getConfigYml().getBool("lore.describe.enabled"); + color = StringUtils.translate(this.getPlugin().getLangYml().getString("description-color")); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java index d7ba80dd..ef4a5d20 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java @@ -1,7 +1,7 @@ package com.willfp.ecoenchants.display.options; +import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter; import com.willfp.ecoenchants.display.options.sorting.SortParameters; import com.willfp.ecoenchants.display.options.sorting.SorterManager; @@ -9,6 +9,7 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import lombok.Getter; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.HashSet; @@ -17,12 +18,7 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -public class DisplayOptions { - /** - * Instance of EcoEnchants. - */ - public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); - +public class DisplayOptions extends PluginDependent { /** * The enchantment sorter being used. */ @@ -33,19 +29,19 @@ public class DisplayOptions { * The description options being used. */ @Getter - private final DescriptionOptions descriptionOptions = new DescriptionOptions(); + private final DescriptionOptions descriptionOptions = new DescriptionOptions(this.getPlugin()); /** * The enchantment level options being used. */ @Getter - private final NumbersOptions numbersOptions = new NumbersOptions(); + private final NumbersOptions numbersOptions = new NumbersOptions(this.getPlugin()); /** * The shrink options being used. */ @Getter - private final ShrinkOptions shrinkOptions = new ShrinkOptions(); + private final ShrinkOptions shrinkOptions = new ShrinkOptions(this.getPlugin()); /** * The enchantment types, sorted according to config. @@ -67,9 +63,12 @@ public class DisplayOptions { /** * Instantiate new display options. + * + * @param plugin EcoEnchants. */ @ApiStatus.Internal - public DisplayOptions() { + public DisplayOptions(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); update(); } @@ -82,24 +81,24 @@ public class DisplayOptions { shrinkOptions.update(); sortedTypes.clear(); - sortedTypes.addAll(PLUGIN.getConfigYml().getStrings("lore.type-ordering").stream() + sortedTypes.addAll(this.getPlugin().getConfigYml().getStrings("lore.type-ordering").stream() .map(typeName -> EnchantmentType.values().stream().filter(type -> type.getName().equalsIgnoreCase(typeName)).findFirst().orElse(null)) .filter(Objects::nonNull) .collect(Collectors.toList())); sortedTypes.addAll(EnchantmentType.values().stream().filter(enchantmentType -> !sortedTypes.contains(enchantmentType)).collect(Collectors.toList())); sortedRarities.clear(); - sortedRarities.addAll(PLUGIN.getConfigYml().getStrings("lore.rarity-ordering").stream() + sortedRarities.addAll(this.getPlugin().getConfigYml().getStrings("lore.rarity-ordering").stream() .map(rarityName -> EnchantmentRarity.values().stream().filter(rarity -> rarity.getName().equalsIgnoreCase(rarityName)).findFirst().orElse(null)) .filter(Objects::nonNull) .collect(Collectors.toList())); sortedRarities.addAll(EnchantmentRarity.values().stream().filter(enchantmentRarity -> !sortedRarities.contains(enchantmentRarity)).collect(Collectors.toList())); - useLoreGetter = PLUGIN.getConfigYml().getBool("advanced.lore-getter"); + useLoreGetter = this.getPlugin().getConfigYml().getBool("advanced.lore-getter"); - boolean byType = PLUGIN.getConfigYml().getBool("lore.sort-by-type"); - boolean byLength = PLUGIN.getConfigYml().getBool("lore.sort-by-length"); - boolean byRarity = PLUGIN.getConfigYml().getBool("lore.sort-by-rarity"); + boolean byType = this.getPlugin().getConfigYml().getBool("lore.sort-by-type"); + boolean byLength = this.getPlugin().getConfigYml().getBool("lore.sort-by-length"); + boolean byRarity = this.getPlugin().getConfigYml().getBool("lore.sort-by-rarity"); Set params = new HashSet<>(); if (byType) { params.add(SortParameters.TYPE); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java index 24625af0..0661faf9 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/NumbersOptions.java @@ -1,15 +1,11 @@ package com.willfp.ecoenchants.display.options; +import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.ecoenchants.EcoEnchantsPlugin; import lombok.Getter; +import org.jetbrains.annotations.NotNull; -public class NumbersOptions { - /** - * Instance of EcoEnchants. - */ - public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); - +public class NumbersOptions extends PluginDependent { /** * If numerals should be used. *

@@ -24,11 +20,20 @@ public class NumbersOptions { @Getter private int threshold; + /** + * Create new numbers options. + * + * @param plugin EcoEnchants. + */ + public NumbersOptions(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + /** * Update the options. */ public void update() { - useNumerals = PLUGIN.getConfigYml().getBool("lore.use-numerals"); - threshold = PLUGIN.getConfigYml().getInt("lore.use-numbers-above-threshold"); + useNumerals = this.getPlugin().getConfigYml().getBool("lore.use-numerals"); + threshold = this.getPlugin().getConfigYml().getInt("lore.use-numbers-above-threshold"); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java index b9fb6194..4611e534 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/ShrinkOptions.java @@ -1,15 +1,11 @@ package com.willfp.ecoenchants.display.options; +import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.ecoenchants.EcoEnchantsPlugin; import lombok.Getter; +import org.jetbrains.annotations.NotNull; -public class ShrinkOptions { - /** - * Instance of EcoEnchants. - */ - public static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance(); - +public class ShrinkOptions extends PluginDependent { /** * The threshold above which enchantments will be shrunk. */ @@ -28,12 +24,21 @@ public class ShrinkOptions { @Getter private int shrinkPerLine; + /** + * Create new shrink options. + * + * @param plugin EcoEnchants. + */ + public ShrinkOptions(@NotNull final AbstractEcoPlugin plugin) { + super(plugin); + } + /** * Update the options. */ public void update() { - threshold = PLUGIN.getConfigYml().getInt("lore.shrink.after-lines"); - enabled = PLUGIN.getConfigYml().getBool("lore.shrink.enabled"); - shrinkPerLine = PLUGIN.getConfigYml().getInt("lore.shrink.maximum-per-line"); + threshold = this.getPlugin().getConfigYml().getInt("lore.shrink.after-lines"); + enabled = this.getPlugin().getConfigYml().getBool("lore.shrink.enabled"); + shrinkPerLine = this.getPlugin().getConfigYml().getInt("lore.shrink.maximum-per-line"); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java index 0fd6b51c..937dd51e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java @@ -1,6 +1,5 @@ package com.willfp.ecoenchants.enchantments.support.merging.anvil; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.tuplets.Pair; import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; From 423b092a3a35d69a957538a0ce0f0f10a67d1760 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 19 Jan 2021 17:46:29 +0000 Subject: [PATCH 12/19] Updated to eco 3.1.0 --- build.gradle | 2 +- .../proxy/v1_15_R1/ChatComponent.java | 11 -- .../proxy/v1_15_R1/VillagerTrade.java | 48 -------- .../proxy/v1_16_R1/ChatComponent.java | 114 ------------------ .../proxy/v1_16_R1/VillagerTrade.java | 48 -------- .../proxy/v1_16_R2/ChatComponent.java | 114 ------------------ .../proxy/v1_16_R2/VillagerTrade.java | 48 -------- .../proxy/v1_16_R3/ChatComponent.java | 114 ------------------ .../proxy/v1_16_R3/VillagerTrade.java | 48 -------- .../willfp/ecoenchants/EcoEnchantsPlugin.java | 33 +++-- .../display/packets/PacketChat.java | 41 ------- .../packets/PacketOpenWindowMerchant.java | 42 ------- .../packets/PacketSetCreativeSlot.java | 26 ---- .../display/packets/PacketSetSlot.java | 40 ------ .../display/packets/PacketWindowItems.java | 45 ------- .../proxy/proxies/ChatComponentProxy.java | 14 --- .../proxy/proxies/VillagerTradeProxy.java | 13 -- 17 files changed, 21 insertions(+), 780 deletions(-) delete mode 100644 eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_15_R1/ChatComponent.java delete mode 100644 eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_15_R1/VillagerTrade.java delete mode 100644 eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/ChatComponent.java delete mode 100644 eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/VillagerTrade.java delete mode 100644 eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/ChatComponent.java delete mode 100644 eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/VillagerTrade.java delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/ChatComponent.java delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/VillagerTrade.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketChat.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketOpenWindowMerchant.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketSetCreativeSlot.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketSetSlot.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketWindowItems.java delete mode 100644 eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/ChatComponentProxy.java delete mode 100644 eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/VillagerTradeProxy.java diff --git a/build.gradle b/build.gradle index dd1a20e0..428d4aa5 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:3.0.0' + compileOnly 'com.willfp:eco:3.1.0' compileOnly 'org.jetbrains:annotations:19.0.0' diff --git a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_15_R1/ChatComponent.java b/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_15_R1/ChatComponent.java deleted file mode 100644 index 5a0c32be..00000000 --- a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_15_R1/ChatComponent.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_15_R1; - -import com.willfp.ecoenchants.proxy.proxies.ChatComponentProxy; -import org.jetbrains.annotations.NotNull; - -public final class ChatComponent implements ChatComponentProxy { - @Override - public Object modifyComponent(@NotNull final Object object) { - return object; - } -} diff --git a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_15_R1/VillagerTrade.java b/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_15_R1/VillagerTrade.java deleted file mode 100644 index 20c2666c..00000000 --- a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_15_R1/VillagerTrade.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_15_R1; - -import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy; -import com.willfp.ecoenchants.display.EnchantDisplay; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftMerchantRecipe; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.MerchantRecipe; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public final class VillagerTrade implements VillagerTradeProxy { - @Override - public void displayTradeEnchantments(@NotNull final MerchantRecipe merchantRecipe) { - try { - // Enables removing final modifier - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - - // Bukkit MerchantRecipe result - Field fResult = MerchantRecipe.class.getDeclaredField("result"); - fResult.setAccessible(true); - ItemStack result = EnchantDisplay.displayEnchantments(merchantRecipe.getResult()); - EnchantDisplay.addV(result); - fResult.set(merchantRecipe, result); - - // Get NMS MerchantRecipe from CraftMerchantRecipe - Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle"); - fHandle.setAccessible(true); - net.minecraft.server.v1_15_R1.MerchantRecipe handle = (net.minecraft.server.v1_15_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe - modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final - - Field fSelling = net.minecraft.server.v1_15_R1.MerchantRecipe.class.getDeclaredField("sellingItem"); - fSelling.setAccessible(true); - modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL); - - ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem); - EnchantDisplay.displayEnchantments(selling); - EnchantDisplay.addV(selling); - - fSelling.set(handle, CraftItemStack.asNMSCopy(selling)); - } catch (IllegalAccessException | NoSuchFieldException e) { - e.printStackTrace(); - } - } -} diff --git a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/ChatComponent.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/ChatComponent.java deleted file mode 100644 index 80247374..00000000 --- a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/ChatComponent.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R1; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.willfp.ecoenchants.display.EnchantDisplay; -import com.willfp.ecoenchants.proxy.proxies.ChatComponentProxy; -import net.minecraft.server.v1_16_R1.ChatBaseComponent; -import net.minecraft.server.v1_16_R1.ChatHoverable; -import net.minecraft.server.v1_16_R1.ChatMessage; -import net.minecraft.server.v1_16_R1.ChatModifier; -import net.minecraft.server.v1_16_R1.IChatBaseComponent; -import net.minecraft.server.v1_16_R1.MojangsonParser; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; - -public final class ChatComponent implements ChatComponentProxy { - @Override - public Object modifyComponent(@NotNull final Object object) { - if (!(object instanceof IChatBaseComponent)) { - return object; - } - - IChatBaseComponent chatComponent = (IChatBaseComponent) object; - chatComponent.stream().forEach(this::modifyBaseComponent); - - return chatComponent; - } - - private void modifyBaseComponent(@NotNull final IChatBaseComponent component) { - component.getSiblings().forEach(this::modifyBaseComponent); - if (component instanceof ChatMessage) { - Arrays.stream(((ChatMessage) component).getArgs()) - .filter(o -> o instanceof IChatBaseComponent) - .map(o -> (IChatBaseComponent) o) - .forEach(this::modifyBaseComponent); - } - - ChatHoverable hoverable = component.getChatModifier().getHoverEvent(); - - if (hoverable == null) { - return; - } - - JsonObject jsonObject = hoverable.b(); - JsonElement json = hoverable.b().get("contents"); - if (json.getAsJsonObject().get("id") == null) { - return; - } - if (json.getAsJsonObject().get("tag") == null) { - return; - } - String id = json.getAsJsonObject().get("id").toString(); - String tag = json.getAsJsonObject().get("tag").toString(); - ItemStack itemStack = getFromTag(tag, id); - - ItemMeta meta = itemStack.getItemMeta(); - assert meta != null; - boolean hideEnchants = false; - if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) { - hideEnchants = true; - } - - itemStack = EnchantDisplay.displayEnchantments(itemStack, hideEnchants); - EnchantDisplay.addV(itemStack); - - json.getAsJsonObject().remove("tag"); - String newTag = toJson(itemStack); - json.getAsJsonObject().add("tag", new JsonPrimitive(newTag)); - - jsonObject.remove("contents"); - jsonObject.add("contents", json); - ChatHoverable newHoverable = ChatHoverable.a(jsonObject); - ChatModifier modifier = component.getChatModifier(); - modifier = modifier.setChatHoverable(newHoverable); - - ((ChatBaseComponent) component).setChatModifier(modifier); - } - - private static ItemStack getFromTag(@NotNull final String jsonTag, - @NotNull final String id) { - String processedId = id; - String processedJsonTag = jsonTag; - processedId = processedId.replace("minecraft:", ""); - processedId = processedId.toUpperCase(); - processedId = processedId.replace("\"", ""); - processedJsonTag = processedJsonTag.substring(1, processedJsonTag.length() - 1); - processedJsonTag = processedJsonTag.replace("id:", "\"id\":"); - processedJsonTag = processedJsonTag.replace("\\", ""); - Material material = Material.getMaterial(processedId); - - assert material != null; - ItemStack itemStack = new ItemStack(material); - net.minecraft.server.v1_16_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - - try { - nmsStack.setTag(MojangsonParser.parse(processedJsonTag)); - } catch (CommandSyntaxException e) { - e.printStackTrace(); - } - return CraftItemStack.asBukkitCopy(nmsStack); - } - - private static String toJson(@NotNull final ItemStack itemStack) { - return CraftItemStack.asNMSCopy(itemStack).getOrCreateTag().toString(); - } -} diff --git a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/VillagerTrade.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/VillagerTrade.java deleted file mode 100644 index faa70436..00000000 --- a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/VillagerTrade.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R1; - -import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy; -import com.willfp.ecoenchants.display.EnchantDisplay; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMerchantRecipe; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.MerchantRecipe; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public final class VillagerTrade implements VillagerTradeProxy { - @Override - public void displayTradeEnchantments(@NotNull final MerchantRecipe merchantRecipe) { - try { - // Enables removing final modifier - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - - // Bukkit MerchantRecipe result - Field fResult = MerchantRecipe.class.getDeclaredField("result"); - fResult.setAccessible(true); - ItemStack result = EnchantDisplay.displayEnchantments(merchantRecipe.getResult()); - EnchantDisplay.addV(result); - fResult.set(merchantRecipe, result); - - // Get NMS MerchantRecipe from CraftMerchantRecipe - Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle"); - fHandle.setAccessible(true); - net.minecraft.server.v1_16_R1.MerchantRecipe handle = (net.minecraft.server.v1_16_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe - modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final - - Field fSelling = net.minecraft.server.v1_16_R1.MerchantRecipe.class.getDeclaredField("sellingItem"); - fSelling.setAccessible(true); - modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL); - - ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem); - EnchantDisplay.displayEnchantments(selling); - EnchantDisplay.addV(selling); - - fSelling.set(handle, CraftItemStack.asNMSCopy(selling)); - } catch (IllegalAccessException | NoSuchFieldException e) { - e.printStackTrace(); - } - } -} diff --git a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/ChatComponent.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/ChatComponent.java deleted file mode 100644 index 9068209b..00000000 --- a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/ChatComponent.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R2; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.willfp.ecoenchants.display.EnchantDisplay; -import com.willfp.ecoenchants.proxy.proxies.ChatComponentProxy; -import net.minecraft.server.v1_16_R2.ChatBaseComponent; -import net.minecraft.server.v1_16_R2.ChatHoverable; -import net.minecraft.server.v1_16_R2.ChatMessage; -import net.minecraft.server.v1_16_R2.ChatModifier; -import net.minecraft.server.v1_16_R2.IChatBaseComponent; -import net.minecraft.server.v1_16_R2.MojangsonParser; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; - -public final class ChatComponent implements ChatComponentProxy { - @Override - public Object modifyComponent(@NotNull final Object object) { - if (!(object instanceof IChatBaseComponent)) { - return object; - } - - IChatBaseComponent chatComponent = (IChatBaseComponent) object; - chatComponent.stream().forEach(this::modifyBaseComponent); - - return chatComponent; - } - - private void modifyBaseComponent(@NotNull final IChatBaseComponent component) { - component.getSiblings().forEach(this::modifyBaseComponent); - if (component instanceof ChatMessage) { - Arrays.stream(((ChatMessage) component).getArgs()) - .filter(o -> o instanceof IChatBaseComponent) - .map(o -> (IChatBaseComponent) o) - .forEach(this::modifyBaseComponent); - } - - ChatHoverable hoverable = component.getChatModifier().getHoverEvent(); - - if (hoverable == null) { - return; - } - - JsonObject jsonObject = hoverable.b(); - JsonElement json = hoverable.b().get("contents"); - if (json.getAsJsonObject().get("id") == null) { - return; - } - if (json.getAsJsonObject().get("tag") == null) { - return; - } - String id = json.getAsJsonObject().get("id").toString(); - String tag = json.getAsJsonObject().get("tag").toString(); - ItemStack itemStack = getFromTag(tag, id); - - ItemMeta meta = itemStack.getItemMeta(); - assert meta != null; - boolean hideEnchants = false; - if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) { - hideEnchants = true; - } - - itemStack = EnchantDisplay.displayEnchantments(itemStack, hideEnchants); - EnchantDisplay.addV(itemStack); - - json.getAsJsonObject().remove("tag"); - String newTag = toJson(itemStack); - json.getAsJsonObject().add("tag", new JsonPrimitive(newTag)); - - jsonObject.remove("contents"); - jsonObject.add("contents", json); - ChatHoverable newHoverable = ChatHoverable.a(jsonObject); - ChatModifier modifier = component.getChatModifier(); - modifier = modifier.setChatHoverable(newHoverable); - - ((ChatBaseComponent) component).setChatModifier(modifier); - } - - private static ItemStack getFromTag(@NotNull final String jsonTag, - @NotNull final String id) { - String processedId = id; - String processedJsonTag = jsonTag; - processedId = processedId.replace("minecraft:", ""); - processedId = processedId.toUpperCase(); - processedId = processedId.replace("\"", ""); - processedJsonTag = processedJsonTag.substring(1, processedJsonTag.length() - 1); - processedJsonTag = processedJsonTag.replace("id:", "\"id\":"); - processedJsonTag = processedJsonTag.replace("\\", ""); - Material material = Material.getMaterial(processedId); - - assert material != null; - ItemStack itemStack = new ItemStack(material); - net.minecraft.server.v1_16_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - - try { - nmsStack.setTag(MojangsonParser.parse(processedJsonTag)); - } catch (CommandSyntaxException e) { - e.printStackTrace(); - } - return CraftItemStack.asBukkitCopy(nmsStack); - } - - private static String toJson(@NotNull final ItemStack itemStack) { - return CraftItemStack.asNMSCopy(itemStack).getOrCreateTag().toString(); - } -} diff --git a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/VillagerTrade.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/VillagerTrade.java deleted file mode 100644 index 57b05390..00000000 --- a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/VillagerTrade.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R2; - -import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy; -import com.willfp.ecoenchants.display.EnchantDisplay; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMerchantRecipe; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.MerchantRecipe; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public final class VillagerTrade implements VillagerTradeProxy { - @Override - public void displayTradeEnchantments(@NotNull final MerchantRecipe merchantRecipe) { - try { - // Enables removing final modifier - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - - // Bukkit MerchantRecipe result - Field fResult = MerchantRecipe.class.getDeclaredField("result"); - fResult.setAccessible(true); - ItemStack result = EnchantDisplay.displayEnchantments(merchantRecipe.getResult()); - EnchantDisplay.addV(result); - fResult.set(merchantRecipe, result); - - // Get NMS MerchantRecipe from CraftMerchantRecipe - Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle"); - fHandle.setAccessible(true); - net.minecraft.server.v1_16_R2.MerchantRecipe handle = (net.minecraft.server.v1_16_R2.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe - modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final - - Field fSelling = net.minecraft.server.v1_16_R2.MerchantRecipe.class.getDeclaredField("sellingItem"); - fSelling.setAccessible(true); - modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL); - - ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem); - EnchantDisplay.displayEnchantments(selling); - EnchantDisplay.addV(selling); - - fSelling.set(handle, CraftItemStack.asNMSCopy(selling)); - } catch (IllegalAccessException | NoSuchFieldException e) { - e.printStackTrace(); - } - } -} diff --git a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/ChatComponent.java b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/ChatComponent.java deleted file mode 100644 index bd4e4015..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/ChatComponent.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R3; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.willfp.ecoenchants.proxy.proxies.ChatComponentProxy; -import com.willfp.ecoenchants.display.EnchantDisplay; -import net.minecraft.server.v1_16_R3.ChatBaseComponent; -import net.minecraft.server.v1_16_R3.ChatHoverable; -import net.minecraft.server.v1_16_R3.ChatMessage; -import net.minecraft.server.v1_16_R3.ChatModifier; -import net.minecraft.server.v1_16_R3.IChatBaseComponent; -import net.minecraft.server.v1_16_R3.MojangsonParser; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; - -public final class ChatComponent implements ChatComponentProxy { - @Override - public Object modifyComponent(@NotNull final Object object) { - if (!(object instanceof IChatBaseComponent)) { - return object; - } - - IChatBaseComponent chatComponent = (IChatBaseComponent) object; - chatComponent.stream().forEach(this::modifyBaseComponent); - - return chatComponent; - } - - private void modifyBaseComponent(@NotNull final IChatBaseComponent component) { - component.getSiblings().forEach(this::modifyBaseComponent); - if (component instanceof ChatMessage) { - Arrays.stream(((ChatMessage) component).getArgs()) - .filter(o -> o instanceof IChatBaseComponent) - .map(o -> (IChatBaseComponent) o) - .forEach(this::modifyBaseComponent); - } - - ChatHoverable hoverable = component.getChatModifier().getHoverEvent(); - - if (hoverable == null) { - return; - } - - JsonObject jsonObject = hoverable.b(); - JsonElement json = hoverable.b().get("contents"); - if (json.getAsJsonObject().get("id") == null) { - return; - } - if (json.getAsJsonObject().get("tag") == null) { - return; - } - String id = json.getAsJsonObject().get("id").toString(); - String tag = json.getAsJsonObject().get("tag").toString(); - ItemStack itemStack = getFromTag(tag, id); - - ItemMeta meta = itemStack.getItemMeta(); - assert meta != null; - boolean hideEnchants = false; - if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) { - hideEnchants = true; - } - - itemStack = EnchantDisplay.displayEnchantments(itemStack, hideEnchants); - EnchantDisplay.addV(itemStack); - - json.getAsJsonObject().remove("tag"); - String newTag = toJson(itemStack); - json.getAsJsonObject().add("tag", new JsonPrimitive(newTag)); - - jsonObject.remove("contents"); - jsonObject.add("contents", json); - ChatHoverable newHoverable = ChatHoverable.a(jsonObject); - ChatModifier modifier = component.getChatModifier(); - modifier = modifier.setChatHoverable(newHoverable); - - ((ChatBaseComponent) component).setChatModifier(modifier); - } - - private static ItemStack getFromTag(@NotNull final String jsonTag, - @NotNull final String id) { - String processedId = id; - String processedJsonTag = jsonTag; - processedId = processedId.replace("minecraft:", ""); - processedId = processedId.toUpperCase(); - processedId = processedId.replace("\"", ""); - processedJsonTag = processedJsonTag.substring(1, processedJsonTag.length() - 1); - processedJsonTag = processedJsonTag.replace("id:", "\"id\":"); - processedJsonTag = processedJsonTag.replace("\\", ""); - Material material = Material.getMaterial(processedId); - - assert material != null; - ItemStack itemStack = new ItemStack(material); - net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - - try { - nmsStack.setTag(MojangsonParser.parse(processedJsonTag)); - } catch (CommandSyntaxException e) { - e.printStackTrace(); - } - return CraftItemStack.asBukkitCopy(nmsStack); - } - - private static String toJson(@NotNull final ItemStack itemStack) { - return CraftItemStack.asNMSCopy(itemStack).getOrCreateTag().toString(); - } -} diff --git a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/VillagerTrade.java b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/VillagerTrade.java deleted file mode 100644 index 7c7d7c5d..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/VillagerTrade.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R3; - -import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy; -import com.willfp.ecoenchants.display.EnchantDisplay; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchantRecipe; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.MerchantRecipe; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public final class VillagerTrade implements VillagerTradeProxy { - @Override - public void displayTradeEnchantments(@NotNull final MerchantRecipe merchantRecipe) { - try { - // Enables removing final modifier - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - - // Bukkit MerchantRecipe result - Field fResult = MerchantRecipe.class.getDeclaredField("result"); - fResult.setAccessible(true); - ItemStack result = EnchantDisplay.displayEnchantments(merchantRecipe.getResult()); - EnchantDisplay.addV(result); - fResult.set(merchantRecipe, result); - - // Get NMS MerchantRecipe from CraftMerchantRecipe - Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle"); - fHandle.setAccessible(true); - net.minecraft.server.v1_16_R3.MerchantRecipe handle = (net.minecraft.server.v1_16_R3.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe - modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final - - Field fSelling = net.minecraft.server.v1_16_R3.MerchantRecipe.class.getDeclaredField("sellingItem"); - fSelling.setAccessible(true); - modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL); - - ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem); - EnchantDisplay.displayEnchantments(selling); - EnchantDisplay.addV(selling); - - fSelling.set(handle, CraftItemStack.asNMSCopy(selling)); - } catch (IllegalAccessException | NoSuchFieldException e) { - e.printStackTrace(); - } - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java index 8da1b0fd..4edf41ee 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java @@ -1,6 +1,8 @@ package com.willfp.ecoenchants; import com.willfp.eco.util.command.AbstractCommand; +import com.willfp.eco.util.display.Display; +import com.willfp.eco.util.display.DisplayModule; import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils; import com.willfp.eco.util.integrations.IntegrationLoader; import com.willfp.eco.util.interfaces.EcoRunnable; @@ -13,11 +15,6 @@ import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo; import com.willfp.ecoenchants.config.EcoEnchantsConfigs; import com.willfp.ecoenchants.display.EnchantDisplay; import com.willfp.ecoenchants.display.EnchantmentCache; -import com.willfp.ecoenchants.display.packets.PacketChat; -import com.willfp.ecoenchants.display.packets.PacketOpenWindowMerchant; -import com.willfp.ecoenchants.display.packets.PacketSetCreativeSlot; -import com.willfp.ecoenchants.display.packets.PacketSetSlot; -import com.willfp.ecoenchants.display.packets.PacketWindowItems; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; @@ -42,6 +39,8 @@ import org.bukkit.Bukkit; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.generator.BlockPopulator; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.Arrays; @@ -68,6 +67,21 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin { */ @Override public void enable() { + Display.registerDisplayModule(new DisplayModule(itemStack -> { + ItemMeta meta = itemStack.getItemMeta(); + if (meta == null) { + return itemStack; + } + boolean hideEnchants = false; + if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) { + hideEnchants = true; + } + + return EnchantDisplay.displayEnchantments(itemStack, hideEnchants); + }, 500, this.getPluginName())); + Display.registerRevertModule(EnchantDisplay::revertDisplay); + Display.registerFinalizeModule(EnchantDisplay::addV); + this.getExtensionLoader().loadExtensions(); if (this.getExtensionLoader().getLoadedExtensions().isEmpty()) { @@ -96,7 +110,6 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin { })); }); - this.getExtensionLoader().unloadExtensions(); } @@ -176,13 +189,7 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin { */ @Override public List getPacketAdapters() { - return Arrays.asList( - new PacketChat(this), - new PacketOpenWindowMerchant(this), - new PacketSetCreativeSlot(this), - new PacketSetSlot(this), - new PacketWindowItems(this) - ); + return new ArrayList<>(); } /** diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketChat.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketChat.java deleted file mode 100644 index 89213ad1..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketChat.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.willfp.ecoenchants.display.packets; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.ListenerPriority; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.wrappers.WrappedChatComponent; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.eco.util.protocollib.AbstractPacketAdapter; -import com.willfp.ecoenchants.proxy.proxies.ChatComponentProxy; -import com.willfp.ecoenchants.util.ProxyUtils; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class PacketChat extends AbstractPacketAdapter { - /** - * Instantiate a new listener for {@link PacketType.Play.Server#CHAT}. - * - * @param plugin The plugin to listen through. - */ - public PacketChat(@NotNull final AbstractEcoPlugin plugin) { - super(plugin, PacketType.Play.Server.CHAT, ListenerPriority.MONITOR, true); - } - - @Override - public void onSend(@NotNull final PacketContainer packet, - @NotNull final Player player) { - for (int i = 0; i < packet.getChatComponents().size(); i++) { - WrappedChatComponent component = packet.getChatComponents().read(i); - if (component == null) { - continue; - } - - if (component.getHandle() == null) { - return; - } - - WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(ProxyUtils.getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle())); - packet.getChatComponents().write(i, newComponent); - } - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketOpenWindowMerchant.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketOpenWindowMerchant.java deleted file mode 100644 index 2fecf3cb..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketOpenWindowMerchant.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.willfp.ecoenchants.display.packets; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.eco.util.protocollib.AbstractPacketAdapter; -import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; -import com.willfp.ecoenchants.proxy.proxies.VillagerTradeProxy; -import com.willfp.ecoenchants.util.ProxyUtils; -import org.bukkit.entity.Player; -import org.bukkit.inventory.MerchantRecipe; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.stream.Collectors; - -public class PacketOpenWindowMerchant extends AbstractPacketAdapter { - /** - * Instantiate a new listener for {@link PacketType.Play.Server#OPEN_WINDOW_MERCHANT}. - * - * @param plugin The plugin to listen through. - */ - public PacketOpenWindowMerchant(@NotNull final AbstractEcoPlugin plugin) { - super(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, false); - } - - @Override - public void onSend(@NotNull final PacketContainer packet, - @NotNull final Player player) { - List recipes = packet.getMerchantRecipeLists().readSafely(0); - - recipes = recipes.stream().peek(merchantRecipe -> { - if (!EnchantmentTarget.ALL.getMaterials().contains(merchantRecipe.getResult().getType())) { - return; - } - - ProxyUtils.getProxy(VillagerTradeProxy.class).displayTradeEnchantments(merchantRecipe); - }).collect(Collectors.toList()); - - packet.getMerchantRecipeLists().writeSafely(0, recipes); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketSetCreativeSlot.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketSetCreativeSlot.java deleted file mode 100644 index d0ec0c6a..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketSetCreativeSlot.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.willfp.ecoenchants.display.packets; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.eco.util.protocollib.AbstractPacketAdapter; -import com.willfp.ecoenchants.display.EnchantDisplay; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class PacketSetCreativeSlot extends AbstractPacketAdapter { - /** - * Instantiate a new listener for {@link PacketType.Play.Client#SET_CREATIVE_SLOT}. - * - * @param plugin The plugin to listen through. - */ - public PacketSetCreativeSlot(@NotNull final AbstractEcoPlugin plugin) { - super(plugin, PacketType.Play.Client.SET_CREATIVE_SLOT, false); - } - - @Override - public void onReceive(@NotNull final PacketContainer packet, - @NotNull final Player player) { - packet.getItemModifier().modify(0, EnchantDisplay::revertDisplay); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketSetSlot.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketSetSlot.java deleted file mode 100644 index 3af365ef..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketSetSlot.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.willfp.ecoenchants.display.packets; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.eco.util.protocollib.AbstractPacketAdapter; -import com.willfp.ecoenchants.display.EnchantDisplay; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; -import org.jetbrains.annotations.NotNull; - -public class PacketSetSlot extends AbstractPacketAdapter { - /** - * Instantiate a new listener for {@link PacketType.Play.Server#SET_SLOT}. - * - * @param plugin The plugin to listen through. - */ - public PacketSetSlot(@NotNull final AbstractEcoPlugin plugin) { - super(plugin, PacketType.Play.Server.SET_SLOT, false); - } - - @Override - public void onSend(@NotNull final PacketContainer packet, - @NotNull final Player player) { - packet.getItemModifier().modify(0, item -> { - boolean hideEnchants = false; - - if (item == null) { - return null; - } - - if (item.getItemMeta() != null) { - hideEnchants = item.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ENCHANTS); - } - - item = EnchantDisplay.displayEnchantments(item, hideEnchants); - return item; - }); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketWindowItems.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketWindowItems.java deleted file mode 100644 index 5d8a693d..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/packets/PacketWindowItems.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.willfp.ecoenchants.display.packets; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.eco.util.protocollib.AbstractPacketAdapter; -import com.willfp.ecoenchants.display.EnchantDisplay; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; -import org.jetbrains.annotations.NotNull; - -public class PacketWindowItems extends AbstractPacketAdapter { - /** - * Instantiate a new listener for {@link PacketType.Play.Server#WINDOW_ITEMS}. - * - * @param plugin The plugin to listen through. - */ - public PacketWindowItems(@NotNull final AbstractEcoPlugin plugin) { - super(plugin, PacketType.Play.Server.WINDOW_ITEMS, false); - } - - @Override - public void onSend(@NotNull final PacketContainer packet, - @NotNull final Player player) { - packet.getItemListModifier().modify(0, itemStacks -> { - if (itemStacks == null) { - return null; - } - itemStacks.forEach(item -> { - if (item == null) { - return; - } - - boolean hideEnchants = false; - - if (item.getItemMeta() != null) { - hideEnchants = item.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ENCHANTS); - } - - EnchantDisplay.displayEnchantments(item, hideEnchants); - }); - return itemStacks; - }); - } -} diff --git a/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/ChatComponentProxy.java b/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/ChatComponentProxy.java deleted file mode 100644 index 52e4fef4..00000000 --- a/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/ChatComponentProxy.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.willfp.ecoenchants.proxy.proxies; - - -import com.willfp.eco.util.proxy.AbstractProxy; -import org.jetbrains.annotations.NotNull; - -public interface ChatComponentProxy extends AbstractProxy { - /** - * Modify hover {@link org.bukkit.inventory.ItemStack}s using EnchantDisplay#displayEnchantments. - * @param object The NMS ChatComponent to modify. - * @return The modified ChatComponent. - */ - Object modifyComponent(@NotNull Object object); -} diff --git a/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/VillagerTradeProxy.java b/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/VillagerTradeProxy.java deleted file mode 100644 index a4743b13..00000000 --- a/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/VillagerTradeProxy.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.willfp.ecoenchants.proxy.proxies; - -import com.willfp.eco.util.proxy.AbstractProxy; -import org.bukkit.inventory.MerchantRecipe; - -public interface VillagerTradeProxy extends AbstractProxy { - /** - * Apply enchant display to the result of trades. - * - * @param merchantRecipe The recipe to modify. - */ - void displayTradeEnchantments(MerchantRecipe merchantRecipe); -} From d2d9b3f7121abe7d7b4795fb47b6bb4a26fb78b0 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 19 Jan 2021 17:46:44 +0000 Subject: [PATCH 13/19] Updated to 6.2.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 56c7bd15..3805a38a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 6.2.0 +version = 6.2.1 plugin-name = EcoEnchants \ No newline at end of file From 58b7e2276920482bf1e6fc0c31c732b0245b97d8 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 20 Jan 2021 20:58:01 +0000 Subject: [PATCH 14/19] Fixed LuckyCatch --- .../enchantments/ecoenchants/normal/LuckyCatch.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/LuckyCatch.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/LuckyCatch.java index de143d7e..422cf375 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/LuckyCatch.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/LuckyCatch.java @@ -28,6 +28,10 @@ public class LuckyCatch extends EcoEnchant { return; } + if (event.getState() == PlayerFishEvent.State.CAUGHT_ENTITY) { + return; + } + int level = EnchantChecks.getItemLevel(item, this); if (this.getDisabledWorlds().contains(player.getWorld())) { From b53303e228e0a74b415dcc545b45accc8eb8240c Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 20 Jan 2021 20:58:13 +0000 Subject: [PATCH 15/19] Updated to 6.2.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 3805a38a..3037f254 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 6.2.1 +version = 6.2.2 plugin-name = EcoEnchants \ No newline at end of file From 8ee6a6d2a98700dc9f8891bd45d6f48404759c82 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 21 Jan 2021 13:15:07 +0000 Subject: [PATCH 16/19] Removed getEnchantmentLevel call --- .../java/com/willfp/ecoenchants/display/EnchantDisplay.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index f8c9a9c8..4849eccf 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -9,6 +9,8 @@ import com.willfp.ecoenchants.display.options.DisplayOptions; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; +import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; +import com.willfp.ecoenchants.util.ProxyUtils; import lombok.experimental.UtilityClass; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; @@ -229,7 +231,7 @@ public class EnchantDisplay { String name = EnchantmentCache.getEntry(enchantment).getName(); if (!(enchantment.getMaxLevel() == 1 && level == 1)) { - if (OPTIONS.getNumbersOptions().isUseNumerals() && item.getEnchantmentLevel(enchantment) < OPTIONS.getNumbersOptions().getThreshold()) { + if (OPTIONS.getNumbersOptions().isUseNumerals() && ProxyUtils.getProxy(FastGetEnchantsProxy.class).getLevelOnItem(item, enchantment) < OPTIONS.getNumbersOptions().getThreshold()) { name += " " + NumberUtils.toNumeral(level); } else { name += " " + level; From 534aad3a9fc3138f0e092268eeb9ab6094d03101 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 21 Jan 2021 22:56:16 +0000 Subject: [PATCH 17/19] Updated to 6.2.3 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 3037f254..bb5da236 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 6.2.2 +version = 6.2.3 plugin-name = EcoEnchants \ No newline at end of file From 317dfdef09194102f55249322e812887a987741a Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 22 Jan 2021 16:07:15 +0000 Subject: [PATCH 18/19] Fixed addV --- .../java/com/willfp/ecoenchants/display/EnchantDisplay.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index 4849eccf..08b6d29c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -78,7 +78,7 @@ public class EnchantDisplay { * @return The item, with KEY_V. */ public static ItemStack addV(@Nullable final ItemStack item) { - if (item == null || item.getItemMeta() == null) { + if (item == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()) || item.getItemMeta() == null) { return item; } From fc9977dcaac8e2ccb8b310b05d50f0296945587b Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 22 Jan 2021 16:07:29 +0000 Subject: [PATCH 19/19] Updated to 6.2.4 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index bb5da236..6511c1f7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 6.2.3 +version = 6.2.4 plugin-name = EcoEnchants \ No newline at end of file