From 054edcf14566d9be0a85e398dc08f67caac5c79b Mon Sep 17 00:00:00 2001 From: MrSnowy Date: Sun, 23 Feb 2025 01:19:44 +0100 Subject: [PATCH] Still rewriting, it compiles now tho! PLEASE DON'T USE! --- .gitignore | 1 + CHANGELOG.md | 3 +- .../teleport_commands/commands/home.java | 268 ++++++++++------- .../teleport_commands/commands/tpa.java | 2 - .../teleport_commands/commands/warp.java | 281 +++++++++--------- .../teleport_commands/common/Player.java | 2 +- .../storage/StorageManager.java | 1 + .../assets/teleport_commands/lang/en_us.json | 1 + .../assets/teleport_commands/lang/hu_hu.json | 1 + .../assets/teleport_commands/lang/it_it.json | 1 + .../assets/teleport_commands/lang/nl_nl.json | 1 + .../assets/teleport_commands/lang/ru_ru.json | 1 + .../assets/teleport_commands/lang/zh_cn.json | 1 + .../assets/teleport_commands/lang/zh_tw.json | 1 + 14 files changed, 309 insertions(+), 256 deletions(-) diff --git a/.gitignore b/.gitignore index c6728e1..12923bf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build/ out/ classes/ +bin/ # idea out diff --git a/CHANGELOG.md b/CHANGELOG.md index b0008cc..1896c82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the Storage classes and functions (I'm doing proper java, yipie) - Better error handling for command suggestions - Added hover effects for warp and homes text (W.I.P) -- Throw an exception when the world isn't found (when doing back or home), instead of giving an incorrect notFound error. +- Throw an exception when the world isn't found (when going back or home), instead of giving an incorrect notFound error. +- Added a new `home.defaultNone` translation key for when there is no default house set. (before this would give `home.homeless` for some reason) ### [v1.2.2] - Handled a case where the client (geyser) will return the language as uppercase instead of lowercase. diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java index f9c51a7..bf1af93 100644 --- a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java +++ b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java @@ -1,15 +1,13 @@ package dev.mrsnowy.teleport_commands.commands; import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.datafixers.util.Pair; import dev.mrsnowy.teleport_commands.TeleportCommands; import dev.mrsnowy.teleport_commands.storage.StorageManager; import dev.mrsnowy.teleport_commands.common.NamedLocation; import dev.mrsnowy.teleport_commands.common.Player; import dev.mrsnowy.teleport_commands.suggestions.HomeSuggestionProvider; -import java.util.Locale; -import java.util.Objects; +import java.util.ArrayList; import java.util.Optional; import net.minecraft.ChatFormatting; @@ -162,7 +160,7 @@ public class home { private static void SetHome(ServerPlayer player, String homeName) throws Exception { homeName = homeName.toLowerCase(); BlockPos blockPos = player.blockPosition(); - ServerLevel world = player.serverLevel(); + String worldString = player.serverLevel().dimension().location().toString(); // Gets player storage and makes it if it doesn't exist Player playerStorage = StorageManager.STORAGE.addPlayer(player.getStringUUID()); @@ -174,7 +172,7 @@ public class home { } // Create a new NamedLocation - playerStorage.setHome(homeName, blockPos, world.dimension().location().toString()); + playerStorage.setHome(homeName, blockPos, worldString); // Set it as the default if there are no other homes if (playerStorage.getHomes().size() == 1) { @@ -189,7 +187,7 @@ public class home { private static void GoHome(ServerPlayer player, String homeName) throws Exception { homeName = homeName.toLowerCase(); - // Gets player storage + // Get player storage Optional optionalPlayerStorage = STORAGE.getPlayer(player.getStringUUID()); if (optionalPlayerStorage.isEmpty()) { player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); @@ -198,20 +196,20 @@ public class home { Player playerStorage = optionalPlayerStorage.get(); - // if homeName is empty, get the default home + // If homeName is empty, get the default home if (homeName.isEmpty()) { - // todo! if there is no default home set, maybe give an message saying: no default home set! String defaultHome = playerStorage.getDefaultHome(); if (defaultHome.isEmpty()) { - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); + // todo! test if this translation key works correctly! + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.defaultNone", player).withStyle(ChatFormatting.AQUA), true); return; } else { homeName = defaultHome; } } - // get the home (if it exists) + // Get the home (if it exists) Optional optionalHome = playerStorage.getHome(homeName); if (optionalHome.isEmpty()) { player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.AQUA), true); @@ -220,24 +218,21 @@ public class home { NamedLocation home = optionalHome.get(); - // get the world, otherwise throw an exception - Optional optionalHomeWorld = home.getWorld(); - if (optionalHomeWorld.isEmpty()) { + // Get the world, otherwise throw an exception + ServerLevel homeWorld = home.getWorld().orElseThrow(() -> { // todo! test this exception - - throw new Exception( String.format("Couldn't find a world with the id: %s \nAvailable worlds: %s", + return new Exception( String.format("Couldn't find a world with the id: %s \nAvailable worlds: %s", home.getWorldString(), TeleportCommands.SERVER.getAllLevels())); - } + }); - ServerLevel homeWorld = optionalHomeWorld.get(); BlockPos teleportBlockPos = home.getBlockPos(); - // check if the player is already at this location (in the same world) + // Check if the player is already at this location (in the same world) if (player.blockPosition().equals(teleportBlockPos) && player.level() == homeWorld) { player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.goSame", player).withStyle(ChatFormatting.AQUA), true); } else { - // teleport the player! + // Teleport the player! Vec3 teleportPos = new Vec3(teleportBlockPos.getX() + 0.5, teleportBlockPos.getY(), teleportBlockPos.getZ() + 0.5); player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.go", player), true); @@ -264,15 +259,16 @@ public class home { return; } - NamedLocation home = optionalHome.get(); + // delete the home + playerStorage.deleteHome(optionalHome.get()); // check if it's the default home, if it is set it to the default value if (playerStorage.getDefaultHome().equals(homeName)) { playerStorage.setDefaultHome(""); + + // todo! maybe ask the player if they want to set a new default home? :3 } - // delete the home - playerStorage.deleteHome(home); player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.delete", player), true); } @@ -280,127 +276,183 @@ public class home { homeName = homeName.toLowerCase(); newHomeName = newHomeName.toLowerCase(); - Pair storages = GetPlayerStorage(player.getStringUUID()); - StorageManager.StorageClass storage = storages.getFirst(); - StorageManager.StorageClass.Player playerStorage = storages.getSecond(); - - boolean newNameNotFound = true; - boolean WarpRenamed = false; - - // check for duplicates - for (StorageManager.StorageClass.NamedLocation currentHome : playerStorage.Homes) { - if (Objects.equals(currentHome.name, newHomeName)) { - newNameNotFound = false; - break; - } + // Gets player storage + Optional optionalPlayerStorage = STORAGE.getPlayer(player.getStringUUID()); + if (optionalPlayerStorage.isEmpty()) { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); + return; } - if (newNameNotFound) { - // get correct home - for (StorageManager.StorageClass.NamedLocation currentHome : playerStorage.Homes) { - if (Objects.equals(currentHome.name, homeName)) { + Player playerStorage = optionalPlayerStorage.get(); - // if the current home is the default home, then change to the new name in the config - if (Objects.equals(playerStorage.DefaultHome, currentHome.name)) { - playerStorage.DefaultHome = newHomeName; - } + // Check if there already is a home with the new name + playerStorage.getHome("newHomeName").ifPresent(name -> { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.renameExists", player).withStyle(ChatFormatting.RED), true); + return; + // todo! does this exit correctly? + }); - currentHome.name = newHomeName; - StorageSaver(); + // Get the home that needs to be renamed + Optional optionalHome = playerStorage.getHome(homeName); + if (optionalHome.isEmpty()) { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.RED), true); + return; + } - WarpRenamed = true; - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.rename", player), true); - break; - } - } + // Rename home + optionalHome.get().setName(newHomeName); - if (!WarpRenamed) { - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.RED), true); - } - } else { - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.renameExists", player).withStyle(ChatFormatting.RED), true); + // check if the current home is the default, then change it to the new name + if (playerStorage.getDefaultHome().equals(homeName)) { + playerStorage.setDefaultHome(newHomeName); } + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.rename", player), true); } private static void SetDefaultHome(ServerPlayer player, String homeName) throws Exception { homeName = homeName.toLowerCase(); - Pair storages = GetPlayerStorage(player.getStringUUID()); - StorageManager.StorageClass storage = storages.getFirst(); - StorageManager.StorageClass.Player playerStorage = storages.getSecond(); - - boolean homeExists = false; - - // check if home exists - for (StorageManager.StorageClass.NamedLocation currentHome : playerStorage.Homes) { - if (Objects.equals(currentHome.name, homeName)){ - homeExists = true; - break; - } + // Gets player storage + Optional optionalPlayerStorage = STORAGE.getPlayer(player.getStringUUID()); + if (optionalPlayerStorage.isEmpty()) { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); + return; } - if (homeExists) { - if (!Objects.equals(playerStorage.DefaultHome, homeName)) { - - playerStorage.DefaultHome = homeName; - StorageSaver(); - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.default", player), true); - - } else { - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.defaultSame", player).withStyle(ChatFormatting.AQUA), true); - } + Player playerStorage = optionalPlayerStorage.get(); - } else { + // Check if the new default home exists + if ( playerStorage.getHome(homeName).isEmpty() ) { player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.RED), true); + return; + } + + // Check if the home is already the default + if (playerStorage.getDefaultHome().equals(homeName)) { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.defaultSame", player).withStyle(ChatFormatting.AQUA), true); + return; } + + // set the new default + playerStorage.setDefaultHome(homeName); + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.default", player), true); } private static void PrintHomes(ServerPlayer player) throws Exception { - StorageManager.StorageClass.Player playerStorage = GetPlayerStorage(player.getStringUUID()).getSecond(); - if (playerStorage.Homes.isEmpty()) { + // Gets player storage + Optional optionalPlayerStorage = STORAGE.getPlayer(player.getStringUUID()); + if (optionalPlayerStorage.isEmpty()) { player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); + return; + } - } else { - player.displayClientMessage(getTranslatedText("commands.teleport_commands.homes.homes", player).withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD) - .append("\n"), false); + Player playerStorage = optionalPlayerStorage.get(); - for (StorageManager.StorageClass.NamedLocation currentHome : playerStorage.Homes) { + ArrayList homes = playerStorage.getHomes(); + + // Check if there are any homes lol + if (homes.isEmpty()) { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); + return; + } - String name = String.format(" - %s", currentHome.name); - String coords = String.format("[X%d Y%d Z%d]", currentHome.x, currentHome.y, currentHome.z); - String dimension = String.format(" [%s]", currentHome.world); + // Print the stuffz - if (Objects.equals(currentHome.name, playerStorage.DefaultHome)) { - player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA) - .append(" ") - .append(getTranslatedText("commands.teleport_commands.common.default", player).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD)), - false - ); - } else { - player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA), false); - } + player.displayClientMessage(getTranslatedText("commands.teleport_commands.homes.homes", player).withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD) + .append("\n"), false); + // todo! Make it send it all at once? + for (NamedLocation currentHome : homes) { - player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) - .append(Component.literal(coords).withStyle(ChatFormatting.LIGHT_PURPLE).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, String.format("X%d Y%d Z%d", currentHome.x, currentHome.y, currentHome.z))))) - .append(Component.literal(dimension).withStyle(ChatFormatting.DARK_PURPLE).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, currentHome.world)))), - false - ); + String name = String.format(" - %s", currentHome.getName()); + String coords = String.format("[X%d Y%d Z%d]", currentHome.getX(), currentHome.getY(), currentHome.getZ()); + String dimension = String.format(" [%s]", currentHome.getWorldString()); - player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) - .append(getTranslatedText("commands.teleport_commands.common.tp", player).withStyle(ChatFormatting.GREEN).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/home %s", currentHome.name))))) + // Check if the home is the default home, then add text showcasing that it is + if (playerStorage.getDefaultHome().equals(currentHome.getName())) { + player.displayClientMessage(Component.literal(name) + .withStyle(ChatFormatting.AQUA) .append(" ") - .append(getTranslatedText("commands.teleport_commands.common.rename", player).withStyle(ChatFormatting.BLUE).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format("/renamehome %s ", currentHome.name))))) - .append(" ") - .append(getTranslatedText("commands.teleport_commands.common.delete", player).withStyle(ChatFormatting.RED).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format("/delhome %s", currentHome.name))))) - .append("\n"), + .append(getTranslatedText("commands.teleport_commands.common.default", player) + .withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD) + ), false ); + } else { + player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA), false); } + // Cords and dimension + player.displayClientMessage(Component.literal(" | ") + .withStyle(ChatFormatting.AQUA) + .append(Component.literal(coords) + .withStyle(ChatFormatting.LIGHT_PURPLE) + .withStyle(style -> + style.withClickEvent( + new ClickEvent( + ClickEvent.Action.COPY_TO_CLIPBOARD, + String.format("X%d Y%d Z%d", currentHome.getX(), currentHome.getY(), currentHome.getZ()) + ) + ) + ) + ) + .append(Component.literal(dimension) + .withStyle(ChatFormatting.DARK_PURPLE) + .withStyle(style -> + style.withClickEvent( + new ClickEvent( + ClickEvent.Action.COPY_TO_CLIPBOARD, + currentHome.getWorldString() + ) + ) + ) + ), + false + ); + + // Teleport, rename and delete buttons + player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) + .append(getTranslatedText("commands.teleport_commands.common.tp", player) + .withStyle(ChatFormatting.GREEN) + .withStyle(style -> + style.withClickEvent( + new ClickEvent( + ClickEvent.Action.RUN_COMMAND, + String.format("/home %s", currentHome.getName()) + ) + ) + ) + ) + .append(" ") + .append(getTranslatedText("commands.teleport_commands.common.rename", player) + .withStyle(ChatFormatting.BLUE) + .withStyle(style -> + style.withClickEvent( + new ClickEvent( + ClickEvent.Action.SUGGEST_COMMAND, + String.format("/renamehome %s ", currentHome.getName()) + ) + ) + ) + ) + .append(" ") + .append(getTranslatedText("commands.teleport_commands.common.delete", player) + .withStyle(ChatFormatting.RED) + .withStyle(style -> + style.withClickEvent( + new ClickEvent( + ClickEvent.Action.SUGGEST_COMMAND, + String.format("/delhome %s", currentHome.getName()) + ) + ) + ) + ) + .append("\n"), + false + ); } - } + } } \ No newline at end of file diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java index d588b8b..6c9e020 100644 --- a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java +++ b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java @@ -31,8 +31,6 @@ public class tpa { this.here = here; tpaList.add(this); } - - } public static void register(Commands commandManager) { diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java index a49d986..6a12133 100644 --- a/common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java +++ b/common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java @@ -1,7 +1,6 @@ package dev.mrsnowy.teleport_commands.commands; import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.datafixers.util.Pair; import dev.mrsnowy.teleport_commands.TeleportCommands; import dev.mrsnowy.teleport_commands.common.NamedLocation; import dev.mrsnowy.teleport_commands.suggestions.WarpSuggestionProvider; @@ -16,8 +15,6 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.phys.Vec3; import java.util.ArrayList; -import java.util.List; -import java.util.Objects; import java.util.Optional; import static dev.mrsnowy.teleport_commands.storage.StorageManager.*; @@ -133,82 +130,71 @@ public class warp { warpName = warpName.toLowerCase(); BlockPos blockPos = new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()); - ServerLevel world = player.serverLevel(); + String worldString = player.serverLevel().dimension().location().toString(); - Pair> storages = getWarpStorage(); - StorageClass storage = storages.getFirst(); - List WarpStorage = storages.getSecond(); - - boolean warpNotFound = true; - - // check for duplicates - for (StorageClass.NamedLocation currentWarp : WarpStorage) { - if (Objects.equals(currentWarp.name, warpName)) { - warpNotFound = false; - break; - } + // Check if warp already exists + if ( STORAGE.getWarp(warpName).isEmpty() ) { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.exists", player).withStyle(ChatFormatting.RED), true); + return; } - if (warpNotFound) { - // Create a new NamedLocation - StorageClass.NamedLocation warpData = new StorageClass.NamedLocation(warpName, blockPos, world.dimension().location().toString()); - storage.Warps.add(warpData); + // Create the warp + STORAGE.setWarp(warpName, blockPos, worldString); - StorageSaver(); - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.set", player), true); - } else { - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.exists", player).withStyle(ChatFormatting.RED), true); - } + // Display message that the home as been set + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.set", player), true); } private static void GoToWarp(ServerPlayer player, String warpName) throws Exception { warpName = warpName.toLowerCase(); - List WarpStorage = getWarpStorage().getSecond(); - boolean foundWorld = false; + // Gets warp + Optional optionalWarp = STORAGE.getWarp(warpName); + if (optionalWarp.isEmpty()) { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.notFound", player).withStyle(ChatFormatting.RED), true); + return; + } + + NamedLocation warp = optionalWarp.get(); - // find correct warp - for (NamedLocation currentWarp : WarpStorage) { - if (Objects.equals(currentWarp.name, warpName)) { + // Get the world, otherwise throw an exception + ServerLevel warpWorld = warp.getWorld().orElseThrow(() -> { + // todo! test this exception + return new Exception( String.format("Couldn't find a world with the id: %s \nAvailable worlds: %s", + warp.getWorldString(), TeleportCommands.SERVER.getAllLevels())); + }); - // find correct world - for (ServerLevel currentWorld : TeleportCommands.SERVER.getAllLevels()) { - if (Objects.equals(currentWorld.dimension().location().toString(), currentWarp.world)) { - foundWorld = true; + BlockPos teleportBlockPos = warp.getBlockPos(); - BlockPos coords = new BlockPos(currentWarp.x, currentWarp.y, currentWarp.z); - BlockPos playerBlockPos = new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()); + // Check if the player is already at this location (in the same world) + if (player.blockPosition().equals(teleportBlockPos) && player.level() == warpWorld) { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.goSame", player).withStyle(ChatFormatting.AQUA), true); - if (!playerBlockPos.equals(coords)) { - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.go", player), true); - Teleporter(player, currentWorld, new Vec3(currentWarp.x + 0.5, currentWarp.y, currentWarp.z + 0.5)); - } else { - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.goSame", player).withStyle(ChatFormatting.AQUA), true); - } - break; - } - } - } - } + } else { + // Teleport the player! + Vec3 teleportPos = new Vec3(teleportBlockPos.getX() + 0.5, teleportBlockPos.getY(), teleportBlockPos.getZ() + 0.5); - if (!foundWorld) { - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.notFound", player).withStyle(ChatFormatting.RED), true); + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.go", player), true); + Teleporter(player, warpWorld, teleportPos); } } private static void DeleteWarp(ServerPlayer player, String warpName) throws Exception { warpName = warpName.toLowerCase(); + // todo! maybe replace with ifPresentOrElse // get the existing warp Optional optionalWarp = STORAGE.getWarp(warpName); if (optionalWarp.isPresent()) { + // Delete the warp STORAGE.rmWarp(optionalWarp.get()); + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.delete", player), true); + } else { // the warp is not found - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.notFound", player) - .withStyle(ChatFormatting.RED), true); + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.notFound", player).withStyle(ChatFormatting.RED), true); } } @@ -216,134 +202,141 @@ public class warp { warpName = warpName.toLowerCase(); newWarpName = newWarpName.toLowerCase(); + // check if there is no existing warp with the new name + if (STORAGE.getWarp(newWarpName).isPresent()) { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.renameExists", player).withStyle(ChatFormatting.RED), true); + return; + } + // get the existing warp - Optional warp = STORAGE.getWarp(warpName); + Optional warpToRename = STORAGE.getWarp(warpName); - if (warp.isPresent()) { - NamedLocation homeToRename = warp.get(); + if (warpToRename.isPresent()) { - // check if there is no existing warp with the new name - if (STORAGE.getWarp(newWarpName).isEmpty()) { - - // set the new name - homeToRename.setName(newWarpName); - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.rename", player), true); - } else { - - // there is already a warp with the new name - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.renameExists", player).withStyle(ChatFormatting.RED), true); - } + // set the new name + warpToRename.get().setName(newWarpName); + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.rename", player), true); } else { // the warp is not found player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.notFound", player).withStyle(ChatFormatting.RED), true); } - } private static void PrintWarps(ServerPlayer player) throws Exception { + // Get warps ArrayList warps = STORAGE.getWarps(); + // Check if there are any warps lol if (warps.isEmpty()) { player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.homeless", player).withStyle(ChatFormatting.AQUA), true); + return; + } - } else { - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warps.warps", player).withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD) - .append("\n"), false); + // Print the stuffz - for (NamedLocation currentWarp : warps) { + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warps.warps", player).withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD) + .append("\n"), false); - String name = String.format(" - %s", currentWarp.getName()); - String coords = String.format("[X%d Y%d Z%d]", currentWarp.getX(), currentWarp.getY(), currentWarp.getZ()); - String dimension = String.format(" [%s]", currentWarp.getWorldString()); + for (NamedLocation currentWarp : warps) { - player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA), false); + String name = String.format(" - %s", currentWarp.getName()); + String coords = String.format("[X%d Y%d Z%d]", currentWarp.getX(), currentWarp.getY(), currentWarp.getZ()); + String dimension = String.format(" [%s]", currentWarp.getWorldString()); - player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) - .append(Component.literal(coords) - .withStyle(ChatFormatting.LIGHT_PURPLE) - .withStyle(style -> style - .withClickEvent(new ClickEvent( + player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA), false); + + player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) + .append(Component.literal(coords) + .withStyle(ChatFormatting.LIGHT_PURPLE) + .withStyle(style -> + style.withClickEvent( + new ClickEvent( ClickEvent.Action.COPY_TO_CLIPBOARD, String.format("X%d Y%d Z%d", currentWarp.getX(), currentWarp.getY(), currentWarp.getZ()) + ) + ) + ) + //todo! test the hover + .withStyle(style -> + style.withHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, getTranslatedText("commands.teleport_commands.common.hoverCopy", player) + )) + ) + ) + .append(Component.literal(dimension) + .withStyle(ChatFormatting.DARK_PURPLE) + .withStyle(style -> + style.withClickEvent( + new ClickEvent( + ClickEvent.Action.COPY_TO_CLIPBOARD, + currentWarp.getWorldString() + ) + ) + ) + .withStyle(style -> style + .withHoverEvent( + new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + getTranslatedText("commands.teleport_commands.common.hoverCopy", player) + ) + ) + ) + ), + false + ); + + // todo! maybe make this a boolean at the begging of the function. + if (player.hasPermissions(4)) { + player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) + .append(getTranslatedText("commands.teleport_commands.common.tp", player) + .withStyle(ChatFormatting.GREEN) + .withStyle(style -> + style.withClickEvent(new ClickEvent( + ClickEvent.Action.RUN_COMMAND, + String.format("/warp %s", currentWarp.getName()) )) ) - //todo! test the hover + ) + .append(" ") + .append(getTranslatedText("commands.teleport_commands.common.rename", player) + .withStyle(ChatFormatting.BLUE) .withStyle(style -> style - .withHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, getTranslatedText("commands.teleport_commands.common.hoverCopy", player) - )) + .withClickEvent(new ClickEvent( + ClickEvent.Action.SUGGEST_COMMAND, + String.format("/renamewarp %s ", currentWarp.getName())) + ) ) ) - .append(Component.literal(dimension) - .withStyle(ChatFormatting.DARK_PURPLE) + .append(" ") + .append(getTranslatedText("commands.teleport_commands.common.delete", player) + .withStyle(ChatFormatting.RED) .withStyle(style -> style .withClickEvent(new ClickEvent( - ClickEvent.Action.COPY_TO_CLIPBOARD, - currentWarp.getWorldString() - )) + ClickEvent.Action.SUGGEST_COMMAND, + String.format("/delwarp %s", currentWarp.getName())) + ) ) + ) + .append("\n"), + false + ); + } else { + player.displayClientMessage(Component.literal(" | ") + .withStyle(ChatFormatting.AQUA) + .append(getTranslatedText("commands.teleport_commands.common.tp", player) + .withStyle(ChatFormatting.GREEN) .withStyle(style -> style - .withHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, getTranslatedText("commands.teleport_commands.common.hoverCopy", player) - )) + .withClickEvent(new ClickEvent( + ClickEvent.Action.RUN_COMMAND, + String.format("/warp %s", currentWarp.getName())) + ) ) - ), + ) + .append("\n"), false ); - - if (player.hasPermissions(4)) { - player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) - .append(getTranslatedText("commands.teleport_commands.common.tp", player) - .withStyle(ChatFormatting.GREEN) - .withStyle(style -> style - .withClickEvent(new ClickEvent( - ClickEvent.Action.RUN_COMMAND, - String.format("/warp %s", currentWarp.getName()) - )) - ) - ) - .append(" ") - .append(getTranslatedText("commands.teleport_commands.common.rename", player) - .withStyle(ChatFormatting.BLUE) - .withStyle(style -> style - .withClickEvent(new ClickEvent( - ClickEvent.Action.SUGGEST_COMMAND, - String.format("/renamewarp %s ", currentWarp.getName())) - ) - ) - ) - .append(" ") - .append(getTranslatedText("commands.teleport_commands.common.delete", player) - .withStyle(ChatFormatting.RED) - .withStyle(style -> style - .withClickEvent(new ClickEvent( - ClickEvent.Action.SUGGEST_COMMAND, - String.format("/delwarp %s", currentWarp.getName())) - ) - ) - ) - .append("\n"), - false - ); - } else { - player.displayClientMessage(Component.literal(" | ") - .withStyle(ChatFormatting.AQUA) - .append(getTranslatedText("commands.teleport_commands.common.tp", player) - .withStyle(ChatFormatting.GREEN) - .withStyle(style -> style - .withClickEvent(new ClickEvent( - ClickEvent.Action.RUN_COMMAND, - String.format("/warp %s", currentWarp.getName())) - ) - ) - ) - .append("\n"), - false - ); - } } - } } } diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/common/Player.java b/common/src/main/java/dev/mrsnowy/teleport_commands/common/Player.java index 5ac38b4..9900342 100644 --- a/common/src/main/java/dev/mrsnowy/teleport_commands/common/Player.java +++ b/common/src/main/java/dev/mrsnowy/teleport_commands/common/Player.java @@ -47,7 +47,7 @@ public class Player { StorageManager.StorageSaver(); } - // todo! modify this so it uses a NamedLocation as an input + // todo! modify this so it uses a NamedLocation // creates a new home, if there already is a home it will update the existing one public void setHome(String name, BlockPos pos, String world) throws Exception { Optional optionalHome = getHome(name); diff --git a/common/src/main/java/dev/mrsnowy/teleport_commands/storage/StorageManager.java b/common/src/main/java/dev/mrsnowy/teleport_commands/storage/StorageManager.java index 77d2a1a..d8d8714 100644 --- a/common/src/main/java/dev/mrsnowy/teleport_commands/storage/StorageManager.java +++ b/common/src/main/java/dev/mrsnowy/teleport_commands/storage/StorageManager.java @@ -83,6 +83,7 @@ public class StorageManager { // ----- + // todo! modify this so it uses a NamedLocation as an input // creates a new warp, if there already is a warp it will update the existing one public void setWarp(String name, BlockPos pos, String world) throws Exception { Optional OptionalWarp = getWarp(name); diff --git a/common/src/main/resources/assets/teleport_commands/lang/en_us.json b/common/src/main/resources/assets/teleport_commands/lang/en_us.json index a155d73..a4afc6b 100644 --- a/common/src/main/resources/assets/teleport_commands/lang/en_us.json +++ b/common/src/main/resources/assets/teleport_commands/lang/en_us.json @@ -15,6 +15,7 @@ "commands.teleport_commands.home.rename": "Home Renamed", "commands.teleport_commands.home.renameError": "Error Renaming Home!", "commands.teleport_commands.home.default": "Default Home Set", + "commands.teleport_commands.home.defaultNone": "No default home set!", "commands.teleport_commands.home.defaultError": "Error Changing Default Home!", "commands.teleport_commands.home.defaultSame": "Home is already set as default!", "commands.teleport_commands.home.notFound": "Home Not Found!", diff --git a/common/src/main/resources/assets/teleport_commands/lang/hu_hu.json b/common/src/main/resources/assets/teleport_commands/lang/hu_hu.json index 82b4721..e65223b 100644 --- a/common/src/main/resources/assets/teleport_commands/lang/hu_hu.json +++ b/common/src/main/resources/assets/teleport_commands/lang/hu_hu.json @@ -15,6 +15,7 @@ "commands.teleport_commands.home.rename": "Otthon átnevezve", "commands.teleport_commands.home.renameError": "Hiba történt az otthon átnevezésével!", "commands.teleport_commands.home.default": "Alap otthon beállítva", + "commands.teleport_commands.home.defaultNone": "No default home set!", "commands.teleport_commands.home.defaultError": "Hiba történt az alap otthon beállításával!", "commands.teleport_commands.home.defaultSame": "Már alap ez az otthon!", "commands.teleport_commands.home.notFound": "Otthon nem találva!", diff --git a/common/src/main/resources/assets/teleport_commands/lang/it_it.json b/common/src/main/resources/assets/teleport_commands/lang/it_it.json index 79711b4..83df551 100644 --- a/common/src/main/resources/assets/teleport_commands/lang/it_it.json +++ b/common/src/main/resources/assets/teleport_commands/lang/it_it.json @@ -15,6 +15,7 @@ "commands.teleport_commands.home.rename": "Casa Rinominata", "commands.teleport_commands.home.renameError": "Errore Durante La Rinomina Della Casa!", "commands.teleport_commands.home.default": "Casa Predefinita Impostata", + "commands.teleport_commands.home.defaultNone": "No default home set!", "commands.teleport_commands.home.defaultError": "Errore Durante Il Cambio Della Casa Predefinita!", "commands.teleport_commands.home.defaultSame": "La Casa È Già Impostata Come Predefinita!", "commands.teleport_commands.home.notFound": "Casa Non Trovata!", diff --git a/common/src/main/resources/assets/teleport_commands/lang/nl_nl.json b/common/src/main/resources/assets/teleport_commands/lang/nl_nl.json index 36f8644..5206eaa 100644 --- a/common/src/main/resources/assets/teleport_commands/lang/nl_nl.json +++ b/common/src/main/resources/assets/teleport_commands/lang/nl_nl.json @@ -15,6 +15,7 @@ "commands.teleport_commands.home.rename": "Huis Hernoemd", "commands.teleport_commands.home.renameError": "Probleem tijdens het wijzigen van de huis naam!", "commands.teleport_commands.home.default": "Standaard Huis Ingesteld", + "commands.teleport_commands.home.defaultNone": "Geen standaard huis ingesteld!", "commands.teleport_commands.home.defaultError": "Probleem Tijdens Het Wijzigen Van Het Standaard Huis!", "commands.teleport_commands.home.defaultSame": "Huis is al als standaard ingesteld!", "commands.teleport_commands.home.notFound": "Huis Niet Gevonden!", diff --git a/common/src/main/resources/assets/teleport_commands/lang/ru_ru.json b/common/src/main/resources/assets/teleport_commands/lang/ru_ru.json index 1db1eda..d2b6393 100644 --- a/common/src/main/resources/assets/teleport_commands/lang/ru_ru.json +++ b/common/src/main/resources/assets/teleport_commands/lang/ru_ru.json @@ -15,6 +15,7 @@ "commands.teleport_commands.home.rename": "Дом переименован", "commands.teleport_commands.home.renameError": "Ошибка переименования дома!", "commands.teleport_commands.home.default": "Дом по умолчанию установлен", + "commands.teleport_commands.home.defaultNone": "No default home set!", "commands.teleport_commands.home.defaultError": "Ошибка изменения дома по умолчанию!", "commands.teleport_commands.home.defaultSame": "Дом уже установлен по умолчанию!", "commands.teleport_commands.home.notFound": "Дом не найден!", diff --git a/common/src/main/resources/assets/teleport_commands/lang/zh_cn.json b/common/src/main/resources/assets/teleport_commands/lang/zh_cn.json index 4e52ab2..aad55d2 100644 --- a/common/src/main/resources/assets/teleport_commands/lang/zh_cn.json +++ b/common/src/main/resources/assets/teleport_commands/lang/zh_cn.json @@ -15,6 +15,7 @@ "commands.teleport_commands.home.rename": "家已重命名", "commands.teleport_commands.home.renameError": "重命名家时发生错误!", "commands.teleport_commands.home.default": "默认的家设置", + "commands.teleport_commands.home.defaultNone": "No default home set!", "commands.teleport_commands.home.defaultError": "变更默认家时发生错误!", "commands.teleport_commands.home.defaultSame": "家已经设定为默认了!", "commands.teleport_commands.home.notFound": "没有找到家!", diff --git a/common/src/main/resources/assets/teleport_commands/lang/zh_tw.json b/common/src/main/resources/assets/teleport_commands/lang/zh_tw.json index 58531e4..bda4cb0 100644 --- a/common/src/main/resources/assets/teleport_commands/lang/zh_tw.json +++ b/common/src/main/resources/assets/teleport_commands/lang/zh_tw.json @@ -15,6 +15,7 @@ "commands.teleport_commands.home.rename": "家已重命名", "commands.teleport_commands.home.renameError": "重命名家時發生錯誤!", "commands.teleport_commands.home.default": "默認的家設置", + "commands.teleport_commands.home.defaultNone": "No default home set!", "commands.teleport_commands.home.defaultError": "變更默認家時發生錯誤!", "commands.teleport_commands.home.defaultSame": "家已經設定為默認了!", "commands.teleport_commands.home.notFound": "沒有找到家!", -- 2.51.2