use of com.github.games647.changeskin.core.message.PermResultMessage in project ChangeSkin by games647.
the class SharedBungeeListener method checkPermissions.
private void checkPermissions(P player, ByteArrayDataInput dataInput) {
CheckPermMessage message = new CheckPermMessage();
message.readFrom(dataInput);
UUID receiverUUID = message.getReceiverUUD();
boolean op = message.isOp();
SkinModel targetSkin = message.getTargetSkin();
UUID skinProfile = targetSkin.getProfileId();
boolean success = op || checkBungeePerms(player, receiverUUID, message.isSkinPerm(), skinProfile);
sendMessage(player, new PermResultMessage(success, targetSkin, receiverUUID));
}
use of com.github.games647.changeskin.core.message.PermResultMessage in project ChangeSkin by games647.
the class MessageListener method onPermissionSuccess.
private void onPermissionSuccess(PermResultMessage message, ProxiedPlayer invoker) {
SkinModel targetSkin = message.getSkin();
UUID receiverUUID = message.getReceiverUUID();
ProxiedPlayer receiver = ProxyServer.getInstance().getPlayer(receiverUUID);
if (receiver == null || !receiver.isConnected()) {
// receiver is not online cancel
return;
}
// add cooldown
core.getCooldownService().trackPlayer(invoker.getUniqueId());
// Save the target uuid from the requesting player source
final UserPreference preferences = core.getStorage().getPreferences(receiver.getUniqueId());
preferences.setTargetSkin(targetSkin);
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> {
if (core.getStorage().save(targetSkin)) {
core.getStorage().save(preferences);
}
});
if (core.getConfig().getBoolean("instantSkinChange")) {
plugin.getApi().applySkin(receiver, targetSkin);
plugin.sendMessage(invoker, "skin-changed");
} else {
plugin.sendMessage(invoker, "skin-changed-no-instant");
}
}
use of com.github.games647.changeskin.core.message.PermResultMessage in project ChangeSkin by games647.
the class MessageListener method onPluginMessage.
@EventHandler
public void onPluginMessage(PluginMessageEvent messageEvent) {
String channel = messageEvent.getTag();
if (messageEvent.isCancelled() || !plugin.getName().equals(channel)) {
return;
}
ByteArrayDataInput dataInput = ByteStreams.newDataInput(messageEvent.getData());
String subChannel = dataInput.readUTF();
ProxiedPlayer invoker = (ProxiedPlayer) messageEvent.getReceiver();
if ("PermissionResult".equals(subChannel)) {
PermResultMessage message = new PermResultMessage();
message.readFrom(dataInput);
if (message.isAllowed()) {
onPermissionSuccess(message, invoker);
} else {
plugin.sendMessage(invoker, "no-permission");
}
} else if ("ForwardCmd".equals(subChannel)) {
onCommandForward(invoker, dataInput);
}
}
Aggregations