Added world option to block turtle egg trampling

This commit is contained in:
JOO200 2020-07-30 19:22:17 +02:00 committed by wizjany
parent f677af566f
commit 3da19a7ff0
4 changed files with 18 additions and 7 deletions

View File

@ -240,6 +240,9 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
disableCreatureCropTrampling = getBoolean("crops.disable-creature-trampling", false);
disablePlayerCropTrampling = getBoolean("crops.disable-player-trampling", false);
disableCreatureTurtleEggTrampling = getBoolean("turtle-egg.disable-crature-trampling", false);
disablePlayerTurtleEggTrampling = getBoolean("turtle-egg.disable-player-trampling", false);
disallowedLightningBlocks = new HashSet<>(convertLegacyBlocks(getStringList("weather.prevent-lightning-strike-blocks", null)));
preventLightningFire = getBoolean("weather.disable-lightning-strike-fire", false);
disableThunder = getBoolean("weather.disable-thunderstorm", false);

View File

@ -121,11 +121,13 @@ public class WorldGuardEntityListener implements Listener {
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld()));
if (block.getType() == Material.FARMLAND) {
if (/* entity instanceof Creature && // catch for any entity (not thrown for players) */
wcfg.disableCreatureCropTrampling) {
event.setCancelled(true);
}
if (block.getType() == Material.FARMLAND && wcfg.disableCreatureCropTrampling) {
event.setCancelled(true);
return;
}
if (block.getType() == Material.TURTLE_EGG && wcfg.disableCreatureTurtleEggTrampling) {
event.setCancelled(true);
return;
}
}

View File

@ -314,13 +314,17 @@ public class WorldGuardPlayerListener implements Listener {
Player player = event.getPlayer();
Block block = event.getClickedBlock(); //not actually clicked but whatever
//int type = block.getTypeId();
Material type = block.getType();
World world = player.getWorld();
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world));
if (block.getType() == Material.FARMLAND && wcfg.disablePlayerCropTrampling) {
if (type == Material.FARMLAND && wcfg.disablePlayerCropTrampling) {
event.setCancelled(true);
return;
}
if (type == Material.TURTLE_EGG && wcfg.disablePlayerTurtleEggTrampling) {
event.setCancelled(true);
return;
}

View File

@ -135,6 +135,8 @@ public abstract class WorldConfiguration {
public boolean removeInfiniteStacks;
public boolean disableCreatureCropTrampling;
public boolean disablePlayerCropTrampling;
public boolean disableCreatureTurtleEggTrampling;
public boolean disablePlayerTurtleEggTrampling;
public boolean preventLightningFire;
public Set<String> disallowedLightningBlocks;
public boolean disableThunder;