diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_namehistory.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_namehistory.java deleted file mode 100644 index 1bc2033c..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_namehistory.java +++ /dev/null @@ -1,23 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import me.totalfreedom.totalfreedommod.rank.Rank; -import me.totalfreedom.totalfreedommod.util.History; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(level = Rank.OP, source = SourceType.BOTH) -@CommandParameters(description = "Check the name history of a specified player.", usage = "/ ", aliases = "nh") -public class Command_namehistory extends FreedomCommand -{ - @Override - public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length != 1) - { - return false; - } - History.reportHistory(sender, args[0]); - return true; - } -} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/History.java b/src/main/java/me/totalfreedom/totalfreedommod/util/History.java deleted file mode 100644 index 682a4fbd..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/History.java +++ /dev/null @@ -1,114 +0,0 @@ -package me.totalfreedom.totalfreedommod.util; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.UUID; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.scheduler.BukkitRunnable; - -public class History -{ - - public static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - public static void reportHistory(final CommandSender sender, final String username) - { - new BukkitRunnable() - { - @Override - public void run() - { - UUID uuid = UUIDFetcher.fetch(username); - if (uuid != null) - { - Gson gson = new GsonBuilder().create(); - String compactUuid = uuid.toString().replace("-", ""); - try - { - //UUIDs or playernames actually work with this one - //TODO: fix the stupid api on how it's not working name histories - //URL url = new URL("https://api.ashcon.app/mojang/v2/user/" + compactUuid); - URL url = new URL("https://api.mojang.com/user/profiles/" + compactUuid + "/names"); - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - //conn.setRequestProperty("User-Agent", ""); - BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); - FName[] oldNames = gson.fromJson(reader, FName[].class); - if (oldNames == null) - { - FSync.playerMsg(sender, ChatColor.RED + "Player not found!"); - return; - } - reader.close(); - conn.disconnect(); - Arrays.sort(oldNames); - printHistory(sender, oldNames); - } - catch (Exception ex) - { - FSync.playerMsg(sender, ChatColor.RED + "Error, see logs for more details."); - FLog.severe(ex); - } - } - else - { - FSync.playerMsg(sender, ChatColor.RED + "Player not found!"); - } - } - }.runTaskAsynchronously(TotalFreedomMod.getPlugin()); - } - - private static void printHistory(CommandSender sender, FName[] oldNames) - { - if (oldNames.length == 1) - { - FSync.playerMsg(sender, ChatColor.GREEN + oldNames[0].getName() + ChatColor.GOLD + " has never changed their name."); - return; - } - FSync.playerMsg(sender, ChatColor.GOLD + "Original name: " + ChatColor.GREEN + oldNames[0].getName()); - for (int i = 1; i < oldNames.length; i++) - { - Date date = new Date(oldNames[i].getChangedToAt()); - String formattedDate = dateFormat.format(date); - FSync.playerMsg(sender, ChatColor.BLUE + formattedDate + ChatColor.GOLD + " changed to " + ChatColor.GREEN + oldNames[i].getName()); - } - } - - private static class FName implements Comparable - { - private final String name; - private final long changedToAt; - - //Added constructor because otherwise there's no way name or changedToAt would have been anything other than null. - public FName(String name, long changedToAt) - { - this.name = name; - this.changedToAt = changedToAt; - } - - @Override - public int compareTo(FName other) - { - return Long.compare(this.changedToAt, other.changedToAt); - } - - public String getName() - { - return name; - } - - public long getChangedToAt() - { - return changedToAt; - } - } -} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/UUIDFetcher.java b/src/main/java/me/totalfreedom/totalfreedommod/util/UUIDFetcher.java deleted file mode 100644 index d0b4881f..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/UUIDFetcher.java +++ /dev/null @@ -1,68 +0,0 @@ -package me.totalfreedom.totalfreedommod.util; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.UUID; - -// UUIDFetcher retrieves UUIDs from usernames via web requests to Mojang. -public class UUIDFetcher -{ - - private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; - - public static UUID fetch(String name) - { - try - { - Gson gson = new GsonBuilder().create(); - UUID uuid; - String body = gson.toJson(name); - URL url = new URL(PROFILE_URL); - HttpURLConnection connection = (HttpURLConnection)url.openConnection(); - connection.setRequestMethod("POST"); - connection.setRequestProperty("Content-Type", "application/json"); - connection.setUseCaches(false); - connection.setDoInput(true); - connection.setDoOutput(true); - OutputStream stream = connection.getOutputStream(); - stream.write(body.getBytes()); - stream.flush(); - stream.close(); - FetchedUuid[] id = gson.fromJson( - new InputStreamReader(connection.getInputStream()), - FetchedUuid[].class); - - if (id.length == 0 || id[0].getID() == null) - { - return null; - } - - String idd = id[0].getID(); - uuid = UUID.fromString(idd.substring(0, 8) + "-" + idd.substring(8, 12) - + "-" + idd.substring(12, 16) + "-" + idd.substring(16, 20) + "-" - + idd.substring(20, 32)); - return uuid; - } - catch (IOException ex) - { - FLog.severe(ex); - } - return null; - } - - private static class FetchedUuid - { - - private String id; - - public String getID() - { - return id; - } - } -} \ No newline at end of file