diff --git a/bukkit/build.gradle b/bukkit/build.gradle index b0d6ba11..5a6aa8c1 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -7,20 +7,19 @@ dependencies { compileOnly 'redis.clients:jedis:' + jedis_version compileOnly 'commons-io:commons-io:2.11.0' + compileOnly 'com.google.guava:guava:31.1-jre' compileOnly 'de.themoep:minedown:1.7.1-SNAPSHOT' compileOnly 'dev.dejvokep:boosted-yaml:1.3' } shadowJar { - relocate 'org.apache', 'net.william278.huskhomes.libraries' - relocate 'dev.dejvokep', 'net.william278.huskhomes.libraries' + relocate 'org.apache.commons.io', 'net.william278.huskhomes.libraries.commons-io' relocate 'de.themoep', 'net.william278.huskhomes.libraries' relocate 'org.jetbrains', 'net.william278.huskhomes.libraries' relocate 'org.intellij', 'net.william278.huskhomes.libraries' relocate 'com.zaxxer', 'net.william278.huskhomes.libraries' - relocate 'org.slf4j', 'net.william278.huskhomes.libraries.slf4j' - relocate 'com.google', 'net.william278.huskhomes.libraries' + relocate 'com.google.gson', 'net.william278.huskhomes.libraries.gson' relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib' - relocate 'org.bstats', 'net.william278.husksync.libraries.bstats' + relocate 'org.bstats', 'net.william278.huskhomes.libraries.bstats' } \ No newline at end of file diff --git a/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java b/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java index 913f627d..f9d2e178 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java +++ b/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java @@ -68,12 +68,6 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes { @Nullable private Server server; - private static BukkitHuskHomes instance; - - public static BukkitHuskHomes getInstance() { - return instance; - } - /** * Returns the {@link Server} the plugin is on * @@ -96,6 +90,13 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes { }); } + // Instance of the plugin + private static BukkitHuskHomes instance; + + public static BukkitHuskHomes getInstance() { + return instance; + } + @Override public void onLoad() { // Set the instance diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java index 2693ff6a..ffbf23cf 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java +++ b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; +import java.util.logging.Level; /** * Bukkit executor that implements and executes {@link CommandBase}s @@ -36,10 +37,15 @@ public class BukkitCommand implements CommandExecutor, TabExecutor { * @param pluginCommand {@link PluginCommand} to register */ public void register(@NotNull PluginCommand pluginCommand) { - pluginCommand.setExecutor(this); - pluginCommand.setTabCompleter(this); - pluginCommand.setPermission(command.permission); - pluginCommand.setDescription(command.getDescription()); + try { + plugin.getLoggingAdapter().log(Level.INFO, "Registering executor for command " + pluginCommand.getName() + "..."); + pluginCommand.setExecutor(this); + pluginCommand.setTabCompleter(this); + pluginCommand.setPermission(command.permission); + pluginCommand.setDescription(command.getDescription()); + } catch (Exception e) { + e.printStackTrace(); + } } @Override diff --git a/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java b/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java index d514b977..b2b20b2e 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java +++ b/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java @@ -1,7 +1,6 @@ package net.william278.huskhomes.listener; import net.william278.huskhomes.BukkitHuskHomes; -import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.player.BukkitPlayer; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; diff --git a/bukkit/src/main/java/net/william278/huskhomes/messenger/PluginMessenger.java b/bukkit/src/main/java/net/william278/huskhomes/messenger/PluginMessenger.java index 6abe4d22..8ea8a09d 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/messenger/PluginMessenger.java +++ b/bukkit/src/main/java/net/william278/huskhomes/messenger/PluginMessenger.java @@ -162,7 +162,7 @@ public class PluginMessenger extends NetworkMessenger implements PluginMessageLi final Message message = Message.fromJson(messageReader.readUTF()); // Ignore plugin messages to other clusters - if (message.clusterId != clusterId) { + if (!message.clusterId.equals(clusterId)) { return; } diff --git a/bukkit/src/main/java/net/william278/huskhomes/messenger/RedisMessenger.java b/bukkit/src/main/java/net/william278/huskhomes/messenger/RedisMessenger.java index b2d2709d..f6a7e746 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/messenger/RedisMessenger.java +++ b/bukkit/src/main/java/net/william278/huskhomes/messenger/RedisMessenger.java @@ -37,7 +37,7 @@ public class RedisMessenger extends PluginMessenger { return; } final Message message = Message.fromJson(encodedMessage); - if (message.clusterId != clusterId) { + if (!message.clusterId.equals(clusterId)) { return; } final Optional receiver = BukkitPlayer.get(message.targetPlayer); diff --git a/bukkit/src/main/java/net/william278/huskhomes/teleport/BukkitTeleportManager.java b/bukkit/src/main/java/net/william278/huskhomes/teleport/BukkitTeleportManager.java index 202fae96..67aa2d70 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/teleport/BukkitTeleportManager.java +++ b/bukkit/src/main/java/net/william278/huskhomes/teleport/BukkitTeleportManager.java @@ -24,11 +24,13 @@ public class BukkitTeleportManager extends TeleportManager { new BukkitRunnable() { @Override public void run() { - System.out.println("teleport warmup tick"); + // Display countdown action bar message + plugin.getLocales().getLocale("teleporting_action_bar_countdown", Integer.toString(teleport.timeLeft)) + .ifPresent(message -> teleport.getPlayer().sendActionBar(message)); + // Tick (decrement) the timed teleport timer final Optional result = tickTimedTeleport(teleport); if (result.isPresent()) { - System.out.println("task cancelled... "); teleportCompletableFuture.complete(teleport); this.cancel(); } diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index a90911da..6cb30a3d 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -8,6 +8,8 @@ libraries: - 'redis.clients:jedis:${jedis_version}' - 'mysql:mysql-connector-java:8.0.29' - 'org.xerial:sqlite-jdbc:3.36.0.3' + - 'dev.dejvokep:boosted-yaml:1.3' + - 'org.apache.commons:commons-text:1.9' commands: home: diff --git a/common/build.gradle b/common/build.gradle index f7ecab80..49936e9e 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,22 +1,24 @@ dependencies { implementation 'commons-io:commons-io:2.11.0' - implementation 'dev.dejvokep:boosted-yaml:1.3' implementation 'de.themoep:minedown:1.7.1-SNAPSHOT' - implementation 'com.zaxxer:HikariCP:5.0.1' implementation 'com.google.code.gson:gson:2.9.0' + implementation('com.zaxxer:HikariCP:5.0.1') { + exclude module: 'slf4j-api' + } + compileOnly 'org.apache.commons:commons-text:1.9' + compileOnly 'dev.dejvokep:boosted-yaml:1.3' + compileOnly 'com.google.guava:guava:31.1-jre' compileOnly 'redis.clients:jedis:' + jedis_version compileOnly 'org.xerial:sqlite-jdbc:' + sqlite_driver_version compileOnly 'org.jetbrains:annotations:23.0.0' } shadowJar { - relocate 'org.apache', 'net.william278.huskhomes.libraries' - relocate 'dev.dejvokep', 'net.william278.huskhomes.libraries' + relocate 'org.apache.commons.io', 'net.william278.huskhomes.libraries.commons-io' relocate 'de.themoep', 'net.william278.huskhomes.libraries' relocate 'org.jetbrains', 'net.william278.huskhomes.libraries' relocate 'org.intellij', 'net.william278.huskhomes.libraries' relocate 'com.zaxxer', 'net.william278.huskhomes.libraries' - relocate 'org.slf4j', 'net.william278.huskhomes.libraries.slf4j' - relocate 'com.google', 'net.william278.huskhomes.libraries' + relocate 'com.google.gson', 'net.william278.huskhomes.libraries.gson' } \ No newline at end of file diff --git a/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java index ab8b1073..e18c3bc5 100644 --- a/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java @@ -17,7 +17,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable, Conso @Override public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - + switch (args.length) { case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> { if (homes.size() == 1) { @@ -29,25 +29,21 @@ public class DelHomeCommand extends CommandBase implements TabCompletable, Conso }); case 1 -> { final String homeName = args[0]; - if (RegexUtil.OWNER_NAME_PATTERN.matcher(homeName).matches()) { - final String ownerName = homeName.split("\\.")[0]; - final String ownersHomeName = homeName.split("\\.")[1]; - plugin.getDatabase().getUserDataByName(ownerName).thenAccept(optionalUserData -> optionalUserData - .ifPresentOrElse(userData -> { - if (!userData.getUserUuid().equals(onlineUser.uuid)) { - if (!onlineUser.hasPermission(Permission.COMMAND_DELETE_HOME_OTHER.node)) { - plugin.getLocales().getLocale("error_no_permission") - .ifPresent(onlineUser::sendMessage); - return; - } - } - plugin.getSavedPositionManager().deleteHome(userData.user(), ownersHomeName); - }, - () -> plugin.getLocales().getLocale("error_home_invalid_other", ownerName, homeName) - .ifPresent(onlineUser::sendMessage))); - } else { - plugin.getSavedPositionManager().deleteHome(onlineUser, homeName); - } + RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(homeIdentifier -> + plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName()).thenAccept( + optionalUserData -> optionalUserData.ifPresentOrElse(userData -> { + if (!userData.getUserUuid().equals(onlineUser.uuid)) { + if (!onlineUser.hasPermission(Permission.COMMAND_DELETE_HOME_OTHER.node)) { + plugin.getLocales().getLocale("error_no_permission") + .ifPresent(onlineUser::sendMessage); + return; + } + } + plugin.getSavedPositionManager().deleteHome(userData.user(), homeIdentifier.homeName()); + }, + () -> plugin.getLocales().getLocale("error_home_invalid_other", + homeIdentifier.ownerName(), homeIdentifier.homeName()).ifPresent(onlineUser::sendMessage))), + () -> plugin.getSavedPositionManager().deleteHome(onlineUser, homeName)); } default -> plugin.getLocales().getLocale("error_invalid_syntax", "/delhome ") .ifPresent(onlineUser::sendMessage); diff --git a/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java index 41aa3b2d..a457fa23 100644 --- a/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java @@ -18,7 +18,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE @Override public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - + switch (args.length) { case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> { switch (homes.size()) { @@ -34,16 +34,13 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE }); case 1 -> { final String homeName = args[0]; - if (RegexUtil.OWNER_NAME_PATTERN.matcher(homeName).matches()) { - final String ownerName = homeName.split("\\.")[0]; - final String ownersHomeName = homeName.split("\\.")[1]; - plugin.getDatabase().getUserDataByName(ownerName).thenAccept(optionalUserData -> optionalUserData - .ifPresentOrElse(userData -> plugin.getTeleportManager().teleportToHome(onlineUser, userData.user(), ownersHomeName), - () -> plugin.getLocales().getLocale("error_home_invalid_other", ownerName, homeName) - .ifPresent(onlineUser::sendMessage))); - } else { - plugin.getTeleportManager().teleportToHome(onlineUser, onlineUser, homeName); - } + RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse( + homeIdentifier -> plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName()) + .thenAccept(optionalUserData -> optionalUserData.ifPresentOrElse( + userData -> plugin.getTeleportManager().teleportToHome(onlineUser, userData.user(), homeIdentifier.ownerName()), + () -> plugin.getLocales().getLocale("error_home_invalid_other", homeIdentifier.ownerName(), homeIdentifier.homeName()) + .ifPresent(onlineUser::sendMessage))), + () -> plugin.getTeleportManager().teleportToHome(onlineUser, onlineUser, homeName)); } default -> plugin.getLocales().getLocale("error_invalid_syntax", "/home [name]") .ifPresent(onlineUser::sendMessage); diff --git a/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java b/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java index f7d0ea93..65f1e2fc 100644 --- a/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java @@ -52,26 +52,20 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable { return; } } - plugin.getLoggingAdapter().info("Getting home list for " + homeOwner); plugin.getDatabase().getUserDataByName(homeOwner).thenAccept(optionalUser -> optionalUser.ifPresentOrElse(userData -> { - plugin.getLoggingAdapter().info("Got user!"); if (!userData.getUserUuid().equals(onlineUser.uuid)) { if (!onlineUser.hasPermission(Permission.COMMAND_HOME_OTHER.node)) { plugin.getLocales().getLocale("error_no_permission").ifPresent(onlineUser::sendMessage); return; } } - plugin.getLoggingAdapter().info("User has perms! Getting list..."); plugin.getDatabase().getHomes(userData.user()).thenAccept(homes -> { - plugin.getLoggingAdapter().info("Got home list!"); if (homes.isEmpty()) { plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage); return; } - plugin.getLoggingAdapter().info("Making list..."); final PrivateHomeList homeList = new PrivateHomeList(homes, userData.user(), plugin); plugin.getCache().positionLists.put(userData.user().uuid, homeList); - plugin.getLoggingAdapter().info("Showing list..."); homeList.getDisplay(pageNumber).forEach(onlineUser::sendMessage); }); }, () -> plugin.getLocales().getLocale("error_invalid_player").ifPresent(onlineUser::sendMessage))); diff --git a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java index d7fbaab1..3ee8359b 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java @@ -16,7 +16,6 @@ public class SetHomeCommand extends CommandBase { @Override public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - switch (args.length) { case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> { if (homes.isEmpty()) { diff --git a/common/src/main/java/net/william278/huskhomes/config/Locales.java b/common/src/main/java/net/william278/huskhomes/config/Locales.java index 98d2c602..2685423c 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Locales.java +++ b/common/src/main/java/net/william278/huskhomes/config/Locales.java @@ -2,6 +2,7 @@ package net.william278.huskhomes.config; import de.themoep.minedown.MineDown; import dev.dejvokep.boostedyaml.YamlDocument; +import org.apache.commons.text.StringEscapeUtils; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -15,10 +16,10 @@ public class Locales { @NotNull private final HashMap rawLocales; - private Locales(YamlDocument localesConfig) { + private Locales(@NotNull YamlDocument localesConfig) { this.rawLocales = new HashMap<>(); for (String localeId : localesConfig.getRoutesAsStrings(false)) { - rawLocales.put(localeId, localesConfig.getString(localeId)); + rawLocales.put(localeId, StringEscapeUtils.unescapeJava(localesConfig.getString(localeId))); } } diff --git a/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java b/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java index ee7e7f0c..2750ebf1 100644 --- a/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java +++ b/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java @@ -289,13 +289,9 @@ public class MySqlDatabase extends Database { resultSet.getBoolean("ignoring_requests"), resultSet.getTimestamp("rtp_cooldown").toInstant().getEpochSecond())); } - } catch (Exception e) { - e.printStackTrace(); } } catch (SQLException e) { getLogger().log(Level.SEVERE, "Failed to fetch a player by name from the database", e); - } catch (Exception e) { - e.printStackTrace(); } return Optional.empty(); }); diff --git a/common/src/main/java/net/william278/huskhomes/listener/EventListener.java b/common/src/main/java/net/william278/huskhomes/listener/EventListener.java index 13d76646..b4251859 100644 --- a/common/src/main/java/net/william278/huskhomes/listener/EventListener.java +++ b/common/src/main/java/net/william278/huskhomes/listener/EventListener.java @@ -15,21 +15,37 @@ public class EventListener { @NotNull protected final HuskHomes plugin; + // Indicates if the first user has joined yet + private boolean firstUser = true; + protected EventListener(@NotNull HuskHomes implementor) { this.plugin = implementor; } + /** + * Handle when the first {@link OnlineUser} joins the server + * + * @param onlineUser {@link OnlineUser} joining the server + */ + private void handleFirstPlayerJoin(@NotNull OnlineUser onlineUser) { + // Cache the server name + plugin.getServer(onlineUser); + } + /** * Handle when a {@link OnlineUser} joins the server * * @param onlineUser the joining {@link OnlineUser} */ protected final void handlePlayerJoin(@NotNull OnlineUser onlineUser) { - plugin.getLoggingAdapter().info("Player " + onlineUser.username + " joined"); + // Handle the first player joining the server + if (firstUser) { + handleFirstPlayerJoin(onlineUser); + firstUser = false; + } + // Ensure the player is present on the database first plugin.getDatabase().ensureUser(onlineUser).thenRun(() -> { - plugin.getLoggingAdapter().info("Player " + onlineUser.username + " ensured"); - // If the server is in proxy mode, check if the player is teleporting cross-server and handle if (plugin.getSettings().getBooleanValue(Settings.ConfigOption.ENABLE_PROXY_MODE)) { plugin.getDatabase().getCurrentTeleport(onlineUser) @@ -43,7 +59,7 @@ public class EventListener { plugin.getLocales().getLocale("teleporting_complete") .ifPresent(onlineUser::sendMessage); } - }))); + }).thenRun(() -> plugin.getDatabase().setCurrentTeleport(onlineUser, null)))); // Update the player list assert plugin.getNetworkMessenger() != null; plugin.getCache().updatePlayerList(plugin, onlineUser); diff --git a/common/src/main/java/net/william278/huskhomes/messenger/Message.java b/common/src/main/java/net/william278/huskhomes/messenger/Message.java index 34d4508a..4f0e003c 100644 --- a/common/src/main/java/net/william278/huskhomes/messenger/Message.java +++ b/common/src/main/java/net/william278/huskhomes/messenger/Message.java @@ -46,7 +46,8 @@ public class Message { * ID of the cluster this message is for */ @SerializedName("cluster_id") - public int clusterId; + @NotNull + public String clusterId; /** * Data to send in the message @@ -55,7 +56,7 @@ public class Message { public String payload; public Message(@NotNull MessageType type, @NotNull String sender, @NotNull String targetPlayer, - @NotNull MessageSerializable payload, @NotNull MessageKind messageKind, int clusterId) { + @NotNull MessageSerializable payload, @NotNull MessageKind messageKind, @NotNull String clusterId) { this.type = type; this.sender = sender; this.targetPlayer = targetPlayer; diff --git a/common/src/main/java/net/william278/huskhomes/messenger/NetworkMessenger.java b/common/src/main/java/net/william278/huskhomes/messenger/NetworkMessenger.java index 9261249d..491e43dd 100644 --- a/common/src/main/java/net/william278/huskhomes/messenger/NetworkMessenger.java +++ b/common/src/main/java/net/william278/huskhomes/messenger/NetworkMessenger.java @@ -41,7 +41,7 @@ public abstract class NetworkMessenger { /** * ID of the HuskHomes network cluster this server is on */ - protected int clusterId; + protected String clusterId; /** * Initialize the network messenger @@ -50,7 +50,7 @@ public abstract class NetworkMessenger { */ public void initialize(@NotNull HuskHomes implementor) { this.processingMessages = new HashMap<>(); - this.clusterId = implementor.getSettings().getIntegerValue(Settings.ConfigOption.CLUSTER_ID); + this.clusterId = implementor.getSettings().getStringValue(Settings.ConfigOption.CLUSTER_ID); } /** 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 e9724965..36f2fa90 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java @@ -15,6 +15,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Optional; import java.util.concurrent.CompletableFuture; +import java.util.logging.Level; /** * Cross-platform teleportation manager @@ -34,9 +35,9 @@ public abstract class TeleportManager { /** * Teleport a {@link OnlineUser} to another {@link User}'s {@link Home} * - * @param onlineUser the {@link OnlineUser} to teleport - * @param homeOwner the {@link User} who owns the home - * @param homeName the name of the home + * @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 OnlineUser onlineUser, @NotNull User homeOwner, @NotNull String homeName) { plugin.getDatabase().getHome(homeOwner, homeName).thenAccept(optionalHome -> @@ -61,8 +62,8 @@ public abstract class TeleportManager { /** * Teleport a {@link OnlineUser} to a server {@link Warp} * - * @param onlineUser the {@link OnlineUser} to teleport - * @param warpName the name of the warp + * @param onlineUser the {@link OnlineUser} to teleport + * @param warpName the name of the warp */ public void teleportToWarp(@NotNull OnlineUser onlineUser, @NotNull String warpName) { plugin.getDatabase().getWarp(warpName).thenAccept(optionalWarp -> @@ -75,7 +76,7 @@ public abstract class TeleportManager { /** * Teleport a {@link OnlineUser} to another player by given input name * - * @param onlineUser the {@link OnlineUser} to teleport + * @param onlineUser the {@link OnlineUser} to teleport * @param targetPlayer the name of the target player */ public void teleportToPlayer(@NotNull OnlineUser onlineUser, @NotNull String targetPlayer) { @@ -111,7 +112,7 @@ public abstract class TeleportManager { playerName, new EmptyPayload(), Message.MessageKind.MESSAGE, - plugin.getSettings().getIntegerValue(Settings.ConfigOption.CLUSTER_ID))) + plugin.getSettings().getStringValue(Settings.ConfigOption.CLUSTER_ID))) .thenApply(reply -> Optional.of(Position.fromJson(reply.payload))).join(); } return Optional.empty(); @@ -121,8 +122,8 @@ public abstract class TeleportManager { /** * Teleport a {@link OnlineUser} to a specified {@link Position}. Respects timed teleport. * - * @param onlineUser the {@link OnlineUser} to teleport - * @param position the target {@link Position} to teleport to + * @param onlineUser the {@link OnlineUser} to teleport + * @param position the target {@link Position} to teleport to */ public CompletableFuture teleport(@NotNull OnlineUser onlineUser, @NotNull Position position) { return CompletableFuture.supplyAsync(() -> { @@ -131,7 +132,7 @@ public abstract class TeleportManager { return processTimedTeleport(new TimedTeleport(onlineUser, position, teleportWarmupTime)) .thenApply(teleport -> { if (!teleport.cancelled) { - return teleport.getPlayer().teleport(teleport.getTargetPosition()).join(); + return teleportNow(onlineUser, position).join(); } else { return TeleportResult.CANCELLED; } @@ -145,7 +146,7 @@ public abstract class TeleportManager { /** * Handles a completed {@link OnlineUser}'s {@link TeleportResult} with the appropriate message * - * @param onlineUser the {@link OnlineUser} 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 OnlineUser onlineUser, @NotNull TeleportResult teleportResult) { @@ -167,8 +168,8 @@ public abstract class TeleportManager { /** * Executes a teleport now, teleporting a {@link OnlineUser} to a specified {@link Position} * - * @param onlineUser the {@link OnlineUser} to teleport - * @param position the target {@link Position} to teleport to + * @param onlineUser the {@link OnlineUser} to teleport + * @param position the target {@link Position} to teleport to */ private CompletableFuture teleportNow(@NotNull OnlineUser onlineUser, @NotNull Position position) { final Teleport teleport = new Teleport(onlineUser, position); @@ -208,6 +209,8 @@ public abstract class TeleportManager { if (teleport.hasTakenDamage()) { plugin.getLocales().getLocale("teleporting_cancelled_damage").ifPresent(locale -> teleport.getPlayer().sendMessage(locale)); + plugin.getLocales().getLocale("teleporting_action_bar_cancelled").ifPresent(locale -> + teleport.getPlayer().sendActionBar(locale)); teleport.cancelled = true; return Optional.of(teleport); } @@ -216,6 +219,8 @@ public abstract class TeleportManager { if (teleport.hasMoved()) { plugin.getLocales().getLocale("teleporting_cancelled_movement").ifPresent(locale -> teleport.getPlayer().sendMessage(locale)); + plugin.getLocales().getLocale("teleporting_action_bar_cancelled").ifPresent(locale -> + teleport.getPlayer().sendActionBar(locale)); teleport.cancelled = true; return Optional.of(teleport); } 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 16950183..0208dc4e 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java @@ -17,7 +17,7 @@ public class TimedTeleport { private final double startHealth; private final int duration; - private int timeLeft; + protected int timeLeft; public boolean cancelled = false; diff --git a/common/src/main/java/net/william278/huskhomes/util/RegexUtil.java b/common/src/main/java/net/william278/huskhomes/util/RegexUtil.java index 188aaaed..4c5c266b 100644 --- a/common/src/main/java/net/william278/huskhomes/util/RegexUtil.java +++ b/common/src/main/java/net/william278/huskhomes/util/RegexUtil.java @@ -1,8 +1,10 @@ package net.william278.huskhomes.util; +import java.util.Optional; import java.util.regex.Pattern; import net.william278.huskhomes.position.PositionMeta; +import org.jetbrains.annotations.NotNull; /** * Provides a number of utility regular expressions for checking home name patterns @@ -20,9 +22,44 @@ public final class RegexUtil { public static final Pattern NAME_PATTERN = Pattern.compile("[A-Za-z\\d_\\-]+"); /** - * Pattern for checking public home input fields + * Pattern for checking home input fields disambiguated by the owner's name + *

* e.g. {@code ownerName.homeName} */ - public static final Pattern OWNER_NAME_PATTERN = Pattern.compile("\\w+\\.[A-Za-z\\d_\\-]+"); + private static final Pattern OWNER_DISAMBIGUATED_HOME_IDENTIFIER_PATTERN = Pattern.compile("\\w+\\.[A-Za-z\\d_\\-]+"); + + /** + * Match pattern for checking home input fields disambiguated by the owner's name + * + * @param input input string to match + * @return An optional containing the {@link DisambiguatedHomeIdentifier} if matched, otherwise empty if not + */ + public static Optional matchDisambiguatedHomeIdentifier(@NotNull String input) { + if (OWNER_DISAMBIGUATED_HOME_IDENTIFIER_PATTERN.matcher(input).matches()) { + final String[] separatedInput = input.split(Pattern.quote(".")); + return Optional.of(new DisambiguatedHomeIdentifier(separatedInput[0], separatedInput[1])); + } else { + return Optional.empty(); + } + } + + /** + * Represents an identifier for a home or warp {@link PositionMeta} that is disambiguated by the owner's name + * + * @param ownerName the username of a home's owner + * @param homeName the name of a home + */ + public record DisambiguatedHomeIdentifier(String ownerName, String homeName) { + + + /** + * Get the period-separated formatted disambiguated home identifier + * + * @return the formatted disambiguated home identifier (e.g. {@code ownerName.homeName}) + */ + public String toString() { + return ownerName + "." + homeName; + } + } } diff --git a/common/src/main/resources/locales/en-gb.yml b/common/src/main/resources/locales/en-gb.yml index f11bbc34..eb567cfe 100644 --- a/common/src/main/resources/locales/en-gb.yml +++ b/common/src/main/resources/locales/en-gb.yml @@ -15,11 +15,11 @@ warp_deleted: '[Successfully deleted the warp called](#00fb9a) [%1%](#00fb9a bol error_home_invalid: '[Error:](#ff3300) [You do not have a home named "%1%"](#ff7e5e)' error_warp_invalid: '[Error:](#ff3300) [There is no warp set named "%1%"](#ff7e5e)' error_invalid_syntax: '[Error:](#ff3300) [Incorrect syntax. Usage: %1%](#ff7e5e)' -edit_home_title: '\\n[Edit home details for](#00fb9a) [%1%](#00fb9a bold)[:](#00fb9a)' -edit_home_title_other: '\\n[Edit home details for %1%''s home,](#00fb9a) [%2%](#00fb9a bold)[:](#00fb9a)' -edit_home_options: '\\n[[Teleport]](green show_text=&7Teleport to this home run_command=/huskhomes:home %1%.%2%) [[Delete]](red show_text=&7Delete this home run_command=/huskhomes:delhome %1%.%2%) [[Relocate]](blue show_text=&7Update this home''s location run_command=/huskhomes:edithome %1%.%2% location)\\n[[Rename]](yellow show_text=&7Change the name of this home suggest_command=/huskhomes:edithome %1%.%2% rename ) [[Edit Description]](gold show_text=&7Update the description of this home suggest_command=/huskhomes:edithome %1%.%2% description )\\n' -edit_home_options_make_public: '\\n[[Teleport]](green show_text=&7Teleport to this home run_command=/huskhomes:home %1%.%2%) [[Delete]](red show_text=&7Delete this home run_command=/huskhomes:delhome %1%.%2%) [[Relocate]](blue show_text=&7Update this home''s location run_command=/huskhomes:edithome %1%.%2% location)\\n[[Rename]](yellow show_text=&7Change the name of this home suggest_command=/huskhomes:edithome %1%.%2% rename ) [[Edit Description]](gold show_text=&7Update the description of this home suggest_command=/huskhomes:edithome %1%.%2% description ) [[Make Public]](dark_green show_text=&7Open this home to the public run_command=/huskhomes:edithome %1%.%2% public)\\n' -edit_home_options_make_private: '\\n[[Teleport]](green show_text=&7Teleport to this home run_command=/huskhomes:home %1%.%2%) [[Delete]](red show_text=&7Delete this home run_command=/huskhomes:delhome %1%.%2%) [[Relocate]](blue show_text=&7Update this home''s location run_command=/huskhomes:edithome %1%.%2% location)\\n[[Rename]](yellow show_text=&7Change the name of this home suggest_command=/huskhomes:edithome %1%.%2% rename ) [[Edit Description]](gold show_text=&7Update the description of this home suggest_command=/huskhomes:edithome %1%.%2% description ) [[Make Private]](dark_red show_text=&7Make this home private run_command=/huskhomes:edithome %1%.%2% private)\\n' +edit_home_title: '\n[Edit home details for](#00fb9a) [%1%](#00fb9a bold)[:](#00fb9a)' +edit_home_title_other: '\n[Edit home details for %1%''s home,](#00fb9a) [%2%](#00fb9a bold)[:](#00fb9a)' +edit_home_options: '\n[[Teleport]](green show_text=&7Teleport to this home run_command=/huskhomes:home %1%.%2%) [[Delete]](red show_text=&7Delete this home run_command=/huskhomes:delhome %1%.%2%) [[Relocate]](blue show_text=&7Update this home''s location run_command=/huskhomes:edithome %1%.%2% location)\n[[Rename]](yellow show_text=&7Change the name of this home suggest_command=/huskhomes:edithome %1%.%2% rename ) [[Edit Description]](gold show_text=&7Update the description of this home suggest_command=/huskhomes:edithome %1%.%2% description )\n' +edit_home_options_make_public: '\n[[Teleport]](green show_text=&7Teleport to this home run_command=/huskhomes:home %1%.%2%) [[Delete]](red show_text=&7Delete this home run_command=/huskhomes:delhome %1%.%2%) [[Relocate]](blue show_text=&7Update this home''s location run_command=/huskhomes:edithome %1%.%2% location)\n[[Rename]](yellow show_text=&7Change the name of this home suggest_command=/huskhomes:edithome %1%.%2% rename ) [[Edit Description]](gold show_text=&7Update the description of this home suggest_command=/huskhomes:edithome %1%.%2% description ) [[Make Public]](dark_green show_text=&7Open this home to the public run_command=/huskhomes:edithome %1%.%2% public)\n' +edit_home_options_make_private: '\n[[Teleport]](green show_text=&7Teleport to this home run_command=/huskhomes:home %1%.%2%) [[Delete]](red show_text=&7Delete this home run_command=/huskhomes:delhome %1%.%2%) [[Relocate]](blue show_text=&7Update this home''s location run_command=/huskhomes:edithome %1%.%2% location)\n[[Rename]](yellow show_text=&7Change the name of this home suggest_command=/huskhomes:edithome %1%.%2% rename ) [[Edit Description]](gold show_text=&7Update the description of this home suggest_command=/huskhomes:edithome %1%.%2% description ) [[Make Private]](dark_red show_text=&7Make this home private run_command=/huskhomes:edithome %1%.%2% private)\n' edit_home_privacy_private: '• Access: &#ff7e5e&Private &7(Only you can use it)' edit_home_privacy_private_other: '• Access: &#ff7e5e&Private &7(Only %1% can use it)' edit_home_privacy_public: '• Access: &aPublic &7(Anyone can use it)' @@ -34,8 +34,8 @@ error_edit_home_description_characters: '[Error:](#ff3300) [Home descriptions ma edit_home_update_location: '[Re-located](#00fb9a) [%1%](#00fb9a bold) [to your current position.](#00fb9a)' edit_home_update_description: '[Changed the description for](#00fb9a) [%1%](#00fb9a bold) [to "%2%"](#00fb9a)' edit_home_update_name: '[Successfully changed your home''s name: %1% →](#00fb9a) [%2%](#00fb9a bold)' -edit_warp_title: '\\n[Edit details for the warp](#00fb9a) [%1%](#00fb9a bold)[:](#00fb9a)' -edit_warp_options: '\\n[[Teleport]](green show_text=&7Teleport to this warp run_command=/huskhomes:warp %1%) [[Delete]](red show_text=&7Delete this warp run_command=/huskhomes:delwarp %1%) [[Relocate]](blue show_text=&7Update this warp''s location run_command=/huskhomes:editwarp %1% location)\\n[[Rename]](yellow show_text=&7Change the name of this warp suggest_command=/huskhomes:editwarp %1% rename ) [[Edit Description]](gold show_text=&7Update this warp''s description suggest_command=/huskhomes:editwarp %1% description )\\n' +edit_warp_title: '\n[Edit details for the warp](#00fb9a) [%1%](#00fb9a bold)[:](#00fb9a)' +edit_warp_options: '\n[[Teleport]](green show_text=&7Teleport to this warp run_command=/huskhomes:warp %1%) [[Delete]](red show_text=&7Delete this warp run_command=/huskhomes:delwarp %1%) [[Relocate]](blue show_text=&7Update this warp''s location run_command=/huskhomes:editwarp %1% location)\n[[Rename]](yellow show_text=&7Change the name of this warp suggest_command=/huskhomes:editwarp %1% rename ) [[Edit Description]](gold show_text=&7Update this warp''s description suggest_command=/huskhomes:editwarp %1% description )\n' error_edit_warp_description_length: '[Error:](#ff3300) [Warp descriptions must be less than 255 characters in length.](#ff7e5e)' error_edit_warp_description_characters: '[Error:](#ff3300) [Warp descriptions may only contain alphanumeric (A-Z, 0-9) characters, hyphens (-) and underscores (_)](#ff7e5e)' edit_warp_update_location: '[Re-located the warp](#00fb9a) [%1%](#00fb9a bold) [to your current position.](#00fb9a)' @@ -49,9 +49,9 @@ edit_timestamp: '• Created: &7%1%' error_no_homes_set: '[Error:](#ff3300) [You haven''t set any homes!](#ff7e5e)' error_no_public_homes_set: '[Error:](#ff3300) [There aren''t any public homes set!](#ff7e5e)' error_no_warps_set: '[Error:](#ff3300) [There aren''t any warps set!](#ff7e5e)' -private_home_list_page_top: '\\n[%1%''s Homes:](#00fb9a) [(](#00fb9a)[%2%-%3%](#00fb9a bold) [of](#00fb9a) [%4%](#00fb9a bold)[)](#00fb9a)\\n' -public_home_list_page_top: '\\n[Public Homes:](#00fb9a) [(](#00fb9a)[%1%-%2%](#00fb9a bold) [of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)\\n' -warp_list_page_top: '\\n[Warps:](#00fb9a) [(](#00fb9a)[%1%-%2%](#00fb9a bold) [of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)\\n' +private_home_list_page_top: '\n[%1%''s Homes:](#00fb9a) [(](#00fb9a)[%2%-%3%](#00fb9a bold) [of](#00fb9a) [%4%](#00fb9a bold)[)](#00fb9a)\n' +public_home_list_page_top: '\n[Public Homes:](#00fb9a) [(](#00fb9a)[%1%-%2%](#00fb9a bold) [of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)\n' +warp_list_page_top: '\n[Warps:](#00fb9a) [(](#00fb9a)[%1%-%2%](#00fb9a bold) [of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)\n' error_public_home_invalid: '[Error:](#ff3300) [Could not find a public home owned by %1% called %2%.](#ff7e5e)' error_set_home_invalid_characters: '[Error:](#ff3300) [Home names must be alphanumeric (A-Z, 0-9, -_)](#ff7e5e)' error_set_home_invalid_length: '[Error:](#ff3300) [Home names can only contain up to 16 characters!](#ff7e5e)' @@ -95,8 +95,8 @@ public_home_list_item: '[[%1%]](show_text=�fb9a&%2%: &7%3% run_command=/huskh warp_list_item: '[[%1%]](show_text=&7%2% run_command=/huskhomes:warp %1%)' home_default_description: '%1%''s home' warp_default_description: 'A publicly accessible warp' -delete_all_homes_confirm: '[Warning:](#ff3300) [Are you sure you want to delete all of your homes?](#ff7e5e)\\n[Once you confirm, it will not be possible to recover them.](gray)\\n[→](gray) [[Confirm]](#ff3300 show_text=&#ff3300&Click to confirm deletion. This cannot be undone. run_command=/delhome all confirm)' -delete_all_warps_confirm: '[Warning:](#ff3300) [Are you sure you want to delete every warp?](#ff7e5e)\\n[Once you confirm, it will not be possible to recover them.](gray)\\n[→](gray) [[Confirm]](#ff3300 show_text=&#ff3300&Click to confirm deletion. This cannot be undone. run_command=/delwarp all confirm)' +delete_all_homes_confirm: '[Warning:](#ff3300) [Are you sure you want to delete all of your homes?](#ff7e5e)\n[Once you confirm, it will not be possible to recover them.](gray)\n[→](gray) [[Confirm]](#ff3300 show_text=&#ff3300&Click to confirm deletion. This cannot be undone. run_command=/delhome all confirm)' +delete_all_warps_confirm: '[Warning:](#ff3300) [Are you sure you want to delete every warp?](#ff7e5e)\n[Once you confirm, it will not be possible to recover them.](gray)\n[→](gray) [[Confirm]](#ff3300 show_text=&#ff3300&Click to confirm deletion. This cannot be undone. run_command=/delwarp all confirm)' delete_all_homes_success: '[Successfully deleted your](#00fb9a) [%1%](#00fb9a bold) [home(s).](#00fb9a)' delete_all_warps_success: '[Successfully deleted all](#00fb9a) [%1%](#00fb9a bold) [server warp(s).](#00fb9a)' error_permission_restricted_warp: '[Error:](#ff3300) [You do not have permission to warp to %1%!](#ff7e5e)' @@ -108,7 +108,7 @@ page_options_min: '[Viewing Page %1%/%2%](#00fb9a) [→](gray show_text=&7View n page_options_min_max: '[Viewing Page %1%/%2%](#00fb9a)' page_options_max: '[←](gray show_text=&7View previous page run_command=%1%) [Viewing Page %2%/%3%](#00fb9a)' page_no_items: '[(No items to display on this page)](gray show_text=&7Try a different page number)' -command_list_header: '\\n[HuskHomes](#00fb9a bold) [| Command List](#00fb9a)' +command_list_header: '\n[HuskHomes](#00fb9a bold) [| Command List](#00fb9a)' command_list_item: '[/%1%](#00fb9a show_text=�fb9a&%2% suggest_command=/%1%) [•](white) [%3%](gray)' error_invalid_on_arrival: '[Error:](#ff3300) [Failed to finish your teleportation as the target world could not be found.](#ff7e5e)' tpignore_toggle_on: '[You are now](#00fb9a) [ignoring](#00fb9a bold) [incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)'