Initial support for auto join channels

This commit is contained in:
Marco Cunha committed 2012-08-25 16:11:09 +02:00
1 parent 091dc495d4
commit 59f3edf7a2
3 files changed
+38 -4

No files matched your search

@@ -1,12 +1,10 @@
package com.palmergames.bukkit.TownyChat.channels;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public abstract class Channel {
@@ -17,6 +15,7 @@ public abstract class Channel {
private String channelTag, messageColour, permission, leavePermission, craftIRCTag;
private double range;
private boolean hooked=false;
private boolean autojoin=true;
protected ConcurrentMap<String, Integer> absentPlayers = null;
protected ConcurrentMap<String, Integer> mutedPlayers = null;
@@ -130,7 +129,13 @@ public abstract class Channel {
* Used to reset channel settings for a given player
*/
public void forgetPlayer(String name) {
join(name);
// If the channel is auto join, they will be added
// If the channel is not auto join, they will marked as absent
if (autojoin) {
join(name);
} else {
leave(name);
}
}
/*
@@ -232,4 +237,12 @@ public abstract class Channel {
public boolean isHooked() {
return hooked;
}
public void setAutoJoin(boolean autojoin) {
this.autojoin = autojoin;
}
public boolean isAutoJoin() {
return autojoin;
}
}
@@ -88,6 +88,16 @@ public class ConfigurationHandler {
}
}
if (key.equalsIgnoreCase("autojoin")) {
if (element instanceof Boolean) {
channel.setAutoJoin((Boolean)element);
} else if (element instanceof String) {
channel.setAutoJoin(Boolean.parseBoolean(element.toString()));
} else if (element instanceof Integer) {
channel.setAutoJoin(Integer.parseInt(element.toString()) != 0);
}
}
if (key.equalsIgnoreCase("channeltag"))
if (element instanceof String)
channel.setChannelTag(element.toString());
@@ -8,6 +8,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import com.palmergames.bukkit.towny.TownyMessaging;
@@ -93,7 +94,17 @@ public class TownyChatPlayerListener implements Listener {
channel.forgetPlayer(name);
}
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(final PlayerJoinEvent event) {
String name = event.getPlayer().getName();
for (Channel channel : plugin.getChannelsHandler().getAllChannels().values()) {
// If the channel is auto join, they will be added
// If the channel is not auto join, they will marked as absent
channel.forgetPlayer(name);
}
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerChat(AsyncPlayerChatEvent event) {