mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Remove WebUtils, MojangUtils, and ashcon and replace references of WebUtils with DataUtils#getPlayer(String username)
This commit is contained in:
parent
cc9967f9c2
commit
bc8c89449e
@ -14,7 +14,6 @@ import dev.plex.punishment.PunishmentType;
|
|||||||
import dev.plex.util.BungeeUtil;
|
import dev.plex.util.BungeeUtil;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import dev.plex.util.WebUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -24,7 +23,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason]", description = "Temporarily ban a player")
|
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason]", description = "Temporarily ban a player")
|
||||||
@CommandPermissions(permission = "plex.tempban", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.tempban", source = RequiredCommandSource.ANY)
|
||||||
@ -39,22 +37,20 @@ public class TempbanCMD extends PlexCommand
|
|||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
PlexPlayer target = DataUtils.getPlayer(args[0]);
|
||||||
String reason;
|
String reason;
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (target == null)
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
|
Player player = Bukkit.getPlayer(target.getUuid());
|
||||||
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
if (plugin.getPunishmentManager().isBanned(target.getUuid()))
|
||||||
Player player = Bukkit.getPlayer(targetUUID);
|
|
||||||
|
|
||||||
if (plugin.getPunishmentManager().isBanned(targetUUID))
|
|
||||||
{
|
{
|
||||||
return messageComponent("playerBanned");
|
return messageComponent("playerBanned");
|
||||||
}
|
}
|
||||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
Punishment punishment = new Punishment(target.getUuid(), getUUID(sender));
|
||||||
punishment.setType(PunishmentType.TEMPBAN);
|
punishment.setType(PunishmentType.TEMPBAN);
|
||||||
if (args.length > 2)
|
if (args.length > 2)
|
||||||
{
|
{
|
||||||
@ -65,7 +61,7 @@ public class TempbanCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
punishment.setReason("No reason provided.");
|
punishment.setReason("No reason provided.");
|
||||||
}
|
}
|
||||||
punishment.setPunishedUsername(plexPlayer.getName());
|
punishment.setPunishedUsername(target.getName());
|
||||||
punishment.setEndDate(TimeUtils.createDate(args[1]));
|
punishment.setEndDate(TimeUtils.createDate(args[1]));
|
||||||
punishment.setCustomTime(false);
|
punishment.setCustomTime(false);
|
||||||
punishment.setActive(true);
|
punishment.setActive(true);
|
||||||
@ -73,8 +69,8 @@ public class TempbanCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||||
}
|
}
|
||||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
plugin.getPunishmentManager().punish(target, punishment);
|
||||||
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName()));
|
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), target.getName()));
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment));
|
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment));
|
||||||
|
@ -11,7 +11,6 @@ import dev.plex.command.source.RequiredCommandSource;
|
|||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.WebUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -19,7 +18,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
||||||
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||||
@ -36,23 +34,22 @@ public class UnbanCMD extends PlexCommand
|
|||||||
|
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
PlexPlayer target = DataUtils.getPlayer(args[0]);
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (target == null)
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) ->
|
plugin.getPunishmentManager().isAsyncBanned(target.getUuid()).whenComplete((aBoolean, throwable) ->
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = getOfflinePlexPlayer(targetUUID);
|
|
||||||
if (!aBoolean)
|
if (!aBoolean)
|
||||||
{
|
{
|
||||||
send(sender, PlexUtils.mmDeserialize(new PlayerNotBannedException().getMessage()));
|
send(sender, PlexUtils.mmDeserialize(new PlayerNotBannedException().getMessage()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.getPunishmentManager().unban(targetUUID);
|
plugin.getPunishmentManager().unban(target.getUuid());
|
||||||
PlexUtils.broadcast(messageComponent("unbanningPlayer", sender.getName(), plexPlayer.getName()));
|
PlexUtils.broadcast(messageComponent("unbanningPlayer", sender.getName(), target.getName()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -3,9 +3,7 @@ package dev.plex.punishment;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.cache.DataUtils;
|
|
||||||
import dev.plex.storage.annotation.SQLTable;
|
import dev.plex.storage.annotation.SQLTable;
|
||||||
import dev.plex.util.MojangUtils;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
package dev.plex.util;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class AshconInfo
|
|
||||||
{
|
|
||||||
private String uuid;
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
@SerializedName("username_history")
|
|
||||||
private UsernameHistory[] usernameHistories;
|
|
||||||
|
|
||||||
private Textures textures;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@NoArgsConstructor
|
|
||||||
public static class UsernameHistory
|
|
||||||
{
|
|
||||||
private String username;
|
|
||||||
@SerializedName("changed_at")
|
|
||||||
private ZonedDateTime zonedDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@NoArgsConstructor
|
|
||||||
public static class Textures
|
|
||||||
{
|
|
||||||
private boolean custom;
|
|
||||||
private boolean slim;
|
|
||||||
private SkinData raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@NoArgsConstructor
|
|
||||||
public static class SkinData
|
|
||||||
{
|
|
||||||
private String value;
|
|
||||||
private String signature;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
package dev.plex.util;
|
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonDeserializer;
|
|
||||||
import dev.plex.Plex;
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class MojangUtils
|
|
||||||
{
|
|
||||||
|
|
||||||
public static AshconInfo getInfo(String nameOrUuid)
|
|
||||||
{
|
|
||||||
CloseableHttpClient client = HttpClients.createDefault();
|
|
||||||
HttpGet get = new HttpGet("https://api.ashcon.app/mojang/v2/user/" + nameOrUuid);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
HttpResponse response = client.execute(get);
|
|
||||||
if (response == null || response.getEntity() == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
|
||||||
JSONObject object = new JSONObject(json);
|
|
||||||
if (!object.isNull("code") && object.getInt("code") == 404)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
client.close();
|
|
||||||
AshconInfo ashconInfo = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, (JsonDeserializer<ZonedDateTime>) (json1, typeOfT, context) ->
|
|
||||||
ZonedDateTime.ofInstant(Instant.from(DateTimeFormatter.ISO_INSTANT.parse(json1.getAsJsonPrimitive().getAsString())), ZoneId.of(Plex.get().config.getString("server.timezone")))).create().fromJson(json, AshconInfo.class);
|
|
||||||
|
|
||||||
Arrays.sort(ashconInfo.getUsernameHistories(), (o1, o2) ->
|
|
||||||
{
|
|
||||||
if (o1.getZonedDateTime() == null || o2.getZonedDateTime() == null)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return o1.getZonedDateTime().compareTo(o2.getZonedDateTime());
|
|
||||||
});
|
|
||||||
|
|
||||||
return ashconInfo;
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
package dev.plex.util;
|
|
||||||
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class WebUtils
|
|
||||||
{
|
|
||||||
public static Object simpleGET(String url)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
catch (IOException | ParseException ex)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UUID getFromName(String name)
|
|
||||||
{
|
|
||||||
JSONObject profile;
|
|
||||||
profile = (JSONObject) simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
|
|
||||||
if (profile == null)
|
|
||||||
{
|
|
||||||
PlexLog.error("Profile from Ashcon API returned null!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String uuidString = (String) profile.get("uuid");
|
|
||||||
return UUID.fromString(uuidString);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user