mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-04-06 03:33:14 +00:00
Fixed duplicate entries when adding/removing players
Some refractoring
This commit is contained in:
parent
9315227906
commit
c82113dc22
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Mon Apr 21 14:50:16 CEST 2014
|
#Mon Apr 21 17:44:46 CEST 2014
|
||||||
build.number=778
|
build.number=782
|
||||||
|
@ -9,6 +9,7 @@ import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
|||||||
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;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -24,11 +25,12 @@ public class Command_saconfig extends TFM_Command
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
if (args[0].equals("list"))
|
if (args[0].equals("list"))
|
||||||
{
|
{
|
||||||
playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperadminNames(), ", "), ChatColor.GOLD);
|
playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperNames(), ", "), ChatColor.GOLD);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +45,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_AdminList.cleanSuperadminList(true);
|
TFM_AdminList.cleanSuperadminList(true);
|
||||||
playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperadminUUIDs(), ", "), ChatColor.YELLOW);
|
playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperUUIDs(), ", "), ChatColor.YELLOW);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,8 +93,7 @@ public class Command_saconfig extends TFM_Command
|
|||||||
|
|
||||||
if (args[0].equalsIgnoreCase("add"))
|
if (args[0].equalsIgnoreCase("add"))
|
||||||
{
|
{
|
||||||
Player player = null;
|
OfflinePlayer player;
|
||||||
String playername = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -101,27 +102,19 @@ public class Command_saconfig extends TFM_Command
|
|||||||
catch (PlayerNotFoundException ex)
|
catch (PlayerNotFoundException ex)
|
||||||
{
|
{
|
||||||
final TFM_Admin superadmin = TFM_AdminList.getEntry(args[1]);
|
final TFM_Admin superadmin = TFM_AdminList.getEntry(args[1]);
|
||||||
if (superadmin != null)
|
|
||||||
{
|
if (superadmin == null)
|
||||||
playername = superadmin.getLastLoginName();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
playerMsg(ex.getMessage(), ChatColor.RED);
|
playerMsg(ex.getMessage(), ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player = Bukkit.getOfflinePlayer(superadmin.getLastLoginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player != null)
|
TFM_Util.adminAction(sender.getName(), "Adding " + player.getName() + " to the superadmin list", true);
|
||||||
{
|
TFM_AdminList.addSuperadmin(player);
|
||||||
TFM_Util.adminAction(sender.getName(), "Adding " + player.getName() + " to the superadmin list.", true);
|
|
||||||
TFM_AdminList.addSuperadmin(player);
|
|
||||||
}
|
|
||||||
else if (playername != null)
|
|
||||||
{
|
|
||||||
TFM_Util.adminAction(sender.getName(), "Adding " + playername + " to the superadmin list.", true);
|
|
||||||
TFM_AdminList.addSuperadmin(player);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +136,7 @@ public class Command_saconfig extends TFM_Command
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TFM_AdminList.getLowerSuperadminNames().contains(targetName.toLowerCase()))
|
if (!TFM_AdminList.getLowerSuperNames().contains(targetName.toLowerCase()))
|
||||||
{
|
{
|
||||||
playerMsg("Superadmin not found: " + targetName);
|
playerMsg("Superadmin not found: " + targetName);
|
||||||
return true;
|
return true;
|
||||||
|
@ -35,14 +35,14 @@ public class Module_players extends TFM_HTTPD_Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Super admins (non-telnet and non-senior)
|
// Super admins (non-telnet and non-senior)
|
||||||
for (UUID superadmin : TFM_AdminList.getSuperadminUUIDs())
|
for (UUID superadmin : TFM_AdminList.getSuperUUIDs())
|
||||||
{
|
{
|
||||||
if (TFM_AdminList.getSenioradminUUIDs().contains(superadmin))
|
if (TFM_AdminList.getSeniorUUIDs().contains(superadmin))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TFM_AdminList.getTelnetadminUUIDs().contains(superadmin))
|
if (TFM_AdminList.getTelnetUUIDs().contains(superadmin))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -51,9 +51,9 @@ public class Module_players extends TFM_HTTPD_Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Telnet admins (non-senior)
|
// Telnet admins (non-senior)
|
||||||
for (UUID telnetadmin : TFM_AdminList.getTelnetadminUUIDs())
|
for (UUID telnetadmin : TFM_AdminList.getTelnetUUIDs())
|
||||||
{
|
{
|
||||||
if (TFM_AdminList.getSenioradminUUIDs().contains(telnetadmin))
|
if (TFM_AdminList.getSeniorUUIDs().contains(telnetadmin))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ public class Module_players extends TFM_HTTPD_Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Senior admins
|
// Senior admins
|
||||||
for (UUID senioradmin : TFM_AdminList.getSenioradminUUIDs())
|
for (UUID senioradmin : TFM_AdminList.getSeniorUUIDs())
|
||||||
{
|
{
|
||||||
senioradmins.add(getName(senioradmin));
|
senioradmins.add(getName(senioradmin));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -19,16 +20,16 @@ public class TFM_Admin
|
|||||||
private Date lastLogin;
|
private Date lastLogin;
|
||||||
private boolean isActivated;
|
private boolean isActivated;
|
||||||
|
|
||||||
public TFM_Admin(UUID uuid, String lastLoginName, List<String> ips, Date lastLogin, String loginMessage, boolean isSeniorAdmin, boolean isTelnetAdmin, List<String> consoleAliases, boolean isActivated)
|
public TFM_Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage, boolean isSeniorAdmin, boolean isTelnetAdmin, boolean isActivated)
|
||||||
{
|
{
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.lastLoginName = lastLoginName;
|
this.lastLoginName = lastLoginName;
|
||||||
this.ips = ips;
|
this.ips = new ArrayList<String>();
|
||||||
this.lastLogin = lastLogin;
|
this.lastLogin = lastLogin;
|
||||||
this.loginMessage = loginMessage;
|
this.loginMessage = loginMessage;
|
||||||
this.isSeniorAdmin = isSeniorAdmin;
|
this.isSeniorAdmin = isSeniorAdmin;
|
||||||
this.isTelnetAdmin = isTelnetAdmin;
|
this.isTelnetAdmin = isTelnetAdmin;
|
||||||
this.consoleAliases = consoleAliases;
|
this.consoleAliases = new ArrayList<String>();
|
||||||
this.isActivated = isActivated;
|
this.isActivated = isActivated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
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.Set;
|
||||||
@ -17,6 +18,7 @@ import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
|
|||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig;
|
import me.StevenLawson.TotalFreedomMod.Config.TFM_MainConfig;
|
||||||
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
|
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
|
||||||
|
import net.minecraft.util.com.google.common.collect.Sets;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -28,72 +30,92 @@ import org.bukkit.util.FileUtil;
|
|||||||
public class TFM_AdminList
|
public class TFM_AdminList
|
||||||
{
|
{
|
||||||
private static final Map<UUID, TFM_Admin> adminList;
|
private static final Map<UUID, TFM_Admin> adminList;
|
||||||
private static final Set<UUID> superadminUUIDs;
|
private static final Set<UUID> superUUIDs;
|
||||||
private static final Set<UUID> telnetadminUUIDs;
|
private static final Set<UUID> telnetUUIDs;
|
||||||
private static final Set<UUID> senioradminUUIDs;
|
private static final Set<UUID> seniorUUIDs;
|
||||||
private static final Set<String> consoleAliases;
|
private static final Set<String> seniorConsoleAliases;
|
||||||
private static final Set<String> superadminIps;
|
private static final Set<String> superIps;
|
||||||
private static int cleanThreshold = 24 * 7; // 1 Week in hours
|
private static int cleanThreshold = 24 * 7; // 1 Week in hours
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
adminList = new HashMap<UUID, TFM_Admin>();
|
adminList = new HashMap<UUID, TFM_Admin>();
|
||||||
superadminUUIDs = new HashSet<UUID>();
|
superUUIDs = new HashSet<UUID>();
|
||||||
telnetadminUUIDs = new HashSet<UUID>();
|
telnetUUIDs = new HashSet<UUID>();
|
||||||
senioradminUUIDs = new HashSet<UUID>();
|
seniorUUIDs = new HashSet<UUID>();
|
||||||
consoleAliases = new HashSet<String>();
|
seniorConsoleAliases = new HashSet<String>();
|
||||||
superadminIps = new HashSet<String>();
|
superIps = new HashSet<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<UUID> getSuperadminUUIDs()
|
private TFM_AdminList()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableSet(superadminUUIDs);
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<UUID> getTelnetadminUUIDs()
|
public static Set<UUID> getSuperUUIDs()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableSet(telnetadminUUIDs);
|
return Collections.unmodifiableSet(superUUIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<UUID> getSenioradminUUIDs()
|
public static Set<UUID> getTelnetUUIDs()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableSet(senioradminUUIDs);
|
return Collections.unmodifiableSet(telnetUUIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getConsoleAliases()
|
public static Set<UUID> getSeniorUUIDs()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableSet(consoleAliases);
|
return Collections.unmodifiableSet(seniorUUIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<String> getSeniorConsoleAliases()
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableSet(seniorConsoleAliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getSuperadminIps()
|
public static Set<String> getSuperadminIps()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableSet(superadminIps);
|
return Collections.unmodifiableSet(superIps);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getSuperadminNames()
|
public static Set<String> getSuperNames()
|
||||||
{
|
{
|
||||||
final Set<String> names = new HashSet<String>();
|
final Set<String> names = new HashSet<String>();
|
||||||
|
|
||||||
for (TFM_Admin admin : adminList.values())
|
for (TFM_Admin admin : adminList.values())
|
||||||
{
|
{
|
||||||
|
if (!admin.isActivated())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
names.add(admin.getLastLoginName());
|
names.add(admin.getLastLoginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Collections.unmodifiableSet(names);
|
return Collections.unmodifiableSet(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getLowerSuperadminNames()
|
public static Set<String> getLowerSuperNames()
|
||||||
{
|
{
|
||||||
final Set<String> names = new HashSet<String>();
|
final Set<String> names = new HashSet<String>();
|
||||||
|
|
||||||
for (TFM_Admin admin : adminList.values())
|
for (TFM_Admin admin : adminList.values())
|
||||||
{
|
{
|
||||||
|
if (!admin.isActivated())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
names.add(admin.getLastLoginName().toLowerCase());
|
names.add(admin.getLastLoginName().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Collections.unmodifiableSet(names);
|
return Collections.unmodifiableSet(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Set<TFM_Admin> getAllAdmins()
|
||||||
|
{
|
||||||
|
return Sets.newHashSet(adminList.values());
|
||||||
|
}
|
||||||
|
|
||||||
public static void load()
|
public static void load()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -176,7 +198,7 @@ public class TFM_AdminList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void backupSavedList()
|
public static void createBackup()
|
||||||
{
|
{
|
||||||
final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE);
|
final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE);
|
||||||
final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE + ".bak");
|
final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE + ".bak");
|
||||||
@ -185,11 +207,11 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
public static void updateIndexLists()
|
public static void updateIndexLists()
|
||||||
{
|
{
|
||||||
superadminUUIDs.clear();
|
superUUIDs.clear();
|
||||||
telnetadminUUIDs.clear();
|
telnetUUIDs.clear();
|
||||||
senioradminUUIDs.clear();
|
seniorUUIDs.clear();
|
||||||
consoleAliases.clear();
|
seniorConsoleAliases.clear();
|
||||||
superadminIps.clear();
|
superIps.clear();
|
||||||
|
|
||||||
for (TFM_Admin admin : adminList.values())
|
for (TFM_Admin admin : adminList.values())
|
||||||
{
|
{
|
||||||
@ -200,27 +222,27 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
final UUID uuid = admin.getUniqueId();
|
final UUID uuid = admin.getUniqueId();
|
||||||
|
|
||||||
superadminUUIDs.add(uuid);
|
superUUIDs.add(uuid);
|
||||||
|
|
||||||
for (String ip : admin.getIps())
|
for (String ip : admin.getIps())
|
||||||
{
|
{
|
||||||
superadminIps.add(ip);
|
superIps.add(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (admin.isTelnetAdmin())
|
if (admin.isTelnetAdmin())
|
||||||
{
|
{
|
||||||
telnetadminUUIDs.add(uuid);
|
telnetUUIDs.add(uuid);
|
||||||
|
|
||||||
for (String alias : admin.getConsoleAliases())
|
for (String alias : admin.getConsoleAliases())
|
||||||
{
|
{
|
||||||
consoleAliases.add(alias.toLowerCase());
|
seniorConsoleAliases.add(alias.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (admin.isSeniorAdmin())
|
if (admin.isSeniorAdmin())
|
||||||
{
|
{
|
||||||
senioradminUUIDs.add(uuid);
|
seniorUUIDs.add(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,8 +251,6 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
public static void save()
|
public static void save()
|
||||||
{
|
{
|
||||||
updateIndexLists();
|
|
||||||
|
|
||||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILE, true);
|
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILE, true);
|
||||||
config.load();
|
config.load();
|
||||||
|
|
||||||
@ -327,12 +347,13 @@ public class TFM_AdminList
|
|||||||
public static void updateLastLogin(Player player)
|
public static void updateLastLogin(Player player)
|
||||||
{
|
{
|
||||||
final TFM_Admin admin = getEntry(player);
|
final TFM_Admin admin = getEntry(player);
|
||||||
if (admin != null)
|
if (admin == null)
|
||||||
{
|
{
|
||||||
admin.setLastLogin(new Date());
|
return;
|
||||||
admin.setLastLoginName(player.getName());
|
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
|
admin.setLastLogin(new Date());
|
||||||
|
admin.setLastLoginName(player.getName());
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSeniorAdmin(CommandSender sender)
|
public static boolean isSeniorAdmin(CommandSender sender)
|
||||||
@ -353,7 +374,7 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
if (!(sender instanceof Player))
|
if (!(sender instanceof Player))
|
||||||
{
|
{
|
||||||
return consoleAliases.contains(sender.getName())
|
return seniorConsoleAliases.contains(sender.getName())
|
||||||
|| (TFM_MainConfig.getInstance().getBoolean(TFM_ConfigEntry.CONSOLE_IS_SENIOR) && sender.getName().equals("CONSOLE"));
|
|| (TFM_MainConfig.getInstance().getBoolean(TFM_ConfigEntry.CONSOLE_IS_SENIOR) && sender.getName().equals("CONSOLE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,13 +394,13 @@ public class TFM_AdminList
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Bukkit.getOnlineMode() && superadminUUIDs.contains(((Player) sender).getUniqueId()))
|
if (Bukkit.getOnlineMode() && superUUIDs.contains(((Player) sender).getUniqueId()))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (superadminIps.contains(TFM_Util.getIp((Player) sender)))
|
if (superIps.contains(TFM_Util.getIp((Player) sender)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -413,7 +434,7 @@ public class TFM_AdminList
|
|||||||
{
|
{
|
||||||
ip = ip.trim();
|
ip = ip.trim();
|
||||||
|
|
||||||
if (superadminIps.contains(ip))
|
if (superIps.contains(ip))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -421,7 +442,7 @@ public class TFM_AdminList
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
String matchIp = null;
|
String matchIp = null;
|
||||||
for (String testIp : superadminIps)
|
for (String testIp : superIps)
|
||||||
{
|
{
|
||||||
if (TFM_Util.fuzzyIpMatch(ip, testIp, 3))
|
if (TFM_Util.fuzzyIpMatch(ip, testIp, 3))
|
||||||
{
|
{
|
||||||
@ -461,7 +482,7 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
public static boolean isAdminImpostor(Player player)
|
public static boolean isAdminImpostor(Player player)
|
||||||
{
|
{
|
||||||
if (superadminUUIDs.contains(player.getUniqueId()))
|
if (superUUIDs.contains(player.getUniqueId()))
|
||||||
{
|
{
|
||||||
return !isSuperAdmin(player);
|
return !isSuperAdmin(player);
|
||||||
}
|
}
|
||||||
@ -469,56 +490,65 @@ public class TFM_AdminList
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addSuperadmin(Player player)
|
public static void addSuperadmin(OfflinePlayer player)
|
||||||
{
|
{
|
||||||
try
|
final UUID uuid = player.getUniqueId();
|
||||||
|
final String ip = TFM_Util.getIp(player);
|
||||||
|
|
||||||
|
if (adminList.containsKey(uuid))
|
||||||
{
|
{
|
||||||
final UUID uuid = player.getUniqueId();
|
final TFM_Admin superadmin = adminList.get(uuid);
|
||||||
final String ip = TFM_Util.getIp(player);
|
superadmin.setActivated(true);
|
||||||
|
|
||||||
if (adminList.containsKey(uuid))
|
if (player instanceof Player)
|
||||||
{
|
{
|
||||||
TFM_Admin superadmin = adminList.get(uuid);
|
|
||||||
superadmin.setActivated(true);
|
|
||||||
superadmin.addIp(TFM_Util.getIp(player));
|
|
||||||
superadmin.setLastLogin(new Date());
|
superadmin.setLastLogin(new Date());
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
final TFM_Admin superadmin = new TFM_Admin(
|
|
||||||
uuid,
|
|
||||||
player.getName(),
|
|
||||||
new ArrayList<String>(),
|
|
||||||
new Date(),
|
|
||||||
"",
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
new ArrayList<String>(),
|
|
||||||
true);
|
|
||||||
superadmin.addIp(ip);
|
superadmin.addIp(ip);
|
||||||
adminList.put(uuid, superadmin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
save();
|
save();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
if (ip == null)
|
||||||
{
|
{
|
||||||
TFM_Log.severe("Cannot add superadmin: " + TFM_Util.formatPlayer(player));
|
TFM_Log.severe("Cannot add superadmin: " + TFM_Util.formatPlayer(player));
|
||||||
TFM_Log.severe(ex);
|
TFM_Log.severe("Could not retrieve IP!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final TFM_Admin superadmin = new TFM_Admin(
|
||||||
|
uuid,
|
||||||
|
player.getName(),
|
||||||
|
new Date(),
|
||||||
|
"",
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true);
|
||||||
|
superadmin.addIp(ip);
|
||||||
|
|
||||||
|
adminList.put(uuid, superadmin);
|
||||||
|
|
||||||
|
save();
|
||||||
|
updateIndexLists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeSuperadmin(OfflinePlayer player)
|
public static void removeSuperadmin(OfflinePlayer player)
|
||||||
{
|
{
|
||||||
final UUID uuid = player.getUniqueId();
|
final UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
if (adminList.containsKey(uuid))
|
if (!adminList.containsKey(uuid))
|
||||||
{
|
{
|
||||||
TFM_Admin superadmin = adminList.get(uuid);
|
TFM_Log.warning("Could not remove admin: " + TFM_Util.formatPlayer(player));
|
||||||
superadmin.setActivated(false);
|
TFM_Log.warning("Player is not an admin!");
|
||||||
Command_logs.deactivateSuperadmin(superadmin);
|
return;
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final TFM_Admin superadmin = adminList.get(uuid);
|
||||||
|
superadmin.setActivated(false);
|
||||||
|
Command_logs.deactivateSuperadmin(superadmin);
|
||||||
|
|
||||||
|
save();
|
||||||
|
updateIndexLists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanSuperadminList(boolean verbose)
|
public static void cleanSuperadminList(boolean verbose)
|
||||||
@ -549,16 +579,8 @@ public class TFM_AdminList
|
|||||||
TFM_TwitterHandler.getInstance().delTwitter(superadmin.getLastLoginName());
|
TFM_TwitterHandler.getInstance().delTwitter(superadmin.getLastLoginName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save();
|
save();
|
||||||
}
|
updateIndexLists();
|
||||||
|
|
||||||
private TFM_AdminList()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getConfigFile()
|
|
||||||
{
|
|
||||||
return new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,11 @@ public class TFM_PlayerList
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TFM_PlayerEntry getEntry(UUID uuid)
|
||||||
|
{
|
||||||
|
return playerList.get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean existsEntry(Player player)
|
public boolean existsEntry(Player player)
|
||||||
{
|
{
|
||||||
return playerList.containsKey(player.getUniqueId());
|
return playerList.containsKey(player.getUniqueId());
|
||||||
|
@ -89,7 +89,7 @@ public class TFM_ServerInterface
|
|||||||
boolean isAdmin;
|
boolean isAdmin;
|
||||||
if (server.getOnlineMode())
|
if (server.getOnlineMode())
|
||||||
{
|
{
|
||||||
isAdmin = TFM_AdminList.getSuperadminUUIDs().contains(uuid);
|
isAdmin = TFM_AdminList.getSuperUUIDs().contains(uuid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -141,9 +141,21 @@ public class TFM_Util
|
|||||||
TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));
|
TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getIp(Player player)
|
public static String getIp(OfflinePlayer player)
|
||||||
{
|
{
|
||||||
return player.getAddress().getAddress().getHostAddress().trim();
|
if (player instanceof Player)
|
||||||
|
{
|
||||||
|
return ((Player) player).getAddress().getAddress().getHostAddress().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player.getUniqueId());
|
||||||
|
|
||||||
|
if (entry == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry.getIps().get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatLocation(Location location)
|
public static String formatLocation(Location location)
|
||||||
@ -155,7 +167,7 @@ public class TFM_Util
|
|||||||
Math.round(location.getZ()));
|
Math.round(location.getZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatPlayer(Player player)
|
public static String formatPlayer(OfflinePlayer player)
|
||||||
{
|
{
|
||||||
return player.getName() + " (" + player.getUniqueId() + ")";
|
return player.getName() + " (" + player.getUniqueId() + ")";
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TFM_AdminList.backupSavedList();
|
TFM_AdminList.createBackup();
|
||||||
TFM_AdminList.load();
|
TFM_AdminList.load();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user