예제 #1
0
 /**
  * Callback for the plugin channel hook
  *
  * @param hookPluginChannels
  */
 public void onPluginChannelMessage(HookPluginChannels hookPluginChannels) {
   if (hookPluginChannels != null
       && hookPluginChannels.channel != null
       && pluginChannels.containsKey(hookPluginChannels.channel)) {
     for (PluginChannelListener pluginChannelListener :
         pluginChannels.get(hookPluginChannels.channel)) {
       try {
         pluginChannelListener.onCustomPayload(
             hookPluginChannels.channel, hookPluginChannels.length, hookPluginChannels.data);
       } catch (Exception ex) {
       }
     }
   }
 }
예제 #2
0
  /** Query loaded mods for registered channels */
  protected void setupPluginChannels() {
    // Clear any channels from before
    pluginChannels.clear();

    // Enumerate mods for plugin channels
    for (PluginChannelListener pluginChannelListener : pluginChannelListeners) {
      List<String> channels = pluginChannelListener.getChannels();

      if (channels != null) {
        for (String channel : channels) {
          if (channel.length() > 16
              || channel.toUpperCase().equals("REGISTER")
              || channel.toUpperCase().equals("UNREGISTER")) continue;

          if (!pluginChannels.containsKey(channel)) {
            pluginChannels.put(channel, new LinkedList<PluginChannelListener>());
          }

          pluginChannels.get(channel).add(pluginChannelListener);
        }
      }
    }

    // If any mods have registered channels, send the REGISTER packet
    if (pluginChannels.keySet().size() > 0) {
      StringBuilder channelList = new StringBuilder();
      boolean separator = false;

      for (String channel : pluginChannels.keySet()) {
        if (separator) channelList.append("\u0000");
        channelList.append(channel);
        separator = true;
      }

      byte[] registrationData = channelList.toString().getBytes(Charset.forName("UTF8"));

      sendPluginChannelMessage("REGISTER", registrationData);
    }
  }