Allow the default CONSOLE to have senior permissions

This commit is contained in:
unknown 2014-04-21 14:52:23 +02:00
parent 7df24c6b86
commit 22b0781020
21 changed files with 75 additions and 79 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Mon Apr 21 14:37:04 CEST 2014 #Mon Apr 21 14:50:16 CEST 2014
build.number=777 build.number=778

View File

@ -129,6 +129,10 @@ protected_areas_enabled: true
auto_protect_spawnpoints: true auto_protect_spawnpoints: true
auto_protect_radius: 25.0 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. # 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. # Make sure these are all lower-case.
host_sender_names: host_sender_names:

View File

@ -10,5 +10,5 @@ public @interface CommandPermissions
SourceType source(); SourceType source();
boolean block_host_console() default false; boolean blockHostConsole() default false;
} }

View File

@ -7,7 +7,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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 = "/<command> [on | off]") @CommandParameters(description = "Close server to non-superadmins.", usage = "/<command> [on | off]")
public class Command_adminmode extends TFM_Command public class Command_adminmode extends TFM_Command
{ {

View File

@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; 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 = "/<command>") @CommandParameters(description = "Make some noise.", usage = "/<command>")
public class Command_deafen extends TFM_Command public class Command_deafen extends TFM_Command
{ {

View File

@ -7,7 +7,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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 = "/<command>") @CommandParameters(description = "Kick all non-superadmins on server.", usage = "/<command>")
public class Command_kicknoob extends TFM_Command public class Command_kicknoob extends TFM_Command
{ {

View File

@ -8,7 +8,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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 = "/<command>") @CommandParameters(description = "Download the superadmin and permban lists from the main TotalFreedom server.", usage = "/<command>")
public class Command_listsync extends TFM_Command public class Command_listsync extends TFM_Command
{ {

View File

@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; 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 = "/<command> <all | purge | <<partialname> on | off>>") @CommandParameters(description = "Block target's minecraft input. This is evil, and I never should have wrote it.", usage = "/<command> <all | purge | <<partialname> on | off>>")
public class Command_lockup extends TFM_Command public class Command_lockup extends TFM_Command
{ {

View File

@ -5,7 +5,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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 = "/<command> <on | off> [range] [blockrate]") @CommandParameters(description = "Attempt to detect \"invisible griefers\" and \"nukers\".", usage = "/<command> <on | off> [range] [blockrate]")
public class Command_nonuke extends TFM_Command public class Command_nonuke extends TFM_Command
{ {

View File

@ -7,7 +7,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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 = "/<command> <list | reload>") @CommandParameters(description = "Manage permanently banned players and IPs.", usage = "/<command> <list | reload>")
public class Command_permban extends TFM_Command public class Command_permban extends TFM_Command
{ {

View File

@ -5,7 +5,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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( @CommandParameters(
description = "Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages.", description = "Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages.",
usage = "/<command> <on | off>") usage = "/<command> <on | off>")

View File

@ -6,7 +6,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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 = "/<command> <message>") @CommandParameters(description = "Broadcasts the given message. Supports colors.", usage = "/<command> <message>")
public class Command_rawsay extends TFM_Command public class Command_rawsay extends TFM_Command
{ {

View File

@ -7,7 +7,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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 = "/<command> <block> [radius (default=50)] [player]") @CommandParameters(description = "Remove all blocks of a certain type in the radius of certain players.", usage = "/<command> <block> [radius (default=50)] [player]")
public class Command_ro extends TFM_Command public class Command_ro extends TFM_Command
{ {

View File

@ -7,7 +7,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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 = "/<command> <[partialname] | undo [partialname] purge [partialname] | purgeall>", aliases = "rb") @CommandParameters(description = "Issues a rollback on a player", usage = "/<command> <[partialname] | undo [partialname] purge [partialname] | purgeall>", aliases = "rb")
public class Command_rollback extends TFM_Command public class Command_rollback extends TFM_Command
{ {

View File

@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; 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 = "/<command>") @CommandParameters(description = "Update server files.", usage = "/<command>")
public class Command_tfupdate extends TFM_Command public class Command_tfupdate extends TFM_Command
{ {

View File

@ -6,7 +6,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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 = "/<command>") @CommandParameters(description = "Wipe the flatlands map. Requires manual restart after command is used.", usage = "/<command>")
public class Command_wipeflatlands extends TFM_Command public class Command_wipeflatlands extends TFM_Command
{ {

View File

@ -59,68 +59,65 @@ public abstract class TFM_Command
public boolean senderHasPermission() public boolean senderHasPermission()
{ {
CommandPermissions permissions = commandClass.getAnnotation(CommandPermissions.class); final CommandPermissions permissions = commandClass.getAnnotation(CommandPermissions.class);
if (permissions != null)
if (permissions == null)
{ {
boolean is_super = TFM_AdminList.isSuperAdmin(this.commandSender); TFM_Log.warning(commandClass.getName() + " is missing permissions annotation.");
boolean is_senior = false; return true;
if (is_super)
{
is_senior = TFM_AdminList.isSeniorAdmin(this.commandSender);
} }
AdminLevel level = permissions.level(); boolean isSuper = TFM_AdminList.isSuperAdmin(commandSender);
SourceType source = permissions.source(); boolean isSenior = false;
boolean block_host_console = permissions.block_host_console();
Player sender_p = null; if (isSuper)
if (this.commandSender instanceof Player)
{ {
sender_p = (Player) this.commandSender; isSenior = TFM_AdminList.isSeniorAdmin(commandSender);
} }
if (sender_p == null) 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) if (source == SourceType.ONLY_IN_GAME)
{ {
return false; return false;
} }
else if (level == AdminLevel.SENIOR && !is_senior) else if (level == AdminLevel.SENIOR && !isSenior)
{ {
return false; return false;
} }
else if (block_host_console && TFM_Util.isFromHostConsole(this.commandSender.getName())) else if (blockHostConsole && TFM_Util.isFromHostConsole(commandSender.getName()))
{ {
return false; return false;
} }
} }
else else
{ {
final Player sender_p = (Player) commandSender;
if (source == SourceType.ONLY_CONSOLE) if (source == SourceType.ONLY_CONSOLE)
{ {
return false; return false;
} }
else if (level == AdminLevel.SENIOR) else if (level == AdminLevel.SENIOR)
{ {
if (is_senior) if (isSenior)
{ {
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p); TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p);
Boolean superadminIdVerified = playerdata.isSuperadminIdVerified(); if (!playerdata.isSuperadminIdVerified())
if (superadminIdVerified != null)
{
if (!superadminIdVerified.booleanValue())
{ {
return false; return false;
} }
} }
}
else else
{ {
return false; return false;
} }
} }
else if (level == AdminLevel.SUPER && !is_super) else if (level == AdminLevel.SUPER && !isSuper)
{ {
return false; return false;
} }
@ -131,12 +128,6 @@ public abstract class TFM_Command
} }
return true; return true;
} }
else
{
TFM_Log.warning(commandClass.getName() + " is missing permissions annotation.");
}
return true;
}
public Player getPlayer(final String partialname) throws PlayerNotFoundException public Player getPlayer(final String partialname) throws PlayerNotFoundException
{ {

View File

@ -153,7 +153,7 @@ public class TFM_CommandLoader
matcher.group(1).split("_")[1], matcher.group(1).split("_")[1],
commandPermissions.level(), commandPermissions.level(),
commandPermissions.source(), commandPermissions.source(),
commandPermissions.block_host_console(), commandPermissions.blockHostConsole(),
commandParameters.description(), commandParameters.description(),
commandParameters.usage(), commandParameters.usage(),
commandParameters.aliases()); commandParameters.aliases());

View File

@ -33,6 +33,7 @@ public enum TFM_ConfigEntry
TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"), TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"),
HTTPD_ENABLED(Boolean.class, "httpd_enabled"), HTTPD_ENABLED(Boolean.class, "httpd_enabled"),
AUTOKICK_ENABLED(Boolean.class, "autokick_enabled"), AUTOKICK_ENABLED(Boolean.class, "autokick_enabled"),
CONSOLE_IS_SENIOR(Boolean.class, "console_is_senior"),
// //
AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"), AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"),
EXPLOSIVE_RADIUS(Double.class, "explosive_radius"), EXPLOSIVE_RADIUS(Double.class, "explosive_radius"),

View File

@ -351,7 +351,7 @@ public class TFM_AdminList
if (!(sender instanceof Player)) 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); final TFM_Admin entry = getEntry((Player) sender);