Skip to content

Commit

Permalink
1.25.0 - Fix enchanted gapples reverting
Browse files Browse the repository at this point in the history
  • Loading branch information
moom0o committed Mar 29, 2022
1 parent 8b07ad7 commit 0432f28
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ RevertStackedItems: true
RevertEnchantments: true
RevertUnEnchantable: true # Removes enchantments that normally can't be applied to that item.
RevertSpecificEnchantments: false # Only revert specific enchantments
SpecificEnchantments:
SpecificEnchantments: # If RevertSpecificEnchantments is enabled, only these specific enchantments will be reverted.
- "DIG_SPEED" # The name of the enchantment in the spigot api
ItemsSkipped: # Items that won't be reverted from illegal enchants or unbreakablity.
- "GOLDEN_APPLE" # Make sure to keep this line here or else enchanted golden apples will be reverted to normal ones.
RevertUnbreakables:
Enabled: true # Revert unbreakable items, items with less than 0 durability will be automatically removed or set to 0 durability, which will break on the next use. Items with higher than max durability will be set to legal maximum durability.
# Only removes player heads, not mob heads
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.moomoo</groupId>
<artifactId>anarchyexploitfixes</artifactId>
<version>1.24.0</version>
<version>1.25.0</version>
<packaging>jar</packaging>

<name>AnarchyExploitFixes</name>
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/me/moomoo/anarchyexploitfixes/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@ public void revert(ItemStack item) {
}

if (getConfig().getBoolean("RevertUnbreakables.Enabled")) {
if (item.getDurability() > item.getType().getMaxDurability()) {
item.setDurability(item.getType().getMaxDurability());
}
if (item.getDurability() < 0) {
item.subtract(item.getAmount());
if (!getConfig().getStringList("ItemsSkipped").contains(item.getType().name())) {
if (item.getDurability() > item.getType().getMaxDurability()) {
item.setDurability(item.getType().getMaxDurability());
}
if (item.getDurability() < 0) {
item.subtract(item.getAmount());
}
}
}

Expand All @@ -268,18 +270,20 @@ public void revert(ItemStack item) {
}

private void revertEnchantments(ItemStack item) {
for (Map.Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
if (entry.getValue() != null && entry.getKey() != null) {
if (getConfig().getBoolean("RevertSpecificEnchantments")) {
for (String s : getConfig().getStringList("SpecificEnchantments")) {
if (entry.getValue() > entry.getKey().getMaxLevel() && entry.getKey().getName().contains(s)) {
if (!getConfig().getStringList("ItemsSkipped").contains(item.getType().name())) {
for (Map.Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
if (entry.getValue() != null && entry.getKey() != null) {
if (getConfig().getBoolean("RevertSpecificEnchantments")) {
for (String s : getConfig().getStringList("SpecificEnchantments")) {
if (entry.getValue() > entry.getKey().getMaxLevel() && entry.getKey().getName().contains(s)) {
replaceEnchantment(item, entry.getKey(), entry.getKey().getMaxLevel());
}
}
} else {
if (entry.getValue() > entry.getKey().getMaxLevel()) {
replaceEnchantment(item, entry.getKey(), entry.getKey().getMaxLevel());
}
}
} else {
if (entry.getValue() > entry.getKey().getMaxLevel()) {
replaceEnchantment(item, entry.getKey(), entry.getKey().getMaxLevel());
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ RevertStackedItems: true
RevertEnchantments: true
RevertUnEnchantable: true # Removes enchantments that normally can't be applied to that item.
RevertSpecificEnchantments: false # Only revert specific enchantments
SpecificEnchantments:
SpecificEnchantments: # If RevertSpecificEnchantments is enabled, only these specific enchantments will be reverted.
- "DIG_SPEED" # The name of the enchantment in the spigot api
ItemsSkipped: # Items that won't be reverted from illegal enchants or unbreakablity.
- "GOLDEN_APPLE" # Make sure to keep this line here or else enchanted golden apples will be reverted to normal ones.
RevertUnbreakables:
Enabled: true # Revert unbreakable items, items with less than 0 durability will be automatically removed or set to 0 durability, which will break on the next use. Items with higher than max durability will be set to legal maximum durability.
# Only removes player heads, not mob heads
Expand Down

0 comments on commit 0432f28

Please sign in to comment.