Ejemplo n.º 1
0
 /**
  * Loads a channel from the specified name.
  *
  * @param name to load
  */
 public Channel load(String name) {
   Channel channel = new Channel(plugin, name);
   String path = "channels." + name;
   // Don't write everything back to disk we are loading
   channel.setAutoSave(false);
   // Set properties
   channel.setRadius(getNode(path + ".radius").getInt());
   channel.setInviteOnly(getNode(path + ".invite-only").getBoolean());
   channel.setPassword(getNode(path + ".password").getString());
   channel.setJoinMessage(
       ChatArguments.fromFormatString(getNode(path + ".join-message").getString()));
   channel.setLeaveMessage(
       ChatArguments.fromFormatString(getNode(path + ".leave-message").getString()));
   channel.setFormat(ChatArguments.fromFormatString(getNode(path + ".format").getString()));
   channel.setBanMessage(
       ChatArguments.fromFormatString(getNode(path + ".ban-message").getString()));
   channel.setIrcEnabled(getNode(path + ".irc.enabled").getBoolean());
   IrcBot bot = plugin.getBots().get(getNode(path + ".irc.bot").getString());
   if (bot != null) {
     channel.connectToIrc(bot);
   }
   for (String b : getNode(path + ".banned").getStringList()) {
     channel.ban(b, false);
   }
   for (String m : getNode(path + ".muted").getStringList()) {
     channel.mute(m);
   }
   for (String c : getNode(path + ".censored-words").getKeys(false)) {
     channel.censor(c, getNode(path + ".censored-words." + c).getString());
   }
   // Turn auto-save back on
   channel.setAutoSave(true);
   channels.add(channel);
   return channel;
 }
Ejemplo n.º 2
0
 public void postLoad(Channel channel) {
   String path = "channels." + channel.getName();
   for (String n : getNode(path + ".listeners").getStringList()) {
     Chatter chatter = plugin.getChatters().get(n);
     if (chatter == null) {
       continue;
     }
     channel.addListener(chatter);
   }
 }
Ejemplo n.º 3
0
 /**
  * Broadcasts a message to all listeners of the channel.
  *
  * @param message
  */
 public void broadcast(Chatter sender, ChatArguments message) {
   ChannelBroadcastEvent event =
       plugin
           .getEngine()
           .getEventManager()
           .callEvent(new ChannelBroadcastEvent(this, sender, message));
   sender = event.getSender();
   message = event.getMessage();
   Placeholders.format(Placeholders.MESSAGE, format, message);
   for (Chatter chatter : listeners) {
     if (sender != null && !chatter.canHear(sender, this)) {
       continue;
     }
     chatter.getParent().sendMessage(format);
   }
   if (bot != null && ircEnabled) {
     bot.sendMessage(message);
   }
   plugin.getChatLogger().log(message);
 }
Ejemplo n.º 4
0
 /**
  * Unbans a name from the channel.
  *
  * @param name
  */
 public void unban(String name) {
   ChannelUnbanEvent event =
       plugin.getEngine().getEventManager().callEvent(new ChannelUnbanEvent(this, name));
   if (event.isCancelled()) {
     return;
   }
   banned.remove(event.getName());
   if (autoSave) {
     save();
   }
 }
Ejemplo n.º 5
0
 /**
  * Censors a word in the channel
  *
  * @param word
  * @param replacement
  */
 public void censor(String word, String replacement) {
   ChannelCensorEvent event =
       plugin
           .getEngine()
           .getEventManager()
           .callEvent(new ChannelCensorEvent(this, word, replacement));
   censoredWords.put(event.getWord().toLowerCase(), event.getReplacement());
   if (autoSave) {
     save();
   }
 }
Ejemplo n.º 6
0
 /**
  * Bans a name from the channel
  *
  * @param name of chatter
  * @param kick whether to kick if online
  * @param reason for kick
  */
 public void ban(String name, boolean kick, ChatArguments reason) {
   ChannelBanEvent event =
       plugin
           .getEngine()
           .getEventManager()
           .callEvent(new ChannelBanEvent(this, name, kick, reason));
   if (event.isCancelled()) {
     return;
   }
   name = event.getName();
   if (event.isKicked()) {
     Chatter chatter = plugin.getChatters().get(name);
     if (chatter == null) {
       return;
     }
     chatter.kick(this, event.getReason());
   }
   banned.add(name);
   if (autoSave) {
     save();
   }
 }
Ejemplo n.º 7
0
 /**
  * Allows the chatter to chat in the channel.
  *
  * @param name
  */
 public void unmute(String name) {
   ChannelMuteChangeEvent event =
       plugin
           .getEngine()
           .getEventManager()
           .callEvent(new ChannelMuteChangeEvent(this, name, false));
   name = event.getName();
   if (event.isMuted()) {
     mute(name);
     return;
   }
   muted.remove(name);
   if (autoSave) {
     save();
   }
 }
Ejemplo n.º 8
0
 /** Constructs a new ChannelConfiguration at 'plugins/WindChat/channels.yml'. */
 public ChannelConfiguration(WindChat plugin) {
   super(new File(plugin.getDataFolder(), "channels.yml"));
   this.plugin = plugin;
 }
Ejemplo n.º 9
0
 /** Saves the channel to disk */
 public void save() {
   plugin.getChannels().save(this);
 }