Skip to content

Commit

Permalink
implement in legacy build and finalize initial rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Mar 7, 2024
1 parent e0bd517 commit 606746a
Show file tree
Hide file tree
Showing 47 changed files with 2,290 additions and 2,840 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import me.moomoo.anarchyexploitfixes.config.LanguageCache;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.models.CachedTickData;
import me.moomoo.anarchyexploitfixes.utils.models.FastPermTool;
import me.moomoo.anarchyexploitfixes.utils.FastPermTool;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import org.bstats.bukkit.Metrics;
import org.bukkit.command.CommandSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.LocationUtil;
import me.moomoo.anarchyexploitfixes.utils.MaterialUtil;
import me.moomoo.anarchyexploitfixes.utils.models.FastPermTool;
import me.moomoo.anarchyexploitfixes.utils.FastPermTool;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.Location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.LocationUtil;
import me.moomoo.anarchyexploitfixes.utils.MaterialUtil;
import me.moomoo.anarchyexploitfixes.utils.models.FastPermTool;
import me.moomoo.anarchyexploitfixes.utils.FastPermTool;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.Location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.LocationUtil;
import me.moomoo.anarchyexploitfixes.utils.MaterialUtil;
import me.moomoo.anarchyexploitfixes.utils.models.FastPermTool;
import me.moomoo.anarchyexploitfixes.utils.FastPermTool;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.Location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.enums.AEFPermission;
import me.moomoo.anarchyexploitfixes.utils.models.FastPermTool;
import me.moomoo.anarchyexploitfixes.utils.FastPermTool;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
Expand Down Expand Up @@ -68,22 +68,22 @@ public void disable() {
}

@Override
public ItemCheckResult itemCheckResult(ItemStack itemStack) {
public ItemLegality getLegality(ItemStack itemStack) {
if (itemStack == null || itemStack.getType().isAir() || !itemStack.hasItemMeta()) {
return ItemCheckResult.FINE;
return ItemLegality.LEGAL;
}

final Component displayName = itemStack.displayName();
if (coloredNames.contains(displayName) || plainTextNames.contains(PlainTextComponentSerializer.plainText().serialize(displayName))) {
return ItemCheckResult.IS_ILLEGAL;
return ItemLegality.ILLEGAL;
}

return ItemCheckResult.FINE;
return ItemLegality.LEGAL;
}

@Override
public void handleItem(ItemStack itemStack, ItemCheckResult checkResult) {
if (checkResult != ItemCheckResult.FINE) {
public void handleItem(ItemStack itemStack, ItemLegality checkResult) {
if (checkResult != ItemLegality.LEGAL) {
itemStack.editMeta(meta -> meta.displayName(null));
}
}
Expand All @@ -93,8 +93,8 @@ private void onPrepareResult(PrepareResultEvent event) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDNAME, event.getView().getPlayer())) return;

ItemStack resultItem = event.getResult();
if (itemCheckResult(resultItem) == ItemCheckResult.IS_ILLEGAL) {
handleItem(resultItem, ItemCheckResult.IS_ILLEGAL);
if (getLegality(resultItem) == ItemLegality.ILLEGAL) {
handleItem(resultItem, ItemLegality.ILLEGAL);
event.setResult(resultItem);
}
}
Expand All @@ -103,19 +103,19 @@ private void onPrepareResult(PrepareResultEvent event) {
private void onInventoryClick(InventoryClickEvent event) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDNAME, event.getWhoClicked())) return;

handleItem(event.getCurrentItem(), itemCheckResult(event.getCurrentItem()));
handleItem(event.getCursor(), itemCheckResult(event.getCursor()));
handleItem(event.getCurrentItem(), getLegality(event.getCurrentItem()));
handleItem(event.getCursor(), getLegality(event.getCursor()));
for (ItemStack itemStack : event.getInventory()) {
handleItem(itemStack, itemCheckResult(itemStack));
handleItem(itemStack, getLegality(itemStack));
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onAttack(PrePlayerAttackEntityEvent event) {
if (!event.willAttack()) return;
ItemStack attackItem = event.getPlayer().getActiveItem();
final ItemCheckResult result = itemCheckResult(attackItem);
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(attackItem);
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDNAME, event.getPlayer())) return;

event.setCancelled(true);
Expand All @@ -126,8 +126,8 @@ private void onAttack(PrePlayerAttackEntityEvent event) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerDropItem(PlayerDropItemEvent event) {
ItemStack droppedItem = event.getItemDrop().getItemStack();
final ItemCheckResult result = itemCheckResult(droppedItem);
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(droppedItem);
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDNAME, event.getPlayer())) return;

handleItem(droppedItem, result);
Expand All @@ -137,8 +137,8 @@ private void onPlayerDropItem(PlayerDropItemEvent event) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
private void onInteract(PlayerInteractEvent event) {
final ItemCheckResult result = itemCheckResult(event.getItem());
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(event.getItem());
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDNAME, event.getPlayer())) return;

