Update Protections to 1.20

* add new materials
* add protections for sniffer eggs
* add protection for signs
This commit is contained in:
Joo200 2023-06-08 21:38:37 +02:00
parent 2f0d211b20
commit 5e81f3cb53
6 changed files with 47 additions and 8 deletions

View File

@ -256,6 +256,8 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
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);

View File

@ -454,7 +454,9 @@ public class EventAbstractionListener extends AbstractListener {
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 class EventAbstractionListener extends AbstractListener {
@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));
}
}

View File

@ -120,6 +120,10 @@ public class WorldGuardEntityListener extends AbstractListener {
event.setCancelled(true);
return;
}
if (block.getType() == Material.SNIFFER_EGG && wcfg.disableCreatureSnifferEggTrampling) {
event.setCancelled(true);
return;
}
}
@EventHandler(priority = EventPriority.HIGH)

View File

@ -307,6 +307,10 @@ public class WorldGuardPlayerListener extends AbstractListener {
event.setCancelled(true);
return;
}
if (type == Material.SNIFFER_EGG && wcfg.disablePlayerSnifferEggTrampling) {
event.setCancelled(true);
return;
}
}
@EventHandler(priority = EventPriority.HIGHEST)

View File

@ -820,15 +820,30 @@ public final class Materials {
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 @@ public final class Materials {
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 @@ public final class Materials {
// 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 final class Materials {
|| 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 final class Materials {
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 final class Materials {
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;
}

View File

@ -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<String> disallowedLightningBlocks;
public boolean disableThunder;