-
-
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.
initial work for illegal item module rewrite
rename banned-blocks to banned-materials and reduce listeners
- Loading branch information
Showing
15 changed files
with
314 additions
and
611 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
136 changes: 136 additions & 0 deletions
136
...ia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/BannedMaterial.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,136 @@ | ||
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.modules.AnarchyExploitFixesModule; | ||
import me.moomoo.anarchyexploitfixes.utils.ItemUtil; | ||
import me.moomoo.anarchyexploitfixes.utils.LogUtil; | ||
import org.bukkit.Material; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerInteractEntityEvent; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.logging.Level; | ||
import java.util.stream.Collectors; | ||
|
||
public class BannedMaterial implements AnarchyExploitFixesModule, Listener { | ||
|
||
private final Set<Material> bannedMaterials; | ||
private final boolean delete, checkStored; | ||
|
||
public BannedMaterial() { | ||
shouldEnable(); | ||
Config config = AnarchyExploitFixes.getConfiguration(); | ||
this.delete = config.getBoolean("illegals.ban-specific-materials.delete-illegals", false); | ||
this.checkStored = config.getBoolean("illegals.ban-specific-materials.check-stored-items", false); | ||
this.bannedMaterials = config.getList("illegals.ban-specific-materials.banned-materials", List.of( | ||
"CHAIN_COMMAND_BLOCK", | ||
"COMMAND_BLOCK", | ||
"COMMAND_BLOCK_MINECART", | ||
"REPEATING_COMMAND_BLOCK", | ||
"BEDROCK", | ||
"BARRIER", | ||
"STRUCTURE_BLOCK", | ||
"STRUCTURE_VOID", | ||
"END_PORTAL_FRAME", | ||
"END_PORTAL", | ||
"NETHER_PORTAL", | ||
"LIGHT")) | ||
.stream() | ||
.map(confMaterial -> { | ||
try { | ||
return Material.valueOf(confMaterial); | ||
} catch (IllegalArgumentException e) { | ||
LogUtil.materialNotRecognized(Level.WARNING, name(), confMaterial); | ||
return null; | ||
} | ||
}) | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toCollection(HashSet::new)); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "ban-specific-materials"; | ||
} | ||
|
||
@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-specific-materials.enable", false); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
HandlerList.unregisterAll(this); | ||
} | ||
|
||
private boolean isIllegal(ItemStack itemStack) { | ||
if (bannedMaterials.contains(itemStack.getType())) { | ||
return true; | ||
} | ||
|
||
if (checkStored) { | ||
Iterable<ItemStack> storedItems = ItemUtil.getStoredItems(itemStack); | ||
if (storedItems == null) return false; | ||
for (ItemStack stored : storedItems) { | ||
if (stored != null && bannedMaterials.contains(stored.getType())) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) | ||
private void onInteract(PlayerInteractEvent event) { | ||
ItemStack interactItem = event.getItem(); | ||
|
||
if (interactItem != null && isIllegal(interactItem)) { | ||
event.setCancelled(true); | ||
if (delete) interactItem.setAmount(0); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onAttack(PrePlayerAttackEntityEvent event) { | ||
if (!event.willAttack()) return; | ||
|
||
ItemStack attackItem = event.getPlayer().getActiveItem(); | ||
|
||
if (isIllegal(attackItem)) { | ||
event.setCancelled(true); | ||
if (delete) attackItem.setAmount(0); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onInteractEntity(PlayerInteractEntityEvent event) { | ||
ItemStack interactItem = event.getPlayer().getInventory().getItem(event.getHand()); | ||
|
||
if (isIllegal(interactItem)) { | ||
event.setCancelled(true); | ||
if (delete) interactItem.setAmount(0); | ||
} | ||
} | ||
} |
214 changes: 0 additions & 214 deletions
214
.../me/moomoo/anarchyexploitfixes/modules/illegals/items/bannedblocks/BanSpecificBlocks.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.