// 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); } }
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); }
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); } }
// 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); }