mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-12 17:45:08 +02:00
Move creature spawn prevention to core
This commit is contained in:
@@ -332,11 +332,13 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
return backup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metrics getMetrics()
|
||||
{
|
||||
return metrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetrics(Metrics metrics)
|
||||
{
|
||||
this.metrics = metrics;
|
||||
|
@@ -11,6 +11,7 @@ import lombok.Cleanup;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,12 +6,24 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
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")
|
||||
private Backup backup = new Backup();
|
||||
@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.")
|
||||
private boolean debug = false;
|
||||
@Comment(
|
||||
|
||||
|
||||
{
|
||||
"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.",
|
||||
@@ -28,8 +38,6 @@ public class General implements StorageObject
|
||||
})
|
||||
private String locale;
|
||||
@Comment(
|
||||
|
||||
|
||||
{
|
||||
"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",
|
||||
@@ -37,8 +45,6 @@ public class General implements StorageObject
|
||||
})
|
||||
private int defaultStacksize = -1;
|
||||
@Comment(
|
||||
|
||||
|
||||
{
|
||||
"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.",
|
||||
@@ -52,8 +58,6 @@ public class General implements StorageObject
|
||||
FILE, GROUPMANAGER, VAULT
|
||||
}
|
||||
@Comment(
|
||||
|
||||
|
||||
{
|
||||
"Sets the place where group options should be stored:",
|
||||
" 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;
|
||||
@Comment(
|
||||
|
||||
{
|
||||
"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"
|
||||
@@ -73,7 +76,6 @@ public class General implements StorageObject
|
||||
{
|
||||
return teleportInvulnerability * 1000;
|
||||
}
|
||||
|
||||
@Comment(
|
||||
{
|
||||
"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 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 ")
|
||||
private long loginAttackDelay = 0;
|
||||
|
||||
@@ -103,4 +91,21 @@ public class General implements StorageObject
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -39,19 +39,9 @@ public class Prevent implements StorageObject
|
||||
"permission essentials.protect.entitytarget.bypass disables this"
|
||||
})
|
||||
private boolean entitytarget = false;
|
||||
@MapKeyType(EntityType.class)
|
||||
@MapValueType(Boolean.class)
|
||||
private Map<EntityType, Boolean> spawn = new HashMap<EntityType, Boolean>();
|
||||
|
||||
public Prevent()
|
||||
{
|
||||
for (EntityType t : EntityType.values())
|
||||
{
|
||||
if (t.isAlive())
|
||||
{
|
||||
spawn.put(t, false);
|
||||
}
|
||||
}
|
||||
pistonPush.add(Material.GLASS);
|
||||
}
|
||||
}
|
@@ -925,4 +925,10 @@ public class FakeServer implements Server
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMotd()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package net.ess3.protect;
|
||||
|
||||
import net.ess3.api.ISettings;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
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)
|
||||
public void onEntityTarget(final EntityTargetEvent event)
|
||||
|
Reference in New Issue
Block a user