mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
name history
i still need to test bcuz i dont have an alt
This commit is contained in:
parent
52be58872e
commit
8428e2a6d3
@ -17,6 +17,8 @@ import me.totalfreedom.plex.util.PlexUtils;
|
||||
import me.totalfreedom.plex.world.CustomWorld;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Plex extends JavaPlugin
|
||||
|
@ -12,6 +12,7 @@ import me.totalfreedom.plex.command.source.CommandSource;
|
||||
import me.totalfreedom.plex.command.source.RequiredCommandSource;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
import me.totalfreedom.plex.util.PlexLog;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
@ -69,6 +70,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
if (!matches(label)) return false;
|
||||
if (this.sender == null)
|
||||
this.sender = new CommandSource(sender);
|
||||
PlexLog.log(this.sender.getSender().getName());
|
||||
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
||||
{
|
||||
send(tl("noPermissionInGame"));
|
||||
|
@ -0,0 +1,78 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import me.totalfreedom.plex.command.PlexCommand;
|
||||
import me.totalfreedom.plex.command.annotation.CommandParameters;
|
||||
import me.totalfreedom.plex.command.annotation.CommandPermissions;
|
||||
import me.totalfreedom.plex.command.exception.CommandArgumentException;
|
||||
import me.totalfreedom.plex.command.source.CommandSource;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
import me.totalfreedom.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static me.totalfreedom.plex.util.PlexUtils.tl;
|
||||
|
||||
@CommandParameters(description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
|
||||
@CommandPermissions(level = Rank.OP)
|
||||
public class NameHistoryCMD extends PlexCommand
|
||||
{
|
||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy 'at' HH:mm:ss");
|
||||
|
||||
public NameHistoryCMD()
|
||||
{
|
||||
super("namehistory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
throw new CommandArgumentException();
|
||||
String username = args[0];
|
||||
JSONArray array;
|
||||
try
|
||||
{
|
||||
JSONObject profile = (JSONObject) PlexUtils.simpleGET("https://api.mojang.com/users/profiles/minecraft/" + username);
|
||||
String uuid = (String) profile.get("id");
|
||||
array = (JSONArray) PlexUtils.simpleGET("https://api.mojang.com/user/profiles/" + uuid + "/names");
|
||||
}
|
||||
catch (ParseException | IOException ex)
|
||||
{
|
||||
send(tl("nameHistoryFail", username));
|
||||
return;
|
||||
}
|
||||
|
||||
array.sort(Comparator.reverseOrder());
|
||||
|
||||
StringBuilder result = new StringBuilder()
|
||||
.append(tl("nameHistoryTitle", username))
|
||||
.append("\n");
|
||||
for (Object o : array)
|
||||
{
|
||||
JSONObject object = (JSONObject) o;
|
||||
Object changedToAt = object.get("changedToAt");
|
||||
if (changedToAt == null)
|
||||
changedToAt = "O";
|
||||
else
|
||||
changedToAt = DATE_FORMAT.format(changedToAt);
|
||||
result.append(tl("nameHistoryBody", object.get("name"), changedToAt))
|
||||
.append("\n");
|
||||
}
|
||||
send(result.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : null;
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ public class CommandHandler
|
||||
commands.add(new OpAllCMD());
|
||||
commands.add(new OpCMD());
|
||||
commands.add(new FreezeCMD());
|
||||
commands.add(new NameHistoryCMD());
|
||||
|
||||
PlexLog.log(String.format("Registered %s commands!", commands.size()));
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
package me.totalfreedom.plex.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.totalfreedom.plex.Plex;
|
||||
@ -14,6 +18,8 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginCommandYamlParser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
public class PlexUtils
|
||||
{
|
||||
@ -78,7 +84,7 @@ public class PlexUtils
|
||||
if (f == null)
|
||||
return ChatColor.RED + "No message";
|
||||
for (Object object : objects)
|
||||
f = f.replace("<v>", String.valueOf(object));
|
||||
f = f.replaceFirst("<v>", String.valueOf(object));
|
||||
ChatColor base = getChatColorFromConfig(plugin.messages, ChatColor.GRAY, "baseColor");
|
||||
ChatColor broadcast = getChatColorFromConfig(plugin.messages, ChatColor.AQUA, "broadcastColor");
|
||||
ChatColor error = getChatColorFromConfig(plugin.messages, ChatColor.RED, "errorColor");
|
||||
@ -136,4 +142,19 @@ public class PlexUtils
|
||||
{
|
||||
Bukkit.broadcastMessage(s);
|
||||
}
|
||||
|
||||
public static Object simpleGET(String url) throws IOException, ParseException
|
||||
{
|
||||
URL u = new URL(url);
|
||||
HttpURLConnection connection = (HttpURLConnection) u.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line;
|
||||
StringBuilder content = new StringBuilder();
|
||||
while ((line = in.readLine()) != null)
|
||||
content.append(line);
|
||||
in.close();
|
||||
connection.disconnect();
|
||||
return new JSONParser().parse(content.toString());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.totalfreedom.plex.world;
|
||||
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
@ -10,6 +9,7 @@ import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CustomWorld extends WorldCreator
|
||||
@ -45,9 +45,9 @@ public class CustomWorld extends WorldCreator
|
||||
@Override
|
||||
public World generate()
|
||||
{
|
||||
boolean addFeatures = Bukkit.getWorld(name) == null;
|
||||
boolean existed = new File(name).exists();
|
||||
World world = super.generate();
|
||||
if (addFeatures)
|
||||
if (!existed)
|
||||
{
|
||||
Block block = world.getBlockAt(0, world.getHighestBlockYAt(0, 0) + 1, 0);
|
||||
block.setType(Material.OAK_SIGN);
|
||||
|
@ -44,3 +44,10 @@ noPermission: <e>You cannot use this command!
|
||||
noPermissionRank: <e>You must be at least <v> rank to use this command!
|
||||
noPermissionInGame: <e>You must be in console to use this command!
|
||||
noPermissionConsole: <e>You must be in-game to use this command!
|
||||
# 1: the username of the name history
|
||||
nameHistoryTitle: Name History of <v>
|
||||
# 1: a username of the found user
|
||||
# 2: when the user changed to that username
|
||||
nameHistoryBody: " - <v> (<v>)"
|
||||
# 1: the username that failed
|
||||
nameHistoryFail: <e>Something went wrong while trying to retrieve name history of <v>! Try again later!
|
Loading…
Reference in New Issue
Block a user