Search in sources :

Example 1 with NamespaceKey

use of com.github.games647.changeskin.core.message.NamespaceKey in project ChangeSkin by games647.

the class ChangeSkinBukkit method onEnable.

@Override
public void onEnable() {
    try {
        bungeeCord = getServer().spigot().getConfig().getBoolean("settings.bungeecord");
    } catch (Exception | NoSuchMethodError ex) {
        logger.warn("Cannot check bungeecord support. You use a non-Spigot build");
    }
    registerCommands();
    try {
        core.load(!bungeeCord);
    } catch (Exception ex) {
        logger.error("Error initializing plugin. Disabling...", ex);
        setEnabled(false);
        return;
    }
    if (bungeeCord) {
        logger.info("BungeeCord detected. Activating BungeeCord support");
        logger.info("Make sure you installed the plugin on BungeeCord too");
        // outgoing
        Messenger messenger = getServer().getMessenger();
        String permissionResultChannel = new NamespaceKey(getName(), PERMISSION_RESULT_CHANNEL).getCombinedName();
        String forwardChannel = new NamespaceKey(getName(), FORWARD_COMMAND_CHANNEL).getCombinedName();
        messenger.registerOutgoingPluginChannel(this, permissionResultChannel);
        messenger.registerOutgoingPluginChannel(this, forwardChannel);
        // incoming
        String updateChannel = new NamespaceKey(getName(), UPDATE_SKIN_CHANNEL).getCombinedName();
        String permissionChannel = new NamespaceKey(getName(), CHECK_PERM_CHANNEL).getCombinedName();
        messenger.registerIncomingPluginChannel(this, updateChannel, new SkinUpdateListener(this));
        messenger.registerIncomingPluginChannel(this, permissionChannel, new CheckPermissionListener(this));
    } else {
        getServer().getPluginManager().registerEvents(new LoginListener(this), this);
    }
}
Also used : NamespaceKey(com.github.games647.changeskin.core.message.NamespaceKey) SkinUpdateListener(com.github.games647.changeskin.bukkit.bungee.SkinUpdateListener) Messenger(org.bukkit.plugin.messaging.Messenger) CheckPermissionListener(com.github.games647.changeskin.bukkit.bungee.CheckPermissionListener)

Example 2 with NamespaceKey

use of com.github.games647.changeskin.core.message.NamespaceKey in project ChangeSkin by games647.

the class ChangeSkinBungee method onEnable.

@Override
public void onEnable() {
    logger = CommonUtil.createLoggerFromJDK(getLogger());
    core = new ChangeSkinCore(this);
    try {
        core.load(true);
    } catch (Exception ioExc) {
        logger.error("Error initializing plugin. Disabling...", ioExc);
        return;
    }
    PluginManager pluginManager = getProxy().getPluginManager();
    pluginManager.registerListener(this, new ConnectListener(this));
    pluginManager.registerListener(this, new ServerSwitchListener(this));
    // this is required to listen to incoming messages from the server
    getProxy().registerChannel(new NamespaceKey(getName(), PERMISSION_RESULT_CHANNEL).getCombinedName());
    getProxy().registerChannel(new NamespaceKey(getName(), FORWARD_COMMAND_CHANNEL).getCombinedName());
    pluginManager.registerListener(this, new PluginMessageListener(this));
    // register commands
    pluginManager.registerCommand(this, new SetCommand(this));
    pluginManager.registerCommand(this, new InvalidateCommand(this));
    pluginManager.registerCommand(this, new UploadCommand(this));
    pluginManager.registerCommand(this, new SelectCommand(this));
    pluginManager.registerCommand(this, new InfoCommand(this));
}
Also used : PluginManager(net.md_5.bungee.api.plugin.PluginManager) ChangeSkinCore(com.github.games647.changeskin.core.ChangeSkinCore) NamespaceKey(com.github.games647.changeskin.core.message.NamespaceKey) ServerSwitchListener(com.github.games647.changeskin.bungee.listener.ServerSwitchListener) UploadCommand(com.github.games647.changeskin.bungee.command.UploadCommand) InfoCommand(com.github.games647.changeskin.bungee.command.InfoCommand) PluginMessageListener(com.github.games647.changeskin.bungee.listener.PluginMessageListener) SelectCommand(com.github.games647.changeskin.bungee.command.SelectCommand) ConnectListener(com.github.games647.changeskin.bungee.listener.ConnectListener) InvalidateCommand(com.github.games647.changeskin.bungee.command.InvalidateCommand) SetCommand(com.github.games647.changeskin.bungee.command.SetCommand)

Example 3 with NamespaceKey

use of com.github.games647.changeskin.core.message.NamespaceKey in project FastLogin by games647.

the class BungeeManager method sendPluginMessage.

public void sendPluginMessage(PluginMessageRecipient player, ChannelMessage message) {
    if (player != null) {
        ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
        message.writeTo(dataOutput);
        NamespaceKey channel = new NamespaceKey(plugin.getName(), message.getChannelName());
        player.sendPluginMessage(plugin, channel.getCombinedName(), dataOutput.toByteArray());
    }
}
Also used : NamespaceKey(com.github.games647.fastlogin.core.message.NamespaceKey) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput)

Example 4 with NamespaceKey

use of com.github.games647.changeskin.core.message.NamespaceKey in project FastLogin by games647.

