From 22b078102005c1bed68ae0f92ddefb57fbdf2fb1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 21 Apr 2014 14:52:23 +0200 Subject: [PATCH] Allow the default CONSOLE to have senior permissions --- .gitignore | 2 +- buildnumber.properties | 4 +- src/config.yml | 4 + .../Commands/CommandPermissions.java | 2 +- .../Commands/Command_adminmode.java | 2 +- .../Commands/Command_deafen.java | 2 +- .../Commands/Command_kicknoob.java | 2 +- .../Commands/Command_listsync.java | 2 +- .../Commands/Command_lockup.java | 2 +- .../Commands/Command_nonuke.java | 2 +- .../Commands/Command_permban.java | 2 +- .../Commands/Command_prelog.java | 2 +- .../Commands/Command_rawsay.java | 2 +- .../TotalFreedomMod/Commands/Command_ro.java | 2 +- .../Commands/Command_rollback.java | 2 +- .../Commands/Command_tfupdate.java | 2 +- .../Commands/Command_wipeflatlands.java | 2 +- .../TotalFreedomMod/Commands/TFM_Command.java | 109 ++++++++---------- .../Commands/TFM_CommandLoader.java | 2 +- .../Config/TFM_ConfigEntry.java | 1 + .../TotalFreedomMod/TFM_AdminList.java | 4 +- 21 files changed, 75 insertions(+), 79 deletions(-) diff --git a/.gitignore b/.gitignore index 7c5c0f4..78958cf 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,4 @@ ehthumbs.db Thumbs.db # TFM files -buildcreator.properties \ No newline at end of file +buildcreator.properties diff --git a/buildnumber.properties b/buildnumber.properties index 59cbd7f..4c40ace 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Mon Apr 21 14:37:04 CEST 2014 -build.number=777 +#Mon Apr 21 14:50:16 CEST 2014 +build.number=778 diff --git a/src/config.yml b/src/config.yml index 8d77091..8fda316 100644 --- a/src/config.yml +++ b/src/config.yml @@ -129,6 +129,10 @@ protected_areas_enabled: true auto_protect_spawnpoints: true auto_protect_radius: 25.0 +# Give the default CONSOLE senior admin privileges. +# Handy in development environments. +console_is_senior: true + # Host Sender Names - Names that indicate automated services or host-based consoles you want to block from using some commands. # Make sure these are all lower-case. host_sender_names: diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/CommandPermissions.java b/src/me/StevenLawson/TotalFreedomMod/Commands/CommandPermissions.java index df50fea..c08b612 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/CommandPermissions.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/CommandPermissions.java @@ -10,5 +10,5 @@ public @interface CommandPermissions SourceType source(); - boolean block_host_console() default false; + boolean blockHostConsole() default false; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java index 8f06018..5b41a78 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java @@ -7,7 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE, block_host_console = true) +@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "Close server to non-superadmins.", usage = "/ [on | off]") public class Command_adminmode extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deafen.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deafen.java index 1bc5648..c3f622c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deafen.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deafen.java @@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH, block_host_console = true) +@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Make some noise.", usage = "/") public class Command_deafen extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java index d14804b..4c2ef44 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java @@ -7,7 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH, block_host_console = true) +@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Kick all non-superadmins on server.", usage = "/") public class Command_kicknoob extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_listsync.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_listsync.java index f0e24ba..ee2d40c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_listsync.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_listsync.java @@ -8,7 +8,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, block_host_console = true) +@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "Download the superadmin and permban lists from the main TotalFreedom server.", usage = "/") public class Command_listsync extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java index dd60c49..904b982 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java @@ -8,7 +8,7 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, block_host_console = true) +@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "Block target's minecraft input. This is evil, and I never should have wrote it.", usage = "/ on | off>>") public class Command_lockup extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nonuke.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nonuke.java index 3bd706d..cb738a3 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nonuke.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nonuke.java @@ -5,7 +5,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, block_host_console = true) +@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "Attempt to detect \"invisible griefers\" and \"nukers\".", usage = "/ [range] [blockrate]") public class Command_nonuke extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java index d40ebb9..90bff34 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java @@ -7,7 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, block_host_console = true) +@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Manage permanently banned players and IPs.", usage = "/ ") public class Command_permban extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_prelog.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_prelog.java index 31da804..7b933ef 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_prelog.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_prelog.java @@ -5,7 +5,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, block_host_console = true) +@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters( description = "Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages.", usage = "/ ") diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rawsay.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rawsay.java index 0c9836f..d857ea4 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rawsay.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rawsay.java @@ -6,7 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, block_host_console = true) +@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "Broadcasts the given message. Supports colors.", usage = "/ ") public class Command_rawsay extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java index 60480e9..5dda719 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java @@ -7,7 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, block_host_console = false) +@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = false) @CommandParameters(description = "Remove all blocks of a certain type in the radius of certain players.", usage = "/ [radius (default=50)] [player]") public class Command_ro extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java index 0e43b8f..1430bec 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java @@ -7,7 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, block_host_console = true) +@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Issues a rollback on a player", usage = "/ <[partialname] | undo [partialname] purge [partialname] | purgeall>", aliases = "rb") public class Command_rollback extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfupdate.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfupdate.java index ba68554..f301273 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfupdate.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfupdate.java @@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, block_host_console = true) +@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "Update server files.", usage = "/") public class Command_tfupdate extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wipeflatlands.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wipeflatlands.java index 2a97b8e..5e5bcbd 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wipeflatlands.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wipeflatlands.java @@ -6,7 +6,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, block_host_console = true) +@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "Wipe the flatlands map. Requires manual restart after command is used.", usage = "/") public class Command_wipeflatlands extends TFM_Command { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java index 55f79ce..58e1488 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java @@ -59,81 +59,72 @@ public abstract class TFM_Command public boolean senderHasPermission() { - CommandPermissions permissions = commandClass.getAnnotation(CommandPermissions.class); - if (permissions != null) + final CommandPermissions permissions = commandClass.getAnnotation(CommandPermissions.class); + + if (permissions == null) { - boolean is_super = TFM_AdminList.isSuperAdmin(this.commandSender); - boolean is_senior = false; - if (is_super) + TFM_Log.warning(commandClass.getName() + " is missing permissions annotation."); + return true; + } + + boolean isSuper = TFM_AdminList.isSuperAdmin(commandSender); + boolean isSenior = false; + + if (isSuper) + { + isSenior = TFM_AdminList.isSeniorAdmin(commandSender); + } + + final AdminLevel level = permissions.level(); + final SourceType source = permissions.source(); + final boolean blockHostConsole = permissions.blockHostConsole(); + + if (!(commandSender instanceof Player)) + { + if (source == SourceType.ONLY_IN_GAME) { - is_senior = TFM_AdminList.isSeniorAdmin(this.commandSender); + return false; } - - AdminLevel level = permissions.level(); - SourceType source = permissions.source(); - boolean block_host_console = permissions.block_host_console(); - - Player sender_p = null; - if (this.commandSender instanceof Player) + else if (level == AdminLevel.SENIOR && !isSenior) { - sender_p = (Player) this.commandSender; + return false; } - - if (sender_p == null) + else if (blockHostConsole && TFM_Util.isFromHostConsole(commandSender.getName())) { - if (source == SourceType.ONLY_IN_GAME) - { - return false; - } - else if (level == AdminLevel.SENIOR && !is_senior) - { - return false; - } - else if (block_host_console && TFM_Util.isFromHostConsole(this.commandSender.getName())) - { - return false; - } + return false; } - else - { - if (source == SourceType.ONLY_CONSOLE) - { - return false; - } - else if (level == AdminLevel.SENIOR) - { - if (is_senior) - { - TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p); - Boolean superadminIdVerified = playerdata.isSuperadminIdVerified(); + } + else + { + final Player sender_p = (Player) commandSender; - if (superadminIdVerified != null) - { - if (!superadminIdVerified.booleanValue()) - { - return false; - } - } - } - else + if (source == SourceType.ONLY_CONSOLE) + { + return false; + } + else if (level == AdminLevel.SENIOR) + { + if (isSenior) + { + TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p); + if (!playerdata.isSuperadminIdVerified()) { return false; } } - else if (level == AdminLevel.SUPER && !is_super) - { - return false; - } - else if (level == AdminLevel.OP && !sender_p.isOp()) + else { return false; } } - return true; - } - else - { - TFM_Log.warning(commandClass.getName() + " is missing permissions annotation."); + else if (level == AdminLevel.SUPER && !isSuper) + { + return false; + } + else if (level == AdminLevel.OP && !sender_p.isOp()) + { + return false; + } } return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java index ffa210d..8c86eda 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java @@ -153,7 +153,7 @@ public class TFM_CommandLoader matcher.group(1).split("_")[1], commandPermissions.level(), commandPermissions.source(), - commandPermissions.block_host_console(), + commandPermissions.blockHostConsole(), commandParameters.description(), commandParameters.usage(), commandParameters.aliases()); diff --git a/src/me/StevenLawson/TotalFreedomMod/Config/TFM_ConfigEntry.java b/src/me/StevenLawson/TotalFreedomMod/Config/TFM_ConfigEntry.java index e2cb029..8b079ff 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Config/TFM_ConfigEntry.java +++ b/src/me/StevenLawson/TotalFreedomMod/Config/TFM_ConfigEntry.java @@ -33,6 +33,7 @@ public enum TFM_ConfigEntry TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"), HTTPD_ENABLED(Boolean.class, "httpd_enabled"), AUTOKICK_ENABLED(Boolean.class, "autokick_enabled"), + CONSOLE_IS_SENIOR(Boolean.class, "console_is_senior"), // AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"), EXPLOSIVE_RADIUS(Double.class, "explosive_radius"), diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java index 0349899..71ab5ce 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java @@ -351,9 +351,9 @@ public class TFM_AdminList if (!(sender instanceof Player)) { - return consoleAliases.contains(sender.getName()); + return consoleAliases.contains(sender.getName()) || sender.getName().equals("CONSOLE"); } - + final TFM_Admin entry = getEntry((Player) sender); if (entry != null) {