2020-06-12 07:45:49 +02:00
|
|
|
package net.ME1312.SubServers.Bungee.Host;
|
|
|
|
|
|
|
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
|
|
|
import net.ME1312.Galaxi.Library.Util;
|
|
|
|
import net.ME1312.SubData.Server.SubDataSerializable;
|
|
|
|
import net.ME1312.SubServers.Bungee.SubAPI;
|
|
|
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
|
|
|
2020-07-25 07:20:59 +02:00
|
|
|
import java.net.InetSocketAddress;
|
2020-06-12 07:45:49 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remote Player Class
|
|
|
|
*/
|
|
|
|
public class RemotePlayer implements SubDataSerializable {
|
|
|
|
private ProxiedPlayer local;
|
|
|
|
private UUID id;
|
|
|
|
private String name;
|
2020-07-25 07:20:59 +02:00
|
|
|
private InetSocketAddress ip;
|
2020-06-12 07:45:49 +02:00
|
|
|
private Proxy proxy;
|
|
|
|
private Server server;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translate a Local Player to a Remote Player
|
|
|
|
*
|
|
|
|
* @param player Local Player
|
|
|
|
*/
|
|
|
|
public RemotePlayer(ProxiedPlayer player) {
|
|
|
|
if (Util.isNull(player)) throw new NullPointerException();
|
|
|
|
this.local = player;
|
|
|
|
this.id = player.getUniqueId();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for a Remote Player using their ID
|
|
|
|
*
|
2020-07-25 07:20:59 +02:00
|
|
|
* @param name Player Name
|
|
|
|
* @param id Player UUID
|
|
|
|
* @param proxy Proxy the player is on
|
|
|
|
* @param server Server the player is on
|
|
|
|
* @param ip Player IP Address
|
2020-06-12 07:45:49 +02:00
|
|
|
*/
|
2020-07-25 07:20:59 +02:00
|
|
|
public RemotePlayer(String name, UUID id, Proxy proxy, Server server, InetSocketAddress ip) {
|
|
|
|
if (Util.isNull(name, id, proxy, ip)) throw new NullPointerException();
|
|
|
|
this.id = id;
|
|
|
|
this.name = name;
|
|
|
|
this.ip = ip;
|
|
|
|
this.proxy = proxy;
|
|
|
|
this.server = server;
|
2020-06-12 07:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Local Player
|
|
|
|
*
|
|
|
|
* @return Local Player (or null when not local)
|
|
|
|
*/
|
|
|
|
public ProxiedPlayer get() {
|
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-13 23:53:18 +02:00
|
|
|
* Get the UUID of this player.
|
2020-06-12 07:45:49 +02:00
|
|
|
*
|
|
|
|
* @return the UUID
|
|
|
|
*/
|
|
|
|
public UUID getUniqueId() {
|
|
|
|
if (local != null) {
|
|
|
|
return local.getUniqueId();
|
|
|
|
} else return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the unique name of this player.
|
|
|
|
*
|
|
|
|
* @return the players username
|
|
|
|
*/
|
|
|
|
public String getName() {
|
|
|
|
if (local != null) {
|
|
|
|
return local.getName();
|
|
|
|
} else return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the remote address of this connection.
|
|
|
|
*
|
|
|
|
* @return the remote address
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("deprecation")
|
2020-07-25 07:20:59 +02:00
|
|
|
public InetSocketAddress getAddress() {
|
2020-06-12 07:45:49 +02:00
|
|
|
if (local != null) {
|
2020-07-25 07:20:59 +02:00
|
|
|
return local.getAddress();
|
2020-06-12 07:45:49 +02:00
|
|
|
} else return ip;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the proxy this player is connected to.
|
|
|
|
*
|
|
|
|
* @return the proxy this player is connected to
|
|
|
|
*/
|
|
|
|
public Proxy getProxy() {
|
|
|
|
if (local != null) {
|
|
|
|
return SubAPI.getInstance().getMasterProxy();
|
|
|
|
} else return proxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the server this player is connected to.
|
|
|
|
*
|
|
|
|
* @return the server this player is connected to
|
|
|
|
*/
|
|
|
|
public Server getServer() {
|
|
|
|
if (local != null) {
|
|
|
|
return (Server) local.getServer().getInfo();
|
|
|
|
} else return server;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
return obj instanceof RemotePlayer && getUniqueId().equals(((RemotePlayer) obj).getUniqueId());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ObjectMap<String> forSubData() {
|
|
|
|
ObjectMap<String> pinfo = new ObjectMap<String>();
|
|
|
|
pinfo.set("name", getName());
|
|
|
|
pinfo.set("id", getUniqueId());
|
2020-07-25 07:20:59 +02:00
|
|
|
pinfo.set("address", getAddress().getAddress().getHostAddress() + ':' + getAddress().getPort());
|
2020-06-12 07:45:49 +02:00
|
|
|
if (getServer() != null) pinfo.set("server", getServer().getName());
|
|
|
|
if (getProxy() != null) pinfo.set("proxy", getProxy().getName());
|
|
|
|
return pinfo;
|
|
|
|
}
|
|
|
|
}
|