mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-24 03:25:24 +01:00
Updated command handling for Bukkit.
This commit is contained in:
parent
ef7d487ec5
commit
3b5a729ef3
@ -264,7 +264,6 @@ public void onBlockBurn(BlockBurnEvent event) {
|
||||
|
||||
if (plugin.disableFireSpreadBlocks.size() > 0) {
|
||||
Block block = event.getBlock();
|
||||
World world = block.getWorld();
|
||||
|
||||
if (plugin.disableFireSpreadBlocks.contains(block.getTypeId())) {
|
||||
event.setCancelled(true);
|
||||
|
@ -422,28 +422,22 @@ public void postReload() {
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, Command cmd,
|
||||
String commandLabel, String[] args) {
|
||||
if (!sender.isPlayer()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player)sender;
|
||||
|
||||
try {
|
||||
return handleCommand(player, cmd.getName(), args);
|
||||
return handleCommand(sender, cmd.getName(), args);
|
||||
} catch (InsufficientArgumentsException e) {
|
||||
if (e.getHelp() != null) {
|
||||
player.sendMessage(ChatColor.RED + e.getHelp());
|
||||
sender.sendMessage(ChatColor.RED + e.getHelp());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (InsufficientPermissionsException e) {
|
||||
player.sendMessage(ChatColor.RED + "You don't have sufficient permission.");
|
||||
sender.sendMessage(ChatColor.RED + "You don't have sufficient permission.");
|
||||
return true;
|
||||
} catch (CommandHandlingException e) {
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
player.sendMessage(ChatColor.RED + "ERROR: " + t.getMessage());
|
||||
sender.sendMessage(ChatColor.RED + "ERROR: " + t.getMessage());
|
||||
t.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
@ -458,18 +452,20 @@ public boolean onCommand(CommandSender sender, Command cmd,
|
||||
* @return
|
||||
* @throws CommandHandlingException
|
||||
*/
|
||||
private boolean handleCommand(Player player, String cmd, String[] args)
|
||||
private boolean handleCommand(CommandSender sender, String cmd, String[] args)
|
||||
throws CommandHandlingException {
|
||||
|
||||
String senderName = sender instanceof Player ? ((Player)sender).getName() : "Console";
|
||||
|
||||
if (cmd.equalsIgnoreCase("stopfire")) {
|
||||
checkPermission(player, "/stopfire");
|
||||
checkPermission(sender, "/stopfire");
|
||||
checkArgs(args, 0, 0);
|
||||
|
||||
if (!fireSpreadDisableToggle) {
|
||||
getServer().broadcastMessage(ChatColor.YELLOW
|
||||
+ "Fire spread has been globally disabled by " + player.getName() + ".");
|
||||
+ "Fire spread has been globally disabled by " + senderName + ".");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "Fire spread was already globally disabled.");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Fire spread was already globally disabled.");
|
||||
}
|
||||
|
||||
fireSpreadDisableToggle = true;
|
||||
@ -478,14 +474,14 @@ private boolean handleCommand(Player player, String cmd, String[] args)
|
||||
}
|
||||
|
||||
if (cmd.equalsIgnoreCase("allowfire")) {
|
||||
checkPermission(player, "/stopfire");
|
||||
checkPermission(sender, "/stopfire");
|
||||
checkArgs(args, 0, 0);
|
||||
|
||||
if (fireSpreadDisableToggle) {
|
||||
getServer().broadcastMessage(ChatColor.YELLOW
|
||||
+ "Fire spread has been globally re-enabled by " + player.getName() + ".");
|
||||
+ "Fire spread has been globally re-enabled by " + senderName + ".");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "Fire spread was already globally enabled.");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Fire spread was already globally enabled.");
|
||||
}
|
||||
|
||||
fireSpreadDisableToggle = false;
|
||||
@ -493,6 +489,12 @@ private boolean handleCommand(Player player, String cmd, String[] args)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (Player)sender;
|
||||
|
||||
if (cmd.equalsIgnoreCase("god")) {
|
||||
checkPermission(player, "/god");
|
||||
checkArgs(args, 0, 1);
|
||||
@ -1270,13 +1272,16 @@ private void checkRegionPermission(Player player, String permission)
|
||||
* Checks to see if there are sufficient permissions, otherwise an exception
|
||||
* is raised in that case.
|
||||
*
|
||||
* @param player
|
||||
* @param sender
|
||||
* @param permission
|
||||
* @throws InsufficientPermissionsException
|
||||
*/
|
||||
private void checkPermission(Player player, String permission)
|
||||
private void checkPermission(CommandSender sender, String permission)
|
||||
throws InsufficientPermissionsException {
|
||||
if (!hasPermission(player, permission)) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
if (!hasPermission((Player)sender, permission)) {
|
||||
throw new InsufficientPermissionsException();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user