Skip to content

Commit 9020956

Browse files
committed
corrections and nbt module rewrite
1 parent 9b48be3 commit 9020956

File tree

13 files changed

+443
-540
lines changed

13 files changed

+443
-540
lines changed

AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/enums/AEFPermission.java

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public enum AEFPermission {
1212
BYPASS_ILLEGAL_UNBREAKABLE("bypass.illegal.unbreakable"),
1313
BYPASS_ILLEGAL_SPAWNEGG("bypass.illegal.spawnegg"),
1414
BYPASS_ILLEGAL_PLAYERHEAD("bypass.illegal.playerhead"),
15+
BYPASS_ILLEGAL_NBT_STOREDITEMS("bypass.illegal.nbt.storeditems"),
16+
BYPASS_ILLEGAL_NBT_CUSTOM("bypass.illegal.nbt.custom"),
1517
SILENT_JOIN("silentJoin"),
1618
SILENT_LEAVE("silentLeave");
1719

AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import me.moomoo.anarchyexploitfixes.modules.illegals.items.enchantments.InapplicableEnchants;
1515
import me.moomoo.anarchyexploitfixes.modules.illegals.items.enchantments.IncompatibleEnchants;
1616
import me.moomoo.anarchyexploitfixes.modules.illegals.items.enchantments.SpecificHigherEnchants;
17-
import me.moomoo.anarchyexploitfixes.modules.illegals.items.nbt.DamageModifierTags;
18-
import me.moomoo.anarchyexploitfixes.modules.illegals.items.nbt.FilledStorageItemTags;
17+
import me.moomoo.anarchyexploitfixes.modules.illegals.items.nbt.CustomNBTFilter;
18+
import me.moomoo.anarchyexploitfixes.modules.illegals.items.nbt.NBTFilledStorageItem;
1919
import me.moomoo.anarchyexploitfixes.modules.illegals.placedblocks.PeriodicallyRemoveIllegalBlocks;
2020
import me.moomoo.anarchyexploitfixes.modules.illegals.placedblocks.RemoveIllegalBlocksOnChunkload;
2121
import me.moomoo.anarchyexploitfixes.modules.illegals.placedblocks.RemoveUnnaturalSpawners;
@@ -106,21 +106,21 @@ static void reloadModules() {
106106
modules.add(new PeriodicallyRemoveIllegalBlocks());
107107
modules.add(new RemoveUnnaturalSpawners());
108108
// Items
109-
modules.add(new BannedItemNames());
110-
modules.add(new OverstackedItems());
111-
modules.add(new RevertUnbreakables());
112-
modules.add(new PlayerHeads());
113-
modules.add(new SpawnEggs());
114-
// Banned Blocks
115-
modules.add(new BannedMaterial());
116109
// Enchantments
117110
modules.add(new IncompatibleEnchants());
118111
modules.add(new HigherEnchants());
119112
modules.add(new SpecificHigherEnchants());
120113
modules.add(new InapplicableEnchants());
121-
// NBT Items
122-
modules.add(new DamageModifierTags());
123-
modules.add(new FilledStorageItemTags());
114+
// Other
115+
modules.add(new BannedItemNames());
116+
modules.add(new OverstackedItems());
117+
modules.add(new UnbreakableItems());
118+
modules.add(new PlayerHeadItems());
119+
modules.add(new SpawnEggItems());
120+
modules.add(new BannedMaterials());
121+
// NBT
122+
modules.add(new CustomNBTFilter());
123+
modules.add(new NBTFilledStorageItem());
124124
/*
125125
Lag Preventions
126126
*/
+5-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
import java.util.Set;
2525
import java.util.stream.Collectors;
2626

27-
public class BannedMaterial implements IllegalItemModule {
27+
public class BannedMaterials implements IllegalItemModule {
2828

2929
private final Set<Material> bannedMaterials;
3030
private final boolean shouldDelete, checkStored;
3131

32-
public BannedMaterial() {
32+
public BannedMaterials() {
3333
shouldEnable();
3434
Config config = AnarchyExploitFixes.getConfiguration();
3535
config.addComment("illegals.ban-specific-materials.enable",
@@ -114,7 +114,9 @@ public ItemCheckResult checkItem(ItemStack itemStack) {
114114

115115
@Override
116116
public void takeAction(ItemStack itemStack, ItemCheckResult result) {
117-
if (shouldDelete) itemStack.setType(Material.AIR);
117+
if (result != ItemCheckResult.FINE) {
118+
if (shouldDelete) itemStack.setType(Material.AIR);
119+
}
118120
}
119121

120122
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/OverstackedItems.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,9 @@ public ItemCheckResult checkItem(ItemStack itemStack) {
116116
return ItemCheckResult.FINE;
117117
}
118118

119-
if (!useWhitelist) {
120-
if (itemStack.getAmount() > itemStack.getMaxStackSize())
119+
if (!useWhitelist || blacklistMode == whitelistedTypes.contains(itemStack.getType())) {
120+
if (itemStack.getAmount() > itemStack.getMaxStackSize()) {
121121
return ItemCheckResult.IS_ILLEGAL;
122-
} else {
123-
if (blacklistMode == whitelistedTypes.contains(itemStack.getType())) {
124-
if (itemStack.getAmount() > itemStack.getMaxStackSize()) {
125-
return ItemCheckResult.IS_ILLEGAL;
126-
}
127122
}
128123
}
129124

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
import org.bukkit.event.player.PlayerInteractEvent;
1818
import org.bukkit.inventory.ItemStack;
1919

20-
public class PlayerHeads implements IllegalItemModule {
20+
public class PlayerHeadItems implements IllegalItemModule {
2121

2222
private final boolean shouldDelete, checkStored;
2323

24-
public PlayerHeads() {
24+
public PlayerHeadItems() {
2525
shouldEnable();
2626
Config config = AnarchyExploitFixes.getConfiguration();
2727
config.addComment("illegals.ban-player-heads.enable",
@@ -85,7 +85,9 @@ public ItemCheckResult checkItem(ItemStack itemStack) {
8585

8686
@Override
8787
public void takeAction(ItemStack itemStack, ItemCheckResult result) {
88-
if (shouldDelete) itemStack.setType(Material.AIR);
88+
if (result != ItemCheckResult.FINE) {
89+
if (shouldDelete) itemStack.setType(Material.AIR);
90+
}
8991
}
9092

9193
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+5-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
import org.bukkit.event.player.PlayerInteractEvent;
1919
import org.bukkit.inventory.ItemStack;
2020

21-
public class SpawnEggs implements IllegalItemModule {
21+
public class SpawnEggItems implements IllegalItemModule {
2222

2323
private final boolean shouldDelete, checkStored;
2424

25-
public SpawnEggs() {
25+
public SpawnEggItems() {
2626
shouldEnable();
2727
Config config = AnarchyExploitFixes.getConfiguration();
2828
config.addComment("illegals.ban-spawn-eggs.enable",
@@ -84,7 +84,9 @@ public ItemCheckResult checkItem(ItemStack itemStack) {
8484

8585
@Override
8686
public void takeAction(ItemStack itemStack, ItemCheckResult result) {
87-
if (shouldDelete) itemStack.setType(Material.AIR);
87+
if (result != ItemCheckResult.FINE) {
88+
if (shouldDelete) itemStack.setType(Material.AIR);
89+
}
8890
}
8991

9092
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+10-33
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import org.bukkit.event.Listener;
1616
import org.bukkit.event.inventory.InventoryClickEvent;
1717
import org.bukkit.event.inventory.InventoryMoveItemEvent;
18-
import org.bukkit.event.player.*;
19-
import org.bukkit.inventory.ItemFlag;
18+
import org.bukkit.event.player.PlayerAttemptPickupItemEvent;
19+
import org.bukkit.event.player.PlayerDropItemEvent;
20+
import org.bukkit.event.player.PlayerInteractEntityEvent;
21+
import org.bukkit.event.player.PlayerInteractEvent;
2022
import org.bukkit.inventory.ItemStack;
2123
import org.bukkit.inventory.meta.Damageable;
2224
import org.bukkit.inventory.meta.ItemMeta;
@@ -28,15 +30,15 @@
2830
import java.util.Set;
2931
import java.util.stream.Collectors;
3032

31-
public class RevertUnbreakables implements IllegalItemModule {
33+
public class UnbreakableItems implements IllegalItemModule {
3234

3335
private final Set<Material> whitelistedTypes;
3436
private ScheduledTask periodicInvCheck;
3537
private Listener hopperListener;
3638
private final long checkPeriod;
3739
private final boolean useWhitelist, blacklistMode, doPeriodicCheck, checkStored, preventHopperBypass;
3840

39-
public RevertUnbreakables() {
41+
public UnbreakableItems() {
4042
shouldEnable();
4143
Config config = AnarchyExploitFixes.getConfiguration();
4244
config.addComment("illegals.revert-unbreakables.enable",
@@ -117,14 +119,9 @@ public ItemCheckResult checkItem(ItemStack itemStack) {
117119
return ItemCheckResult.FINE;
118120
}
119121

120-
if (!useWhitelist) {
121-
if (isUnbreakable(itemStack))
122+
if (!useWhitelist || blacklistMode == whitelistedTypes.contains(itemStack.getType())) {
123+
if (isUnbreakable(itemStack)) {
122124
return ItemCheckResult.IS_ILLEGAL;
123-
} else {
124-
if (blacklistMode == whitelistedTypes.contains(itemStack.getType())) {
125-
if (isUnbreakable(itemStack)) {
126-
return ItemCheckResult.IS_ILLEGAL;
127-
}
128125
}
129126
}
130127

@@ -144,28 +141,8 @@ public ItemCheckResult checkItem(ItemStack itemStack) {
144141

145142
@Override
146143
public void takeAction(ItemStack itemStack, ItemCheckResult result) {
147-
if (result == ItemCheckResult.IS_ILLEGAL) {
148-
if (itemStack.hasItemFlag(ItemFlag.HIDE_UNBREAKABLE))
149-
itemStack.removeItemFlags(ItemFlag.HIDE_UNBREAKABLE);
150-
151-
ItemMeta itemMeta = itemStack.getItemMeta();
152-
153-
if (itemMeta.isUnbreakable()) {
154-
itemMeta.setUnbreakable(false);
155-
itemStack.setItemMeta(itemMeta);
156-
}
157-
158-
// Remove items with impossible durability values
159-
Damageable damageMeta = (Damageable) itemMeta;
160-
if (!damageMeta.hasDamage()) return;
161-
final short itemMaxDurability = itemStack.getType().getMaxDurability();
162-
if (itemMaxDurability == 0) return;
163-
164-
final int remainingDurability = itemMaxDurability - damageMeta.getDamage();
165-
if (remainingDurability > itemMaxDurability || remainingDurability < 0) {
166-
damageMeta.setDamage(1);
167-
itemStack.setItemMeta(damageMeta);
168-
}
144+
if (result != ItemCheckResult.FINE) {
145+
itemStack.setType(Material.AIR);
169146
}
170147
}
171148

0 commit comments

Comments
 (0)