From 853631139de91d00c967aefa1ee9e11741ba51ac Mon Sep 17 00:00:00 2001 From: Joo200 Date: Thu, 8 Jun 2023 21:38:37 +0200 Subject: [PATCH] Update Protections to 1.20 * add new materials * add protections for sniffer eggs * add protection for signs --- .../bukkit/BukkitWorldConfiguration.java | 2 ++ .../listener/EventAbstractionListener.java | 8 ++--- .../listener/WorldGuardEntityListener.java | 4 +++ .../listener/WorldGuardPlayerListener.java | 4 +++ .../worldguard/bukkit/util/Materials.java | 35 ++++++++++++++++--- .../worldguard/config/WorldConfiguration.java | 2 ++ 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java index f204cd2e..ba58b48e 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java @@ -256,6 +256,8 @@ public void loadConfiguration() { disableCreatureTurtleEggTrampling = getBoolean("turtle-egg.disable-creature-trampling", false); disablePlayerTurtleEggTrampling = getBoolean("turtle-egg.disable-player-trampling", false); + disableCreatureSnifferEggTrampling = getBoolean("sniffer-egg.disable-creature-trampling", false); + disablePlayerSnifferEggTrampling = getBoolean("sniffer-egg.disable-player-trampling", false); disallowedLightningBlocks = new HashSet<>(convertLegacyBlocks(getStringList("weather.prevent-lightning-strike-blocks", null))); preventLightningFire = getBoolean("weather.disable-lightning-strike-fire", false); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 2882ca25..d35483d4 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -454,7 +454,9 @@ public void onPlayerInteract(PlayerInteractEvent event) { switch (event.getAction()) { case PHYSICAL: if (event.useInteractedBlock() != Result.DENY) { - if (clicked.getType() == Material.FARMLAND || clicked.getType() == Material.TURTLE_EGG) { + if (clicked.getType() == Material.FARMLAND || + clicked.getType() == Material.TURTLE_EGG || + clicked.getType() == Material.SNIFFER_EGG) { BreakBlockEvent breakDelagate = new BreakBlockEvent(event, cause, clicked); breakDelagate.setSilent(true); breakDelagate.getRelevantFlags().add(Flags.TRAMPLE_BLOCKS); @@ -600,9 +602,7 @@ public void onBlockIgnite(BlockIgniteEvent event) { @EventHandler(ignoreCancelled = true) public void onSignChange(SignChangeEvent event) { - Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), event.getBlock())); - - if (event.isCancelled()) { + if (Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getPlayer()), event.getBlock()))) { playDenyEffect(event.getPlayer(), event.getBlock().getLocation().add(0.5, 0.5, 0.5)); } } diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index 1037ad42..71f6c8d7 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -120,6 +120,10 @@ public void onEntityInteract(EntityInteractEvent event) { event.setCancelled(true); return; } + if (block.getType() == Material.SNIFFER_EGG && wcfg.disableCreatureSnifferEggTrampling) { + event.setCancelled(true); + return; + } } @EventHandler(priority = EventPriority.HIGH) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java index 6685f617..d9daa9e8 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java @@ -307,6 +307,10 @@ private void handlePhysicalInteract(PlayerInteractEvent event) { event.setCancelled(true); return; } + if (type == Material.SNIFFER_EGG && wcfg.disablePlayerSnifferEggTrampling) { + event.setCancelled(true); + return; + } } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index ab4fe660..d2574d29 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -820,15 +820,30 @@ private static void putMaterialTag(Tag tag, Integer value) { MATERIAL_FLAGS.put(Material.ECHO_SHARD, 0); MATERIAL_FLAGS.put(Material.REINFORCED_DEEPSLATE, 0); - // 1.19.3: Try to register those things + // 1.20 try { SIGNS_TAG = Tag.ALL_SIGNS; MATERIAL_FLAGS.put(Material.BAMBOO_MOSAIC, 0); MATERIAL_FLAGS.put(Material.BAMBOO_BLOCK, 0); MATERIAL_FLAGS.put(Material.STRIPPED_BAMBOO_BLOCK, 0); + MATERIAL_FLAGS.put(Material.SUSPICIOUS_SAND, 0); + MATERIAL_FLAGS.put(Material.SUSPICIOUS_GRAVEL, 0); + MATERIAL_FLAGS.put(Material.PITCHER_PLANT, 0); + MATERIAL_FLAGS.put(Material.CHISELED_BOOKSHELF, MODIFIED_ON_RIGHT); + MATERIAL_FLAGS.put(Material.DECORATED_POT, MODIFIED_ON_RIGHT); + MATERIAL_FLAGS.put(Material.BRUSH, 0); + MATERIAL_FLAGS.put(Material.SNIFFER_EGG, 0); + MATERIAL_FLAGS.put(Material.CALIBRATED_SCULK_SENSOR, 0); + MATERIAL_FLAGS.put(Material.PIGLIN_HEAD, 0); + MATERIAL_FLAGS.put(Material.PIGLIN_WALL_HEAD, 0); + MATERIAL_FLAGS.put(Material.TORCHFLOWER_SEEDS, 0); + MATERIAL_FLAGS.put(Material.TORCHFLOWER_CROP, 0); + MATERIAL_FLAGS.put(Material.PITCHER_CROP, 0); + MATERIAL_FLAGS.put(Material.PINK_PETALS, 0); + MATERIAL_FLAGS.put(Material.PITCHER_POD, 0); + MATERIAL_FLAGS.put(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE, 0); } catch (NoSuchFieldError ignored) { - SIGNS_TAG = Tag.SIGNS; } // Generated via tag @@ -868,6 +883,12 @@ private static void putMaterialTag(Tag tag, Integer value) { putMaterialTag(Tag.CANDLES, MODIFIED_ON_RIGHT); putMaterialTag(Tag.CANDLE_CAKES, MODIFIED_ON_RIGHT); putMaterialTag(Tag.CAULDRONS, MODIFIED_ON_RIGHT); + try { + // 1.20 + putMaterialTag(Tag.ITEMS_TRIM_TEMPLATES, 0); + putMaterialTag(Tag.ITEMS_DECORATED_POT_SHERDS, 0); + } catch (NoSuchFieldError ignored) { + } Stream.concat(Stream.concat( Tag.CORAL_BLOCKS.getValues().stream(), @@ -882,7 +903,6 @@ private static void putMaterialTag(Tag tag, Integer value) { // Check for missing items/blocks for (Material material : Material.values()) { - //noinspection deprecation if (material.isLegacy()) continue; // Add spawn eggs if (isSpawnEgg(material)) { @@ -1113,6 +1133,7 @@ public static boolean isInventoryBlock(Material material) { || material == Material.BARREL || material == Material.BLAST_FURNACE || material == Material.SMOKER + || material == Material.CHISELED_BOOKSHELF || Tag.ITEMS_CHEST_BOATS.isTagged(material) || Tag.SHULKER_BOXES.isTagged(material); } @@ -1176,6 +1197,7 @@ public static EntityType getEntitySpawnEgg(Material material) { case SKELETON_HORSE_SPAWN_EGG -> EntityType.SKELETON_HORSE; case SKELETON_SPAWN_EGG -> EntityType.SKELETON; case SLIME_SPAWN_EGG -> EntityType.SLIME; + case SNIFFER_SPAWN_EGG -> EntityType.SNIFFER; case SNOW_GOLEM_SPAWN_EGG -> EntityType.SNOWMAN; case SQUID_SPAWN_EGG -> EntityType.SQUID; case STRAY_SPAWN_EGG -> EntityType.STRAY; @@ -1435,7 +1457,12 @@ public static boolean isToolApplicable(Material toolMaterial, Material targetMat case INK_SAC: return SIGNS_TAG.isTagged(targetMaterial); case HONEYCOMB: - return isUnwaxedCopper(targetMaterial); + return isUnwaxedCopper(targetMaterial) || SIGNS_TAG.isTagged(targetMaterial); + case BRUSH: + return switch (targetMaterial) { + case SUSPICIOUS_GRAVEL, SUSPICIOUS_SAND -> true; + default -> false; + }; default: return false; } diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java b/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java index 55f19de1..df3d5fc1 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java @@ -139,6 +139,8 @@ public abstract class WorldConfiguration { public boolean disablePlayerCropTrampling; public boolean disableCreatureTurtleEggTrampling; public boolean disablePlayerTurtleEggTrampling; + public boolean disableCreatureSnifferEggTrampling; + public boolean disablePlayerSnifferEggTrampling; public boolean preventLightningFire; public Set disallowedLightningBlocks; public boolean disableThunder;