Exemplo n.º 1
0
  // Events
  public void onPlayerLogin(ChatPlayer cp) {
    ((ChatChannel) getDefaultChannel()).connectWithoutBroadcast(cp.getPlayer().getName());

    if (cp.hasAutoJoin()) {
      if (cp.isJoinAllAvailableEnabled()) {
        ISMain.getChannelManager().joinAllAvailableChannels(cp);
      } else {
        List<String> channelNames = cp.getAutoJoinList();

        for (String channelName : channelNames) {
          List<Channel> l = matchChannel(channelName);

          if ((l.size() == 1) && (cp.canConnect((Channel) l.get(0), ""))) {
            ((ChatChannel) l.get(0)).connectWithoutBroadcast(cp.getPlayer().getName());
          }
        }
      }
    }

    getDefaultChannel().assignFocus(cp.getPlayer().getName(), true);

    if ((cp.getPlayer().isOp())
        && (cp.canConnect(ISMain.getChannelManager().getHelpOpChannel(), ""))) {
      getHelpOpChannel().addListener(cp.getPlayer().getName(), false);
    }
  }
Exemplo n.º 2
0
  public ChannelManager() {
    registerChannel(new DebugChannel());

    if (!configFile.exists()) {
      try {
        configFile.getParentFile().mkdirs();
        configFile.createNewFile();
        ISMain.log(
            "No channel config found... Created new config & internally writing default channels");
      } catch (IOException ex) {
        ISMain.log("Could not create channel config file: " + ex.getMessage(), 2);
      }

      writeDefaults();
    } else {
      YamlConfiguration channelConfig = ISMain.getChannelConfig();

      try {
        channelConfig.load(configFile);
      } catch (Throwable t) {
        ISMain.log("Could not load channels: " + t.getMessage(), 2);
        writeDefaults();
      }

      List<String> _channelList = channelConfig.getStringList("channels");

      for (String _channel : _channelList) {
        ChatChannel cc = new ChatChannel(_channel);
        registerChannel(cc);
      }

      for (Map.Entry<Channel, Boolean> entry : channels.entrySet()) {
        if (((ChatChannel) entry.getKey()).isDefault()) {
          this.def = entry.getKey();
          break;
        }
      }

      for (Map.Entry<Channel, Boolean> entry : channels.entrySet()) {
        if (((ChatChannel) entry.getKey()).isHelpOp()) {
          this.helpop = entry.getKey();
          break;
        }
      }
    }

    Bukkit.getScheduler()
        .scheduleAsyncRepeatingTask(ISMain.getInstance(), new MPMThread(), 0L, 1200L);
  }
Exemplo n.º 3
0
  public void saveChannels() {
    List<String> l = new LinkedList<String>();

    for (Map.Entry<Channel, Boolean> entry : channels.entrySet()) {
      l.add(entry.getKey().getName());
      entry.getKey().dump();
    }

    ISMain.getChannelConfig().set("channels", l);

    try {
      ISMain.getChannelConfig().save(configFile);
    } catch (IOException ex) {
      ISMain.log("Could not save channel config: " + ex.getMessage(), 2);
    }
  }
Exemplo n.º 4
0
  // ChatChannel stuff
  public void removeChannel(ChatChannel channel) {
    unregisterChannel(channel);

    for (Map.Entry<String, Boolean> listener : channel.listeners.entrySet()) {
      if (listener.getValue()) {
        if (!def.hasListener(listener.getKey())) {
          def.addListener(listener.getKey(), true);
        } else {
          def.assignFocus(listener.getKey(), true);
        }
      }
    }

    List<String> l = new LinkedList<String>();

    for (Map.Entry<Channel, Boolean> entry : channels.entrySet()) {
      if (entry.getKey().getName().equals(channel.getName())) continue;

      l.add(entry.getKey().getName());
    }

    ISMain.getChannelConfig().set("channels", l);
    ISMain.getChannelConfig().set(channel.getName(), null);
  }