From a91128ca3df3e3b2cd9a6ab14d79bed02beb9d3d Mon Sep 17 00:00:00 2001 From: William Date: Tue, 16 Aug 2022 00:58:26 +0100 Subject: [PATCH] Add /edithome, use instant for timestamps, new locales --- bukkit/build.gradle | 1 + .../huskhomes/command/BukkitCommandType.java | 1 + .../huskhomes/player/BukkitPlayer.java | 9 +- bukkit/src/main/resources/plugin.yml | 2 + .../huskhomes/BukkitPluginTests.java | 24 +- .../net/william278/huskhomes/cache/Cache.java | 2 +- .../huskhomes/command/DelHomeCommand.java | 34 +- .../huskhomes/command/DelWarpCommand.java | 13 +- .../huskhomes/command/EditHomeCommand.java | 233 +++++++++++++ .../huskhomes/command/HomeCommand.java | 24 +- .../huskhomes/command/PublicHomeCommand.java | 2 +- .../huskhomes/command/SetHomeCommand.java | 22 +- .../huskhomes/command/SetWarpCommand.java | 4 +- .../huskhomes/command/TabCompletable.java | 3 +- .../huskhomes/command/WarpCommand.java | 2 +- .../william278/huskhomes/config/Locales.java | 32 +- .../huskhomes/database/MySqlDatabase.java | 36 +- .../huskhomes/database/SqLiteDatabase.java | 23 +- .../william278/huskhomes/player/UserData.java | 3 +- .../william278/huskhomes/position/Home.java | 63 +++- .../huskhomes/position/PositionMeta.java | 11 +- .../huskhomes/position/SavedPosition.java | 2 +- .../position/SavedPositionManager.java | 310 +++++++++++++++--- common/src/main/resources/locales/en-gb.yml | 142 ++++---- 24 files changed, 793 insertions(+), 205 deletions(-) create mode 100644 common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java diff --git a/bukkit/build.gradle b/bukkit/build.gradle index 17602cfd..2ae05330 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -13,6 +13,7 @@ dependencies { compileOnly 'net.william278:Annotaml:1.0.1' testImplementation 'com.github.seeseemelk:MockBukkit-v1.19:2.117.0' + testImplementation 'de.themoep:minedown:1.7.1-SNAPSHOT' testImplementation 'redis.clients:jedis:' + jedis_version testImplementation 'org.xerial:sqlite-jdbc:' + sqlite_driver_version testImplementation 'mysql:mysql-connector-java:8.0.30' diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java index 01585ff5..3d047d14 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java +++ b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java @@ -12,6 +12,7 @@ public enum BukkitCommandType { SET_HOME_COMMAND(new SetHomeCommand(BukkitHuskHomes.getInstance())), HOME_LIST_COMMAND(new HomeListCommand(BukkitHuskHomes.getInstance())), DEL_HOME_COMMAND(new DelHomeCommand(BukkitHuskHomes.getInstance())), + EDIT_HOME_COMMAND(new EditHomeCommand(BukkitHuskHomes.getInstance())), PUBLIC_HOME_COMMAND(new PublicHomeCommand(BukkitHuskHomes.getInstance())), PUBLIC_HOME_LIST_COMMAND(new PublicHomeListCommand(BukkitHuskHomes.getInstance())), WARP_COMMAND(new WarpCommand(BukkitHuskHomes.getInstance())), diff --git a/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java b/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java index 22cd42c9..8dd9a3de 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java +++ b/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java @@ -3,6 +3,7 @@ package net.william278.huskhomes.player; import de.themoep.minedown.MineDown; import io.papermc.lib.PaperLib; import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; import net.william278.huskhomes.BukkitHuskHomes; import net.william278.huskhomes.position.Location; import net.william278.huskhomes.position.Position; @@ -96,7 +97,11 @@ public class BukkitPlayer extends OnlineUser { @Override public void sendMessage(@NotNull MineDown mineDown) { - player.spigot().sendMessage(mineDown.replace().toComponent()); + final BaseComponent[] messageComponents = mineDown.replace().toComponent(); + if (messageComponents.length == 0) { + return; + } + player.spigot().sendMessage(messageComponents); } @Override @@ -147,7 +152,7 @@ public class BukkitPlayer extends OnlineUser { /** * Send a Bukkit plugin message */ - public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, @NotNull byte[] message) { + public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, final byte[] message) { player.sendPluginMessage(source, channel, message); } } diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index 3303fc32..544372db 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -19,6 +19,8 @@ commands: usage: /homelist [page] delhome: usage: /delhome + edithome: + usage: /edithome [rename|description|relocate|privacy] [args] publichome: usage: /publichome [.] publichomelist: diff --git a/bukkit/src/test/java/net/william278/huskhomes/BukkitPluginTests.java b/bukkit/src/test/java/net/william278/huskhomes/BukkitPluginTests.java index a2327e15..2af15a18 100644 --- a/bukkit/src/test/java/net/william278/huskhomes/BukkitPluginTests.java +++ b/bukkit/src/test/java/net/william278/huskhomes/BukkitPluginTests.java @@ -3,15 +3,17 @@ package net.william278.huskhomes; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import be.seeseemelk.mockbukkit.entity.PlayerMock; +import de.themoep.minedown.MineDown; import net.william278.huskhomes.command.BukkitCommandType; import net.william278.huskhomes.player.BukkitPlayer; -import net.william278.huskhomes.position.Home; -import net.william278.huskhomes.position.PositionMeta; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.util.Map; +import java.util.Optional; + /** * Uses MockBukkit to test the plugin on a mock Paper server implementing the Bukkit 1.19 API. */ @@ -51,4 +53,22 @@ public class BukkitPluginTests { Assertions.assertNotNull(BukkitPlayer.adapt(player)); } + @Test + public void testLocalesLoading() { + final Map rawLocales = plugin.getLocales().rawLocales; + Assertions.assertTrue(rawLocales.size() > 0); + rawLocales.forEach((key, value) -> Assertions.assertNotNull(value)); + } + + @Test + public void testLocaleParsing() { + final Map rawLocales = plugin.getLocales().rawLocales; + BukkitPlayer bukkitPlayer = BukkitPlayer.adapt(server.addPlayer()); + rawLocales.forEach((key, value) -> { + Optional locale = plugin.getLocales().getLocale(key); + Assertions.assertTrue(locale.isPresent()); + bukkitPlayer.sendMessage(locale.get()); + }); + } + } diff --git a/common/src/main/java/net/william278/huskhomes/cache/Cache.java b/common/src/main/java/net/william278/huskhomes/cache/Cache.java index a858c232..21a76990 100644 --- a/common/src/main/java/net/william278/huskhomes/cache/Cache.java +++ b/common/src/main/java/net/william278/huskhomes/cache/Cache.java @@ -13,7 +13,7 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; /** - * A cache used to hold persistently used data + * A cache used to hold frequently accessed data (i.e. TAB-completed homes and warps) */ public class Cache { 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 e18c3bc5..c199f8f7 100644 --- a/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java @@ -2,6 +2,7 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.player.OnlineUser; +import net.william278.huskhomes.player.User; import net.william278.huskhomes.util.Permission; import net.william278.huskhomes.util.RegexUtil; import org.jetbrains.annotations.NotNull; @@ -21,7 +22,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable, Conso switch (args.length) { case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> { if (homes.size() == 1) { - homes.stream().findFirst().ifPresent(home -> plugin.getSavedPositionManager().deleteHome(onlineUser, home.meta.name)); + homes.stream().findFirst().ifPresent(home -> deletePlayerHome(onlineUser, onlineUser, home.meta.name)); } else { plugin.getLocales().getLocale("error_invalid_syntax", "/delhome ") .ifPresent(onlineUser::sendMessage); @@ -39,24 +40,49 @@ public class DelHomeCommand extends CommandBase implements TabCompletable, Conso return; } } - plugin.getSavedPositionManager().deleteHome(userData.user(), homeIdentifier.homeName()); + deletePlayerHome(onlineUser, userData.user(), homeName); }, () -> plugin.getLocales().getLocale("error_home_invalid_other", homeIdentifier.ownerName(), homeIdentifier.homeName()).ifPresent(onlineUser::sendMessage))), - () -> plugin.getSavedPositionManager().deleteHome(onlineUser, homeName)); + () -> deletePlayerHome(onlineUser, onlineUser, homeName)); } default -> plugin.getLocales().getLocale("error_invalid_syntax", "/delhome ") .ifPresent(onlineUser::sendMessage); } } + /** + * Delete a player's home + * + * @param deleter the player who is deleting the home + * @param homeOwner The player who owns the home + * @param homeName The home name to delete + */ + private void deletePlayerHome(@NotNull OnlineUser deleter, @NotNull User homeOwner, @NotNull String homeName) { + plugin.getSavedPositionManager().deleteHome(homeOwner, homeName).thenAccept(deleted -> { + if (deleter.uuid.equals(homeOwner.uuid)) { + if (deleted) { + plugin.getLocales().getLocale("home_deleted", homeName).ifPresent(deleter::sendMessage); + } else { + plugin.getLocales().getLocale("error_home_invalid_other", homeName).ifPresent(deleter::sendMessage); + } + } else { + if (deleted) { + plugin.getLocales().getLocale("home_deleted_other", homeOwner.username, homeName).ifPresent(deleter::sendMessage); + } else { + plugin.getLocales().getLocale("error_home_invalid_other", homeOwner.username, homeName).ifPresent(deleter::sendMessage); + } + } + }); + } + @Override public void onConsoleExecute(@NotNull String[] args) { } @Override - public List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + public @NotNull List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { return plugin.getCache().homes.get(onlineUser.uuid).stream() .filter(s -> s.startsWith(args.length >= 1 ? args[0] : "")) .sorted().collect(Collectors.toList()); diff --git a/common/src/main/java/net/william278/huskhomes/command/DelWarpCommand.java b/common/src/main/java/net/william278/huskhomes/command/DelWarpCommand.java index 8b7f0bb9..8b4777ab 100644 --- a/common/src/main/java/net/william278/huskhomes/command/DelWarpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/DelWarpCommand.java @@ -17,7 +17,14 @@ public class DelWarpCommand extends CommandBase implements TabCompletable, Conso @Override public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { if (args.length == 1) { - plugin.getSavedPositionManager().deleteWarp(args[0]); + final String warpName = args[0]; + plugin.getSavedPositionManager().deleteWarp(warpName).thenAccept(deleted -> { + if (deleted) { + plugin.getLocales().getLocale("warp_deleted").ifPresent(onlineUser::sendMessage); + } else { + plugin.getLocales().getLocale("error_warp_invalid", warpName).ifPresent(onlineUser::sendMessage); + } + }); } else { plugin.getLocales().getLocale("error_invalid_syntax", "/delwarp ") .ifPresent(onlineUser::sendMessage); @@ -26,11 +33,11 @@ public class DelWarpCommand extends CommandBase implements TabCompletable, Conso @Override public void onConsoleExecute(@NotNull String[] args) { - + //todo } @Override - public List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + public @NotNull List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { return plugin.getCache().warps.stream() .filter(s -> s.startsWith(args.length >= 1 ? args[0] : "")) .sorted().collect(Collectors.toList()); diff --git a/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java new file mode 100644 index 00000000..f8c490e8 --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java @@ -0,0 +1,233 @@ +package net.william278.huskhomes.command; + +import de.themoep.minedown.MineDown; +import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.player.OnlineUser; +import net.william278.huskhomes.position.Home; +import net.william278.huskhomes.position.PositionMeta; +import net.william278.huskhomes.util.Permission; +import net.william278.huskhomes.util.RegexUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.StringJoiner; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +public class EditHomeCommand extends CommandBase implements TabCompletable, ConsoleExecutable { + + private final String[] EDIT_HOME_COMPLETIONS = {"rename", "description", "relocate", "privacy"}; + + public EditHomeCommand(@NotNull HuskHomes implementor) { + super("edithome", Permission.COMMAND_EDIT_HOME, implementor); + } + + @Override + public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + if (args.length >= 1) { + final String homeName = args[0]; + final String editOperation = args.length >= 2 ? args[1] : null; + final String editArgs = getEditArguments(args); + + 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_EDIT_HOME_OTHER.node)) { + plugin.getLocales().getLocale("error_no_permission") + .ifPresent(onlineUser::sendMessage); + return; + } + } + plugin.getDatabase().getHome(userData.user(), homeIdentifier.homeName()).thenAccept(optionalHome -> { + if (optionalHome.isEmpty()) { + plugin.getLocales().getLocale("error_home_invalid_other", + homeIdentifier.ownerName(), homeIdentifier.homeName()) + .ifPresent(onlineUser::sendMessage); + return; + } + editHome(optionalHome.get(), onlineUser, editOperation, editArgs); + }); + + }, + () -> plugin.getLocales().getLocale("error_home_invalid_other", + homeIdentifier.ownerName(), homeIdentifier.homeName()) + .ifPresent(onlineUser::sendMessage))), + () -> plugin.getDatabase().getHome(onlineUser, homeName).thenAccept(optionalHome -> { + if (optionalHome.isEmpty()) { + plugin.getLocales().getLocale("error_home_invalid", homeName) + .ifPresent(onlineUser::sendMessage); + return; + } + editHome(optionalHome.get(), onlineUser, editOperation, editArgs); + }) + ); + } else { + plugin.getLocales().getLocale("error_invalid_syntax", + "/edithome [" + String.join("|", EDIT_HOME_COMPLETIONS) + "] [args]") + .ifPresent(onlineUser::sendMessage); + } + } + + /** + * Perform the specified EditOperation on the specified home + * + * @param home The home to edit + * @param editor The player who is editing the home + * @param editOperation The edit operation to perform + * @param editArgs Arguments for the edit operation + */ + private void editHome(@NotNull Home home, @NotNull OnlineUser editor, + @Nullable String editOperation, @Nullable String editArgs) { + if (editOperation == null) { + try { + boolean otherOwner = editor.uuid.equals(home.owner.uuid); + home.getHomeEditorWindow(plugin.getLocales(), otherOwner, plugin.getSettings().crossServer, + !otherOwner || editor.hasPermission(Permission.COMMAND_EDIT_HOME_OTHER.node)) + .forEach(editor::sendMessage); + } catch (Exception e){ + e.printStackTrace(); + } + return; + } + switch (editOperation.toLowerCase()) { + case "rename" -> { + if (editArgs == null || editArgs.contains(Pattern.quote(" "))) { + plugin.getLocales().getLocale("error_invalid_syntax", + "/edithome rename ") + .ifPresent(editor::sendMessage); + return; + } + + final String oldHomeName = home.meta.name; + plugin.getSavedPositionManager().updateHomeMeta(home, new PositionMeta(editArgs, home.meta.description)) + .thenAccept(renameResult -> + editor.sendMessage(switch (renameResult.resultType()) { + case SUCCESS -> { + if (home.owner.uuid.equals(editor.uuid)) { + yield plugin.getLocales().getLocale("edit_home_update_name", + oldHomeName, editArgs).orElse(new MineDown("")); + } else { + yield plugin.getLocales().getLocale("edit_home_update_name_other", + home.owner.username, oldHomeName, editArgs).orElse(new MineDown("")); + } + } + case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_set_home_name_taken") + .orElse(new MineDown("")); + case FAILED_NAME_LENGTH -> + plugin.getLocales().getLocale("error_set_home_invalid_length") + .orElse(new MineDown("")); + case FAILED_NAME_CHARACTERS -> + plugin.getLocales().getLocale("error_set_home_invalid_characters") + .orElse(new MineDown("")); + default -> new MineDown(""); + })); + } + case "description" -> { //todo not working + if (editArgs == null) { + plugin.getLocales().getLocale("error_invalid_syntax", + "/edithome description ") + .ifPresent(editor::sendMessage); + return; + } + + final String oldHomeDescription = home.meta.description; + plugin.getSavedPositionManager().updateHomeMeta(home, new PositionMeta(home.meta.name, editArgs)) + .thenAccept(renameResult -> + editor.sendMessage(switch (renameResult.resultType()) { + case SUCCESS -> { + if (home.owner.uuid.equals(editor.uuid)) { + yield plugin.getLocales().getLocale("edit_home_update_name", + oldHomeDescription, editArgs).orElse(new MineDown("")); + } else { + yield plugin.getLocales().getLocale("edit_home_update_name_other", + home.owner.username, oldHomeDescription, editArgs).orElse(new MineDown("")); + } + } + case FAILED_DESCRIPTION_LENGTH -> + plugin.getLocales().getLocale("error_set_home_invalid_length") + .orElse(new MineDown("")); + case FAILED_DESCRIPTION_CHARACTERS -> + plugin.getLocales().getLocale("error_set_home_invalid_characters") + .orElse(new MineDown("")); + default -> new MineDown(""); + })); + } + case "relocate" -> editor.getPosition().thenAccept(position -> + plugin.getSavedPositionManager().updateHomePosition(home, position).thenRun(() -> { + if (home.owner.uuid.equals(editor.uuid)) { + editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location", + home.meta.name).orElse(new MineDown(""))); + } else { + editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location_other", + home.owner.username, home.meta.name).orElse(new MineDown(""))); + } + })); + case "privacy" -> { + boolean newIsPublic = !home.isPublic; + if (editArgs != null) { + if (editArgs.equalsIgnoreCase("private")) { + newIsPublic = false; + } else if (editArgs.equalsIgnoreCase("public")) { + newIsPublic = true; + } else { + plugin.getLocales().getLocale("error_invalid_syntax", + "/edithome privacy [private|public]") + .ifPresent(editor::sendMessage); + return; + } + } + final String privacyKeyedString = newIsPublic ? "public" : "private"; + + if (newIsPublic == home.isPublic) { + plugin.getLocales().getLocale( + "error_edit_home_privacy_already_" + privacyKeyedString) + .ifPresent(editor::sendMessage); + return; + } + + //todo economy check here + + plugin.getSavedPositionManager().updateHomePrivacy(home, newIsPublic).thenRun(() -> { + if (home.owner.uuid.equals(editor.uuid)) { + editor.sendMessage(plugin.getLocales().getLocale( + "edit_home_privacy_" + privacyKeyedString + "_success", + home.meta.name).orElse(new MineDown(""))); + } else { + editor.sendMessage(plugin.getLocales().getLocale( + "edit_home_privacy_" + privacyKeyedString + "_success_other", + home.owner.username, home.meta.name).orElse(new MineDown(""))); + } + }); + } + default -> plugin.getLocales().getLocale("error_invalid_syntax", + "/edithome [" + String.join("|", EDIT_HOME_COMPLETIONS) + "] [args]") + .ifPresent(editor::sendMessage); + } + } + + @Nullable + private String getEditArguments(@NotNull String[] args) { + if (args.length > 2) { + final StringJoiner joiner = new StringJoiner(" "); + for (int i = 2; i < args.length; i++) { + joiner.add(args[i]); + } + return joiner.toString(); + } + return null; + } + + @Override + public void onConsoleExecute(@NotNull String[] args) { + //todo + } + + @Override + public @NotNull List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + return plugin.getCache().homes.get(onlineUser.uuid).stream() + .filter(s -> s.toLowerCase().startsWith(args.length >= 1 ? args[0].toLowerCase() : "")) + .sorted().collect(Collectors.toList()); + } +} 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 7ead51ee..5d23ec52 100644 --- a/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java @@ -18,19 +18,23 @@ 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 -> { // Send the home list if they have homes set. If they have just one home set, teleport the player - switch (homes.size()) { - case 0 -> plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage); - case 1 -> plugin.getTeleportManager().teleport(onlineUser, homes.get(0)).thenAccept(result -> - plugin.getTeleportManager().finishTeleport(onlineUser, result)); - default -> { - final PrivateHomeList homeList = new PrivateHomeList(homes, onlineUser, plugin); - plugin.getCache().positionLists.put(onlineUser.uuid, homeList); - homeList.getDisplay(1).forEach(onlineUser::sendMessage); + try { + switch (homes.size()) { + case 0 -> + plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage); + case 1 -> plugin.getTeleportManager().teleport(onlineUser, homes.get(0)).thenAccept(result -> + plugin.getTeleportManager().finishTeleport(onlineUser, result)).join(); + default -> { + final PrivateHomeList homeList = new PrivateHomeList(homes, onlineUser, plugin); + plugin.getCache().positionLists.put(onlineUser.uuid, homeList); + homeList.getDisplay(1).forEach(onlineUser::sendMessage); + } } + } catch (Exception e) { + e.printStackTrace(); } }); case 1 -> { @@ -55,7 +59,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE } @Override - public List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + public @NotNull List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { return plugin.getCache().homes.get(onlineUser.uuid).stream() .filter(s -> s.toLowerCase().startsWith(args.length >= 1 ? args[0].toLowerCase() : "")) .sorted().collect(Collectors.toList()); diff --git a/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java index 409df062..ac263327 100644 --- a/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java @@ -65,7 +65,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co } @Override - public List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + public @NotNull List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { // Return every public home name as username.home_name from the cache final List publicHomes = new ArrayList<>(); plugin.getCache().publicHomes.forEach((ownerName, homeNames) -> 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 3ee8359b..0c02026a 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java @@ -8,6 +8,8 @@ import net.william278.huskhomes.position.PositionMeta; import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; +import java.util.Optional; + public class SetHomeCommand extends CommandBase { public SetHomeCommand(@NotNull HuskHomes implementor) { @@ -35,20 +37,16 @@ public class SetHomeCommand extends CommandBase { onlineUser.getPosition().thenAccept(position -> plugin.getSavedPositionManager().setHome(new PositionMeta(homeName, plugin.getLocales().getRawLocale("home_default_description", user.username).orElse("")), user, position).thenAccept(setResult -> - onlineUser.sendMessage(switch (setResult.resultType()) { + (switch (setResult.resultType()) { case SUCCESS -> { - assert setResult.setPosition() != null; - yield plugin.getLocales().getLocale("set_home_success", setResult.setPosition().meta.name) - .orElse(new MineDown("")); + assert setResult.savedPosition().isPresent(); + yield plugin.getLocales().getLocale("set_home_success", setResult.savedPosition().get().meta.name); } - case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_set_home_name_taken") - .orElse(new MineDown("")); - case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_set_home_invalid_length") - .orElse(new MineDown("")); - case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_set_home_invalid_characters") - .orElse(new MineDown("")); - default -> new MineDown(""); - }))); + case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_set_home_name_taken"); + case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_set_home_invalid_length"); + case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_set_home_invalid_characters"); + default -> Optional.of(new MineDown("")); + }).ifPresent(onlineUser::sendMessage))); } } diff --git a/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java b/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java index 91d60ca7..ae105e55 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java @@ -29,8 +29,8 @@ public class SetWarpCommand extends CommandBase { position).thenAccept(setResult -> onlineUser.sendMessage(switch (setResult.resultType()) { case SUCCESS -> { - assert setResult.setPosition() != null; - yield plugin.getLocales().getLocale("set_warp_success", setResult.setPosition().meta.name) + assert setResult.savedPosition().isPresent(); + yield plugin.getLocales().getLocale("set_warp_success", setResult.savedPosition().get().meta.name) .orElse(new MineDown("")); } case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_set_warp_name_taken") diff --git a/common/src/main/java/net/william278/huskhomes/command/TabCompletable.java b/common/src/main/java/net/william278/huskhomes/command/TabCompletable.java index 870f941d..798392f4 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TabCompletable.java +++ b/common/src/main/java/net/william278/huskhomes/command/TabCompletable.java @@ -14,9 +14,10 @@ public interface TabCompletable { * What should be returned when the player attempts to TAB-complete the command * * @param onlineUser {@link OnlineUser} doing the TAB completion - * @param args Current command arguments + * @param args Current command arguments * @return List of String arguments to offer TAB suggestions */ + @NotNull List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args); } diff --git a/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java b/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java index 9dd6263f..0b7e369b 100644 --- a/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java @@ -37,7 +37,7 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE } @Override - public List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + public @NotNull List onTabComplete(@NotNull OnlineUser onlineUser, @NotNull String[] args) { return plugin.getCache().warps.stream() .filter(s -> s.toLowerCase().startsWith(args.length >= 1 ? args[0].toLowerCase() : "")) .sorted().collect(Collectors.toList()); 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 a5199360..bd1db69c 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Locales.java +++ b/common/src/main/java/net/william278/huskhomes/config/Locales.java @@ -3,13 +3,15 @@ package net.william278.huskhomes.config; import de.themoep.minedown.MineDown; import net.william278.annotaml.RootedMap; import net.william278.annotaml.YamlFile; +import org.apache.commons.text.StringEscapeUtils; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; import java.util.Optional; /** - * Loaded locales used by the plugin to display various locales + * Loaded locales used by the plugin to display styled messages */ @YamlFile(header = """ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ @@ -25,26 +27,23 @@ public class Locales { public Map rawLocales = new HashMap<>(); /** - * Returns an unformatted locale loaded from the locales file + * Returns a raw, un-formatted locale loaded from the locales file * * @param localeId String identifier of the locale, corresponding to a key in the file * @return An {@link Optional} containing the locale corresponding to the id, if it exists */ - public Optional getRawLocale(String localeId) { - if (rawLocales.containsKey(localeId)) { - return Optional.of(rawLocales.get(localeId)); - } - return Optional.empty(); + public Optional getRawLocale(@NotNull String localeId) { + return Optional.ofNullable(rawLocales.get(localeId)).map(StringEscapeUtils::unescapeJava); } /** - * Returns an unformatted locale loaded from the locales file, with replacements applied + * Returnsa raw, un-formatted locale loaded from the locales file, with replacements applied * - * @param localeId String identifier of the locale, corresponding to a key in the file + * @param localeId String identifier of the locale, corresponding to a key in the file * @param replacements Ordered array of replacement strings to fill in placeholders with * @return An {@link Optional} containing the replacement-applied locale corresponding to the id, if it exists */ - public Optional getRawLocale(String localeId, String... replacements) { + public Optional getRawLocale(@NotNull String localeId, @NotNull String... replacements) { return getRawLocale(localeId).map(locale -> applyReplacements(locale, replacements)); } @@ -54,34 +53,35 @@ public class Locales { * @param localeId String identifier of the locale, corresponding to a key in the file * @return An {@link Optional} containing the formatted locale corresponding to the id, if it exists */ - public Optional getLocale(String localeId) { + public Optional getLocale(@NotNull String localeId) { return getRawLocale(localeId).map(MineDown::new); } /** * Returns a MineDown-formatted locale from the locales file, with replacements applied * - * @param localeId String identifier of the locale, corresponding to a key in the file + * @param localeId String identifier of the locale, corresponding to a key in the file * @param replacements Ordered array of replacement strings to fill in placeholders with * @return An {@link Optional} containing the replacement-applied, formatted locale corresponding to the id, if it exists */ - public Optional getLocale(String localeId, String... replacements) { + public Optional getLocale(@NotNull String localeId, @NotNull String... replacements) { return getRawLocale(localeId, replacements).map(MineDown::new); } /** * Apply placeholder replacements to a raw locale * - * @param rawLocale The raw, unparsed locale + * @param rawLocale The raw, unparsed locale * @param replacements Ordered array of replacement strings to fill in placeholders with * @return the raw locale, with inserted placeholders */ - private String applyReplacements(String rawLocale, String... replacements) { + @NotNull + private String applyReplacements(@NotNull String rawLocale, @NotNull String... replacements) { int replacementIndexer = 1; for (String replacement : replacements) { String replacementString = "%" + replacementIndexer + "%"; rawLocale = rawLocale.replace(replacementString, replacement); - replacementIndexer = replacementIndexer + 1; + replacementIndexer += 1; } return rawLocale; } 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 705f17ac..5714f373 100644 --- a/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java +++ b/common/src/main/java/net/william278/huskhomes/database/MySqlDatabase.java @@ -13,7 +13,6 @@ import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.sql.*; -import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -161,7 +160,7 @@ public class MySqlDatabase extends Database { statement.setInt(1, setPosition(position, connection)); statement.setString(2, position.meta.name); statement.setString(3, position.meta.description); - statement.setTimestamp(4, new Timestamp(Instant.ofEpochSecond(position.meta.timestamp).toEpochMilli())); + statement.setTimestamp(4, Timestamp.from(position.meta.creationTime)); statement.executeUpdate(); final ResultSet resultSet = statement.getGeneratedKeys(); @@ -255,7 +254,7 @@ public class MySqlDatabase extends Database { resultSet.getString("username")), resultSet.getInt("home_slots"), resultSet.getBoolean("ignoring_requests"), - resultSet.getTimestamp("rtp_cooldown").toInstant().getEpochSecond())); + resultSet.getTimestamp("rtp_cooldown").toInstant())); } } } catch (SQLException e) { @@ -283,7 +282,7 @@ public class MySqlDatabase extends Database { resultSet.getString("username")), resultSet.getInt("home_slots"), resultSet.getBoolean("ignoring_requests"), - resultSet.getTimestamp("rtp_cooldown").toInstant().getEpochSecond())); + resultSet.getTimestamp("rtp_cooldown").toInstant())); } } } catch (SQLException e) { @@ -321,7 +320,7 @@ public class MySqlDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("home_uuid")), user, resultSet.getBoolean("public"))); @@ -358,7 +357,7 @@ public class MySqlDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("warp_uuid")))); } } @@ -395,7 +394,7 @@ public class MySqlDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("home_uuid")), new User(UUID.fromString(resultSet.getString("owner_uuid")), resultSet.getString("owner_username")), @@ -436,7 +435,7 @@ public class MySqlDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("home_uuid")), new User(UUID.fromString(resultSet.getString("owner_uuid")), resultSet.getString("owner_username")), @@ -445,6 +444,8 @@ public class MySqlDatabase extends Database { } } catch (SQLException e) { getLogger().log(Level.SEVERE, "Failed to query a player's home", e); + } catch (Exception e) { + e.printStackTrace(); } return Optional.empty(); }); @@ -475,7 +476,7 @@ public class MySqlDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("home_uuid")), new User(UUID.fromString(resultSet.getString("owner_uuid")), resultSet.getString("owner_username")), @@ -513,7 +514,7 @@ public class MySqlDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("warp_uuid")))); } } @@ -548,7 +549,7 @@ public class MySqlDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("warp_uuid")))); } } @@ -601,7 +602,7 @@ public class MySqlDatabase extends Database { statement.setInt(1, userData.homeSlots()); statement.setBoolean(2, userData.ignoringTeleports()); - statement.setLong(3, userData.rtpCooldown()); + statement.setTimestamp(3, Timestamp.from(userData.rtpCooldown())); statement.setString(4, userData.getUserUuid().toString()); statement.executeUpdate(); } @@ -856,6 +857,7 @@ public class MySqlDatabase extends Database { return CompletableFuture.runAsync(() -> getHome(home.uuid) .thenAccept(existingHome -> existingHome.ifPresentOrElse(presentHome -> { try (Connection connection = getConnection()) { + // Update the home's saved position, including metadata try (PreparedStatement statement = connection.prepareStatement(formatStatementTables(""" SELECT `saved_position_id` FROM `%homes_table%` WHERE `uuid`=?;"""))) { @@ -866,6 +868,16 @@ public class MySqlDatabase extends Database { updateSavedPosition(resultSet.getInt("saved_position_id"), home, connection); } } + + // Update the home privacy + try (PreparedStatement statement = connection.prepareStatement(formatStatementTables(""" + UPDATE `%homes_table%` + SET `public`=? + WHERE `uuid`=?;"""))) { + statement.setBoolean(1, home.isPublic); + statement.setString(2, home.uuid.toString()); + statement.executeUpdate(); + } } catch (SQLException e) { getLogger().log(Level.SEVERE, "Failed to update a home in the database for " + home.owner.username, e); diff --git a/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java b/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java index 449633ac..f51cd3bf 100644 --- a/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java +++ b/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java @@ -14,7 +14,6 @@ import org.sqlite.SQLiteConfig; import java.io.File; import java.io.IOException; import java.sql.*; -import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -173,7 +172,7 @@ public class SqLiteDatabase extends Database { statement.setInt(1, setPosition(position, connection)); statement.setString(2, position.meta.name); statement.setString(3, position.meta.description); - statement.setTimestamp(4, new Timestamp(Instant.ofEpochSecond(position.meta.timestamp).toEpochMilli())); + statement.setTimestamp(4, Timestamp.from(position.meta.creationTime)); statement.executeUpdate(); // Return the ID of the newly inserted row @@ -269,7 +268,7 @@ public class SqLiteDatabase extends Database { resultSet.getString("username")), resultSet.getInt("home_slots"), resultSet.getBoolean("ignoring_requests"), - resultSet.getTimestamp("rtp_cooldown").toInstant().getEpochSecond())); + resultSet.getTimestamp("rtp_cooldown").toInstant())); } } } catch (SQLException e) { @@ -297,7 +296,7 @@ public class SqLiteDatabase extends Database { resultSet.getString("username")), resultSet.getInt("home_slots"), resultSet.getBoolean("ignoring_requests"), - resultSet.getTimestamp("rtp_cooldown").toInstant().getEpochSecond())); + resultSet.getTimestamp("rtp_cooldown").toInstant())); } } } catch (SQLException e) { @@ -335,7 +334,7 @@ public class SqLiteDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("home_uuid")), user, resultSet.getBoolean("public"))); @@ -372,7 +371,7 @@ public class SqLiteDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("warp_uuid")))); } } @@ -409,7 +408,7 @@ public class SqLiteDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("home_uuid")), new User(UUID.fromString(resultSet.getString("owner_uuid")), resultSet.getString("owner_username")), @@ -450,7 +449,7 @@ public class SqLiteDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("home_uuid")), new User(UUID.fromString(resultSet.getString("owner_uuid")), resultSet.getString("owner_username")), @@ -489,7 +488,7 @@ public class SqLiteDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("home_uuid")), new User(UUID.fromString(resultSet.getString("owner_uuid")), resultSet.getString("owner_username")), @@ -527,7 +526,7 @@ public class SqLiteDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("warp_uuid")))); } } @@ -562,7 +561,7 @@ public class SqLiteDatabase extends Database { new Server(resultSet.getString("server_name")), new PositionMeta(resultSet.getString("name"), resultSet.getString("description"), - resultSet.getTimestamp("timestamp").toInstant().getEpochSecond()), + resultSet.getTimestamp("timestamp").toInstant()), UUID.fromString(resultSet.getString("warp_uuid")))); } } @@ -615,7 +614,7 @@ public class SqLiteDatabase extends Database { statement.setInt(1, userData.homeSlots()); statement.setBoolean(2, userData.ignoringTeleports()); - statement.setLong(3, userData.rtpCooldown()); + statement.setTimestamp(3, Timestamp.from(userData.rtpCooldown())); statement.setString(4, userData.getUserUuid().toString()); statement.executeUpdate(); } diff --git a/common/src/main/java/net/william278/huskhomes/player/UserData.java b/common/src/main/java/net/william278/huskhomes/player/UserData.java index 6d1ca685..e19f576d 100644 --- a/common/src/main/java/net/william278/huskhomes/player/UserData.java +++ b/common/src/main/java/net/william278/huskhomes/player/UserData.java @@ -2,12 +2,13 @@ package net.william278.huskhomes.player; import org.jetbrains.annotations.NotNull; +import java.time.Instant; import java.util.UUID; /** * Represents data about a player on the server */ -public record UserData(@NotNull User user, int homeSlots, boolean ignoringTeleports, long rtpCooldown) { +public record UserData(@NotNull User user, int homeSlots, boolean ignoringTeleports, @NotNull Instant rtpCooldown) { @NotNull public UUID getUserUuid() { diff --git a/common/src/main/java/net/william278/huskhomes/position/Home.java b/common/src/main/java/net/william278/huskhomes/position/Home.java index 8819cca5..be38c4e5 100644 --- a/common/src/main/java/net/william278/huskhomes/position/Home.java +++ b/common/src/main/java/net/william278/huskhomes/position/Home.java @@ -1,9 +1,16 @@ package net.william278.huskhomes.position; +import de.themoep.minedown.MineDown; +import net.william278.huskhomes.config.Locales; import net.william278.huskhomes.player.User; import org.jetbrains.annotations.NotNull; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; +import java.util.regex.Pattern; /** * Represents a home set by a {@link User} @@ -30,9 +37,63 @@ public class Home extends SavedPosition { this.isPublic = isPublic; } - public Home(@NotNull Position position, @NotNull PositionMeta meta, @NotNull User owner) { + public Home(@NotNull Position position, @NotNull PositionMeta meta, @NotNull User owner) { super(position, meta); this.owner = owner; this.isPublic = false; } + + @NotNull + public List getHomeEditorWindow(@NotNull Locales locales, final boolean otherViewer, + final boolean showServerInformation, final boolean showButtons) { + return new ArrayList<>() {{ + if (!otherViewer) { + locales.getLocale("edit_home_menu_title", meta.name) + .ifPresent(this::add); + } else { + locales.getLocale("edit_home_menu_title_other", owner.username, meta.name) + .ifPresent(this::add); + } + + locales.getLocale("edit_home_menu_metadata", + DateTimeFormatter.ofPattern("MMM dd yyyy, HH:mm") + .format(meta.creationTime.atZone(ZoneId.systemDefault())), + uuid.toString().split(Pattern.quote("-"))[0], + uuid.toString()) + .ifPresent(this::add); + + if (!isPublic) { + locales.getLocale("edit_home_menu_privacy_private").ifPresent(this::add); + } else { + locales.getLocale("edit_home_menu_privacy_public").ifPresent(this::add); + } + + if (meta.description.length() > 0) { + locales.getLocale("edit_home_menu_description", MineDown.escape(meta.description)) + .ifPresent(this::add); + } + + if (!showServerInformation) { + locales.getLocale("edit_home_menu_world", world.name).ifPresent(this::add); + } else { + locales.getLocale("edit_home_menu_world_server", world.name, server.name).ifPresent(this::add); + } + + locales.getLocale("edit_home_menu_coordinates", + String.format("%.1f", x), String.format("%.1f", y), String.format("%.1f", z), + String.format("%.2f", yaw), String.format("%.2f", pitch)) + .ifPresent(this::add); + + if (showButtons) { + final String formattedName = owner.username + "." + meta.name; + locales.getLocale("edit_home_menu_manage_buttons", + formattedName) + .ifPresent(this::add); + locales.getLocale("edit_home_menu_meta_edit_buttons", + formattedName) + .ifPresent(this::add); + } + }}; + } + } diff --git a/common/src/main/java/net/william278/huskhomes/position/PositionMeta.java b/common/src/main/java/net/william278/huskhomes/position/PositionMeta.java index 33f9af5b..e00b310c 100644 --- a/common/src/main/java/net/william278/huskhomes/position/PositionMeta.java +++ b/common/src/main/java/net/william278/huskhomes/position/PositionMeta.java @@ -22,20 +22,21 @@ public class PositionMeta { public String description; /** - * The epoch timestamp of a position's creation + * The time the position was created */ - public long timestamp; + @NotNull + public Instant creationTime; - public PositionMeta(@NotNull String name, @NotNull String description, long timestamp) { + public PositionMeta(@NotNull String name, @NotNull String description, @NotNull Instant creationTime) { this.name = name; this.description = description; - this.timestamp = timestamp; + this.creationTime = creationTime; } public PositionMeta(@NotNull String name, @NotNull String description) { this.name = name; this.description = description; - this.timestamp = Instant.now().getEpochSecond(); + this.creationTime = Instant.now(); } } diff --git a/common/src/main/java/net/william278/huskhomes/position/SavedPosition.java b/common/src/main/java/net/william278/huskhomes/position/SavedPosition.java index f6b7632f..591b8067 100644 --- a/common/src/main/java/net/william278/huskhomes/position/SavedPosition.java +++ b/common/src/main/java/net/william278/huskhomes/position/SavedPosition.java @@ -13,7 +13,7 @@ public abstract class SavedPosition extends Position { * Metadata about this position (name, description) */ @NotNull - public final PositionMeta meta; + public PositionMeta meta; /** * A unique ID representing this position 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 4b472b70..bd23c7c4 100644 --- a/common/src/main/java/net/william278/huskhomes/position/SavedPositionManager.java +++ b/common/src/main/java/net/william278/huskhomes/position/SavedPositionManager.java @@ -5,7 +5,6 @@ import net.william278.huskhomes.database.Database; import net.william278.huskhomes.player.User; import net.william278.huskhomes.util.RegexUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Optional; @@ -38,23 +37,22 @@ public class SavedPositionManager { * @param homeMeta metadata about the home * @param homeOwner the owner of the home * @param position where the home should be set - * @return a future supplying the {@link SetResult}; the result of setting the home + * @return a future supplying the {@link SaveResult}; the result of setting the home */ - public CompletableFuture setHome(@NotNull PositionMeta homeMeta, @NotNull User homeOwner, - @NotNull Position position) { - return CompletableFuture.supplyAsync(() -> - validateMeta(homeMeta).map(resultType -> new SetResult(resultType, null)).orElseGet(() -> - database.getHome(homeOwner, homeMeta.name).thenApply(optionalHome -> { - if (optionalHome.isEmpty()) { - final Home home = new Home(position, homeMeta, homeOwner); - cache.homes.putIfAbsent(home.owner.uuid, new ArrayList<>()); - cache.homes.get(home.owner.uuid).add(home.meta.name); - cache.positionLists.clear(); - return database.setHome(home).thenApply(value -> - new SetResult(SetResult.ResultType.SUCCESS, home)).join(); - } - return new SetResult(SetResult.ResultType.FAILED_DUPLICATE, null); - }).join())); + public CompletableFuture setHome(@NotNull PositionMeta homeMeta, @NotNull User homeOwner, + @NotNull Position position) { + return database.getHome(homeOwner, homeMeta.name).thenApply(optionalHome -> + validateMeta(homeMeta).map(resultType -> new SaveResult(resultType, Optional.empty())).orElseGet(() -> { + if (optionalHome.isEmpty()) { + final Home home = new Home(position, homeMeta, homeOwner); + cache.homes.putIfAbsent(home.owner.uuid, new ArrayList<>()); + cache.homes.get(home.owner.uuid).add(home.meta.name); + cache.positionLists.clear(); + return database.setHome(home).thenApply(value -> + new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(home))).join(); + } + return new SaveResult(SaveResult.ResultType.FAILED_DUPLICATE, Optional.empty()); + })); } /** @@ -62,10 +60,11 @@ public class SavedPositionManager { * * @param homeOwner the owner of the home * @param homeName the name of the home - * @return a future supplying a boolean; {@code true} if the home was deleted, otherwise {@code false} if the home name was invalid. + * @return a future supplying a boolean; {@code true} if the home was deleted, otherwise {@code false} + * if the home name was invalid. */ public CompletableFuture deleteHome(@NotNull User homeOwner, @NotNull String homeName) { - return CompletableFuture.supplyAsync(() -> database.getHome(homeOwner, homeName).thenApply(optionalHome -> { + return database.getHome(homeOwner, homeName).thenApply(optionalHome -> { if (optionalHome.isPresent()) { final Home home = optionalHome.get(); return database.deleteHome(home.uuid).thenApply(ignored -> { @@ -78,7 +77,129 @@ public class SavedPositionManager { }).join(); } return false; - }).join()); + }); + } + + /** + * Tries to update an existing home with new metadata + * + * @param homeOwner the owner of the home + * @param existingHomeName the current name of the home to update + * @param newHomeMeta the new metadata for the home + * @return a future supplying the {@link SaveResult}; the result of updating the home + */ + public CompletableFuture updateHomeMeta(@NotNull User homeOwner, @NotNull String existingHomeName, + @NotNull PositionMeta newHomeMeta) { + return database.getHome(homeOwner, existingHomeName).thenApply(optionalHome -> { + if (optionalHome.isPresent()) { + return updateHomeMeta(optionalHome.get(), newHomeMeta).join(); + } + return new SaveResult(SaveResult.ResultType.FAILED_DOES_NOT_EXIST, Optional.empty()); + }); + } + + /** + * Tries to update an existing home with new metadata + * + * @param home the home to update + * @param newHomeMeta the new metadata for the home + * @return a future supplying the {@link SaveResult}; the result of updating the home + */ + public CompletableFuture updateHomeMeta(@NotNull Home home, @NotNull PositionMeta newHomeMeta) { + return CompletableFuture.supplyAsync(() -> { + if (database.getHome(home.owner, newHomeMeta.name).join().isPresent()) { + return new SaveResult(SaveResult.ResultType.FAILED_DUPLICATE, Optional.empty()); + } + final String existingHomeName = home.meta.name; + return validateMeta(newHomeMeta).map(resultType -> + new SaveResult(resultType, Optional.empty())).orElseGet(() -> { + home.meta = newHomeMeta; + if (!existingHomeName.equals(newHomeMeta.name)) { + cache.homes.get(home.owner.uuid).remove(existingHomeName); + cache.homes.get(home.owner.uuid).add(newHomeMeta.name); + } + cache.positionLists.clear(); + return database.setHome(home).thenApply(value -> + new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(home))).join(); + }); + }); + } + + + /** + * Tries to update the position of a {@link User}'s home + * + * @param homeOwner the owner of the home + * @param homeName the name of the home + * @param newPosition the new position for the home + * @return a future supplying the {@link SaveResult}; the result of updating the home + */ + public CompletableFuture updateHomePosition(@NotNull User homeOwner, @NotNull String homeName, + @NotNull Position newPosition) { + return database.getHome(homeOwner, homeName).thenApply(optionalHome -> { + if (optionalHome.isPresent()) { + return updateHomePosition(optionalHome.get(), newPosition).join(); + } + return false; + }); + } + + /** + * Tries to update the position of a {@link User}'s home + * + * @param home the home to update + * @param newPosition the new position for the home + * @return a future supplying the {@link SaveResult}; the result of updating the home + */ + public CompletableFuture updateHomePosition(@NotNull Home home, @NotNull Position newPosition) { + home.x = newPosition.x; + home.y = newPosition.y; + home.z = newPosition.z; + home.pitch = newPosition.pitch; + home.yaw = newPosition.yaw; + home.world = newPosition.world; + home.server = newPosition.server; + return database.setHome(home).thenApply(ignored -> true); + } + + /** + * Tries to change the privacy of a {@link User}'s home by given name + * + * @param homeOwner the owner of the home + * @param homeName the name of the home + * @param isHomePublic whether the home should be public or not + * @return a future supplying a boolean; {@code true} if the privacy was changed, otherwise {@code false} + * if the home name was invalid. + */ + public CompletableFuture updateHomePrivacy(@NotNull User homeOwner, @NotNull String homeName, + final boolean isHomePublic) { + return database.getHome(homeOwner, homeName).thenApply(optionalHome -> { + if (optionalHome.isPresent()) { + return updateHomePrivacy(optionalHome.get(), isHomePublic).join(); + } + return false; + }); + } + + /** + * Tries to change the privacy of a {@link User}'s home by given name + * + * @param home the home to update + * @param isHomePublic whether the home should be public or not + * @return a future supplying a boolean; {@code true} if the privacy was changed, otherwise {@code false} + */ + public CompletableFuture updateHomePrivacy(@NotNull Home home, final boolean isHomePublic) { + home.isPublic = isHomePublic; + return database.setHome(home).thenApply(ignored -> { + if (isHomePublic) { + cache.publicHomes.putIfAbsent(home.owner.username, new ArrayList<>()); + cache.publicHomes.get(home.owner.username).add(home.meta.name); + } else if (cache.publicHomes.containsKey(home.owner.username)) { + cache.publicHomes.get(home.owner.username).remove(home.meta.name); + } + cache.positionLists.clear(); + return true; + }); } /** @@ -87,31 +208,31 @@ public class SavedPositionManager { * * @param warpMeta metadata about the warp * @param position where the warp should be set - * @return a future supplying the {@link SetResult}; the result of setting the warp + * @return a future supplying the {@link SaveResult}; the result of setting the warp */ - public CompletableFuture setWarp(@NotNull PositionMeta warpMeta, @NotNull Position position) { - return CompletableFuture.supplyAsync(() -> - validateMeta(warpMeta).map(resultType -> new SetResult(resultType, null)).orElseGet(() -> - database.getWarp(warpMeta.name).thenApply(optionalWarp -> { - if (optionalWarp.isEmpty()) { - final Warp warp = new Warp(position, warpMeta); - cache.warps.add(warp.meta.name); - cache.positionLists.clear(); - return database.setWarp(warp).thenApply(ignored -> - new SetResult(SetResult.ResultType.SUCCESS, warp)).join(); - } - return new SetResult(SetResult.ResultType.FAILED_DUPLICATE, null); - }).join())); + public CompletableFuture setWarp(@NotNull PositionMeta warpMeta, @NotNull Position position) { + return database.getWarp(warpMeta.name).thenApply(optionalWarp -> + validateMeta(warpMeta).map(resultType -> new SaveResult(resultType, Optional.empty())).orElseGet(() -> { + if (optionalWarp.isEmpty()) { + final Warp warp = new Warp(position, warpMeta); + cache.warps.add(warp.meta.name); + cache.positionLists.clear(); + return database.setWarp(warp).thenApply(ignored -> + new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(warp))).join(); + } + return new SaveResult(SaveResult.ResultType.FAILED_DUPLICATE, Optional.empty()); + })); } /** * Tries to delete a warp by given name * * @param warpName the name of the warp - * @return a future supplying a boolean; {@code true} if the warp was deleted, otherwise {@code false} if the warp name was invalid. + * @return a future supplying a boolean; {@code true} if the warp was deleted, otherwise {@code false} + * if the warp name was invalid. */ public CompletableFuture deleteWarp(@NotNull String warpName) { - return CompletableFuture.supplyAsync(() -> database.getWarp(warpName).thenApply(optionalWarp -> { + return database.getWarp(warpName).thenApply(optionalWarp -> { if (optionalWarp.isPresent()) { final Warp warp = optionalWarp.get(); return database.deleteWarp(warp.uuid).thenApply(ignored -> { @@ -121,40 +242,120 @@ public class SavedPositionManager { }).join(); } return false; - }).join()); + }); + } + + /** + * Tries to update an existing home with new metadata + * + * @param existingWarpName the current name of the home to update + * @param newWarpMeta the new metadata for the home + * @return a future supplying the {@link SaveResult}; the result of updating the home + */ + public CompletableFuture updateWarpMeta(@NotNull String existingWarpName, + @NotNull PositionMeta newWarpMeta) { + return database.getWarp(existingWarpName).thenApply(optionalWarp -> { + if (optionalWarp.isPresent()) { + return updateWarpMeta(optionalWarp.get(), newWarpMeta).join(); + } + return new SaveResult(SaveResult.ResultType.FAILED_DOES_NOT_EXIST, Optional.empty()); + }); + } + + /** + * Tries to update an existing warp with new metadata + * + * @param warp the warp to update + * @param newWarpMeta the new metadata for the home + * @return a future supplying the {@link SaveResult}; the result of updating the warp + */ + public CompletableFuture updateWarpMeta(@NotNull Warp warp, @NotNull PositionMeta newWarpMeta) { + return CompletableFuture.supplyAsync(() -> { + if (database.getWarp(newWarpMeta.name).join().isPresent()) { + return new SaveResult(SaveResult.ResultType.FAILED_DUPLICATE, Optional.empty()); + } + final String existingWarpName = warp.meta.name; + return validateMeta(newWarpMeta).map(resultType -> + new SaveResult(resultType, Optional.empty())).orElseGet(() -> { + warp.meta = newWarpMeta; + if (!existingWarpName.equals(newWarpMeta.name)) { + cache.warps.remove(existingWarpName); + cache.warps.add(newWarpMeta.name); + } + cache.positionLists.clear(); + return database.setWarp(warp).thenApply(value -> + new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(warp))).join(); + }); + }); + } + + + /** + * Tries to update the position of a warp + * + * @param warpName the name of the home + * @param newPosition the new position for the home + * @return a future supplying the {@link SaveResult}; the result of updating the home + */ + public CompletableFuture updateWarpPosition(@NotNull String warpName, + @NotNull Position newPosition) { + return database.getWarp(warpName).thenApply(optionalWarp -> { + if (optionalWarp.isPresent()) { + return updateWarpPosition(optionalWarp.get(), newPosition).join(); + } + return false; + }); + } + + /** + * Tries to update the position of a warp + * + * @param warp the warp to update + * @param newPosition the new position for the warp + * @return a future supplying the {@link SaveResult}; the result of updating the warp + */ + public CompletableFuture updateWarpPosition(@NotNull Warp warp, @NotNull Position newPosition) { + warp.x = newPosition.x; + warp.y = newPosition.y; + warp.z = newPosition.z; + warp.pitch = newPosition.pitch; + warp.yaw = newPosition.yaw; + warp.world = newPosition.world; + warp.server = newPosition.server; + return database.setWarp(warp).thenApply(ignored -> true); } /** * Validates {@link PositionMeta} to ensure it can be added to the database * * @param positionMeta the {@link PositionMeta} to validate - * @return An optional. If the {@link PositionMeta} is invalid, this will contain a {@link SetResult.ResultType} + * @return An optional. If the {@link PositionMeta} is invalid, this will contain a {@link SaveResult.ResultType} * identifying which constraint is violated by the metadata */ - private Optional validateMeta(PositionMeta positionMeta) { + private Optional validateMeta(@NotNull PositionMeta positionMeta) { //todo options for allowing unicode names / descriptions if (positionMeta.name.length() > 16) { - return Optional.of(SetResult.ResultType.FAILED_NAME_LENGTH); + return Optional.of(SaveResult.ResultType.FAILED_NAME_LENGTH); } if (!RegexUtil.NAME_PATTERN.matcher(positionMeta.name).matches()) { - return Optional.of(SetResult.ResultType.FAILED_NAME_CHARACTERS); + return Optional.of(SaveResult.ResultType.FAILED_NAME_CHARACTERS); } if (positionMeta.description.length() > 255) { - return Optional.of(SetResult.ResultType.FAILED_DESCRIPTION_LENGTH); + return Optional.of(SaveResult.ResultType.FAILED_DESCRIPTION_LENGTH); } if (!RegexUtil.DESCRIPTION_PATTERN.matcher(positionMeta.name).matches()) { - return Optional.of(SetResult.ResultType.FAILED_DESCRIPTION_CHARACTERS); + return Optional.of(SaveResult.ResultType.FAILED_DESCRIPTION_CHARACTERS); } return Optional.empty(); } /** - * Holds information about the result of setting a warp or home + * A record of information about the result of setting or updating a {@link SavedPosition} in the form of a warp or home * - * @param resultType - * @param setPosition + * @param resultType The {@link ResultType} of the result returned, indicating success + * @param savedPosition The {@link Position} of the saved position, if the result is {@link ResultType#SUCCESS}, otherwise {@link Optional#empty()} */ - public record SetResult(@NotNull ResultType resultType, @Nullable SavedPosition setPosition) { + public record SaveResult(@NotNull ResultType resultType, @NotNull Optional savedPosition) { /** * Indicates the result of setting a warp or home @@ -165,33 +366,38 @@ public class SavedPositionManager { */ SUCCESS(true), + /** + * The home or warp was not set or updated because it does not exist + */ + FAILED_DOES_NOT_EXIST(false), + /** * The position was not set; one by this name has already been set (for the user in the case of homes) */ FAILED_DUPLICATE(false), /** - * The position was not set; the name exceeds the maximum length + * The position was not set or updated; the name exceeds the maximum length */ FAILED_NAME_LENGTH(false), /** - * The position was not set; the description exceeds the maximum length + * The position was not set or updated; the description exceeds the maximum length */ FAILED_DESCRIPTION_LENGTH(false), /** - * The position was not set; the name uses illegal characters + * The position was not set or updated; the name uses illegal characters */ FAILED_NAME_CHARACTERS(false), /** - * The position was not set; the description uses illegal characters + * The position was not set or updated; the description uses illegal characters */ FAILED_DESCRIPTION_CHARACTERS(false), /** - * The position was not set; the position is not in a valid world + * The position was not set or updated; an exception occurred */ FAILED_ERROR(false); diff --git a/common/src/main/resources/locales/en-gb.yml b/common/src/main/resources/locales/en-gb.yml index eb567cfe..b6b15002 100644 --- a/common/src/main/resources/locales/en-gb.yml +++ b/common/src/main/resources/locales/en-gb.yml @@ -1,5 +1,3 @@ -error_no_permission: '[Error:](#ff3300) [You do not have permission to execute that command.](#ff7e5e)' -error_no_last_position: '[Error:](#ff3300) [You have no last position to return to!](#ff7e5e)' teleporting_last_position: '[Returning to your last position in](#00fb9a) [%1%](#00fb9a bold) [seconds](#00fb9a)' teleporting_offline_player: '[Teleporting you to where %1% last logged out...](#00fb9a)' teleporting_countdown_start: '[You will be teleported in](#00fb9a) [%1%](#00fb9a bold) [seconds](#00fb9a)' @@ -12,64 +10,44 @@ teleporting_please_stand_still: '[Teleportation will be cancelled if you move or home_deleted: '[Successfully deleted the home called](#00fb9a) [%1%](#00fb9a bold)' home_deleted_other: '[Successfully deleted %1%''s home,](#00fb9a) [%2%](#00fb9a bold)' warp_deleted: '[Successfully deleted the warp called](#00fb9a) [%1%](#00fb9a bold)' -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_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)' + + +edit_home_menu_title: '[Viewing home details for](#00fb9a) [%1%](#00fb9a bold)[:](#00fb9a)' +edit_home_menu_title_other: '[Viewing details for %1%''s home,](#00fb9a) [%2%](#00fb9a bold)[:](#00fb9a)' +edit_home_menu_metadata: '[⌚ %1%](#ffc43b-#f5c962 show_text=&7Set Timestamp:\n&8When the home was set) [⚡ %2%](#62a9f5-#7ab8fa show_text=&7ID:\n&8%3%)' +edit_home_menu_privacy_private: '[☁ Private Home](#ffc43b-#f5c962 show_text=&7Privacy:\n&8The home is private to the owner)' +edit_home_menu_privacy_public: '[☀ Public Home](#23a825-#36f539 show_text=&7Privacy:\n&8Anyone can teleport to the home)' +edit_home_menu_description: '[🔱 %1%](#ffc43b-#f5c962 show_text=&7Description:\n&8The description set for the home)\n' + +edit_home_menu_world: '[▼ %1%](#ffc43b-#f5c962 show_text=&7World:\n&8The world where the home is set)' +edit_home_menu_world_server: '[▼ %1%](#ffc43b-#f5c962 show_text=&7World:\n&8The world where the home is set) [🏹 %2%](#23a825-#36f539 show_text=&7Server:\n&8The server where the home is set)' +edit_home_menu_coordinates: '[⚐ x: %1%, y: %2%, z: %3%](#ffc43b-#f5c962 show_text=&7Coordinates:\n&8The coordinates, where the home is set\n&7yaw: &8%4%, &7pitch: &8%5%)\n' + +edit_home_menu_manage_buttons: '[Manage:](gray) [[❌ Delete…]](#ff7e5e show_text=&7Click to delete this home\n&#ff3300&⚠ This cannot be undone! run_command=/huskhomes:delhome %1%) [[▼ Relocate]](#ffc43b show_text=&7Click to relocate this home to your position run_command=/huskhomes:edithome %1% relocate) [[☀ Toggle Privacy]](#00fb9a show_text=&7Click to toggle the privacy of this home run_command=/huskhomes:edithome %1% privacy)' +edit_home_menu_meta_edit_buttons: '[Edit:](gray) [[✎ Rename…]](#00fb9a show_text=&7Click to suggest the rename command suggest_command=/huskhomes:edithome %1% rename ) [[🔱 Description…]](#23a825 show_text=&7Click to suggest the edit description command suggest_command=/huskhomes:edithome %1% description )' + edit_home_privacy_public_success: '[Successfully made the home,](#00fb9a) [%1%](#00fb9a bold)[, open to the public.](#00fb9a)' -edit_home_privacy_public_success_economy: '[Successfully made the home,](#00fb9a) [%1%](#00fb9a bold)[, open to the public for %2%.](#00fb9a)' edit_home_privacy_private_success: '[Successfully made the home,](#00fb9a) [%1%](#00fb9a bold)[, private.](#00fb9a)' -error_edit_home_privacy_already_public: '[Error:](#ff3300) [This home is already set as public.](#ff7e5e)' -error_edit_home_privacy_already_private: '[Error:](#ff3300) [This home is already set as private.](#ff7e5e)' -error_edit_home_privacy_no_permission: '[Error:](#ff3300) [You do not have permission to make homes public.](#ff7e5e)' -error_edit_home_description_length: '[Error:](#ff3300) [Home descriptions must be less than 255 characters in length.](#ff7e5e)' -error_edit_home_description_characters: '[Error:](#ff3300) [Home descriptions may only contain alphanumeric (A-Z, 0-9) characters, hyphens (-) and underscores (_)](#ff7e5e)' +edit_home_privacy_public_success_other: '[Successfully made %1%''s home,](#00fb9a) [%2%](#00fb9a bold)[, open to the public.](#00fb9a)' +edit_home_privacy_private_success_other: '[Successfully made %1%''s home,](#00fb9a) [%2%](#00fb9a bold)[, private.](#00fb9a)' edit_home_update_location: '[Re-located](#00fb9a) [%1%](#00fb9a bold) [to your current position.](#00fb9a)' +edit_home_update_location_other: '[Re-located %1%''s home,](#00fb9a) [%2%](#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_home_update_name_other: '[Successfully renamed %1%''s home: %2% →](#00fb9a) [%3%](#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' -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)' edit_warp_update_description: '[Changed the description for the warp](#00fb9a) [%1%](#00fb9a bold) [to "%2%".](#00fb9a)' edit_warp_update_name: '[Successfully changed a warp''s name: %1% →](#00fb9a) [%2%](#00fb9a bold)' -edit_description: '• Description: &7%1%' -edit_location: '• Location: &7%1%, %2%, %3%' -edit_world: '• World: &7%1%' -edit_server: '• Server: &7%1%' -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' -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)' -error_set_warp_invalid_characters: '[Error:](#ff3300) [Warp names must be alphanumeric (A-Z,0-9, -_)](#ff7e5e)' -error_set_warp_invalid_length: '[Error:](#ff3300) [Warp names can only contain up to 16 characters!](#ff7e5e)' -error_set_home_maximum_homes: '[Error:](#ff3300) [You can only set a maximum of %1% homes!](#ff7e5e)' -error_insufficient_funds: '[Error:](#ff3300) [You do not have enough money! (Cost: %1%)](#ff7e5e)' set_home_spent_money: '[Successfully spent %1% to set an additional home!](gray)' set_home_used_free_slots: '[You''ve used all of your free set home slots (%1%); setting additional homes will cost %2% each.](gray)' set_home_success: '[Successfully set a new home called](#00fb9a) [%1%](#00fb9a bold)' set_warp_success: '[Successfully set a new warp called](#00fb9a) [%1%](#00fb9a bold)' -error_set_home_name_taken: '[Error:](#ff3300) [You already have a home set with that name.](#ff7e5e)' -error_set_warp_name_taken: '[Error:](#ff3300) [There is already a warp set with that name.](#ff7e5e)' set_spawn_success: '[Updated spawn position for this server to your current location.](#00fb9a)' -error_spawn_undefined: '[Error:](#ff3300) [There is no spawn position defined on this server.](#ff7e5e)' -error_tpa_no_pending_request: '[Error:](#ff3300) [You do not have a pending teleport request.](#ff7e5e)' -error_tpa_request_expired: '[Error:](#ff3300) [Your pending teleport request has expired.](#ff7e5e)' -error_player_not_found: '[Error:](#ff3300) [Could not find the player %1%.](#ff7e5e)' return_by_death: '[Return to where you died?](gray) [/back](#00fb9a show_text=�fb9a&Click to return to where you died run_command=/back)' teleport_request_options: '[Click an option:](gray) [[Accept]](#00fb9a show_text=�fb9a&Accept the teleport request; /tpaccept %1% run_command=/tpaccept %1%) [•](gray) [[Decline]](#ff7e5e show_text=&#ff7e5e&Decline the teleport request; /tpdeny %1% run_command=/tpdeny %1%)' tpa_you_accepted: '[You accepted %1%''s teleport request](#00fb9a)' @@ -80,29 +58,22 @@ tpa_request_sent: '[You sent a teleport request to teleport to](#00fb9a) [%1%](# tpa_request_ask: '[%1%](#00fb9a bold) [has requested to teleport to you](#00fb9a)' tpahere_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [to teleport to you](#00fb9a)' tpahere_request_ask: '[%1%](#00fb9a bold) [has requested that you teleport to them](#00fb9a)' -error_tp_self: '[Error:](#ff3300) [You can''t teleport to yourself!](#ff7e5e)' -error_rtp_invalid_dimension: '[Error:](#ff3300) [You can only randomly teleport in the overworld!](#ff7e5e)' -error_rtp_cooldown: '[Error:](#ff3300) [You must wait %1% minutes before randomly teleporting again.](#ff7e5e)' rtp_spent_money: '[Spent %1% to randomly teleport.](gray)' back_spent_money: '[Spent %1% to return to your last position.](gray)' -error_command_disabled: '[Error:](#ff3300) [That command is disabled!](#ff7e5e)' -error_console_only: '[Error:](#ff3300) [That command can only be run from the server console.](#ff7e5e)' -error_tp_invalid_world: '[Error:](#ff3300) [Please specify a valid server world.](#ff7e5e)' -error_rtp_randomization_timeout: '[Error:](#ff3300) [Failed to find a safe random location to teleport you.](#ff7e5e)' -list_item_divider: ' [•](gray) ' -home_list_item: '[[%1%]](show_text=&7%3% run_command=/huskhomes:edithome %2%.%1%)' -public_home_list_item: '[[%1%]](show_text=�fb9a&%2%: &7%3% run_command=/huskhomes:phome %2%.%1%)' -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_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)' teleporting_complete_console: '[Console teleported you to %1%.](gray)' spawn_warp_default_description: 'The /spawn position of the server' -error_invalid_page_number: '[Error:](#ff3300) [Please specify a valid page number.](#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)' +tpignore_toggle_off: '[You are now](#00fb9a) [listening](#00fb9a bold) [to any incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to ignore incoming teleport requests run_command=/huskhomes:tpignore)' +tpignore_on_reminder: '[You are currently ignoring incoming teleport requests!](gray) [(Click to toggle)](gray show_text=&7Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' +tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)' + page_options: '[←](gray show_text=&7View previous page run_command=%1%) [Viewing Page %2%/%3%](#00fb9a) [→](gray show_text=&7View next page run_command=%4%)' page_options_min: '[Viewing Page %1%/%2%](#00fb9a) [→](gray show_text=&7View next page run_command=%3%)' page_options_min_max: '[Viewing Page %1%/%2%](#00fb9a)' @@ -110,20 +81,61 @@ page_options_max: '[←](gray show_text=&7View previous page run_command=%1%) [V 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_item: '[/%1%](#00fb9a show_text=�fb9a&%2% suggest_command=/%1%) [•](white) [%3%](gray)' +list_item_divider: ' [•](gray) ' +home_list_item: '[[%1%]](show_text=&7%3% run_command=/huskhomes:edithome %2%.%1%)' +public_home_list_item: '[[%1%]](show_text=�fb9a&%2%: &7%3% run_command=/huskhomes:phome %2%.%1%)' +warp_list_item: '[[%1%]](show_text=&7%2% run_command=/huskhomes:warp %1%)' + + +error_no_permission: '[Error:](#ff3300) [You do not have permission to execute that command.](#ff7e5e)' +error_no_last_position: '[Error:](#ff3300) [You have no last position to return to!](#ff7e5e)' +error_in_game_only: '[Error:](#ff3300) [That command can only be run in-game.](#ff7e5e)' +error_invalid_server: '[Error:](#ff3300) [Failed to finish your teleportation as the target server could not be found or was offline.](#ff7e5e)' +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)' +error_edit_home_privacy_already_public: '[Error:](#ff3300) [This home is already set as public.](#ff7e5e)' +error_edit_home_privacy_already_private: '[Error:](#ff3300) [This home is already set as private.](#ff7e5e)' +error_edit_home_privacy_no_permission: '[Error:](#ff3300) [You do not have permission to make homes public.](#ff7e5e)' +error_edit_home_description_length: '[Error:](#ff3300) [Home descriptions must be less than 255 characters in length.](#ff7e5e)' +error_edit_home_description_characters: '[Error:](#ff3300) [Home descriptions may only contain alphanumeric (A-Z, 0-9) characters, hyphens (-) and underscores (_)](#ff7e5e)' +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)' +error_no_homes_set: '[Error:](#ff3300) [You have not set any homes!](#ff7e5e)' +error_no_public_homes_set: '[Error:](#ff3300) [There are no public homes set!](#ff7e5e)' +error_no_warps_set: '[Error:](#ff3300) [There are no warps set!](#ff7e5e)' +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)' +error_set_warp_invalid_characters: '[Error:](#ff3300) [Warp names must be alphanumeric (A-Z,0-9, -_)](#ff7e5e)' +error_set_warp_invalid_length: '[Error:](#ff3300) [Warp names can only contain up to 16 characters!](#ff7e5e)' +error_set_home_maximum_homes: '[Error:](#ff3300) [You can only set a maximum of %1% homes!](#ff7e5e)' +error_insufficient_funds: '[Error:](#ff3300) [You do not have enough money! (Cost: %1%)](#ff7e5e)' +error_spawn_undefined: '[Error:](#ff3300) [There is no spawn position defined on this server.](#ff7e5e)' +error_tpa_no_pending_request: '[Error:](#ff3300) [You do not have a pending teleport request.](#ff7e5e)' +error_tpa_request_expired: '[Error:](#ff3300) [Your pending teleport request has expired.](#ff7e5e)' +error_player_not_found: '[Error:](#ff3300) [Could not find the player %1%.](#ff7e5e)' +error_set_home_name_taken: '[Error:](#ff3300) [You already have a home set with that name.](#ff7e5e)' +error_set_warp_name_taken: '[Error:](#ff3300) [There is already a warp set with that name.](#ff7e5e)' +error_tp_self: '[Error:](#ff3300) [You cannot teleport to yourself!](#ff7e5e)' +error_rtp_invalid_dimension: '[Error:](#ff3300) [You can only randomly teleport in the overworld!](#ff7e5e)' +error_rtp_cooldown: '[Error:](#ff3300) [You must wait %1% minutes before randomly teleporting again.](#ff7e5e)' +error_command_disabled: '[Error:](#ff3300) [That command is disabled!](#ff7e5e)' +error_console_only: '[Error:](#ff3300) [That command can only be run from the server console.](#ff7e5e)' +error_tp_invalid_world: '[Error:](#ff3300) [Please specify a valid server world.](#ff7e5e)' +error_rtp_randomization_timeout: '[Error:](#ff3300) [Failed to find a safe random location to teleport you.](#ff7e5e)' +error_permission_restricted_warp: '[Error:](#ff3300) [You do not have permission to warp to %1%!](#ff7e5e)' +error_invalid_page_number: '[Error:](#ff3300) [Please specify a valid page number.](#ff7e5e)' 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)' -tpignore_toggle_off: '[You are now](#00fb9a) [listening](#00fb9a bold) [to any incoming teleport requests.](#00fb9a) [(Click to toggle)](gray show_text=&7Click to ignore incoming teleport requests run_command=/huskhomes:tpignore)' -tpignore_on_reminder: '[You are currently ignoring incoming teleport requests!](gray) [(Click to toggle)](gray show_text=&7Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' error_ignoring_teleport_requests: '[Error:](#ff3300) [You are currently ignoring teleport requests!](#ff7e5e) [(Click to toggle)](#ff7e5e show_text=&#ff7e5e&Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)' error_no_offline_position: '[Error:](#ff3300) [Could not find where %1% last logged out.](#ff7e5e)' error_invalid_player: '[Error:](#ff3300) [Please specify the name of a valid player!](#ff7e5e)' -error_no_homes_set_other: '[Error:](#ff3300) [%1% hasn''t set any homes!](#ff7e5e)' -error_home_invalid_other: '[Error:](#ff3300) [%1% doesn''t have a home set named "%2%"](#ff7e5e)' +error_no_homes_set_other: '[Error:](#ff3300) [%1% has not set any homes!](#ff7e5e)' +error_home_invalid_other: '[Error:](#ff3300) [%1% does not have a home set named "%2%"](#ff7e5e)' error_edit_home_maximum_public_homes: '[Error:](#ff3300) [You can only make a maximum of %1% homes public.](#ff7e5e)' -tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you!](#00fb9a)' -error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)' -teleporting_all_players: '[Teleporting all players to your position...](#00fb9a)' error_illegal_target_coordinates: '[Error:](#ff3300) [Aborted teleport as it exceeds the possible game world limits.](#ff7e5e)' +error_no_other_online_players: '[Error:](#ff3300) [There are no other online players who could teleport to you.](#ff7e5e)' + home_command_description: 'Teleport to one of your homes' sethome_command_description: 'Set a new home with given name' delhome_command_description: 'Delete a home you previously set' @@ -150,6 +162,4 @@ spawn_command_description: 'Teleport to spawn' setspawn_command_description: 'Set the spawn position' tpaall_command_description: 'Request that everyone teleports to you' tpall_command_description: 'Teleport everyone to your position' -huskhomes_command_description: 'View plugin information & reload configs' -error_in_game_only: '[Error:](#ff3300) [That command can only be run in-game.](#ff7e5e)' -error_invalid_server: '[Error:](#ff3300) [Failed to finish your teleportation as the target server could not be found or was offline.](#ff7e5e)' \ No newline at end of file +huskhomes_command_description: 'View plugin information & reload configs' \ No newline at end of file