the class BungeeManager method registerPluginChannels.

private void registerPluginChannels() {
    Server server = Bukkit.getServer();
    // check for incoming messages from the bungeecord version of this plugin
    String groupId = plugin.getName();
    String forceChannel = NamespaceKey.getCombined(groupId, LoginActionMessage.FORCE_CHANNEL);
    server.getMessenger().registerIncomingPluginChannel(plugin, forceChannel, new BungeeListener(plugin));
    // outgoing
    String successChannel = new NamespaceKey(groupId, SUCCESS_CHANNEL).getCombinedName();
    String changeChannel = new NamespaceKey(groupId, CHANGE_CHANNEL).getCombinedName();
    server.getMessenger().registerOutgoingPluginChannel(plugin, successChannel);
    server.getMessenger().registerOutgoingPluginChannel(plugin, changeChannel);
}
Also used : NamespaceKey(com.github.games647.fastlogin.core.message.NamespaceKey) Server(org.bukkit.Server) BungeeListener(com.github.games647.fastlogin.bukkit.listener.BungeeListener)

Example 5 with NamespaceKey

use of com.github.games647.changeskin.core.message.NamespaceKey in project ChangeSkin by games647.

the class ChangeSkinSponge method onInit.

@Listener
public void onInit(GameInitializationEvent initEvent) {
    if (!initialized)
        return;
    CommandManager cmdManager = Sponge.getCommandManager();
    // command and event register
    cmdManager.register(this, injector.getInstance(SelectCommand.class).buildSpec(), "skin-select", "skinselect");
    cmdManager.register(this, injector.getInstance(InfoCommand.class).buildSpec(), "skin-info");
    cmdManager.register(this, injector.getInstance(UploadCommand.class).buildSpec(), "skin-upload");
    cmdManager.register(this, injector.getInstance(SetCommand.class).buildSpec(), "changeskin", "setskin", "skin");
    cmdManager.register(this, injector.getInstance(InvalidateCommand.class).buildSpec(), "skininvalidate", "skin-invalidate");
    Sponge.getEventManager().registerListeners(this, injector.getInstance(LoginListener.class));
    // incoming channel
    ChannelRegistrar channelReg = Sponge.getChannelRegistrar();
    String updateChannelName = new NamespaceKey(ARTIFACT_ID, UPDATE_SKIN_CHANNEL).getCombinedName();
    String permissionChannelName = new NamespaceKey(ARTIFACT_ID, CHECK_PERM_CHANNEL).getCombinedName();
    RawDataChannel updateChannel = channelReg.getOrCreateRaw(this, updateChannelName);
    RawDataChannel permChannel = channelReg.getOrCreateRaw(this, permissionChannelName);
    updateChannel.addListener(Type.SERVER, injector.getInstance(UpdateSkinListener.class));
    permChannel.addListener(Type.SERVER, injector.getInstance(CheckPermissionListener.class));
}
Also used : NamespaceKey(com.github.games647.changeskin.core.message.NamespaceKey) CommandManager(org.spongepowered.api.command.CommandManager) ChannelRegistrar(org.spongepowered.api.network.ChannelRegistrar) UpdateSkinListener(com.github.games647.changeskin.sponge.bungee.UpdateSkinListener) RawDataChannel(org.spongepowered.api.network.ChannelBinding.RawDataChannel) CheckPermissionListener(com.github.games647.changeskin.sponge.bungee.CheckPermissionListener) CheckPermissionListener(com.github.games647.changeskin.sponge.bungee.CheckPermissionListener) UpdateSkinListener(com.github.games647.changeskin.sponge.bungee.UpdateSkinListener) Listener(org.spongepowered.api.event.Listener)

Aggregations

NamespaceKey (com.github.games647.changeskin.core.message.NamespaceKey)5 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)4 NamespaceKey (com.github.games647.fastlogin.core.message.NamespaceKey)3 CheckPermissionListener (com.github.games647.changeskin.bukkit.bungee.CheckPermissionListener)1 SkinUpdateListener (com.github.games647.changeskin.bukkit.bungee.SkinUpdateListener)1 InfoCommand (com.github.games647.changeskin.bungee.command.InfoCommand)1 InvalidateCommand (com.github.games647.changeskin.bungee.command.InvalidateCommand)1 SelectCommand (com.github.games647.changeskin.bungee.command.SelectCommand)1 SetCommand (com.github.games647.changeskin.bungee.command.SetCommand)1 UploadCommand (com.github.games647.changeskin.bungee.command.UploadCommand)1 ConnectListener (com.github.games647.changeskin.bungee.listener.ConnectListener)1 PluginMessageListener (com.github.games647.changeskin.bungee.listener.PluginMessageListener)1 ServerSwitchListener (com.github.games647.changeskin.bungee.listener.ServerSwitchListener)1 ChangeSkinCore (com.github.games647.changeskin.core.ChangeSkinCore)1 CheckPermissionListener (com.github.games647.changeskin.sponge.bungee.CheckPermissionListener)1 UpdateSkinListener (com.github.games647.changeskin.sponge.bungee.UpdateSkinListener)1 BungeeListener (com.github.games647.fastlogin.bukkit.listener.BungeeListener)1 PluginManager (net.md_5.bungee.api.plugin.PluginManager)1 Server (org.bukkit.Server)1 Messenger (org.bukkit.plugin.messaging.Messenger)1