Vytvořen command který přesune OP hráče do jiného světa.

tpwCommand
Gioth8281 1 year ago
parent f25197f6fd
commit 755e3a910d
  1. 4
      src/main/java/commands/tabCompleter.java
  2. 27
      src/main/java/commands/teleportWorld.java
  3. 2
      src/main/java/xyz/soukup/mineconomiaCoreV2/MineconomiaCoreV2.java
  4. 2
      src/main/resources/plugin.yml

@ -17,11 +17,11 @@ public class tabCompleter implements TabCompleter {
List<String> completions = new ArrayList<>(); List<String> completions = new ArrayList<>();
if (command.getName().equalsIgnoreCase("tpw") && commandSender.isOp()) { if (command.getName().equalsIgnoreCase("tpw") && commandSender.isOp()) {
if (strings.length == 0) { if (strings.length == 1) {
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
completions.add(world.getName()); completions.add(world.getName());
} }
} else if (strings.length == 1) { } else if (strings.length == 2) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
completions.add(player.getName()); completions.add(player.getName());
} }

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
public class teleportWorld implements CommandExecutor { public class teleportWorld implements CommandExecutor {
// Teleports player with OP to another world.
@Override @Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if (commandSender instanceof Player) { if (commandSender instanceof Player) {
@ -20,28 +21,40 @@ public class teleportWorld implements CommandExecutor {
} }
World world = Bukkit.getWorld(strings[0]); World world = Bukkit.getWorld(strings[0]);
World playerWorld = player.getWorld();
if (playerWorld.equals(world)) { if (world == null) {
player.sendMessage("You are already in this world!"); // Edit player.sendMessage("This is not a valid world!");
return false; return true;
} }
if (strings.length > 2) { if (strings.length > 1) {
try { try {
Player targetPlayer = Bukkit.getPlayer(strings[1]); 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.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; return true;
} catch (Exception e) { } catch (Exception e) {
player.sendMessage("This is not a valid player!"); 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.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 true;
} }
return false; return false;

@ -1,6 +1,7 @@
package xyz.soukup.mineconomiaCoreV2; package xyz.soukup.mineconomiaCoreV2;
import commands.tabCompleter; import commands.tabCompleter;
import commands.teleportWorld;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import xyz.soukup.mineconomiaCoreV2.database.HibernateUtil; import xyz.soukup.mineconomiaCoreV2.database.HibernateUtil;
@ -25,6 +26,7 @@ public final class MineconomiaCoreV2 extends JavaPlugin {
Objects.requireNonNull(plugin.getCommand("tractor")).setExecutor(new giveTractorCommand()); Objects.requireNonNull(plugin.getCommand("tractor")).setExecutor(new giveTractorCommand());
// TPW registration // TPW registration
this.getCommand("tpw").setExecutor(new teleportWorld());
this.getCommand("tpw").setTabCompleter(new tabCompleter()); this.getCommand("tpw").setTabCompleter(new tabCompleter());

@ -5,6 +5,6 @@ api-version: '1.21'
commands: commands:
tpw: tpw:
description: "Teleportuje tě do jiného světa" description: "Teleportuje tě do jiného světa"
usage: /<command> usage: /<command> [arguments]
tractor: tractor:
description: "blieat" description: "blieat"

Loading…
Cancel
Save