-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite playerheads and spawneggs module
- Loading branch information
Showing
8 changed files
with
316 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
...Folia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/PlayerHeads.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package me.moomoo.anarchyexploitfixes.modules.illegals.items; | ||
|
||
import io.papermc.paper.event.player.PrePlayerAttackEntityEvent; | ||
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; | ||
import me.moomoo.anarchyexploitfixes.config.Config; | ||
import me.moomoo.anarchyexploitfixes.enums.AEFPermission; | ||
import me.moomoo.anarchyexploitfixes.utils.ItemUtil; | ||
import me.moomoo.anarchyexploitfixes.utils.models.HumanPermHelper; | ||
import org.bukkit.Material; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.block.BlockDispenseEvent; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.event.player.PlayerDropItemEvent; | ||
import org.bukkit.event.player.PlayerInteractEntityEvent; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class PlayerHeads implements IllegalItemModule { | ||
|
||
private final boolean shouldDelete, checkStored; | ||
|
||
public PlayerHeads() { | ||
shouldEnable(); | ||
Config config = AnarchyExploitFixes.getConfiguration(); | ||
config.addComment("illegals.ban-player-heads.enable", | ||
"Prevents usage of player heads. Bypass permission: " + AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD.get()); | ||
this.shouldDelete = config.getBoolean("illegals.ban-player-heads.remove-items", false); | ||
this.checkStored = config.getBoolean("illegals.ban-player-heads.check-stored-items", false, | ||
"Will delete shulker/bundle if they contain any spawneggs."); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "ban-player-heads"; | ||
} | ||
|
||
@Override | ||
public String category() { | ||
return "illegals"; | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@Override | ||
public boolean shouldEnable() { | ||
return AnarchyExploitFixes.getConfiguration().getBoolean("illegals.ban-player-heads.enable", false); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
HandlerList.unregisterAll(this); | ||
} | ||
|
||
@Override | ||
public ItemCheckResult checkItem(ItemStack itemStack) { | ||
if (itemStack == null) { | ||
return ItemCheckResult.FINE; | ||
} | ||
|
||
switch (itemStack.getType()) { | ||
case PLAYER_HEAD, PLAYER_WALL_HEAD -> { | ||
return ItemCheckResult.IS_ILLEGAL; | ||
} | ||
} | ||
|
||
if (checkStored) { | ||
Iterable<ItemStack> storedItems = ItemUtil.getStoredItems(itemStack); | ||
if (storedItems != null) { | ||
for (ItemStack stored : storedItems) { | ||
if (checkItem(stored) != ItemCheckResult.FINE) { | ||
return ItemCheckResult.CONTAINS_ILLEGAL; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return ItemCheckResult.FINE; | ||
} | ||
|
||
@Override | ||
public void takeAction(ItemStack itemStack, ItemCheckResult result) { | ||
if (shouldDelete) itemStack.setType(Material.AIR); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onDispense(BlockDispenseEvent event) { | ||
switch (event.getItem().getType()) { | ||
case PLAYER_HEAD, PLAYER_WALL_HEAD -> event.setCancelled(true); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onInventoryClick(InventoryClickEvent event) { | ||
if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD, event.getWhoClicked())) return; | ||
|
||
takeAction(event.getCurrentItem(), checkItem(event.getCurrentItem())); | ||
takeAction(event.getCursor(), checkItem(event.getCursor())); | ||
for (ItemStack itemStack : event.getWhoClicked().getInventory()) { | ||
takeAction(itemStack, checkItem(itemStack)); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onAttack(PrePlayerAttackEntityEvent event) { | ||
if (!event.willAttack()) return; | ||
ItemStack attackItem = event.getPlayer().getActiveItem(); | ||
final ItemCheckResult result = checkItem(attackItem); | ||
if (result != ItemCheckResult.FINE) { | ||
if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD, event.getPlayer())) return; | ||
|
||
event.setCancelled(true); | ||
takeAction(attackItem, result); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onPlayerDropItem(PlayerDropItemEvent event) { | ||
ItemStack droppedItem = event.getItemDrop().getItemStack(); | ||
final ItemCheckResult result = checkItem(droppedItem); | ||
if (result != ItemCheckResult.FINE) { | ||
if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD, event.getPlayer())) return; | ||
|
||
takeAction(droppedItem, result); | ||
event.getItemDrop().setItemStack(droppedItem); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) | ||
private void onInteract(PlayerInteractEvent event) { | ||
final ItemCheckResult result = checkItem(event.getItem()); | ||
if (result != ItemCheckResult.FINE) { | ||
if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD, event.getPlayer())) return; | ||
|
||
event.setCancelled(true); | ||
takeAction(event.getItem(), result); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onInteractEntity(PlayerInteractEntityEvent event) { | ||
ItemStack handItem = event.getPlayer().getInventory().getItem(event.getHand()); | ||
final ItemCheckResult result = checkItem(handItem); | ||
if (result != ItemCheckResult.FINE) { | ||
if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD, event.getPlayer())) return; | ||
|
||
event.setCancelled(true); | ||
takeAction(handItem, result); | ||
} | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
...esFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/SpawnEggs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package me.moomoo.anarchyexploitfixes.modules.illegals.items; | ||
|
||
import io.papermc.paper.event.player.PrePlayerAttackEntityEvent; | ||
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; | ||
import me.moomoo.anarchyexploitfixes.config.Config; | ||
import me.moomoo.anarchyexploitfixes.enums.AEFPermission; | ||
import me.moomoo.anarchyexploitfixes.utils.ItemUtil; | ||
import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; | ||
import me.moomoo.anarchyexploitfixes.utils.models.HumanPermHelper; | ||
import org.bukkit.Material; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.block.BlockDispenseEvent; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.event.player.PlayerDropItemEvent; | ||
import org.bukkit.event.player.PlayerInteractEntityEvent; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class SpawnEggs implements IllegalItemModule { | ||
|
||
private final boolean shouldDelete, checkStored; | ||
|
||
public SpawnEggs() { | ||
shouldEnable(); | ||
Config config = AnarchyExploitFixes.getConfiguration(); | ||
config.addComment("illegals.ban-spawn-eggs.enable", | ||
"Prevents usage of spawn eggs. Bypass permission: " + AEFPermission.BYPASS_ILLEGAL_SPAWNEGG.get()); | ||
this.shouldDelete = config.getBoolean("illegals.ban-spawn-eggs.remove-spawn-eggs", false); | ||
this.checkStored = config.getBoolean("illegals.ban-spawn-eggs.check-stored-items", false, | ||
"Will delete shulker/bundle if they contain any spawneggs."); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "ban-spawn-eggs"; | ||
} | ||
|
||
@Override | ||
public String category() { | ||
return "illegals"; | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@Override | ||
public boolean shouldEnable() { | ||
return AnarchyExploitFixes.getConfiguration().getBoolean("illegals.ban-spawn-eggs.enable", false); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
HandlerList.unregisterAll(this); | ||
} | ||
|
||
@Override | ||
public ItemCheckResult checkItem(ItemStack itemStack) { | ||
if (itemStack == null) { | ||
return ItemCheckResult.FINE; | ||
} | ||
|
||
if (MaterialUtil.isSpawnEgg(itemStack.getType())) { | ||
return ItemCheckResult.IS_ILLEGAL; | ||
} | ||
|
||
if (checkStored) { | ||
Iterable<ItemStack> storedItems = ItemUtil.getStoredItems(itemStack); | ||
if (storedItems != null) { | ||
for (ItemStack stored : storedItems) { | ||
if (checkItem(stored) != ItemCheckResult.FINE) { | ||
return ItemCheckResult.CONTAINS_ILLEGAL; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return ItemCheckResult.FINE; | ||
} | ||
|
||
@Override | ||
public void takeAction(ItemStack itemStack, ItemCheckResult result) { | ||
if (shouldDelete) itemStack.setType(Material.AIR); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onDispense(BlockDispenseEvent event) { | ||
if (MaterialUtil.isSpawnEgg(event.getItem())) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onInventoryClick(InventoryClickEvent event) { | ||
if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_SPAWNEGG, event.getWhoClicked())) return; | ||
|
||
takeAction(event.getCurrentItem(), checkItem(event.getCurrentItem())); | ||
takeAction(event.getCursor(), checkItem(event.getCursor())); | ||
for (ItemStack itemStack : event.getWhoClicked().getInventory()) { | ||
takeAction(itemStack, checkItem(itemStack)); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onAttack(PrePlayerAttackEntityEvent event) { | ||
if (!event.willAttack()) return; | ||
ItemStack attackItem = event.getPlayer().getActiveItem(); | ||
final ItemCheckResult result = checkItem(attackItem); | ||
if (result != ItemCheckResult.FINE) { | ||
if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_SPAWNEGG, event.getPlayer())) return; | ||
|
||
event.setCancelled(true); | ||
takeAction(attackItem, result); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onPlayerDropItem(PlayerDropItemEvent event) { | ||
ItemStack droppedItem = event.getItemDrop().getItemStack(); | ||
final ItemCheckResult result = checkItem(droppedItem); | ||
if (result != ItemCheckResult.FINE) { | ||
if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_SPAWNEGG, event.getPlayer())) return; | ||
|
||
takeAction(droppedItem, result); | ||
event.getItemDrop().setItemStack(droppedItem); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) | ||
private void onInteract(PlayerInteractEvent event) { | ||
final ItemCheckResult result = checkItem(event.getItem()); | ||
if (result != ItemCheckResult.FINE) { | ||
if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_SPAWNEGG, event.getPlayer())) return; | ||
|
||
event.setCancelled(true); | ||
takeAction(event.getItem(), result); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onInteractEntity(PlayerInteractEntityEvent event) { | ||
ItemStack handItem = event.getPlayer().getInventory().getItem(event.getHand()); | ||
final ItemCheckResult result = checkItem(handItem); | ||
if (result != ItemCheckResult.FINE) { | ||
if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_SPAWNEGG, event.getPlayer())) return; | ||
|
||
event.setCancelled(true); | ||
takeAction(handItem, result); | ||
} | ||
} | ||
} |
Oops, something went wrong.