[Bleeding] Working on TFM_Admin

This commit is contained in:
unknown 2014-04-08 20:31:04 +02:00
parent 6365672eda
commit ec8a528564
42 changed files with 310 additions and 344 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Fri Apr 04 16:47:53 CEST 2014 #Wed Apr 09 20:26:09 CEST 2014
build.number=708 build.number=712

View File

@ -1,94 +0,0 @@
package com.evilmidget38;
import com.google.common.collect.ImmutableList;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.JSONParser;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
public class UUIDFetcher implements Callable<Map<String, UUID>>
{
private static final int MAX_SEARCH = 100;
private static final String PROFILE_URL = "https://api.mojang.com/profiles/page/";
private static final String AGENT = "minecraft";
private final JSONParser jsonParser = new JSONParser();
private final List<String> names;
public UUIDFetcher(List<String> names)
{
this.names = ImmutableList.copyOf(names);
}
@Override
public Map<String, UUID> call() throws Exception
{
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
String body = buildBody(names);
for (int i = 1; i < MAX_SEARCH; i++)
{
HttpURLConnection connection = createConnection(i);
writeBody(connection, body);
JSONObject jsonObject = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
JSONArray array = (JSONArray) jsonObject.get("profiles");
Number count = (Number) jsonObject.get("size");
if (count.intValue() == 0)
{
break;
}
for (Object profile : array)
{
JSONObject jsonProfile = (JSONObject) profile;
String id = (String) jsonProfile.get("id");
String name = (String) jsonProfile.get("name");
UUID uuid = UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
uuidMap.put(name, uuid);
}
}
return uuidMap;
}
private static void writeBody(HttpURLConnection connection, String body) throws Exception
{
DataOutputStream writer = new DataOutputStream(connection.getOutputStream());
writer.write(body.getBytes());
writer.flush();
writer.close();
}
private static HttpURLConnection createConnection(int page) throws Exception
{
URL url = new URL(PROFILE_URL + page);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
return connection;
}
@SuppressWarnings("unchecked")
private static String buildBody(List<String> names)
{
List<JSONObject> lookups = new ArrayList<JSONObject>();
for (String name : names)
{
JSONObject obj = new JSONObject();
obj.put("name", name);
obj.put("agent", AGENT);
lookups.add(obj);
}
return JSONValue.toJSONString(lookups);
}
}

View File

@ -31,7 +31,7 @@ public class Command_adminmode extends TFM_Command
TFM_Util.adminAction(sender.getName(), "Closing the server to non-superadmins.", true); TFM_Util.adminAction(sender.getName(), "Closing the server to non-superadmins.", true);
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
player.kickPlayer("Server is now closed to non-superadmins."); player.kickPlayer("Server is now closed to non-superadmins.");
} }

View File

