Added /stoplag or /halt-activity to cease all intensive operations (such as fire spread, water flow, mob spawning, etc.) and to remove mobs (except wolves) and item drops proactively for those situations when you (or someone else) messes up really badly.

This commit is contained in:
sk89q 2011-06-20 19:23:03 -07:00
parent 6496bbd87f
commit c9f99e0903
8 changed files with 224 additions and 4 deletions

View File

@ -60,6 +60,7 @@ public class ConfigurationManager {
public boolean suppressTickSyncWarnings;
public boolean useRegionsScheduler;
public boolean activityHaltToggle = false;
/**
* Construct the object.

View File

@ -74,6 +74,8 @@ public void registerEvents() {
pm.registerEvent(Event.Type.REDSTONE_CHANGE, this, Priority.High, plugin);
pm.registerEvent(Event.Type.SNOW_FORM, this, Priority.High, plugin);
pm.registerEvent(Event.Type.LEAVES_DECAY, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_FORM, this, Priority.High, plugin);
pm.registerEvent(Event.Type.BLOCK_SPREAD, this, Priority.High, plugin);
}
/**
@ -191,6 +193,11 @@ public void onBlockFromTo(BlockFromToEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
if (wcfg.simulateSponge && isWater) {
int ox = blockTo.getX();
int oy = blockTo.getY();
@ -273,6 +280,11 @@ public void onBlockIgnite(BlockIgniteEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
boolean isFireSpread = cause == IgniteCause.SPREAD;
if (wcfg.preventLightningFire && cause == IgniteCause.LIGHTNING) {
@ -367,6 +379,11 @@ public void onBlockBurn(BlockBurnEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
if (wcfg.disableFireSpread) {
event.setCancelled(true);
return;
@ -418,6 +435,11 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
int id = event.getChangedTypeId();
if (id == 13 && wcfg.noPhysicsGravel) {
@ -600,6 +622,13 @@ public void onSnowForm(SnowFormEvent event) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.SNOW_FALL,
event.getBlock().getLocation())) {
event.setCancelled(true);
@ -612,8 +641,39 @@ public void onLeavesDecay(LeavesDecayEvent event) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
if (!plugin.getGlobalRegionManager().allows(DefaultFlag.LEAF_DECAY, event.getBlock().getLocation())) {
event.setCancelled(true);
}
}
/**
* Called when a block is formed based on world conditions.
*/
public void onBlockForm(BlockFormEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
}
/**
* Called when a block spreads based on world conditions.
*/
public void onBlockSpread(BlockSpreadEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
}
}

View File

