use of de.themoep.connectorplugin.LocationInfo in project ConnectorPlugin by Phoenix616.
the class TeleportCommand method run.
@Override
public boolean run(CommandSource sender, String alias, String[] args) {
if (args.length < 2) {
return false;
}
Player player = plugin.getProxy().getPlayer(args[0]).orElse(null);
if (player == null) {
sender.sendMessage(Component.text("No player with the name " + args[0] + " found!").color(NamedTextColor.RED));
return true;
}
RegisteredServer server = plugin.getProxy().getServer(args[1]).orElse(null);
if (server == null) {
sender.sendMessage(Component.text("No server with the name " + args[1] + " found!").color(NamedTextColor.RED));
return true;
}
if (args.length == 2) {
player.createConnectionRequest(server).connect().thenAccept(result -> {
if (result.isSuccessful()) {
sender.sendMessage(Component.text("Connected player " + player.getUsername() + " to server " + server.getServerInfo().getName()).color(NamedTextColor.GREEN));
} else {
sender.sendMessage(Component.text("Error while connecting player " + player.getUsername() + " to server " + server.getServerInfo().getName() + ": " + result.getReasonComponent().orElse(Component.empty())).color(NamedTextColor.RED));
}
});
return true;
}
if (args.length == 3) {
plugin.getBridge().teleport(player.getUsername(), server.getServerInfo().getName(), args[2], m -> sender.sendMessage(LegacyComponentSerializer.legacySection().deserialize(m))).thenAccept(success -> {
if (!success) {
sender.sendMessage(Component.text("Error while teleporting...").color(NamedTextColor.RED));
}
});
return true;
}
if (args.length < 6) {
return false;
}
try {
LocationInfo location = new LocationInfo(server.getServerInfo().getName(), args[2], Double.parseDouble(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), args.length > 6 ? Float.parseFloat(args[6]) : 0, args.length > 7 ? Float.parseFloat(args[7]) : 0);
plugin.getBridge().teleport(player.getUsername(), location, m -> sender.sendMessage(LegacyComponentSerializer.legacySection().deserialize(m))).thenAccept(success -> {
if (!success) {
sender.sendMessage(Component.text("Error while teleporting...").color(NamedTextColor.RED));
}
});
return true;
} catch (IllegalArgumentException e) {
sender.sendMessage(Component.text("Error while parsing input! " + e.getMessage()).color(NamedTextColor.RED));
return false;
}
}
use of de.themoep.connectorplugin.LocationInfo in project ConnectorPlugin by Phoenix616.
the class TeleportCommand method run.
@Override
public boolean run(CommandSender sender, String[] args) {
if (args.length < 2) {
return false;
}
ProxiedPlayer player = plugin.getProxy().getPlayer(args[0]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "No player with the name " + args[0] + " found!");
return true;
}
ServerInfo server = plugin.getProxy().getServerInfo(args[1]);
if (server == null) {
sender.sendMessage(ChatColor.RED + "No server with the name " + args[1] + " found!");
return true;
}
if (args.length == 2) {
player.connect(server, (success, ex) -> {
if (success) {
sender.sendMessage(ChatColor.GREEN + "Connected player " + player.getName() + " to server " + server.getName());
} else {
sender.sendMessage(ChatColor.RED + "Error while connecting player " + player.getName() + " to server " + server.getName() + ": " + ex.getMessage());
}
});
return true;
}
if (args.length == 3) {
plugin.getBridge().teleport(player.getName(), server.getName(), args[2], sender::sendMessage).thenAccept(success -> {
if (!success) {
sender.sendMessage(ChatColor.RED + "Error while teleporting...");
}
});
return true;
}
if (args.length < 6) {
return false;
}
try {
LocationInfo location = new LocationInfo(server.getName(), args[2], Double.parseDouble(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), args.length > 6 ? Float.parseFloat(args[6]) : 0, args.length > 7 ? Float.parseFloat(args[7]) : 0);
plugin.getBridge().teleport(player.getName(), location, sender::sendMessage).thenAccept(success -> {
if (!success) {
sender.sendMessage(ChatColor.RED + "Error while teleporting...");
}
});
return true;
} catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.RED + "Error while parsing input! " + e.getMessage());
return false;
}
}
use of de.themoep.connectorplugin.LocationInfo in project ConnectorPlugin by Phoenix616.
the class Bridge method getLocation.
/**
* Get the location of a player on the server
* @param player The player to get the location for
* @return A future for when the location was queried
*/
public CompletableFuture<LocationInfo> getLocation(ProxiedPlayer player) {
CompletableFuture<LocationInfo> future = new CompletableFuture<>();
ByteArrayDataOutput out = ByteStreams.newDataOutput();
long id = RANDOM.nextLong();
out.writeUTF(plugin.getServerName());
out.writeLong(id);
out.writeUTF(player.getName());
responses.put(id, new ResponseHandler.Location(future));
sendData(Action.GET_LOCATION, MessageTarget.SERVER, player, out.toByteArray());
return future;
}
use of de.themoep.connectorplugin.LocationInfo in project ConnectorPlugin by Phoenix616.
the class Bridge method getLocation.
/**
* Get the location a player is connected to
* @param player The player to get the location for
* @return A future for when the location was queried
*/
public CompletableFuture<LocationInfo> getLocation(String player) {
CompletableFuture<LocationInfo> future = new CompletableFuture<>();
ByteArrayDataOutput out = ByteStreams.newDataOutput();
long id = RANDOM.nextLong();
out.writeUTF(plugin.getServerName());
out.writeLong(id);
out.writeUTF(player);
responses.put(id, new ResponseHandler.Location(future));
sendData(Action.GET_LOCATION, MessageTarget.ALL_PROXIES, PLAYER_PREFIX + player, out.toByteArray());
return future;
}
use of de.themoep.connectorplugin.LocationInfo in project ConnectorPlugin by Phoenix616.
the class Bridge method getLocation.
/**
* Get the location of a player on the server
* @param player The player to get the location for
* @return A future for when the location was queried
*/
public CompletableFuture<LocationInfo> getLocation(Player player) {
CompletableFuture<LocationInfo> future = new CompletableFuture<>();
ByteArrayDataOutput out = ByteStreams.newDataOutput();
long id = RANDOM.nextLong();
out.writeUTF(plugin.getServerName());
out.writeLong(id);
out.writeUTF(player.getUsername());
responses.put(id, new ResponseHandler.Location(future));
sendData(Action.GET_LOCATION, MessageTarget.SERVER, player, out.toByteArray());
return future;
}
Aggregations