mirror of
https://github.com/plexusorg/Plex.git
synced 2026-06-04 21:46:55 +00:00
More modernization for the database
This commit is contained in:
@@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class BungeeUtil
|
||||
{
|
||||
public static void kickPlayer(Player player, Component message)
|
||||
public static void kickPlayer(Plex plugin, Player player, Component message)
|
||||
{
|
||||
if (Bukkit.getServerConfig().isProxyEnabled())
|
||||
{
|
||||
@@ -18,7 +18,7 @@ public class BungeeUtil
|
||||
out.writeUTF("KickPlayer");
|
||||
out.writeUTF(player.getName());
|
||||
out.writeUTF(LegacyComponentSerializer.legacySection().serialize(message));
|
||||
player.sendPluginMessage(Plex.get(), "BungeeCord", out.toByteArray());
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -13,17 +13,17 @@ import org.bukkit.World;
|
||||
|
||||
public class GameRuleUtil
|
||||
{
|
||||
public static void commitGlobalGameRules(World world)
|
||||
public static void commitGlobalGameRules(Plex plugin, World world)
|
||||
{
|
||||
for (String s : Plex.get().config.getStringList("global_gamerules"))
|
||||
for (String s : plugin.config.getStringList("global_gamerules"))
|
||||
{
|
||||
readGameRules(world, s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void commitSpecificGameRules(World world)
|
||||
public static void commitSpecificGameRules(Plex plugin, World world)
|
||||
{
|
||||
for (String s : Plex.get().config.getStringList("worlds." + world.getName().toLowerCase(Locale.ROOT) + ".gameRules"))
|
||||
for (String s : plugin.config.getStringList("worlds." + world.getName().toLowerCase(Locale.ROOT) + ".gameRules"))
|
||||
{
|
||||
readGameRules(world, s);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
@@ -8,6 +7,7 @@ import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
public class PlexLog
|
||||
{
|
||||
private static final ComponentLogger logger = ComponentLogger.logger("");
|
||||
private static boolean debugEnabled;
|
||||
|
||||
public static void log(String message, Object... strings)
|
||||
{
|
||||
@@ -62,9 +62,14 @@ public class PlexLog
|
||||
logger.warn(PlexUtils.mmDeserialize("<#eb7c0e>[Plex Warning] <gold>" + message));
|
||||
}
|
||||
|
||||
public static void setDebugEnabled(boolean debugEnabled)
|
||||
{
|
||||
PlexLog.debugEnabled = debugEnabled;
|
||||
}
|
||||
|
||||
public static void debug(String message, Object... strings)
|
||||
{
|
||||
if (Plex.get().config.getBoolean("debug"))
|
||||
if (debugEnabled)
|
||||
{
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.plex.util;
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.config.Config;
|
||||
import dev.plex.listener.impl.ChatListener;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
|
||||
@@ -34,9 +34,17 @@ import org.bukkit.command.PluginCommandYamlParser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class PlexUtils implements PlexBase
|
||||
public class PlexUtils
|
||||
{
|
||||
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
|
||||
private static Config config;
|
||||
private static Config messages;
|
||||
|
||||
public static void configure(Config config, Config messages)
|
||||
{
|
||||
PlexUtils.config = config;
|
||||
PlexUtils.messages = messages;
|
||||
}
|
||||
|
||||
public static List<String> DEVELOPERS =
|
||||
Arrays.asList("78408086-1991-4c33-a571-d8fa325465b2", // Telesphoreo
|
||||
@@ -78,13 +86,13 @@ public class PlexUtils implements PlexBase
|
||||
players[0].getWorld().playSound(location, org.bukkit.Sound.BLOCK_FIRE_EXTINGUISH, 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
public static void testConnections()
|
||||
public static void testConnections(Plex plugin)
|
||||
{
|
||||
if (Plex.get().getSqlConnection().getDataSource() != null)
|
||||
if (plugin.getSqlConnection().getDataSource() != null)
|
||||
{
|
||||
try (Connection ignored = Plex.get().getSqlConnection().getCon())
|
||||
try (Connection ignored = plugin.getSqlConnection().getCon())
|
||||
{
|
||||
PlexLog.log("Successfully enabled " + Plex.get().getStorageType().getDisplayName() + "!");
|
||||
PlexLog.log("Successfully enabled " + plugin.getStorageType().getDisplayName() + "!");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
@@ -194,9 +202,9 @@ public class PlexUtils implements PlexBase
|
||||
public static Component mmDeserialize(String input)
|
||||
{
|
||||
boolean aprilFools = true; // true by default
|
||||
if (plugin.config.contains("april_fools"))
|
||||
if (config != null && config.contains("april_fools"))
|
||||
{
|
||||
aprilFools = plugin.config.getBoolean("april_fools");
|
||||
aprilFools = config.getBoolean("april_fools");
|
||||
}
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.systemDefault());
|
||||
if (aprilFools && date.getMonth() == Month.APRIL && date.getDayOfMonth() == 1)
|
||||
@@ -235,7 +243,7 @@ public class PlexUtils implements PlexBase
|
||||
|
||||
public static String messageString(String entry, Object... objects)
|
||||
{
|
||||
String f = plugin.messages.getString(entry);
|
||||
String f = messages.getString(entry);
|
||||
if (f == null)
|
||||
{
|
||||
throw new NullPointerException();
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import dev.plex.Plex;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
@@ -28,7 +26,7 @@ public class TimeUtils
|
||||
add("mo");
|
||||
add("y");
|
||||
}};
|
||||
public static String TIMEZONE = Plex.get().config.getString("server.timezone");
|
||||
public static String TIMEZONE = "Etc/UTC";
|
||||
|
||||
private static int parseInteger(String s) throws NumberFormatException
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.plex.util;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.Plex;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -23,7 +23,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class UpdateChecker implements PlexBase
|
||||
public class UpdateChecker
|
||||
{
|
||||
/*
|
||||
* -4 = Never checked for updates
|
||||
@@ -33,11 +33,19 @@ public class UpdateChecker implements PlexBase
|
||||
* 0 = Up to date
|
||||
* > 0 = Number of commits behind
|
||||
*/
|
||||
private final Plex plugin;
|
||||
private final String DOWNLOAD_PAGE = "https://ci.plex.us.org/job/";
|
||||
private final String REPO = plugin.config.getString("update_repo");
|
||||
private String BRANCH = plugin.config.getString("update_branch");
|
||||
private final String REPO;
|
||||
private String BRANCH;
|
||||
private int distance = -4;
|
||||
|
||||
public UpdateChecker(Plex plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.REPO = plugin.config.getString("update_repo");
|
||||
this.BRANCH = plugin.config.getString("update_branch");
|
||||
}
|
||||
|
||||
// Adapted from Paper
|
||||
private int fetchDistanceFromGitHub(@NonNull String repo, @NonNull String branch, @NonNull String hash)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.Instant;
|
||||
@@ -16,7 +16,7 @@ import java.time.ZonedDateTime;
|
||||
|
||||
public class ZonedDateTimeAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime>
|
||||
{
|
||||
private static final String TIMEZONE = Plex.get().config.getString("server.timezone");
|
||||
private static final String TIMEZONE = TimeUtils.TIMEZONE;
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ZonedDateTime src, Type typeOfSrc, JsonSerializationContext context)
|
||||
|
||||
@@ -25,7 +25,7 @@ public class MessageUtil
|
||||
private static final Gson GSON = new Gson();
|
||||
private static JedisPubSub SUBSCRIBER;
|
||||
|
||||
public static void subscribe()
|
||||
public static void subscribe(Plex plugin)
|
||||
{
|
||||
PlexLog.debug("Subscribing");
|
||||
SUBSCRIBER = new JedisPubSub()
|
||||
@@ -46,7 +46,7 @@ public class MessageUtil
|
||||
String[] server = object.getString("server").split(":");
|
||||
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")));
|
||||
plugin.getServer().getConsoleSender().sendMessage(messageComponent("adminChatFormat", sender, object.getString("message")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,15 +63,15 @@ public class MessageUtil
|
||||
}
|
||||
};
|
||||
// SUBSCRIBER.subscribe("staffchat", "chat");
|
||||
Plex.get().getRedisConnection().runAsync(jedis ->
|
||||
plugin.getRedisConnection().runAsync(jedis ->
|
||||
{
|
||||
jedis.subscribe(SUBSCRIBER, "staffchat", "chat");
|
||||
});
|
||||
}
|
||||
|
||||
public static void sendStaffChat(CommandSender sender, Component message, UUID... ignore)
|
||||
public static void sendStaffChat(Plex plugin, CommandSender sender, Component message, UUID... ignore)
|
||||
{
|
||||
if (!Plex.get().getRedisConnection().isEnabled() || Plex.get().getRedisConnection().getJedis() == null)
|
||||
if (!plugin.getRedisConnection().isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -82,6 +82,6 @@ public class MessageUtil
|
||||
object.put("message", miniMessage);
|
||||
object.put("ignore", GSON.toJson(ignore));
|
||||
object.put("server", String.format("%s:%s", Bukkit.getServer().getIp(), Bukkit.getServer().getPort()));
|
||||
Plex.get().getRedisConnection().getJedis().publish("staffchat", object.toString());
|
||||
plugin.getRedisConnection().execute(jedis -> jedis.publish("staffchat", object.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user