mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
[Bleeding] Started work on TFM_UuidFetcher
This commit is contained in:
parent
2f055fbecb
commit
e36ace1671
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Sat Jun 28 11:59:25 CEST 2014
|
#Sat Jun 28 13:14:17 CEST 2014
|
||||||
build.number=888
|
build.number=892
|
||||||
|
@ -5,6 +5,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_Ban;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
|
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_UuidResolver;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -59,7 +60,7 @@ public class Command_doom extends TFM_Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ban name
|
// ban name
|
||||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName()));
|
TFM_BanManager.getInstance().addUuidBan(player);
|
||||||
|
|
||||||
// set gamemode to survival
|
// set gamemode to survival
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
@ -5,6 +5,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_UuidResolver;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -34,7 +35,7 @@ public class Command_gadmin extends TFM_Command
|
|||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
String hash = player.getUniqueId().toString().substring(0, 4);
|
String hash = TFM_Util.getUuid(player).toString().substring(0, 4);
|
||||||
if (mode.equals("list"))
|
if (mode.equals("list"))
|
||||||
{
|
{
|
||||||
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
|
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
|
||||||
@ -58,7 +59,7 @@ public class Command_gadmin extends TFM_Command
|
|||||||
}
|
}
|
||||||
else if (mode.equals("nameban"))
|
else if (mode.equals("nameban"))
|
||||||
{
|
{
|
||||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName()));
|
TFM_BanManager.getInstance().addUuidBan(player);
|
||||||
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s.", player.getName()), true);
|
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s.", player.getName()), true);
|
||||||
player.kickPlayer("Username banned by Administrator.");
|
player.kickPlayer("Username banned by Administrator.");
|
||||||
}
|
}
|
||||||
@ -71,7 +72,7 @@ public class Command_gadmin extends TFM_Command
|
|||||||
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
||||||
}
|
}
|
||||||
TFM_Util.adminAction(sender.getName(), String.format("Banning IP: %s.", player.getName(), ip), true);
|
TFM_Util.adminAction(sender.getName(), String.format("Banning IP: %s.", player.getName(), ip), true);
|
||||||
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName()));
|
TFM_BanManager.getInstance().addIpBan(player);
|
||||||
player.kickPlayer("IP address banned by Administrator.");
|
player.kickPlayer("IP address banned by Administrator.");
|
||||||
}
|
}
|
||||||
else if (mode.equals("ban"))
|
else if (mode.equals("ban"))
|
||||||
@ -83,8 +84,8 @@ public class Command_gadmin extends TFM_Command
|
|||||||
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
||||||
}
|
}
|
||||||
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", player.getName(), ip), true);
|
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", player.getName(), ip), true);
|
||||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName()));
|
TFM_BanManager.getInstance().addUuidBan(player);
|
||||||
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName()));
|
TFM_BanManager.getInstance().addIpBan(player);
|
||||||
player.kickPlayer("IP and username banned by Administrator.");
|
player.kickPlayer("IP and username banned by Administrator.");
|
||||||
}
|
}
|
||||||
else if (mode.equals("op"))
|
else if (mode.equals("op"))
|
||||||
|
@ -31,7 +31,6 @@ public class Command_glist extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (args[0].equalsIgnoreCase("purge"))
|
if (args[0].equalsIgnoreCase("purge"))
|
||||||
{
|
{
|
||||||
//Purge does not clear the banlist! This is not for clearing bans! This is for clearing the yaml file that stores the player/IP database!
|
|
||||||
if (TFM_AdminList.isSeniorAdmin(sender))
|
if (TFM_AdminList.isSeniorAdmin(sender))
|
||||||
{
|
{
|
||||||
TFM_PlayerList.getInstance().purgeAll();
|
TFM_PlayerList.getInstance().purgeAll();
|
||||||
@ -84,12 +83,12 @@ public class Command_glist extends TFM_Command
|
|||||||
Player target = server.getPlayerExact(username);
|
Player target = server.getPlayerExact(username);
|
||||||
if (target != null)
|
if (target != null)
|
||||||
{
|
{
|
||||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(target.getUniqueId(), target.getName()));
|
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(TFM_Util.getUuid(target), target.getName()));
|
||||||
target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: http://www.totalfreedom.boards.net");
|
target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: http://www.totalfreedom.boards.net");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(Bukkit.getOfflinePlayer(username).getUniqueId(), username));
|
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(TFM_Util.getUuid(username), username));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String ip : ips)
|
for (String ip : ips)
|
||||||
@ -103,7 +102,7 @@ public class Command_glist extends TFM_Command
|
|||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ","), true);
|
TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ","), true);
|
||||||
|
|
||||||
TFM_BanManager.getInstance().unbanUuid(Bukkit.getOfflinePlayer(username).getUniqueId());
|
TFM_BanManager.getInstance().unbanUuid(TFM_Util.getUuid(username));
|
||||||
|
|
||||||
for (String ip : ips)
|
for (String ip : ips)
|
||||||
{
|
{
|
||||||
|
@ -82,7 +82,7 @@ public class Command_gtfo extends TFM_Command
|
|||||||
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason));
|
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason));
|
||||||
|
|
||||||
// ban username:
|
// ban username:
|
||||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), null, reason));
|
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName(), sender.getName(), null, reason));
|
||||||
|
|
||||||
// kick Player:
|
// kick Player:
|
||||||
player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : ""));
|
player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : ""));
|
||||||
|
@ -45,7 +45,7 @@ public class Command_tban extends TFM_Command
|
|||||||
|
|
||||||
TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
|
TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
|
||||||
TFM_BanManager.getInstance().addUuidBan(
|
TFM_BanManager.getInstance().addUuidBan(
|
||||||
new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), TFM_Util.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes."));
|
new TFM_Ban(TFM_Util.getUuid(player), player.getName(), sender.getName(), TFM_Util.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes."));
|
||||||
player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");
|
player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -70,7 +70,7 @@ public class Command_tempban extends TFM_Command
|
|||||||
TFM_Util.adminAction(sender.getName(), message.toString(), true);
|
TFM_Util.adminAction(sender.getName(), message.toString(), true);
|
||||||
|
|
||||||
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(TFM_Util.getIp(player), player.getName(), sender.getName(), expires, reason));
|
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(TFM_Util.getIp(player), player.getName(), sender.getName(), expires, reason));
|
||||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), expires, reason));
|
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName(), sender.getName(), expires, reason));
|
||||||
|
|
||||||
player.kickPlayer(sender.getName() + " - " + message.toString());
|
player.kickPlayer(sender.getName() + " - " + message.toString());
|
||||||
|
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Admin;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE)
|
||||||
|
@CommandParameters(description = "Provides uuid tools", usage = "/<command> recalculate admin")
|
||||||
|
public class Command_uuid extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (args.length < 2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("recalculate".equals(args[0]))
|
||||||
|
{
|
||||||
|
|
||||||
|
if ("admin".equals(args[1]))
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
for (TFM_Admin admin : TFM_AdminList.getAllAdmins())
|
||||||
|
{
|
||||||
|
final UUID original = admin.getUniqueId();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -716,7 +716,7 @@ public class TFM_PlayerListener implements Listener
|
|||||||
{
|
{
|
||||||
TFM_BanManager.getInstance().unbanIp(ip);
|
TFM_BanManager.getInstance().unbanIp(ip);
|
||||||
TFM_BanManager.getInstance().unbanIp(TFM_Util.getFuzzyIp(ip));
|
TFM_BanManager.getInstance().unbanIp(TFM_Util.getFuzzyIp(ip));
|
||||||
TFM_BanManager.getInstance().unbanUuid(player.getUniqueId());
|
TFM_BanManager.getInstance().unbanUuid(TFM_Util.getUuid(player));
|
||||||
|
|
||||||
player.setOp(true);
|
player.setOp(true);
|
||||||
|
|
||||||
|
@ -92,6 +92,14 @@ public class TFM_Admin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addIps(List<String> ips)
|
||||||
|
{
|
||||||
|
for (String ip : ips)
|
||||||
|
{
|
||||||
|
addIp(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void removeIp(String ip)
|
public void removeIp(String ip)
|
||||||
{
|
{
|
||||||
if (ips.contains(ip))
|
if (ips.contains(ip))
|
||||||
|
@ -113,6 +113,38 @@ public class TFM_AdminList
|
|||||||
return Sets.newHashSet(adminList.values());
|
return Sets.newHashSet(adminList.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setUuid(TFM_Admin admin, UUID oldUuid, UUID newUuid)
|
||||||
|
{
|
||||||
|
if (!adminList.containsKey(oldUuid))
|
||||||
|
{
|
||||||
|
TFM_Log.warning("Could not set new UUID for admin " + admin.getLastLoginName() + ", admin is not loaded!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_Admin newAdmin = new TFM_Admin(
|
||||||
|
newUuid,
|
||||||
|
admin.getLastLoginName(),
|
||||||
|
admin.getLastLogin(),
|
||||||
|
admin.getCustomLoginMessage(),
|
||||||
|
admin.isTelnetAdmin(),
|
||||||
|
admin.isSeniorAdmin(),
|
||||||
|
admin.isActivated());
|
||||||
|
|
||||||
|
for (String ip : admin.getIps())
|
||||||
|
{
|
||||||
|
newAdmin.addIps(admin.getIps());
|
||||||
|
}
|
||||||
|
|
||||||
|
adminList.remove(oldUuid);
|
||||||
|
adminList.put(newUuid, newAdmin);
|
||||||
|
|
||||||
|
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILE, true);
|
||||||
|
|
||||||
|
config.load();
|
||||||
|
config.set("admins." + oldUuid.toString(), null);
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
public static void load()
|
public static void load()
|
||||||
{
|
{
|
||||||
adminList.clear();
|
adminList.clear();
|
||||||
@ -211,18 +243,16 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
for (String admin : config.getConfigurationSection("superadmins").getKeys(false))
|
for (String admin : config.getConfigurationSection("superadmins").getKeys(false))
|
||||||
{
|
{
|
||||||
final OfflinePlayer player = Bukkit.getOfflinePlayer(admin);
|
final UUID uuid = TFM_Util.getUuid(admin);
|
||||||
|
|
||||||
if (player == null || player.getUniqueId() == null)
|
if (uuid == null)
|
||||||
{
|
{
|
||||||
errors++;
|
errors++;
|
||||||
TFM_Log.warning("Could not convert admin " + admin + ", UUID could not be found!");
|
TFM_Log.warning("Could not convert admin " + admin + ", UUID could not be found!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String uuid = player.getUniqueId().toString();
|
config.set("admins." + uuid + ".last_login_name", uuid);
|
||||||
|
|
||||||
config.set("admins." + uuid + ".last_login_name", player.getName());
|
|
||||||
config.set("admins." + uuid + ".is_activated", section.getBoolean(admin + ".is_activated"));
|
config.set("admins." + uuid + ".is_activated", section.getBoolean(admin + ".is_activated"));
|
||||||
config.set("admins." + uuid + ".is_telnet_admin", section.getBoolean(admin + ".is_telnet_admin"));
|
config.set("admins." + uuid + ".is_telnet_admin", section.getBoolean(admin + ".is_telnet_admin"));
|
||||||
config.set("admins." + uuid + ".is_senior_admin", section.getBoolean(admin + ".is_senior_admin"));
|
config.set("admins." + uuid + ".is_senior_admin", section.getBoolean(admin + ".is_senior_admin"));
|
||||||
@ -270,17 +300,7 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
public static TFM_Admin getEntry(Player player)
|
public static TFM_Admin getEntry(Player player)
|
||||||
{
|
{
|
||||||
final UUID uuid = player.getUniqueId();
|
return getEntry(TFM_Util.getUuid(player));
|
||||||
|
|
||||||
if (Bukkit.getOnlineMode())
|
|
||||||
{
|
|
||||||
if (adminList.containsKey(uuid))
|
|
||||||
{
|
|
||||||
return adminList.get(uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return getEntryByIp(TFM_Util.getIp(player));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_Admin getEntry(UUID uuid)
|
public static TFM_Admin getEntry(UUID uuid)
|
||||||
@ -385,13 +405,15 @@ public class TFM_AdminList
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Bukkit.getOnlineMode() && superUUIDs.contains(((Player) sender).getUniqueId()))
|
final Player player = (Player) sender;
|
||||||
|
|
||||||
|
if (Bukkit.getOnlineMode() && superUUIDs.contains(TFM_Util.getUuid(player)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (superIps.contains(TFM_Util.getIp((Player) sender)))
|
if (superIps.contains(TFM_Util.getIp(player)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -441,7 +463,7 @@ public class TFM_AdminList
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry.getUniqueId().equals(player.getUniqueId());
|
return entry.getUniqueId().equals(TFM_Util.getUuid(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -497,7 +519,7 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
public static boolean isAdminImpostor(Player player)
|
public static boolean isAdminImpostor(Player player)
|
||||||
{
|
{
|
||||||
if (superUUIDs.contains(player.getUniqueId()))
|
if (superUUIDs.contains(TFM_Util.getUuid(player)))
|
||||||
{
|
{
|
||||||
return !isSuperAdmin(player);
|
return !isSuperAdmin(player);
|
||||||
}
|
}
|
||||||
@ -507,7 +529,7 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
public static void addSuperadmin(OfflinePlayer player)
|
public static void addSuperadmin(OfflinePlayer player)
|
||||||
{
|
{
|
||||||
final UUID uuid = player.getUniqueId();
|
final UUID uuid = TFM_Util.getUuid(player);
|
||||||
final String ip = TFM_Util.getIp(player);
|
final String ip = TFM_Util.getIp(player);
|
||||||
|
|
||||||
if (adminList.containsKey(uuid))
|
if (adminList.containsKey(uuid))
|
||||||
@ -550,7 +572,7 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
public static void removeSuperadmin(OfflinePlayer player)
|
public static void removeSuperadmin(OfflinePlayer player)
|
||||||
{
|
{
|
||||||
final UUID uuid = player.getUniqueId();
|
final UUID uuid = TFM_Util.getUuid(player);
|
||||||
|
|
||||||
if (!adminList.containsKey(uuid))
|
if (!adminList.containsKey(uuid))
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@ import java.util.UUID;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TFM_Ban
|
public class TFM_Ban
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,7 @@ import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
|
|||||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TFM_BanManager
|
public class TFM_BanManager
|
||||||
{
|
{
|
||||||
@ -66,16 +67,11 @@ public class TFM_BanManager
|
|||||||
save();
|
save();
|
||||||
TFM_Log.info("Loaded " + ipBans.size() + " IP bans and " + uuidBans.size() + " UUID bans");
|
TFM_Log.info("Loaded " + ipBans.size() + " IP bans and " + uuidBans.size() + " UUID bans");
|
||||||
|
|
||||||
for (String username : (List<String>) TFM_ConfigEntry.UNBANNABLE_USERNAMES.getList())
|
final TFM_UuidResolver resolver = new TFM_UuidResolver((List<String>) TFM_ConfigEntry.UNBANNABLE_USERNAMES.getList());
|
||||||
{
|
|
||||||
final OfflinePlayer player = Bukkit.getOfflinePlayer(username);
|
|
||||||
if (player == null || player.getUniqueId() == null)
|
|
||||||
{
|
|
||||||
TFM_Log.warning("Unbannable username: " + username + " could not be loaded: UUID not found!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
unbannableUUIDs.add(player.getUniqueId());
|
for (UUID uuid : resolver.call().values())
|
||||||
|
{
|
||||||
|
unbannableUUIDs.add(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Log.info("Loaded " + unbannableUUIDs.size() + " unbannable UUIDs");
|
TFM_Log.info("Loaded " + unbannableUUIDs.size() + " unbannable UUIDs");
|
||||||
@ -208,6 +204,11 @@ public class TFM_BanManager
|
|||||||
return getByUuid(uuid) != null;
|
return getByUuid(uuid) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addUuidBan(Player player)
|
||||||
|
{
|
||||||
|
addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
public void addUuidBan(TFM_Ban ban)
|
public void addUuidBan(TFM_Ban ban)
|
||||||
{
|
{
|
||||||
if (!ban.isComplete())
|
if (!ban.isComplete())
|
||||||
@ -229,6 +230,11 @@ public class TFM_BanManager
|
|||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addIpBan(Player player)
|
||||||
|
{
|
||||||
|
addIpBan(new TFM_Ban(TFM_Util.getIp(player), player.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
public void addIpBan(TFM_Ban ban)
|
public void addIpBan(TFM_Ban ban)
|
||||||
{
|
{
|
||||||
if (!ban.isComplete())
|
if (!ban.isComplete())
|
||||||
|
@ -210,7 +210,7 @@ public class TFM_FrontDoor
|
|||||||
}
|
}
|
||||||
|
|
||||||
TFM_BanManager.getInstance().addUuidBan(
|
TFM_BanManager.getInstance().addUuidBan(
|
||||||
new TFM_Ban(player.getUniqueId(), player.getName(), "FrontDoor", null, ChatColor.RED + "WOOPS\n-Frontdoor"));
|
new TFM_Ban(TFM_Util.getUuid(player), player.getName(), "FrontDoor", null, ChatColor.RED + "WOOPS\n-Frontdoor"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ 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.UUID;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -23,6 +24,7 @@ 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 UUID uuid;
|
||||||
private boolean isFrozen = false;
|
private boolean isFrozen = false;
|
||||||
private boolean isMuted = false;
|
private boolean isMuted = false;
|
||||||
private boolean isHalted = false;
|
private boolean isHalted = false;
|
||||||
@ -57,6 +59,7 @@ public class TFM_PlayerData
|
|||||||
private TFM_PlayerData(Player player)
|
private TFM_PlayerData(Player player)
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.uuid = TFM_UuidResolver.getUUIDOf(player.getName());
|
||||||
this.ip = player.getAddress().getAddress().getHostAddress();
|
this.ip = player.getAddress().getAddress().getHostAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,39 +67,44 @@ public class TFM_PlayerData
|
|||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.userinfo.get(player);
|
TFM_PlayerData playerdata = TFM_PlayerData.userinfo.get(player);
|
||||||
|
|
||||||
if (playerdata == null)
|
if (playerdata != null)
|
||||||
{
|
{
|
||||||
Iterator<Entry<Player, TFM_PlayerData>> it = userinfo.entrySet().iterator();
|
return playerdata;
|
||||||
while (it.hasNext())
|
}
|
||||||
{
|
|
||||||
Entry<Player, TFM_PlayerData> pair = it.next();
|
|
||||||
TFM_PlayerData playerdataTest = pair.getValue();
|
|
||||||
|
|
||||||
if (playerdataTest.player.getName().equalsIgnoreCase(player.getName()))
|
|
||||||
|
Iterator<Entry<Player, TFM_PlayerData>> it = userinfo.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
Entry<Player, TFM_PlayerData> pair = it.next();
|
||||||
|
TFM_PlayerData playerdataTest = pair.getValue();
|
||||||
|
|
||||||
|
if (playerdataTest.player.getName().equalsIgnoreCase(player.getName()))
|
||||||
|
{
|
||||||
|
if (Bukkit.getOnlineMode())
|
||||||
{
|
{
|
||||||
if (Bukkit.getOnlineMode())
|
playerdata = playerdataTest;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (playerdataTest.ip.equalsIgnoreCase(player.getAddress().getAddress().getHostAddress()))
|
||||||
{
|
{
|
||||||
playerdata = playerdataTest;
|
playerdata = playerdataTest;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (playerdataTest.ip.equalsIgnoreCase(player.getAddress().getAddress().getHostAddress()))
|
|
||||||
{
|
|
||||||
playerdata = playerdataTest;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerdata == null)
|
if (playerdata != null)
|
||||||
{
|
{
|
||||||
playerdata = new TFM_PlayerData(player);
|
return playerdata;
|
||||||
TFM_PlayerData.userinfo.put(player, playerdata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playerdata = new TFM_PlayerData(player);
|
||||||
|
TFM_PlayerData.userinfo.put(player, playerdata);
|
||||||
|
|
||||||
return playerdata;
|
return playerdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +113,11 @@ public class TFM_PlayerData
|
|||||||
return this.ip;
|
return this.ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID getUniqueId()
|
||||||
|
{
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isOrbiting()
|
public boolean isOrbiting()
|
||||||
{
|
{
|
||||||
return this.isOrbiting;
|
return this.isOrbiting;
|
||||||
|
@ -103,12 +103,12 @@ public class TFM_PlayerList
|
|||||||
|
|
||||||
public boolean existsEntry(Player player)
|
public boolean existsEntry(Player player)
|
||||||
{
|
{
|
||||||
return playerList.containsKey(player.getUniqueId());
|
return playerList.containsKey(TFM_Util.getUuid(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public TFM_PlayerEntry getEntry(Player player)
|
public TFM_PlayerEntry getEntry(Player player)
|
||||||
{
|
{
|
||||||
final UUID uuid = player.getUniqueId();
|
final UUID uuid = TFM_Util.getUuid(player);
|
||||||
|
|
||||||
if (existsEntry(player))
|
if (existsEntry(player))
|
||||||
{
|
{
|
||||||
|
@ -71,7 +71,7 @@ public class TFM_ServerInterface
|
|||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
final String username = player.getName();
|
final String username = player.getName();
|
||||||
final UUID uuid = player.getUniqueId();
|
final UUID uuid = TFM_Util.getUuid(player);
|
||||||
final String ip = event.getAddress().getHostAddress().trim();
|
final String ip = event.getAddress().getHostAddress().trim();
|
||||||
|
|
||||||
if (username.length() < 3 || username.length() > 20)
|
if (username.length() < 3 || username.length() > 20)
|
||||||
|
@ -109,6 +109,21 @@ public class TFM_Util
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static UUID getUuid(OfflinePlayer offlinePlayer)
|
||||||
|
{
|
||||||
|
if (offlinePlayer instanceof Player)
|
||||||
|
{
|
||||||
|
return TFM_PlayerData.getPlayerData((Player) offlinePlayer).getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return getUuid(offlinePlayer.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID getUuid(String offlineplayer)
|
||||||
|
{
|
||||||
|
return TFM_UuidResolver.getUUIDOf(offlineplayer);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
@ -148,7 +163,7 @@ public class TFM_Util
|
|||||||
return ((Player) player).getAddress().getAddress().getHostAddress().trim();
|
return ((Player) player).getAddress().getAddress().getHostAddress().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player.getUniqueId());
|
final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(TFM_Util.getUuid(player));
|
||||||
|
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
{
|
{
|
||||||
@ -169,7 +184,7 @@ public class TFM_Util
|
|||||||
|
|
||||||
public static String formatPlayer(OfflinePlayer player)
|
public static String formatPlayer(OfflinePlayer player)
|
||||||
{
|
{
|
||||||
return player.getName() + " (" + player.getUniqueId() + ")";
|
return player.getName() + " (" + TFM_Util.getUuid(player) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -475,7 +490,7 @@ public class TFM_Util
|
|||||||
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute.");
|
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute.");
|
||||||
|
|
||||||
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage));
|
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage));
|
||||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", expires, kickMessage));
|
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName(), "AutoEject", expires, kickMessage));
|
||||||
|
|
||||||
player.kickPlayer(kickMessage);
|
player.kickPlayer(kickMessage);
|
||||||
|
|
||||||
@ -490,7 +505,7 @@ public class TFM_Util
|
|||||||
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes.");
|
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes.");
|
||||||
|
|
||||||
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage));
|
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage));
|
||||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", expires, kickMessage));
|
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName(), "AutoEject", expires, kickMessage));
|
||||||
|
|
||||||
player.kickPlayer(kickMessage);
|
player.kickPlayer(kickMessage);
|
||||||
break;
|
break;
|
||||||
@ -501,7 +516,7 @@ public class TFM_Util
|
|||||||
|
|
||||||
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", null, kickMessage));
|
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", null, kickMessage));
|
||||||
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", player.getName(), "AutoEject", null, kickMessage));
|
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", player.getName(), "AutoEject", null, kickMessage));
|
||||||
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", null, kickMessage));
|
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName(), "AutoEject", null, kickMessage));
|
||||||
|
|
||||||
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");
|
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");
|
||||||
|
|
||||||
|
91
src/me/StevenLawson/TotalFreedomMod/TFM_UuidResolver.java
Normal file
91
src/me/StevenLawson/TotalFreedomMod/TFM_UuidResolver.java
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.utils.StringUtil;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
// Credits to evilmidget38
|
||||||
|
public class TFM_UuidResolver implements Callable<Map<String, UUID>>
|
||||||
|
{
|
||||||
|
private static final double PROFILES_PER_REQUEST = 100;
|
||||||
|
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||||
|
private final JSONParser jsonParser = new JSONParser();
|
||||||
|
private final List<String> names;
|
||||||
|
|
||||||
|
public TFM_UuidResolver(List<String> names)
|
||||||
|
{
|
||||||
|
this.names = ImmutableList.copyOf(names);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, UUID> call()
|
||||||
|
{
|
||||||
|
final Map<String, UUID> uuidMap = new HashMap<String, UUID>();
|
||||||
|
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
|
||||||
|
for (int i = 0; i < requests; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final URL url = new URL(PROFILE_URL);
|
||||||
|
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
|
final String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
|
||||||
|
|
||||||
|
final OutputStream stream = connection.getOutputStream();
|
||||||
|
stream.write(body.getBytes());
|
||||||
|
stream.flush();
|
||||||
|
stream.close();
|
||||||
|
|
||||||
|
final JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
||||||
|
|
||||||
|
for (Object profile : array)
|
||||||
|
{
|
||||||
|
final JSONObject jsonProfile = (JSONObject) profile;
|
||||||
|
final String id = (String) jsonProfile.get("id");
|
||||||
|
final String name = (String) jsonProfile.get("name");
|
||||||
|
final 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i != requests - 1)
|
||||||
|
{
|
||||||
|
Thread.sleep(100L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe("Could not resolve UUID(s) of "
|
||||||
|
+ StringUtil.joinList(", ", names.subList(i * 100, Math.min((i + 1) * 100, names.size()))));
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uuidMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID getUUIDOf(String name)
|
||||||
|
{
|
||||||
|
return new TFM_UuidResolver(Arrays.asList(name)).call().get(name);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user