From 073356be49e067201d335e7e449c5c7fe2dae92a Mon Sep 17 00:00:00 2001 From: Allink <44676012+allinkdev@users.noreply.github.com> Date: Sat, 16 Jul 2022 23:03:23 +0100 Subject: [PATCH] Properly patch Game Master Blocks (#245) * Break cancelled blocks on interact * Cancel master blocks * Add Scissors maven repository * Remove Scissors repo (it is already included in the AMG repo) * Remove unused import & add TODO for the 1.19 port --- pom.xml | 7 +++--- .../blocking/BlockBlocker.java | 14 +++++++++-- .../blocking/EventBlocker.java | 23 +++++++++++++++---- .../blocking/InteractBlocker.java | 20 ++++++++-------- .../command/Command_toggle.java | 12 +++------- .../totalfreedommod/config/ConfigEntry.java | 3 +-- src/main/resources/config.yml | 3 +-- 7 files changed, 47 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index fd106e42..aa17eabe 100644 --- a/pom.xml +++ b/pom.xml @@ -100,8 +100,7 @@ esentialsx-repo https://repo.essentialsx.net/releases/ - - + @@ -128,8 +127,8 @@ - io.papermc.paper - paper-api + me.totalfreedom.scissors + scissors-api 1.17.1-R0.1-SNAPSHOT provided diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java index 746ce186..492deea9 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java @@ -71,7 +71,7 @@ public class BlockBlocker extends FreedomService } case STRUCTURE_BLOCK: { - if (!ConfigEntry.ALLOW_STRUCTURE_BLOCKS.getBoolean()) + if (!ConfigEntry.ALLOW_MASTERBLOCKS.getBoolean()) { player.sendMessage(ChatColor.GRAY + "Structure blocks are disabled."); player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); @@ -81,7 +81,7 @@ public class BlockBlocker extends FreedomService } case JIGSAW: { - if (!ConfigEntry.ALLOW_JIGSAWS.getBoolean()) + if (!ConfigEntry.ALLOW_MASTERBLOCKS.getBoolean()) { player.sendMessage(ChatColor.GRAY + "Jigsaws are disabled."); player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); @@ -89,6 +89,16 @@ public class BlockBlocker extends FreedomService } break; } + case REPEATING_COMMAND_BLOCK: + case CHAIN_COMMAND_BLOCK: + case COMMAND_BLOCK: + if (!ConfigEntry.ALLOW_MASTERBLOCKS.getBoolean()) + { + player.sendMessage(ChatColor.GRAY + "Command blocks are disabled."); + player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); + event.setCancelled(true); + } + break; case GRINDSTONE: { if (!ConfigEntry.ALLOW_GRINDSTONES.getBoolean()) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java index 5a004763..bc2ec9ba 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java @@ -4,7 +4,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; - +/* TODO This will have to be changed from com.github.atlasmediagroup.scissors to me.totalfreedom.scissors when we migrate to 1.19 */ +import com.github.atlasmediagroup.scissors.event.block.MasterBlockFireEvent; import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; @@ -108,10 +109,12 @@ public class EventBlocker extends FreedomService event.setRadius(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue()); } - + @EventHandler(priority = EventPriority.HIGH) - public void onBlockExplode(BlockExplodeEvent event) { - if(!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { + public void onBlockExplode(BlockExplodeEvent event) + { + if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) + { event.setCancelled(true); return; } @@ -119,6 +122,16 @@ public class EventBlocker extends FreedomService event.setYield(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue()); } + @EventHandler(priority = EventPriority.HIGHEST) + public void onMasterBlockFire(MasterBlockFireEvent event) + { + if (!ConfigEntry.ALLOW_MASTERBLOCKS.getBoolean()) + { + event.setCancelled(true); + event.getAt().getBlock().setType(Material.CAKE); + } + } + @EventHandler(priority = EventPriority.HIGH) public void onEntityCombust(EntityCombustEvent event) { @@ -152,7 +165,7 @@ public class EventBlocker extends FreedomService Entity entity = event.getEntity(); if (entity instanceof Tameable) { - if (((Tameable)entity).isTamed()) + if (((Tameable) entity).isTamed()) { event.setCancelled(true); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java index 17f6c5fe..f9aa91fe 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java @@ -69,24 +69,22 @@ public class InteractBlocker extends FreedomService private void handleRightClick(PlayerInteractEvent event) { final Player player = event.getPlayer(); + final Block clickedBlock = event.getClickedBlock(); - if (event.getClickedBlock() != null) + if (clickedBlock == null) { - if (event.getClickedBlock().getType().equals(Material.STRUCTURE_BLOCK) || event.getClickedBlock().getType().equals(Material.JIGSAW) || event.getClickedBlock().getType().equals(Material.RESPAWN_ANCHOR)) - { - event.setCancelled(true); - event.getPlayer().closeInventory(); - } + return; + } + + if (clickedBlock.getType() == Material.RESPAWN_ANCHOR && !ConfigEntry.ALLOW_RESPAWN_ANCHORS.getBoolean()) + { + event.setCancelled(true); + return; } if (Groups.SPAWN_EGGS.contains(event.getMaterial())) { event.setCancelled(true); - Block clickedBlock = event.getClickedBlock(); - if (clickedBlock == null) - { - return; - } EntityType eggType = null; try { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java index 712ff7ff..2639b9d5 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java @@ -19,7 +19,7 @@ public class Command_toggle extends FreedomCommand private final List toggles = Arrays.asList( "waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk", "firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke [range] [count]", - "explosives [radius]", "unsafeenchs", "bells", "armorstands", "structureblocks", "jigsaws", "grindstones", + "explosives [radius]", "unsafeenchs", "bells", "armorstands", "masterblocks", "grindstones", "jukeboxes", "spawners", "4chan", "beehives", "respawnanchors", "autotp", "autoclear", "minecarts", "mp44", "landmines", "tossmob", "gravity"); @@ -193,15 +193,9 @@ public class Command_toggle extends FreedomCommand break; } - case "structureblocks": + case "masterblocks": { - toggle("Structure blocks are", ConfigEntry.ALLOW_STRUCTURE_BLOCKS); - break; - } - - case "jigsaws": - { - toggle("Jigsaws are", ConfigEntry.ALLOW_JIGSAWS); + toggle("Master blocks are", ConfigEntry.ALLOW_MASTERBLOCKS); break; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index 598c3d1f..4c58eb10 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -25,8 +25,6 @@ public enum ConfigEntry ALLOW_BELLS(Boolean.class, "allow.bells"), ALLOW_ARMOR_STANDS(Boolean.class, "allow.armorstands"), ALLOW_MINECARTS(Boolean.class, "allow.minecarts"), - ALLOW_STRUCTURE_BLOCKS(Boolean.class, "allow.structureblocks"), - ALLOW_JIGSAWS(Boolean.class, "allow.jigsaws"), ALLOW_GRINDSTONES(Boolean.class, "allow.grindstones"), ALLOW_JUKEBOXES(Boolean.class, "allow.jukeboxes"), ALLOW_SPAWNERS(Boolean.class, "allow.spawners"), @@ -35,6 +33,7 @@ public enum ConfigEntry AUTO_TP(Boolean.class, "allow.auto_tp"), AUTO_CLEAR(Boolean.class, "allow.auto_clear"), ALLOW_GRAVITY(Boolean.class, "allow.gravity"), + ALLOW_MASTERBLOCKS(Boolean.class, "allow.masterblocks"), // BLOCKED_CHATCODES(String.class, "blocked_chatcodes"), // diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d0f9ff4d..2aa7a488 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -224,8 +224,6 @@ allow: minecarts: true clearonjoin: false tpronjoin: false - structureblocks: false - jigsaws: false grindstones: true jukeboxes: true spawners: false @@ -234,6 +232,7 @@ allow: auto_tp: false auto_clear: false gravity: false + masterblocks: false blocked_commands: #