diff --git a/src/main/java/commands/tabCompleter.java b/src/main/java/commands/tabCompleter.java index c0dc01c..1f86e88 100644 --- a/src/main/java/commands/tabCompleter.java +++ b/src/main/java/commands/tabCompleter.java @@ -17,11 +17,11 @@ public class tabCompleter implements TabCompleter { List completions = new ArrayList<>(); if (command.getName().equalsIgnoreCase("tpw") && commandSender.isOp()) { - if (strings.length == 0) { + if (strings.length == 1) { for (World world : Bukkit.getWorlds()) { completions.add(world.getName()); } - } else if (strings.length == 1) { + } else if (strings.length == 2) { for (Player player : Bukkit.getOnlinePlayers()) { completions.add(player.getName()); } diff --git a/src/main/java/commands/teleportWorld.java b/src/main/java/commands/teleportWorld.java index 3ec5923..9bb51b9 100644 --- a/src/main/java/commands/teleportWorld.java +++ b/src/main/java/commands/teleportWorld.java @@ -9,6 +9,7 @@ import org.bukkit.entity.Player; public class teleportWorld implements CommandExecutor { + // Teleports player with OP to another world. @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { if (commandSender instanceof Player) { @@ -20,28 +21,40 @@ public class teleportWorld implements CommandExecutor { } World world = Bukkit.getWorld(strings[0]); - World playerWorld = player.getWorld(); - if (playerWorld.equals(world)) { - player.sendMessage("You are already in this world!"); // Edit - return false; + if (world == null) { + player.sendMessage("This is not a valid world!"); + return true; } - if (strings.length > 2) { + if (strings.length > 1) { try { Player targetPlayer = Bukkit.getPlayer(strings[1]); + World targetPlayerWorld = targetPlayer.getWorld(); + + if (targetPlayerWorld.equals(world)) { + player.sendMessage(String.format("Player %s is already in this world!", strings[1])); + return true; + } targetPlayer.teleport(world.getSpawnLocation()); - targetPlayer.sendMessage(String.format("Successfully teleported %s from %s to %s.", targetPlayer, playerWorld, world)); // Edit + targetPlayer.sendMessage(String.format("Successfully teleported %s from %s to %s.", strings[1], targetPlayerWorld.getName(), world.getName())); return true; } catch (Exception e) { player.sendMessage("This is not a valid player!"); + return true; } } + World playerWorld = player.getWorld(); + + if (playerWorld.equals(world)) { + player.sendMessage("You are already in this world!"); + return true; + } player.teleport(world.getSpawnLocation()); - player.sendMessage(String.format("Successfully teleported from %s to %s.", playerWorld, world)); // Edit + player.sendMessage(String.format("Successfully teleported from %s to %s.", playerWorld.getName(), world.getName())); return true; } return false; diff --git a/src/main/java/xyz/soukup/mineconomiaCoreV2/MineconomiaCoreV2.java b/src/main/java/xyz/soukup/mineconomiaCoreV2/MineconomiaCoreV2.java index ad8090a..d295e3b 100644 --- a/src/main/java/xyz/soukup/mineconomiaCoreV2/MineconomiaCoreV2.java +++ b/src/main/java/xyz/soukup/mineconomiaCoreV2/MineconomiaCoreV2.java @@ -1,6 +1,7 @@ package xyz.soukup.mineconomiaCoreV2; import commands.tabCompleter; +import commands.teleportWorld; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; import xyz.soukup.mineconomiaCoreV2.database.HibernateUtil; @@ -25,6 +26,7 @@ public final class MineconomiaCoreV2 extends JavaPlugin { Objects.requireNonNull(plugin.getCommand("tractor")).setExecutor(new giveTractorCommand()); // TPW registration + this.getCommand("tpw").setExecutor(new teleportWorld()); this.getCommand("tpw").setTabCompleter(new tabCompleter()); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 138d385..7786bc5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,6 +5,6 @@ api-version: '1.21' commands: tpw: description: "Teleportuje tě do jiného světa" - usage: / + usage: / [arguments] tractor: description: "blieat"