Made /stoplag handle TNT removal better.

This commit is contained in:
sk89q 2011-06-29 16:15:56 -07:00
parent d90b960597
commit bed6782a00
5 changed files with 20 additions and 14 deletions

View File

@ -24,7 +24,7 @@
import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.blocks.BlockType;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
@ -219,4 +219,18 @@ public static String replaceColorMacros(String str) {
return str; return str;
} }
/**
* Returns whether an entity should be removed for the halt activity mode.
*
* @param entity
* @return
*/
public static boolean isIntensiveEntity(Entity entity) {
return entity instanceof Item
|| entity instanceof TNTPrimed
|| (entity instanceof LivingEntity
&& !(entity instanceof Tameable)
&& !(entity instanceof Player));
}
} }

View File

@ -486,6 +486,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
} }
} else if (ent instanceof TNTPrimed) { } else if (ent instanceof TNTPrimed) {
if (cfg.activityHaltToggle) { if (cfg.activityHaltToggle) {
ent.remove();
event.setCancelled(true); event.setCancelled(true);
return; return;
} }

View File

@ -23,7 +23,6 @@
import java.util.Set; import java.util.Set;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag; import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -145,10 +144,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
int removed = 0; int removed = 0;
for (Entity entity : player.getWorld().getEntities()) { for (Entity entity : player.getWorld().getEntities()) {
if (entity instanceof Item if (BukkitUtil.isIntensiveEntity(entity)) {
|| (entity instanceof LivingEntity
&& !(entity instanceof Tameable)
&& !(entity instanceof Player))) {
entity.remove(); entity.remove();
removed++; removed++;
} }

View File

@ -66,10 +66,7 @@ public void onChunkLoad(ChunkLoadEvent event) {
int removed = 0; int removed = 0;
for (Entity entity : event.getChunk().getEntities()) { for (Entity entity : event.getChunk().getEntities()) {
if (entity instanceof Item if (BukkitUtil.isIntensiveEntity(entity)) {
|| (entity instanceof LivingEntity
&& !(entity instanceof Tameable)
&& !(entity instanceof Player))) {
entity.remove(); entity.remove();
removed++; removed++;
} }

View File

@ -19,6 +19,7 @@
package com.sk89q.worldguard.bukkit.commands; package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.ConfigurationManager; import com.sk89q.worldguard.bukkit.ConfigurationManager;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
@ -115,10 +116,7 @@ public static void stopLag(CommandContext args, WorldGuardPlugin plugin,
int removed = 0; int removed = 0;
for (Entity entity : world.getEntities()) { for (Entity entity : world.getEntities()) {
if (entity instanceof Item if (BukkitUtil.isIntensiveEntity(entity)) {
|| (entity instanceof LivingEntity
&& !(entity instanceof Tameable)
&& !(entity instanceof Player))) {
entity.remove(); entity.remove();
removed++; removed++;
} }