mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 15:08:18 +01:00
Fix NPE where players trigger creature spawn
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1052 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
6416041d22
commit
fb80869961
@ -49,8 +49,6 @@ public class EssentialsProtect extends JavaPlugin
|
|||||||
blockListener = new EssentialsProtectBlockListener(this);
|
blockListener = new EssentialsProtectBlockListener(this);
|
||||||
entityListener = new EssentialsProtectEntityListener(this);
|
entityListener = new EssentialsProtectEntityListener(this);
|
||||||
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, 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_PLACE, blockListener, Priority.Highest, this);
|
||||||
pm.registerEvent(Type.BLOCK_FROMTO, blockListener, Priority.Highest, this);
|
pm.registerEvent(Type.BLOCK_FROMTO, blockListener, Priority.Highest, this);
|
||||||
pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this);
|
pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this);
|
||||||
|
@ -10,6 +10,7 @@ import net.minecraft.server.Packet60Explosion;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Creeper;
|
import org.bukkit.entity.Creeper;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
@ -144,16 +145,18 @@ public class EssentialsProtectEntityListener extends EntityListener
|
|||||||
{
|
{
|
||||||
//Nicccccccccce plaaacccccccccce..
|
//Nicccccccccce plaaacccccccccce..
|
||||||
int maxHeight = Essentials.getSettings().getEpCreeperMaxHeight();
|
int maxHeight = Essentials.getSettings().getEpCreeperMaxHeight();
|
||||||
if ( EssentialsProtect.guardSettings.get("protect.prevent.creeper-explosion") ||
|
if (EssentialsProtect.guardSettings.get("protect.prevent.creeper-explosion")
|
||||||
EssentialsProtect.guardSettings.get("protect.prevent.creeper-blockdamage") ||
|
|| EssentialsProtect.guardSettings.get("protect.prevent.creeper-blockdamage")
|
||||||
(maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))
|
|| (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))
|
||||||
{
|
{
|
||||||
HashSet<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size());
|
HashSet<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size());
|
||||||
Player[] players = parent.getServer().getOnlinePlayers();
|
Player[] players = parent.getServer().getOnlinePlayers();
|
||||||
List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length);
|
List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length);
|
||||||
Location loc = event.getLocation();
|
Location loc = event.getLocation();
|
||||||
for (Player player : players) {
|
for (Player player : players)
|
||||||
if (player.getWorld().equals(loc.getWorld())) {
|
{
|
||||||
|
if (player.getWorld().equals(loc.getWorld()))
|
||||||
|
{
|
||||||
blocksUnderPlayers.add(
|
blocksUnderPlayers.add(
|
||||||
new ChunkPosition(
|
new ChunkPosition(
|
||||||
player.getLocation().getBlockX(),
|
player.getLocation().getBlockX(),
|
||||||
@ -161,9 +164,11 @@ public class EssentialsProtectEntityListener extends EntityListener
|
|||||||
player.getLocation().getBlockZ()));
|
player.getLocation().getBlockZ()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Block block : event.blockList()) {
|
for (Block block : event.blockList())
|
||||||
|
{
|
||||||
ChunkPosition cp = new ChunkPosition(block.getX(), block.getY(), block.getZ());
|
ChunkPosition cp = new ChunkPosition(block.getX(), block.getY(), block.getZ());
|
||||||
if (!blocksUnderPlayers.contains(cp)) {
|
if (!blocksUnderPlayers.contains(cp))
|
||||||
|
{
|
||||||
set.add(cp);
|
set.add(cp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,12 +190,17 @@ public class EssentialsProtectEntityListener extends EntityListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
String creatureName = event.getCreatureType().toString().toLowerCase();
|
||||||
if (creatureName == null || creatureName.isEmpty()) {
|
if (creatureName == null || creatureName.isEmpty())
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (EssentialsProtect.guardSettings.get("protect.prevent.spawn."+creatureName)) {
|
if (EssentialsProtect.guardSettings.get("protect.prevent.spawn." + creatureName))
|
||||||
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user