so far it is working but the only thing preventing me from going to fully asynchronous calls for punishments is httpd...

This commit is contained in:
Taah
2022-04-04 01:36:50 -07:00
parent 35d436bb61
commit 6f4bc5aec1
38 changed files with 483 additions and 528 deletions

View File

@ -6,39 +6,11 @@ import dev.plex.Plex;
import dev.plex.PlexBase;
import dev.plex.config.Config;
import dev.plex.storage.StorageType;
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.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameRule;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.PluginCommandYamlParser;
import org.bukkit.entity.Player;
@ -47,6 +19,20 @@ 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.sql.Connection;
import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
public class PlexUtils extends PlexBase
{
private static final Random RANDOM;
@ -85,27 +71,21 @@ public class PlexUtils extends PlexBase
public static void testConnections()
{
if (Plex.get().getSqlConnection().getCon() != null)
try (Connection con = Plex.get().getSqlConnection().getCon())
{
if (Plex.get().getStorageType() == StorageType.MARIADB)
{
PlexLog.log("Successfully enabled MySQL!");
}
else if (Plex.get().getStorageType() == StorageType.SQLITE)
} else if (Plex.get().getStorageType() == StorageType.SQLITE)
{
PlexLog.log("Successfully enabled SQLite!");
}
try
{
Plex.get().getSqlConnection().getCon().close();
}
catch (SQLException ignored)
{
}
}
else if (Plex.get().getMongoConnection().getDatastore() != null)
} catch (SQLException e)
{
PlexLog.log("Successfully enabled MongoDB!");
if (Plex.get().getMongoConnection().getDatastore() != null)
{
PlexLog.log("Successfully enabled MongoDB!");
}
}
}
@ -211,12 +191,10 @@ public class PlexUtils extends PlexBase
if (config.getString(path) == null)
{
color = def;
}
else if (ChatColor.getByChar(config.getString(path)) == null)
} else if (ChatColor.getByChar(config.getString(path)) == null)
{
color = def;
}
else
} else
{
color = ChatColor.getByChar(config.getString(path));
}
@ -262,14 +240,13 @@ public class PlexUtils extends PlexBase
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);
PlexLog.debug("Setting game rule " + gameRule + " for world " + world.getName() + " with value " + value);
}
else
} else
{
PlexLog.error(String.format("Failed to set game rule %s for world %s with value %s!", gameRule, world.getName().toLowerCase(Locale.ROOT), value));
}
@ -309,7 +286,7 @@ public class PlexUtils extends PlexBase
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;
@ -321,8 +298,7 @@ public class PlexUtils extends PlexBase
in.close();
connection.disconnect();
return new JSONParser().parse(content.toString());
}
catch (IOException | ParseException ex)
} catch (IOException | ParseException ex)
{
return null;
}
@ -331,13 +307,13 @@ public class PlexUtils extends PlexBase
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);
}
@ -355,14 +331,12 @@ public class PlexUtils extends PlexBase
{
Class<?> clazz = Class.forName(info.getName());
classes.add(clazz);
}
catch (ClassNotFoundException ex)
} catch (ClassNotFoundException ex)
{
PlexLog.error("Unable to find class " + info.getName() + " in " + packageName);
}
});
}
catch (IOException ex)
} catch (IOException ex)
{
PlexLog.error("Something went wrong while fetching classes from " + packageName);
throw new RuntimeException(ex);
@ -379,7 +353,7 @@ public class PlexUtils extends PlexBase
{
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);