diff --git a/src/config.yml b/src/config.yml index 36c93132..83a5c78f 100644 --- a/src/config.yml +++ b/src/config.yml @@ -58,20 +58,3 @@ admin_only_mode: false protected_areas_enabled: true auto_protect_spawnpoints: true auto_protect_radius: 25.0 - -# SuperAwesomeAdmins - Because normal superadmin just isn't awesome enough. These users can do even more awesomey admin shit. -super_awesome_admins: - - console - - markbyron - - mark - - madgeek1450 - - madgeek - - darthsalamon - - darth - -# Login Title Message Customization - Format: '&b is ', where &b is a color code. -user_titles: - markbyron: the &downer&b. - madgeek1450: the &5chief-developer&b and &6master-ass-kicker&b. - darthsalamon: a &5developer&b! - miwojedk: a &4master-builder&b. diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java index 3995bbec..e4d7c3d4 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -30,7 +31,7 @@ public class Command_adminmode extends TFM_Command TFM_Util.adminAction(sender.getName(), "Closing the server to non-superadmins.", true); for (Player p : server.getOnlinePlayers()) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { p.kickPlayer("Server is now closed to non-superadmins."); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java index ce326217..3bf3cf20 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cage.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; @@ -16,7 +17,7 @@ public class Command_cage extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length == 0) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java index ffd189d2..d8949522 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.Random; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.Material; @@ -14,7 +15,7 @@ public class Command_cake extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { StringBuilder output = new StringBuilder(); Random randomGenerator = new Random(); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java index 5cd00a44..e1ac4f23 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Minecart; @@ -34,7 +34,7 @@ public class Command_cartsit extends TFM_Command return true; } } - else if (target_player != sender_p && !TFM_Util.isUserSuperadmin(sender)) + else if (target_player != sender_p && !TFM_SuperadminList.isUserSuperadmin(sender)) { sender.sendMessage("Only superadmins can select another player as a /cartsit target."); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_clearall.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_clearall.java index 3ff916e8..3a38471e 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_clearall.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_clearall.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -13,7 +13,7 @@ public class Command_clearall extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!(TFM_Util.isUserSuperadmin(sender) || senderIsConsole)) + if (!(TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole)) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java index 5472e955..7770e37c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_creative.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.GameMode; import org.bukkit.command.Command; @@ -34,7 +34,7 @@ public class Command_creative extends TFM_Command } else { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { try { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deop.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deop.java index c93af282..74c49abe 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deop.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deop.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.OfflinePlayer; @@ -14,7 +15,7 @@ public class Command_deop extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!(TFM_Util.isUserSuperadmin(sender) || senderIsConsole)) + if (!(TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole)) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deopall.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deopall.java index 563d7631..1341273b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deopall.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_deopall.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; @@ -11,7 +12,7 @@ public class Command_deopall extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (TFM_Util.isUserSuperadmin(sender) || senderIsConsole) + if (TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole) { TFM_Util.adminAction(sender.getName(), "De-opping all players on the server", true); @@ -20,18 +21,6 @@ public class Command_deopall extends TFM_Command p.setOp(false); p.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP); } -// if (args.length >= 1) -// { -// if (args[0].equalsIgnoreCase("purge")) -// { -// sender.sendMessage(ChatColor.GRAY + "Purging ops.txt."); -// -// for (OfflinePlayer p : server.getOperators()) -// { -// p.setOp(false); -// } -// } -// } } else { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java index 62972f39..a0251bd0 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -13,7 +14,7 @@ public class Command_doom extends TFM_Command @Override public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!(senderIsConsole && TotalFreedomMod.superAwesomeAdmins.contains(sender.getName().toLowerCase()))) + if (!(senderIsConsole && TFM_SuperadminList.isSuperAwesomeAdmin(sender))) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; @@ -41,9 +42,10 @@ public class Command_doom extends TFM_Command final String IP = p.getAddress().getAddress().getHostAddress().trim(); // remove from superadmin - if (TFM_Util.isUserSuperadmin(p)) + if (TFM_SuperadminList.isUserSuperadmin(p)) { - server.dispatchCommand(sender, "saconfig delete " + p.getName()); + TFM_Util.adminAction(sender.getName(), "Removing " + p.getName() + " from the superadmin list.", true); + TFM_SuperadminList.removeSuperadmin(p); } // remove from whitelist diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java index 7c090587..3759bab4 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.Location; import org.bukkit.command.Command; @@ -17,7 +17,7 @@ public class Command_expel extends TFM_Command { sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); } - else if (TFM_Util.isUserSuperadmin(sender)) + else if (TFM_SuperadminList.isUserSuperadmin(sender)) { double radius = 50.0; double strength = 100.0; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_explosives.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_explosives.java index dbbf72b7..8b58341c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_explosives.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_explosives.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -11,7 +11,7 @@ public class Command_explosives extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length == 0) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fireplace.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fireplace.java index 6f29688e..95c384be 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fireplace.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fireplace.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -11,7 +11,7 @@ public class Command_fireplace extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length != 1) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_firespread.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_firespread.java index d80c2094..011efc5d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_firespread.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_firespread.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -11,7 +11,7 @@ public class Command_firespread extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length != 1) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fluidspread.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fluidspread.java index 59358e15..3ba7e0d7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fluidspread.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fluidspread.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -11,7 +11,7 @@ public class Command_fluidspread extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length != 1) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java index 4bbb7931..89b16948 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fr.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; @@ -13,7 +14,7 @@ public class Command_fr extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length == 0) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fuckoff.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fuckoff.java index cf5dfe99..a1e4a7f7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fuckoff.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_fuckoff.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; @@ -17,13 +18,13 @@ public class Command_fuckoff extends TFM_Command return true; } - if (!TFM_Util.isUserSuperadmin(sender)) + if (!TFM_SuperadminList.isUserSuperadmin(sender)) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; } - if (!TotalFreedomMod.superAwesomeAdmins.contains(sender.getName().toLowerCase())) + if (!TFM_SuperadminList.isSuperAwesomeAdmin(sender_p)) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java index 2efbc782..d94c57b9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; @@ -20,7 +21,7 @@ public class Command_gadmin extends TFM_Command String mode = args[0].toLowerCase(); - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (mode.equals("list")) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java index fac9b766..b073d3dd 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -12,7 +12,7 @@ public class Command_gcmd extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length < 2) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java index c7414302..ec1db969 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java @@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.ArrayList; import java.util.List; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_UserList; import me.StevenLawson.TotalFreedomMod.TFM_UserList.TFM_UserListEntry; import me.StevenLawson.TotalFreedomMod.TFM_Util; @@ -20,7 +21,7 @@ public class Command_glist extends TFM_Command return false; } - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length == 1) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java index 61b73670..95e4e6eb 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -19,7 +20,7 @@ public class Command_gtfo extends TFM_Command return false; } - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { Player p; try diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java index 75783536..c420fe8d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; @@ -13,7 +14,7 @@ public class Command_halt extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!(TFM_Util.isUserSuperadmin(sender) || senderIsConsole)) + if (!(TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole)) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; @@ -30,7 +31,7 @@ public class Command_halt extends TFM_Command int counter = 0; for (Player p : server.getOnlinePlayers()) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { setHalted(p, true); counter++; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java index 492394b6..8528cf4e 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_kicknoob.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -21,7 +22,7 @@ public class Command_kicknoob extends TFM_Command for (Player p : server.getOnlinePlayers()) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { p.kickPlayer("Disconnected by admin."); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lavadmg.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lavadmg.java index 92c87ea5..d2bbd918 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lavadmg.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lavadmg.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -11,7 +11,7 @@ public class Command_lavadmg extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length != 1) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lavaplace.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lavaplace.java index be5a0e0e..9d5b7425 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lavaplace.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lavaplace.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -11,7 +11,7 @@ public class Command_lavaplace extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length != 1) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java index 526033ea..84bc150b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java @@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.ArrayList; import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -30,7 +30,7 @@ public class Command_list extends TFM_Command if (!is_clanforge) { - if (TFM_Util.isUserSuperadmin(p)) + if (TFM_SuperadminList.isUserSuperadmin(p)) { if (p.isOp()) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java index e927429d..2bead4f0 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.Random; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; @@ -15,7 +16,7 @@ public class Command_lockup extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!(senderIsConsole && TotalFreedomMod.superAwesomeAdmins.contains(sender.getName().toLowerCase()))) + if (!(senderIsConsole && TFM_SuperadminList.isSuperAwesomeAdmin(sender))) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_op.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_op.java index 28bb0e7c..722bcc85 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_op.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_op.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -44,7 +45,7 @@ public class Command_op extends TFM_Command // if the player is not online if (p == null) { - if (TFM_Util.isUserSuperadmin(sender) || senderIsConsole) + if (TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole) { p = server.getOfflinePlayer(args[0]); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opall.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opall.java index 311e16fa..4ffd23b9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opall.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opall.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.GameMode; @@ -12,7 +13,7 @@ public class Command_opall extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (TFM_Util.isUserSuperadmin(sender) || senderIsConsole) + if (TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole) { TFM_Util.adminAction(sender.getName(), "Opping all players on the server", false); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opme.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opme.java index 8c9e5b27..b8d231fb 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opme.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_opme.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; @@ -15,7 +16,7 @@ public class Command_opme extends TFM_Command { sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); } - else if (TFM_Util.isUserSuperadmin(sender)) + else if (TFM_SuperadminList.isUserSuperadmin(sender)) { TFM_Util.adminAction(sender.getName(), "Opping " + sender.getName(), false); sender.setOp(true); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java index 8af074fc..f7139193 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_orbit.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; @@ -15,7 +16,7 @@ public class Command_orbit extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length == 0) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java index 4924a24a..6d19d0da 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java @@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.ArrayList; import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; @@ -56,7 +56,7 @@ public class Command_potion extends TFM_Command if (!target.equals(sender_p)) { - if (!TFM_Util.isUserSuperadmin(sender)) + if (!TFM_SuperadminList.isUserSuperadmin(sender)) { sender.sendMessage("Only superadmins can clear potion effects from other players."); return true; @@ -101,7 +101,7 @@ public class Command_potion extends TFM_Command if (!target.equals(sender_p)) { - if (!TFM_Util.isUserSuperadmin(sender)) + if (!TFM_SuperadminList.isUserSuperadmin(sender)) { sender.sendMessage("Only superadmins can apply potion effects to other players."); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_prelog.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_prelog.java index 9b0a7b1c..6f581c5d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_prelog.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_prelog.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -11,7 +11,7 @@ public class Command_prelog extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length != 1) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_protectarea.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_protectarea.java index 142364f6..558dc91c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_protectarea.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_protectarea.java @@ -1,7 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; @@ -13,7 +13,7 @@ public class Command_protectarea extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!TFM_Util.isUserSuperadmin(sender)) + if (!TFM_SuperadminList.isUserSuperadmin(sender)) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java index 8ca3b5f8..7f510601 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -12,7 +13,7 @@ public class Command_rd extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!(senderIsConsole || TFM_Util.isUserSuperadmin(sender))) + if (!(senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender))) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java index 49adf4ab..be9a50e1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java @@ -1,17 +1,11 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import me.StevenLawson.TotalFreedomMod.TFM_Log; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; +import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; public class Command_saconfig extends TFM_Command @@ -23,24 +17,24 @@ public class Command_saconfig extends TFM_Command { if (args[0].equals("list")) { - sender.sendMessage(ChatColor.GOLD + "Superadmins: " + TFM_Util.implodeStringList(", ", TotalFreedomMod.superadmins)); + sender.sendMessage(ChatColor.GOLD + "Superadmins: " + StringUtils.join(TFM_SuperadminList.getSuperadminNames(), ", ")); return true; } - + return false; } - - if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit")) + + if (!senderIsConsole) { - sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console."); + sender.sendMessage(ChatColor.GRAY + "This command may only be used from the console."); return true; } - + if (args.length < 2) { return false; } - + if (args[0].equalsIgnoreCase("add")) { Player p; @@ -53,118 +47,38 @@ public class Command_saconfig extends TFM_Command sender.sendMessage(ex.getMessage()); return true; } - - String user_name = p.getName().toLowerCase().trim(); - String new_ip = p.getAddress().getAddress().getHostAddress(); - - boolean something_changed = false; - - if (!TotalFreedomMod.superadmins.contains(user_name)) - { - TotalFreedomMod.superadmins.add(user_name); - sender.sendMessage("Adding new superadmin: " + user_name); - something_changed = true; - } - - if (!TotalFreedomMod.superadmin_ips.contains(new_ip)) - { - TotalFreedomMod.superadmin_ips.add(new_ip); - sender.sendMessage("Adding new superadmin IP: " + new_ip); - something_changed = true; - } - - if (!something_changed) - { - sender.sendMessage("That superadmin/superadmin ip pair already exists. Nothing to change!"); - } - else - { - TFM_Util.adminAction(sender.getName(), "Adding " + user_name + " to the superadmin list.", true); - } - - FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); - - List user_ips = new ArrayList(); - if (config.contains(user_name)) - { - user_ips = (List) config.getStringList(user_name); - } - - if (!user_ips.contains(new_ip)) - { - user_ips.add(new_ip); - } - - config.set(user_name, user_ips); - - try - { - config.save(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); - } - catch (IOException ex) - { - TFM_Log.severe(ex); - } + + TFM_Util.adminAction(sender.getName(), "Adding " + p.getName() + " to the superadmin list.", true); + + TFM_SuperadminList.addSuperadmin(p); } else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("remove")) { - FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); - - String user_name = null; + String target_name = args[1]; + try { - Player p = getPlayer(args[1]); - user_name = p.getName().toLowerCase().trim(); + target_name = getPlayer(target_name).getName(); } catch (CantFindPlayerException ex) { - for (String user : config.getKeys(false)) - { - if (user.equalsIgnoreCase(args[1])) - { - user_name = user; - break; - } - } } - - if (user_name == null) + + if (!TFM_SuperadminList.getSuperadminNames().contains(target_name.toLowerCase())) { - sender.sendMessage("Superadmin not found: " + user_name); + sender.sendMessage("Superadmin not found: " + target_name); return true; } - TFM_Util.adminAction(sender.getName(), "Removing " + user_name + " from the superadmin list.", true); + TFM_Util.adminAction(sender.getName(), "Removing " + target_name + " from the superadmin list.", true); - sender.sendMessage("Removing superadmin: " + user_name); - TotalFreedomMod.superadmins.remove(user_name); - - if (config.contains(user_name)) - { - List user_ips = (List) config.getStringList(user_name); - for (String ip : user_ips) - { - sender.sendMessage("Removing superadmin IP: " + ip); - TotalFreedomMod.superadmin_ips.remove(ip); - } - } - - config.set(user_name, null); - - try - { - config.save(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); - } - catch (IOException ex) - { - TFM_Log.severe(ex); - } + TFM_SuperadminList.removeSuperadmin(target_name); } else { return false; } - + return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_say.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_say.java index 1e45ea11..1ab62b55 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_say.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_say.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.Arrays; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -37,7 +38,7 @@ public class Command_say extends TFM_Command } } - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { TFM_Util.bcastMsg(String.format("[Server:%s] %s", sender.getName(), message), ChatColor.LIGHT_PURPLE); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setspawnworld.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setspawnworld.java index 9a00fa9b..2a022514 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setspawnworld.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setspawnworld.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -20,7 +21,7 @@ public class Command_setspawnworld extends TFM_Command return true; } - if (!TFM_Util.isUserSuperadmin(sender)) + if (!TFM_SuperadminList.isUserSuperadmin(sender)) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java index a740edf4..728db0f9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -21,7 +22,7 @@ public class Command_smite extends TFM_Command return false; } - if (!TFM_Util.isUserSuperadmin(sender)) + if (!TFM_SuperadminList.isUserSuperadmin(sender)) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java index 575008eb..58125e37 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; @@ -19,7 +20,7 @@ public class Command_stfu extends TFM_Command return false; } - if (!(senderIsConsole || TFM_Util.isUserSuperadmin(sender))) + if (!(senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender))) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; @@ -72,7 +73,7 @@ public class Command_stfu extends TFM_Command int counter = 0; for (Player p : server.getOnlinePlayers()) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { playerdata = TFM_UserInfo.getPlayerData(p); playerdata.setMuted(true); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stop.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stop.java index c82dd3f7..fa9bdc60 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stop.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stop.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -12,7 +13,7 @@ public class Command_stop extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { TFM_Util.bcastMsg("Server is going offline.", ChatColor.GRAY); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_survival.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_survival.java index f902bc66..42f64bc6 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_survival.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_survival.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.GameMode; import org.bukkit.command.Command; @@ -34,7 +34,7 @@ public class Command_survival extends TFM_Command } else { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { try { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java index 0638416b..f67e3da9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java @@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.text.SimpleDateFormat; import java.util.Date; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.apache.commons.lang.ArrayUtils; @@ -22,7 +23,7 @@ public class Command_tempban extends TFM_Command return false; } - if (!(senderIsConsole || TFM_Util.isUserSuperadmin(sender))) + if (!(senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender))) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfbanlist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfbanlist.java index 46b8837e..ff7be72b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfbanlist.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfbanlist.java @@ -1,7 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_Log; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import net.minecraft.server.BanList; import net.minecraft.server.MinecraftServer; import org.bukkit.ChatColor; @@ -19,7 +19,7 @@ public class Command_tfbanlist extends TFM_Command { if (args[0].equalsIgnoreCase("purge")) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { try { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfipbanlist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfipbanlist.java index c1836fd1..fc93b647 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfipbanlist.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfipbanlist.java @@ -4,7 +4,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import me.StevenLawson.TotalFreedomMod.TFM_Log; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import net.minecraft.server.BanList; import net.minecraft.server.MinecraftServer; import org.bukkit.ChatColor; @@ -21,7 +21,7 @@ public class Command_tfipbanlist extends TFM_Command { if (args[0].equalsIgnoreCase("purge")) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { try { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uall.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uall.java index 031888d8..ae41c4f9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uall.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_uall.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -14,7 +15,7 @@ public class Command_uall extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!(TFM_Util.isUserSuperadmin(sender) || senderIsConsole)) + if (!(TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole)) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_waterplace.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_waterplace.java index 7447cb59..0287f44b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_waterplace.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_waterplace.java @@ -1,6 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -11,7 +11,7 @@ public class Command_waterplace extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args.length != 1) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java index 28d90337..3caf587b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.Set; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import net.minecraft.server.MinecraftServer; @@ -61,7 +62,7 @@ public class Command_whitelist extends TFM_Command } // all commands past this line are superadmin-only - if (!(senderIsConsole || TFM_Util.isUserSuperadmin(sender))) + if (!(senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender))) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wildcard.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wildcard.java index 1b807b6b..a8cf476f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wildcard.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wildcard.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.Arrays; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.command.Command; @@ -12,7 +13,7 @@ public class Command_wildcard extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (senderIsConsole || TFM_Util.isUserSuperadmin(sender)) + if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) { if (args[0].equals("wildcard")) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wipeflatlands.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wipeflatlands.java index d0472379..7db73713 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wipeflatlands.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_wipeflatlands.java @@ -1,5 +1,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; @@ -12,7 +13,7 @@ public class Command_wipeflatlands extends TFM_Command @Override public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (!(senderIsConsole && TotalFreedomMod.superAwesomeAdmins.contains(sender.getName().toLowerCase()))) + if (!(senderIsConsole && TFM_SuperadminList.isSuperAwesomeAdmin(sender))) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java index 3836fff6..08f74acd 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java @@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Listener; import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; @@ -89,7 +90,7 @@ public class TFM_BlockListener implements Listener if (TotalFreedomMod.protectedAreasEnabled) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { if (TFM_ProtectedArea.isInProtectedArea(block_pos)) { @@ -152,7 +153,7 @@ public class TFM_BlockListener implements Listener if (TotalFreedomMod.protectedAreasEnabled) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { if (TFM_ProtectedArea.isInProtectedArea(block_pos)) { @@ -257,14 +258,14 @@ public class TFM_BlockListener implements Listener { Player player = event.getPlayer(); - if (!TFM_Util.isUserSuperadmin(player)) + if (!TFM_SuperadminList.isUserSuperadmin(player)) { TFM_Util.playerMsg(player, "You do not have permission to set Command Block commands."); event.setCancelled(true); return; } - if (!TotalFreedomMod.superAwesomeAdmins.contains(player.getName().toLowerCase())) + if (!TFM_SuperadminList.isSuperAwesomeAdmin(player)) { TFM_Util.playerMsg(player, "You do not have permission to set Command Block commands."); event.setCancelled(true); diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index bb12034c..ed22a20b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -174,7 +174,7 @@ public class TFM_PlayerListener implements Listener boolean do_freeze = false; if (TotalFreedomMod.allPlayersFrozen) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { do_freeze = true; } @@ -301,7 +301,7 @@ public class TFM_PlayerListener implements Listener // check for muted if (playerdata.isMuted()) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { p.sendMessage(ChatColor.RED + "You are muted, STFU!"); event.setCancelled(true); @@ -385,21 +385,21 @@ public class TFM_PlayerListener implements Listener //Commands that will auto-kick the user: if (Pattern.compile("^/stop").matcher(command).find()) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { block_command = true; } } else if (Pattern.compile("^/reload").matcher(command).find()) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { block_command = true; } } else if (Pattern.compile("^/save-").matcher(command).find()) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { block_command = true; } @@ -437,14 +437,14 @@ public class TFM_PlayerListener implements Listener } else if (Pattern.compile("^/kick").matcher(command).find()) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { block_command = true; } } else if (Pattern.compile("^/kill").matcher(command).find()) { - if (!TFM_Util.isUserSuperadmin(p)) + if (!TFM_SuperadminList.isUserSuperadmin(p)) { block_command = true; } @@ -526,9 +526,9 @@ public class TFM_PlayerListener implements Listener TFM_UserList.getInstance(TotalFreedomMod.plugin).addUser(p); - boolean superadmin_impostor = TFM_Util.isSuperadminImpostor(p); + boolean superadmin_impostor = TFM_SuperadminList.isSuperadminImpostor(p); - if (superadmin_impostor || TFM_Util.isUserSuperadmin(p)) + if (superadmin_impostor || TFM_SuperadminList.isUserSuperadmin(p)) { TFM_Util.bcastMsg(ChatColor.AQUA + p.getName() + " is " + TFM_Util.getRank(p)); @@ -542,6 +542,8 @@ public class TFM_PlayerListener implements Listener else { p.setOp(true); + + TFM_SuperadminList.updateLastLogin(p); } } @@ -594,12 +596,11 @@ public class TFM_PlayerListener implements Listener boolean is_superadmin; if (server.getOnlineMode()) { - is_superadmin = TotalFreedomMod.superadmins.contains(player_name.toLowerCase()); + is_superadmin = TFM_SuperadminList.getSuperadminNames().contains(player_name.toLowerCase()); } else { - //is_superadmin = TotalFreedomMod.superadmin_ips.contains(player_ip); - is_superadmin = TFM_Util.checkPartialSuperadminIP(player_ip); + is_superadmin = TFM_SuperadminList.checkPartialSuperadminIP(player_ip); } if (!is_superadmin) @@ -760,7 +761,7 @@ public class TFM_PlayerListener implements Listener can_kick = false; for (Player test_player : server.getOnlinePlayers()) { - if (!TFM_Util.isUserSuperadmin(test_player)) + if (!TFM_SuperadminList.isUserSuperadmin(test_player)) { can_kick = true; test_player.kickPlayer("You have been kicked to free up room for an admin."); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Superadmin.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Superadmin.java new file mode 100644 index 00000000..d879b148 --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Superadmin.java @@ -0,0 +1,98 @@ +package me.StevenLawson.TotalFreedomMod; + +import java.util.Date; +import java.util.List; +import org.apache.commons.lang.StringUtils; +import org.bukkit.configuration.ConfigurationSection; + +public class TFM_Superadmin +{ + private final String name; + private final String custom_login_message; + private final boolean is_super_awesome_admin; + private final List console_aliases; + private List ips; + private Date last_login; + + public TFM_Superadmin(String name, List ips, Date last_login, String custom_login_message, boolean is_super_awesome_admin, List console_aliases) + { + this.name = name.toLowerCase(); + this.ips = ips; + this.last_login = last_login; + this.custom_login_message = custom_login_message; + this.is_super_awesome_admin = is_super_awesome_admin; + this.console_aliases = console_aliases; + } + + public TFM_Superadmin(String name, ConfigurationSection section) + { + this.name = name.toLowerCase(); + this.ips = section.getStringList("ips"); + this.last_login = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L)))); + this.custom_login_message = section.getString("custom_login_message", ""); + this.is_super_awesome_admin = section.getBoolean("is_super_awesome_admin", false); + this.console_aliases = section.getStringList("console_aliases"); + } + + @Override + public String toString() + { + StringBuilder output = new StringBuilder(); + + try + { + output.append("Name: ").append(this.name).append("\n"); + output.append("- IPs: ").append(StringUtils.join(this.ips, ", ")).append("\n"); + output.append("- Last Login: ").append(TFM_Util.dateToString(this.last_login)).append("\n"); + output.append("- Custom Login Message: ").append(this.custom_login_message).append("\n"); + output.append("- Is Super Awesome Admin: ").append(this.is_super_awesome_admin).append("\n"); + output.append("- Console Aliases: ").append(StringUtils.join(this.console_aliases, ", ")); + } + catch (Exception ex) + { + TFM_Log.severe(ex); + } + + return output.toString(); + } + + public String getName() + { + return name; + } + + public List getIps() + { + return ips; + } + + public Date getLastLogin() + { + return last_login; + } + + public String getCustomLoginMessage() + { + return custom_login_message; + } + + public boolean isSuperAwesomeAdmin() + { + return is_super_awesome_admin; + } + + public List getConsoleAliases() + { + return console_aliases; + } + + public void setIps(List ips) + { + this.ips = ips; + } + + public void setLastLogin(Date last_login) + { + this.last_login = last_login; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_SuperadminList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_SuperadminList.java new file mode 100644 index 00000000..6051690c --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_SuperadminList.java @@ -0,0 +1,355 @@ +package me.StevenLawson.TotalFreedomMod; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +public class TFM_SuperadminList +{ + private static Map superadminList = new HashMap(); + private static List superadminNames = new ArrayList(); + private static List superadminIPs = new ArrayList(); + private static List superAwesomeAdminsConsole = new ArrayList(); + + private TFM_SuperadminList() + { + throw new AssertionError(); + } + + public static List getSuperadminIPs() + { + return superadminIPs; + } + + public static List getSuperadminNames() + { + return superadminNames; + } + + public static void loadSuperadminList() + { + convertV1List(); + + superadminList.clear(); + + TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file); + FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); + + if (config.isConfigurationSection("superadmins")) + { + ConfigurationSection section = config.getConfigurationSection("superadmins"); + + for (String admin_name : section.getKeys(false)) + { + TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, section.getConfigurationSection(admin_name)); + superadminList.put(admin_name.toLowerCase(), superadmin); + } + } + else + { + TFM_Log.warning("Missing superadmins section in superadmin.yml."); + } + + updateIndexLists(); + } + + public static void updateIndexLists() + { + superadminNames.clear(); + superadminIPs.clear(); + + Iterator> it = superadminList.entrySet().iterator(); + while (it.hasNext()) + { + Entry pair = it.next(); + + String admin_name = pair.getKey().toLowerCase(); + TFM_Superadmin superadmin = pair.getValue(); + + superadminNames.add(admin_name); + + for (String ip : superadmin.getIps()) + { + superadminIPs.add(ip); + } + + if (superadmin.isSuperAwesomeAdmin()) + { + superAwesomeAdminsConsole.add(admin_name); + + for (String console_alias : superadmin.getConsoleAliases()) + { + superAwesomeAdminsConsole.add(console_alias.toLowerCase()); + } + } + } + } + + public static void convertV1List() + { + superadminList.clear(); + + TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file); + FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); + + if (!config.isConfigurationSection("superadmins")) + { + for (String admin_name : config.getKeys(false)) + { + TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, config.getStringList(admin_name), new Date(), "", false, new ArrayList()); + superadminList.put(admin_name.toLowerCase(), superadmin); + } + + saveSuperadminList(); + } + } + + public static void saveSuperadminList() + { + updateIndexLists(); + + YamlConfiguration config = new YamlConfiguration(); + + Iterator> it = superadminList.entrySet().iterator(); + while (it.hasNext()) + { + Entry pair = it.next(); + + String admin_name = pair.getKey().toLowerCase(); + TFM_Superadmin superadmin = pair.getValue(); + + config.set("superadmins." + admin_name + ".ips", superadmin.getIps()); + config.set("superadmins." + admin_name + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin())); + config.set("superadmins." + admin_name + ".custom_login_message", superadmin.getCustomLoginMessage()); + config.set("superadmins." + admin_name + ".is_super_awesome_admin", superadmin.isSuperAwesomeAdmin()); + config.set("superadmins." + admin_name + ".console_aliases", superadmin.getConsoleAliases()); + } + + try + { + config.save(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); + } + catch (IOException ex) + { + TFM_Log.severe(ex); + } + } + + public static TFM_Superadmin getAdminEntry(String admin_name) + { + admin_name = admin_name.toLowerCase(); + + if (superadminList.containsKey(admin_name)) + { + return superadminList.get(admin_name); + } + else + { + return null; + } + } + + public static TFM_Superadmin getAdminEntry(Player p) + { + return getAdminEntry(p.getName().toLowerCase()); + } + + public static TFM_Superadmin getAdminEntryByIP(String ip) + { + Iterator> it = superadminList.entrySet().iterator(); + while (it.hasNext()) + { + Entry pair = it.next(); + TFM_Superadmin superadmin = pair.getValue(); + if (superadmin.getIps().contains(ip)) + { + return superadmin; + } + } + return null; + } + + public static void updateLastLogin(Player p) + { + TFM_Superadmin admin_entry = getAdminEntry(p); + if (admin_entry != null) + { + admin_entry.setLastLogin(new Date()); + saveSuperadminList(); + } + } + + public static boolean isSuperAwesomeAdmin(CommandSender user) + { + String user_name = user.getName().toLowerCase(); + + if (!(user instanceof Player)) + { + return superAwesomeAdminsConsole.contains(user_name); + } + + TFM_Superadmin admin_entry = getAdminEntry((Player) user); + if (admin_entry != null) + { + return admin_entry.isSuperAwesomeAdmin(); + } + + return false; + } + + public static boolean isUserSuperadmin(CommandSender user) + { + if (!(user instanceof Player)) + { + return true; + } + + if (Bukkit.getOnlineMode()) + { + if (superadminNames.contains(user.getName().toLowerCase())) + { + return true; + } + } + + try + { + String user_ip = ((Player) user).getAddress().getAddress().getHostAddress(); + if (user_ip != null && !user_ip.isEmpty()) + { + if (superadminIPs.contains(user_ip)) + { + return true; + } + } + } + catch (Exception ex) + { + return false; + } + + return false; + } + + public static boolean checkPartialSuperadminIP(String user_ip) + { + user_ip = user_ip.trim(); + + if (superadminIPs.contains(user_ip)) + { + return true; + } + else + { + String[] user_octets = user_ip.split("\\."); + if (user_octets.length != 4) + { + return false; + } + + String match_ip = null; + for (String test_ip : getSuperadminIPs()) + { + String[] test_octets = test_ip.split("\\."); + if (test_octets.length == 4) + { + if (user_octets[0].equals(test_octets[0]) && user_octets[1].equals(test_octets[1]) && user_octets[2].equals(test_octets[2])) + { + match_ip = test_ip; + break; + } + } + } + + if (match_ip != null) + { + TFM_Superadmin admin_entry = getAdminEntryByIP(match_ip); + + if (admin_entry != null) + { + List ips = admin_entry.getIps(); + ips.add(user_ip); + admin_entry.setIps(ips); + saveSuperadminList(); + } + + return true; + } + } + + return false; + } + + public static boolean isSuperadminImpostor(CommandSender user) + { + if (!(user instanceof Player)) + { + return false; + } + + Player p = (Player) user; + + if (superadminNames.contains(p.getName().toLowerCase())) + { + return !isUserSuperadmin(p); + } + + return false; + } + + public static void addSuperadmin(String admin_name, List ips) + { + Date last_login = new Date(); + String custom_login_message = ""; + boolean is_super_awesome_admin = false; + List console_aliases = new ArrayList(); + + TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, ips, last_login, custom_login_message, is_super_awesome_admin, console_aliases); + superadminList.put(admin_name.toLowerCase(), superadmin); + + saveSuperadminList(); + } + + public static void addSuperadmin(Player p) + { + String admin_name = p.getName().toLowerCase(); + List ips = Arrays.asList(p.getAddress().getAddress().getHostAddress()); + + addSuperadmin(admin_name, ips); + } + + public static void addSuperadmin(String admin_name) + { + addSuperadmin(admin_name, new ArrayList()); + } + + public static void removeSuperadmin(String admin_name) + { + admin_name = admin_name.toLowerCase(); + + if (superadminList.containsKey(admin_name)) + { + superadminList.remove(admin_name); + } + + saveSuperadminList(); + } + + public static void removeSuperadmin(Player p) + { + removeSuperadmin(p.getName()); + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index 5bc24ac5..23cf6979 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -1,8 +1,9 @@ package me.StevenLawson.TotalFreedomMod; import java.io.*; -import java.net.InetSocketAddress; import java.net.URI; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; import java.util.jar.JarFile; import java.util.regex.Matcher; @@ -18,8 +19,6 @@ import org.apache.commons.lang.exception.ExceptionUtils; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.*; public class TFM_Util @@ -102,16 +101,6 @@ public class TFM_Util public static String implodeStringList(String glue, List pieces) { -// StringBuilder output = new StringBuilder(); -// for (int i = 0; i < pieces.size(); i++) -// { -// if (i != 0) -// { -// output.append(glue); -// } -// output.append(pieces.get(i)); -// } -// return output.toString(); return StringUtils.join(pieces, glue); } @@ -266,113 +255,16 @@ public class TFM_Util } } + @Deprecated public static boolean isUserSuperadmin(CommandSender user) { - try - { - if (!(user instanceof Player)) - { - return true; - } - - if (Bukkit.getOnlineMode()) - { - if (TotalFreedomMod.superadmins.contains(user.getName().toLowerCase())) - { - return true; - } - } - - Player p = (Player) user; - if (p != null) - { - InetSocketAddress address = p.getAddress(); - if (address != null) - { - String user_ip = address.getAddress().getHostAddress(); - if (user_ip != null && !user_ip.isEmpty()) - { - if (TotalFreedomMod.superadmin_ips.contains(user_ip)) - { - return true; - } - } - } - } - } - catch (Exception ex) - { - TFM_Log.severe(ex); - } - - return false; + return TFM_SuperadminList.isUserSuperadmin(user); } + @Deprecated public static boolean checkPartialSuperadminIP(String user_ip) { - user_ip = user_ip.trim(); - - if (TotalFreedomMod.superadmin_ips.contains(user_ip)) - { - return true; - } - else - { - String[] user_octets = user_ip.split("\\."); - if (user_octets.length != 4) - { - return false; - } - - String match_ip = null; - for (String test_ip : TotalFreedomMod.superadmin_ips) - { - String[] test_octets = test_ip.split("\\."); - if (test_octets.length == 4) - { - if (user_octets[0].equals(test_octets[0]) && user_octets[1].equals(test_octets[1]) && user_octets[2].equals(test_octets[2])) - { - match_ip = test_ip; - break; - } - } - } - - if (match_ip != null) - { - TotalFreedomMod.superadmin_ips.add(user_ip); - - FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); - - fileloop: - for (String user : config.getKeys(false)) - { - List user_ips = (List) config.getStringList(user); - for (String ip : user_ips) - { - ip = ip.toLowerCase().trim(); - if (ip.equals(match_ip)) - { - TFM_Log.info("New IP '" + user_ip + "' matches old IP '" + match_ip + "' via partial match, adding it to superadmin list."); - user_ips.add(user_ip); - config.set(user, user_ips); - break fileloop; - } - } - } - - try - { - config.save(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); - } - catch (IOException ex) - { - TFM_Log.severe(ex); - } - } - - return match_ip != null; - } + return TFM_SuperadminList.checkPartialSuperadminIP(user_ip); } public static int wipeEntities(boolean wipe_explosives, boolean wipe_carts) @@ -659,21 +551,10 @@ public class TFM_Util Bukkit.getServer().createWorld(flatlands); } + @Deprecated public static boolean isSuperadminImpostor(CommandSender user) { - if (!(user instanceof Player)) - { - return false; - } - - Player p = (Player) user; - - if (TotalFreedomMod.superadmins.contains(p.getName().toLowerCase())) - { - return !TFM_Util.isUserSuperadmin(p); - } - - return false; + return TFM_SuperadminList.isSuperadminImpostor(user); } //JeromSar @@ -684,33 +565,20 @@ public class TFM_Util return "an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "impostor" + ChatColor.RESET + ChatColor.AQUA + "!"; } -// if (sender.getName().equalsIgnoreCase("markbyron")) -// { -// return "the " + ChatColor.LIGHT_PURPLE + "owner" + ChatColor.AQUA + "."; -// } -// -// if (sender.getName().equalsIgnoreCase("madgeek1450")) -// { -// return "the " + ChatColor.DARK_PURPLE + "chief-developer" + ChatColor.AQUA + " and " + ChatColor.GOLD + "master-ass-kicker" + ChatColor.AQUA + "."; -// } -// -// if (sender.getName().equalsIgnoreCase("darthsalamon")) -// { -// return "a " + ChatColor.DARK_PURPLE + "developer" + ChatColor.AQUA + "!"; -// } -// -// if (sender.getName().equalsIgnoreCase("miwojedk")) -// { -// return "a " + ChatColor.DARK_RED + "master-builder" + ChatColor.AQUA + "!"; -// } + TFM_Superadmin admin_entry = TFM_SuperadminList.getAdminEntry(sender.getName()); - if (TotalFreedomMod.customUserTitles.containsKey(sender.getName().toLowerCase())) + if (admin_entry != null) { - return ChatColor.translateAlternateColorCodes('&', TotalFreedomMod.customUserTitles.get(sender.getName().toLowerCase())); - } + String custom_login_message = admin_entry.getCustomLoginMessage(); + + if (custom_login_message != null) + { + if (!custom_login_message.isEmpty()) + { + return ChatColor.translateAlternateColorCodes('&', custom_login_message); + } + } - if (TFM_Util.isUserSuperadmin(sender)) - { return "an " + ChatColor.RED + "admin" + ChatColor.AQUA + "."; } @@ -1023,6 +891,25 @@ public class TFM_Util } } } + + public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; + + public static String dateToString(Date date) + { + return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).format(date); + } + + public static Date stringToDate(String date_str) + { + try + { + return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).parse(date_str); + } + catch (ParseException ex) + { + return new Date(0L); + } + } // I wrote all this before i discovered getTargetBlock >.> - might come in handy some day... // public static final double LOOKAT_VIEW_HEIGHT = 1.65; // public static final double LOOKAT_STEP_DISTANCE = 0.2; diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index c19d7b54..50cbd34d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -3,7 +3,6 @@ package me.StevenLawson.TotalFreedomMod; import java.io.File; import java.io.InputStream; import java.util.*; -import java.util.Map.Entry; import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command; import me.StevenLawson.TotalFreedomMod.Listener.TFM_BlockListener; import me.StevenLawson.TotalFreedomMod.Listener.TFM_EntityListener; @@ -52,11 +51,13 @@ public class TotalFreedomMod extends JavaPlugin public static String pluginName = ""; public static TotalFreedomMod plugin = null; + public static File plugin_file = null; @Override public void onEnable() { TotalFreedomMod.plugin = this; + TotalFreedomMod.plugin_file = getFile(); TotalFreedomMod.pluginName = this.getDescription().getName(); @@ -195,11 +196,9 @@ public class TotalFreedomMod extends JavaPlugin public static String flatlandsGenerationParams = "16,stone,32,dirt,1,grass"; public static boolean allowFliudSpread = false; public static boolean adminOnlyMode = false; - public static List superAwesomeAdmins = Arrays.asList("markbyron", "mark", "madgeek1450", "madgeek", "darthsalamon", "darth"); public static boolean protectedAreasEnabled = true; public static boolean autoProtectSpawnpoints = true; public static double autoProtectRadius = 25.0D; - public static Map customUserTitles = new HashMap(); public void loadMainConfig() { @@ -237,21 +236,9 @@ public class TotalFreedomMod extends JavaPlugin flatlandsGenerationParams = config.getString("flatlands_generation_params", flatlandsGenerationParams); allowFliudSpread = config.getBoolean("allow_fluid_spread", allowFliudSpread); adminOnlyMode = config.getBoolean("admin_only_mode", adminOnlyMode); - superAwesomeAdmins = config.getStringList("super_awesome_admins"); protectedAreasEnabled = config.getBoolean("protected_areas_enabled", protectedAreasEnabled); autoProtectSpawnpoints = config.getBoolean("auto_protect_spawnpoints", autoProtectSpawnpoints); autoProtectRadius = config.getDouble("auto_protect_radius", autoProtectRadius); - - if (config.isConfigurationSection("user_titles")) - { - Map raw_titles = config.getConfigurationSection("user_titles").getValues(false); - Iterator> it = raw_titles.entrySet().iterator(); - while (it.hasNext()) - { - Entry pair = it.next(); - customUserTitles.put(pair.getKey(), (String) pair.getValue()); - } - } } catch (Exception ex) { @@ -259,33 +246,19 @@ public class TotalFreedomMod extends JavaPlugin } } + @Deprecated public static List superadmins = new ArrayList(); + @Deprecated public static List superadmin_ips = new ArrayList(); public void loadSuperadminConfig() { try { - TFM_Util.createDefaultConfiguration(SUPERADMIN_FILE, getFile()); - FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), SUPERADMIN_FILE)); + TFM_SuperadminList.loadSuperadminList(); - superadmins = new ArrayList(); - superadmin_ips = new ArrayList(); - - for (String user : config.getKeys(false)) - { - superadmins.add(user.toLowerCase().trim()); - - List user_ips = (List) config.getStringList(user); - for (String ip : user_ips) - { - ip = ip.toLowerCase().trim(); - if (!superadmin_ips.contains(ip)) - { - superadmin_ips.add(ip); - } - } - } + superadmins = TFM_SuperadminList.getSuperadminNames(); + superadmin_ips = TFM_SuperadminList.getSuperadminIPs(); } catch (Exception ex) { diff --git a/src/superadmin.yml b/src/superadmin.yml index c7303559..b78262d3 100644 --- a/src/superadmin.yml +++ b/src/superadmin.yml @@ -1,9 +1,27 @@ -madgeek1450: - - 127.0.0.1 - - 8.8.8.8 -markbyron: - - 74.125.224.72 - - 8.8.4.4 -darthsalamon: - - 80.60.73.144 - - 213.211.159.63 +superadmins: + darthsalamon: + ips: + - 80.60.73.144 + - 213.211.159.63 + last_login: Fri, 9 Nov 2012 03:09:14 -0500 + custom_login_message: a &5developer&b! + is_super_awesome_admin: true + console_aliases: + - darth + madgeek1450: + ips: + - 127.0.0.1 + - 8.8.8.8 + last_login: Sun, 11 Nov 2012 01:09:14 -0500 + custom_login_message: the &5chief-developer&b and &6master-ass-kicker&b. + is_super_awesome_admin: true + console_aliases: + - madgeek + markbyron: + ips: + - 74.125.224.72 + - 8.8.4.4 + last_login: Sat, 10 Nov 2012 02:09:14 -0500 + custom_login_message: the &downer&b. + is_super_awesome_admin: true + console_aliases: []