mirror of
https://github.com/plexusorg/Plex.git
synced 2025-06-28 22:46:40 +00:00
Reformat
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class AshconInfo
|
||||
|
@ -1,9 +1,10 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import lombok.Getter;
|
||||
|
||||
public class BuildInfo
|
||||
{
|
||||
|
@ -1,11 +1,12 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import java.util.Locale;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class GameRuleUtil
|
||||
{
|
||||
public static <T> void commitGlobalGameRules(World world)
|
||||
@ -28,8 +29,8 @@ public class GameRuleUtil
|
||||
private static <T> void readGameRules(World world, String s)
|
||||
{
|
||||
String gameRule = s.split(";")[0];
|
||||
T value = (T)s.split(";")[1];
|
||||
GameRule<T> rule = (GameRule<T>)GameRule.getByName(gameRule);
|
||||
T value = (T) s.split(";")[1];
|
||||
GameRule<T> rule = (GameRule<T>) GameRule.getByName(gameRule);
|
||||
if (rule != null && check(value).getClass().equals(rule.getType()))
|
||||
{
|
||||
world.setGameRule(rule, value);
|
||||
|
@ -3,6 +3,13 @@ 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;
|
||||
@ -10,12 +17,6 @@ import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
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;
|
||||
|
||||
public class MojangUtils
|
||||
{
|
||||
@ -38,7 +39,7 @@ public class MojangUtils
|
||||
return null;
|
||||
}
|
||||
client.close();
|
||||
AshconInfo ashconInfo = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, (JsonDeserializer<ZonedDateTime>)(json1, typeOfT, context) ->
|
||||
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) ->
|
||||
|
@ -8,15 +8,6 @@ import dev.plex.listener.impl.ChatListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.storage.StorageType;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Month;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@ -30,6 +21,16 @@ import org.bukkit.command.PluginCommandYamlParser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Month;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlexUtils implements PlexBase
|
||||
{
|
||||
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
|
||||
@ -185,7 +186,7 @@ public class PlexUtils implements PlexBase
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((TextComponent)component).content();
|
||||
return ((TextComponent) component).content();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -1,8 +1,9 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class RandomUtil
|
||||
{
|
||||
|
||||
|
@ -3,6 +3,7 @@ package dev.plex.util;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import dev.plex.Plex;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -48,7 +49,7 @@ public class ReflectionsUtil
|
||||
{
|
||||
if (clazz.getSuperclass() == subType || Arrays.asList(clazz.getInterfaces()).contains(subType))
|
||||
{
|
||||
classes.add((Class<? extends T>)clazz);
|
||||
classes.add((Class<? extends T>) clazz);
|
||||
}
|
||||
});
|
||||
return Collections.unmodifiableSet(classes);
|
||||
|
@ -1,6 +1,8 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
@ -9,7 +11,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
||||
public class TimeUtils
|
||||
{
|
||||
|
@ -5,16 +5,6 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import dev.plex.PlexBase;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import javax.annotation.Nonnull;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@ -27,6 +17,17 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class UpdateChecker implements PlexBase
|
||||
{
|
||||
/*
|
||||
@ -47,7 +48,7 @@ public class UpdateChecker implements PlexBase
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpURLConnection connection = (HttpURLConnection)new URL("https://api.github.com/repos/" + repo + "/compare/" + branch + "..." + hash).openConnection();
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL("https://api.github.com/repos/" + repo + "/compare/" + branch + "..." + hash).openConnection();
|
||||
connection.connect();
|
||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND)
|
||||
{
|
||||
|
@ -1,14 +1,15 @@
|
||||
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;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
public class WebUtils
|
||||
{
|
||||
@ -17,7 +18,7 @@ public class WebUtils
|
||||
try
|
||||
{
|
||||
URL u = new URL(url);
|
||||
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
|
||||
HttpURLConnection connection = (HttpURLConnection) u.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line;
|
||||
@ -39,13 +40,13 @@ public class WebUtils
|
||||
public static UUID getFromName(String name)
|
||||
{
|
||||
JSONObject profile;
|
||||
profile = (JSONObject)simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
|
||||
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");
|
||||
String uuidString = (String) profile.get("uuid");
|
||||
return UUID.fromString(uuidString);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,8 @@
|
||||
package dev.plex.util.adapter;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.*;
|
||||
import dev.plex.Plex;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package dev.plex.util.item;
|
||||
|
||||
import java.util.Arrays;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
@ -10,6 +9,8 @@ import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ItemBuilder
|
||||
{
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package dev.plex.util.minimessage;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.Context;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@ -12,6 +11,8 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SafeMiniMessage
|
||||
{
|
||||
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(new SafeMiniMessageTagResolver()).build();
|
||||
|
@ -6,7 +6,6 @@ import dev.plex.Plex;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -14,29 +13,43 @@ import org.bukkit.entity.Player;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static dev.plex.util.PlexUtils.messageComponent;
|
||||
|
||||
public class MessageUtil {
|
||||
public class MessageUtil
|
||||
{
|
||||
private static final Gson GSON = new Gson();
|
||||
private static JedisPubSub SUBSCRIBER;
|
||||
|
||||
public static void subscribe() {
|
||||
public static void subscribe()
|
||||
{
|
||||
PlexLog.debug("Subscribing");
|
||||
SUBSCRIBER = new JedisPubSub() {
|
||||
SUBSCRIBER = new JedisPubSub()
|
||||
{
|
||||
@Override
|
||||
public void onMessage(String channel, String message) {
|
||||
try {
|
||||
public void onMessage(String channel, String message)
|
||||
{
|
||||
try
|
||||
{
|
||||
JSONObject object = new JSONObject(message);
|
||||
if (channel.equalsIgnoreCase("staffchat")) {
|
||||
UUID[] ignore = GSON.fromJson(object.getString("ignore"), new TypeToken<UUID[]>(){}.getType());
|
||||
String sender = object.getString("sender").isEmpty() ? "CONSOLE": object.getString("sender");
|
||||
if (channel.equalsIgnoreCase("staffchat"))
|
||||
{
|
||||
UUID[] ignore = GSON.fromJson(object.getString("ignore"), new TypeToken<UUID[]>()
|
||||
{
|
||||
}.getType());
|
||||
String sender = object.getString("sender").isEmpty() ? "CONSOLE" : object.getString("sender");
|
||||
PlexUtils.adminChat(sender, object.getString("message"), ignore);
|
||||
String[] server = object.getString("server").split(":");
|
||||
if (!Bukkit.getServer().getIp().equalsIgnoreCase(server[0]) || Bukkit.getServer().getPort() != Integer.parseInt(server[1])) {
|
||||
if (!Bukkit.getServer().getIp().equalsIgnoreCase(server[0]) || Bukkit.getServer().getPort() != Integer.parseInt(server[1]))
|
||||
{
|
||||
Plex.get().getServer().getConsoleSender().sendMessage(messageComponent("adminChatFormat", sender, object.getString("message")));
|
||||
}
|
||||
}
|
||||
} catch (JSONException ignored) {
|
||||
}
|
||||
catch (JSONException ignored)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -47,14 +60,17 @@ public class MessageUtil {
|
||||
PlexLog.debug("Subscribed to {0}", channel);
|
||||
}
|
||||
};
|
||||
// SUBSCRIBER.subscribe("staffchat", "chat");
|
||||
Plex.get().getRedisConnection().runAsync(jedis -> {
|
||||
// SUBSCRIBER.subscribe("staffchat", "chat");
|
||||
Plex.get().getRedisConnection().runAsync(jedis ->
|
||||
{
|
||||
jedis.subscribe(SUBSCRIBER, "staffchat", "chat");
|
||||
});
|
||||
}
|
||||
|
||||
public static void sendStaffChat(CommandSender sender, Component message, UUID... ignore) {
|
||||
if (!Plex.get().getRedisConnection().isEnabled() || Plex.get().getRedisConnection().getJedis() == null) {
|
||||
public static void sendStaffChat(CommandSender sender, Component message, UUID... ignore)
|
||||
{
|
||||
if (!Plex.get().getRedisConnection().isEnabled() || Plex.get().getRedisConnection().getJedis() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user