diff --git a/src/main/java/com/sk89q/worldguard/bukkit/LegacyConsoleSender.java b/src/main/java/com/sk89q/worldguard/bukkit/LegacyConsoleSender.java new file mode 100644 index 00000000..be8cad1e --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/bukkit/LegacyConsoleSender.java @@ -0,0 +1,87 @@ +package com.sk89q.worldguard.bukkit; + +import java.util.Set; + +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.plugin.Plugin; + +/** +* Console sender. +* +* @author sk89q +*/ +class LegacyConsoleSender implements CommandSender { + private Server server; + + public LegacyConsoleSender(Server server) { + this.server = server; + } + + public void sendMessage(String message) { + WorldGuardPlugin.logger.info(message); + } + + public Server getServer() { + return server; + } + + public String getName() { + return "CONSOLE"; + } + + public boolean isPermissionSet(String name) { + return true; + } + + public boolean isPermissionSet(Permission perm) { + return true; + } + + public boolean hasPermission(String name) { + return true; + } + + public boolean hasPermission(Permission perm) { + return true; + } + + public PermissionAttachment addAttachment(Plugin plugin, String name, + boolean value) { + throw new UnsupportedOperationException("Fake legacy console command sender does not support this"); + } + + public PermissionAttachment addAttachment(Plugin plugin) { + throw new UnsupportedOperationException("Fake legacy console command sender does not support this"); + } + + public PermissionAttachment addAttachment(Plugin plugin, String name, + boolean value, int ticks) { + throw new UnsupportedOperationException("Fake legacy console command sender does not support this"); + } + + public PermissionAttachment addAttachment(Plugin plugin, int ticks) { + throw new UnsupportedOperationException("Fake legacy console command sender does not support this"); + } + + public void removeAttachment(PermissionAttachment attachment) { + throw new UnsupportedOperationException("Fake legacy console command sender does not support this"); + } + + public void recalculatePermissions() { + } + + public Set getEffectivePermissions() { + throw new UnsupportedOperationException("Fake legacy console command sender does not support this"); + } + + public boolean isOp() { + return true; + } + + public void setOp(boolean value) { + } +} \ No newline at end of file diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 32f8d05f..2da39510 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -569,7 +569,11 @@ public CommandSender matchPlayerOrConsole(CommandSender sender, String filter) if (filter.equalsIgnoreCase("#console") || filter.equalsIgnoreCase("*console*") || filter.equalsIgnoreCase("!")) { - return getServer().getConsoleSender(); + try { + return getServer().getConsoleSender(); + } catch (Throwable t) { + return new LegacyConsoleSender(getServer()); + } } return matchSinglePlayer(sender, filter);