summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect/src/com/earth2me/essentials
diff options
context:
space:
mode:
authorementalo <ementalo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-03-31 22:20:53 +0000
committerementalo <ementalo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-03-31 22:20:53 +0000
commitfb8086996112b8eeec916ad8070513dcc198aaf6 (patch)
tree55ef0f63c5cd4fd8d318a292c65923486196820e /EssentialsProtect/src/com/earth2me/essentials
parent6416041d2233da8c6fc4a9ca0ffb738f2cbbfa08 (diff)
downloadEssentials-fb8086996112b8eeec916ad8070513dcc198aaf6.tar
Essentials-fb8086996112b8eeec916ad8070513dcc198aaf6.tar.gz
Essentials-fb8086996112b8eeec916ad8070513dcc198aaf6.tar.lz
Essentials-fb8086996112b8eeec916ad8070513dcc198aaf6.tar.xz
Essentials-fb8086996112b8eeec916ad8070513dcc198aaf6.zip
Fix NPE where players trigger creature spawn
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1052 e251c2fe-e539-e718-e476-b85c1f46cddb
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java2
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java40
2 files changed, 25 insertions, 17 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
index 798153b1c..ec93acc2c 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
@@ -49,8 +49,6 @@ public class EssentialsProtect extends JavaPlugin
blockListener = new EssentialsProtectBlockListener(this);
entityListener = new EssentialsProtectEntityListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this);
- // Why is this commented?
- //pm.registerEvent(Type.BLOCK_DAMAGED, blockListener, Priority.High, this);
pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_FROMTO, blockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this);
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
index 97b5c59e5..cad4389d6 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
@@ -10,6 +10,7 @@ import net.minecraft.server.Packet60Explosion;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@@ -89,7 +90,7 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true);
return;
}
-
+
if (eAttack instanceof Creeper && EssentialsProtect.guardSettings.get("protect.prevent.creeper-playerdamage"))
{
event.setCancelled(true);
@@ -144,32 +145,36 @@ public class EssentialsProtectEntityListener extends EntityListener
{
//Nicccccccccce plaaacccccccccce..
int maxHeight = Essentials.getSettings().getEpCreeperMaxHeight();
- if ( EssentialsProtect.guardSettings.get("protect.prevent.creeper-explosion") ||
- EssentialsProtect.guardSettings.get("protect.prevent.creeper-blockdamage") ||
- (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))
+ if (EssentialsProtect.guardSettings.get("protect.prevent.creeper-explosion")
+ || EssentialsProtect.guardSettings.get("protect.prevent.creeper-blockdamage")
+ || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))
{
HashSet<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size());
Player[] players = parent.getServer().getOnlinePlayers();
List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length);
Location loc = event.getLocation();
- for (Player player : players) {
- if (player.getWorld().equals(loc.getWorld())) {
+ for (Player player : players)
+ {
+ if (player.getWorld().equals(loc.getWorld()))
+ {
blocksUnderPlayers.add(
- new ChunkPosition(
+ new ChunkPosition(
player.getLocation().getBlockX(),
player.getLocation().getBlockY() - 1,
player.getLocation().getBlockZ()));
}
}
- for (Block block : event.blockList()) {
+ for (Block block : event.blockList())
+ {
ChunkPosition cp = new ChunkPosition(block.getX(), block.getY(), block.getZ());
- if (!blocksUnderPlayers.contains(cp)) {
+ if (!blocksUnderPlayers.contains(cp))
+ {
set.add(cp);
}
}
-
- ((CraftServer)parent.getServer()).getServer().f.a(loc.getX(), loc.getY(), loc.getZ(), 64.0D,
- new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set));
+
+ ((CraftServer)parent.getServer()).getServer().f.a(loc.getX(), loc.getY(), loc.getZ(), 64.0D,
+ new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set));
event.setCancelled(true);
return;
}
@@ -185,12 +190,17 @@ public class EssentialsProtectEntityListener extends EntityListener
}
@Override
- public void onCreatureSpawn(CreatureSpawnEvent event) {
+ public void onCreatureSpawn(CreatureSpawnEvent event)
+ {
+ if (event.getEntity() instanceof CraftPlayer) return;
+ if (event.isCancelled()) return;
String creatureName = event.getCreatureType().toString().toLowerCase();
- if (creatureName == null || creatureName.isEmpty()) {
+ if (creatureName == null || creatureName.isEmpty())
+ {
return;
}
- if (EssentialsProtect.guardSettings.get("protect.prevent.spawn."+creatureName)) {
+ if (EssentialsProtect.guardSettings.get("protect.prevent.spawn." + creatureName))
+ {
event.setCancelled(true);
}
}