diff --git a/build.gradle.kts b/build.gradle.kts index 8f563a6c..78471c84 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,10 +18,12 @@ repositories { } dependencies { + implementation("com.github.Minestom", "Minestom", "6b8a4e4cc9") // minstom itself implementation("com.google.code.gson:gson:2.10.1") // serializing implementation("org.slf4j:slf4j-api:2.0.13") // logging implementation("net.kyori:adventure-text-minimessage:4.16.0")// better components + implementation("mysql:mysql-connector-java:8.0.28") //mysql connector implementation("org.tomlj:tomlj:1.1.1") // Config lang implementation("com.rabbitmq:amqp-client:5.21.0") // Message broker } @@ -36,11 +38,6 @@ tasks.withType { options.compilerArgs.add("--enable-preview") } -tasks.withType { - // use String templates - options.compilerArgs.add("--enable-preview") -} - tasks { assemble { dependsOn("shadowJar") @@ -51,5 +48,6 @@ tasks { } mergeServiceFiles() archiveFileName.set("cytosis.jar") + //destinationDirectory.set(file(providers.gradleProperty("server_dir").get())) } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 2aa768dd..08fcd7b8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,2 @@ -rootProject.name = "MinestomBase" +rootProject.name = "Cytosis" diff --git a/src/main/java/net/cytonic/cytosis/Cytosis.java b/src/main/java/net/cytonic/cytosis/Cytosis.java index 07a49b2f..ad364f0e 100644 --- a/src/main/java/net/cytonic/cytosis/Cytosis.java +++ b/src/main/java/net/cytonic/cytosis/Cytosis.java @@ -1,6 +1,7 @@ package net.cytonic.cytosis; import net.cytonic.cytosis.commands.CommandHandler; +import net.cytonic.cytosis.config.CytosisSettings; import net.cytonic.cytosis.events.EventHandler; import net.cytonic.cytosis.events.ServerEventListeners; import net.cytonic.cytosis.files.FileManager; @@ -17,9 +18,9 @@ import net.minestom.server.instance.block.Block; import net.minestom.server.network.ConnectionManager; import net.minestom.server.permission.Permission; - import java.util.*; + public class Cytosis { // manager stuff @@ -31,9 +32,10 @@ public class Cytosis { private static CommandManager COMMAND_MANAGER; private static CommandHandler COMMAND_HANDLER; private static FileManager FILE_MANAGER; + private static DatabaseManager DATABASE_MANAGER; private static MessagingManager MESSAGE_MANAGER; - private static ConsoleSender CONSOLE_SENDER; + private static int SERVER_PORT; private static List FLAGS; @@ -46,9 +48,6 @@ public static void main(String[] args) { MINECRAFT_SERVER = MinecraftServer.init(); MinecraftServer.setBrandName("Cytosis"); - Logger.info("Initializing Mojang Authentication"); - MojangAuth.init(); //VERY IMPORTANT! (This is online mode!) - Logger.info("Starting instance manager."); INSTANCE_MANAGER = MinecraftServer.getInstanceManager(); @@ -56,6 +55,9 @@ public static void main(String[] args) { CONNECTION_MANAGER = MinecraftServer.getConnectionManager(); + Logger.info("Starting manager."); + DATABASE_MANAGER = new DatabaseManager(); + // Commands Logger.info("Starting command manager."); COMMAND_MANAGER = MinecraftServer.getCommandManager(); @@ -78,6 +80,8 @@ public static void main(String[] args) { Logger.error("An error occurred whilst initializing the file manager!", throwable); } else { Logger.info("File manager initialized!"); + if (CytosisSettings.SERVER_ONLINE_MODE) + mojangAuth(); Logger.info("Completing nonessential startup tasks."); completeNonEssentialTasks(start); } @@ -100,6 +104,10 @@ public static CommandManager getCommandManager() { return COMMAND_MANAGER; } + public static DatabaseManager getDatabaseManager() { + return DATABASE_MANAGER; + } + public static Set getOnlinePlayers() { Set players = new HashSet<>(); INSTANCE_MANAGER.getInstances().forEach(instance -> players.addAll(instance.getPlayers())); @@ -108,9 +116,8 @@ public static Set getOnlinePlayers() { public static Optional getPlayer(String username) { Player target = null; - for (Player onlinePlayer : getOnlinePlayers()) { + for (Player onlinePlayer : getOnlinePlayers()) if (onlinePlayer.getUsername().equals(username)) target = onlinePlayer; - } return Optional.ofNullable(target); } @@ -134,6 +141,11 @@ public static ConsoleSender getConsoleSender() { return CONSOLE_SENDER; } + public static void mojangAuth() { + Logger.info("Initializing Mojang Authentication"); + MojangAuth.init(); //VERY IMPORTANT! (This is online mode!) + } + public static void completeNonEssentialTasks(long start) { // basic world generator Logger.info("Generating basic world"); @@ -146,6 +158,11 @@ public static void completeNonEssentialTasks(long start) { Logger.info("Initializing server events"); ServerEventListeners.initServerEvents(); + Logger.info("Initializing database"); + DATABASE_MANAGER.setupDatabase(); + + MinecraftServer.getSchedulerManager().buildShutdownTask(() -> DATABASE_MANAGER.shutdown()); + Logger.info("Initializing server commands"); COMMAND_HANDLER = new CommandHandler(); COMMAND_HANDLER.setupConsole(); @@ -159,12 +176,15 @@ public static void completeNonEssentialTasks(long start) { Logger.info("Messaging manager initialized!"); } }); + + SERVER_PORT = CytosisSettings.SERVER_PORT; // Start the server - Logger.info("Server started on port 25565"); - MINECRAFT_SERVER.start("0.0.0.0", 25565); + Logger.info(STR."Server started on port \{SERVER_PORT}"); + MINECRAFT_SERVER.start("0.0.0.0", SERVER_PORT); + long end = System.currentTimeMillis(); - Logger.info(StringTemplate.STR."Server started in \{end - start}ms!"); + Logger.info(STR."Server started in \{end - start}ms!"); if (FLAGS.contains("--ci-test")) { Logger.info("Stopping server due to '--ci-test' flag."); diff --git a/src/main/java/net/cytonic/cytosis/DatabaseManager.java b/src/main/java/net/cytonic/cytosis/DatabaseManager.java new file mode 100644 index 00000000..2831affa --- /dev/null +++ b/src/main/java/net/cytonic/cytosis/DatabaseManager.java @@ -0,0 +1,34 @@ +package net.cytonic.cytosis; + +import net.cytonic.cytosis.data.Database; +import net.cytonic.cytosis.logging.Logger; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class DatabaseManager { + + private final ExecutorService worker; + private Database database; + + public DatabaseManager() { + this.worker = Executors.newSingleThreadExecutor(Thread.ofVirtual().name("CytosisManagerWorker") + .uncaughtExceptionHandler((t, e) -> Logger.error(STR."An uncaught exception occoured on the thread: \{t.getName()}", e)).factory()); + } + + public void shutdown() { + worker.submit(() -> { + database.disconnect(); + Logger.info("Good night!"); + }); + } + + public void setupDatabase() { + worker.submit(() -> { + database = new Database(); + database.connect(); + database.createChatTable(); + }); + } + + public Database getDatabase() {return database;} +} \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/commands/GamemodeCommand.java b/src/main/java/net/cytonic/cytosis/commands/GamemodeCommand.java index 6df97548..79f853f8 100644 --- a/src/main/java/net/cytonic/cytosis/commands/GamemodeCommand.java +++ b/src/main/java/net/cytonic/cytosis/commands/GamemodeCommand.java @@ -18,7 +18,7 @@ public GamemodeCommand() { // using a gamemode as an argument var gameModeArgument = ArgumentType.Enum("gamemode", GameMode.class).setFormat(ArgumentEnum.Format.LOWER_CASED); - gameModeArgument.setCallback((sender, exception) -> sender.sendMessage("The gamemode " + exception.getInput() + " is invalid!")); + gameModeArgument.setCallback((sender, exception) -> sender.sendMessage(STR."The gamemode \{exception.getInput()} is invalid!")); var shorthand = ArgumentType.Word("shorthand").from("c", "s", "sv", "a", "0", "1", "2", "3"); shorthand.setSuggestionCallback((sender, context, suggestion) -> { @@ -27,13 +27,13 @@ public GamemodeCommand() { suggestion.addEntry(new SuggestionEntry("sv", Component.text("Represents the Survival gamemode"))); suggestion.addEntry(new SuggestionEntry("a", Component.text("Represents the Adventure gamemode"))); }); - shorthand.setCallback((sender, exception) -> sender.sendMessage(Component.text("The shorthand '" + exception.getInput() + "' is invalid!", NamedTextColor.RED))); + shorthand.setCallback((sender, exception) -> sender.sendMessage(Component.text(STR."The shorthand '\{exception.getInput()}' is invalid!", NamedTextColor.RED))); addSyntax((sender, context) -> { if (sender instanceof final Player player) { final GameMode gameMode = context.get(gameModeArgument); player.setGameMode(gameMode); - player.sendMessage(Component.text("Updated your gamemode to " + gameMode.name(), NamedTextColor.GREEN)); + player.sendMessage(Component.text(STR."Updated your gamemode to \{gameMode.name()}", NamedTextColor.GREEN)); } else { sender.sendMessage(Component.text("Hey! You can't do this.", NamedTextColor.RED)); } @@ -50,11 +50,11 @@ public GamemodeCommand() { case "sv", "0" -> gm = GameMode.SURVIVAL; } if (gm == null) { - sender.sendMessage(Component.text("The shorthand '" + gameMode + "' is invalid!", NamedTextColor.RED)); + sender.sendMessage(Component.text(STR."The shorthand '\{gameMode}' is invalid!", NamedTextColor.RED)); return; } player.setGameMode(gm); - player.sendMessage(Component.text("Updated your gamemode to " + gm.name(), NamedTextColor.GREEN)); + player.sendMessage(Component.text(STR."Updated your gamemode to \{gm.name()}", NamedTextColor.GREEN)); } else { sender.sendMessage(Component.text("Hey! You can't do this.", NamedTextColor.RED)); } diff --git a/src/main/java/net/cytonic/cytosis/commands/OperatorCommand.java b/src/main/java/net/cytonic/cytosis/commands/OperatorCommand.java index 35d339b6..c8f3aa14 100644 --- a/src/main/java/net/cytonic/cytosis/commands/OperatorCommand.java +++ b/src/main/java/net/cytonic/cytosis/commands/OperatorCommand.java @@ -17,7 +17,7 @@ public OperatorCommand() { var playerArg = ArgumentType.Word("player").from(getPlayerNames()); playerArg.setCallback((sender, exception) -> { final String input = exception.getInput(); - sender.sendMessage("The player " + input + " is invalid!"); + sender.sendMessage(STR."The player \{input} is invalid!"); }); setDefaultExecutor((sender, context) -> { @@ -27,7 +27,7 @@ public OperatorCommand() { return; } final String playerName = context.get(playerArg); - Cytosis.getPlayer(playerName).ifPresentOrElse(Cytosis::opPlayer, () -> sender.sendMessage(Component.text("Couldn't find the player '" + playerName + "'. Did you spell their name right?"))); + Cytosis.getPlayer(playerName).ifPresentOrElse(Cytosis::opPlayer, () -> sender.sendMessage(Component.text(STR."Couldn't find the player '\{playerName}'. Did you spell their name right?"))); }); } diff --git a/src/main/java/net/cytonic/cytosis/config/CytosisSettings.java b/src/main/java/net/cytonic/cytosis/config/CytosisSettings.java index ad9169c1..76c9e7e3 100644 --- a/src/main/java/net/cytonic/cytosis/config/CytosisSettings.java +++ b/src/main/java/net/cytonic/cytosis/config/CytosisSettings.java @@ -22,6 +22,8 @@ public class CytosisSettings { public static int DATABASE_PORT = 3306; public static String DATABASE_NAME = ""; public static boolean DATABASE_USE_SSL = false; + public static boolean SERVER_ONLINE_MODE = true; + public static int SERVER_PORT = 25565; // RabbitMQ public static boolean RABBITMQ_ENABLED = false; @@ -49,6 +51,10 @@ public static void inportConfig(Map config) { case "database.port" -> DATABASE_PORT = toInt(value); case "database.name" -> DATABASE_NAME = (String) value; case "database.use_ssl" -> DATABASE_USE_SSL = (boolean) value; + + // server + case "server.online_mode" -> SERVER_ONLINE_MODE = (boolean) value; + case "server.port" -> SERVER_PORT = toInt(value); // RabbitMQ case "rabbitmq.host" -> RABBITMQ_HOST = (String) value; @@ -56,6 +62,7 @@ public static void inportConfig(Map config) { case "rabbitmq.username" -> RABBITMQ_USERNAME = (String) value; case "rabbitmq.port" -> RABBITMQ_PORT = toInt(value); case "rabbitmq.enabled" -> RABBITMQ_ENABLED = (boolean) value; + default -> { /*Do nothing*/ } } } catch (ClassCastException e) { diff --git a/src/main/java/net/cytonic/cytosis/data/Database.java b/src/main/java/net/cytonic/cytosis/data/Database.java new file mode 100644 index 00000000..34713025 --- /dev/null +++ b/src/main/java/net/cytonic/cytosis/data/Database.java @@ -0,0 +1,103 @@ +package net.cytonic.cytosis.data; + +import net.cytonic.cytosis.config.CytosisSettings; +import net.cytonic.cytosis.logging.Logger; +import net.minestom.server.MinecraftServer; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class Database { + + private final ExecutorService worker; + private final String host; + private final int port; + private final String database; + private final String username; + private final String password; + private final boolean ssl; + private Connection connection; + + public Database() { + this.worker = Executors.newSingleThreadExecutor(Thread.ofVirtual().name("CytosisDatabaseWorker").uncaughtExceptionHandler((t, e) -> Logger.error(STR."An uncaught exception occoured on the thread: \{t.getName()}", e)).factory()); + this.host = CytosisSettings.DATABASE_HOST; + this.port = CytosisSettings.DATABASE_PORT; + this.database = CytosisSettings.DATABASE_NAME; + this.username = CytosisSettings.DATABASE_USER; + this.password = CytosisSettings.DATABASE_PASSWORD; + this.ssl = CytosisSettings.DATABASE_USE_SSL; + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + } catch (ClassNotFoundException e) { + Logger.error("Failed to load database driver"); + Logger.error(e.toString()); + } + } + + public boolean isConnected() { + return (connection != null); + } + + public void connect() { + worker.submit(() -> { + if (!isConnected()) { + try { + connection = DriverManager.getConnection(STR."jdbc:mysql://\{host}:\{port}/\{database}?useSSL=\{ssl}&autoReconnect=true", username, password); + } catch (SQLException e) { + Logger.error("Invalid Database Credentials!",e); + MinecraftServer.stopCleanly(); + } + } + }); + + } + + public void disconnect() { + worker.submit(() -> { + if (isConnected()) { + try { + connection.close(); + Logger.info("Database connection closed!"); + } catch (SQLException e) { + Logger.error("An error occurred whilst disconnecting from the database. Please report the following stacktrace to Foxikle: ",e); + } + } + }); + } + + private Connection getConnection() { + return connection; + } + + public void createChatTable() { + worker.submit(() -> { + if (isConnected()) { + PreparedStatement ps; + try { + ps = getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS cytonicchat (id INT NOT NULL AUTO_INCREMENT, timestamp TIMESTAMP, uuid VARCHAR(36), message TEXT, PRIMARY KEY(id))"); + ps.executeUpdate(); + } catch (SQLException e) { + Logger.error("An error occoured whilst fetching data from the database. Please report the following stacktrace to Foxikle:",e); + } + } + }); + } + + public void addChat(UUID uuid, String message) { + worker.submit(() -> { + PreparedStatement ps; + try { + ps = connection.prepareStatement("INSERT INTO cytonicchat (timestamp,uuid,message) VALUES (CURRENT_TIMESTAMP,?,?)"); + ps.setString(1, uuid.toString()); + ps.setString(2, message); + ps.executeUpdate(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }); + } +} \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/events/ServerEventListeners.java b/src/main/java/net/cytonic/cytosis/events/ServerEventListeners.java index 10416f81..695cd579 100644 --- a/src/main/java/net/cytonic/cytosis/events/ServerEventListeners.java +++ b/src/main/java/net/cytonic/cytosis/events/ServerEventListeners.java @@ -6,6 +6,7 @@ import net.minestom.server.coordinate.Pos; import net.minestom.server.entity.Player; import net.minestom.server.event.player.AsyncPlayerConfigurationEvent; +import net.minestom.server.event.player.PlayerChatEvent; import net.minestom.server.event.player.PlayerSpawnEvent; public class ServerEventListeners { @@ -23,10 +24,16 @@ public static void initServerEvents() { Cytosis.getEventHandler().registerGlobalEvent(PlayerSpawnEvent.class, event -> { final Player player = event.getPlayer(); if (CytosisSettings.LOG_PLAYER_IPS) - Logger.info(event.getPlayer().getUsername() + " (" + event.getPlayer().getUuid() + ") joined with the ip: " + player.getPlayerConnection().getServerAddress()); + Logger.info(STR."\{event.getPlayer().getUsername()} (\{event.getPlayer().getUuid()}) joined with the ip: \{player.getPlayerConnection().getServerAddress()}"); else - Logger.info(event.getPlayer().getUsername() + " (" + event.getPlayer().getUuid() + ") joined."); + Logger.info(STR."\{event.getPlayer().getUsername()} (\{event.getPlayer().getUuid()}) joined."); player.sendMessage("Hello!"); }); + Logger.info("Registering player chat event."); + Cytosis.getEventHandler().registerGlobalEvent(PlayerChatEvent.class, event -> { + final Player player = event.getPlayer(); + if (CytosisSettings.LOG_PLAYER_CHAT) + Cytosis.getDatabaseManager().getDatabase().addChat(player.getUuid(),event.getMessage()); + }); } } \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/files/FileManager.java b/src/main/java/net/cytonic/cytosis/files/FileManager.java index 26873c17..8afd21a6 100644 --- a/src/main/java/net/cytonic/cytosis/files/FileManager.java +++ b/src/main/java/net/cytonic/cytosis/files/FileManager.java @@ -5,7 +5,6 @@ import org.tomlj.Toml; import org.tomlj.TomlParseResult; import org.tomlj.TomlTable; - import java.io.*; import java.nio.file.Path; import java.util.HashMap; @@ -15,8 +14,8 @@ import java.util.concurrent.Executors; public class FileManager { - private static final Path CONFIG_PATH = Path.of("config.toml"); + private static final Path CONFIG_PATH = Path.of("config.toml"); private final ExecutorService worker; public FileManager() { @@ -49,29 +48,28 @@ public CompletableFuture createConfigFile() { try { extractResource("config.toml", CONFIG_PATH).whenComplete((file, throwable) -> { if (throwable != null) { - Logger.error("An error occoured whilst extracting the config.toml file!", throwable); + Logger.error("An error occurred whilst extracting the config.toml file!", throwable); future.completeExceptionally(throwable); return; } - try { parseToml(Toml.parse(CONFIG_PATH)); future.complete(file); } catch (IllegalStateException | IOException e) { - Logger.error("An error occoured whilst parsing the config.toml file!", e); + Logger.error("An error occurred whilst parsing the config.toml file!", e); + future.completeExceptionally(e); } - }); } catch (Exception e) { - Logger.error("An error occoured whilst creating the config.toml file!", e); + Logger.error("An error occurred whilst creating the config.toml file!", e); future.completeExceptionally(e); } } else { try { parseToml(Toml.parse(CONFIG_PATH)); } catch (IOException e) { - Logger.error("An error occoured whilst parsing the config.toml file!", e); + Logger.error("An error occurred whilst parsing the config.toml file!", e); future.completeExceptionally(e); } future.complete(CONFIG_PATH.toFile()); @@ -96,13 +94,10 @@ private CompletableFuture extractResource(String resource, Path path) { if (stream == null) { throw new IllegalStateException(STR."The resource \"\{resource}\" does not exist!"); } - OutputStream outputStream = new FileOutputStream(path.toFile()); byte[] buffer = new byte[1024]; int length; - while ((length = stream.read(buffer)) > 0) { - outputStream.write(buffer, 0, length); - } + while ((length = stream.read(buffer)) > 0) outputStream.write(buffer, 0, length); outputStream.close(); stream.close(); future.complete(path.toFile()); @@ -111,13 +106,12 @@ private CompletableFuture extractResource(String resource, Path path) { future.completeExceptionally(e); } }); - return future; } private void parseToml(TomlParseResult toml) { if (!toml.errors().isEmpty()) { - Logger.error("An error occoured whilst parsing the config.toml file!", toml.errors().getFirst()); + Logger.error("An error occurred whilst parsing the config.toml file!", toml.errors().getFirst()); return; } Map config = recursiveParse(toml.toMap(), ""); diff --git a/src/main/java/net/cytonic/cytosis/logging/LoggerImpl.java b/src/main/java/net/cytonic/cytosis/logging/LoggerImpl.java index f19f1ab1..0a7fba5d 100644 --- a/src/main/java/net/cytonic/cytosis/logging/LoggerImpl.java +++ b/src/main/java/net/cytonic/cytosis/logging/LoggerImpl.java @@ -64,9 +64,7 @@ private void newLine() { public Logger print(String message) { synchronized (printLock) { if (LOG_LEVEL.ordinal() > level.ordinal()) return this; - if (loggerWasLast && !lastLogger.equals(this) && !newLine) { - newLine(); - } + if (loggerWasLast && !lastLogger.equals(this) && !newLine) newLine(); if (newLine) { consolePrint(preparePrefix()); newLine = false; @@ -90,7 +88,6 @@ private void printNonNewLine(String message) { consolePrint(translateColor() + message); return; } - String[] split = message.split(Pattern.quote("\r"), -1); consolePrint("\r"); consolePrint(preparePrefix()); @@ -131,9 +128,9 @@ public Logger printf(String message, Object... args) { public Logger throwable(Throwable throwable, Object... args) { String info = ""; if (args.length == 1) { - info = " -> (" + args[0] + ")"; + info = STR." -> (\{args[0]})"; } else if (args.length > 1) { - info = " -> (" + String.format(args[0].toString(), args[1]) + ")"; + info = STR." -> (\{String.format(args[0].toString(), args[1])})"; } return print(throwable.getMessage() + info); } diff --git a/src/main/java/net/cytonic/cytosis/logging/SLF4JCompatibilityLayer.java b/src/main/java/net/cytonic/cytosis/logging/SLF4JCompatibilityLayer.java index 534a8bb9..5ff50e55 100644 --- a/src/main/java/net/cytonic/cytosis/logging/SLF4JCompatibilityLayer.java +++ b/src/main/java/net/cytonic/cytosis/logging/SLF4JCompatibilityLayer.java @@ -18,7 +18,7 @@ public SLF4JCompatibilityLayer(String name) { @Override public String getName() { - return "[Cytosis] " + name; + return STR."[Cytosis] \{name}"; } @Override diff --git a/src/main/java/net/cytonic/cytosis/logging/loading/StatusUpdater.java b/src/main/java/net/cytonic/cytosis/logging/loading/StatusUpdater.java index 8cd5df2a..5556a38f 100644 --- a/src/main/java/net/cytonic/cytosis/logging/loading/StatusUpdater.java +++ b/src/main/java/net/cytonic/cytosis/logging/loading/StatusUpdater.java @@ -19,4 +19,4 @@ public interface StatusUpdater { * @param message the new message */ void message(String message); -} +} \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/utils/UuidUtils.java b/src/main/java/net/cytonic/cytosis/utils/UuidUtils.java index c5afd71b..32ac68da 100644 --- a/src/main/java/net/cytonic/cytosis/utils/UuidUtils.java +++ b/src/main/java/net/cytonic/cytosis/utils/UuidUtils.java @@ -33,7 +33,7 @@ public static String getMojandUUID(final String username) { } con.disconnect(); } catch (IOException e) { - Logger.error("An error occoured whilst fetching " + username + "'s UUID from Mojang's API."); + Logger.error(STR."An error occoured whilst fetching \{username}'s UUID from Mojang's API."); } return null; } @@ -41,9 +41,9 @@ public static String getMojandUUID(final String username) { public static UUID getUUID(final String username) { String raw = getMojandUUID(username); - if (raw == null) throw new IllegalArgumentException("A player by the name '" + username + "' does not exist!"); + if (raw == null) throw new IllegalArgumentException(STR."A player by the name '\{username}' does not exist!"); if (raw.length() != 32) - throw new IllegalArgumentException("Raw UUID provided is not 32 characters! '" + raw + "' is " + raw.length()); + throw new IllegalArgumentException(STR."Raw UUID provided is not 32 characters! '\{raw}' is \{raw.length()}"); return UUID.fromString(raw.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5")); } diff --git a/src/main/resources/config.toml b/src/main/resources/config.toml index e3e2ddef..8407f69f 100644 --- a/src/main/resources/config.toml +++ b/src/main/resources/config.toml @@ -7,6 +7,10 @@ user = "" # Username to connect to the database password = "" # Password to connect to the database use_ssl = false # Whether to use SSL +# server stuff +[server] +online_mode = true +port = 25565 # Logging Configuration # Enable/disable logging for various player activities