From 8b809b6b5b5a314add6d6882c46d3d80d9996f18 Mon Sep 17 00:00:00 2001 From: William278 Date: Mon, 20 Mar 2023 12:57:52 +0000 Subject: [PATCH] Finish command refactoring --- .../huskhomes/command/BukkitCommand.java | 7 +- .../net/william278/huskhomes/HuskHomes.java | 4 +- .../william278/huskhomes/command/Command.java | 8 +- .../huskhomes/command/InGameCommand.java | 29 ++ .../william278/huskhomes/command/Node.java | 77 +++++ .../huskhomes/command/SetPositionCommand.java | 19 +- .../huskhomes/command/SetSpawnCommand.java | 13 +- .../command/TeleportRequestCommand.java | 57 ++++ .../huskhomes/command/TpAllCommand.java | 50 ++- .../huskhomes/command/TpCommand.java | 303 ++++-------------- .../huskhomes/command/TpHereCommand.java | 62 ++-- .../huskhomes/command/TpIgnoreCommand.java | 37 ++- .../huskhomes/command/TpOfflineCommand.java | 23 +- .../huskhomes/command/TpRespondCommand.java | 39 +-- .../huskhomes/command/TpaAllCommand.java | 55 +--- .../huskhomes/command/TpaCommand.java | 60 ---- .../huskhomes/command/TpaHereCommand.java | 60 ---- .../command/UserListTabProvider.java | 25 ++ .../huskhomes/manager/RequestsManager.java | 26 +- .../william278/huskhomes/network/Message.java | 5 + .../network/PluginMessageBroker.java | 2 - .../huskhomes/network/RedisBroker.java | 8 +- .../huskhomes/teleport/Teleport.java | 3 +- .../huskhomes/teleport/TeleportBuilder.java | 6 +- common/src/main/resources/locales/bg-bg.yml | 2 +- common/src/main/resources/locales/de-de.yml | 4 +- common/src/main/resources/locales/en-gb.yml | 4 +- common/src/main/resources/locales/es-es.yml | 4 +- common/src/main/resources/locales/it-it.yml | 4 +- common/src/main/resources/locales/pl.yml | 4 +- common/src/main/resources/locales/tr-tr.yml | 4 +- common/src/main/resources/locales/uk-ua.yml | 4 +- common/src/main/resources/locales/zh-cn.yml | 4 +- common/src/main/resources/locales/zh-tw.yml | 4 +- 34 files changed, 427 insertions(+), 589 deletions(-) create mode 100644 common/src/main/java/net/william278/huskhomes/command/InGameCommand.java create mode 100644 common/src/main/java/net/william278/huskhomes/command/TeleportRequestCommand.java delete mode 100644 common/src/main/java/net/william278/huskhomes/command/TpaCommand.java delete mode 100644 common/src/main/java/net/william278/huskhomes/command/TpaHereCommand.java create mode 100644 common/src/main/java/net/william278/huskhomes/command/UserListTabProvider.java diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java index 7f5ce13e..ac19b423 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java +++ b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java @@ -2,6 +2,7 @@ package net.william278.huskhomes.command; import me.lucko.commodore.CommodoreProvider; import net.william278.huskhomes.BukkitHuskHomes; +import net.william278.huskhomes.teleport.TeleportRequest; import net.william278.huskhomes.user.BukkitUser; import org.bukkit.command.*; import org.bukkit.entity.Player; @@ -34,7 +35,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String alias, @NotNull String[] args) { - return this.command.suggest(sender instanceof Player player ? BukkitUser.adapt(player) : plugin.getConsole(), args); + return this.command.getSuggestions(sender instanceof Player player ? BukkitUser.adapt(player) : plugin.getConsole(), args); } public void register() { @@ -99,8 +100,8 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { EDIT_WARP_COMMAND(new EditWarpCommand(BukkitHuskHomes.getInstance())), TP_COMMAND(new TpCommand(BukkitHuskHomes.getInstance())), TP_HERE_COMMAND(new TpHereCommand(BukkitHuskHomes.getInstance())), - TPA_COMMAND(new TpaCommand(BukkitHuskHomes.getInstance())), - TPA_HERE_COMMAND(new TpaHereCommand(BukkitHuskHomes.getInstance())), + TPA_COMMAND(new TeleportRequestCommand(BukkitHuskHomes.getInstance(), TeleportRequest.Type.TPA)), + TPA_HERE_COMMAND(new TeleportRequestCommand(BukkitHuskHomes.getInstance(), TeleportRequest.Type.TPA_HERE)), TPACCEPT_COMMAND(new TpRespondCommand(BukkitHuskHomes.getInstance(), true)), TPDECLINE_COMMAND(new TpRespondCommand(BukkitHuskHomes.getInstance(), false)), RTP_COMMAND(new RtpCommand(BukkitHuskHomes.getInstance())), diff --git a/common/src/main/java/net/william278/huskhomes/HuskHomes.java b/common/src/main/java/net/william278/huskhomes/HuskHomes.java index 81614aa6..071dca48 100644 --- a/common/src/main/java/net/william278/huskhomes/HuskHomes.java +++ b/common/src/main/java/net/william278/huskhomes/HuskHomes.java @@ -154,9 +154,9 @@ public interface HuskHomes extends TaskRunner, EventDispatcher { * * @return the {@link Position} of the spawn, or an empty {@link Optional} if it has not been set */ - default Optional getSpawn() { + default Optional getSpawn() { return getSettings().isCrossServer() && getSettings().isGlobalSpawn() - ? getDatabase().getWarp(getSettings().getGlobalSpawnName()) + ? getDatabase().getWarp(getSettings().getGlobalSpawnName()).map(warp -> (Position) warp) : getLocalCachedSpawn().map(spawn -> spawn.getPosition(getServerName())); } diff --git a/common/src/main/java/net/william278/huskhomes/command/Command.java b/common/src/main/java/net/william278/huskhomes/command/Command.java index 97655e9a..89d05413 100644 --- a/common/src/main/java/net/william278/huskhomes/command/Command.java +++ b/common/src/main/java/net/william278/huskhomes/command/Command.java @@ -12,8 +12,7 @@ public abstract class Command extends Node implements TabProvider { private final String usage; - protected Command(@NotNull String name, @NotNull List aliases, @NotNull String usage, - @NotNull HuskHomes plugin) { + protected Command(@NotNull String name, @NotNull List aliases, @NotNull String usage, @NotNull HuskHomes plugin) { super(name, aliases, plugin); this.usage = usage; } @@ -65,4 +64,9 @@ public abstract class Command extends Node implements TabProvider { return Map.of(); } + @NotNull + public final HuskHomes getPlugin() { + return plugin; + } + } \ No newline at end of file diff --git a/common/src/main/java/net/william278/huskhomes/command/InGameCommand.java b/common/src/main/java/net/william278/huskhomes/command/InGameCommand.java new file mode 100644 index 00000000..f107a27a --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/command/InGameCommand.java @@ -0,0 +1,29 @@ +package net.william278.huskhomes.command; + +import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.user.CommandUser; +import net.william278.huskhomes.user.OnlineUser; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public abstract class InGameCommand extends Command { + + protected InGameCommand(@NotNull String name, @NotNull List aliases, @NotNull String usage, + @NotNull HuskHomes plugin) { + super(name, aliases, usage, plugin); + } + + @Override + public void execute(@NotNull CommandUser executor, @NotNull String[] args) { + if (!(executor instanceof OnlineUser user)) { + plugin.getLocales().getLocale("error_in_game_only") + .ifPresent(executor::sendMessage); + return; + } + this.execute(user, args); + } + + public abstract void execute(@NotNull OnlineUser executor, @NotNull String[] args); + +} diff --git a/common/src/main/java/net/william278/huskhomes/command/Node.java b/common/src/main/java/net/william278/huskhomes/command/Node.java index 8904527f..f91b2c1f 100644 --- a/common/src/main/java/net/william278/huskhomes/command/Node.java +++ b/common/src/main/java/net/william278/huskhomes/command/Node.java @@ -1,14 +1,18 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.position.Position; +import net.william278.huskhomes.position.World; import net.william278.huskhomes.teleport.Teleportable; import net.william278.huskhomes.user.CommandUser; import net.william278.huskhomes.user.ConsoleUser; +import net.william278.huskhomes.user.OnlineUser; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Optional; import java.util.StringJoiner; +import java.util.UUID; public abstract class Node implements Executable { @@ -86,6 +90,17 @@ public abstract class Node implements Executable { return Optional.empty(); } + protected Optional parseFloatArg(@NotNull String[] args, int index) { + try { + if (args.length > index) { + return Optional.of(Float.parseFloat(args[index])); + } + } catch (NumberFormatException e) { + return Optional.empty(); + } + return Optional.empty(); + } + protected Optional parseDoubleArg(@NotNull String[] args, int index) { try { if (args.length > index) { @@ -97,6 +112,25 @@ public abstract class Node implements Executable { return Optional.empty(); } + protected Optional parseCoordinateArg(@NotNull String[] args, int index, double relativeTo) { + try { + if (args.length > index) { + final String arg = args[index]; + if (arg.startsWith("~")) { + final String coordinate = arg.substring(1); + if (coordinate.isBlank()) { + return Optional.of(relativeTo); + } + return Optional.of(relativeTo + Double.parseDouble(coordinate)); + } + return Optional.of(Double.parseDouble(arg)); + } + } catch (NumberFormatException e) { + return Optional.empty(); + } + return Optional.empty(); + } + protected Optional parseStringArg(@NotNull String[] args, int index) { if (args.length > index) { return Optional.of(args[index]); @@ -104,6 +138,19 @@ public abstract class Node implements Executable { return Optional.empty(); } + protected Optional parseWorldArg(@NotNull String[] args, int index) { + if (args.length > index) { + final String worldName = args[index]; + final World.Environment environment = worldName.endsWith("_the_end") ? World.Environment.THE_END : + worldName.endsWith("nether") ? World.Environment.NETHER : World.Environment.OVERWORLD; + return Optional.of(plugin.getWorlds().stream() + .filter(world -> world.getName().equalsIgnoreCase(worldName)) + .findFirst() + .orElse(new World(worldName, new UUID(0, 0), environment))); + } + return Optional.empty(); + } + protected Optional parseGreedyString(@NotNull String[] args, int startIndex) { if (args.length > startIndex) { final StringJoiner sentence = new StringJoiner(" "); @@ -115,9 +162,39 @@ public abstract class Node implements Executable { return Optional.empty(); } + protected Position getBasePosition(@NotNull CommandUser executor) { + return executor instanceof OnlineUser user ? user.getPosition() : plugin.getSpawn() + .orElse(new Position(0, 0, 0, 0, 0, plugin.getWorlds().get(0), plugin.getServerName())); + } + + protected Optional parsePositionArgs(@NotNull Position basePosition, @NotNull String[] args, int startIndex) { + // Parse x, y, and z + final Optional x = parseCoordinateArg(args, startIndex, basePosition.getX()); + final Optional y = parseCoordinateArg(args, startIndex + 1, basePosition.getY()); + final Optional z = parseCoordinateArg(args, startIndex + 2, basePosition.getZ()); + if (x.isEmpty() || y.isEmpty() || z.isEmpty()) { + return Optional.empty(); + } + + // Parse world and server name + final Optional world = parseWorldArg(args, startIndex + 3); + final Optional server = parseStringArg(args, startIndex + 4); + + // Parse yaw, pitch + int angleStartIndex = (world.isEmpty() ? 3 : server.isEmpty() ? 4 : 5); + final Optional yaw = parseFloatArg(args, startIndex + angleStartIndex); + final Optional pitch = parseFloatArg(args, startIndex + angleStartIndex + 1); + + return Optional.of(new Position(x.get(), y.get(), z.get(), + yaw.orElse(basePosition.getYaw()), pitch.orElse(basePosition.getPitch()), + world.orElse(basePosition.getWorld()), server.orElse(basePosition.getServer()))); + } + + protected Optional resolveTeleportable(@NotNull CommandUser executor, @NotNull String[] args) { return parseStringArg(args, 0).map(Teleportable::username) .or(() -> executor instanceof Teleportable ? Optional.of((Teleportable) executor) : Optional.empty()); } + } \ No newline at end of file diff --git a/common/src/main/java/net/william278/huskhomes/command/SetPositionCommand.java b/common/src/main/java/net/william278/huskhomes/command/SetPositionCommand.java index 70cad3c8..b7c84b5a 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetPositionCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetPositionCommand.java @@ -1,35 +1,28 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; -import net.william278.huskhomes.user.CommandUser; import net.william278.huskhomes.user.OnlineUser; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Optional; -public abstract class SetPositionCommand extends Command { +public abstract class SetPositionCommand extends InGameCommand { protected SetPositionCommand(@NotNull String name, @NotNull HuskHomes plugin) { super(name, List.of(), "", plugin); } @Override - public void execute(@NotNull CommandUser executor, @NotNull String[] args) { - if (!(executor instanceof OnlineUser user)) { - plugin.getLocales().getLocale("error_in_game_only") + public void execute(@NotNull OnlineUser executor, @NotNull String[] args) { + final Optional name = parseStringArg(args, 0); + if (name.isEmpty()) { + plugin.getLocales().getLocale("error_invalid_syntax", getUsage()) .ifPresent(executor::sendMessage); return; } - final Optional name = parseStringArg(args, 0); - if (name.isEmpty()) { - plugin.getLocales().getLocale("error_invalid_syntax", getUsage()) - .ifPresent(user::sendMessage); - return; - } - - this.execute(user, name.get()); + this.execute(executor, name.get()); } protected abstract void execute(@NotNull OnlineUser setter, @NotNull String name); diff --git a/common/src/main/java/net/william278/huskhomes/command/SetSpawnCommand.java b/common/src/main/java/net/william278/huskhomes/command/SetSpawnCommand.java index be3e4972..9c7f247f 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetSpawnCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetSpawnCommand.java @@ -2,28 +2,21 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.position.Position; -import net.william278.huskhomes.user.CommandUser; import net.william278.huskhomes.user.OnlineUser; import net.william278.huskhomes.util.ValidationException; import org.jetbrains.annotations.NotNull; import java.util.List; -public class SetSpawnCommand extends Command { +public class SetSpawnCommand extends InGameCommand { protected SetSpawnCommand(@NotNull HuskHomes plugin) { super("setspawn", List.of(), "", plugin); } @Override - public void execute(@NotNull CommandUser executor, @NotNull String[] args) { - if (!(executor instanceof OnlineUser user)) { - plugin.getLocales().getLocale("error_in_game_only") - .ifPresent(executor::sendMessage); - return; - } - - final Position position = user.getPosition(); + public void execute(@NotNull OnlineUser executor, @NotNull String[] args) { + final Position position = executor.getPosition(); try { if (plugin.getSettings().isCrossServer() && plugin.getSettings().isGlobalSpawn()) { final String warpName = plugin.getSettings().getGlobalSpawnName(); diff --git a/common/src/main/java/net/william278/huskhomes/command/TeleportRequestCommand.java b/common/src/main/java/net/william278/huskhomes/command/TeleportRequestCommand.java new file mode 100644 index 00000000..9535f41a --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/command/TeleportRequestCommand.java @@ -0,0 +1,57 @@ +package net.william278.huskhomes.command; + +import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.manager.RequestsManager; +import net.william278.huskhomes.teleport.TeleportRequest; +import net.william278.huskhomes.user.OnlineUser; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Optional; + +public class TeleportRequestCommand extends InGameCommand implements UserListTabProvider { + + private final TeleportRequest.Type requestType; + + protected TeleportRequestCommand(@NotNull HuskHomes plugin, @NotNull TeleportRequest.Type requestType) { + super(requestType == TeleportRequest.Type.TPA ? "tpa" : "tpahere", List.of(), "", plugin); + this.requestType = requestType; + } + + @Override + public void execute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + final RequestsManager manager = plugin.getManager().requests(); + if (manager.isIgnoringRequests(onlineUser)) { + plugin.getLocales().getLocale("error_ignoring_teleport_requests") + .ifPresent(onlineUser::sendMessage); + return; + } + + final Optional optionalTarget = parseStringArg(args, 0); + if (optionalTarget.isEmpty()) { + plugin.getLocales().getLocale("error_invalid_syntax", getUsage()) + .ifPresent(onlineUser::sendMessage); + return; + } + + final String target = optionalTarget.get(); + if (target.equalsIgnoreCase(onlineUser.getUsername())) { + plugin.getLocales().getLocale("error_teleport_request_self") + .ifPresent(onlineUser::sendMessage); + return; + } + + try { + manager.sendTeleportRequest(onlineUser, target, requestType); + } catch (IllegalArgumentException e) { + plugin.getLocales().getLocale("error_player_not_found", target) + .ifPresent(onlineUser::sendMessage); + return; + } + + plugin.getLocales() + .getLocale(requestType == TeleportRequest.Type.TPA ? "tpa" : "tpahere" + "_request_sent", target) + .ifPresent(onlineUser::sendMessage); + } + +} diff --git a/common/src/main/java/net/william278/huskhomes/command/TpAllCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpAllCommand.java index 9ec6d4be..7459ff4f 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpAllCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpAllCommand.java @@ -1,6 +1,8 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.network.Message; +import net.william278.huskhomes.network.Payload; import net.william278.huskhomes.user.OnlineUser; import net.william278.huskhomes.position.Position; import net.william278.huskhomes.teleport.Teleport; @@ -9,42 +11,32 @@ import org.jetbrains.annotations.NotNull; import java.util.List; -public class TpAllCommand extends Command { +public class TpAllCommand extends InGameCommand { - protected TpAllCommand(@NotNull HuskHomes implementor) { - super("tpall", Permission.COMMAND_TPALL, implementor); + protected TpAllCommand(@NotNull HuskHomes plugin) { + super("tpall", List.of(), "", plugin); } @Override - public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - if (args.length != 0) { - plugin.getLocales().getLocale("error_invalid_syntax", "/tpaall") - .ifPresent(onlineUser::sendMessage); - return; + public void execute(@NotNull OnlineUser executor, @NotNull String[] args) { + final Position targetPosition = executor.getPosition(); + for (OnlineUser user : plugin.getOnlineUsers()) { + Teleport.builder(plugin) + .teleporter(user) + .target(targetPosition) + .toTeleport().execute(); } - // Determine players to teleport and teleport them - plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenAccept(fetchedPlayers -> { - final List players = fetchedPlayers.stream() - .filter(userName -> !userName.equalsIgnoreCase(onlineUser.getUsername())).toList(); - if (players.isEmpty()) { - plugin.getLocales().getLocale("error_no_players_online").ifPresent(onlineUser::sendMessage); - return; - } - - // Send a message - plugin.getLocales().getLocale("teleporting_all_players", Integer.toString(players.size())) - .ifPresent(onlineUser::sendMessage); - - // Teleport every player - final Position targetPosition = onlineUser.getPosition(); - players.forEach(playerName -> Teleport.builder(plugin, onlineUser) - .setTeleporter(playerName) - .setTarget(targetPosition) - .toTeleport() - .thenAccept(Teleport::execute)); - }); + if (plugin.getSettings().isCrossServer()) { + Message.builder() + .target(Message.TARGET_ALL) + .type(Message.Type.TELEPORT_TO_POSITION) + .payload(Payload.withPosition(targetPosition)) + .build().send(plugin.getMessenger(), executor); + } + plugin.getLocales().getLocale("teleporting_all_players") + .ifPresent(executor::sendMessage); } } diff --git a/common/src/main/java/net/william278/huskhomes/command/TpCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpCommand.java index c202f97b..f2a0a466 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpCommand.java @@ -1,220 +1,90 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.teleport.*; +import net.william278.huskhomes.user.CommandUser; import net.william278.huskhomes.user.OnlineUser; import net.william278.huskhomes.position.Position; -import net.william278.huskhomes.position.Server; -import net.william278.huskhomes.position.World; -import net.william278.huskhomes.teleport.Teleport; -import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.*; -import java.util.logging.Level; import java.util.stream.Collectors; -public class TpCommand extends Command implements TabProvider, ConsoleExecutable { +public class TpCommand extends Command implements TabProvider { protected TpCommand(@NotNull HuskHomes implementor) { - super("tp", Permission.COMMAND_TP, implementor, "tpo"); + super("tp", List.of("tpo"), "[] [target]", implementor); } @Override - public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - // Ensure a valid target was found - final Optional teleportTarget = getTeleportTarget(args, onlineUser); - if (teleportTarget.isEmpty()) { - plugin.getLocales().getLocale("error_invalid_syntax", "/tp [destination]") - .ifPresent(onlineUser::sendMessage); - return; - } - - // Determine the player to teleport - final String targetPlayerToTeleport = ((teleportTarget.get() instanceof TargetPlayer) && args.length == 2) - ? args[0] : ((teleportTarget.get() instanceof TargetPosition) - ? args.length > 3 ? (isCoordinate(args[1]) && isCoordinate(args[2]) && isCoordinate(args[3]) ? args[0] : onlineUser.getUsername()) - : onlineUser.getUsername() : onlineUser.getUsername()); - - // Find the online user to teleport - plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenRun(() -> { - // Get the list of potential teleports, filtered against vanished players, but ensuring the executor is in the list - final Set players = plugin.getCache().getPlayers(); - players.add(onlineUser.getUsername()); - - // Find the player to teleport - final String playerToTeleport = players.stream() - .filter(user -> user.equalsIgnoreCase(targetPlayerToTeleport)).findFirst() - .or(() -> Optional.ofNullable(targetPlayerToTeleport.equals("@s") ? onlineUser.getUsername() : null)) - .or(() -> plugin.getCache().getPlayers().stream().filter(user -> user.toLowerCase().startsWith(targetPlayerToTeleport)).findFirst()) - .orElse(null); - - // Ensure the player to teleport exists - if (playerToTeleport == null) { - plugin.getLocales().getLocale("error_player_not_found", targetPlayerToTeleport) - .ifPresent(onlineUser::sendMessage); - return; - } - - // Ensure the user has permission to teleport the player to teleport - if (!playerToTeleport.equals(onlineUser.getUsername())) { - if (!onlineUser.hasPermission(Permission.COMMAND_TP_OTHER.node)) { - plugin.getLocales().getLocale("error_no_permission") - .ifPresent(onlineUser::sendMessage); - return; - } - } - - // Execute the teleport - if (teleportTarget.get() instanceof TargetPlayer targetPlayer) { - // Carry out the teleport to a player, by name - Teleport.builder(plugin, onlineUser) - .setTeleporter(playerToTeleport) - .setTarget(targetPlayer.playerName) - .toTeleport() - .thenAccept(teleport -> teleport.execute().thenAccept(result -> { - if (result.successful()) { - result.getTeleporter() - .flatMap(teleporter -> plugin.getLocales().getLocale("teleporting_other_complete", - teleporter.getUsername(), targetPlayer.playerName)) - .ifPresent(onlineUser::sendMessage); - } else { - plugin.getLocales().getLocale("error_player_not_found", targetPlayer.playerName) - .ifPresent(onlineUser::sendMessage); - } - })); - } else if (teleportTarget.get() instanceof TargetPosition targetPosition) { - // Handle coordinate teleport targets - if (!onlineUser.hasPermission(Permission.COMMAND_TP_TO_COORDINATES.node)) { - plugin.getLocales().getLocale("error_no_permission").ifPresent(onlineUser::sendMessage); + public void execute(@NotNull CommandUser executor, @NotNull String[] args) { + switch (args.length) { + case 1 -> { + if (!(executor instanceof OnlineUser user)) { + plugin.getLocales().getLocale("error_in_game_only") + .ifPresent(executor::sendMessage); return; } - // Carry out the teleport to a position - Teleport.builder(plugin, onlineUser) - .setTeleporter(playerToTeleport) - .setTarget(targetPosition.position) - .toTeleport() - .thenAccept(teleport -> teleport.execute().thenAccept(result -> { - if (!result.successful() || playerToTeleport.equalsIgnoreCase(onlineUser.getUsername()) || result.getDestination().isEmpty()) { - return; - } - final Position destination = result.getDestination().get(); - result.getTeleporter() - .flatMap(teleporter -> plugin.getLocales() - .getLocale("teleporting_other_complete_position", teleporter.getUsername(), - Integer.toString((int) destination.getX()), - Integer.toString((int) destination.getY()), - Integer.toString((int) destination.getZ()))) - .ifPresent(onlineUser::sendMessage); - })); + this.execute(executor, user, Target.username(args[0]), args); } - }); + case 2 -> execute(executor, Teleportable.username(args[0]), Target.username(args[1]), args); + default -> { + final Position basePosition = getBasePosition(executor); + Optional target = parsePositionArgs(basePosition, args, 0); + if (target.isPresent()) { + if (!(executor instanceof OnlineUser user)) { + plugin.getLocales().getLocale("error_in_game_only") + .ifPresent(executor::sendMessage); + return; + } + + this.execute(executor, user, target.get(), args); + return; + } + + target = parsePositionArgs(basePosition, args, 1); + if (target.isPresent() && args.length >= 1) { + this.execute(executor, Teleportable.username(args[0]), target.get(), args); + return; + } + + plugin.getLocales().getLocale("error_invalid_syntax", getUsage()) + .ifPresent(executor::sendMessage); + } + } } - /** - * Determines the teleport target from a set of arguments, which may be comprised of usernames and/or position - * coordinates with a world and server. - * - * @param args The arguments to parse. - * @param relativeTo The position to use as a relative reference. This is used for relative coordinate handling - * (e.g. {@code ~-10 ~ ~20}) - * @return The teleport target, if it could be parsed, otherwise and empty {@link Optional}. - */ - @NotNull - private Optional getTeleportTarget(@NotNull String[] args, @NotNull OnlineUser relativeTo) { - if (args.length == 1 || args.length == 2) { - return Optional.of(new TargetPlayer(args[args.length - 1])); - } - if (args.length > 2 && args.length < 7) { - final Optional targetPosition = Position.parse(args, relativeTo.getPosition()) - .map(TargetPosition::new); - return targetPosition.or(() -> Position.parse(Arrays.copyOfRange(args, 1, args.length), - relativeTo.getPosition()).map(TargetPosition::new)); - } - return Optional.empty(); - } - - /** - * Determines if a string is a valid (relative) position coordinate double target. - * - * @param coordinate The string to check. - * @return {@code true} if the string is a valid coordinate, otherwise {@code false}. - */ - private boolean isCoordinate(@NotNull String coordinate) { + // Execute a teleport + private void execute(@NotNull CommandUser executor, @NotNull Teleportable teleportable, @NotNull Target target, + @NotNull String[] args) { try { - if (coordinate.startsWith("~")) { - coordinate = coordinate.substring(1); + final TeleportBuilder builder = Teleport.builder(plugin) + .teleporter(teleportable) + .target(target); + if (executor instanceof OnlineUser user) { + builder.executor(user); } - if (coordinate.isBlank()) { - return true; - } - Double.parseDouble(coordinate); - return true; - } catch (NumberFormatException e) { - return false; + builder.toTeleport().execute(); + } catch (TeleportationException e) { + e.displayMessage(executor, plugin, args); } } - @Override - public void onConsoleExecute(@NotNull String[] args) { - if (args.length < 2 || args.length > 6) { - plugin.log(Level.WARNING, "Invalid syntax. Usage: tp "); - return; - } - final OnlineUser playerToTeleport = plugin.findOnlinePlayer(args[0]).orElse(null); - if (playerToTeleport == null) { - plugin.log(Level.WARNING, "Player not found: " + args[0]); - return; - } - final TeleportTarget teleportTarget; - if (args.length == 2) { - teleportTarget = new TargetPlayer(args[1]); - } else { - try { - teleportTarget = new TargetPosition(new Position( - Double.parseDouble(args[1]), - Double.parseDouble(args[2]), - Double.parseDouble(args[3]), - 0f, 0f, - args.length >= 5 ? new World(args[4], UUID.randomUUID()) : plugin.getWorlds().get(0), - args.length == 6 ? new Server(args[5]) : plugin.getServerName())); - } catch (NumberFormatException e) { - plugin.log(Level.WARNING, "Invalid syntax. Usage: tp [world] [server]"); - return; - } - } - - // Execute the console teleport - final TeleportBuilder builder = Teleport.builder(plugin, playerToTeleport) - .setTeleporter(playerToTeleport.getUsername()); - if (teleportTarget instanceof TargetPlayer targetPlayer) { - builder.setTarget(targetPlayer.playerName); - } else { - builder.setTarget(((TargetPosition) teleportTarget).position); - } - builder.toTeleport().thenAccept(teleport -> teleport.execute().thenAccept(result -> { - if (result.successful()) { - plugin.log(Level.INFO, "Successfully teleported " + playerToTeleport.getUsername()); - } else { - plugin.log(Level.WARNING, "Failed to teleport " + playerToTeleport.getUsername() + " to " + teleportTarget); - } - })); - } - @Override @NotNull public final List suggest(@NotNull CommandUser user, @NotNull String[] args) { - final boolean serveCoordinateCompletions = user != null && user.hasPermission(Permission.COMMAND_TP_TO_COORDINATES.node); + final Position basePosition = getBasePosition(user); + final boolean serveCoordinateCompletions = user.hasPermission(getPermission("coordinates")); switch (args.length) { case 0, 1 -> { final ArrayList completions = new ArrayList<>(); completions.addAll(serveCoordinateCompletions ? List.of("~", "~ ~", "~ ~ ~", - Integer.toString((int) user.getPosition().getX()), - ((int) user.getPosition().getX() + " " + (int) user.getPosition().getY()), - ((int) user.getPosition().getX() + " " + (int) user.getPosition().getY() + " " + (int) user.getPosition().getZ())) - : Collections.emptyList()); + Integer.toString((int) basePosition.getX()), + ((int) basePosition.getX() + " " + (int) basePosition.getY()), + ((int) basePosition.getX() + " " + (int) basePosition.getY() + " " + (int) basePosition.getZ())) + : List.of()); completions.addAll(plugin.getCache().getPlayers()); return completions.stream() .filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : "")) @@ -222,19 +92,16 @@ public class TpCommand extends Command implements TabProvider, ConsoleExecutable } case 2 -> { final ArrayList completions = new ArrayList<>(); - if (isCoordinate(args[0])) { - if (user == null) { - return completions; - } - completions.addAll(List.of("~", Integer.toString((int) user.getPosition().getY()))); - completions.addAll(List.of("~ ~", (int) user.getPosition().getY() + " " + (int) user.getPosition().getZ())); + if (isCoordinate(args, 0)) { + completions.addAll(List.of("~", Integer.toString((int) basePosition.getY()))); + completions.addAll(List.of("~ ~", (int) basePosition.getY() + " " + (int) basePosition.getZ())); } else { completions.addAll(serveCoordinateCompletions ? List.of("~", "~ ~", "~ ~ ~", - Integer.toString((int) user.getPosition().getX()), - ((int) user.getPosition().getX() + " " + (int) user.getPosition().getY()), - ((int) user.getPosition().getX() + " " + (int) user.getPosition().getY() + " " + (int) user.getPosition().getZ())) - : Collections.emptyList()); + Integer.toString((int) basePosition.getX()), + ((int) basePosition.getX() + " " + (int) basePosition.getY()), + ((int) basePosition.getX() + " " + (int) basePosition.getY() + " " + (int) basePosition.getZ())) + : List.of()); completions.addAll(plugin.getCache().getPlayers()); } return completions.stream() @@ -243,17 +110,17 @@ public class TpCommand extends Command implements TabProvider, ConsoleExecutable } case 3 -> { final ArrayList completions = new ArrayList<>(); - if (isCoordinate(args[0]) && isCoordinate(args[1])) { + if (isCoordinate(args, 1) && isCoordinate(args, 2)) { if (!serveCoordinateCompletions) { return completions; } - completions.addAll(List.of("~", Integer.toString((int) user.getPosition().getZ()))); - } else if (isCoordinate(args[1])) { + completions.addAll(List.of("~", Integer.toString((int) basePosition.getZ()))); + } else if (isCoordinate(args, 1)) { if (!serveCoordinateCompletions) { return completions; } - completions.addAll(List.of("~", Integer.toString((int) user.getPosition().getY()))); - completions.addAll(List.of("~ ~", (int) user.getPosition().getY() + " " + (int) user.getPosition().getZ())); + completions.addAll(List.of("~", Integer.toString((int) basePosition.getY()))); + completions.addAll(List.of("~ ~", (int) basePosition.getY() + " " + (int) basePosition.getZ())); } return completions.stream() .filter(s -> s.toLowerCase().startsWith(args[2].toLowerCase())) @@ -261,54 +128,24 @@ public class TpCommand extends Command implements TabProvider, ConsoleExecutable } case 4 -> { final ArrayList completions = new ArrayList<>(); - if (isCoordinate(args[1]) && isCoordinate(args[2]) && !isCoordinate(args[0])) { + if (isCoordinate(args, 1) && isCoordinate(args, 2) && !isCoordinate(args, 0)) { if (!serveCoordinateCompletions) { return completions; } - completions.addAll(List.of("~", Integer.toString((int) user.getPosition().getZ()))); + completions.addAll(List.of("~", Integer.toString((int) basePosition.getZ()))); } return completions.stream() .filter(s -> s.toLowerCase().startsWith(args[3].toLowerCase())) .sorted().collect(Collectors.toList()); } default -> { - return Collections.emptyList(); + return List.of(); } } } - /** - * Represents a target position to teleport to - */ - private static final class TargetPosition extends TeleportTarget { - /** - * The target {@link Position} - */ - private final Position position; - - private TargetPosition(@NotNull Position position) { - this.position = position; - } - + private boolean isCoordinate(@NotNull String[] args, int index) { + return parseCoordinateArg(args, index, 0d).isPresent(); } - /** - * Represents a target player to teleport to - */ - private static final class TargetPlayer extends TeleportTarget { - /** - * Name of the target player - */ - private final String playerName; - - private TargetPlayer(@NotNull String playerName) { - this.playerName = playerName; - } - } - - /** - * Identifies the target of a teleport command operation - */ - private static abstract class TeleportTarget { - } } diff --git a/common/src/main/java/net/william278/huskhomes/command/TpHereCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpHereCommand.java index 4320bb02..dcbe1360 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpHereCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpHereCommand.java @@ -1,6 +1,9 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.teleport.Target; +import net.william278.huskhomes.teleport.Teleportable; +import net.william278.huskhomes.teleport.TeleportationException; import net.william278.huskhomes.user.OnlineUser; import net.william278.huskhomes.teleport.Teleport; import net.william278.huskhomes.util.Permission; @@ -9,53 +12,34 @@ import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; -public class TpHereCommand extends Command implements TabProvider { +public class TpHereCommand extends InGameCommand implements UserListTabProvider { - protected TpHereCommand(@NotNull HuskHomes implementor) { - super("tphere", Permission.COMMAND_TPHERE, implementor, "tpohere"); + protected TpHereCommand(@NotNull HuskHomes plugin) { + super("tphere", List.of("tpohere"), "", plugin); } @Override - public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - CompletableFuture.runAsync(() -> { - if (args.length != 1) { - plugin.getLocales().getLocale("error_invalid_syntax", "/tphere ") - .ifPresent(onlineUser::sendMessage); - return; - } - final String targetPlayerName = args[0]; - plugin.findPlayer(onlineUser, targetPlayerName).thenAccept(teleporterName -> { - if (teleporterName.isEmpty()) { - plugin.getLocales().getLocale("error_player_not_found", targetPlayerName) - .ifPresent(onlineUser::sendMessage); - return; - } + public void execute(@NotNull OnlineUser executor, @NotNull String[] args) { + final Optional optionalTarget = parseStringArg(args, 0); + if (optionalTarget.isEmpty()) { + plugin.getLocales().getLocale("error_invalid_syntax", getUsage()) + .ifPresent(executor::sendMessage); + return; + } - Teleport.builder(plugin, onlineUser) - .setTeleporter(teleporterName.get()) - .setTarget(onlineUser.getPosition()) - .toTeleport() - .thenAccept(teleport -> teleport.execute().thenAccept(result -> { - if (result.successful()) { - result.getTeleporter() - .flatMap(teleporter -> plugin.getLocales().getLocale("teleporting_other_complete", - teleporter.getUsername(), onlineUser.getUsername())) - .ifPresent(onlineUser::sendMessage); - } - })); - }); - - }); + try { + Teleport.builder(plugin) + .executor(executor) + .teleporter(optionalTarget.get()) + .target(executor.getPosition()) + .toTeleport().execute(); + } catch (TeleportationException e) { + e.displayMessage(executor, plugin, args); + } } - @Override - @NotNull - public final List suggest(@NotNull CommandUser user, @NotNull String[] args) { - return args.length <= 1 ? plugin.getCache().getPlayers().stream() - .filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : "")) - .sorted().collect(Collectors.toList()) : Collections.emptyList(); - } } diff --git a/common/src/main/java/net/william278/huskhomes/command/TpIgnoreCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpIgnoreCommand.java index 5b6edcb7..67f60691 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpIgnoreCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpIgnoreCommand.java @@ -2,35 +2,34 @@ package net.william278.huskhomes.command; import de.themoep.minedown.adventure.MineDown; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.manager.RequestsManager; import net.william278.huskhomes.user.OnlineUser; import net.william278.huskhomes.user.SavedUser; import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; -public class TpIgnoreCommand extends Command { +import java.util.List; - protected TpIgnoreCommand(@NotNull HuskHomes implementor) { - super("tpignore", Permission.COMMAND_TPIGNORE, implementor); +public class TpIgnoreCommand extends InGameCommand { + + protected TpIgnoreCommand(@NotNull HuskHomes plugin) { + super("tpignore", List.of(), "", plugin); } @Override - public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - if (args.length != 0) { - plugin.getLocales().getLocale("error_invalid_syntax", "/tpignore") - .ifPresent(onlineUser::sendMessage); - return; - } + public void execute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + final RequestsManager manager = plugin.getManager().requests(); + final boolean isIgnoringRequests = !manager.isIgnoringRequests(onlineUser); - // Update local value - final boolean isIgnoringRequests = !plugin.getRequestManager().isIgnoringRequests(onlineUser); - plugin.getRequestManager().setIgnoringRequests(onlineUser, isIgnoringRequests); + final SavedUser user = plugin.getDatabase().getUserData(onlineUser.getUuid()) + .orElseThrow(() -> new IllegalStateException("User data not found for " + onlineUser.getUsername())); + user.setIgnoringTeleports(isIgnoringRequests); + manager.setIgnoringRequests(onlineUser, isIgnoringRequests); + plugin.getDatabase().updateUserData(user); - // Update value on the database and send a message | todo: Clean this up - plugin.getDatabase().getUserData(onlineUser.getUuid()) - .thenAcceptAsync(userData -> userData.ifPresent(data -> plugin.getDatabase() - .updateUserData(new SavedUser(onlineUser, data.homeSlots(), isIgnoringRequests, data.rtpCooldown())) - .thenRun(() -> plugin.getLocales().getRawLocale("tpignore_toggle_" + (isIgnoringRequests ? "on" : "off"), - plugin.getLocales().getRawLocale("tpignore_toggle_button").orElse("")) - .ifPresent(locale -> onlineUser.sendMessage(new MineDown(locale)))))); + plugin.getLocales().getRawLocale("tpignore_toggle_" + (isIgnoringRequests ? "on" : "off"), + plugin.getLocales().getRawLocale("tpignore_toggle_button").orElse("")) + .map(MineDown::new) + .ifPresent(onlineUser::sendMessage); } } diff --git a/common/src/main/java/net/william278/huskhomes/command/TpOfflineCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpOfflineCommand.java index c2315a70..eb391129 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpOfflineCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpOfflineCommand.java @@ -4,31 +4,22 @@ import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.position.Position; import net.william278.huskhomes.teleport.Teleport; import net.william278.huskhomes.teleport.TeleportationException; -import net.william278.huskhomes.user.CommandUser; import net.william278.huskhomes.user.OnlineUser; import net.william278.huskhomes.user.SavedUser; import net.william278.huskhomes.user.User; import org.jetbrains.annotations.NotNull; -import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; -public class TpOfflineCommand extends Command implements TabProvider { +public class TpOfflineCommand extends InGameCommand implements UserListTabProvider { protected TpOfflineCommand(@NotNull HuskHomes plugin) { super("tpoffline", List.of(), "", plugin); } @Override - public void execute(@NotNull CommandUser executor, @NotNull String[] args) { - if (!(executor instanceof OnlineUser user)) { - plugin.getLocales().getLocale("error_in_game_only") - .ifPresent(executor::sendMessage); - return; - } - + public void execute(@NotNull OnlineUser executor, @NotNull String[] args) { final Optional optionalUser = parseStringArg(args, 0); if (optionalUser.isEmpty()) { plugin.getLocales().getLocale("error_invalid_syntax", getUsage()) @@ -45,7 +36,7 @@ public class TpOfflineCommand extends Command implements TabProvider { return; } - this.teleportToOfflinePosition(user, targetUserData.get(), args); + this.teleportToOfflinePosition(executor, targetUserData.get(), args); } private void teleportToOfflinePosition(@NotNull OnlineUser user, @NotNull User target, @NotNull String[] args) { @@ -71,12 +62,4 @@ public class TpOfflineCommand extends Command implements TabProvider { } } - @Override - @NotNull - public final List suggest(@NotNull CommandUser user, @NotNull String[] args) { - return args.length <= 1 ? plugin.getCache().getPlayers().stream() - .filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : "")) - .sorted().collect(Collectors.toList()) : Collections.emptyList(); - } - } diff --git a/common/src/main/java/net/william278/huskhomes/command/TpRespondCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpRespondCommand.java index 69b0926f..350e282b 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpRespondCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpRespondCommand.java @@ -2,49 +2,32 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.user.OnlineUser; -import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; +import java.util.Optional; /** * A command used for responding to tp requests - can either be a /tpaccept or /tpdecline command, controlled by the * acceptRequestCommand flag */ -public class TpRespondCommand extends Command implements TabProvider { +public class TpRespondCommand extends InGameCommand implements UserListTabProvider { - private final boolean acceptRequestCommand; + private final boolean accept; - protected TpRespondCommand(@NotNull HuskHomes implementor, boolean acceptRequestCommand) { - super(acceptRequestCommand ? "tpaccept" : "tpdecline", acceptRequestCommand ? Permission.COMMAND_TPACCEPT : Permission.COMMAND_TPDECLINE, implementor); - this.acceptRequestCommand = acceptRequestCommand; + protected TpRespondCommand(@NotNull HuskHomes plugin, boolean accept) { + super(accept ? "tpaccept" : "tpdecline", List.of(), "[player]", plugin); + this.accept = accept; } @Override - public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - if (args.length > 1) { - plugin.getLocales().getLocale("error_invalid_syntax", "/" + command + " [player]") - .ifPresent(onlineUser::sendMessage); + public void execute(@NotNull OnlineUser executor, @NotNull String[] args) { + final Optional requesterName = parseStringArg(args, 0); + if (requesterName.isPresent()) { + plugin.getManager().requests().respondToTeleportRequestBySenderName(executor, requesterName.get(), accept); return; } - - if (args.length == 1) { - // Respond to the request from specified sender name - plugin.getRequestManager().respondToTeleportRequestBySenderName(onlineUser, args[0], acceptRequestCommand); - return; - } - - plugin.getRequestManager().respondToTeleportRequest(onlineUser, acceptRequestCommand); + plugin.getManager().requests().respondToTeleportRequest(executor, accept); } - @Override - @NotNull - public final List suggest(@NotNull CommandUser user, @NotNull String[] args) { - return args.length <= 1 ? plugin.getCache().getPlayers().stream() - .filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : "")) - .sorted().collect(Collectors.toList()) : Collections.emptyList(); - } } diff --git a/common/src/main/java/net/william278/huskhomes/command/TpaAllCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpaAllCommand.java index 7c5cfcc8..dc70ded8 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpaAllCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpaAllCommand.java @@ -1,63 +1,38 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.network.Message; +import net.william278.huskhomes.network.Payload; +import net.william278.huskhomes.position.Position; +import net.william278.huskhomes.teleport.Teleport; +import net.william278.huskhomes.teleport.TeleportBuilder; import net.william278.huskhomes.user.OnlineUser; import net.william278.huskhomes.teleport.TeleportRequest; -import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; +import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; -public class TpaAllCommand extends Command { +public class TpaAllCommand extends InGameCommand { - protected TpaAllCommand(@NotNull HuskHomes implementor) { - super("tpaall", Permission.COMMAND_TPA_ALL, implementor); + protected TpaAllCommand(@NotNull HuskHomes plugin) { + super("tpaall", List.of(), "", plugin); } @Override - public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - if (plugin.getRequestManager().isIgnoringRequests(onlineUser)) { + public void execute(@NotNull OnlineUser executor, @NotNull String[] args) { + if (plugin.getManager().requests().isIgnoringRequests(executor)) { plugin.getLocales().getLocale("error_ignoring_teleport_requests") - .ifPresent(onlineUser::sendMessage); + .ifPresent(executor::sendMessage); return; } - if (args.length != 0) { - plugin.getLocales().getLocale("error_invalid_syntax", "/tpaall") - .ifPresent(onlineUser::sendMessage); - return; - } - - // Determine players to teleport and teleport them - plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenAccept(playerList -> { - final List players = plugin.getCache().getPlayers().stream() - .filter(userName -> !userName.equalsIgnoreCase(onlineUser.getUsername())).toList(); - if (players.isEmpty()) { - plugin.getLocales().getLocale("error_no_players_online").ifPresent(onlineUser::sendMessage); - return; - } - - // Send a teleport request to every player - final AtomicInteger counter = new AtomicInteger(0); - final List> sentRequestsFuture = new ArrayList<>(); - players.forEach(playerName -> sentRequestsFuture.add(plugin.getRequestManager() - .sendTeleportRequest(onlineUser, playerName, TeleportRequest.Type.TPA_HERE) - .thenAccept(sent -> counter.addAndGet(sent.isPresent() ? 1 : 0)))); - - // Send a message when all requests have been sent - CompletableFuture.allOf(sentRequestsFuture.toArray(new CompletableFuture[0])).thenRun(() -> { - if (counter.get() == 0) { - plugin.getLocales().getLocale("error_no_players_online") - .ifPresent(onlineUser::sendMessage); - return; - } - plugin.getLocales().getLocale("tpaall_request_sent", Integer.toString(counter.get())) - .ifPresent(onlineUser::sendMessage); - }); - }); + plugin.getManager().requests().sendTeleportAllRequest(executor); + plugin.getLocales().getLocale("teleporting_all_players") + .ifPresent(executor::sendMessage); } } diff --git a/common/src/main/java/net/william278/huskhomes/command/TpaCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpaCommand.java deleted file mode 100644 index 01a86d2d..00000000 --- a/common/src/main/java/net/william278/huskhomes/command/TpaCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.william278.huskhomes.command; - -import net.william278.huskhomes.HuskHomes; -import net.william278.huskhomes.user.OnlineUser; -import net.william278.huskhomes.teleport.TeleportRequest; -import net.william278.huskhomes.util.Permission; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -public class TpaCommand extends Command implements TabProvider { - - protected TpaCommand(@NotNull HuskHomes implementor) { - super("tpa", Permission.COMMAND_TPA, implementor); - } - - @Override - public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - if (plugin.getRequestManager().isIgnoringRequests(onlineUser)) { - plugin.getLocales().getLocale("error_ignoring_teleport_requests") - .ifPresent(onlineUser::sendMessage); - return; - } - - if (args.length == 1) { - plugin.getRequestManager() - .sendTeleportRequest(onlineUser, args[0], TeleportRequest.Type.TPA) - .thenAccept(sent -> { - if (sent.isEmpty()) { - if (args[0].equalsIgnoreCase(onlineUser.getUsername())) { - plugin.getLocales().getLocale("error_teleport_request_self") - .ifPresent(onlineUser::sendMessage); - return; - } - - plugin.getLocales().getLocale("error_player_not_found", args[0]) - .ifPresent(onlineUser::sendMessage); - return; - } - - plugin.getLocales().getLocale("tpa_request_sent", sent.get().getRecipientName()) - .ifPresent(onlineUser::sendMessage); - }); - } else { - plugin.getLocales().getLocale("error_invalid_syntax", "/tpa ") - .ifPresent(onlineUser::sendMessage); - } - } - - @Override - @NotNull - public final List suggest(@NotNull CommandUser user, @NotNull String[] args) { - return args.length <= 1 ? plugin.getCache().getPlayers().stream() - .filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : "")) - .sorted().collect(Collectors.toList()) : Collections.emptyList(); - } -} diff --git a/common/src/main/java/net/william278/huskhomes/command/TpaHereCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpaHereCommand.java deleted file mode 100644 index ebc81215..00000000 --- a/common/src/main/java/net/william278/huskhomes/command/TpaHereCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.william278.huskhomes.command; - -import net.william278.huskhomes.HuskHomes; -import net.william278.huskhomes.user.OnlineUser; -import net.william278.huskhomes.teleport.TeleportRequest; -import net.william278.huskhomes.util.Permission; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -public class TpaHereCommand extends Command implements TabProvider { - - protected TpaHereCommand(@NotNull HuskHomes implementor) { - super("tpahere", Permission.COMMAND_TPAHERE, implementor); - } - - @Override - public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { - if (plugin.getRequestManager().isIgnoringRequests(onlineUser)) { - plugin.getLocales().getLocale("error_ignoring_teleport_requests") - .ifPresent(onlineUser::sendMessage); - return; - } - - if (args.length == 1) { - plugin.getRequestManager() - .sendTeleportRequest(onlineUser, args[0], TeleportRequest.Type.TPA_HERE) - .thenAccept(sent -> { - if (sent.isEmpty()) { - if (args[0].equalsIgnoreCase(onlineUser.getUsername())) { - plugin.getLocales().getLocale("error_teleport_request_self") - .ifPresent(onlineUser::sendMessage); - return; - } - - plugin.getLocales().getLocale("error_player_not_found", args[0]) - .ifPresent(onlineUser::sendMessage); - return; - } - - plugin.getLocales().getLocale("tpahere_request_sent", sent.get().getRecipientName()) - .ifPresent(onlineUser::sendMessage); - }); - } else { - plugin.getLocales().getLocale("error_invalid_syntax", "/tpahere ") - .ifPresent(onlineUser::sendMessage); - } - } - - @Override - @NotNull - public final List suggest(@NotNull CommandUser user, @NotNull String[] args) { - return args.length <= 1 ? plugin.getCache().getPlayers().stream() - .filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : "")) - .sorted().collect(Collectors.toList()) : Collections.emptyList(); - } -} diff --git a/common/src/main/java/net/william278/huskhomes/command/UserListTabProvider.java b/common/src/main/java/net/william278/huskhomes/command/UserListTabProvider.java new file mode 100644 index 00000000..931bc432 --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/command/UserListTabProvider.java @@ -0,0 +1,25 @@ +package net.william278.huskhomes.command; + +import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.user.CommandUser; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public interface UserListTabProvider extends TabProvider { + + @Override + @Nullable + default List suggest(@NotNull CommandUser user, @NotNull String[] args) { + return args.length <= 1 ? getPlugin().getCache().getPlayers().stream() + .filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : "")) + .sorted().collect(Collectors.toList()) : Collections.emptyList(); + } + + @NotNull + HuskHomes getPlugin(); + +} diff --git a/common/src/main/java/net/william278/huskhomes/manager/RequestsManager.java b/common/src/main/java/net/william278/huskhomes/manager/RequestsManager.java index a5e80fe7..40a6a13a 100644 --- a/common/src/main/java/net/william278/huskhomes/manager/RequestsManager.java +++ b/common/src/main/java/net/william278/huskhomes/manager/RequestsManager.java @@ -115,6 +115,26 @@ public class RequestsManager { .findFirst()); } + public void sendTeleportAllRequest(@NotNull OnlineUser requester) { + final long expiry = Instant.now().getEpochSecond() + plugin.getSettings().getTeleportRequestExpiryTime(); + final TeleportRequest request = new TeleportRequest(requester, TeleportRequest.Type.TPA_HERE, expiry); + for (OnlineUser onlineUser : plugin.getOnlineUsers()) { + if (onlineUser.equals(requester)) { + continue; + } + request.setRecipientName(onlineUser.getUsername()); + sendLocalTeleportRequest(request, onlineUser); + } + + if (plugin.getSettings().isCrossServer()) { + Message.builder() + .type(Message.Type.TELEPORT_REQUEST) + .payload(Payload.withTeleportRequest(request)) + .target(Message.TARGET_ALL) + .build().send(plugin.getMessenger(), requester); + } + } + /** * Sends a teleport request of the given type to the specified user, by name, if they exist. * @@ -122,7 +142,8 @@ public class RequestsManager { * @param targetUser The user to send the request to * @param type The type of request to send */ - public void sendTeleportRequest(@NotNull OnlineUser requester, @NotNull String targetUser, @NotNull TeleportRequest.Type type) throws IllegalArgumentException { + public void sendTeleportRequest(@NotNull OnlineUser requester, @NotNull String targetUser, + @NotNull TeleportRequest.Type type) throws IllegalArgumentException { final long expiry = Instant.now().getEpochSecond() + plugin.getSettings().getTeleportRequestExpiryTime(); final TeleportRequest request = new TeleportRequest(requester, type, expiry); final Optional localTarget = plugin.findOnlinePlayer(targetUser); @@ -130,7 +151,6 @@ public class RequestsManager { if (localTarget.get().equals(requester)) { throw new IllegalArgumentException("Cannot send a teleport request to yourself"); } - request.setRecipientName(localTarget.get().getUsername()); sendLocalTeleportRequest(request, localTarget.get()); return; } @@ -156,6 +176,8 @@ public class RequestsManager { * sent because the recipient is ignoring requests or is vanished ({@link OnlineUser#isVanished()}) */ public void sendLocalTeleportRequest(@NotNull TeleportRequest request, @NotNull OnlineUser recipient) { + request.setRecipientName(recipient.getUsername()); + // Silently ignore the request if the recipient is ignoring requests or is vanished if (isIgnoringRequests(recipient) || recipient.isVanished()) { request.setStatus(TeleportRequest.Status.IGNORED); diff --git a/common/src/main/java/net/william278/huskhomes/network/Message.java b/common/src/main/java/net/william278/huskhomes/network/Message.java index 54ab01e3..e9e15584 100644 --- a/common/src/main/java/net/william278/huskhomes/network/Message.java +++ b/common/src/main/java/net/william278/huskhomes/network/Message.java @@ -12,6 +12,11 @@ import java.util.UUID; */ public class Message { + /** + * Message target indicating all players + */ + public static final String TARGET_ALL = "ALL"; + @Expose private UUID id; @Expose diff --git a/common/src/main/java/net/william278/huskhomes/network/PluginMessageBroker.java b/common/src/main/java/net/william278/huskhomes/network/PluginMessageBroker.java index 8a3ae0cf..99081626 100644 --- a/common/src/main/java/net/william278/huskhomes/network/PluginMessageBroker.java +++ b/common/src/main/java/net/william278/huskhomes/network/PluginMessageBroker.java @@ -8,8 +8,6 @@ import net.william278.huskhomes.user.OnlineUser; import org.jetbrains.annotations.NotNull; import java.io.*; -import java.util.ArrayList; -import java.util.List; import java.util.logging.Level; /** diff --git a/common/src/main/java/net/william278/huskhomes/network/RedisBroker.java b/common/src/main/java/net/william278/huskhomes/network/RedisBroker.java index b352ff6b..76ccc1c3 100644 --- a/common/src/main/java/net/william278/huskhomes/network/RedisBroker.java +++ b/common/src/main/java/net/william278/huskhomes/network/RedisBroker.java @@ -11,7 +11,7 @@ import redis.clients.jedis.JedisPubSub; import java.util.logging.Level; /** - * Redis message broker implementation + * Redis PubSub broker implementation */ public class RedisBroker extends PluginMessageBroker { private JedisPool jedisPool; @@ -50,9 +50,9 @@ public class RedisBroker extends PluginMessageBroker { final Message message = plugin.getGson().fromJson(encodedMessage, Message.class); plugin.getOnlineUsers().stream() - .filter(online -> online.getUsername().equalsIgnoreCase(message.getTarget())) - .findFirst() - .ifPresent(receiver -> handle(receiver, message)); + .filter(online -> message.getTarget().equals(Message.TARGET_ALL) + || online.getUsername().equals(message.getTarget())) + .forEach(receiver -> handle(receiver, message)); } }, getSubChannelId()); } diff --git a/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java b/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java index 672884c5..6fa4360d 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java @@ -79,7 +79,8 @@ public class Teleport { // Teleport a local user final OnlineUser teleporter = localTeleporter.get(); if (target instanceof Username username) { - final Optional localTarget = username.findLocally(plugin); + final Optional localTarget = username.name().equals("@s") + ? Optional.of(executor) : username.findLocally(plugin); if (localTarget.isPresent()) { fireEvent((event) -> { executeEconomyActions(); diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java b/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java index ac9c1a6b..4be058c7 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TeleportBuilder.java @@ -37,6 +37,9 @@ public class TeleportBuilder { } private void validateTeleport() throws IllegalStateException { + if (teleporter == null) { + throw new IllegalStateException("Teleporter must be set"); + } if (executor == null) { if (teleporter instanceof OnlineUser onlineUser) { executor = onlineUser; @@ -44,9 +47,6 @@ public class TeleportBuilder { throw new IllegalStateException("Executor must be set if teleporter is not an OnlineUser"); } } - if (teleporter == null) { - throw new IllegalStateException("Teleporter must be set"); - } if (target == null) { throw new IllegalStateException("Target must be set"); } diff --git a/common/src/main/resources/locales/bg-bg.yml b/common/src/main/resources/locales/bg-bg.yml index b51f771c..440ba58b 100644 --- a/common/src/main/resources/locales/bg-bg.yml +++ b/common/src/main/resources/locales/bg-bg.yml @@ -8,7 +8,7 @@ teleporting_action_bar_processing: '[Teleporting…](#00fb9a)' teleporting_action_bar_cancelled: '[Телепортацията отказана!](#ff7e5e)' teleporting_other_complete: '[Teleported %1% to %2%.](#00fb9a)' teleporting_other_complete_position: '[Teleported %1% to ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)' -teleporting_all_players: '[Teleporting](#00fb9a) [%1%](#00fb9a bold) [player(s) to your position…](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)' teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)' tpa_request_sent: '[You sent a teleport request asking to teleport to](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)' tpahere_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [to teleport to you.](#00fb9a)' diff --git a/common/src/main/resources/locales/de-de.yml b/common/src/main/resources/locales/de-de.yml index 240d3f79..2c393282 100644 --- a/common/src/main/resources/locales/de-de.yml +++ b/common/src/main/resources/locales/de-de.yml @@ -8,11 +8,11 @@ teleporting_action_bar_processing: '[Teleportiere…](#00fb9a)' teleporting_action_bar_cancelled: '[Teleportation abgebrochen!](#ff7e5e)' teleporting_other_complete: '[%1% wurde zu %2% teleportiert.](#00fb9a)' teleporting_other_complete_position: '[%1% wurde zu ⚐ x: %2%, y: %3%, z: %4% teleportiert.](#00fb9a)' -teleporting_all_players: '[Teleportiere](#00fb9a) [%1%](#00fb9a bold) [Spieler zu deiner Position…](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)' teleporting_random_generation: '[Eine zufällige sichere Position um dich zu teleportieren, wird gesucht…](#00fb9a)' tpa_request_sent: '[Du hast](#00fb9a) [%1%](#00fb9a bold) [eine Teleportanfrage gesendet.](#00fb9a)' tpahere_request_sent: '[Du hast eine Teleportanfrage gestellt und](#00fb9a) [%1%](#00fb9a bold) [gebeten sich zu dir zu teleportieren.](#00fb9a)' -tpaall_request_sent: '[Du hast eine Teleportanfrage gestellt und](#00fb9a) [%1%](#00fb9a bold) [Spieler gebeten sich zu dir zu teleportieren.](#00fb9a)' +tpaall_request_sent: '[You sent a teleport request to every player asking them to teleport to you.](#00fb9a)' tpa_request_received: '[%1%](#00fb9a bold) [hat darum gebeten, sich zu dir zu teleportieren.](#00fb9a)' tpahere_request_received: '[%1%](#00fb9a bold) [hat darum gebeten, dass du dich zu ihm teleportierst.](#00fb9a)' teleport_request_buttons: '[Optionen:](gray) [[✔ Akzeptieren…]](#00fb9a show_text=�fb9a&Teleportanfrage akzeptieren\n&8Klicke, um die Teleportanfrage von %1% zu akzeptieren run_command=/huskhomes:tpaccept %1%) [[❌ Ablehnen…]](#ff3300 show_text=&#ff3300&Teleportanfrage ablehnen\n&8Klicke, um die Teleportanfrage von %1% abzulehnen run_command=/huskhomes:tpdeny %1%)' diff --git a/common/src/main/resources/locales/en-gb.yml b/common/src/main/resources/locales/en-gb.yml index 6dafea43..b9908421 100644 --- a/common/src/main/resources/locales/en-gb.yml +++ b/common/src/main/resources/locales/en-gb.yml @@ -8,11 +8,11 @@ teleporting_action_bar_processing: '[Teleporting…](#00fb9a)' teleporting_action_bar_cancelled: '[Teleportation cancelled!](#ff7e5e)' teleporting_other_complete: '[Teleported %1% to %2%.](#00fb9a)' teleporting_other_complete_position: '[Teleported %1% to ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)' -teleporting_all_players: '[Teleporting](#00fb9a) [%1%](#00fb9a bold) [player(s) to your position…](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)' teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)' tpa_request_sent: '[You sent a teleport request asking to teleport to](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)' tpahere_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [to teleport to you.](#00fb9a)' -tpaall_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [player(s) to teleport to you.](#00fb9a)' +tpaall_request_sent: '[You sent a teleport request to every player asking them to teleport to you.](#00fb9a)' tpa_request_received: '[%1%](#00fb9a bold) [has requested to teleport to you.](#00fb9a)' tpahere_request_received: '[%1%](#00fb9a bold) [has requested that you teleport to them.](#00fb9a)' teleport_request_buttons: '[Options:](gray) [[✔ Accept…]](#00fb9a show_text=�fb9a&Accept teleport request\n&8Click to accept %1%''s request run_command=/huskhomes:tpaccept %1%) [[❌ Decline…]](#ff3300 show_text=&#ff3300&Decline teleport request\n&8Click to decline %1%''s request run_command=/huskhomes:tpdeny %1%)' diff --git a/common/src/main/resources/locales/es-es.yml b/common/src/main/resources/locales/es-es.yml index 4dee5246..c2c8c9eb 100644 --- a/common/src/main/resources/locales/es-es.yml +++ b/common/src/main/resources/locales/es-es.yml @@ -8,11 +8,11 @@ teleporting_action_bar_processing: '[Teletransportando...](#00fb9a)' teleporting_action_bar_cancelled: '[¡Teleportación cancelada!](#ff7e5e)' teleporting_other_complete: '[Teletransportado %1% a %2%.](#00fb9a)' teleporting_other_complete_position: '[Teletransportado %1% a ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)' -teleporting_all_players: '[Teletransportando a ](#00fb9a) [%1%](#00fb9a bold) [jugador(es) a su posición...](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)' teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)' tpa_request_sent: '[Has enviado una solicitud de teletransporte a](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)' tpahere_request_sent: '[Has enviado una solicitud de teletransporte pidiendo a](#00fb9a) [%1%](#00fb9a bold) [que se teletransporte hacia ti.](#00fb9a)' -tpaall_request_sent: '[Has enviado una solicitud de teletransporte a](#00fb9a) [%1%](#00fb9a bold) [jugador(es) para teletransportarse hacia ti.](#00fb9a)' +tpaall_request_sent: '[You sent a teleport request to every player asking them to teleport to you.](#00fb9a)' tpa_request_received: '[%1%](#00fb9a bold) [ha solicitado teletransportarse hacia ti.](#00fb9a)' tpahere_request_received: '[%1%](#00fb9a bold) [ha solicitado que te teletransportes a ellos.](#00fb9a)' teleport_request_buttons: '[Opciones:](gray) [[✔ Aceptar…]](#00fb9a show_text=�fb9a&Aceptar solicitud de teletransporte\n&8Clic para aceptar la solicitud de %1%. run_command=/huskhomes:tpaccept %1%) [[❌ Rechazar…]](#ff3300 show_text=&#ff3300&Decline teleport request\n&8Clic para rechazar la solicitud de %1%. run_command=/huskhomes:tpdeny %1%)' diff --git a/common/src/main/resources/locales/it-it.yml b/common/src/main/resources/locales/it-it.yml index b2ed1f92..e508638a 100644 --- a/common/src/main/resources/locales/it-it.yml +++ b/common/src/main/resources/locales/it-it.yml @@ -8,11 +8,11 @@ teleporting_action_bar_processing: '[Teletrasporto in corso...](#00fb9a)' teleporting_action_bar_cancelled: '[Teletrasporto cancellato!](#ff7e5e)' teleporting_other_complete: '[Hai teletrasportato %1% da %2%.](#00fb9a)' teleporting_other_complete_position: '[Hai telerasportato %1% a ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)' -teleporting_all_players: '[Stai teletrasportando](#00fb9a) [%1%](#00fb9a bold) [giocatore(i) nella tua posizione…](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)' teleporting_random_generation: '[Ricerca di un punto di teletrasporto sicuro…](#00fb9a)' tpa_request_sent: '[Hai richiesto di teletrasportarti da](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)' tpahere_request_sent: '[Hai richiesto il teletrasporto a](#00fb9a) [%1%](#00fb9a bold) [ verso la tua posizione.](#00fb9a)' -tpaall_request_sent: '[Hai chiesto a](#00fb9a) [%1%](#00fb9a bold) [ giocatore(i) di teletrasportarsi da te.](#00fb9a)' +tpaall_request_sent: '[You sent a teleport request to every player asking them to teleport to you.](#00fb9a)' tpa_request_received: '[%1%](#00fb9a bold) [ha richiesto di teletrasportarsi da te.](#00fb9a)' tpahere_request_received: '[%1%](#00fb9a bold) [ha richiesto di teletrasportarti da lui.](#00fb9a)' teleport_request_buttons: '[Opzioni:](gray) [[✔ Accetta…]](#00fb9a show_text=�fb9a&Accetta la richiesta di teletrasporto\n&8Clicca per accettare la richiesta di %1% run_command=/huskhomes:tpaccept %1%) [[❌ Decline…]](#ff3300 show_text=&#ff3300&Decline teleport request\n&8Click to decline %1%''s request run_command=/huskhomes:tpdeny %1%)' diff --git a/common/src/main/resources/locales/pl.yml b/common/src/main/resources/locales/pl.yml index 486ab122..1a7d7472 100644 --- a/common/src/main/resources/locales/pl.yml +++ b/common/src/main/resources/locales/pl.yml @@ -8,11 +8,11 @@ teleporting_action_bar_processing: '[Teleporting…](#00fb9a)' teleporting_action_bar_cancelled: '[Teleportacja anulowana!](#ff7e5e)' teleporting_other_complete: '[Teleported %1% to %2%.](#00fb9a)' teleporting_other_complete_position: '[Teleported %1% to ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)' -teleporting_all_players: '[Teleporting](#00fb9a) [%1%](#00fb9a bold) [player(s) to your position…](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)' teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)' tpa_request_sent: '[You sent a teleport request asking to teleport to](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)' tpahere_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [to teleport to you.](#00fb9a)' -tpaall_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [player(s) to teleport to you.](#00fb9a)' +tpaall_request_sent: '[You sent a teleport request to every player asking them to teleport to you.](#00fb9a)' tpa_request_received: '[%1%](#00fb9a bold) [has requested to teleport to you.](#00fb9a)' tpahere_request_received: '[%1%](#00fb9a bold) [has requested that you teleport to them.](#00fb9a)' teleport_request_buttons: '[Options:](gray) [[✔ Accept…]](#00fb9a show_text=�fb9a&Accept teleport request\n&8Click to accept %1%''s request run_command=/huskhomes:tpaccept %1%) [[❌ Decline…]](#ff3300 show_text=&#ff3300&Decline teleport request\n&8Click to decline %1%''s request run_command=/huskhomes:tpdeny %1%)' diff --git a/common/src/main/resources/locales/tr-tr.yml b/common/src/main/resources/locales/tr-tr.yml index b4cbe750..3b6dbf94 100644 --- a/common/src/main/resources/locales/tr-tr.yml +++ b/common/src/main/resources/locales/tr-tr.yml @@ -8,11 +8,11 @@ teleporting_action_bar_processing: '[Işınlanılıyor…](#00fb9a)' teleporting_action_bar_cancelled: '[Işınlanma iptal edildi!](#ff7e5e)' teleporting_other_complete: '[%1% den %2% ye ışınlanıldı.](#00fb9a)' teleporting_other_complete_position: '[%1% ⚐ konumuna ışınlandı x: %2%, y: %3%, z: %4%.](#00fb9a)' -teleporting_all_players: '[%1%](#00fb9a bold) [oyuncu(lar) konumunuza ışınlanıyor……](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)' teleporting_random_generation: '[Sizi ışınlamak için güvenli bir rasgele konum aranıyor…](#00fb9a)' tpa_request_sent: '[%1%](#00fb9a bold) [hedefine ışınlanmak için bir ışınlanma isteği gönderdiniz.](#00fb9a)' tpahere_request_sent: '[%1%](#00fb9a bold) [adlı oyuncunun size ışınlanmasını isteyen bir ışınlanma isteği gönderdiniz.](#00fb9a)' -tpaall_request_sent: '[%1%](#00fb9a bold) [oyuncunun size ışınlanmasını isteyen bir ışınlanma isteği gönderdiniz.](#00fb9a)' +tpaall_request_sent: '[You sent a teleport request to every player asking them to teleport to you.](#00fb9a)' tpa_request_received: '[%1%](#00fb9a bold) [size ışınlanmak istiyor.](#00fb9a)' tpahere_request_received: '[%1%](#00fb9a bold)[, ona ışınlanmanızı istiyor.](#00fb9a)' teleport_request_buttons: '[Seçenekler:](gray) [[✔ Kabul et…]](#00fb9a show_text=�fb9a&Işınlanma isteğini kabul et\n&8%1% adlı oyuncunun isteğini kabul etmek için tıklayın run_command=/huskhomes:tpaccept %1%) [[❌ Reddet…]](#ff3300 show_text=&#ff3300&Işınlanmayı reddet request\n&8%1% adlı oyuncunun isteğini reddetmek için tıklayın run_command=/huskhomes:tpdeny %1%)' diff --git a/common/src/main/resources/locales/uk-ua.yml b/common/src/main/resources/locales/uk-ua.yml index 27d19548..36cd9270 100644 --- a/common/src/main/resources/locales/uk-ua.yml +++ b/common/src/main/resources/locales/uk-ua.yml @@ -8,11 +8,11 @@ teleporting_action_bar_processing: '[Teleporting…](#00fb9a)' teleporting_action_bar_cancelled: '[Телепортацію скасовано!](#ff7e5e)' teleporting_other_complete: '[Teleported %1% to %2%.](#00fb9a)' teleporting_other_complete_position: '[Teleported %1% to ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)' -teleporting_all_players: '[Teleporting](#00fb9a) [%1%](#00fb9a bold) [player(s) to your position…](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)' teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)' tpa_request_sent: '[You sent a teleport request asking to teleport to](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)' tpahere_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [to teleport to you.](#00fb9a)' -tpaall_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [player(s) to teleport to you.](#00fb9a)' +tpaall_request_sent: '[You sent a teleport request to every player asking them to teleport to you.](#00fb9a)' tpa_request_received: '[%1%](#00fb9a bold) [has requested to teleport to you.](#00fb9a)' tpahere_request_received: '[%1%](#00fb9a bold) [has requested that you teleport to them.](#00fb9a)' teleport_request_buttons: '[Options:](gray) [[✔ Accept…]](#00fb9a show_text=�fb9a&Accept teleport request\n&8Click to accept %1%''s request run_command=/huskhomes:tpaccept %1%) [[❌ Decline…]](#ff3300 show_text=&#ff3300&Decline teleport request\n&8Click to decline %1%''s request run_command=/huskhomes:tpdeny %1%)' diff --git a/common/src/main/resources/locales/zh-cn.yml b/common/src/main/resources/locales/zh-cn.yml index e722176a..ab2e5425 100644 --- a/common/src/main/resources/locales/zh-cn.yml +++ b/common/src/main/resources/locales/zh-cn.yml @@ -8,11 +8,11 @@ teleporting_action_bar_processing: '[传送……](#00fb9a)' teleporting_action_bar_cancelled: '[传送取消!](#ff7e5e)' teleporting_other_complete: '[将 %1% 传送到 %2%.](#00fb9a)' teleporting_other_complete_position: '[将 %1% 传送到 ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)' -teleporting_all_players: '[将](#00fb9a) [%1%](#00fb9a bold) [名玩家传送到您的位置…](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)' teleporting_random_generation: '[正在寻找一个安全的随机位置传送您…](#00fb9a)' tpa_request_sent: '[已发送传送请求, 传送到](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)' tpahere_request_sent: '[已发送传送请求, 请求](#00fb9a) [%1%](#00fb9a bold) [传送过来.](#00fb9a)' -tpaall_request_sent: '[已发送传送请求, 请求](#00fb9a) [%1%](#00fb9a bold) [传送过来.](#00fb9a)' +tpaall_request_sent: '[You sent a teleport request to every player asking them to teleport to you.](#00fb9a)' tpa_request_received: '[%1%](#00fb9a bold) [请求传送过来.](#00fb9a)' tpahere_request_received: '[%1%](#00fb9a bold) [请求您传送过去.](#00fb9a)' teleport_request_buttons: '[选项:](gray) [[✔ 接受…]](#00fb9a show_text=�fb9a&接受传送请求\n&8点击接受 %1% 的请求 run_command=/huskhomes:tpaccept %1%) [[❌ 拒绝…]](#ff3300 show_text=&#ff3300&拒绝传送请求\n&8点击拒绝 %1% 的请求 run_command=/huskhomes:tpdeny %1%)' diff --git a/common/src/main/resources/locales/zh-tw.yml b/common/src/main/resources/locales/zh-tw.yml index 0200c563..bf69805f 100644 --- a/common/src/main/resources/locales/zh-tw.yml +++ b/common/src/main/resources/locales/zh-tw.yml @@ -8,11 +8,11 @@ teleporting_action_bar_processing: '[傳送中……](#00fb9a)' teleporting_action_bar_cancelled: '[傳送取消!](#ff7e5e)' teleporting_other_complete: '[將 %1% 傳送到 %2%.](#00fb9a)' teleporting_other_complete_position: '[將 %1% 傳送到 ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)' -teleporting_all_players: '[將](#00fb9a) [%1%](#00fb9a bold) [名玩家傳送到您的位置…](#00fb9a)' +teleporting_all_players: '[Teleporting all players to your position…](#00fb9a)' teleporting_random_generation: '[正在尋找一個安全的隨機位置…](#00fb9a)' tpa_request_sent: '[您發送了一個傳送請求給](#00fb9a) [%1%](#00fb9a bold)' tpahere_request_sent: '[您發送了一個傳送請求, 請求](#00fb9a) [%1%](#00fb9a bold) [傳送過來.](#00fb9a)' -tpaall_request_sent: '[你向所有玩家發送了一個傳送請求,要求](#00fb9a) [%1%](#00fb9a bold) [個玩家傳送到你身邊!.](#00fb9a)' +tpaall_request_sent: '[You sent a teleport request to every player asking them to teleport to you.](#00fb9a)' tpa_request_received: '[%1%](#00fb9a bold) [請求傳送過來.](#00fb9a)' tpahere_request_received: '[%1%](#00fb9a bold) [請求您傳送過去.](#00fb9a)' teleport_request_buttons: '[傳送請求:](gray) [[✔ 接受…]](#00fb9a show_text=�fb9a&接受傳送請求\n&8點擊接受 %1% 的請求 run_command=/huskhomes:tpaccept %1%) [[❌ 拒絕…]](#ff3300 show_text=&#ff3300&拒絕傳送請求\n&8點擊拒絕 %1% 的請求 run_command=/huskhomes:tpdeny %1%)'