Search in sources :

Example 1 with PermResultMessage

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));
}
Also used : CheckPermMessage(com.github.games647.changeskin.core.message.CheckPermMessage) PermResultMessage(com.github.games647.changeskin.core.message.PermResultMessage) UUID(java.util.UUID) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Example 2 with PermResultMessage

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");
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) UserPreference(com.github.games647.changeskin.core.model.UserPreference) UUID(java.util.UUID) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Example 3 with PermResultMessage

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);
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) PermResultMessage(com.github.games647.changeskin.core.message.PermResultMessage) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

PermResultMessage (com.github.games647.changeskin.core.message.PermResultMessage)2 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)2 UUID (java.util.UUID)2 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)2 CheckPermMessage (com.github.games647.changeskin.core.message.CheckPermMessage)1 UserPreference (com.github.games647.changeskin.core.model.UserPreference)1 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)1 EventHandler (net.md_5.bungee.event.EventHandler)1