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

2
.gitignore vendored
View File

@ -19,4 +19,4 @@ ehthumbs.db
Thumbs.db Thumbs.db
# TFM files # TFM files
buildcreator.properties buildcreator.properties

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,81 +59,72 @@ 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) }
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;
} }
else if (level == AdminLevel.SENIOR && !isSenior)
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)
{ {
sender_p = (Player) this.commandSender; return false;
} }
else if (blockHostConsole && TFM_Util.isFromHostConsole(commandSender.getName()))
if (sender_p == null)
{ {
if (source == SourceType.ONLY_IN_GAME) return false;
{
return false;
}
else if (level == AdminLevel.SENIOR && !is_senior)
{
return false;
}
else if (block_host_console && TFM_Util.isFromHostConsole(this.commandSender.getName()))
{
return false;
}
} }
else }
{ else
if (source == SourceType.ONLY_CONSOLE) {
{ final Player sender_p = (Player) commandSender;
return false;
}
else if (level == AdminLevel.SENIOR)
{
if (is_senior)
{
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p);
Boolean superadminIdVerified = playerdata.isSuperadminIdVerified();
if (superadminIdVerified != null) if (source == SourceType.ONLY_CONSOLE)
{ {
if (!superadminIdVerified.booleanValue()) return false;
{ }
return false; else if (level == AdminLevel.SENIOR)
} {
} if (isSenior)
} {
else TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p);
if (!playerdata.isSuperadminIdVerified())
{ {
return false; return false;
} }
} }
else if (level == AdminLevel.SUPER && !is_super) else
{
return false;
}
else if (level == AdminLevel.OP && !sender_p.isOp())
{ {
return false; return false;
} }
} }
return true; else if (level == AdminLevel.SUPER && !isSuper)
} {
else return false;
{ }
TFM_Log.warning(commandClass.getName() + " is missing permissions annotation."); else if (level == AdminLevel.OP && !sender_p.isOp())
{
return false;
}
} }
return true; return true;
} }

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,9 +351,9 @@ 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);
if (entry != null) if (entry != null)
{ {