@ -426,6 +426,11 @@ public void onEntityExplode(EntityExplodeEvent event) {
}
}
} else if (ent instanceof TNTPrimed) {
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
if (wcfg.blockTNT) {
event.setCancelled(true);
return;
@ -462,6 +467,12 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
if (cfg.activityHaltToggle) {
event.setCancelled(true);
return;
}
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
//CreatureType creaType = (CreatureType) CreatureType.valueOf(event.getMobType().toString());

View File

@ -20,13 +20,14 @@
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.util.Iterator;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.entity.*;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Result;
@ -49,6 +50,11 @@
*/
public class WorldGuardPlayerListener extends PlayerListener {
/**
* Logger for messages.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
private WorldGuardPlugin plugin;
/**
@ -111,6 +117,26 @@ public void onPlayerJoin(PlayerJoinEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(player.getWorld());
if (cfg.activityHaltToggle) {
player.sendMessage(ChatColor.YELLOW
+ "Intensive server activity has been HALTED.");
int removed = 0;
for (Entity entity : player.getWorld().getEntities()) {
if (entity instanceof Item
|| (entity instanceof LivingEntity && !(entity instanceof Tameable))) {
entity.remove();
removed++;
}
}
if (removed > 10) {
logger.info("WG Halt-Act: " + removed + " entities (>10) auto-removed from "
+ player.getWorld().toString());
}
}
if (wcfg.fireSpreadDisableToggle) {
player.sendMessage(ChatColor.YELLOW
+ "Fire spread is currently globally disabled for this world.");
@ -241,7 +267,7 @@ public void onPlayerMove(PlayerMoveEvent event) {
}
}
}
/**
* Called when a player left clicks air.
*
@ -291,7 +317,7 @@ private void handleBlockLeftClick(PlayerInteractEvent event) {
}
}
/**
/**
* Called when a player right clicks air.
*
* @param event

View File

@ -138,6 +138,7 @@ public void onEnable() {
(new WorldGuardBlockListener(this)).registerEvents();
(new WorldGuardEntityListener(this)).registerEvents();
(new WorldGuardWeatherListener(this)).registerEvents();
(new WorldGuardWorldListener(this)).registerEvents();
flagStateManager = new FlagStateManager(this);

View File

@ -0,0 +1,66 @@
// $Id$
/*
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
* All rights reserved.
*/
package com.sk89q.worldguard.bukkit;
import org.bukkit.entity.*;
import org.bukkit.event.Event;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.WorldListener;
import org.bukkit.plugin.PluginManager;
import java.util.logging.Logger;
public class WorldGuardWorldListener extends WorldListener {
/**
* Logger for messages.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
private WorldGuardPlugin plugin;
/**
* Construct the object;
*
* @param plugin
*/
public WorldGuardWorldListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
/**
* Register events.
*/
public void registerEvents() {
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.CHUNK_LOAD, this, Event.Priority.Normal, plugin);
}
/**
* Called when a chunk is loaded.
*/
public void onChunkLoad(ChunkLoadEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
if (cfg.activityHaltToggle) {
int removed = 0;
for (Entity entity : event.getChunk().getEntities()) {
if (entity instanceof Item
|| (entity instanceof LivingEntity && !(entity instanceof Tameable))) {
entity.remove();
removed++;
}
}
if (removed > 50) {
logger.info("WG Halt-Act: " + removed + " entities (>50) auto-removed from "
+ event.getChunk().toString());
}
}
}
}

View File

@ -19,12 +19,14 @@
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.entity.*;
public class ToggleCommands {
@ -87,4 +89,53 @@ public static void allowFire(CommandContext args, WorldGuardPlugin plugin,
wcfg.fireSpreadDisableToggle = false;
}
@Command(aliases = {"halt-activity"},
usage = "", desc = "Attempts to cease as much activity in order to stop lag",
flags = "c", min = 0, max = 0)
@CommandPermissions({"worldguard.halt-activity"})
public static void stopLag(CommandContext args, WorldGuardPlugin plugin,
CommandSender sender) throws CommandException {
ConfigurationManager configManager = plugin.getGlobalStateManager();
configManager.activityHaltToggle = !args.hasFlag('c');
if (configManager.activityHaltToggle) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.YELLOW
+ "ALL intensive server activity halted.");
}
plugin.getServer().broadcastMessage(ChatColor.YELLOW
+ "ALL intensive server activity halted by "
+ plugin.toName(sender) + ".");
for (World world : plugin.getServer().getWorlds()) {
int removed = 0;
for (Entity entity : world.getEntities()) {
if (entity instanceof Item
|| (entity instanceof LivingEntity && !(entity instanceof Tameable))) {
entity.remove();
removed++;
}
}
if (removed > 10) {
sender.sendMessage("" + removed + " entities (>10) auto-removed from "
+ world.toString());
}
}
} else {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.YELLOW
+ "ALL intensive server activity no longer halted.");
}
plugin.getServer().broadcastMessage(ChatColor.YELLOW
+ "ALL intensive server activity is now allowed.");
}
}
}

View File

@ -8,6 +8,10 @@ commands:
allowfire:
description: Re-enables fire spread if he has been disabled with /stopfire
usage: /<command>
halt-activity:
aliases: [stoplag, haltactivity]
description: Attempts to stop all intensive operations (toggle)
usage: /<command> [-c]
god:
description: Enable god mode
usage: /<command> [player]