event.setCancelled(true);
Expand All @@ -149,8 +149,8 @@ private void onInteract(PlayerInteractEvent event) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onInteractEntity(PlayerInteractEntityEvent event) {
ItemStack handItem = event.getPlayer().getInventory().getItem(event.getHand());
final ItemCheckResult result = itemCheckResult(handItem);
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(handItem);
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDNAME, event.getPlayer())) return;

event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import me.moomoo.anarchyexploitfixes.enums.AEFPermission;
import me.moomoo.anarchyexploitfixes.utils.ItemUtil;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;
import me.moomoo.anarchyexploitfixes.utils.models.FastPermTool;
import me.moomoo.anarchyexploitfixes.utils.FastPermTool;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -89,32 +89,32 @@ public void disable() {
}

@Override
public ItemCheckResult itemCheckResult(ItemStack itemStack) {
public ItemLegality getLegality(ItemStack itemStack) {
if (itemStack == null) {
return ItemCheckResult.FINE;
return ItemLegality.LEGAL;
}

if (bannedMaterials.contains(itemStack.getType())) {
return ItemCheckResult.IS_ILLEGAL;
return ItemLegality.ILLEGAL;
}

if (checkStored) {
Iterable<ItemStack> storedItems = ItemUtil.getStoredItems(itemStack);
if (storedItems != null) {
for (ItemStack stored : storedItems) {
if (itemCheckResult(stored) != ItemCheckResult.FINE) {
return ItemCheckResult.CONTAINS_ILLEGAL;
if (getLegality(stored) != ItemLegality.LEGAL) {
return ItemLegality.CONTAINS_ILLEGAL;
}
}
}
}

return ItemCheckResult.FINE;
return ItemLegality.LEGAL;
}

@Override
public void handleItem(ItemStack itemStack, ItemCheckResult checkResult) {
if (checkResult != ItemCheckResult.FINE) {
public void handleItem(ItemStack itemStack, ItemLegality checkResult) {
if (checkResult != ItemLegality.LEGAL) {
if (shouldDelete) itemStack.setType(Material.AIR);
}
}
Expand All @@ -123,19 +123,19 @@ public void handleItem(ItemStack itemStack, ItemCheckResult checkResult) {
private void onInventoryClick(InventoryClickEvent event) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDMATERIAL, event.getWhoClicked())) return;

handleItem(event.getCurrentItem(), itemCheckResult(event.getCurrentItem()));
handleItem(event.getCursor(), itemCheckResult(event.getCursor()));
handleItem(event.getCurrentItem(), getLegality(event.getCurrentItem()));
handleItem(event.getCursor(), getLegality(event.getCursor()));
for (ItemStack itemStack : event.getWhoClicked().getInventory()) {
handleItem(itemStack, itemCheckResult(itemStack));
handleItem(itemStack, getLegality(itemStack));
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onAttack(PrePlayerAttackEntityEvent event) {
if (!event.willAttack()) return;
ItemStack attackItem = event.getPlayer().getActiveItem();
final ItemCheckResult result = itemCheckResult(attackItem);
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(attackItem);
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDMATERIAL, event.getPlayer())) return;

event.setCancelled(true);
Expand All @@ -146,8 +146,8 @@ private void onAttack(PrePlayerAttackEntityEvent event) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerDropItem(PlayerDropItemEvent event) {
ItemStack droppedItem = event.getItemDrop().getItemStack();
final ItemCheckResult result = itemCheckResult(droppedItem);
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(droppedItem);
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDMATERIAL, event.getPlayer())) return;

handleItem(droppedItem, result);
Expand All @@ -157,8 +157,8 @@ private void onPlayerDropItem(PlayerDropItemEvent event) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
private void onInteract(PlayerInteractEvent event) {
final ItemCheckResult result = itemCheckResult(event.getItem());
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(event.getItem());
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDMATERIAL, event.getPlayer())) return;

event.setCancelled(true);
Expand All @@ -169,8 +169,8 @@ private void onInteract(PlayerInteractEvent event) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onInteractEntity(PlayerInteractEntityEvent event) {
ItemStack handItem = event.getPlayer().getInventory().getItem(event.getHand());
final ItemCheckResult result = itemCheckResult(handItem);
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(handItem);
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_BANNEDMATERIAL, event.getPlayer())) return;

event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

