[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!
#Fri Apr 04 16:47:53 CEST 2014
build.number=708
#Wed Apr 09 20:26:09 CEST 2014
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);
for (Player player : server.getOnlinePlayers())
{
if (!TFM_SuperadminList.isUserSuperadmin(player))
if (!TFM_SuperadminList.isSuperAdmin(player))
{
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
{
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);
}

View file

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

View file

@ -36,7 +36,7 @@ public class Command_cartsit extends TFM_Command
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.");
return true;

View file

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

View file

@ -39,7 +39,7 @@ public class Command_doom extends TFM_Command
final String IP = player.getAddress().getAddress().getHostAddress().trim();
// 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_SuperadminList.removeSuperadmin(player);

View file

@ -44,7 +44,7 @@ public class Command_fr extends TFM_Command
playerMsg("Players are now frozen.");
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);
}

View file

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

View file

@ -38,7 +38,7 @@ public class Command_invis extends TFM_Command
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
{
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);
player.setHealth(0.0);

View file

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

View file

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List;
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_Util;
import org.apache.commons.lang.StringUtils;
@ -55,7 +55,7 @@ public class Command_list extends TFM_Command
final List<String> names = new ArrayList<String>();
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)
{

View file

@ -11,7 +11,7 @@ import java.util.Map;
import java.util.Map.Entry;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
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.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
@ -109,7 +109,7 @@ public class Command_logs extends TFM_Command
}.runTaskAsynchronously(TotalFreedomMod.plugin);
}
public static void deactivateSuperadmin(TFM_Superadmin superadmin)
public static void deactivateSuperadmin(TFM_Admin superadmin)
{
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 (player == null)
{
if (TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole)
if (TFM_SuperadminList.isSuperAdmin(sender) || senderIsConsole)
{
player = server.getOfflinePlayer(args[0]);
}

View file

@ -38,7 +38,7 @@ public class Command_potion extends TFM_Command
}
else if (args[0].equalsIgnoreCase("clearall"))
{
if (!(TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole))
if (!(TFM_SuperadminList.isSuperAdmin(sender) || senderIsConsole))
{
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
return true;
@ -71,7 +71,7 @@ public class Command_potion extends TFM_Command
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.");
return true;
@ -116,7 +116,7 @@ public class Command_potion extends TFM_Command
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.");
return true;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -56,7 +56,7 @@ public class Command_whitelist extends TFM_Command
}
// 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);
return true;

View file

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

View file

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

View file

@ -26,7 +26,7 @@ public class Module_list extends TFM_HTTPD_Module
for (Player player : onlinePlayers)
{
String prefix = "";
if (TFM_SuperadminList.isUserSuperadmin(player))
if (TFM_SuperadminList.isSuperAdmin(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)
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;
}
if (TFM_SuperadminList.getTelnetadminNames().contains(superadmin))
if (TFM_SuperadminList.getTelnetadminUUIDs().contains(superadmin))
{
continue;
}
@ -50,9 +50,9 @@ public class Module_players extends TFM_HTTPD_Module
}
// 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;
}
@ -60,7 +60,7 @@ public class Module_players extends TFM_HTTPD_Module
}
// Senior admins
for (String senioradmin : TFM_SuperadminList.getSenioradminNames())
for (String senioradmin : TFM_SuperadminList.getSenioradminUUIDs())
{
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.Response;
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 net.minecraft.util.org.apache.commons.io.FileUtils;
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)
{
TFM_Superadmin entry = TFM_SuperadminList.getAdminEntryByIP(remoteAddress);
TFM_Admin entry = TFM_SuperadminList.getAdminEntryByIP(remoteAddress);
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_SuperadminList.isUserSuperadmin(player))
if (!TFM_SuperadminList.isSuperAdmin(player))
{
if (TFM_ProtectedArea.isInProtectedArea(blockLocation))
{
@ -161,7 +161,7 @@ public class TFM_BlockListener implements Listener
if (TFM_ConfigEntry.PROTECTED_AREAS_ENABLED.getBoolean())
{
if (!TFM_SuperadminList.isUserSuperadmin(player))
if (!TFM_SuperadminList.isSuperAdmin(player))
{
if (TFM_ProtectedArea.isInProtectedArea(blockLocation))
{
@ -249,7 +249,7 @@ public class TFM_BlockListener implements Listener
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onRollbackBlockBreak(BlockBreakEvent event)
{
if (!TFM_SuperadminList.isUserSuperadmin(event.getPlayer()))
if (!TFM_SuperadminList.isSuperAdmin(event.getPlayer()))
{
TFM_RollbackManager.blockBreak(event);
}
@ -258,7 +258,7 @@ public class TFM_BlockListener implements Listener
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onRollbackBlockPlace(BlockPlaceEvent event)
{
if (!TFM_SuperadminList.isUserSuperadmin(event.getPlayer()))
if (!TFM_SuperadminList.isSuperAdmin(event.getPlayer()))
{
TFM_RollbackManager.blockPlace(event);
}

View file

@ -8,6 +8,7 @@ import java.util.Map.Entry;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.*;
import me.StevenLawson.TotalFreedomMod.Commands.Command_landmine;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList.PlayerEntry;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
@ -96,7 +97,7 @@ public class TFM_PlayerListener implements Listener
{
case STICK:
{
if (!TFM_SuperadminList.isUserSuperadmin(player))
if (!TFM_SuperadminList.isSuperAdmin(player))
{
break;
}
@ -330,7 +331,7 @@ public class TFM_PlayerListener implements Listener
boolean freeze = false;
if (TotalFreedomMod.allPlayersFrozen)
{
if (!TFM_SuperadminList.isUserSuperadmin(player))
if (!TFM_SuperadminList.isSuperAdmin(player))
{
freeze = true;
}
@ -489,7 +490,7 @@ public class TFM_PlayerListener implements Listener
// Check for muted
if (playerdata.isMuted())
{
if (!TFM_SuperadminList.isUserSuperadmin(player))
if (!TFM_SuperadminList.isSuperAdmin(player))
{
player.sendMessage(ChatColor.RED + "You are muted, STFU!");
event.setCancelled(true);
@ -554,9 +555,9 @@ public class TFM_PlayerListener implements Listener
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{
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);
if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT)
@ -582,7 +583,7 @@ public class TFM_PlayerListener implements Listener
// Block commands if player is muted
if (playerdata.isMuted())
{
if (!TFM_SuperadminList.isUserSuperadmin(player))
if (!TFM_SuperadminList.isSuperAdmin(player))
{
for (String commandName : BLOCKED_MUTED_CMDS)
{
@ -614,11 +615,11 @@ public class TFM_PlayerListener implements Listener
event.setCancelled(true);
}
if (!TFM_SuperadminList.isUserSuperadmin(player))
if (!TFM_SuperadminList.isSuperAdmin(player))
{
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);
}
@ -658,7 +659,6 @@ public class TFM_PlayerListener implements Listener
playerdata.clearHistory();
}
// Log player quitting, because 1.7 doesn't do this
TFM_Log.info("[EXIT] " + player.getName() + " left the game.", true);
}
@ -678,7 +678,6 @@ public class TFM_PlayerListener implements Listener
playerdata.clearHistory();
}
// Log player quitting, because 1.7 doesn't do this
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 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);
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);
if (impostor || TFM_SuperadminList.isUserSuperadmin(player))
if (impostor || TFM_SuperadminList.isSuperAdmin(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.TelnetPreLoginEvent;
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 org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@ -23,7 +23,7 @@ public class TFM_TelnetListener implements Listener
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()))
{

View file

@ -6,7 +6,7 @@ import java.util.List;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.configuration.ConfigurationSection;
public class TFM_Superadmin
public class TFM_Admin
{
private final String name;
private final String loginMessage;
@ -17,7 +17,7 @@ public class TFM_Superadmin
private Date lastLogin;
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.ips = ips;
@ -29,7 +29,7 @@ public class TFM_Superadmin
this.isActivated = isActivated;
}
public TFM_Superadmin(String name, ConfigurationSection section)
public TFM_Admin(String name, ConfigurationSection section)
{
this.name = name.toLowerCase();
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)
{
if (guest == supervisor || TFM_SuperadminList.isUserSuperadmin(guest))
if (guest == supervisor || TFM_SuperadminList.isSuperAdmin(guest))
{
return false;
}
if (TFM_SuperadminList.isUserSuperadmin(supervisor))
if (TFM_SuperadminList.isSuperAdmin(supervisor))
{
guestList.put(guest, supervisor);
wipeAccessCache();
@ -194,11 +194,11 @@ public final class TFM_AdminWorld extends TFM_CustomWorld
Boolean cached = accessCache.get(player);
if (cached == null)
{
boolean canAccess = TFM_SuperadminList.isUserSuperadmin(player);
boolean canAccess = TFM_SuperadminList.isSuperAdmin(player);
if (!canAccess)
{
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)
{
guestList.remove(player);

View file

@ -190,7 +190,7 @@ public class TFM_CommandBlocker
public static CommandBlockerRank getSenderRank(CommandSender sender)
{
if (!TFM_SuperadminList.isUserSuperadmin(sender))
if (!TFM_SuperadminList.isSuperAdmin(sender))
{
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>();
private final Player player;
private final String ip;
private final String username;
private boolean isFrozen = false;
private boolean isMuted = false;
private boolean isHalted = false;
@ -55,11 +54,10 @@ public class TFM_PlayerData
private boolean cmdspyEnabled = false;
private String tag = null;
public TFM_PlayerData(Player player)
private TFM_PlayerData(Player player)
{
this.player = player;
this.ip = player.getAddress().getAddress().getHostAddress();
this.username = player.getName();
}
public static TFM_PlayerData getPlayerData(Player player)
@ -74,7 +72,7 @@ public class TFM_PlayerData
Entry<Player, TFM_PlayerData> pair = it.next();
TFM_PlayerData playerdataTest = pair.getValue();
if (playerdataTest.username.equalsIgnoreCase(player.getName()))
if (playerdataTest.player.getName().equalsIgnoreCase(player.getName()))
{
if (Bukkit.getOnlineMode())
{
@ -107,11 +105,6 @@ public class TFM_PlayerData
return this.ip;
}
public String getPlayerName()
{
return this.username;
}
public boolean isOrbiting()
{
return this.isOrbiting;
@ -325,7 +318,7 @@ public class TFM_PlayerData
{
private Player player;
public ArrowShooter(Player player)
private ArrowShooter(Player player)
{
this.player = player;
}
@ -385,7 +378,7 @@ public class TFM_PlayerData
player.setOp(false);
player.setGameMode(GameMode.SURVIVAL);
player.setFlying(false);
player.setDisplayName(username);
player.setDisplayName(player.getName());
player.closeInventory();
player.setTotalExperience(0);

View file

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

View file

@ -32,7 +32,7 @@ public enum TFM_PlayerRank
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)
{
@ -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;

View file

@ -54,7 +54,7 @@ public class TFM_ServerInterface
{
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");
return;
@ -164,11 +164,11 @@ public class TFM_ServerInterface
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;
if (server.getOnlineMode())
{
isSuperadmin = TFM_SuperadminList.getSuperadminNames().contains(username.toLowerCase());
isSuperadmin = TFM_SuperadminList.getSuperadminUUIDs().contains(username.toLowerCase());
}
else
{
@ -331,7 +331,7 @@ public class TFM_ServerInterface
{
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.");
count--;

View file

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

View file

@ -93,6 +93,20 @@ public class TFM_Util
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)
{
TFM_Log.info(message, true);
@ -139,6 +153,11 @@ public class TFM_Util
Math.round(location.getZ()));
}
public static String formatPlayer(Player player)
{
return player.getName() + " (" + player.getUniqueId() + ")";
}
public static void gotoWorld(CommandSender sender, String targetworld)
{
if (sender instanceof Player)
@ -737,7 +756,7 @@ public class TFM_Util
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);
}

View file

@ -118,7 +118,7 @@ public class TFM_WorldEditBridge
public void validateSelection(final Player player)
{
if (TFM_SuperadminList.isUserSuperadmin(player))
if (TFM_SuperadminList.isSuperAdmin(player))
{
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
superadmins:
darthsalamon:
ips:
- 80.60.73.144
- 213.211.159.63
admins:
b3c3b05a-a52d-33a6-a9c6-6e5063e00f0a:
last_login_name: DarthSalamon
- 127.0.0.1
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_telnet_admin: true
console_aliases:
- darth
is_activated: true
madgeek1450:
ips:
- 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
# Todo: Add mark and madgeek