Skip to content

Commit

Permalink
try fix playerheads module on folia
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Nov 29, 2023
1 parent 1bd11f2 commit 3f7ff2a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void enable() {

@Override
public boolean shouldEnable() {
return AnarchyExploitFixes.getConfiguration().getBoolean("chat.prevent-scanning-server-plugins.enable", false, "Prevents hacked clients running .plugins to find out what plugins the server is using");
return AnarchyExploitFixes.getConfiguration().getBoolean("chat.prevent-scanning-server-plugins.enable", true, "Prevents hacked clients running .plugins to find out what plugins the server is using");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.SkullMeta;

import static me.moomoo.anarchyexploitfixes.utils.ItemUtils.isShulkerBox;

Expand All @@ -34,14 +33,12 @@ public class BanPlayerHeads implements AnarchyExploitFixesModule, Listener {
private ScheduledTask periodicInvCheck;
private Listener hopperListener;
private final boolean enableStrictPrevention, removeIllegalShulkers, preventHopperBypass;
private final ItemStack PLAYER_HEAD;
private final long checkPeriod;

public BanPlayerHeads() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
this.PLAYER_HEAD = new ItemStack(Material.PLAYER_HEAD, 1);
config.addComment("illegals.player-heads.remove-items.enable", "This deletes playerheads with and without owners");
this.preventHopperBypass = config.getBoolean("illegals.player-heads.remove-items.prevent-hopper32k-mechanic", false, """
Prevents Hopper32k mechanic of placing a shulker containing illegals on top of a hopper and using the illegal\s
Expand Down Expand Up @@ -70,8 +67,8 @@ public void enable() {
this.hopperListener = new Listener() {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onInventoryMove(InventoryMoveItemEvent event) {
ItemStack hopperItem = event.getItem();
if (hopperItem.isSimilar(PLAYER_HEAD) || ((SkullMeta) hopperItem.getItemMeta()).hasOwner()) {
final Material material = event.getItem().getType();
if (material.equals(Material.PLAYER_HEAD) || material.equals(Material.PLAYER_WALL_HEAD)) {
event.setCancelled(true);
}
}
Expand Down Expand Up @@ -102,7 +99,8 @@ public void disable() {
private void removePlayerHeadItemIfPresent(ItemStack item) {
if (item == null) return;

if (item.getType().equals(PLAYER_HEAD.getType()) && (item.isSimilar(PLAYER_HEAD) || ((SkullMeta) item.getItemMeta()).hasOwner())) {
final Material material = item.getType();
if (material.equals(Material.PLAYER_HEAD) || material.equals(Material.PLAYER_WALL_HEAD)) {
item.subtract(item.getAmount());
}

Expand All @@ -115,10 +113,10 @@ private void removePlayerHeadItemIfPresent(ItemStack item) {

private boolean shulkerContainsIllegalHead(ShulkerBox shulkerBox) {
for (ItemStack shulkerContentItem : shulkerBox.getInventory()) {
if (shulkerContentItem != null && shulkerContentItem.getType().equals(PLAYER_HEAD.getType())) {
if (shulkerContentItem.isSimilar(PLAYER_HEAD) || ((SkullMeta) shulkerContentItem.getItemMeta()).hasOwner()) {
return true;
}
if (shulkerContentItem == null) continue;
final Material material = shulkerContentItem.getType();
if (material.equals(Material.PLAYER_HEAD) || material.equals(Material.PLAYER_WALL_HEAD)) {
return true;
}
}
return false;
Expand Down Expand Up @@ -148,11 +146,10 @@ private void onPlayerPickupItem(PlayerAttemptPickupItemEvent event) {

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onBlockPlace(BlockPlaceEvent event) {
if (removeIllegalShulkers) {
Block placedBlock = event.getBlockPlaced();
if (isShulkerBox(placedBlock.getType()) && shulkerContainsIllegalHead((ShulkerBox) placedBlock.getState())) {
placedBlock.setType(Material.AIR);
}
if (!removeIllegalShulkers) return;
Block placedBlock = event.getBlockPlaced();
if (isShulkerBox(placedBlock.getType()) && shulkerContainsIllegalHead((ShulkerBox) placedBlock.getState())) {
placedBlock.setType(Material.AIR);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

public class PreventPlacingPlayerHeads implements AnarchyExploitFixesModule, Listener {
Expand Down Expand Up @@ -42,10 +41,9 @@ public void disable() {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onBlockPlace(PlayerInteractEvent event) {
if (
event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
&& event.getMaterial().equals(Material.PLAYER_HEAD)
) {
if (event.getAction().isLeftClick()) return;
final Material material = event.getMaterial();
if (material.equals(Material.PLAYER_HEAD) || material.equals(Material.PLAYER_WALL_HEAD)) {
event.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void enable() {

@Override
public boolean shouldEnable() {
return AnarchyExploitFixes.getConfiguration().getBoolean("chat.prevent-scanning-server-plugins.enable", false, "Prevents hacked clients running .plugins to find out what plugins the server is using");
return AnarchyExploitFixes.getConfiguration().getBoolean("chat.prevent-scanning-server-plugins.enable", true, "Prevents hacked clients running .plugins to find out what plugins the server is using");
}

private static boolean isSuspectedScanPacket(String buffer) {
Expand Down

0 comments on commit 3f7ff2a

Please sign in to comment.