mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
107 lines
5.2 KiB
Java
107 lines
5.2 KiB
Java
package me.william278.huskhomes2.commands;
|
|
|
|
import me.william278.huskhomes2.HuskHomes;
|
|
import me.william278.huskhomes2.integrations.vanishChecker;
|
|
import me.william278.huskhomes2.messageManager;
|
|
import me.william278.huskhomes2.objects.TeleportationPoint;
|
|
import me.william278.huskhomes2.teleportManager;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.TabCompleter;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.util.StringUtil;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
public class TpCommand extends CommandBase {
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
if (sender instanceof Player) {
|
|
Player p = (Player) sender;
|
|
if (args.length >= 1) {
|
|
switch (args.length) {
|
|
case 1:
|
|
String targetPlayer = args[0];
|
|
teleportManager.teleportPlayer(p, targetPlayer);
|
|
return true;
|
|
case 3:
|
|
try {
|
|
double x = Double.parseDouble(args[0]);
|
|
double y = Double.parseDouble(args[1]);
|
|
double z = Double.parseDouble(args[2]);
|
|
TeleportationPoint teleportationPoint = new TeleportationPoint(p.getWorld().getName(), x, y, z, 0F, 0F, HuskHomes.settings.getServerID());
|
|
teleportManager.teleportPlayer(p, teleportationPoint);
|
|
} catch (Exception e) {
|
|
messageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
|
}
|
|
return true;
|
|
case 4:
|
|
try {
|
|
double x = Double.parseDouble(args[0]);
|
|
double y = Double.parseDouble(args[1]);
|
|
double z = Double.parseDouble(args[2]);
|
|
String worldName = args[3];
|
|
if (Bukkit.getWorld(worldName) == null) {
|
|
messageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
|
return true;
|
|
}
|
|
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, 0F, 0F, HuskHomes.settings.getServerID());
|
|
teleportManager.teleportPlayer(p, teleportationPoint);
|
|
} catch (Exception e) {
|
|
messageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> [world] [server]");
|
|
}
|
|
return true;
|
|
case 5:
|
|
if (HuskHomes.settings.doBungee()) {
|
|
try {
|
|
double x = Double.parseDouble(args[0]);
|
|
double y = Double.parseDouble(args[1]);
|
|
double z = Double.parseDouble(args[2]);
|
|
String worldName = args[3];
|
|
String serverName = args[4];
|
|
if (Bukkit.getWorld(worldName) == null) {
|
|
messageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> <world> <server>");
|
|
return true;
|
|
}
|
|
TeleportationPoint teleportationPoint = new TeleportationPoint(worldName, x, y, z, 0F, 0F, serverName);
|
|
teleportManager.teleportPlayer(p, teleportationPoint);
|
|
} catch (Exception e) {
|
|
messageManager.sendMessage(p, "error_invalid_syntax", "/tp <x> <y> <z> <world> <server>");
|
|
}
|
|
} else {
|
|
messageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
|
}
|
|
return true;
|
|
}
|
|
} else {
|
|
messageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static class Tab implements TabCompleter {
|
|
@Override
|
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
ArrayList<String> players = new ArrayList<>();
|
|
if (args.length == 0 || args.length == 1) {
|
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
if (!vanishChecker.isVanished(p) && !(p.getName().equals(sender.getName()))) {
|
|
players.add(p.getName());
|
|
}
|
|
}
|
|
}
|
|
final List<String> tabCompletions = new ArrayList<>();
|
|
StringUtil.copyPartialMatches(args[0], players, tabCompletions);
|
|
Collections.sort(tabCompletions);
|
|
return tabCompletions;
|
|
}
|
|
|
|
}
|
|
}
|