mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-04 14:38:58 +00:00
Initial support for auto join channels
This commit is contained in:
1 parent
091dc495d4
commit
59f3edf7a2
3 files changed
+37
-3
No files matched your search
@@ -1,12 +1,10 @@
|
|||||||
package com.palmergames.bukkit.TownyChat.channels;
|
package com.palmergames.bukkit.TownyChat.channels;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
|
||||||
public abstract class Channel {
|
public abstract class Channel {
|
||||||
@@ -17,6 +15,7 @@ public abstract class Channel {
|
|||||||
private String channelTag, messageColour, permission, leavePermission, craftIRCTag;
|
private String channelTag, messageColour, permission, leavePermission, craftIRCTag;
|
||||||
private double range;
|
private double range;
|
||||||
private boolean hooked=false;
|
private boolean hooked=false;
|
||||||
|
private boolean autojoin=true;
|
||||||
protected ConcurrentMap<String, Integer> absentPlayers = null;
|
protected ConcurrentMap<String, Integer> absentPlayers = null;
|
||||||
protected ConcurrentMap<String, Integer> mutedPlayers = null;
|
protected ConcurrentMap<String, Integer> mutedPlayers = null;
|
||||||
|
|
||||||
@@ -130,7 +129,13 @@ public abstract class Channel {
|
|||||||
* Used to reset channel settings for a given player
|
* Used to reset channel settings for a given player
|
||||||
*/
|
*/
|
||||||
public void forgetPlayer(String name) {
|
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() {
|
public boolean isHooked() {
|
||||||
return hooked;
|
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 (key.equalsIgnoreCase("channeltag"))
|
||||||
if (element instanceof String)
|
if (element instanceof String)
|
||||||
channel.setChannelTag(element.toString());
|
channel.setChannelTag(element.toString());
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||||
@@ -94,6 +95,16 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user