1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-13 18:14:38 +02:00

Move creature spawn prevention to core

This commit is contained in:
ementalo
2012-07-06 15:57:54 +01:00
parent 30600295a6
commit 06e6749ca3
6 changed files with 71 additions and 64 deletions

View File

@@ -332,11 +332,13 @@ public class Essentials extends JavaPlugin implements IEssentials
return backup; return backup;
} }
@Override
public Metrics getMetrics() public Metrics getMetrics()
{ {
return metrics; return metrics;
} }
@Override
public void setMetrics(Metrics metrics) public void setMetrics(Metrics metrics)
{ {
this.metrics = metrics; this.metrics = metrics;

View File

@@ -11,6 +11,7 @@ import lombok.Cleanup;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Ageable; import org.bukkit.entity.Ageable;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@@ -172,4 +173,32 @@ public class EssentialsEntityListener implements Listener
} }
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCreatureSpawn(final CreatureSpawnEvent event)
{
if (event.getEntity().getType() == EntityType.PLAYER)
{
return;
}
final EntityType creature = event.getEntityType();
if (creature == null)
{
return;
}
final ISettings settings = ess.getSettings();
settings.acquireReadLock();
try
{
final Boolean prevent = settings.getData().getGeneral().getPreventSpawn(creature);
if (prevent != null && prevent)
{
event.setCancelled(true);
}
}
finally
{
settings.unlock();
}
}
} }

View File

@@ -6,12 +6,24 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.bukkit.entity.EntityType;
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class General implements StorageObject public class General implements StorageObject
{ {
public General()
{
//Populate creature spawn values
for (EntityType t : EntityType.values())
{
if (t.isAlive())
{
creatureSpawn.put(t, false);
}
}
}
@Comment("Backup runs a command while saving is disabled") @Comment("Backup runs a command while saving is disabled")
private Backup backup = new Backup(); private Backup backup = new Backup();
@Comment("You can disable the death messages of minecraft.") @Comment("You can disable the death messages of minecraft.")
@@ -19,8 +31,6 @@ public class General implements StorageObject
@Comment("Turn this on, if you want to see more error messages, if something goes wrong.") @Comment("Turn this on, if you want to see more error messages, if something goes wrong.")
private boolean debug = false; private boolean debug = false;
@Comment( @Comment(
{ {
"Set the locale here, if you want to change the language of Essentials.", "Set the locale here, if you want to change the language of Essentials.",
"If this is not set, Essentials will use the language of your computer.", "If this is not set, Essentials will use the language of your computer.",
@@ -28,8 +38,6 @@ public class General implements StorageObject
}) })
private String locale; private String locale;
@Comment( @Comment(
{ {
"The number of items given, if the quantity parameter is left out in /item or /give.", "The number of items given, if the quantity parameter is left out in /item or /give.",
"If this number is below 1, the maximum stack size size is given. If oversized stacks", "If this number is below 1, the maximum stack size size is given. If oversized stacks",
@@ -37,8 +45,6 @@ public class General implements StorageObject
}) })
private int defaultStacksize = -1; private int defaultStacksize = -1;
@Comment( @Comment(
{ {
"Oversized stacks are stacks that ignore the normal max stacksize.", "Oversized stacks are stacks that ignore the normal max stacksize.",
"They can be obtained using /give and /item, if the player has essentials.oversizedstacks permission.", "They can be obtained using /give and /item, if the player has essentials.oversizedstacks permission.",
@@ -52,8 +58,6 @@ public class General implements StorageObject
FILE, GROUPMANAGER, VAULT FILE, GROUPMANAGER, VAULT
} }
@Comment( @Comment(
{ {
"Sets the place where group options should be stored:", "Sets the place where group options should be stored:",
" FILE: Options are stored inside groups.yml in the Essentials folder", " FILE: Options are stored inside groups.yml in the Essentials folder",
@@ -62,7 +66,6 @@ public class General implements StorageObject
}) })
private GroupStorage groupStorage = GroupStorage.FILE; private GroupStorage groupStorage = GroupStorage.FILE;
@Comment( @Comment(
{ {
"The delay, in seconds, a player can't be attacked by other players after he has been teleported by a command", "The delay, in seconds, a player can't be attacked by other players after he has been teleported by a command",
"This will also prevent that the player can attack other players" "This will also prevent that the player can attack other players"
@@ -73,7 +76,6 @@ public class General implements StorageObject
{ {
return teleportInvulnerability * 1000; return teleportInvulnerability * 1000;
} }
@Comment( @Comment(
{ {
"Set to true to enable per-world permissions for teleporting between worlds with essentials commands", "Set to true to enable per-world permissions for teleporting between worlds with essentials commands",
@@ -82,20 +84,6 @@ public class General implements StorageObject
}) })
private boolean worldTeleportPermissions = false; private boolean worldTeleportPermissions = false;
private boolean worldHomePermissions = false; private boolean worldHomePermissions = false;
@Comment("Prevent creatures spawning")
private Map<String, Boolean> creatureSpawn = new HashMap<String, Boolean>();
public boolean getPreventSpawn(String creatureName)
{
if (creatureSpawn == null)
{
return false;
}
return creatureSpawn.get(creatureName);
}
@Comment("Delay to wait before people can cause attack damage after logging in ") @Comment("Delay to wait before people can cause attack damage after logging in ")
private long loginAttackDelay = 0; private long loginAttackDelay = 0;
@@ -103,4 +91,21 @@ public class General implements StorageObject
{ {
return loginAttackDelay * 1000; return loginAttackDelay * 1000;
} }
public boolean metricsEnabled = true;
@Comment("Prevent creatures spawning")
private Map<EntityType, Boolean> creatureSpawn = new HashMap<EntityType, Boolean>();
public boolean getPreventSpawn(String creatureName)
{
return getPreventSpawn(EntityType.fromName(creatureName));
}
public boolean getPreventSpawn(EntityType creature)
{
if (creatureSpawn == null)
{
return false;
}
return creatureSpawn.get(creature);
}
} }

View File

@@ -39,19 +39,9 @@ public class Prevent implements StorageObject
"permission essentials.protect.entitytarget.bypass disables this" "permission essentials.protect.entitytarget.bypass disables this"
}) })
private boolean entitytarget = false; private boolean entitytarget = false;
@MapKeyType(EntityType.class)
@MapValueType(Boolean.class)
private Map<EntityType, Boolean> spawn = new HashMap<EntityType, Boolean>();
public Prevent() public Prevent()
{ {
for (EntityType t : EntityType.values())
{
if (t.isAlive())
{
spawn.put(t, false);
}
}
pistonPush.add(Material.GLASS); pistonPush.add(Material.GLASS);
} }
} }

View File

@@ -925,4 +925,10 @@ public class FakeServer implements Server
{ {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
@Override
public String getMotd()
{
throw new UnsupportedOperationException("Not supported yet.");
}
} }

View File

@@ -1,5 +1,6 @@
package net.ess3.protect; package net.ess3.protect;
import net.ess3.api.ISettings;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@@ -236,33 +237,7 @@ public class EssentialsProtectEntityListener implements Listener
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCreatureSpawn(final CreatureSpawnEvent event)
{
if (event.getEntity().getType() == EntityType.PLAYER)
{
return;
}
final EntityType creature = event.getEntityType();
if (creature == null)
{
return;
}
final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock();
try
{
final Boolean prevent = settings.getData().getPrevent().getSpawn().get(creature);
if (prevent != null && prevent)
{
event.setCancelled(true);
}
}
finally
{
settings.unlock();
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityTarget(final EntityTargetEvent event) public void onEntityTarget(final EntityTargetEvent event)