getOnlineServers(@NotNull OnlineUser requester);
/**
- * Send a {@link Player} to a target {@link Server} on the proxy network
+ * Send a {@link OnlineUser} to a target {@link Server} on the proxy network
*
- * @param server The {@link Server} to send the {@link Player} to
+ * @param server The {@link Server} to send the {@link OnlineUser} to
* @return A future, returning {@code true} if the player was sent.
* If the player could not be sent (i.e. the server was offline), this will return {@code false}
*/
- public abstract CompletableFuture sendPlayer(@NotNull Player player, @NotNull Server server);
+ public abstract CompletableFuture sendPlayer(@NotNull OnlineUser onlineUser, @NotNull Server server);
/**
* Send a network {@link Message} to a target player on the proxy
@@ -93,7 +92,7 @@ public abstract class NetworkMessenger {
* @param message The {@link Message} to send
* @return A future containing a reply to the {@link Message} that was sent
*/
- public abstract CompletableFuture sendMessage(@NotNull Player sender, @NotNull Message message);
+ public abstract CompletableFuture sendMessage(@NotNull OnlineUser sender, @NotNull Message message);
/**
* Send a reply to a received {@link Message}
@@ -101,15 +100,15 @@ public abstract class NetworkMessenger {
* @param reply The reply {@link Message} to send
* @return A future completing when the message has been sent
*/
- protected abstract CompletableFuture sendReply(@NotNull Player replier, @NotNull Message reply);
+ protected abstract CompletableFuture sendReply(@NotNull OnlineUser replier, @NotNull Message reply);
/**
* Handle and action received network {@link Message}s
*
- * @param receiver The online {@link Player} receiving the message
+ * @param receiver The online {@link OnlineUser} receiving the message
* @param message The received {@link Message}
*/
- protected final void handleMessage(@NotNull Player receiver, @NotNull Message message) {
+ protected final void handleMessage(@NotNull OnlineUser receiver, @NotNull Message message) {
switch (message.kind) {
// Handle a message and send reply
case MESSAGE -> prepareReply(receiver, message).thenAccept(reply -> sendReply(receiver, message));
@@ -123,7 +122,7 @@ public abstract class NetworkMessenger {
}
}
- private CompletableFuture prepareReply(@NotNull final Player receiver, @NotNull final Message message) {
+ private CompletableFuture prepareReply(@NotNull final OnlineUser receiver, @NotNull final Message message) {
return CompletableFuture.supplyAsync(() -> {
// Handle different message types and apply changes for reply message
switch (message.type) {
@@ -137,7 +136,7 @@ public abstract class NetworkMessenger {
// Prepare reply message
message.targetPlayer = message.sender;
- message.sender = receiver.getName();
+ message.sender = receiver.username;
message.kind = Message.MessageKind.REPLY;
return message;
});
diff --git a/common/src/main/java/net/william278/huskhomes/player/Player.java b/common/src/main/java/net/william278/huskhomes/player/OnlineUser.java
similarity index 63%
rename from common/src/main/java/net/william278/huskhomes/player/Player.java
rename to common/src/main/java/net/william278/huskhomes/player/OnlineUser.java
index 26348c0b..2e723b0e 100644
--- a/common/src/main/java/net/william278/huskhomes/player/Player.java
+++ b/common/src/main/java/net/william278/huskhomes/player/OnlineUser.java
@@ -3,7 +3,6 @@ package net.william278.huskhomes.player;
import de.themoep.minedown.MineDown;
import net.william278.huskhomes.position.Location;
import net.william278.huskhomes.position.Position;
-import net.william278.huskhomes.position.Server;
import net.william278.huskhomes.teleport.TeleportResult;
import net.william278.huskhomes.util.EconomyUnsupportedException;
import org.jetbrains.annotations.NotNull;
@@ -12,44 +11,35 @@ import java.util.UUID;
import java.util.concurrent.CompletableFuture;
/**
- * A cross-platform representation of a player
+ * A cross-platform representation of a logged-in {@link User}
*/
-public interface Player {
+public abstract class OnlineUser extends User {
- /**
- * Return the player's name
- *
- * @return the player's name
- */
- String getName();
+ public OnlineUser(@NotNull UUID uuid, @NotNull String username) {
+ super(uuid, username);
+ }
- /**
- * Return the player's {@link UUID}
- *
- * @return the player {@link UUID}
- */
- UUID getUuid();
/**
* Returns the current {@link Position} of this player
*
* @return the player's current {@link Position}
*/
- CompletableFuture getPosition();
+ public abstract CompletableFuture getPosition();
/**
* Returns the current local {@link Location} of this player
*
* @return the player's current {@link Location} on the server
*/
- Location getLocation();
+ public abstract Location getLocation();
/**
* Returns the health of this player
*
* @return the player's health points
*/
- double getHealth();
+ public abstract double getHealth();
/**
* Returns if the player has the permission node
@@ -57,35 +47,43 @@ public interface Player {
* @param node The permission node string
* @return {@code true} if the player has the node; {@code false} otherwise
*/
- boolean hasPermission(@NotNull String node);
+ public abstract boolean hasPermission(@NotNull String node);
/**
- * Dispatch a MineDown-formatted message to this player
+ * Dispatch a MineDown-formatted action bar message to this player
*
* @param mineDown the parsed {@link MineDown} to send
*/
- void sendMessage(@NotNull MineDown mineDown);
+ public abstract void sendActionBar(@NotNull MineDown mineDown);
+
+
+ /**
+ * Dispatch a MineDown-formatted chat message to this player
+ *
+ * @param mineDown the parsed {@link MineDown} to send
+ */
+ public abstract void sendMessage(@NotNull MineDown mineDown);
/**
* Teleport a player to the specified {@link Location}
*
* @param location the {@link Location} to teleport the player to
*/
- CompletableFuture teleport(Location location);
+ public abstract CompletableFuture teleport(Location location);
/**
* Returns the maximum number of homes this player can set
*
* @return a {@link CompletableFuture} providing the max number of homes this player can set
*/
- CompletableFuture getMaxHomes();
+ public abstract CompletableFuture getMaxHomes();
/**
* Returns the number of homes this player can set for free
*
* @return a {@link CompletableFuture} providing the max number of homes this player can set
*/
- CompletableFuture getFreeHomes();
+ public abstract CompletableFuture getFreeHomes();
/**
* Get this player's economy balance
@@ -93,14 +91,14 @@ public interface Player {
* @return the player's economy balance
* @throws EconomyUnsupportedException if the economy integration is not enabled
*/
- double getEconomyBalance() throws EconomyUnsupportedException;
+ public abstract double getEconomyBalance() throws EconomyUnsupportedException;
/**
* Deduct money from this player's economy balance
*
* @throws EconomyUnsupportedException if the economy integration is not enabled
*/
- void deductEconomyBalance() throws EconomyUnsupportedException;
+ public abstract void deductEconomyBalance() throws EconomyUnsupportedException;
}
\ No newline at end of file
diff --git a/common/src/main/java/net/william278/huskhomes/player/User.java b/common/src/main/java/net/william278/huskhomes/player/User.java
index aaf08ebc..e8112cd5 100644
--- a/common/src/main/java/net/william278/huskhomes/player/User.java
+++ b/common/src/main/java/net/william278/huskhomes/player/User.java
@@ -5,13 +5,14 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
/**
- * Represents persistently stored {@link User} data about a {@link Player}; uuid and username
- * A {@link Player} may be retrieved from a user by the platform implementing classes
+ * Represents a user who has data saved in the database
*/
public class User {
+ @NotNull
public final UUID uuid;
+ @NotNull
public final String username;
/**
@@ -25,13 +26,4 @@ public class User {
this.username = username;
}
- /**
- * Get a user from an online {@link Player}
- *
- * @param player the online {@link Player}
- */
- public User(Player player) {
- this.uuid = player.getUuid();
- this.username = player.getName();
- }
}
diff --git a/common/src/main/java/net/william278/huskhomes/position/SavedPositionManager.java b/common/src/main/java/net/william278/huskhomes/position/SavedPositionManager.java
index 789ea004..e3fdd5fa 100644
--- a/common/src/main/java/net/william278/huskhomes/position/SavedPositionManager.java
+++ b/common/src/main/java/net/william278/huskhomes/position/SavedPositionManager.java
@@ -1,7 +1,7 @@
package net.william278.huskhomes.position;
import net.william278.huskhomes.cache.Cache;
-import net.william278.huskhomes.data.Database;
+import net.william278.huskhomes.database.Database;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.util.RegexUtil;
import org.jetbrains.annotations.NotNull;
diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java b/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java
index 099b4000..e9724965 100644
--- a/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java
+++ b/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java
@@ -4,7 +4,7 @@ import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Settings;
import net.william278.huskhomes.messenger.EmptyPayload;
import net.william278.huskhomes.messenger.Message;
-import net.william278.huskhomes.player.Player;
+import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.Position;
@@ -32,74 +32,74 @@ public abstract class TeleportManager {
}
/**
- * Teleport a {@link Player} to another {@link User}'s {@link Home}
+ * Teleport a {@link OnlineUser} to another {@link User}'s {@link Home}
*
- * @param player the {@link Player} to teleport
+ * @param onlineUser the {@link OnlineUser} to teleport
* @param homeOwner the {@link User} who owns the home
* @param homeName the name of the home
*/
- public void teleportToHome(@NotNull Player player, @NotNull User homeOwner, @NotNull String homeName) {
+ public void teleportToHome(@NotNull OnlineUser onlineUser, @NotNull User homeOwner, @NotNull String homeName) {
plugin.getDatabase().getHome(homeOwner, homeName).thenAccept(optionalHome ->
optionalHome.ifPresentOrElse(home -> {
- if (!homeOwner.uuid.equals(player.getUuid())) {
- if (!home.isPublic && !player.hasPermission(Permission.COMMAND_HOME_OTHER.node)) {
+ if (!homeOwner.uuid.equals(onlineUser.uuid)) {
+ if (!home.isPublic && !onlineUser.hasPermission(Permission.COMMAND_HOME_OTHER.node)) {
plugin.getLocales().getLocale("error_public_home_invalid", homeOwner.username, homeName)
- .ifPresent(player::sendMessage);
+ .ifPresent(onlineUser::sendMessage);
return;
}
}
- teleport(player, home).thenAccept(result -> finishTeleport(player, result));
+ teleport(onlineUser, home).thenAccept(result -> finishTeleport(onlineUser, result));
}, () -> {
- if (homeOwner.uuid.equals(player.getUuid())) {
- plugin.getLocales().getLocale("error_home_invalid", homeName).ifPresent(player::sendMessage);
+ if (homeOwner.uuid.equals(onlineUser.uuid)) {
+ plugin.getLocales().getLocale("error_home_invalid", homeName).ifPresent(onlineUser::sendMessage);
} else {
- plugin.getLocales().getLocale("error_home_invalid_other", homeName).ifPresent(player::sendMessage);
+ plugin.getLocales().getLocale("error_home_invalid_other", homeName).ifPresent(onlineUser::sendMessage);
}
}));
}
/**
- * Teleport a {@link Player} to a server {@link Warp}
+ * Teleport a {@link OnlineUser} to a server {@link Warp}
*
- * @param player the {@link Player} to teleport
+ * @param onlineUser the {@link OnlineUser} to teleport
* @param warpName the name of the warp
*/
- public void teleportToWarp(@NotNull Player player, @NotNull String warpName) {
+ public void teleportToWarp(@NotNull OnlineUser onlineUser, @NotNull String warpName) {
plugin.getDatabase().getWarp(warpName).thenAccept(optionalWarp ->
optionalWarp.ifPresentOrElse(warp -> //todo permission restricted warps
- teleport(player, warp).thenAccept(result -> finishTeleport(player, result)), () ->
+ teleport(onlineUser, warp).thenAccept(result -> finishTeleport(onlineUser, result)), () ->
plugin.getLocales().getLocale("error_warp_invalid", warpName)
- .ifPresent(player::sendMessage)));
+ .ifPresent(onlineUser::sendMessage)));
}
/**
- * Teleport a {@link Player} to another player by given input name
+ * Teleport a {@link OnlineUser} to another player by given input name
*
- * @param player the {@link Player} to teleport
+ * @param onlineUser the {@link OnlineUser} to teleport
* @param targetPlayer the name of the target player
*/
- public void teleportToPlayer(@NotNull Player player, @NotNull String targetPlayer) {
+ public void teleportToPlayer(@NotNull OnlineUser onlineUser, @NotNull String targetPlayer) {
MatcherUtil.matchPlayerName(targetPlayer, plugin).ifPresentOrElse(playerName ->
- getPlayerPosition(player, playerName).thenAccept(optionalPosition ->
+ getPlayerPosition(onlineUser, playerName).thenAccept(optionalPosition ->
optionalPosition.ifPresentOrElse(targetPosition ->
- teleport(player, targetPosition).thenAccept(result ->
- finishTeleport(player, result)),
+ teleport(onlineUser, targetPosition).thenAccept(result ->
+ finishTeleport(onlineUser, result)),
() -> plugin.getLocales().getLocale("error_invalid_player").
- ifPresent(player::sendMessage))),
- () -> plugin.getLocales().getLocale("error_invalid_player").ifPresent(player::sendMessage));
+ ifPresent(onlineUser::sendMessage))),
+ () -> plugin.getLocales().getLocale("error_invalid_player").ifPresent(onlineUser::sendMessage));
}
/**
* Gets the position of a player by their username, including players on other servers
*
- * @param requester the {@link Player} requesting their position
+ * @param requester the {@link OnlineUser} requesting their position
* @param playerName the username of the player being requested
* @return future optionally supplying the player's position, if the player could be found
*/
- private CompletableFuture> getPlayerPosition(@NotNull Player requester, @NotNull String playerName) {
+ private CompletableFuture> getPlayerPosition(@NotNull OnlineUser requester, @NotNull String playerName) {
return CompletableFuture.supplyAsync(() -> {
- final Optional localPlayer = plugin.getOnlinePlayers().stream().filter(player ->
- player.getName().equalsIgnoreCase(playerName)).findFirst();
+ final Optional localPlayer = plugin.getOnlinePlayers().stream().filter(player ->
+ player.username.equalsIgnoreCase(playerName)).findFirst();
if (localPlayer.isPresent()) {
return localPlayer.get().getPosition().thenApply(Optional::of).join();
}
@@ -107,7 +107,7 @@ public abstract class TeleportManager {
assert plugin.getNetworkMessenger() != null;
return plugin.getNetworkMessenger().sendMessage(requester,
new Message(Message.MessageType.POSITION_REQUEST,
- requester.getName(),
+ requester.username,
playerName,
new EmptyPayload(),
Message.MessageKind.MESSAGE,
@@ -119,16 +119,16 @@ public abstract class TeleportManager {
}
/**
- * Teleport a {@link Player} to a specified {@link Position}. Respects timed teleport.
+ * Teleport a {@link OnlineUser} to a specified {@link Position}. Respects timed teleport.
*
- * @param player the {@link Player} to teleport
+ * @param onlineUser the {@link OnlineUser} to teleport
* @param position the target {@link Position} to teleport to
*/
- public CompletableFuture teleport(@NotNull Player player, @NotNull Position position) {
+ public CompletableFuture teleport(@NotNull OnlineUser onlineUser, @NotNull Position position) {
return CompletableFuture.supplyAsync(() -> {
final int teleportWarmupTime = plugin.getSettings().getIntegerValue(Settings.ConfigOption.TELEPORT_WARMUP_TIME);
- if (!player.hasPermission(Permission.BYPASS_TELEPORT_WARMUP.node) && teleportWarmupTime > 0) {
- return processTimedTeleport(new TimedTeleport(player, position, teleportWarmupTime))
+ if (!onlineUser.hasPermission(Permission.BYPASS_TELEPORT_WARMUP.node) && teleportWarmupTime > 0) {
+ return processTimedTeleport(new TimedTeleport(onlineUser, position, teleportWarmupTime))
.thenApply(teleport -> {
if (!teleport.cancelled) {
return teleport.getPlayer().teleport(teleport.getTargetPosition()).join();
@@ -137,58 +137,57 @@ public abstract class TeleportManager {
}
}).join();
} else {
- return teleportNow(player, position).join();
+ return teleportNow(onlineUser, position).join();
}
});
}
/**
- * Handles a completed {@link Player}'s {@link TeleportResult} with the appropriate message
+ * Handles a completed {@link OnlineUser}'s {@link TeleportResult} with the appropriate message
*
- * @param player the {@link Player} who just completed a teleport
+ * @param onlineUser the {@link OnlineUser} who just completed a teleport
* @param teleportResult the {@link TeleportResult} to handle
*/
- public void finishTeleport(@NotNull Player player, @NotNull TeleportResult teleportResult) {
+ public void finishTeleport(@NotNull OnlineUser onlineUser, @NotNull TeleportResult teleportResult) {
switch (teleportResult) {
case COMPLETED_LOCALLY -> plugin.getLocales().getLocale("teleporting_complete")
- .ifPresent(player::sendMessage);
+ .ifPresent(onlineUser::sendMessage);
case FAILED_INVALID_WORLD -> plugin.getLocales().getLocale("error_invalid_on_arrival")
- .ifPresent(player::sendMessage);
+ .ifPresent(onlineUser::sendMessage);
case FAILED_UNSAFE -> {
//todo
}
case FAILED_ILLEGAL_COORDINATES -> plugin.getLocales().getLocale("error_illegal_target_coordinates")
- .ifPresent(player::sendMessage);
+ .ifPresent(onlineUser::sendMessage);
case FAILED_INVALID_SERVER -> plugin.getLocales().getLocale("error_invalid_server")
- .ifPresent(player::sendMessage);
+ .ifPresent(onlineUser::sendMessage);
}
}
/**
- * Executes a teleport now, teleporting a {@link Player} to a specified {@link Position}
+ * Executes a teleport now, teleporting a {@link OnlineUser} to a specified {@link Position}
*
- * @param player the {@link Player} to teleport
+ * @param onlineUser the {@link OnlineUser} to teleport
* @param position the target {@link Position} to teleport to
*/
- private CompletableFuture teleportNow(@NotNull Player player, @NotNull Position position) {
- final User user = new User(player);
- final Teleport teleport = new Teleport(user, position);
- return CompletableFuture.supplyAsync(() -> player.getPosition().thenApply(preTeleportPosition -> plugin.getDatabase()
- .setLastPosition(user, preTeleportPosition) // Update the player's last position
- .thenApply(ignored -> plugin.getServer(player).thenApply(server -> {
+ private CompletableFuture teleportNow(@NotNull OnlineUser onlineUser, @NotNull Position position) {
+ final Teleport teleport = new Teleport(onlineUser, position);
+ return CompletableFuture.supplyAsync(() -> onlineUser.getPosition().thenApply(preTeleportPosition -> plugin.getDatabase()
+ .setLastPosition(onlineUser, preTeleportPosition) // Update the player's last position
+ .thenApply(ignored -> plugin.getServer(onlineUser).thenApply(server -> {
// Teleport player locally, or across server depending on need
if (position.server.equals(server)) {
- return player.teleport(teleport.target).join();
+ return onlineUser.teleport(teleport.target).join();
} else {
- return teleportCrossServer(player, teleport).join();
+ return teleportCrossServer(onlineUser, teleport).join();
}
}).join()).join()).join());
}
- private CompletableFuture teleportCrossServer(Player player, Teleport teleport) {
+ private CompletableFuture teleportCrossServer(OnlineUser onlineUser, Teleport teleport) {
assert plugin.getNetworkMessenger() != null;
return CompletableFuture.supplyAsync(() -> plugin.getDatabase().setCurrentTeleport(teleport.player, teleport)
- .thenApply(ignored -> plugin.getNetworkMessenger().sendPlayer(player, teleport.target.server)
+ .thenApply(ignored -> plugin.getNetworkMessenger().sendPlayer(onlineUser, teleport.target.server)
.thenApply(completed -> completed ? TeleportResult.COMPLETED_CROSS_SERVER :
TeleportResult.FAILED_INVALID_SERVER)
.join()).join());
diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java b/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java
index d592992b..16950183 100644
--- a/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java
+++ b/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java
@@ -1,6 +1,6 @@
package net.william278.huskhomes.teleport;
-import net.william278.huskhomes.player.Player;
+import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.position.Location;
import net.william278.huskhomes.position.Position;
import org.jetbrains.annotations.NotNull;
@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
*/
public class TimedTeleport {
- private final Player player;
+ private final OnlineUser onlineUser;
private final Position targetPosition;
private final Location startLocation;
@@ -21,11 +21,11 @@ public class TimedTeleport {
public boolean cancelled = false;
- protected TimedTeleport(@NotNull Player player, @NotNull Position targetPosition, int duration) {
- this.player = player;
+ protected TimedTeleport(@NotNull OnlineUser onlineUser, @NotNull Position targetPosition, int duration) {
+ this.onlineUser = onlineUser;
this.targetPosition = targetPosition;
- this.startLocation = player.getLocation();
- this.startHealth = player.getHealth();
+ this.startLocation = onlineUser.getLocation();
+ this.startHealth = onlineUser.getHealth();
this.duration = duration;
this.timeLeft = duration;
}
@@ -41,10 +41,10 @@ public class TimedTeleport {
/**
* Get the teleporting player
*
- * @return the {@link Player} who is teleporting
+ * @return the {@link OnlineUser} who is teleporting
*/
- public Player getPlayer() {
- return player;
+ public OnlineUser getPlayer() {
+ return onlineUser;
}
/**
@@ -54,9 +54,9 @@ public class TimedTeleport {
*/
public boolean hasMoved() {
final double maxMovementDistance = 0.1d;
- double movementDistance = Math.abs(startLocation.x - player.getLocation().x) +
- Math.abs(startLocation.y - player.getLocation().y) +
- Math.abs(startLocation.z - player.getLocation().z);
+ double movementDistance = Math.abs(startLocation.x - onlineUser.getLocation().x) +
+ Math.abs(startLocation.y - onlineUser.getLocation().y) +
+ Math.abs(startLocation.z - onlineUser.getLocation().z);
return movementDistance > maxMovementDistance;
}
@@ -66,7 +66,7 @@ public class TimedTeleport {
* @return {@code true} if the player has taken damage
*/
public boolean hasTakenDamage() {
- return player.getHealth() < startHealth;
+ return onlineUser.getHealth() < startHealth;
}
/**
diff --git a/common/src/main/java/net/william278/huskhomes/util/Logger.java b/common/src/main/java/net/william278/huskhomes/util/Logger.java
index 17272067..b0479917 100644
--- a/common/src/main/java/net/william278/huskhomes/util/Logger.java
+++ b/common/src/main/java/net/william278/huskhomes/util/Logger.java
@@ -1,20 +1,37 @@
package net.william278.huskhomes.util;
+import de.themoep.minedown.MineDown;
+import org.jetbrains.annotations.NotNull;
+
import java.util.logging.Level;
/**
* An abstract, cross-platform representation of a logger
*/
-public interface Logger {
+public abstract class Logger {
- void log(Level level, String message, Exception e);
+ private boolean debug;
- void log(Level level, String message);
+ public abstract void log(@NotNull Level level, @NotNull String message, @NotNull Exception e);
- void info(String message);
+ public abstract void log(@NotNull Level level, @NotNull String message);
- void severe(String message);
+ public abstract void log(@NotNull Level level, @NotNull MineDown mineDown);
- void config(String message);
+ public abstract void info(@NotNull String message);
+
+ public abstract void severe(@NotNull String message);
+
+ public final void debug(@NotNull String message) {
+ if (debug) {
+ log(Level.INFO, "[DEBUG] " + message);
+ }
+ }
+
+ public abstract void config(@NotNull String message);
+
+ public final void showDebugLogs(boolean debug) {
+ this.debug = debug;
+ }
}
diff --git a/common/src/main/java/net/william278/huskhomes/util/UpdateChecker.java b/common/src/main/java/net/william278/huskhomes/util/UpdateChecker.java
new file mode 100644
index 00000000..383b976c
--- /dev/null
+++ b/common/src/main/java/net/william278/huskhomes/util/UpdateChecker.java
@@ -0,0 +1,57 @@
+package net.william278.huskhomes.util;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.concurrent.CompletableFuture;
+import java.util.logging.Level;
+
+public class UpdateChecker {
+
+ private final static int SPIGOT_PROJECT_ID = 83767;
+ private final Logger logger;
+ private final Version currentVersion;
+
+ public UpdateChecker(@NotNull Version currentVersion, @NotNull Logger logger) {
+ this.currentVersion = currentVersion;
+ this.logger = logger;
+ }
+
+ public CompletableFuture fetchLatestVersion() {
+ return CompletableFuture.supplyAsync(() -> {
+ try {
+ final URL url = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + SPIGOT_PROJECT_ID);
+ URLConnection urlConnection = url.openConnection();
+ return Version.pluginVersion(new BufferedReader(new InputStreamReader(urlConnection.getInputStream())).readLine());
+ } catch (Exception e) {
+ logger.log(Level.WARNING, "Failed to fetch the latest plugin version", e);
+ }
+ return new Version();
+ });
+ }
+
+ public boolean isUpdateAvailable(@NotNull Version latestVersion) {
+ return latestVersion.compareTo(currentVersion) > 0;
+ }
+
+ public Version getCurrentVersion() {
+ return currentVersion;
+ }
+
+ public CompletableFuture isUpToDate() {
+ return fetchLatestVersion().thenApply(this::isUpdateAvailable);
+ }
+
+ public void logToConsole() {
+ fetchLatestVersion().thenAccept(latestVersion -> {
+ if (isUpdateAvailable(latestVersion)) {
+ logger.log(Level.WARNING, "A new version of HuskHomes is available: v" + latestVersion);
+ } else {
+ logger.log(Level.INFO, "HuskHomes is up-to-date! (Running: v" + getCurrentVersion().toString() + ")");
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/common/src/main/java/net/william278/huskhomes/util/Version.java b/common/src/main/java/net/william278/huskhomes/util/Version.java
new file mode 100644
index 00000000..f9a16f91
--- /dev/null
+++ b/common/src/main/java/net/william278/huskhomes/util/Version.java
@@ -0,0 +1,71 @@
+package net.william278.huskhomes.util;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Arrays;
+import java.util.StringJoiner;
+import java.util.regex.Pattern;
+
+public class Version implements Comparable {
+ private final static String VERSION_SEPARATOR = ".";
+ private final static String MINECRAFT_META_SEPARATOR = "-";
+ private final static String PLUGIN_META_SEPARATOR = "+";
+
+ private int[] versions = new int[]{};
+ @NotNull
+ private String metadata = "";
+ @NotNull
+ private String metaSeparator = "";
+
+ protected Version() {
+ }
+
+ private Version(@NotNull String version, @NotNull String metaSeparator) {
+ this.parse(version, metaSeparator);
+ this.metaSeparator = metaSeparator;
+ }
+
+ @NotNull
+ public static Version pluginVersion(@NotNull String versionString) {
+ return new Version(versionString, PLUGIN_META_SEPARATOR);
+ }
+
+ @NotNull
+ public static Version minecraftVersion(@NotNull String versionString) {
+ return new Version(versionString, MINECRAFT_META_SEPARATOR);
+ }
+
+ private void parse(@NotNull String version, @NotNull String metaSeparator) {
+ int metaIndex = version.indexOf(metaSeparator);
+ if (metaIndex > 0) {
+ this.metadata = version.substring(metaIndex + 1);
+ version = version.substring(0, metaIndex);
+ }
+ String[] versions = version.split(Pattern.quote(VERSION_SEPARATOR));
+ this.versions = Arrays.stream(versions).mapToInt(Integer::parseInt).toArray();
+ }
+
+ @Override
+ public int compareTo(@NotNull Version other) {
+ int length = Math.max(this.versions.length, other.versions.length);
+ for (int i = 0; i < length; i++) {
+ int a = i < this.versions.length ? this.versions[i] : 0;
+ int b = i < other.versions.length ? other.versions[i] : 0;
+
+ if (a < b) return -1;
+ if (a > b) return 1;
+ }
+
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ final StringJoiner joiner = new StringJoiner(VERSION_SEPARATOR);
+ for (int version : this.versions) {
+ joiner.add(String.valueOf(version));
+ }
+ return joiner + ((!this.metadata.isEmpty()) ? (this.metaSeparator + this.metadata) : "");
+ }
+
+}
diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml
index af6cc5b5..af7ada00 100644
--- a/common/src/main/resources/config.yml
+++ b/common/src/main/resources/config.yml
@@ -6,6 +6,7 @@
language: 'en-gb'
check_for_updates: true
+debug_logging: false
data_storage_options:
storage_type: 'SQLite'
mysql_credentials:
diff --git a/common/src/main/resources/languages/en-gb.yml b/common/src/main/resources/locales/en-gb.yml
similarity index 100%
rename from common/src/main/resources/languages/en-gb.yml
rename to common/src/main/resources/locales/en-gb.yml