Skip to content

Commit

Permalink
fix buggy config defaults, always-true for nameColors revert and bugg…
Browse files Browse the repository at this point in the history
…y concurrent modification in conflicting enchantments
  • Loading branch information
crxyne committed May 6, 2024
1 parent 3e5a8eb commit 906c2de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static int maxBookItemsInShulker() {
}

public static boolean shouldCleanBookShulkers() {
return AntiIllegals.config().getBoolean("shulkerBoxes", true);
return AntiIllegals.config().getBoolean("shulkerBoxes");
}

public static void dropBookShulkerItem(@NotNull final Location location, @NotNull final ItemStack itemStack) {
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/org/zeroBzeroT/antiillegals/helpers/RevertHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static ItemState checkItemStackUncached(@NotNull final ItemStack itemSta
if (BookHelper.isBookItem(itemStack))
return ItemState.IS_BOOK;

if (checkRecursive && AntiIllegals.config().getBoolean("shulkerBoxes", true)) {
if (checkRecursive && AntiIllegals.config().getBoolean("shulkerBoxes")) {
final Optional<RevertionResult> result = InventoryHolderHelper.modifyInventory(itemStack,
inventory -> checkInventory(inventory, location, true, true)
);
Expand Down Expand Up @@ -312,11 +312,16 @@ public static ItemState checkItemStack(@Nullable final ItemStack itemStack, @Nul
* @return whether the name was stripped from color
*/
private static boolean revertColoredName(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("nameColors", true) || !itemStack.hasItemMeta())
if (!AntiIllegals.config().getBoolean("nameColors") || !itemStack.hasItemMeta())
return false;

final ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(ChatColor.stripColor(itemMeta.getDisplayName()));
final String displayName = itemMeta.getDisplayName();

if (displayName == null || !displayName.contains("§"))
return false;

itemMeta.setDisplayName(ChatColor.stripColor(displayName));
itemStack.setItemMeta(itemMeta);
return true;
}
Expand All @@ -327,7 +332,7 @@ private static boolean revertColoredName(@NotNull final ItemStack itemStack) {
* @return whether the durability was reverted
*/
private static boolean revertIllegalDurability(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("durability", true))
if (!AntiIllegals.config().getBoolean("durability"))
return false;

final Material material = itemStack.getType();
Expand All @@ -354,7 +359,7 @@ private static boolean revertIllegalDurability(@NotNull final ItemStack itemStac
* @return whether the unbreakable tag was removed
*/
private static boolean revertUnbreakableTag(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("unbreakables", true) || !itemStack.hasItemMeta())
if (!AntiIllegals.config().getBoolean("unbreakables") || !itemStack.hasItemMeta())
return false;

if (!MaterialHelper.hasDurability(itemStack.getType()))
Expand All @@ -375,7 +380,7 @@ private static boolean revertUnbreakableTag(@NotNull final ItemStack itemStack)
* @return whether the item was deleted
*/
private static boolean deleteIllegalItem(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("illegalBlocks", true))
if (!AntiIllegals.config().getBoolean("illegalBlocks"))
return false;

if (!MaterialHelper.isIllegalBlock(itemStack)) return false;
Expand All @@ -390,7 +395,7 @@ private static boolean deleteIllegalItem(@NotNull final ItemStack itemStack) {
* @return whether the furnace was deleted
*/
private static boolean deleteNBTFurnace(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("nbtFurnaces", true))
if (!AntiIllegals.config().getBoolean("nbtFurnaces"))
return false;

if (itemStack.getType() != Material.FURNACE)
Expand All @@ -411,7 +416,7 @@ private static boolean deleteNBTFurnace(@NotNull final ItemStack itemStack) {
* @return whether the stack size was modified
*/
private static boolean revertOverstackedItem(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("overstackedItems", true))
if (!AntiIllegals.config().getBoolean("overstackedItems"))
return false;

final int amount = itemStack.getAmount();
Expand All @@ -430,7 +435,7 @@ private static boolean revertOverstackedItem(@NotNull final ItemStack itemStack)
* @return whether the enchantments were modified
*/
private static boolean removeConflictingEnchantments(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("conflictingEnchantments", true))
if (!AntiIllegals.config().getBoolean("conflictingEnchantments"))
return false;

if (!MaterialHelper.isArmor(itemStack) && !MaterialHelper.isWeapon(itemStack)) return false;
Expand All @@ -446,14 +451,8 @@ private static boolean removeConflictingEnchantments(@NotNull final ItemStack it
if (!base.conflictsWith(compare)) continue;

itemStack.removeEnchantment(base);
keys.remove(base);

wasFixed = true;

if (i > 0) {
i--;
break;
}
}
}
return wasFixed;
Expand All @@ -465,7 +464,7 @@ private static boolean removeConflictingEnchantments(@NotNull final ItemStack it
* @return whether attribute modifiers were removed
*/
private static boolean removeAttributes(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("attributeModifiers", true))
if (!AntiIllegals.config().getBoolean("attributeModifiers"))
return false;

final NBTItem nbtItem = new NBTItem(itemStack);
Expand All @@ -482,7 +481,7 @@ private static boolean removeAttributes(@NotNull final ItemStack itemStack) {
* @return whether any effects were removed
*/
private static boolean removeCustomPotionEffects(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("customPotionEffects", true))
if (!AntiIllegals.config().getBoolean("customPotionEffects"))
return false;

if (!(itemStack.getItemMeta() instanceof final PotionMeta meta))
Expand All @@ -506,7 +505,7 @@ private static boolean removeCustomPotionEffects(@NotNull final ItemStack itemSt
* @return whether any enchantments were modified
*/
private static boolean removeIllegalEnchantmentLevels(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("maxEnchantments", true)) return false;
if (!AntiIllegals.config().getBoolean("maxEnchantments")) return false;
final boolean allowCollectibles = AntiIllegals.INSTANCE.getConfig().getBoolean("allowCollectibles");

boolean wasFixed = false;
Expand Down Expand Up @@ -543,7 +542,7 @@ private static boolean removeIllegalEnchantmentLevels(@NotNull final ItemStack i
* @return whether the flight duration (if any) was modified
*/
private static boolean removeIllegalFlightTime(@NotNull final ItemStack itemStack) {
if (!AntiIllegals.config().getBoolean("flightTime", true))
if (!AntiIllegals.config().getBoolean("flightTime"))
return false;

final ItemMeta meta = itemStack.getItemMeta();
Expand Down

0 comments on commit 906c2de

Please sign in to comment.