parent
b734d2352b
commit
2f64f05ce8
4 changed files with 89 additions and 1 deletions
@ -0,0 +1,33 @@ |
|||||||
|
package commands; |
||||||
|
|
||||||
|
import org.bukkit.Bukkit; |
||||||
|
import org.bukkit.World; |
||||||
|
import org.bukkit.command.Command; |
||||||
|
import org.bukkit.command.CommandSender; |
||||||
|
import org.bukkit.command.TabCompleter; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class tabCompleter implements TabCompleter { |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { |
||||||
|
List<String> completions = new ArrayList<>(); |
||||||
|
|
||||||
|
if (command.getName().equalsIgnoreCase("tpw") && commandSender.isOp()) { |
||||||
|
if (strings.length == 0) { |
||||||
|
for (World world : Bukkit.getWorlds()) { |
||||||
|
completions.add(world.getName()); |
||||||
|
} |
||||||
|
} else if (strings.length == 1) { |
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) { |
||||||
|
completions.add(player.getName()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return completions; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,49 @@ |
|||||||
|
package commands; |
||||||
|
|
||||||
|
import org.bukkit.Bukkit; |
||||||
|
import org.bukkit.World; |
||||||
|
import org.bukkit.command.Command; |
||||||
|
import org.bukkit.command.CommandExecutor; |
||||||
|
import org.bukkit.command.CommandSender; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
|
||||||
|
public class teleportWorld implements CommandExecutor { |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { |
||||||
|
if (commandSender instanceof Player) { |
||||||
|
|
||||||
|
Player player = (Player) commandSender; |
||||||
|
|
||||||
|
if (!player.isOp() || strings.length == 0) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
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 (strings.length > 2) { |
||||||
|
try { |
||||||
|
Player targetPlayer = Bukkit.getPlayer(strings[1]); |
||||||
|
|
||||||
|
targetPlayer.teleport(world.getSpawnLocation()); |
||||||
|
targetPlayer.sendMessage(String.format("Successfully teleported %s from %s to %s.", targetPlayer, playerWorld, world)); // Edit
|
||||||
|
return true; |
||||||
|
} catch (Exception e) { |
||||||
|
player.sendMessage("This is not a valid player!"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
player.teleport(world.getSpawnLocation()); |
||||||
|
player.sendMessage(String.format("Successfully teleported from %s to %s.", playerWorld, world)); // Edit
|
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue