Search in sources :

Example 1 with LocationInfo

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;
    }
}
Also used : List(java.util.List) Component(net.kyori.adventure.text.Component) Locale(java.util.Locale) Player(com.velocitypowered.api.proxy.Player) CommandSource(com.velocitypowered.api.command.CommandSource) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) LocationInfo(de.themoep.connectorplugin.LocationInfo) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) Player(com.velocitypowered.api.proxy.Player) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) LocationInfo(de.themoep.connectorplugin.LocationInfo)

Example 2 with LocationInfo

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;
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ServerInfo(net.md_5.bungee.api.config.ServerInfo) LocationInfo(de.themoep.connectorplugin.LocationInfo)

Example 3 with LocationInfo

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ResponseHandler(de.themoep.connectorplugin.ResponseHandler) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) LocationInfo(de.themoep.connectorplugin.LocationInfo)

Example 4 with LocationInfo

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ResponseHandler(de.themoep.connectorplugin.ResponseHandler) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) LocationInfo(de.themoep.connectorplugin.LocationInfo)

Example 5 with LocationInfo

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ResponseHandler(de.themoep.connectorplugin.ResponseHandler) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) LocationInfo(de.themoep.connectorplugin.LocationInfo)

Aggregations

LocationInfo (de.themoep.connectorplugin.LocationInfo)6 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)3 ResponseHandler (de.themoep.connectorplugin.ResponseHandler)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CommandSource (com.velocitypowered.api.command.CommandSource)1 Player (com.velocitypowered.api.proxy.Player)1 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Collectors (java.util.stream.Collectors)1 Component (net.kyori.adventure.text.Component)1 NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)1 LegacyComponentSerializer (net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer)1 ServerInfo (net.md_5.bungee.api.config.ServerInfo)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1