mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Removes /nh and code associated with it (except this time its based on the right branch)
This commit is contained in:
parent
44bae8ab00
commit
2d918fe17b
@ -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 = "/<command> <username>", 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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<FName>
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user