Added command blocking.

This commit is contained in:
sk89q 2011-06-26 10:40:08 -07:00
parent 855bc59a53
commit c9178da608
3 changed files with 92 additions and 1 deletions

View File

@ -20,6 +20,7 @@
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
@ -84,6 +85,7 @@ public void registerEvents() {
registerEvent("PLAYER_ITEM_HELD", Priority.High);
registerEvent("PLAYER_BED_ENTER", Priority.High);
registerEvent("PLAYER_MOVE", Priority.High);
registerEvent("PLAYER_COMMAND_PREPROCESS", Priority.High);
}
/**
@ -885,4 +887,30 @@ public void onPlayerBedEnter(PlayerBedEnterEvent event) {
}
}
}
/**
* Called on command run.
*/
@Override
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions) {
Vector pt = toVector(player.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
String[] parts = event.getMessage().split(" ");
Set<String> blockedCommands = set.getFlag(DefaultFlag.BLOCKED_CMDS);
if (blockedCommands != null && blockedCommands.contains(parts[0].toLowerCase())) {
player.sendMessage(ChatColor.RED + parts[0].toLowerCase() + " is blocked in this area.");
event.setCancelled(true);
return;
}
}
}
}

View File

@ -0,0 +1,62 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.protection.flags;
import org.bukkit.command.CommandSender;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
/**
*
* @author sk89q
*/
public class CommandStringFlag extends Flag<String> {
public CommandStringFlag(String name, char legacyCode) {
super(name, legacyCode);
}
public CommandStringFlag(String name) {
super(name);
}
@Override
public String parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat {
input = input.trim();
if (!input.startsWith("/")) {
input = "/" + input;
}
return input.toLowerCase();
}
@Override
public String unmarshal(Object o) {
if (o instanceof String) {
return (String) o;
} else {
return null;
}
}
@Override
public Object marshal(String o) {
return o;
}
}

View File

@ -62,6 +62,7 @@ public final class DefaultFlag {
public static final RegionGroupFlag SPAWN_PERM = new RegionGroupFlag("spawn-group");
public static final BooleanFlag BUYABLE = new BooleanFlag("buyable");
public static final DoubleFlag PRICE = new DoubleFlag("price");
public static final SetFlag<String> BLOCKED_CMDS = new SetFlag<String>("blocked-cmds", new CommandStringFlag(null));
public static final Flag<?>[] flagsList = new Flag<?>[] {
PASSTHROUGH, BUILD, PVP, MOB_DAMAGE, MOB_SPAWNING, CREEPER_EXPLOSION, SLEEP,
@ -69,7 +70,7 @@ public final class DefaultFlag {
USE, PLACE_VEHICLE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER,
NOTIFY_LEAVE, DENY_SPAWN, HEAL_DELAY, HEAL_AMOUNT, TELE_LOC,
TELE_PERM, SPAWN_LOC, SPAWN_PERM, BUYABLE, PRICE, SNOW_FALL, LEAF_DECAY,
GHAST_FIREBALL
GHAST_FIREBALL, BLOCKED_CMDS
};
private DefaultFlag() {