@ -217,7 +217,7 @@ public class Command_adminworld extends TFM_Command
private void assertCommandPerms(CommandSender sender, Player sender_p) throws PermissionDeniedException private void assertCommandPerms(CommandSender sender, Player sender_p) throws PermissionDeniedException
{ {
if (!(sender instanceof Player) || sender_p == null || !TFM_SuperadminList.isUserSuperadmin(sender)) if (!(sender instanceof Player) || sender_p == null || !TFM_SuperadminList.isSuperAdmin(sender))
{ {
throw new PermissionDeniedException(TotalFreedomMod.MSG_NO_PERMS); throw new PermissionDeniedException(TotalFreedomMod.MSG_NO_PERMS);
} }

View File

@ -47,7 +47,7 @@ public class Command_blockcmd extends TFM_Command
return true; return true;
} }
if (TFM_SuperadminList.isUserSuperadmin(player)) if (TFM_SuperadminList.isSuperAdmin(player))
{ {
playerMsg(player.getName() + " is a Superadmin, and cannot have their commands blocked."); playerMsg(player.getName() + " is a Superadmin, and cannot have their commands blocked.");
return true; return true;

View File

@ -36,7 +36,7 @@ public class Command_cartsit extends TFM_Command
return true; return true;
} }
} }
else if (targetPlayer != sender_p && !TFM_SuperadminList.isUserSuperadmin(sender)) else if (targetPlayer != sender_p && !TFM_SuperadminList.isSuperAdmin(sender))
{ {
sender.sendMessage("Only superadmins can select another player as a /cartsit target."); sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
return true; return true;

View File

@ -33,7 +33,7 @@ public class Command_creative extends TFM_Command
{ {
if (args[0].equalsIgnoreCase("-a")) if (args[0].equalsIgnoreCase("-a"))
{ {
if (!TFM_SuperadminList.isUserSuperadmin(sender)) if (!TFM_SuperadminList.isSuperAdmin(sender))
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
@ -48,7 +48,7 @@ public class Command_creative extends TFM_Command
return true; return true;
} }
if (!(senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender))) if (!(senderIsConsole || TFM_SuperadminList.isSuperAdmin(sender)))
{ {
playerMsg("Only superadmins can change other user's gamemode."); playerMsg("Only superadmins can change other user's gamemode.");
return true; return true;

View File

@ -39,7 +39,7 @@ public class Command_doom extends TFM_Command
final String IP = player.getAddress().getAddress().getHostAddress().trim(); final String IP = player.getAddress().getAddress().getHostAddress().trim();
// remove from superadmin // remove from superadmin
if (TFM_SuperadminList.isUserSuperadmin(player)) if (TFM_SuperadminList.isSuperAdmin(player))
{ {
TFM_Util.adminAction(sender.getName(), "Removing " + player.getName() + " from the superadmin list.", true); TFM_Util.adminAction(sender.getName(), "Removing " + player.getName() + " from the superadmin list.", true);
TFM_SuperadminList.removeSuperadmin(player); TFM_SuperadminList.removeSuperadmin(player);

View File

@ -44,7 +44,7 @@ public class Command_fr extends TFM_Command
playerMsg("Players are now frozen."); playerMsg("Players are now frozen.");
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
TFM_Util.playerMsg(player, "You have been frozen due to rule breaker(s), you will be unfrozen very soon.", ChatColor.RED); TFM_Util.playerMsg(player, "You have been frozen due to rule breaker(s), you will be unfrozen very soon.", ChatColor.RED);
} }

View File

@ -25,7 +25,7 @@ public class Command_halt extends TFM_Command
int counter = 0; int counter = 0;
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
TFM_PlayerData.getPlayerData(player).setHalted(true); TFM_PlayerData.getPlayerData(player).setHalted(true);
counter++; counter++;

View File

@ -38,7 +38,7 @@ public class Command_invis extends TFM_Command
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
{ {
players.add(player.getName()); players.add(player.getName());
if (smite && !TFM_SuperadminList.isUserSuperadmin(player)) if (smite && !TFM_SuperadminList.isSuperAdmin(player))
{ {
TFM_Util.adminAction(sender.getName(), "Smiting all invisible players", true); TFM_Util.adminAction(sender.getName(), "Smiting all invisible players", true);
player.setHealth(0.0); player.setHealth(0.0);

View File

@ -18,7 +18,7 @@ public class Command_kicknoob extends TFM_Command
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
player.kickPlayer(ChatColor.RED + "Disconnected by admin."); player.kickPlayer(ChatColor.RED + "Disconnected by admin.");
} }

View File

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank; import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank;
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin; import me.StevenLawson.TotalFreedomMod.TFM_Admin;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -55,7 +55,7 @@ public class Command_list extends TFM_Command
final List<String> names = new ArrayList<String>(); final List<String> names = new ArrayList<String>();
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
final boolean userSuperadmin = TFM_SuperadminList.isUserSuperadmin(player); final boolean userSuperadmin = TFM_SuperadminList.isSuperAdmin(player);
if (listFilter == Command_list.ListFilter.ADMINS && !userSuperadmin) if (listFilter == Command_list.ListFilter.ADMINS && !userSuperadmin)
{ {

View File

@ -11,7 +11,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin; import me.StevenLawson.TotalFreedomMod.TFM_Admin;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
@ -109,7 +109,7 @@ public class Command_logs extends TFM_Command
}.runTaskAsynchronously(TotalFreedomMod.plugin); }.runTaskAsynchronously(TotalFreedomMod.plugin);
} }
public static void deactivateSuperadmin(TFM_Superadmin superadmin) public static void deactivateSuperadmin(TFM_Admin superadmin)
{ {
for (String ip : superadmin.getIps()) for (String ip : superadmin.getIps())
{ {

View File

@ -38,7 +38,7 @@ public class Command_op extends TFM_Command
// if the player is not online // if the player is not online
if (player == null) if (player == null)
{ {
if (TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole) if (TFM_SuperadminList.isSuperAdmin(sender) || senderIsConsole)
{ {
player = server.getOfflinePlayer(args[0]); player = server.getOfflinePlayer(args[0]);
} }

View File

@ -38,7 +38,7 @@ public class Command_potion extends TFM_Command
} }
else if (args[0].equalsIgnoreCase("clearall")) else if (args[0].equalsIgnoreCase("clearall"))
{ {
if (!(TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole)) if (!(TFM_SuperadminList.isSuperAdmin(sender) || senderIsConsole))
{ {
playerMsg(TotalFreedomMod.MSG_NO_PERMS); playerMsg(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
@ -71,7 +71,7 @@ public class Command_potion extends TFM_Command
if (!target.equals(sender_p)) if (!target.equals(sender_p))
{ {
if (!TFM_SuperadminList.isUserSuperadmin(sender)) if (!TFM_SuperadminList.isSuperAdmin(sender))
{ {
playerMsg("Only superadmins can clear potion effects from other players."); playerMsg("Only superadmins can clear potion effects from other players.");
return true; return true;
@ -116,7 +116,7 @@ public class Command_potion extends TFM_Command
if (!target.equals(sender_p)) if (!target.equals(sender_p))
{ {
if (!TFM_SuperadminList.isUserSuperadmin(sender)) if (!TFM_SuperadminList.isSuperAdmin(sender))
{ {
sender.sendMessage("Only superadmins can apply potion effects to other players."); sender.sendMessage("Only superadmins can apply potion effects to other players.");
return true; return true;

View File

@ -1,7 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin; import me.StevenLawson.TotalFreedomMod.TFM_Admin;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler; import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
@ -23,7 +23,7 @@ public class Command_saconfig extends TFM_Command
{ {
if (args[0].equals("list")) if (args[0].equals("list"))
{ {
playerMsg("Superadmins: " + StringUtils.join(TFM_SuperadminList.getSuperadminNames(), ", "), ChatColor.GOLD); playerMsg("Superadmins: " + StringUtils.join(TFM_SuperadminList.getSuperadminUUIDs(), ", "), ChatColor.GOLD);
} }
else else
{ {
@ -37,7 +37,7 @@ public class Command_saconfig extends TFM_Command
{ {
TFM_Util.adminAction(sender.getName(), "Cleaning superadmin list", true); TFM_Util.adminAction(sender.getName(), "Cleaning superadmin list", true);
TFM_SuperadminList.cleanSuperadminList(true); TFM_SuperadminList.cleanSuperadminList(true);
playerMsg("Superadmins: " + StringUtils.join(TFM_SuperadminList.getSuperadminNames(), ", "), ChatColor.YELLOW); playerMsg("Superadmins: " + StringUtils.join(TFM_SuperadminList.getSuperadminUUIDs(), ", "), ChatColor.YELLOW);
} }
else else
{ {
@ -53,13 +53,13 @@ public class Command_saconfig extends TFM_Command
{ {
if (args[0].equalsIgnoreCase("info")) if (args[0].equalsIgnoreCase("info"))
{ {
if (!TFM_SuperadminList.isUserSuperadmin(sender)) if (!TFM_SuperadminList.isSuperAdmin(sender))
{ {
playerMsg(TotalFreedomMod.MSG_NO_PERMS); playerMsg(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
} }
TFM_Superadmin superadmin = TFM_SuperadminList.getAdminEntry(args[1].toLowerCase()); TFM_Admin superadmin = TFM_SuperadminList.getAdminEntry(args[1].toLowerCase());
if (superadmin == null) if (superadmin == null)
{ {
@ -101,7 +101,7 @@ public class Command_saconfig extends TFM_Command
} }
catch (PlayerNotFoundException ex) catch (PlayerNotFoundException ex)
{ {
TFM_Superadmin superadmin = TFM_SuperadminList.getAdminEntry(args[1].toLowerCase()); TFM_Admin superadmin = TFM_SuperadminList.getAdminEntry(args[1].toLowerCase());
if (superadmin != null) if (superadmin != null)
{ {
admin_name = superadmin.getName(); admin_name = superadmin.getName();
@ -142,7 +142,7 @@ public class Command_saconfig extends TFM_Command
{ {
} }
if (!TFM_SuperadminList.getSuperadminNames().contains(targetName.toLowerCase())) if (!TFM_SuperadminList.getSuperadminUUIDs().contains(targetName.toLowerCase()))
{ {
playerMsg("Superadmin not found: " + targetName); playerMsg("Superadmin not found: " + targetName);
return true; return true;

View File

@ -68,7 +68,7 @@ public class Command_stfu extends TFM_Command
int counter = 0; int counter = 0;
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
playerdata = TFM_PlayerData.getPlayerData(player); playerdata = TFM_PlayerData.getPlayerData(player);
playerdata.setMuted(true); playerdata.setMuted(true);
@ -118,7 +118,7 @@ public class Command_stfu extends TFM_Command
} }
else else
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
TFM_Util.adminAction(sender.getName(), "Muting " + player.getName(), true); TFM_Util.adminAction(sender.getName(), "Muting " + player.getName(), true);
playerdata.setMuted(true); playerdata.setMuted(true);

View File

@ -35,7 +35,7 @@ public class Command_survival extends TFM_Command
{ {
if (args[0].equalsIgnoreCase("-a")) if (args[0].equalsIgnoreCase("-a"))
{ {
if (!TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole) if (!TFM_SuperadminList.isSuperAdmin(sender) || senderIsConsole)
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
@ -50,7 +50,7 @@ public class Command_survival extends TFM_Command
return true; return true;
} }
if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) if (senderIsConsole || TFM_SuperadminList.isSuperAdmin(sender))
{ {
try try
{ {

View File

@ -27,7 +27,7 @@ public class Command_tag extends TFM_Command
{ {
if ("clearall".equals(args[0])) if ("clearall".equals(args[0]))
{ {
if (!TFM_SuperadminList.isUserSuperadmin(sender)) if (!TFM_SuperadminList.isSuperAdmin(sender))
{ {
playerMsg(TotalFreedomMod.MSG_NO_PERMS); playerMsg(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
@ -69,7 +69,7 @@ public class Command_tag extends TFM_Command
return true; return true;
} }
if (!TFM_SuperadminList.isUserSuperadmin(sender)) if (!TFM_SuperadminList.isSuperAdmin(sender))
{ {
for (String word : FORBIDDEN_WORDS) for (String word : FORBIDDEN_WORDS)
{ {
@ -98,7 +98,7 @@ public class Command_tag extends TFM_Command
{ {
if ("clear".equals(args[0])) if ("clear".equals(args[0]))
{ {
if (!TFM_SuperadminList.isUserSuperadmin(sender)) if (!TFM_SuperadminList.isSuperAdmin(sender))
{ {
playerMsg(TotalFreedomMod.MSG_NO_PERMS); playerMsg(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;

View File

@ -21,7 +21,7 @@ public class Command_tfbanlist extends TFM_Command
{ {
if (args[0].equalsIgnoreCase("purge")) if (args[0].equalsIgnoreCase("purge"))
{ {
if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) if (senderIsConsole || TFM_SuperadminList.isSuperAdmin(sender))
{ {
try try
{ {

View File

@ -22,7 +22,7 @@ public class Command_tfipbanlist extends TFM_Command
{ {
if (args[0].equalsIgnoreCase("purge")) if (args[0].equalsIgnoreCase("purge"))
{ {
if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender)) if (senderIsConsole || TFM_SuperadminList.isSuperAdmin(sender))
{ {
try try
{ {

View File

@ -56,7 +56,7 @@ public class Command_whitelist extends TFM_Command
} }
// all commands past this line are superadmin-only // all commands past this line are superadmin-only
if (!(senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender))) if (!(senderIsConsole || TFM_SuperadminList.isSuperAdmin(sender)))
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;

View File

@ -57,7 +57,7 @@ public class Command_whohas extends TFM_Command
if (player.getInventory().contains(material)) if (player.getInventory().contains(material))
{ {
players.add(player.getName()); players.add(player.getName());
if (smite & !TFM_SuperadminList.isUserSuperadmin(player)) if (smite & !TFM_SuperadminList.isSuperAdmin(player))
{ {
Command_smite.smite(player); Command_smite.smite(player);
} }

View File

@ -62,7 +62,7 @@ public abstract class TFM_Command
CommandPermissions permissions = commandClass.getAnnotation(CommandPermissions.class); CommandPermissions permissions = commandClass.getAnnotation(CommandPermissions.class);
if (permissions != null) if (permissions != null)
{ {
boolean is_super = TFM_SuperadminList.isUserSuperadmin(this.commandSender); boolean is_super = TFM_SuperadminList.isSuperAdmin(this.commandSender);
boolean is_senior = false; boolean is_senior = false;
if (is_super) if (is_super)
{ {

View File

@ -26,7 +26,7 @@ public class Module_list extends TFM_HTTPD_Module
for (Player player : onlinePlayers) for (Player player : onlinePlayers)
{ {
String prefix = ""; String prefix = "";
if (TFM_SuperadminList.isUserSuperadmin(player)) if (TFM_SuperadminList.isSuperAdmin(player))
{ {
if (TFM_SuperadminList.isSeniorAdmin(player)) if (TFM_SuperadminList.isSeniorAdmin(player))
{ {

View File

@ -34,14 +34,14 @@ public class Module_players extends TFM_HTTPD_Module
} }
// Super admins (non-telnet and non-senior) // Super admins (non-telnet and non-senior)
for (String superadmin : TFM_SuperadminList.getSuperadminNames()) for (String superadmin : TFM_SuperadminList.getSuperadminUUIDs())
{ {
if (TFM_SuperadminList.getSenioradminNames().contains(superadmin)) if (TFM_SuperadminList.getSenioradminUUIDs().contains(superadmin))
{ {
continue; continue;
} }
if (TFM_SuperadminList.getTelnetadminNames().contains(superadmin)) if (TFM_SuperadminList.getTelnetadminUUIDs().contains(superadmin))
{ {
continue; continue;
} }
@ -50,9 +50,9 @@ public class Module_players extends TFM_HTTPD_Module
} }
// Telnet admins (non-senior) // Telnet admins (non-senior)
for (String telnetadmin : TFM_SuperadminList.getTelnetadminNames()) for (String telnetadmin : TFM_SuperadminList.getTelnetadminUUIDs())
{ {
if (TFM_SuperadminList.getSenioradminNames().contains(telnetadmin)) if (TFM_SuperadminList.getSenioradminUUIDs().contains(telnetadmin))
{ {
continue; continue;
} }
@ -60,7 +60,7 @@ public class Module_players extends TFM_HTTPD_Module
} }
// Senior admins // Senior admins
for (String senioradmin : TFM_SuperadminList.getSenioradminNames()) for (String senioradmin : TFM_SuperadminList.getSenioradminUUIDs())
{ {
senioradmins.add(getName(senioradmin)); senioradmins.add(getName(senioradmin));
} }

View File

@ -12,7 +12,7 @@ import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Method; import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Method;
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Response; import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Response;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin; import me.StevenLawson.TotalFreedomMod.TFM_Admin;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import net.minecraft.util.org.apache.commons.io.FileUtils; import net.minecraft.util.org.apache.commons.io.FileUtils;
import net.minecraft.util.org.apache.commons.lang3.StringEscapeUtils; import net.minecraft.util.org.apache.commons.lang3.StringEscapeUtils;
@ -223,7 +223,7 @@ public class Module_schematic extends TFM_HTTPD_Module
private boolean isAuthorized(String remoteAddress) private boolean isAuthorized(String remoteAddress)
{ {
TFM_Superadmin entry = TFM_SuperadminList.getAdminEntryByIP(remoteAddress); TFM_Admin entry = TFM_SuperadminList.getAdminEntryByIP(remoteAddress);
return entry != null && entry.isActivated(); return entry != null && entry.isActivated();
} }

View File

@ -91,7 +91,7 @@ public class TFM_BlockListener implements Listener
if (TFM_ConfigEntry.PROTECTED_AREAS_ENABLED.getBoolean()) if (TFM_ConfigEntry.PROTECTED_AREAS_ENABLED.getBoolean())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
if (TFM_ProtectedArea.isInProtectedArea(blockLocation)) if (TFM_ProtectedArea.isInProtectedArea(blockLocation))
{ {
@ -161,7 +161,7 @@ public class TFM_BlockListener implements Listener
if (TFM_ConfigEntry.PROTECTED_AREAS_ENABLED.getBoolean()) if (TFM_ConfigEntry.PROTECTED_AREAS_ENABLED.getBoolean())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
if (TFM_ProtectedArea.isInProtectedArea(blockLocation)) if (TFM_ProtectedArea.isInProtectedArea(blockLocation))
{ {
@ -249,7 +249,7 @@ public class TFM_BlockListener implements Listener
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onRollbackBlockBreak(BlockBreakEvent event) public void onRollbackBlockBreak(BlockBreakEvent event)
{ {
if (!TFM_SuperadminList.isUserSuperadmin(event.getPlayer())) if (!TFM_SuperadminList.isSuperAdmin(event.getPlayer()))
{ {
TFM_RollbackManager.blockBreak(event); TFM_RollbackManager.blockBreak(event);
} }
@ -258,7 +258,7 @@ public class TFM_BlockListener implements Listener
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onRollbackBlockPlace(BlockPlaceEvent event) public void onRollbackBlockPlace(BlockPlaceEvent event)
{ {
if (!TFM_SuperadminList.isUserSuperadmin(event.getPlayer())) if (!TFM_SuperadminList.isSuperAdmin(event.getPlayer()))
{ {
TFM_RollbackManager.blockPlace(event); TFM_RollbackManager.blockPlace(event);
} }

View File

@ -8,6 +8,7 @@ import java.util.Map.Entry;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.*; import me.StevenLawson.TotalFreedomMod.*;
import me.StevenLawson.TotalFreedomMod.Commands.Command_landmine; import me.StevenLawson.TotalFreedomMod.Commands.Command_landmine;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList.PlayerEntry;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry; import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -96,7 +97,7 @@ public class TFM_PlayerListener implements Listener
{ {
case STICK: case STICK:
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
break; break;
} }
@ -330,7 +331,7 @@ public class TFM_PlayerListener implements Listener
boolean freeze = false; boolean freeze = false;
if (TotalFreedomMod.allPlayersFrozen) if (TotalFreedomMod.allPlayersFrozen)
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
freeze = true; freeze = true;
} }
@ -489,7 +490,7 @@ public class TFM_PlayerListener implements Listener
// Check for muted // Check for muted
if (playerdata.isMuted()) if (playerdata.isMuted())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
player.sendMessage(ChatColor.RED + "You are muted, STFU!"); player.sendMessage(ChatColor.RED + "You are muted, STFU!");
event.setCancelled(true); event.setCancelled(true);
@ -554,9 +555,9 @@ public class TFM_PlayerListener implements Listener
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{ {
String command = event.getMessage(); String command = event.getMessage();
Player player = event.getPlayer(); final Player player = event.getPlayer();
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
playerdata.setLastCommand(command); playerdata.setLastCommand(command);
if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT) if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT)
@ -582,7 +583,7 @@ public class TFM_PlayerListener implements Listener
// Block commands if player is muted // Block commands if player is muted
if (playerdata.isMuted()) if (playerdata.isMuted())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
for (String commandName : BLOCKED_MUTED_CMDS) for (String commandName : BLOCKED_MUTED_CMDS)
{ {
@ -614,11 +615,11 @@ public class TFM_PlayerListener implements Listener
event.setCancelled(true); event.setCancelled(true);
} }
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isSuperAdmin(player))
{ {
for (Player pl : Bukkit.getOnlinePlayers()) for (Player pl : Bukkit.getOnlinePlayers())
{ {
if (TFM_SuperadminList.isUserSuperadmin(pl) && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled()) if (TFM_SuperadminList.isSuperAdmin(pl) && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled())
{ {
TFM_Util.playerMsg(pl, player.getName() + ": " + command); TFM_Util.playerMsg(pl, player.getName() + ": " + command);
} }
@ -658,7 +659,6 @@ public class TFM_PlayerListener implements Listener
playerdata.clearHistory(); playerdata.clearHistory();
} }
// Log player quitting, because 1.7 doesn't do this
TFM_Log.info("[EXIT] " + player.getName() + " left the game.", true); TFM_Log.info("[EXIT] " + player.getName() + " left the game.", true);
} }
@ -678,7 +678,6 @@ public class TFM_PlayerListener implements Listener
playerdata.clearHistory(); playerdata.clearHistory();
} }
// Log player quitting, because 1.7 doesn't do this
TFM_Log.info("[EXIT] " + player.getName() + " left the game.", true); TFM_Log.info("[EXIT] " + player.getName() + " left the game.", true);
} }
@ -687,17 +686,32 @@ public class TFM_PlayerListener implements Listener
{ {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String ip = TFM_Util.getIp(player); final String ip = TFM_Util.getIp(player);
TFM_Log.info("[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip, true);
// Update player information
if (!TFM_PlayerList.getInstance().existsEntry(player))
{
TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player));
final PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player);
entry.setLastJoinUnix(TFM_Util.getUnixTime());
entry.setLastJoinName(player.getName());
entry.save();
}
else
{
// Preload the entry; the login unix is defaulted to the current time
final PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player);
entry.addIp(ip);
entry.save();
}
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
playerdata.setSuperadminIdVerified(null); playerdata.setSuperadminIdVerified(null);
TFM_Log.info("[JOIN] " + player.getName() + " (" + player.getUniqueId() + ") joined the game with IP address: " + ip, true);
TFM_PlayerList.getInstance().getEntry(player);
final boolean impostor = TFM_SuperadminList.isSuperadminImpostor(player); final boolean impostor = TFM_SuperadminList.isSuperadminImpostor(player);
if (impostor || TFM_SuperadminList.isUserSuperadmin(player)) if (impostor || TFM_SuperadminList.isSuperAdmin(player))
{ {
TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player)); TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));

View File

@ -3,7 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.BukkitTelnet.api.TelnetCommandEvent; import me.StevenLawson.BukkitTelnet.api.TelnetCommandEvent;
import me.StevenLawson.BukkitTelnet.api.TelnetPreLoginEvent; import me.StevenLawson.BukkitTelnet.api.TelnetPreLoginEvent;
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker; import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin; import me.StevenLawson.TotalFreedomMod.TFM_Admin;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -23,7 +23,7 @@ public class TFM_TelnetListener implements Listener
return; return;
} }
final TFM_Superadmin admin = TFM_SuperadminList.getAdminEntryByIP(ip, true); final TFM_Admin admin = TFM_SuperadminList.getAdminEntryByIP(ip, true);
if (admin == null || !(admin.isTelnetAdmin() || admin.isSeniorAdmin())) if (admin == null || !(admin.isTelnetAdmin() || admin.isSeniorAdmin()))
{ {

View File

@ -6,7 +6,7 @@ import java.util.List;
import net.minecraft.util.org.apache.commons.lang3.StringUtils; import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class TFM_Superadmin public class TFM_Admin
{ {
private final String name; private final String name;
private final String loginMessage; private final String loginMessage;
@ -17,7 +17,7 @@ public class TFM_Superadmin
private Date lastLogin; private Date lastLogin;
private boolean isActivated; private boolean isActivated;
public TFM_Superadmin(String name, List<String> ips, Date lastLogin, String loginMessage, boolean isSeniorAdmin, boolean isTelnetAdmin, List<String> consoleAliases, boolean isActivated) public TFM_Admin(String name, List<String> ips, Date lastLogin, String loginMessage, boolean isSeniorAdmin, boolean isTelnetAdmin, List<String> consoleAliases, boolean isActivated)
{ {
this.name = name.toLowerCase(); this.name = name.toLowerCase();
this.ips = ips; this.ips = ips;
@ -29,7 +29,7 @@ public class TFM_Superadmin
this.isActivated = isActivated; this.isActivated = isActivated;
} }
public TFM_Superadmin(String name, ConfigurationSection section) public TFM_Admin(String name, ConfigurationSection section)
{ {
this.name = name.toLowerCase(); this.name = name.toLowerCase();
this.ips = section.getStringList("ips"); this.ips = section.getStringList("ips");

View File

@ -79,12 +79,12 @@ public final class TFM_AdminWorld extends TFM_CustomWorld
public boolean addGuest(Player guest, Player supervisor) public boolean addGuest(Player guest, Player supervisor)
{ {
if (guest == supervisor || TFM_SuperadminList.isUserSuperadmin(guest)) if (guest == supervisor || TFM_SuperadminList.isSuperAdmin(guest))
{ {
return false; return false;
} }
if (TFM_SuperadminList.isUserSuperadmin(supervisor)) if (TFM_SuperadminList.isSuperAdmin(supervisor))
{ {
guestList.put(guest, supervisor); guestList.put(guest, supervisor);
wipeAccessCache(); wipeAccessCache();
@ -194,11 +194,11 @@ public final class TFM_AdminWorld extends TFM_CustomWorld
Boolean cached = accessCache.get(player); Boolean cached = accessCache.get(player);
if (cached == null) if (cached == null)
{ {
boolean canAccess = TFM_SuperadminList.isUserSuperadmin(player); boolean canAccess = TFM_SuperadminList.isSuperAdmin(player);
if (!canAccess) if (!canAccess)
{ {
Player supervisor = guestList.get(player); Player supervisor = guestList.get(player);
canAccess = supervisor != null && supervisor.isOnline() && TFM_SuperadminList.isUserSuperadmin(supervisor); canAccess = supervisor != null && supervisor.isOnline() && TFM_SuperadminList.isSuperAdmin(supervisor);
if (!canAccess) if (!canAccess)
{ {
guestList.remove(player); guestList.remove(player);

View File

@ -190,7 +190,7 @@ public class TFM_CommandBlocker
public static CommandBlockerRank getSenderRank(CommandSender sender) public static CommandBlockerRank getSenderRank(CommandSender sender)
{ {
if (!TFM_SuperadminList.isUserSuperadmin(sender)) if (!TFM_SuperadminList.isSuperAdmin(sender))
{ {
if (sender.isOp()) if (sender.isOp())
{ {

View File

@ -23,7 +23,6 @@ public class TFM_PlayerData
public final static Map<Player, TFM_PlayerData> userinfo = new HashMap<Player, TFM_PlayerData>(); public final static Map<Player, TFM_PlayerData> userinfo = new HashMap<Player, TFM_PlayerData>();
private final Player player; private final Player player;
private final String ip; private final String ip;
private final String username;
private boolean isFrozen = false; private boolean isFrozen = false;
private boolean isMuted = false; private boolean isMuted = false;
private boolean isHalted = false; private boolean isHalted = false;
@ -55,11 +54,10 @@ public class TFM_PlayerData
private boolean cmdspyEnabled = false; private boolean cmdspyEnabled = false;
private String tag = null; private String tag = null;
public TFM_PlayerData(Player player) private TFM_PlayerData(Player player)
{ {
this.player = player; this.player = player;
this.ip = player.getAddress().getAddress().getHostAddress(); this.ip = player.getAddress().getAddress().getHostAddress();
this.username = player.getName();
} }
public static TFM_PlayerData getPlayerData(Player player) public static TFM_PlayerData getPlayerData(Player player)
@ -74,7 +72,7 @@ public class TFM_PlayerData
Entry<Player, TFM_PlayerData> pair = it.next(); Entry<Player, TFM_PlayerData> pair = it.next();
TFM_PlayerData playerdataTest = pair.getValue(); TFM_PlayerData playerdataTest = pair.getValue();
if (playerdataTest.username.equalsIgnoreCase(player.getName())) if (playerdataTest.player.getName().equalsIgnoreCase(player.getName()))
{ {
if (Bukkit.getOnlineMode()) if (Bukkit.getOnlineMode())
{ {
@ -107,11 +105,6 @@ public class TFM_PlayerData
return this.ip; return this.ip;
} }
public String getPlayerName()
{
return this.username;
}
public boolean isOrbiting() public boolean isOrbiting()
{ {
return this.isOrbiting; return this.isOrbiting;
@ -325,7 +318,7 @@ public class TFM_PlayerData
{ {
private Player player; private Player player;
public ArrowShooter(Player player) private ArrowShooter(Player player)
{ {
this.player = player; this.player = player;
} }
@ -385,7 +378,7 @@ public class TFM_PlayerData
player.setOp(false); player.setOp(false);
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
player.setFlying(false); player.setFlying(false);
player.setDisplayName(username); player.setDisplayName(player.getName());
player.closeInventory(); player.closeInventory();
player.setTotalExperience(0); player.setTotalExperience(0);

View File

@ -1,22 +1,16 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import net.pravian.bukkitlib.YamlConfig;
import java.util.logging.Logger;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -25,13 +19,12 @@ public class TFM_PlayerList
private static final TFM_PlayerList INSTANCE = new TFM_PlayerList(); private static final TFM_PlayerList INSTANCE = new TFM_PlayerList();
private static final String USERLIST_FILENAME = "playerlist.yml"; private static final String USERLIST_FILENAME = "playerlist.yml";
private final Map<UUID, PlayerEntry> playerList; private final Map<UUID, PlayerEntry> playerList;
private final YamlConfiguration config;
private File configFile; private File configFile;
private TFM_PlayerList() private TFM_PlayerList()
{ {
this.playerList = new HashMap<UUID, PlayerEntry>(); this.playerList = new HashMap<UUID, PlayerEntry>();
this.config = new YamlConfiguration(); this.configFile = new File(TotalFreedomMod.plugin.getDataFolder(), USERLIST_FILENAME);
} }
public File getConfigFile() public File getConfigFile()
@ -43,7 +36,8 @@ public class TFM_PlayerList
{ {
playerList.clear(); playerList.clear();
configFile = new File(TotalFreedomMod.plugin.getDataFolder(), USERLIST_FILENAME); configFile = getConfigFile();
final YamlConfiguration config = new YamlConfiguration();
if (configFile.exists()) if (configFile.exists())
{ {
@ -118,15 +112,21 @@ public class TFM_PlayerList
return null; return null;
} }
public boolean existsEntry(Player player)
{
return playerList.containsKey(player.getUniqueId());
}
public PlayerEntry getEntry(Player player) public PlayerEntry getEntry(Player player)
{ {
final UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
PlayerEntry entry = playerList.get(uuid); if (existsEntry(player))
if (entry == null)
{ {
entry = new PlayerEntry(uuid); return playerList.get(uuid);
}
final PlayerEntry entry = new PlayerEntry(uuid);
entry.setFirstJoinName(player.getName()); entry.setFirstJoinName(player.getName());
entry.setLastJoinName(player.getName()); entry.setLastJoinName(player.getName());
@ -135,15 +135,18 @@ public class TFM_PlayerList
entry.setFirstJoinUnix(unix); entry.setFirstJoinUnix(unix);
entry.setLastJoinUnix(unix); entry.setLastJoinUnix(unix);
entry.addIp(TFM_Util.getIp(player));
entry.save(); entry.save();
playerList.put(uuid, entry); playerList.put(uuid, entry);
}
return entry; return entry;
} }
public void purgeAll() public void purgeAll()
{ {
final YamlConfiguration config = loadConfig();
// Clear the config entries // Clear the config entries
for (String key : config.getKeys(false)) for (String key : config.getKeys(false))
{ {
@ -165,6 +168,23 @@ public class TFM_PlayerList
load(); load();
} }
private YamlConfiguration loadConfig()
{
final YamlConfiguration config = new YamlConfiguration();
try
{
config.load(configFile);
}
catch (Exception ex)
{
TFM_Log.severe("Could not load player config file: " + ex.getMessage());
TFM_Log.severe(ex);
purgeAll();
return null;
}
return config;
}
/*public String searchByPartialName(String needle) /*public String searchByPartialName(String needle)
{ {
needle = needle.toLowerCase().trim(); needle = needle.toLowerCase().trim();
@ -294,6 +314,7 @@ public class TFM_PlayerList
throw new IllegalStateException("Entry is not complete"); throw new IllegalStateException("Entry is not complete");
} }
final YamlConfiguration config = loadConfig();
final ConfigurationSection section; final ConfigurationSection section;
if (config.isConfigurationSection(uuid.toString())) if (config.isConfigurationSection(uuid.toString()))

View File

@ -32,7 +32,7 @@ public enum TFM_PlayerRank
return fromSender(sender).getLoginMessage(); return fromSender(sender).getLoginMessage();
} }
final TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry((Player) sender); final TFM_Admin entry = TFM_SuperadminList.getAdminEntry((Player) sender);
if (entry == null) if (entry == null)
{ {
@ -69,7 +69,7 @@ public enum TFM_PlayerRank
} }
final TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry((Player) sender); final TFM_Admin entry = TFM_SuperadminList.getAdminEntry((Player) sender);
final TFM_PlayerRank rank; final TFM_PlayerRank rank;

View File

@ -54,7 +54,7 @@ public class TFM_ServerInterface
{ {
name = name.toLowerCase().trim(); name = name.toLowerCase().trim();
if (TFM_SuperadminList.getSuperadminNames().contains(name)) if (TFM_SuperadminList.getSuperadminUUIDs().contains(name))
{ {
TFM_Log.info("Not banning username " + name + ": is superadmin"); TFM_Log.info("Not banning username " + name + ": is superadmin");
return; return;
@ -164,11 +164,11 @@ public class TFM_ServerInterface
return; return;
} }
// not safe to use TFM_Util.isUserSuperadmin for player logging in because player.getAddress() will return a null until after player login. // not safe to use TFM_Util.isSuperAdmin for player logging in because player.getAddress() will return a null until after player login.
boolean isSuperadmin; boolean isSuperadmin;
if (server.getOnlineMode()) if (server.getOnlineMode())
{ {
isSuperadmin = TFM_SuperadminList.getSuperadminNames().contains(username.toLowerCase()); isSuperadmin = TFM_SuperadminList.getSuperadminUUIDs().contains(username.toLowerCase());
} }
else else
{ {
@ -331,7 +331,7 @@ public class TFM_ServerInterface
{ {
for (Player p : server.getOnlinePlayers()) for (Player p : server.getOnlinePlayers())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(p)) if (!TFM_SuperadminList.isSuperAdmin(p))
{ {
p.kickPlayer("You have been kicked to free up room for an admin."); p.kickPlayer("You have been kicked to free up room for an admin.");
count--; count--;

View File

@ -6,10 +6,13 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import me.StevenLawson.TotalFreedomMod.Commands.Command_logs; import me.StevenLawson.TotalFreedomMod.Commands.Command_logs;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -22,36 +25,57 @@ import org.bukkit.util.FileUtil;
public class TFM_SuperadminList public class TFM_SuperadminList
{ {
private static final Map<String, TFM_Superadmin> superadminList = new HashMap<String, TFM_Superadmin>(); private static final Map<UUID, TFM_Admin> superadminList;
private static List<String> superadminNames = new ArrayList<String>(); private static final Set<UUID> superadminUUIDs;
private static List<String> senioradminNames = new ArrayList<String>(); private static final Set<UUID> telnetadminUUIDs;
private static List<String> telnetadminNames = new ArrayList<String>(); private static final Set<UUID> senioradminUUIDs;
private static List<String> superadminIPs = new ArrayList<String>(); private static final Set<String> senioradminAliases;
private static final Set<String> superadminIps;
private static int cleanThreshold = 24 * 7; // 1 Week in hours private static int cleanThreshold = 24 * 7; // 1 Week in hours
static
{
superadminList = new HashMap<UUID, TFM_Admin>();
superadminUUIDs = new HashSet<UUID>();
telnetadminUUIDs = new HashSet<UUID>();
senioradminUUIDs = new HashSet<UUID>();
senioradminAliases = new HashSet<String>();
superadminIps = new HashSet<String>();
}
private TFM_SuperadminList() private TFM_SuperadminList()
{ {
throw new AssertionError(); throw new AssertionError();
} }
public static List<String> getSuperadminIPs() public static Set<UUID> getSuperadminUUIDs()
{ {
return Collections.unmodifiableList(superadminIPs); return Collections.unmodifiableSet(superadminUUIDs);
} }
public static List<String> getSuperadminNames() public static Set<UUID> getTelnetadminUUIDs()
{ {
return Collections.unmodifiableList(superadminNames); return Collections.unmodifiableSet(telnetadminUUIDs);
} }
public static List<String> getTelnetadminNames() public static Set<UUID> getSenioradminUUIDs()
{ {
return Collections.unmodifiableList(telnetadminNames); return Collections.unmodifiableSet(senioradminUUIDs);
} }
public static List<String> getSenioradminNames() public static Set<String> getConsoleAliases()
{ {
return Collections.unmodifiableList(senioradminNames); return Collections.unmodifiableSet(senioradminAliases);
}
public static Set<String> getSuperadminIps()
{
return Collections.unmodifiableSet(superadminIps);
}
public File getConfigFile()
{
return new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE);
} }
public static void loadSuperadminList() public static void loadSuperadminList()
@ -61,23 +85,36 @@ public class TFM_SuperadminList
superadminList.clear(); superadminList.clear();
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE); TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE);
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
final FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold); cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold);
if (config.isConfigurationSection("superadmins")) if (config.isConfigurationSection("superadmins"))
{ {
ConfigurationSection section = config.getConfigurationSection("superadmins"); // TODO: Loading from old
}
for (String admin_name : section.getKeys(false)) if (!config.isConfigurationSection("admins"))
{ {
TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, section.getConfigurationSection(admin_name)); TFM_Log.warning("Missing admins section in superadmin.yml.");
superadminList.put(admin_name.toLowerCase(), superadmin); return;
} }
}
else final ConfigurationSection section = config.getConfigurationSection("superadmins");
for (String uuidString : section.getKeys(false))
{ {
TFM_Log.warning("Missing superadmins section in superadmin.yml."); if (!TFM_Util.isUniqueId(uuidString))
{
TFM_Log.warning("Invalid Unique ID: " + uuidString + " in superadmin.yml, ignoring");
continue;
}
final UUID uuid = UUID.fromString(uuidString);
final TFM_Admin superadmin = new TFM_Admin(uuid, section.getConfigurationSection(uuidString));
superadminList.put(uuid, superadmin);
} }
updateIndexLists(); updateIndexLists();
@ -90,57 +127,53 @@ public class TFM_SuperadminList
public static void backupSavedList() public static void backupSavedList()
{ {
File a = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE); final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE);
File b = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE + ".bak"); final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE + ".bak");
FileUtil.copy(a, b); FileUtil.copy(oldYaml, newYaml);
} }
public static void updateIndexLists() public static void updateIndexLists()
{ {
superadminNames.clear(); superadminUUIDs.clear();
telnetadminNames.clear(); telnetadminUUIDs.clear();
senioradminNames.clear(); senioradminUUIDs.clear();
superadminIPs.clear(); senioradminAliases.clear();
superadminIps.clear();
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator(); final Iterator<Entry<UUID, TFM_Admin>> it = superadminList.entrySet().iterator();
while (it.hasNext()) while (it.hasNext())
{ {
Entry<String, TFM_Superadmin> pair = it.next(); final Entry<UUID, TFM_Admin> pair = it.next();
String name = pair.getKey().toLowerCase(); final UUID uuid = pair.getKey();
TFM_Superadmin superadmin = pair.getValue(); TFM_Admin superadmin = pair.getValue();
if (superadmin.isActivated()) if (superadmin.isActivated())
{ {
superadminNames.add(name); superadminUUIDs.add(uuid);
for (String ip : superadmin.getIps()) for (String ip : superadmin.getIps())
{ {
superadminIPs.add(ip); superadminIps.add(ip);
} }
if (superadmin.isSeniorAdmin()) if (superadmin.isSeniorAdmin())
{ {
senioradminNames.add(name); senioradminUUIDs.add(uuid);
for (String console_alias : superadmin.getConsoleAliases()) for (String alias : superadmin.getConsoleAliases())
{ {
senioradminNames.add(console_alias.toLowerCase()); senioradminAliases.add(alias.toLowerCase());
} }
} }
if (superadmin.isTelnetAdmin()) if (superadmin.isTelnetAdmin())
{ {
telnetadminNames.add(name); telnetadminUUIDs.add(uuid);
} }
} }
} }
superadminNames = TFM_Util.removeDuplicates(superadminNames);
telnetadminNames = TFM_Util.removeDuplicates(telnetadminNames);
senioradminNames = TFM_Util.removeDuplicates(senioradminNames);
superadminIPs = TFM_Util.removeDuplicates(superadminIPs);
TFM_AdminWorld.getInstance().wipeAccessCache(); TFM_AdminWorld.getInstance().wipeAccessCache();
} }
@ -154,21 +187,22 @@ public class TFM_SuperadminList
config.set("clean_threshold_hours", cleanThreshold); config.set("clean_threshold_hours", cleanThreshold);
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator(); Iterator<Entry<UUID, TFM_Admin>> it = superadminList.entrySet().iterator();
while (it.hasNext()) while (it.hasNext())
{ {
Entry<String, TFM_Superadmin> pair = it.next(); Entry<UUID, TFM_Admin> pair = it.next();
String admin_name = pair.getKey().toLowerCase(); UUID uuid = pair.getKey();
TFM_Superadmin superadmin = pair.getValue(); TFM_Admin superadmin = pair.getValue();
config.set("superadmins." + admin_name + ".ips", TFM_Util.removeDuplicates(superadmin.getIps())); config.set("superadmins." + uuid + ".last_login_name", superadmin.getLastLoginName());
config.set("superadmins." + admin_name + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin())); config.set("superadmins." + uuid + ".is_activated", superadmin.isActivated());
config.set("superadmins." + admin_name + ".custom_login_message", superadmin.getCustomLoginMessage()); config.set("superadmins." + uuid + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
config.set("superadmins." + admin_name + ".is_senior_admin", superadmin.isSeniorAdmin()); config.set("superadmins." + uuid + ".custom_login_message", superadmin.getCustomLoginMessage());
config.set("superadmins." + admin_name + ".is_telnet_admin", superadmin.isTelnetAdmin()); config.set("superadmins." + uuid + ".is_senior_admin", superadmin.isSeniorAdmin());
config.set("superadmins." + admin_name + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases())); config.set("superadmins." + uuid + ".is_telnet_admin", superadmin.isTelnetAdmin());
config.set("superadmins." + admin_name + ".is_activated", superadmin.isActivated()); config.set("superadmins." + uuid + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases()));
config.set("superadmins." + uuid + ".ips", TFM_Util.removeDuplicates(superadmin.getIps()));
} }
config.save(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); config.save(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
@ -179,15 +213,15 @@ public class TFM_SuperadminList
} }
} }
public static TFM_Superadmin getAdminEntry(Player player) public static TFM_Admin getAdminEntry(Player player)
{ {
final String name = player.getName().toLowerCase(); final UUID uuid = player.getUniqueId();
if (Bukkit.getOnlineMode()) if (Bukkit.getOnlineMode())
{ {
if (superadminList.containsKey(name)) if (superadminList.containsKey(uuid))
{ {
return superadminList.get(name); return superadminList.get(uuid);
} }
} }
@ -207,37 +241,35 @@ public class TFM_SuperadminList
} }
@Deprecated @Deprecated
public static TFM_Superadmin getAdminEntry(String name) public static TFM_Admin getAdminEntry(String name)
{ {
name = name.toLowerCase(); for (UUID uuid : superadminList.keySet())
if (superadminList.containsKey(name))
{ {
return superadminList.get(name); if (superadminList.get(uuid).getLastLoginName().equalsIgnoreCase(name))
{
return superadminList.get(uuid);
}
} }
else
{
return null; return null;
} }
}
public static TFM_Superadmin getAdminEntryByIP(String ip) public static TFM_Admin getAdminEntryByIP(String ip)
{ {
return getAdminEntryByIP(ip, false); return getAdminEntryByIP(ip, false);
} }
public static TFM_Superadmin getAdminEntryByIP(String needleIP, boolean fuzzy) public static TFM_Admin getAdminEntryByIP(String needleIp, boolean fuzzy)
{ {
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator(); Iterator<Entry<UUID, TFM_Admin>> it = superadminList.entrySet().iterator();
while (it.hasNext()) while (it.hasNext())
{ {
Entry<String, TFM_Superadmin> pair = it.next(); Entry<UUID, TFM_Admin> pair = it.next();
TFM_Superadmin superadmin = pair.getValue(); TFM_Admin superadmin = pair.getValue();
if (fuzzy) if (fuzzy)
{ {
for (String haystackIP : superadmin.getIps()) for (String haystackIP : superadmin.getIps())
{ {
if (TFM_Util.fuzzyIpMatch(needleIP, haystackIP, 3)) if (TFM_Util.fuzzyIpMatch(needleIp, haystackIP, 3))
{ {
return superadmin; return superadmin;
} }
@ -245,7 +277,7 @@ public class TFM_SuperadminList
} }
else else
{ {
if (superadmin.getIps().contains(needleIP)) if (superadmin.getIps().contains(needleIp))
{ {
return superadmin; return superadmin;
} }
@ -256,7 +288,7 @@ public class TFM_SuperadminList
public static void updateLastLogin(Player player) public static void updateLastLogin(Player player)
{ {
TFM_Superadmin admin_entry = getAdminEntry(player); TFM_Admin admin_entry = getAdminEntry(player);
if (admin_entry != null) if (admin_entry != null)
{ {
admin_entry.setLastLogin(new Date()); admin_entry.setLastLogin(new Date());
@ -269,24 +301,23 @@ public class TFM_SuperadminList
return isSeniorAdmin(user, false); return isSeniorAdmin(user, false);
} }
public static boolean isSeniorAdmin(CommandSender user, boolean verifySuperadmin) public static boolean isSeniorAdmin(CommandSender sender, boolean verifySuperadmin)
{ {
if (verifySuperadmin) if (verifySuperadmin)
{ {
if (!isUserSuperadmin(user)) if (!isSuperAdmin(sender))
{ {
return false; return false;
} }
} }
String username = user.getName().toLowerCase();
if (!(user instanceof Player)) if (!(sender instanceof Player))
{ {
return senioradminNames.contains(username); return senioradminUUIDs.contains(((Player) sender).getUniqueId());
} }
TFM_Superadmin entry = getAdminEntry((Player) user); final TFM_Admin entry = getAdminEntry((Player) sender);
if (entry != null) if (entry != null)
{ {
return entry.isSeniorAdmin(); return entry.isSeniorAdmin();
@ -295,16 +326,16 @@ public class TFM_SuperadminList
return false; return false;
} }
public static boolean isUserSuperadmin(CommandSender user) public static boolean isSuperAdmin(CommandSender sender)
{ {
if (!(user instanceof Player)) if (!(sender instanceof Player))
{ {
return true; return true;
} }
if (Bukkit.getOnlineMode()) if (Bukkit.getOnlineMode())
{ {
if (superadminNames.contains(user.getName().toLowerCase())) if (superadminUUIDs.contains(((Player) sender).getUniqueId()));
{ {
return true; return true;
} }
@ -312,16 +343,16 @@ public class TFM_SuperadminList
try try
{ {
String ip = ((Player) user).getAddress().getAddress().getHostAddress(); final String ip = TFM_Util.getIp((Player) sender);
if (ip != null && !ip.isEmpty()) if (ip != null && !ip.isEmpty())
{ {
if (superadminIPs.contains(ip)) if (superadminIps.contains(ip))
{ {
return true; return true;
} }
} }
} }
catch (Exception ex) catch (RuntimeException ex)
{ {
return false; return false;
} }
@ -335,14 +366,14 @@ public class TFM_SuperadminList
{ {
ip = ip.trim(); ip = ip.trim();
if (superadminIPs.contains(ip)) if (superadminIps.contains(ip))
{ {
return true; return true;
} }
else else
{ {
String matchIp = null; String matchIp = null;
for (String testIp : getSuperadminIPs()) for (String testIp : getSuperadminIps())
{ {
if (TFM_Util.fuzzyIpMatch(ip, testIp, 3)) if (TFM_Util.fuzzyIpMatch(ip, testIp, 3))
{ {
@ -353,7 +384,7 @@ public class TFM_SuperadminList
if (matchIp != null) if (matchIp != null)
{ {
TFM_Superadmin entry = getAdminEntryByIP(matchIp); TFM_Admin entry = getAdminEntryByIP(matchIp);
if (entry != null) if (entry != null)
{ {
@ -386,9 +417,9 @@ public class TFM_SuperadminList
Player player = (Player) user; Player player = (Player) user;
if (superadminNames.contains(player.getName().toLowerCase())) if (superadminUUIDs.contains(player.getName().toLowerCase()))
{ {
return !isUserSuperadmin(player); return !isSuperAdmin(player);
} }
return false; return false;
@ -402,14 +433,14 @@ public class TFM_SuperadminList
if (superadminList.containsKey(username)) if (superadminList.containsKey(username))
{ {
TFM_Superadmin superadmin = superadminList.get(username); TFM_Admin superadmin = superadminList.get(username);
superadmin.setActivated(true); superadmin.setActivated(true);
superadmin.getIps().addAll(ips); superadmin.getIps().addAll(ips);
superadmin.setLastLogin(new Date()); superadmin.setLastLogin(new Date());
} }
else else
{ {
TFM_Superadmin superadmin = new TFM_Superadmin(username, ips, new Date(), "", false, false, new ArrayList<String>(), true); TFM_Admin superadmin = new TFM_Admin(username, ips, new Date(), "", false, false, new ArrayList<String>(), true);
superadminList.put(username.toLowerCase(), superadmin); superadminList.put(username.toLowerCase(), superadmin);
} }
@ -442,7 +473,7 @@ public class TFM_SuperadminList
if (superadminList.containsKey(username)) if (superadminList.containsKey(username))
{ {
TFM_Superadmin superadmin = superadminList.get(username); TFM_Admin superadmin = superadminList.get(username);
superadmin.setActivated(false); superadmin.setActivated(false);
Command_logs.deactivateSuperadmin(superadmin); Command_logs.deactivateSuperadmin(superadmin);
saveSuperadminList(); saveSuperadminList();
@ -463,11 +494,11 @@ public class TFM_SuperadminList
{ {
try try
{ {
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator(); Iterator<Entry<String, TFM_Admin>> it = superadminList.entrySet().iterator();
while (it.hasNext()) while (it.hasNext())
{ {
Entry<String, TFM_Superadmin> pair = it.next(); Entry<String, TFM_Admin> pair = it.next();
TFM_Superadmin superadmin = pair.getValue(); TFM_Admin superadmin = pair.getValue();
if (superadmin.isActivated() && !superadmin.isSeniorAdmin()) if (superadmin.isActivated() && !superadmin.isSeniorAdmin())
{ {
Date lastLogin = superadmin.getLastLogin(); Date lastLogin = superadmin.getLastLogin();
@ -504,7 +535,7 @@ public class TFM_SuperadminList
return true; return true;
} }
TFM_Superadmin entry = getAdminEntry(username); TFM_Admin entry = getAdminEntry(username);
if (entry != null) if (entry != null)
{ {
return entry.getIps().contains(ip); return entry.getIps().contains(ip);

View File

@ -93,6 +93,20 @@ public class TFM_Util
throw new AssertionError(); throw new AssertionError();
} }
public static boolean isUniqueId(String uuid)
{
try
{
UUID.fromString(uuid);
}
catch (IllegalArgumentException ex)
{
return false;
}
return true;
}
public static void bcastMsg(String message, ChatColor color) public static void bcastMsg(String message, ChatColor color)
{ {
TFM_Log.info(message, true); TFM_Log.info(message, true);
@ -139,6 +153,11 @@ public class TFM_Util
Math.round(location.getZ())); Math.round(location.getZ()));
} }
public static String formatPlayer(Player player)
{
return player.getName() + " (" + player.getUniqueId() + ")";
}
public static void gotoWorld(CommandSender sender, String targetworld) public static void gotoWorld(CommandSender sender, String targetworld)
{ {
if (sender instanceof Player) if (sender instanceof Player)
@ -737,7 +756,7 @@ public class TFM_Util
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{ {
if (TFM_SuperadminList.isUserSuperadmin(player)) if (TFM_SuperadminList.isSuperAdmin(player))
{ {
player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + name + ": " + ChatColor.AQUA + message); player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + name + ": " + ChatColor.AQUA + message);
} }

View File

@ -118,7 +118,7 @@ public class TFM_WorldEditBridge
public void validateSelection(final Player player) public void validateSelection(final Player player)
{ {
if (TFM_SuperadminList.isUserSuperadmin(player)) if (TFM_SuperadminList.isSuperAdmin(player))
{ {
return; return;
} }

View File

@ -1,34 +1,16 @@
# Amount of hours after which admins are set to be deactivated when cleaning the superadmin list.
clean_threshold_hours: 168 clean_threshold_hours: 168
superadmins:
darthsalamon: admins:
ips: b3c3b05a-a52d-33a6-a9c6-6e5063e00f0a:
- 80.60.73.144 last_login_name: DarthSalamon
- 213.211.159.63 - 127.0.0.1
last_login: Fri, 9 Nov 2012 03:09:14 -0500 last_login: Fri, 9 Nov 2012 03:09:14 -0500
custom_login_message: a &5Developer&b! custom_login_message: the &5Lead Executive Developer&b.
is_senior_admin: true is_senior_admin: true
is_telnet_admin: true is_telnet_admin: true
console_aliases: console_aliases:
- darth - darth
is_activated: true is_activated: true
madgeek1450:
ips: # Todo: Add mark and madgeek
- 127.0.0.1
- 8.8.8.8
last_login: Sun, 11 Nov 2012 01:09:14 -0500
custom_login_message: the &4Co-Founder&b and &6Master-ass-kicker&b.
is_senior_admin: true
is_telnet_admin: true
console_aliases:
- madgeek
is_activated: true
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_senior_admin: true
is_telnet_admin: true
console_aliases: []
is_activated: true