use of net.md_5.bungee.api.connection.ProxiedPlayer in project ChangeSkin by games647.
the class BungeeSkinAPI method applySkin.
@Override
public void applySkin(ProxiedPlayer player, SkinModel targetSkin) {
plugin.getLog().debug("Applying skin for {}", player.getName());
InitialHandler initialHandler = (InitialHandler) player.getPendingConnection();
LoginResult loginProfile = initialHandler.getLoginProfile();
// this is null in offline mode
if (loginProfile == null) {
String mojangUUID = UUIDTypeAdapter.toMojangId(player.getUniqueId());
if (profileSetter != null) {
try {
LoginResult loginResult = new LoginResult(mojangUUID, player.getName(), toProperties(targetSkin));
profileSetter.invokeExact(initialHandler, loginResult);
} catch (Error error) {
// rethrow errors we shouldn't silence them like OutOfMemoryError
throw error;
} catch (Throwable throwable) {
plugin.getLog().error("Error applying skin: {} for {}", targetSkin, player, throwable);
}
}
} else {
applyProperties(loginProfile, targetSkin);
}
// send plugin channel update request
plugin.sendPluginMessage(player.getServer(), new SkinUpdateMessage(player.getName()));
}
use of net.md_5.bungee.api.connection.ProxiedPlayer in project ChangeSkin by games647.
the class SetCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
boolean isOp = sender.getGroups().contains(plugin.getName() + "-OP");
if (sender instanceof ProxiedPlayer) {
sender.removeGroups(plugin.getName() + "-OP");
if (plugin.getCore().getCooldownService().isTracked(((ProxiedPlayer) sender).getUniqueId())) {
plugin.sendMessage(sender, "cooldown");
return;
}
}
if (args.length > 0 && "set".equalsIgnoreCase(args[0])) {
args = Arrays.copyOfRange(args, 1, args.length);
}
if (args.length > 1) {
if (!sender.hasPermission(plugin.getName().toLowerCase() + ".command.setskin.other") && !sender.hasPermission(plugin.getName().toLowerCase() + ".command.setskin.*")) {
plugin.sendMessage(sender, "no-permission-other");
return;
}
String targetPlayerName = args[0];
String toSkin = args[1];
ProxiedPlayer targetPlayer = ProxyServer.getInstance().getPlayer(targetPlayerName);
if (targetPlayer == null) {
plugin.sendMessage(sender, "not-online");
} else {
setSkin(sender, targetPlayer, toSkin, isOp, isKeepSkin(args));
}
} else if (sender instanceof ProxiedPlayer) {
if (args.length == 1) {
if ("reset".equalsIgnoreCase(args[0])) {
onReset(sender, isOp);
return;
}
setSkin(sender, (ProxiedPlayer) sender, args[0], isOp, isKeepSkin(args));
} else {
plugin.sendMessage(sender, "no-skin");
}
} else {
plugin.sendMessage(sender, "no-console");
}
}
use of net.md_5.bungee.api.connection.ProxiedPlayer in project ChangeSkin by games647.
the class ServerSwitchListener method onServerConnect.
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerConnect(ServerConnectEvent connectEvent) {
ServerInfo targetServer = connectEvent.getTarget();
Server fromServer = connectEvent.getPlayer().getServer();
if (fromServer != null && Objects.equals(targetServer, fromServer.getInfo())) {
// check if we are switching to the same server
return;
}
if (!isBlacklistEnabled()) {
return;
}
ProxiedPlayer player = connectEvent.getPlayer();
UserPreference session = plugin.getLoginSession(player.getPendingConnection());
List<String> blacklist = core.getConfig().getStringList("server-blacklist");
if (blacklist.contains(targetServer.getName())) {
// clear the skin
plugin.getApi().applySkin(player, null);
} else if (session == null) {
// lazy load
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> onLazyLoad(player));
} else {
// player switched to an enabled server
Optional<SkinModel> optSkin = session.getTargetSkin();
optSkin.ifPresent(skin -> plugin.getApi().applySkin(player, skin));
}
}
use of net.md_5.bungee.api.connection.ProxiedPlayer in project ChangeSkin by games647.
the class ConnectListener method onPlayerLogin.
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerLogin(PostLoginEvent postLoginEvent) {
ProxiedPlayer player = postLoginEvent.getPlayer();
UserPreference preferences = plugin.getLoginSession(player.getPendingConnection());
if (preferences == null || isBlacklistEnabled()) {
return;
}
if (!preferences.getTargetSkin().isPresent()) {
getRandomSkin().ifPresent(preferences::setTargetSkin);
}
preferences.getTargetSkin().ifPresent(skin -> plugin.getApi().applySkin(player, skin));
}
use of net.md_5.bungee.api.connection.ProxiedPlayer in project ViaCheckConnection by x9nico.
the class Bungee method join.
@SuppressWarnings({ "unchecked" })
@EventHandler
public void join(ServerConnectedEvent e) throws IOException {
ProxiedPlayer p = e.getPlayer();
Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
if (Bungee.isProtocolSupport()) {
if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_8.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_8").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_2.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_2").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_3.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_3").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_10.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_10").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_11").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_11_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.unknown.getId()) {
p.sendMessage(new TextComponent(config.getString("unknown_version").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_7_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_7_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_7_6.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_7_6").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_2.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12_2").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_13.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_13").replace("&", "§")));
}
} else {
if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_8.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_8").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_2.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_2").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_9_3.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_9_3").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_10.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_10").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_11").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_11_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_11_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.unknown.getId()) {
p.sendMessage(new TextComponent(config.getString("unknown_version").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_1.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12_1").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_12_2.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_12_2").replace("&", "§")));
} else if (Via.getAPI().getPlayerVersion(p) == ProtocolVersion.v1_13.getId()) {
p.sendMessage(new TextComponent(config.getString("v1_13").replace("&", "§")));
}
}
}
Aggregations