public interface IllegalItemModule extends AnarchyExploitFixesModule, Listener {

ItemCheckResult itemCheckResult(ItemStack itemStack);
void handleItem(ItemStack itemStack, ItemCheckResult checkResult);
ItemLegality getLegality(ItemStack itemStack);
void handleItem(ItemStack itemStack, ItemLegality checkResult);

enum ItemCheckResult {
IS_ILLEGAL,
enum ItemLegality {
LEGAL,
ILLEGAL,
CONTAINS_ILLEGAL,
FINE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import me.moomoo.anarchyexploitfixes.enums.AEFPermission;
import me.moomoo.anarchyexploitfixes.utils.ItemUtil;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;
import me.moomoo.anarchyexploitfixes.utils.models.FastPermTool;
import me.moomoo.anarchyexploitfixes.utils.FastPermTool;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -83,7 +83,7 @@ public void enable() {
this.hopperListener = new Listener() {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onInventoryMove(InventoryMoveItemEvent event) {
if (itemCheckResult(event.getItem()) != ItemCheckResult.FINE) {
if (getLegality(event.getItem()) != ItemLegality.LEGAL) {
event.setCancelled(true);
}
}
Expand All @@ -94,7 +94,7 @@ private void onInventoryMove(InventoryMoveItemEvent event) {
if (doPeriodicCheck) {
this.periodicInvCheck = plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, periodic_inv_check ->
plugin.getServer().getOnlinePlayers().forEach(player -> player.getScheduler().run(plugin, scheduled_inv_check ->
player.getInventory().forEach(item -> handleItem(item, itemCheckResult(item))), null)), checkPeriod, checkPeriod);
player.getInventory().forEach(item -> handleItem(item, getLegality(item))), null)), checkPeriod, checkPeriod);
}
}

Expand All @@ -111,35 +111,35 @@ public void disable() {
}

@Override
public ItemCheckResult itemCheckResult(ItemStack itemStack) {
public ItemLegality getLegality(ItemStack itemStack) {
if (itemStack == null || itemStack.getType().isAir()) {
return ItemCheckResult.FINE;
return ItemLegality.LEGAL;
}

if (!useWhitelist || blacklistMode == whitelistedTypes.contains(itemStack.getType())) {
if (itemStack.getAmount() > itemStack.getMaxStackSize()) {
return ItemCheckResult.IS_ILLEGAL;
return ItemLegality.ILLEGAL;
}
}

if (checkStored) {
Iterable<ItemStack> storedItems = ItemUtil.getStoredItems(itemStack);
if (storedItems != null) {
for (ItemStack stored : storedItems) {
if (itemCheckResult(stored) != ItemCheckResult.FINE) {
return ItemCheckResult.CONTAINS_ILLEGAL;
if (getLegality(stored) != ItemLegality.LEGAL) {
return ItemLegality.CONTAINS_ILLEGAL;
}
}
}
}

return ItemCheckResult.FINE;
return ItemLegality.LEGAL;
}

@Override
public void handleItem(ItemStack itemStack, ItemCheckResult checkResult) {
public void handleItem(ItemStack itemStack, ItemLegality checkResult) {
switch (checkResult) {
case IS_ILLEGAL -> itemStack.setAmount(itemStack.getMaxStackSize());
case ILLEGAL -> itemStack.setAmount(itemStack.getMaxStackSize());
case CONTAINS_ILLEGAL -> itemStack.setType(Material.AIR);
}
}
Expand All @@ -148,19 +148,19 @@ public void handleItem(ItemStack itemStack, ItemCheckResult checkResult) {
private void onInventoryClick(InventoryClickEvent event) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_OVERSTACKED, event.getWhoClicked())) return;

handleItem(event.getCurrentItem(), itemCheckResult(event.getCurrentItem()));
handleItem(event.getCursor(), itemCheckResult(event.getCursor()));
handleItem(event.getCurrentItem(), getLegality(event.getCurrentItem()));
handleItem(event.getCursor(), getLegality(event.getCursor()));
for (ItemStack itemStack : event.getWhoClicked().getInventory()) {
handleItem(itemStack, itemCheckResult(itemStack));
handleItem(itemStack, getLegality(itemStack));
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onAttack(PrePlayerAttackEntityEvent event) {
if (!event.willAttack()) return;
ItemStack attackItem = event.getPlayer().getActiveItem();
final ItemCheckResult result = itemCheckResult(attackItem);
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(attackItem);
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_OVERSTACKED, event.getPlayer())) return;

event.setCancelled(true);
Expand All @@ -171,8 +171,8 @@ private void onAttack(PrePlayerAttackEntityEvent event) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerDropItem(PlayerDropItemEvent event) {
ItemStack droppedItem = event.getItemDrop().getItemStack();
final ItemCheckResult result = itemCheckResult(droppedItem);
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(droppedItem);
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_OVERSTACKED, event.getPlayer())) return;

handleItem(droppedItem, result);
Expand All @@ -182,8 +182,8 @@ private void onPlayerDropItem(PlayerDropItemEvent event) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
private void onInteract(PlayerInteractEvent event) {
final ItemCheckResult result = itemCheckResult(event.getItem());
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(event.getItem());
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_OVERSTACKED, event.getPlayer())) return;

event.setCancelled(true);
Expand All @@ -194,8 +194,8 @@ private void onInteract(PlayerInteractEvent event) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onInteractEntity(PlayerInteractEntityEvent event) {
ItemStack handItem = event.getPlayer().getInventory().getItem(event.getHand());
final ItemCheckResult result = itemCheckResult(handItem);
if (result != ItemCheckResult.FINE) {
final ItemLegality result = getLegality(handItem);
if (result != ItemLegality.LEGAL) {
if (FastPermTool.hasPermission(AEFPermission.BYPASS_ILLEGAL_OVERSTACKED, event.getPlayer())) return;

event.setCancelled(true);
Expand Down
Loading

0 comments on commit 606746a

Please sign in to comment.