Added Flags#LEAF_DECAY

This commit is contained in:
Florian CUNY 2019-02-24 17:49:07 +01:00
parent 7da7dd4884
commit b5a657de52
3 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package world.bentobox.bentobox.listeners.flags.settings;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.LeavesDecayEvent;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import java.util.Optional;
/**
* Handles {@link world.bentobox.bentobox.lists.Flags#LEAF_DECAY}.
* @author Poslovitch
* @since 1.4.0
*/
public class DecayListener extends FlagListener {
/**
* Prevents leaves from decaying.
* @param e event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onLeavesDecay(LeavesDecayEvent e) {
if (!getIWM().inWorld(e.getBlock().getLocation())) {
return;
}
Optional<Island> island = getIslands().getIslandAt(e.getBlock().getLocation());
// Cancel the event if needed - this means if this is not allowed on the island or in the world.
e.setCancelled(island.map(i -> !i.isAllowed(Flags.LEAF_DECAY)).orElse(!Flags.LEAF_DECAY.isSetForWorld(e.getBlock().getWorld())));
}
}

View File

@ -32,6 +32,7 @@ import world.bentobox.bentobox.listeners.flags.protection.ShearingListener;
import world.bentobox.bentobox.listeners.flags.protection.TNTListener;
import world.bentobox.bentobox.listeners.flags.protection.TeleportationListener;
import world.bentobox.bentobox.listeners.flags.protection.ThrowingListener;
import world.bentobox.bentobox.listeners.flags.settings.DecayListener;
import world.bentobox.bentobox.listeners.flags.settings.MobSpawnListener;
import world.bentobox.bentobox.listeners.flags.settings.PVPListener;
import world.bentobox.bentobox.listeners.flags.worldsettings.ChestDamageListener;
@ -263,6 +264,13 @@ public final class Flags {
.listener(new MobSpawnListener()).build();
public static final Flag MONSTER_SPAWN = new Flag.Builder("MONSTER_SPAWN", Material.SPAWNER).defaultSetting(true).type(Type.SETTING).build();
/**
* If {@code false}, prevents leaves from disappearing.
* @since 1.4.0
* @see DecayListener
*/
public static final Flag LEAF_DECAY = new Flag.Builder("LEAF_DECAY", Material.OAK_LEAVES).type(Type.SETTING).listener(new DecayListener()).defaultSetting(true).build();
/*
* World Settings - they apply to every island in the game worlds.
*/

View File

@ -693,6 +693,9 @@ protection:
description: "Toggle usage"
name: "Jukebox use"
hint: "No jukebox use allowed"
LEAF_DECAY:
name: "Leaf decay"
description: "Allow leaves to naturally decay"
LEASH:
description: "Toggle use"
name: "Leash use"