A Minecraft server-side mod that adds various teleportation related commands
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Still rewriting, it compiles now tho! PLEASE DON'T USE!

+309 -256
+1
.gitignore
··· 3 3 build/ 4 4 out/ 5 5 classes/ 6 + bin/ 6 7 7 8 # idea 8 9 out
+2 -1
CHANGELOG.md
··· 12 12 - Improved the Storage classes and functions (I'm doing proper java, yipie) 13 13 - Better error handling for command suggestions 14 14 - Added hover effects for warp and homes text (W.I.P) 15 - - Throw an exception when the world isn't found (when doing back or home), instead of giving an incorrect notFound error. 15 + - Throw an exception when the world isn't found (when going back or home), instead of giving an incorrect notFound error. 16 + - Added a new `home.defaultNone` translation key for when there is no default house set. (before this would give `home.homeless` for some reason) 16 17 17 18 ### [v1.2.2] 18 19 - Handled a case where the client (geyser) will return the language as uppercase instead of lowercase.
+160 -108
common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java
··· 1 1 package dev.mrsnowy.teleport_commands.commands; 2 2 3 3 import com.mojang.brigadier.arguments.StringArgumentType; 4 - import com.mojang.datafixers.util.Pair; 5 4 import dev.mrsnowy.teleport_commands.TeleportCommands; 6 5 import dev.mrsnowy.teleport_commands.storage.StorageManager; 7 6 import dev.mrsnowy.teleport_commands.common.NamedLocation; 8 7 import dev.mrsnowy.teleport_commands.common.Player; 9 8 import dev.mrsnowy.teleport_commands.suggestions.HomeSuggestionProvider; 10 9 11 - import java.util.Locale; 12 - import java.util.Objects; 10 + import java.util.ArrayList; 13 11 import java.util.Optional; 14 12 15 13 import net.minecraft.ChatFormatting; ··· 162 160 private static void SetHome(ServerPlayer player, String homeName) throws Exception { 163 161 homeName = homeName.toLowerCase(); 164 162 BlockPos blockPos = player.blockPosition(); 165 - ServerLevel world = player.serverLevel(); 163 + String worldString = player.serverLevel().dimension().location().toString(); 166 164 167 165 // Gets player storage and makes it if it doesn't exist 168 166 Player playerStorage = StorageManager.STORAGE.addPlayer(player.getStringUUID()); ··· 174 172 } 175 173 176 174 // Create a new NamedLocation 177 - playerStorage.setHome(homeName, blockPos, world.dimension().location().toString()); 175 + playerStorage.setHome(homeName, blockPos, worldString); 178 176 179 177 // Set it as the default if there are no other homes 180 178 if (playerStorage.getHomes().size() == 1) { ··· 189 187 private static void GoHome(ServerPlayer player, String homeName) throws Exception { 190 188 homeName = homeName.toLowerCase(); 191 189 192 - // Gets player storage 190 + // Get player storage 193 191 Optional<Player> optionalPlayerStorage = STORAGE.getPlayer(player.getStringUUID()); 194 192 if (optionalPlayerStorage.isEmpty()) { 195 193 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); ··· 198 196 199 197 Player playerStorage = optionalPlayerStorage.get(); 200 198 201 - // if homeName is empty, get the default home 199 + // If homeName is empty, get the default home 202 200 if (homeName.isEmpty()) { 203 - // todo! if there is no default home set, maybe give an message saying: no default home set! 204 201 String defaultHome = playerStorage.getDefaultHome(); 205 202 206 203 if (defaultHome.isEmpty()) { 207 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); 204 + // todo! test if this translation key works correctly! 205 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.defaultNone", player).withStyle(ChatFormatting.AQUA), true); 208 206 return; 209 207 } else { 210 208 homeName = defaultHome; 211 209 } 212 210 } 213 211 214 - // get the home (if it exists) 212 + // Get the home (if it exists) 215 213 Optional<NamedLocation> optionalHome = playerStorage.getHome(homeName); 216 214 if (optionalHome.isEmpty()) { 217 215 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.AQUA), true); ··· 220 218 221 219 NamedLocation home = optionalHome.get(); 222 220 223 - // get the world, otherwise throw an exception 224 - Optional<ServerLevel> optionalHomeWorld = home.getWorld(); 225 - if (optionalHomeWorld.isEmpty()) { 221 + // Get the world, otherwise throw an exception 222 + ServerLevel homeWorld = home.getWorld().orElseThrow(() -> { 226 223 // todo! test this exception 227 - 228 - throw new Exception( String.format("Couldn't find a world with the id: %s \nAvailable worlds: %s", 224 + return new Exception( String.format("Couldn't find a world with the id: %s \nAvailable worlds: %s", 229 225 home.getWorldString(), TeleportCommands.SERVER.getAllLevels())); 230 - } 226 + }); 231 227 232 - ServerLevel homeWorld = optionalHomeWorld.get(); 233 228 BlockPos teleportBlockPos = home.getBlockPos(); 234 229 235 - // check if the player is already at this location (in the same world) 230 + // Check if the player is already at this location (in the same world) 236 231 if (player.blockPosition().equals(teleportBlockPos) && player.level() == homeWorld) { 237 232 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.goSame", player).withStyle(ChatFormatting.AQUA), true); 238 233 239 234 } else { 240 - // teleport the player! 235 + // Teleport the player! 241 236 Vec3 teleportPos = new Vec3(teleportBlockPos.getX() + 0.5, teleportBlockPos.getY(), teleportBlockPos.getZ() + 0.5); 242 237 243 238 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.go", player), true); ··· 264 259 return; 265 260 } 266 261 267 - NamedLocation home = optionalHome.get(); 262 + // delete the home 263 + playerStorage.deleteHome(optionalHome.get()); 268 264 269 265 // check if it's the default home, if it is set it to the default value 270 266 if (playerStorage.getDefaultHome().equals(homeName)) { 271 267 playerStorage.setDefaultHome(""); 268 + 269 + // todo! maybe ask the player if they want to set a new default home? :3 272 270 } 273 271 274 - // delete the home 275 - playerStorage.deleteHome(home); 276 272 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.delete", player), true); 277 273 } 278 274 ··· 280 276 homeName = homeName.toLowerCase(); 281 277 newHomeName = newHomeName.toLowerCase(); 282 278 283 - Pair<StorageManager.StorageClass, StorageManager.StorageClass.Player> storages = GetPlayerStorage(player.getStringUUID()); 284 - StorageManager.StorageClass storage = storages.getFirst(); 285 - StorageManager.StorageClass.Player playerStorage = storages.getSecond(); 286 - 287 - boolean newNameNotFound = true; 288 - boolean WarpRenamed = false; 289 - 290 - // check for duplicates 291 - for (StorageManager.StorageClass.NamedLocation currentHome : playerStorage.Homes) { 292 - if (Objects.equals(currentHome.name, newHomeName)) { 293 - newNameNotFound = false; 294 - break; 295 - } 279 + // Gets player storage 280 + Optional<Player> optionalPlayerStorage = STORAGE.getPlayer(player.getStringUUID()); 281 + if (optionalPlayerStorage.isEmpty()) { 282 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); 283 + return; 296 284 } 297 285 298 - if (newNameNotFound) { 299 - // get correct home 300 - for (StorageManager.StorageClass.NamedLocation currentHome : playerStorage.Homes) { 301 - if (Objects.equals(currentHome.name, homeName)) { 286 + Player playerStorage = optionalPlayerStorage.get(); 302 287 303 - // if the current home is the default home, then change to the new name in the config 304 - if (Objects.equals(playerStorage.DefaultHome, currentHome.name)) { 305 - playerStorage.DefaultHome = newHomeName; 306 - } 288 + // Check if there already is a home with the new name 289 + playerStorage.getHome("newHomeName").ifPresent(name -> { 290 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.renameExists", player).withStyle(ChatFormatting.RED), true); 291 + return; 292 + // todo! does this exit correctly? 293 + }); 307 294 308 - currentHome.name = newHomeName; 309 - StorageSaver(); 295 + // Get the home that needs to be renamed 296 + Optional<NamedLocation> optionalHome = playerStorage.getHome(homeName); 297 + if (optionalHome.isEmpty()) { 298 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.RED), true); 299 + return; 300 + } 310 301 311 - WarpRenamed = true; 312 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.rename", player), true); 313 - break; 314 - } 315 - } 302 + // Rename home 303 + optionalHome.get().setName(newHomeName); 316 304 317 - if (!WarpRenamed) { 318 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.RED), true); 319 - } 320 - } else { 321 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.renameExists", player).withStyle(ChatFormatting.RED), true); 305 + // check if the current home is the default, then change it to the new name 306 + if (playerStorage.getDefaultHome().equals(homeName)) { 307 + playerStorage.setDefaultHome(newHomeName); 322 308 } 323 309 310 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.rename", player), true); 324 311 } 325 312 326 313 private static void SetDefaultHome(ServerPlayer player, String homeName) throws Exception { 327 314 homeName = homeName.toLowerCase(); 328 315 329 - Pair<StorageManager.StorageClass, StorageManager.StorageClass.Player> storages = GetPlayerStorage(player.getStringUUID()); 330 - StorageManager.StorageClass storage = storages.getFirst(); 331 - StorageManager.StorageClass.Player playerStorage = storages.getSecond(); 332 - 333 - boolean homeExists = false; 334 - 335 - // check if home exists 336 - for (StorageManager.StorageClass.NamedLocation currentHome : playerStorage.Homes) { 337 - if (Objects.equals(currentHome.name, homeName)){ 338 - homeExists = true; 339 - break; 340 - } 316 + // Gets player storage 317 + Optional<Player> optionalPlayerStorage = STORAGE.getPlayer(player.getStringUUID()); 318 + if (optionalPlayerStorage.isEmpty()) { 319 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); 320 + return; 341 321 } 342 322 343 - if (homeExists) { 344 - if (!Objects.equals(playerStorage.DefaultHome, homeName)) { 323 + Player playerStorage = optionalPlayerStorage.get(); 345 324 346 - playerStorage.DefaultHome = homeName; 347 - StorageSaver(); 348 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.default", player), true); 349 - 350 - } else { 351 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.defaultSame", player).withStyle(ChatFormatting.AQUA), true); 352 - } 353 - 354 - } else { 325 + // Check if the new default home exists 326 + if ( playerStorage.getHome(homeName).isEmpty() ) { 355 327 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.RED), true); 328 + return; 356 329 } 330 + 331 + // Check if the home is already the default 332 + if (playerStorage.getDefaultHome().equals(homeName)) { 333 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.defaultSame", player).withStyle(ChatFormatting.AQUA), true); 334 + return; 335 + } 336 + 337 + // set the new default 338 + playerStorage.setDefaultHome(homeName); 339 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.default", player), true); 357 340 } 358 341 359 342 private static void PrintHomes(ServerPlayer player) throws Exception { 360 - StorageManager.StorageClass.Player playerStorage = GetPlayerStorage(player.getStringUUID()).getSecond(); 361 343 362 - if (playerStorage.Homes.isEmpty()) { 344 + // Gets player storage 345 + Optional<Player> optionalPlayerStorage = STORAGE.getPlayer(player.getStringUUID()); 346 + if (optionalPlayerStorage.isEmpty()) { 363 347 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); 348 + return; 349 + } 364 350 365 - } else { 366 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.homes.homes", player).withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD) 367 - .append("\n"), false); 351 + Player playerStorage = optionalPlayerStorage.get(); 368 352 369 - for (StorageManager.StorageClass.NamedLocation currentHome : playerStorage.Homes) { 353 + ArrayList<NamedLocation> homes = playerStorage.getHomes(); 370 354 371 - String name = String.format(" - %s", currentHome.name); 372 - String coords = String.format("[X%d Y%d Z%d]", currentHome.x, currentHome.y, currentHome.z); 373 - String dimension = String.format(" [%s]", currentHome.world); 355 + // Check if there are any homes lol 356 + if (homes.isEmpty()) { 357 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); 358 + return; 359 + } 360 + 361 + // Print the stuffz 374 362 375 - if (Objects.equals(currentHome.name, playerStorage.DefaultHome)) { 376 - player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA) 377 - .append(" ") 378 - .append(getTranslatedText("commands.teleport_commands.common.default", player).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD)), 379 - false 380 - ); 381 - } else { 382 - player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA), false); 383 - } 363 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.homes.homes", player).withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD) 364 + .append("\n"), false); 384 365 366 + // todo! Make it send it all at once? 367 + for (NamedLocation currentHome : homes) { 385 368 386 - player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) 387 - .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))))) 388 - .append(Component.literal(dimension).withStyle(ChatFormatting.DARK_PURPLE).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, currentHome.world)))), 389 - false 390 - ); 369 + String name = String.format(" - %s", currentHome.getName()); 370 + String coords = String.format("[X%d Y%d Z%d]", currentHome.getX(), currentHome.getY(), currentHome.getZ()); 371 + String dimension = String.format(" [%s]", currentHome.getWorldString()); 391 372 392 - player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) 393 - .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))))) 394 - .append(" ") 395 - .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))))) 373 + // Check if the home is the default home, then add text showcasing that it is 374 + if (playerStorage.getDefaultHome().equals(currentHome.getName())) { 375 + player.displayClientMessage(Component.literal(name) 376 + .withStyle(ChatFormatting.AQUA) 396 377 .append(" ") 397 - .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))))) 398 - .append("\n"), 378 + .append(getTranslatedText("commands.teleport_commands.common.default", player) 379 + .withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD) 380 + ), 399 381 false 400 382 ); 383 + } else { 384 + player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA), false); 401 385 } 402 386 387 + // Cords and dimension 388 + player.displayClientMessage(Component.literal(" | ") 389 + .withStyle(ChatFormatting.AQUA) 390 + .append(Component.literal(coords) 391 + .withStyle(ChatFormatting.LIGHT_PURPLE) 392 + .withStyle(style -> 393 + style.withClickEvent( 394 + new ClickEvent( 395 + ClickEvent.Action.COPY_TO_CLIPBOARD, 396 + String.format("X%d Y%d Z%d", currentHome.getX(), currentHome.getY(), currentHome.getZ()) 397 + ) 398 + ) 399 + ) 400 + ) 401 + .append(Component.literal(dimension) 402 + .withStyle(ChatFormatting.DARK_PURPLE) 403 + .withStyle(style -> 404 + style.withClickEvent( 405 + new ClickEvent( 406 + ClickEvent.Action.COPY_TO_CLIPBOARD, 407 + currentHome.getWorldString() 408 + ) 409 + ) 410 + ) 411 + ), 412 + false 413 + ); 414 + 415 + // Teleport, rename and delete buttons 416 + player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) 417 + .append(getTranslatedText("commands.teleport_commands.common.tp", player) 418 + .withStyle(ChatFormatting.GREEN) 419 + .withStyle(style -> 420 + style.withClickEvent( 421 + new ClickEvent( 422 + ClickEvent.Action.RUN_COMMAND, 423 + String.format("/home %s", currentHome.getName()) 424 + ) 425 + ) 426 + ) 427 + ) 428 + .append(" ") 429 + .append(getTranslatedText("commands.teleport_commands.common.rename", player) 430 + .withStyle(ChatFormatting.BLUE) 431 + .withStyle(style -> 432 + style.withClickEvent( 433 + new ClickEvent( 434 + ClickEvent.Action.SUGGEST_COMMAND, 435 + String.format("/renamehome %s ", currentHome.getName()) 436 + ) 437 + ) 438 + ) 439 + ) 440 + .append(" ") 441 + .append(getTranslatedText("commands.teleport_commands.common.delete", player) 442 + .withStyle(ChatFormatting.RED) 443 + .withStyle(style -> 444 + style.withClickEvent( 445 + new ClickEvent( 446 + ClickEvent.Action.SUGGEST_COMMAND, 447 + String.format("/delhome %s", currentHome.getName()) 448 + ) 449 + ) 450 + ) 451 + ) 452 + .append("\n"), 453 + false 454 + ); 403 455 } 404 - } 405 456 457 + } 406 458 }
-2
common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java
··· 31 31 this.here = here; 32 32 tpaList.add(this); 33 33 } 34 - 35 - 36 34 } 37 35 38 36 public static void register(Commands commandManager) {
+137 -144
common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java
··· 1 1 package dev.mrsnowy.teleport_commands.commands; 2 2 3 3 import com.mojang.brigadier.arguments.StringArgumentType; 4 - import com.mojang.datafixers.util.Pair; 5 4 import dev.mrsnowy.teleport_commands.TeleportCommands; 6 5 import dev.mrsnowy.teleport_commands.common.NamedLocation; 7 6 import dev.mrsnowy.teleport_commands.suggestions.WarpSuggestionProvider; ··· 16 15 import net.minecraft.world.phys.Vec3; 17 16 18 17 import java.util.ArrayList; 19 - import java.util.List; 20 - import java.util.Objects; 21 18 import java.util.Optional; 22 19 23 20 import static dev.mrsnowy.teleport_commands.storage.StorageManager.*; ··· 133 130 warpName = warpName.toLowerCase(); 134 131 135 132 BlockPos blockPos = new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()); 136 - ServerLevel world = player.serverLevel(); 133 + String worldString = player.serverLevel().dimension().location().toString(); 137 134 138 - Pair<StorageClass, List<StorageClass.NamedLocation>> storages = getWarpStorage(); 139 - StorageClass storage = storages.getFirst(); 140 - List<StorageClass.NamedLocation> WarpStorage = storages.getSecond(); 141 - 142 - boolean warpNotFound = true; 143 - 144 - // check for duplicates 145 - for (StorageClass.NamedLocation currentWarp : WarpStorage) { 146 - if (Objects.equals(currentWarp.name, warpName)) { 147 - warpNotFound = false; 148 - break; 149 - } 135 + // Check if warp already exists 136 + if ( STORAGE.getWarp(warpName).isEmpty() ) { 137 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.exists", player).withStyle(ChatFormatting.RED), true); 138 + return; 150 139 } 151 140 152 - if (warpNotFound) { 153 - // Create a new NamedLocation 154 - StorageClass.NamedLocation warpData = new StorageClass.NamedLocation(warpName, blockPos, world.dimension().location().toString()); 155 - storage.Warps.add(warpData); 141 + // Create the warp 142 + STORAGE.setWarp(warpName, blockPos, worldString); 156 143 157 - StorageSaver(); 158 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.set", player), true); 159 - } else { 160 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.exists", player).withStyle(ChatFormatting.RED), true); 161 - } 144 + // Display message that the home as been set 145 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.set", player), true); 162 146 } 163 147 164 148 private static void GoToWarp(ServerPlayer player, String warpName) throws Exception { 165 149 warpName = warpName.toLowerCase(); 166 - List<NamedLocation> WarpStorage = getWarpStorage().getSecond(); 167 150 168 - boolean foundWorld = false; 151 + // Gets warp 152 + Optional<NamedLocation> optionalWarp = STORAGE.getWarp(warpName); 153 + if (optionalWarp.isEmpty()) { 154 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.notFound", player).withStyle(ChatFormatting.RED), true); 155 + return; 156 + } 169 157 170 - // find correct warp 171 - for (NamedLocation currentWarp : WarpStorage) { 172 - if (Objects.equals(currentWarp.name, warpName)) { 158 + NamedLocation warp = optionalWarp.get(); 173 159 174 - // find correct world 175 - for (ServerLevel currentWorld : TeleportCommands.SERVER.getAllLevels()) { 176 - if (Objects.equals(currentWorld.dimension().location().toString(), currentWarp.world)) { 177 - foundWorld = true; 160 + // Get the world, otherwise throw an exception 161 + ServerLevel warpWorld = warp.getWorld().orElseThrow(() -> { 162 + // todo! test this exception 163 + return new Exception( String.format("Couldn't find a world with the id: %s \nAvailable worlds: %s", 164 + warp.getWorldString(), TeleportCommands.SERVER.getAllLevels())); 165 + }); 178 166 179 - BlockPos coords = new BlockPos(currentWarp.x, currentWarp.y, currentWarp.z); 180 - BlockPos playerBlockPos = new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()); 167 + BlockPos teleportBlockPos = warp.getBlockPos(); 168 + 169 + // Check if the player is already at this location (in the same world) 170 + if (player.blockPosition().equals(teleportBlockPos) && player.level() == warpWorld) { 171 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.goSame", player).withStyle(ChatFormatting.AQUA), true); 181 172 182 - if (!playerBlockPos.equals(coords)) { 183 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.go", player), true); 184 - Teleporter(player, currentWorld, new Vec3(currentWarp.x + 0.5, currentWarp.y, currentWarp.z + 0.5)); 185 - } else { 186 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.goSame", player).withStyle(ChatFormatting.AQUA), true); 187 - } 188 - break; 189 - } 190 - } 191 - } 192 - } 173 + } else { 174 + // Teleport the player! 175 + Vec3 teleportPos = new Vec3(teleportBlockPos.getX() + 0.5, teleportBlockPos.getY(), teleportBlockPos.getZ() + 0.5); 193 176 194 - if (!foundWorld) { 195 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.notFound", player).withStyle(ChatFormatting.RED), true); 177 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.go", player), true); 178 + Teleporter(player, warpWorld, teleportPos); 196 179 } 197 180 } 198 181 199 182 private static void DeleteWarp(ServerPlayer player, String warpName) throws Exception { 200 183 warpName = warpName.toLowerCase(); 201 184 185 + // todo! maybe replace with ifPresentOrElse 202 186 // get the existing warp 203 187 Optional<NamedLocation> optionalWarp = STORAGE.getWarp(warpName); 204 188 205 189 if (optionalWarp.isPresent()) { 190 + // Delete the warp 206 191 STORAGE.rmWarp(optionalWarp.get()); 192 + 193 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.delete", player), true); 207 194 208 195 } else { 209 196 // the warp is not found 210 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.notFound", player) 211 - .withStyle(ChatFormatting.RED), true); 197 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.notFound", player).withStyle(ChatFormatting.RED), true); 212 198 } 213 199 } 214 200 ··· 216 202 warpName = warpName.toLowerCase(); 217 203 newWarpName = newWarpName.toLowerCase(); 218 204 205 + // check if there is no existing warp with the new name 206 + if (STORAGE.getWarp(newWarpName).isPresent()) { 207 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.renameExists", player).withStyle(ChatFormatting.RED), true); 208 + return; 209 + } 210 + 219 211 // get the existing warp 220 - Optional<NamedLocation> warp = STORAGE.getWarp(warpName); 212 + Optional<NamedLocation> warpToRename = STORAGE.getWarp(warpName); 221 213 222 - if (warp.isPresent()) { 223 - NamedLocation homeToRename = warp.get(); 224 - 225 - // check if there is no existing warp with the new name 226 - if (STORAGE.getWarp(newWarpName).isEmpty()) { 227 - 228 - // set the new name 229 - homeToRename.setName(newWarpName); 230 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.rename", player), true); 231 - } else { 214 + if (warpToRename.isPresent()) { 232 215 233 - // there is already a warp with the new name 234 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.renameExists", player).withStyle(ChatFormatting.RED), true); 235 - } 216 + // set the new name 217 + warpToRename.get().setName(newWarpName); 218 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.rename", player), true); 236 219 237 220 } else { 238 221 // the warp is not found 239 222 player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.notFound", player).withStyle(ChatFormatting.RED), true); 240 223 } 241 - 242 224 } 243 225 244 226 private static void PrintWarps(ServerPlayer player) throws Exception { 227 + // Get warps 245 228 ArrayList<NamedLocation> warps = STORAGE.getWarps(); 246 229 230 + // Check if there are any warps lol 247 231 if (warps.isEmpty()) { 248 232 player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.homeless", player).withStyle(ChatFormatting.AQUA), true); 233 + return; 234 + } 235 + 236 + // Print the stuffz 249 237 250 - } else { 251 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warps.warps", player).withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD) 252 - .append("\n"), false); 238 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warps.warps", player).withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD) 239 + .append("\n"), false); 253 240 254 - for (NamedLocation currentWarp : warps) { 241 + for (NamedLocation currentWarp : warps) { 255 242 256 - String name = String.format(" - %s", currentWarp.getName()); 257 - String coords = String.format("[X%d Y%d Z%d]", currentWarp.getX(), currentWarp.getY(), currentWarp.getZ()); 258 - String dimension = String.format(" [%s]", currentWarp.getWorldString()); 243 + String name = String.format(" - %s", currentWarp.getName()); 244 + String coords = String.format("[X%d Y%d Z%d]", currentWarp.getX(), currentWarp.getY(), currentWarp.getZ()); 245 + String dimension = String.format(" [%s]", currentWarp.getWorldString()); 259 246 260 - player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA), false); 247 + player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA), false); 261 248 262 - player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) 263 - .append(Component.literal(coords) 264 - .withStyle(ChatFormatting.LIGHT_PURPLE) 265 - .withStyle(style -> style 266 - .withClickEvent(new ClickEvent( 249 + player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) 250 + .append(Component.literal(coords) 251 + .withStyle(ChatFormatting.LIGHT_PURPLE) 252 + .withStyle(style -> 253 + style.withClickEvent( 254 + new ClickEvent( 267 255 ClickEvent.Action.COPY_TO_CLIPBOARD, 268 256 String.format("X%d Y%d Z%d", currentWarp.getX(), currentWarp.getY(), currentWarp.getZ()) 257 + ) 258 + ) 259 + ) 260 + //todo! test the hover 261 + .withStyle(style -> 262 + style.withHoverEvent(new HoverEvent( 263 + HoverEvent.Action.SHOW_TEXT, getTranslatedText("commands.teleport_commands.common.hoverCopy", player) 264 + )) 265 + ) 266 + ) 267 + .append(Component.literal(dimension) 268 + .withStyle(ChatFormatting.DARK_PURPLE) 269 + .withStyle(style -> 270 + style.withClickEvent( 271 + new ClickEvent( 272 + ClickEvent.Action.COPY_TO_CLIPBOARD, 273 + currentWarp.getWorldString() 274 + ) 275 + ) 276 + ) 277 + .withStyle(style -> style 278 + .withHoverEvent( 279 + new HoverEvent( 280 + HoverEvent.Action.SHOW_TEXT, 281 + getTranslatedText("commands.teleport_commands.common.hoverCopy", player) 282 + ) 283 + ) 284 + ) 285 + ), 286 + false 287 + ); 288 + 289 + // todo! maybe make this a boolean at the begging of the function. 290 + if (player.hasPermissions(4)) { 291 + player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) 292 + .append(getTranslatedText("commands.teleport_commands.common.tp", player) 293 + .withStyle(ChatFormatting.GREEN) 294 + .withStyle(style -> 295 + style.withClickEvent(new ClickEvent( 296 + ClickEvent.Action.RUN_COMMAND, 297 + String.format("/warp %s", currentWarp.getName()) 269 298 )) 270 299 ) 271 - //todo! test the hover 300 + ) 301 + .append(" ") 302 + .append(getTranslatedText("commands.teleport_commands.common.rename", player) 303 + .withStyle(ChatFormatting.BLUE) 272 304 .withStyle(style -> style 273 - .withHoverEvent(new HoverEvent( 274 - HoverEvent.Action.SHOW_TEXT, getTranslatedText("commands.teleport_commands.common.hoverCopy", player) 275 - )) 305 + .withClickEvent(new ClickEvent( 306 + ClickEvent.Action.SUGGEST_COMMAND, 307 + String.format("/renamewarp %s ", currentWarp.getName())) 308 + ) 276 309 ) 277 310 ) 278 - .append(Component.literal(dimension) 279 - .withStyle(ChatFormatting.DARK_PURPLE) 311 + .append(" ") 312 + .append(getTranslatedText("commands.teleport_commands.common.delete", player) 313 + .withStyle(ChatFormatting.RED) 280 314 .withStyle(style -> style 281 315 .withClickEvent(new ClickEvent( 282 - ClickEvent.Action.COPY_TO_CLIPBOARD, 283 - currentWarp.getWorldString() 284 - )) 316 + ClickEvent.Action.SUGGEST_COMMAND, 317 + String.format("/delwarp %s", currentWarp.getName())) 318 + ) 285 319 ) 320 + ) 321 + .append("\n"), 322 + false 323 + ); 324 + } else { 325 + player.displayClientMessage(Component.literal(" | ") 326 + .withStyle(ChatFormatting.AQUA) 327 + .append(getTranslatedText("commands.teleport_commands.common.tp", player) 328 + .withStyle(ChatFormatting.GREEN) 286 329 .withStyle(style -> style 287 - .withHoverEvent(new HoverEvent( 288 - HoverEvent.Action.SHOW_TEXT, getTranslatedText("commands.teleport_commands.common.hoverCopy", player) 289 - )) 330 + .withClickEvent(new ClickEvent( 331 + ClickEvent.Action.RUN_COMMAND, 332 + String.format("/warp %s", currentWarp.getName())) 333 + ) 290 334 ) 291 - ), 335 + ) 336 + .append("\n"), 292 337 false 293 338 ); 294 - 295 - if (player.hasPermissions(4)) { 296 - player.displayClientMessage(Component.literal(" | ").withStyle(ChatFormatting.AQUA) 297 - .append(getTranslatedText("commands.teleport_commands.common.tp", player) 298 - .withStyle(ChatFormatting.GREEN) 299 - .withStyle(style -> style 300 - .withClickEvent(new ClickEvent( 301 - ClickEvent.Action.RUN_COMMAND, 302 - String.format("/warp %s", currentWarp.getName()) 303 - )) 304 - ) 305 - ) 306 - .append(" ") 307 - .append(getTranslatedText("commands.teleport_commands.common.rename", player) 308 - .withStyle(ChatFormatting.BLUE) 309 - .withStyle(style -> style 310 - .withClickEvent(new ClickEvent( 311 - ClickEvent.Action.SUGGEST_COMMAND, 312 - String.format("/renamewarp %s ", currentWarp.getName())) 313 - ) 314 - ) 315 - ) 316 - .append(" ") 317 - .append(getTranslatedText("commands.teleport_commands.common.delete", player) 318 - .withStyle(ChatFormatting.RED) 319 - .withStyle(style -> style 320 - .withClickEvent(new ClickEvent( 321 - ClickEvent.Action.SUGGEST_COMMAND, 322 - String.format("/delwarp %s", currentWarp.getName())) 323 - ) 324 - ) 325 - ) 326 - .append("\n"), 327 - false 328 - ); 329 - } else { 330 - player.displayClientMessage(Component.literal(" | ") 331 - .withStyle(ChatFormatting.AQUA) 332 - .append(getTranslatedText("commands.teleport_commands.common.tp", player) 333 - .withStyle(ChatFormatting.GREEN) 334 - .withStyle(style -> style 335 - .withClickEvent(new ClickEvent( 336 - ClickEvent.Action.RUN_COMMAND, 337 - String.format("/warp %s", currentWarp.getName())) 338 - ) 339 - ) 340 - ) 341 - .append("\n"), 342 - false 343 - ); 344 - } 345 339 } 346 - 347 340 } 348 341 } 349 342 }
+1 -1
common/src/main/java/dev/mrsnowy/teleport_commands/common/Player.java
··· 47 47 StorageManager.StorageSaver(); 48 48 } 49 49 50 - // todo! modify this so it uses a NamedLocation as an input 50 + // todo! modify this so it uses a NamedLocation 51 51 // creates a new home, if there already is a home it will update the existing one 52 52 public void setHome(String name, BlockPos pos, String world) throws Exception { 53 53 Optional<NamedLocation> optionalHome = getHome(name);
+1
common/src/main/java/dev/mrsnowy/teleport_commands/storage/StorageManager.java
··· 83 83 84 84 // ----- 85 85 86 + // todo! modify this so it uses a NamedLocation as an input 86 87 // creates a new warp, if there already is a warp it will update the existing one 87 88 public void setWarp(String name, BlockPos pos, String world) throws Exception { 88 89 Optional<NamedLocation> OptionalWarp = getWarp(name);
+1
common/src/main/resources/assets/teleport_commands/lang/en_us.json
··· 15 15 "commands.teleport_commands.home.rename": "Home Renamed", 16 16 "commands.teleport_commands.home.renameError": "Error Renaming Home!", 17 17 "commands.teleport_commands.home.default": "Default Home Set", 18 + "commands.teleport_commands.home.defaultNone": "No default home set!", 18 19 "commands.teleport_commands.home.defaultError": "Error Changing Default Home!", 19 20 "commands.teleport_commands.home.defaultSame": "Home is already set as default!", 20 21 "commands.teleport_commands.home.notFound": "Home Not Found!",
+1
common/src/main/resources/assets/teleport_commands/lang/hu_hu.json
··· 15 15 "commands.teleport_commands.home.rename": "Otthon átnevezve", 16 16 "commands.teleport_commands.home.renameError": "Hiba történt az otthon átnevezésével!", 17 17 "commands.teleport_commands.home.default": "Alap otthon beállítva", 18 + "commands.teleport_commands.home.defaultNone": "No default home set!", 18 19 "commands.teleport_commands.home.defaultError": "Hiba történt az alap otthon beállításával!", 19 20 "commands.teleport_commands.home.defaultSame": "Már alap ez az otthon!", 20 21 "commands.teleport_commands.home.notFound": "Otthon nem találva!",
+1
common/src/main/resources/assets/teleport_commands/lang/it_it.json
··· 15 15 "commands.teleport_commands.home.rename": "Casa Rinominata", 16 16 "commands.teleport_commands.home.renameError": "Errore Durante La Rinomina Della Casa!", 17 17 "commands.teleport_commands.home.default": "Casa Predefinita Impostata", 18 + "commands.teleport_commands.home.defaultNone": "No default home set!", 18 19 "commands.teleport_commands.home.defaultError": "Errore Durante Il Cambio Della Casa Predefinita!", 19 20 "commands.teleport_commands.home.defaultSame": "La Casa È Già Impostata Come Predefinita!", 20 21 "commands.teleport_commands.home.notFound": "Casa Non Trovata!",
+1
common/src/main/resources/assets/teleport_commands/lang/nl_nl.json
··· 15 15 "commands.teleport_commands.home.rename": "Huis Hernoemd", 16 16 "commands.teleport_commands.home.renameError": "Probleem tijdens het wijzigen van de huis naam!", 17 17 "commands.teleport_commands.home.default": "Standaard Huis Ingesteld", 18 + "commands.teleport_commands.home.defaultNone": "Geen standaard huis ingesteld!", 18 19 "commands.teleport_commands.home.defaultError": "Probleem Tijdens Het Wijzigen Van Het Standaard Huis!", 19 20 "commands.teleport_commands.home.defaultSame": "Huis is al als standaard ingesteld!", 20 21 "commands.teleport_commands.home.notFound": "Huis Niet Gevonden!",
+1
common/src/main/resources/assets/teleport_commands/lang/ru_ru.json
··· 15 15 "commands.teleport_commands.home.rename": "Дом переименован", 16 16 "commands.teleport_commands.home.renameError": "Ошибка переименования дома!", 17 17 "commands.teleport_commands.home.default": "Дом по умолчанию установлен", 18 + "commands.teleport_commands.home.defaultNone": "No default home set!", 18 19 "commands.teleport_commands.home.defaultError": "Ошибка изменения дома по умолчанию!", 19 20 "commands.teleport_commands.home.defaultSame": "Дом уже установлен по умолчанию!", 20 21 "commands.teleport_commands.home.notFound": "Дом не найден!",
+1
common/src/main/resources/assets/teleport_commands/lang/zh_cn.json
··· 15 15 "commands.teleport_commands.home.rename": "家已重命名", 16 16 "commands.teleport_commands.home.renameError": "重命名家时发生错误!", 17 17 "commands.teleport_commands.home.default": "默认的家设置", 18 + "commands.teleport_commands.home.defaultNone": "No default home set!", 18 19 "commands.teleport_commands.home.defaultError": "变更默认家时发生错误!", 19 20 "commands.teleport_commands.home.defaultSame": "家已经设定为默认了!", 20 21 "commands.teleport_commands.home.notFound": "没有找到家!",
+1
common/src/main/resources/assets/teleport_commands/lang/zh_tw.json
··· 15 15 "commands.teleport_commands.home.rename": "家已重命名", 16 16 "commands.teleport_commands.home.renameError": "重命名家時發生錯誤!", 17 17 "commands.teleport_commands.home.default": "默認的家設置", 18 + "commands.teleport_commands.home.defaultNone": "No default home set!", 18 19 "commands.teleport_commands.home.defaultError": "變更默認家時發生錯誤!", 19 20 "commands.teleport_commands.home.defaultSame": "家已經設定為默認了!", 20 21 "commands.teleport_commands.home.notFound": "沒有找到家!",