Added Flags#NATURAL_SPAWNING_OUTSIDE_RANGE

#513
This commit is contained in:
Florian CUNY 2019-02-10 13:14:24 +01:00
parent 7a43c0b792
commit 82e7093fbc
3 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package world.bentobox.bentobox.listeners.flags.worldsettings;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.CreatureSpawnEvent;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;
/**
* Handles {@link world.bentobox.bentobox.lists.Flags#NATURAL_SPAWNING_OUTSIDE_RANGE}.
*
* @author Poslovitch
* @since 1.3.0
*/
public class NaturalSpawningOutsideRangeListener extends FlagListener {
@EventHandler(priority = EventPriority.LOWEST)
public void onCreatureSpawn(CreatureSpawnEvent e) {
if (!getIWM().inWorld(e.getLocation()) || Flags.NATURAL_SPAWNING_OUTSIDE_RANGE.isSetForWorld(e.getLocation().getWorld())) {
// We do not want to run any check if this is not the right world or if it is allowed.
return;
}
// If it is a natural spawn and there is no protected island at the location, block the spawn.
if (e.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL && !getIslands().getProtectedIslandAt(e.getLocation()).isPresent()) {
e.setCancelled(true);
}
}
}

View File

@ -46,6 +46,7 @@ import world.bentobox.bentobox.listeners.flags.worldsettings.InvincibleVisitorsL
import world.bentobox.bentobox.listeners.flags.worldsettings.IslandRespawnListener;
import world.bentobox.bentobox.listeners.flags.worldsettings.ItemFrameListener;
import world.bentobox.bentobox.listeners.flags.worldsettings.LiquidsFlowingOutListener;
import world.bentobox.bentobox.listeners.flags.worldsettings.NaturalSpawningOutsideRangeListener;
import world.bentobox.bentobox.listeners.flags.worldsettings.ObsidianScoopingListener;
import world.bentobox.bentobox.listeners.flags.worldsettings.OfflineRedstoneListener;
import world.bentobox.bentobox.listeners.flags.worldsettings.PistonPushListener;
@ -306,6 +307,15 @@ public final class Flags {
*/
public static final Flag TREES_GROWING_OUTSIDE_RANGE = new Flag.Builder("TREES_GROWING_OUTSIDE_RANGE", Material.OAK_SAPLING).type(Type.WORLD_SETTING).listener(new TreesGrowingOutsideRangeListener()).build();
/**
* Toggles whether monsters and animals can spawn naturally outside an island's protection range or not.
* It is allowed by default.
*
* @since 1.3.0
* @see NaturalSpawningOutsideRangeListener
*/
public static final Flag NATURAL_SPAWNING_OUTSIDE_RANGE = new Flag.Builder("NATURAL_SPAWNING_OUTSIDE_RANGE", Material.ZOMBIE_SPAWN_EGG).type(Type.WORLD_SETTING).listener(new NaturalSpawningOutsideRangeListener()).defaultSetting(true).build();
/**
* Provides a list of all the Flag instances contained in this class using reflection.
* @return List of all the flags in this class

View File

@ -687,6 +687,16 @@ protection:
name: "Name tags"
description: "Toggle use"
hint: "No name tags use"
NATURAL_SPAWNING_OUTSIDE_RANGE:
name: "Natural creature spawning outside range"
description: |-
&aToggle whether creatures (animals and
&amonsters) can spawn naturally outside
&aan island's protection range.
&cNote that it doesn't prevent creatures
&cto spawn via a mob spawner or a spawn
&cegg.
NOTE_BLOCK:
description: "Toggle use"
name: "Note block"