mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-02 06:28:58 +00:00
merged mcunhas join/leave support
This commit is contained in:
commit
2d7decccce
17 files changed
+1168
-34
No files matched your search
@@ -10,7 +10,13 @@ import org.dynmap.DynmapAPI;
|
||||
|
||||
import com.ensifera.animosity.craftirc.CraftIRC;
|
||||
import com.palmergames.bukkit.TownyChat.CraftIRCHandler;
|
||||
import com.palmergames.bukkit.TownyChat.Command.ChannelCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.JoinCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.LeaveCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.MuteCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.MuteListCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.UnmuteCommand;
|
||||
import com.palmergames.bukkit.TownyChat.channels.ChannelsHolder;
|
||||
import com.palmergames.bukkit.TownyChat.config.ConfigurationHandler;
|
||||
import com.palmergames.bukkit.TownyChat.listener.HeroicDeathForwarder;
|
||||
@@ -68,7 +74,12 @@ public class Chat extends JavaPlugin {
|
||||
}
|
||||
|
||||
getCommand("townychat").setExecutor(new TownyChatCommand(this));
|
||||
|
||||
getCommand("channel").setExecutor(new ChannelCommand(this));
|
||||
getCommand("join").setExecutor(new JoinCommand(this));
|
||||
getCommand("leave").setExecutor(new LeaveCommand(this));
|
||||
getCommand("chmute").setExecutor(new MuteCommand(this));
|
||||
getCommand("chunmute").setExecutor(new UnmuteCommand(this));
|
||||
getCommand("mutelist").setExecutor(new MuteListCommand(this));
|
||||
}
|
||||
|
||||
private boolean load() {
|
||||
@@ -209,5 +220,4 @@ public class Chat extends JavaPlugin {
|
||||
public HeroicDeathForwarder getHeroicDeath() {
|
||||
return heroicDeathListener;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.palmergames.bukkit.TownyChat.Command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
|
||||
public class ChannelCommand implements CommandExecutor {
|
||||
|
||||
Chat plugin = null;
|
||||
|
||||
public ChannelCommand(Chat instance) {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (!label.equalsIgnoreCase("ch") && !label.equalsIgnoreCase("channel")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("join")) {
|
||||
return plugin.getCommand("join").getExecutor().onCommand(sender, cmd, label, args);
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("leave")) {
|
||||
return plugin.getCommand("leave").getExecutor().onCommand(sender, cmd, label, args);
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("mute")) {
|
||||
return plugin.getCommand("chmute").getExecutor().onCommand(sender, cmd, label, args);
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("unmute")) {
|
||||
return plugin.getCommand("chunmute").getExecutor().onCommand(sender, cmd, label, args);
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("mutelist")) {
|
||||
return plugin.getCommand("mutelist").getExecutor().onCommand(sender, cmd, label, args);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.palmergames.bukkit.TownyChat.Command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import com.palmergames.bukkit.util.Colors;
|
||||
|
||||
public class JoinCommand implements CommandExecutor {
|
||||
|
||||
Chat plugin = null;
|
||||
|
||||
public JoinCommand(Chat instance) {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
// If not our command
|
||||
if ((!label.equalsIgnoreCase("join") || args.length != 1) &&
|
||||
(!label.equalsIgnoreCase("ch") || args.length != 2 || !args[0].equalsIgnoreCase("join"))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] Error: Invalid command!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
return false; // Don't think it can happen but ...
|
||||
}
|
||||
|
||||
Player player = ((Player)sender);
|
||||
|
||||
String name = null;
|
||||
if (label.equalsIgnoreCase("join")){
|
||||
name = args[0];
|
||||
} else {
|
||||
name = args[1];
|
||||
}
|
||||
|
||||
Channel chan = plugin.getChannelsHandler().getChannel(name);
|
||||
|
||||
// If we can't find the channel by name, look up all the channel commands for an alias
|
||||
if (chan == null) {
|
||||
for(Channel chan2 : plugin.getChannelsHandler().getAllChannels().values()) {
|
||||
for (String command : chan2.getCommands()) {
|
||||
if (command.equalsIgnoreCase(name)) {
|
||||
chan = chan2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (chan != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chan == null) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] There is no channel called " + Colors.White + name);
|
||||
return true;
|
||||
}
|
||||
|
||||
// You can join if:
|
||||
// - Towny doesn't recognize your permissions plugin
|
||||
// - channel has no permission set OR [by default they don't]
|
||||
// - channel has permission set AND:
|
||||
// - player has channel permission
|
||||
String joinPerm = chan.getPermission();
|
||||
if ((joinPerm != null && (plugin.getTowny().isPermissions() && !TownyUniverse.getPermissionSource().has(player, joinPerm)))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] You cannot join " + Colors.White + chan.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!chan.join(sender.getName())){
|
||||
TownyMessaging.sendMsg(sender, "[TownyChat] You are already in " + Colors.White + chan.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
TownyMessaging.sendMsg(sender, "[TownyChat] You joined " + Colors.White + chan.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.palmergames.bukkit.TownyChat.Command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.TownyChat.channels.channelTypes;
|
||||
import com.palmergames.bukkit.TownyChat.util.TownyUtil;
|
||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import com.palmergames.bukkit.util.Colors;
|
||||
|
||||
public class LeaveCommand implements CommandExecutor {
|
||||
|
||||
Chat plugin = null;
|
||||
|
||||
public LeaveCommand(Chat instance) {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
// If not our command
|
||||
if ((!label.equalsIgnoreCase("leave") || args.length != 1) &&
|
||||
(!label.equalsIgnoreCase("ch") || args.length != 2 || !args[0].equalsIgnoreCase("leave"))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] Error: Invalid command!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
return false; // Don't think it can happen but ...
|
||||
}
|
||||
|
||||
Player player = ((Player)sender);
|
||||
|
||||
String name = null;
|
||||
if (label.equalsIgnoreCase("leave")){
|
||||
name = args[0];
|
||||
} else {
|
||||
name = args[1];
|
||||
}
|
||||
|
||||
Channel chan = plugin.getChannelsHandler().getChannel(name);
|
||||
|
||||
// If we can't find the channel by name, look up all the channel commands for an alias
|
||||
if (chan == null) {
|
||||
for(Channel chan2 : plugin.getChannelsHandler().getAllChannels().values()) {
|
||||
for (String command : chan2.getCommands()) {
|
||||
if (command.equalsIgnoreCase(name)) {
|
||||
chan = chan2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (chan != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chan == null) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] There is no channel called " + Colors.White + name);
|
||||
return true;
|
||||
}
|
||||
|
||||
// You can leave if:
|
||||
// - Towny recognizes your permissions plugin AND
|
||||
// - channel has leaving permission set AND [by default they always do and you can provide your own permission name]
|
||||
// - player has leaving permission set [by default they don't]
|
||||
String leavePerm = chan.getLeavePermission();
|
||||
if ( leavePerm == null ||
|
||||
( leavePerm != null && ( !plugin.getTowny().isPermissions() ||
|
||||
( plugin.getTowny().isPermissions() && !TownyUniverse.getPermissionSource().has( player, leavePerm ) )))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] You cannot leave " + Colors.White + chan.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we fail you weren't in there to start with
|
||||
if (!chan.leave(sender.getName())){
|
||||
TownyMessaging.sendMsg(sender, "[TownyChat] You already left " + Colors.White + chan.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Announce it
|
||||
TownyMessaging.sendMsg(sender, "[TownyChat] You left " + Colors.White + chan.getName());
|
||||
|
||||
// Find what the next channel is if any
|
||||
Channel nextChannel = null;
|
||||
if (plugin.getTowny().hasPlayerMode(player, chan.getName())) {
|
||||
if (plugin.getChannelsHandler().getDefaultChannel() != null && plugin.getChannelsHandler().getDefaultChannel().isPresent(player.getName())) {
|
||||
nextChannel = plugin.getChannelsHandler().getDefaultChannel();
|
||||
TownyUtil.removeAndSetPlayerMode(plugin.getTowny(), player, chan.getName(), nextChannel.getName(), true);
|
||||
}
|
||||
}
|
||||
if (nextChannel == null) {
|
||||
nextChannel = plugin.getChannelsHandler().getActiveChannel(player, channelTypes.GLOBAL);
|
||||
}
|
||||
|
||||
// If the new channel is not us, announce it
|
||||
if (nextChannel != null && !chan.getName().equalsIgnoreCase(nextChannel.getName())) {
|
||||
TownyMessaging.sendMsg(sender, "[TownyChat] You are now talking in " + Colors.White + nextChannel.getName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.palmergames.bukkit.TownyChat.Command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import com.palmergames.bukkit.util.Colors;
|
||||
|
||||
public class MuteCommand implements CommandExecutor {
|
||||
|
||||
Chat plugin = null;
|
||||
|
||||
public MuteCommand(Chat instance) {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
// If not our command
|
||||
if ((!label.equalsIgnoreCase("mute") || args.length != 2) &&
|
||||
(!label.equalsIgnoreCase("chmute") || args.length != 2) &&
|
||||
(!label.equalsIgnoreCase("ch") || args.length != 3 || !args[0].equalsIgnoreCase("mute"))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] Error: Invalid command!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
return false; // Don't think it can happen but ...
|
||||
}
|
||||
|
||||
Player player = ((Player)sender);
|
||||
|
||||
String channelName = null;
|
||||
String mutee = null;
|
||||
if (label.equalsIgnoreCase("chmute") || label.equalsIgnoreCase("mute")){
|
||||
channelName = args[0];
|
||||
mutee = args[1];
|
||||
} else {
|
||||
channelName = args[1];
|
||||
mutee = args[2];
|
||||
}
|
||||
|
||||
String mutePerm = plugin.getChannelsHandler().getMutePermission();
|
||||
if ((mutePerm == null) || (mutePerm != null && (plugin.getTowny().isPermissions() && !TownyUniverse.getPermissionSource().has(player, mutePerm)))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] You don't have mute permissions");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player muteePlayer = plugin.getServer().getPlayer(mutee);
|
||||
if (muteePlayer == null) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] There are no online players with name " + Colors.White + mutee);
|
||||
return true;
|
||||
}
|
||||
|
||||
mutee = muteePlayer.getName();
|
||||
|
||||
if (plugin.getTowny().isPermissions() && TownyUniverse.getPermissionSource().isTownyAdmin(muteePlayer)){
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] You can't mute a Towny administrator.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String unmutePerm = plugin.getChannelsHandler().getUnmutePermission();
|
||||
if ((mutePerm != null && (plugin.getTowny().isPermissions() && TownyUniverse.getPermissionSource().has(muteePlayer, mutePerm))) ||
|
||||
(unmutePerm != null && (plugin.getTowny().isPermissions() && TownyUniverse.getPermissionSource().has(muteePlayer, unmutePerm)))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] You can't mute a chat moderator.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Channel chan = plugin.getChannelsHandler().getChannel(channelName);
|
||||
|
||||
// If we can't find the channel by name, look up all the channel commands for an alias
|
||||
if (chan == null) {
|
||||
for(Channel chan2 : plugin.getChannelsHandler().getAllChannels().values()) {
|
||||
for (String command : chan2.getCommands()) {
|
||||
if (command.equalsIgnoreCase(channelName)) {
|
||||
chan = chan2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (chan != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chan == null) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] There is no channel called " + Colors.White + channelName);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (!chan.mute(mutee)) {
|
||||
TownyMessaging.sendMsg(sender, "[TownyChat] Player is already muted in "+ Colors.White + chan.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
TownyMessaging.sendMsg(sender, "[TownyChat] " + Colors.White + mutee + Colors.Green +" is now muted in "+ Colors.White + chan.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.palmergames.bukkit.TownyChat.Command;
|
||||
|
||||
import java.util.Iterator;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import com.palmergames.bukkit.util.Colors;
|
||||
|
||||
public class MuteListCommand implements CommandExecutor {
|
||||
|
||||
Chat plugin = null;
|
||||
|
||||
public MuteListCommand(Chat instance) {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
// If not our command
|
||||
if ((!label.equalsIgnoreCase("mutelist") || args.length != 1) &&
|
||||
(!label.equalsIgnoreCase("ch") || args.length != 2 || !args[0].equalsIgnoreCase("mutelist"))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] Error: Invalid command!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
return false; // Don't think it can happen but ...
|
||||
}
|
||||
|
||||
Player player = ((Player)sender);
|
||||
|
||||
String name = null;
|
||||
if (label.equalsIgnoreCase("mutelist")){
|
||||
name = args[0];
|
||||
} else {
|
||||
name = args[1];
|
||||
}
|
||||
|
||||
String mutePerm = plugin.getChannelsHandler().getMutePermission();
|
||||
String unmutePerm = plugin.getChannelsHandler().getUnmutePermission();
|
||||
if ((mutePerm == null && unmutePerm == null) ||
|
||||
(mutePerm != null && (plugin.getTowny().isPermissions() && !TownyUniverse.getPermissionSource().has(player, mutePerm))) ||
|
||||
(unmutePerm != null && (plugin.getTowny().isPermissions() && !TownyUniverse.getPermissionSource().has(player, unmutePerm)))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] You don't have permissions to see mute list");
|
||||
return true;
|
||||
}
|
||||
|
||||
Channel chan = plugin.getChannelsHandler().getChannel(name);
|
||||
|
||||
// If we can't find the channel by name, look up all the channel commands for an alias
|
||||
if (chan == null) {
|
||||
for(Channel chan2 : plugin.getChannelsHandler().getAllChannels().values()) {
|
||||
for (String command : chan2.getCommands()) {
|
||||
if (command.equalsIgnoreCase(name)) {
|
||||
chan = chan2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (chan != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chan == null) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] There is no channel called " + Colors.White + name);
|
||||
return true;
|
||||
}
|
||||
|
||||
name = chan.getName();
|
||||
|
||||
// TODO Support paging through this list
|
||||
int count = 0;
|
||||
String players = "";
|
||||
|
||||
if (chan.hasMuteList()) {
|
||||
Iterator<String> iter = chan.getMuteList().iterator();
|
||||
boolean first = true;
|
||||
while(iter.hasNext()) {
|
||||
if (!first) {
|
||||
players += Colors.Green + ", "+ Colors.White;
|
||||
}
|
||||
players += iter.next();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
TownyMessaging.sendMsg(sender, "[TownyChat] There are no muted playeers in " + Colors.White + chan.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
String msg = "[TownyChat] " + Colors.White + count + Colors.Green + " players muted in " + Colors.White + chan.getName() + Colors.Green + ": " + Colors.White + players;
|
||||
|
||||
TownyMessaging.sendMsg(sender, msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.palmergames.bukkit.TownyChat.Command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import com.palmergames.bukkit.util.Colors;
|
||||
|
||||
public class UnmuteCommand implements CommandExecutor {
|
||||
|
||||
Chat plugin = null;
|
||||
|
||||
public UnmuteCommand(Chat instance) {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
// If not our command
|
||||
if ((!label.equalsIgnoreCase("unmute") || args.length != 2) &&
|
||||
(!label.equalsIgnoreCase("chunmute") || args.length != 2) &&
|
||||
(!label.equalsIgnoreCase("ch") || args.length != 3 || !args[0].equalsIgnoreCase("unmute"))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] Error: Invalid command!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
return false; // Don't think it can happen but ...
|
||||
}
|
||||
|
||||
Player player = ((Player)sender);
|
||||
|
||||
String channelName = null;
|
||||
String mutee = null;
|
||||
if (label.equalsIgnoreCase("chunmute") || label.equalsIgnoreCase("unmute")){
|
||||
channelName = args[0];
|
||||
mutee = args[1];
|
||||
} else {
|
||||
channelName = args[1];
|
||||
mutee = args[2];
|
||||
}
|
||||
|
||||
String unmutePerm = plugin.getChannelsHandler().getUnmutePermission();
|
||||
if ((unmutePerm == null) || (unmutePerm != null && (plugin.getTowny().isPermissions() && !TownyUniverse.getPermissionSource().has(player, unmutePerm)))) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] You don't have unmute permissions");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player muteePlayer = plugin.getServer().getPlayer(mutee);
|
||||
if (muteePlayer == null) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] There are no online players with name " + Colors.White + mutee);
|
||||
return true;
|
||||
}
|
||||
|
||||
mutee = muteePlayer.getName();
|
||||
|
||||
Channel chan = plugin.getChannelsHandler().getChannel(channelName);
|
||||
|
||||
// If we can't find the channel by name, look up all the channel commands for an alias
|
||||
if (chan == null) {
|
||||
for(Channel chan2 : plugin.getChannelsHandler().getAllChannels().values()) {
|
||||
for (String command : chan2.getCommands()) {
|
||||
if (command.equalsIgnoreCase(channelName)) {
|
||||
chan = chan2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (chan != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chan == null) {
|
||||
TownyMessaging.sendErrorMsg(sender, "[TownyChat] There is no channel called " + Colors.White + channelName);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (!chan.unmute(mutee)) {
|
||||
TownyMessaging.sendMsg(sender, "[TownyChat] Player is not muted in "+ Colors.White + chan.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
TownyMessaging.sendMsg(sender, "[TownyChat] " + Colors.White + mutee + Colors.Green +" is now unmuted in "+ Colors.White + chan.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.palmergames.bukkit.TownyChat.channels;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
@@ -9,8 +12,12 @@ public abstract class Channel {
|
||||
private String name;
|
||||
private List<String> commands;
|
||||
private channelTypes type;
|
||||
private String channelTag, messageColour, permission, craftIRCTag;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -118,4 +125,124 @@ public abstract class Channel {
|
||||
*/
|
||||
public abstract void chatProcess(AsyncPlayerChatEvent event);
|
||||
|
||||
/*
|
||||
* Used to reset channel settings for a given player
|
||||
*/
|
||||
public void forgetPlayer(String 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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Mark a player as having left chat
|
||||
*/
|
||||
public boolean leave(String name) {
|
||||
if (absentPlayers == null) {
|
||||
absentPlayers = new ConcurrentHashMap<String, Integer> ();
|
||||
}
|
||||
Integer res = absentPlayers.put(name, 1);
|
||||
return (res == null || res == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Mark a player has having joined the chat
|
||||
*/
|
||||
public boolean join(String name) {
|
||||
if (absentPlayers == null) return false;
|
||||
Integer res = absentPlayers.remove(name);
|
||||
return (res != null && res == 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if a player is present in a chat
|
||||
*/
|
||||
public boolean isPresent(String name) {
|
||||
if (absentPlayers == null) return true;
|
||||
if (absentPlayers.containsKey(name)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if a player is not present in a chat
|
||||
*/
|
||||
public boolean isAbsent(String name) {
|
||||
return !isPresent(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if a player is muted in a channel
|
||||
*/
|
||||
public boolean isMuted(String name) {
|
||||
if (mutedPlayers == null) return false;
|
||||
if (!mutedPlayers.containsKey(name)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mute a player
|
||||
*/
|
||||
public boolean mute(String name) {
|
||||
if (mutedPlayers == null) {
|
||||
mutedPlayers = new ConcurrentHashMap<String, Integer> ();
|
||||
}
|
||||
Integer i = mutedPlayers.get(name);
|
||||
if (i != null) return false;
|
||||
mutedPlayers.put(name, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unmute a player
|
||||
*/
|
||||
public boolean unmute(String name) {
|
||||
if (mutedPlayers == null) return false;
|
||||
Integer i = mutedPlayers.get(name);
|
||||
if (i == null) return false;
|
||||
mutedPlayers.remove(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get name of permissions node to leave a the channel
|
||||
*/
|
||||
public String getLeavePermission() {
|
||||
return leavePermission;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set name of permissions node to leave a the channel
|
||||
*/
|
||||
public void setLeavePermission(String permission) {
|
||||
leavePermission = permission;;
|
||||
}
|
||||
|
||||
public boolean hasMuteList() {
|
||||
if (mutedPlayers == null || mutedPlayers.isEmpty()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set<String> getMuteList() {
|
||||
return mutedPlayers.keySet();
|
||||
}
|
||||
|
||||
public void setHooked(boolean hooked) {
|
||||
this.hooked = hooked;
|
||||
}
|
||||
|
||||
public boolean isHooked() {
|
||||
return hooked;
|
||||
}
|
||||
|
||||
public void setAutoJoin(boolean autojoin) {
|
||||
this.autojoin = autojoin;
|
||||
}
|
||||
|
||||
public boolean isAutoJoin() {
|
||||
return autojoin;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
public class ChannelsHolder {
|
||||
|
||||
private Chat plugin;
|
||||
private Channel defaultChan = null;
|
||||
|
||||
/** Constructor
|
||||
*
|
||||
@@ -27,6 +28,13 @@ public class ChannelsHolder {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void setDefaultChannel(Channel channel) {
|
||||
defaultChan = channel;
|
||||
}
|
||||
|
||||
public Channel getDefaultChannel() {
|
||||
return defaultChan;
|
||||
}
|
||||
|
||||
// Container for all channels
|
||||
private Map<String,Channel> channels = new HashMap<String,Channel>();
|
||||
@@ -83,6 +91,49 @@ public class ChannelsHolder {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find a channel we are able to talk in, and have not left, starting with the greatest range.
|
||||
*
|
||||
* @param player
|
||||
* @param type
|
||||
* @return channel or null if none.
|
||||
*/
|
||||
public Channel getActiveChannel(Player player, channelTypes type) {
|
||||
|
||||
Channel local = null;
|
||||
Channel global = null;
|
||||
Channel world = null;
|
||||
|
||||
String name = player.getName();
|
||||
|
||||
for (Channel channel: channels.values()) {
|
||||
if (!channel.isPresent(name)) continue;
|
||||
if (!channel.getType().equals(type)) continue;
|
||||
if (!plugin.getTowny().isPermissions() ||
|
||||
(plugin.getTowny().isPermissions() && ((TownyUniverse.getPermissionSource().has(player, channel.getPermission())) ||
|
||||
(channel.getPermission().isEmpty())))) {
|
||||
if (channel.getRange() == -1) {
|
||||
global = channel;
|
||||
} else if (channel.getRange() == 0) {
|
||||
world = channel;
|
||||
} else
|
||||
local = channel;
|
||||
}
|
||||
}
|
||||
|
||||
if (global != null)
|
||||
return global;
|
||||
|
||||
if (world != null)
|
||||
return world;
|
||||
|
||||
if (local != null)
|
||||
return local;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find a channel we are able to talk in, starting with the greatest range.
|
||||
*
|
||||
@@ -97,17 +148,16 @@ public class ChannelsHolder {
|
||||
Channel world = null;
|
||||
|
||||
for (Channel channel: channels.values()) {
|
||||
if (channel.getType().equals(type)) {
|
||||
if (!plugin.getTowny().isPermissions()
|
||||
|| (plugin.getTowny().isPermissions() && ((TownyUniverse.getPermissionSource().has(player, channel.getPermission()))
|
||||
|| (channel.getPermission().isEmpty())))) {
|
||||
if (channel.getRange() == -1) {
|
||||
global = channel;
|
||||
} else if (channel.getRange() == 0) {
|
||||
world = channel;
|
||||
} else
|
||||
local = channel;
|
||||
}
|
||||
if (!channel.getType().equals(type)) continue;
|
||||
if (!plugin.getTowny().isPermissions() ||
|
||||
(plugin.getTowny().isPermissions() && ((TownyUniverse.getPermissionSource().has(player, channel.getPermission())) ||
|
||||
(channel.getPermission().isEmpty())))) {
|
||||
if (channel.getRange() == -1) {
|
||||
global = channel;
|
||||
} else if (channel.getRange() == 0) {
|
||||
world = channel;
|
||||
} else
|
||||
local = channel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,5 +191,11 @@ public class ChannelsHolder {
|
||||
return perms;
|
||||
}
|
||||
|
||||
public String getMutePermission() {
|
||||
return "townychat.mod.mute";
|
||||
}
|
||||
|
||||
public String getUnmutePermission() {
|
||||
return "townychat.mod.unmute";
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.dynmap.DynmapAPI;
|
||||
@@ -15,7 +15,9 @@ import com.palmergames.bukkit.TownyChat.Chat;
|
||||
import com.palmergames.bukkit.TownyChat.CraftIRCHandler;
|
||||
import com.palmergames.bukkit.TownyChat.TownyChatFormatter;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||
import com.palmergames.bukkit.TownyChat.events.AsyncChatHookEvent;
|
||||
import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
|
||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
@@ -23,10 +25,12 @@ import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import com.palmergames.bukkit.util.BukkitTools;
|
||||
import com.palmergames.bukkit.util.Colors;
|
||||
|
||||
public class StandardChannel extends Channel {
|
||||
|
||||
private Chat plugin;
|
||||
|
||||
public StandardChannel(Chat instance, String name) {
|
||||
super(name);
|
||||
this.plugin = instance;
|
||||
@@ -52,7 +56,14 @@ public class StandardChannel extends Channel {
|
||||
// Not in a town/nation (doesn't matter which)
|
||||
}
|
||||
|
||||
|
||||
boolean notifyjoin = false;
|
||||
// If player sends a message to a channel it had left
|
||||
// tell the channel to add the player back
|
||||
if (isAbsent(player.getName())) {
|
||||
join(player.getName());
|
||||
notifyjoin = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieve the channel specific format
|
||||
* and compile a set of recipients
|
||||
@@ -112,6 +123,25 @@ public class StandardChannel extends Channel {
|
||||
event.getRecipients().clear();
|
||||
event.getRecipients().addAll(recipients);
|
||||
|
||||
if (isHooked()) {
|
||||
AsyncChatHookEvent hookEvent = new AsyncChatHookEvent(event, this);
|
||||
Bukkit.getServer().getPluginManager().callEvent(hookEvent);
|
||||
if (hookEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (hookEvent.isChanged()) {
|
||||
event.setMessage(hookEvent.getMessage());
|
||||
event.setFormat(hookEvent.getFormat());
|
||||
event.getRecipients().clear();
|
||||
event.getRecipients().addAll(hookEvent.getRecipients());
|
||||
}
|
||||
}
|
||||
|
||||
if (notifyjoin) {
|
||||
TownyMessaging.sendMsg(player, "You join " + Colors.White + getName());
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform any last channel specific functions
|
||||
* like logging this chat and relaying to IRC/Dynmap.
|
||||
@@ -214,7 +244,14 @@ public class StandardChannel extends Channel {
|
||||
// Failed to fetch user so ignore.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Spy's can leave channels and we'll respect that
|
||||
if (absentPlayers != null) {
|
||||
// Ignore players who have left this channel
|
||||
if (absentPlayers.containsKey(test.getName())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
recipients.add(test);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.TownyChat.channels.StandardChannel;
|
||||
@@ -77,7 +75,42 @@ public class ConfigurationHandler {
|
||||
if (key.equalsIgnoreCase("type"))
|
||||
if (element instanceof String)
|
||||
channel.setType(channelTypes.valueOf(element.toString()));
|
||||
|
||||
|
||||
if (key.equalsIgnoreCase("hooked")) {
|
||||
if (element instanceof Boolean) {
|
||||
channel.setHooked((Boolean)element);
|
||||
} else if (element instanceof String) {
|
||||
channel.setHooked(Boolean.parseBoolean(element.toString()));
|
||||
} else if (element instanceof Integer) {
|
||||
channel.setHooked(Integer.parseInt(element.toString()) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
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("default")) {
|
||||
boolean set = false;
|
||||
if (element instanceof Boolean) {
|
||||
set = (element != null && ((Boolean)element) == true);
|
||||
} else if (element instanceof String) {
|
||||
set = Boolean.parseBoolean((String)element);
|
||||
} else if (element instanceof Integer) {
|
||||
set = (element != null && ((Integer)element) != 0);
|
||||
}
|
||||
if (set) {
|
||||
plugin.getChannelsHandler().setDefaultChannel(channel);
|
||||
plugin.getLogger().info("Default Channel set to " + channel.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (key.equalsIgnoreCase("channeltag"))
|
||||
if (element instanceof String)
|
||||
channel.setChannelTag(element.toString());
|
||||
@@ -90,6 +123,10 @@ public class ConfigurationHandler {
|
||||
if (element instanceof String)
|
||||
channel.setPermission(element.toString());
|
||||
|
||||
if (key.equalsIgnoreCase("leavepermission"))
|
||||
if (element instanceof String)
|
||||
channel.setLeavePermission(element.toString());
|
||||
|
||||
if (key.equalsIgnoreCase("craftIRCTag"))
|
||||
if (element instanceof String)
|
||||
channel.setCraftIRCTag(element.toString());
|
||||
@@ -98,6 +135,10 @@ public class ConfigurationHandler {
|
||||
channel.setRange(Double.valueOf(element.toString()));
|
||||
}
|
||||
|
||||
// If no leave permission is set, create a default permission name
|
||||
if (channel.getLeavePermission() == null) {
|
||||
channel.setLeavePermission("towny.chat.leave." + channel.getName().toLowerCase());
|
||||
}
|
||||
plugin.getChannelsHandler().addChannel(channel);
|
||||
|
||||
//System.out.print("Channel: " + channel.getName() + " : Type : " + channel.getType().name());
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.palmergames.bukkit.TownyChat.events;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
|
||||
/*
|
||||
* Allows other plugins to hook into a chat message being accepted into any of the channels
|
||||
*/
|
||||
public class AsyncChatHookEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
protected AsyncPlayerChatEvent event = null;
|
||||
protected boolean changed = false;
|
||||
protected Channel channel=null;
|
||||
|
||||
public AsyncChatHookEvent(AsyncPlayerChatEvent event, Channel channel) {
|
||||
this.event = event;
|
||||
this.changed = false;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if the hooked event was changed
|
||||
*/
|
||||
public boolean isChanged() {
|
||||
return changed;
|
||||
}
|
||||
|
||||
/*
|
||||
* Informs TownyChat if the event was changed or not
|
||||
*/
|
||||
public void setChanged(boolean changed) {
|
||||
this.changed = changed;
|
||||
}
|
||||
|
||||
public AsyncPlayerChatEvent getAsyncPlayerChatEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return event.getFormat();
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return event.getMessage();
|
||||
}
|
||||
|
||||
public Set<Player> getRecipients() {
|
||||
return event.getRecipients();
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return event.getPlayer();
|
||||
}
|
||||
|
||||
public void setRecipients(Set<Player> recipients) {
|
||||
changed = true;
|
||||
event.getRecipients().clear();
|
||||
event.getRecipients().addAll(recipients);
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
changed = true;
|
||||
event.setFormat(format);
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
changed = true;
|
||||
event.setFormat(message);
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancel) {
|
||||
changed = (cancel == true);
|
||||
event.setCancelled(cancel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -8,18 +8,23 @@ 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;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.TownyChat.channels.channelTypes;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||
import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
|
||||
import com.palmergames.bukkit.TownyChat.tasks.onPlayerJoinTask;
|
||||
import com.palmergames.bukkit.TownyChat.util.TownyUtil;
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
import com.palmergames.bukkit.TownyChat.TownyChatFormatter;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import com.palmergames.bukkit.util.Colors;
|
||||
import com.palmergames.util.StringMgmt;
|
||||
|
||||
public class TownyChatPlayerListener implements Listener {
|
||||
@@ -32,6 +37,38 @@ public class TownyChatPlayerListener implements Listener {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String name = player.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
|
||||
// TODO: Only do this for channels the user has permissions for
|
||||
channel.forgetPlayer(name);
|
||||
}
|
||||
Channel channel = plugin.getChannelsHandler().getDefaultChannel();
|
||||
if (channel != null) {
|
||||
// See if we have permissions for the default channel
|
||||
channel = plugin.getChannelsHandler().getChannel(player, channel.getCommands().get(0));
|
||||
if (channel != null) {
|
||||
// Schedule it as delayed task because Towny may not have processed this just yet
|
||||
// and would reset the mode otherwise
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new onPlayerJoinTask(plugin, player, channel), 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerQuit(final PlayerQuitEvent 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.LOWEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
|
||||
@@ -50,20 +87,50 @@ public class TownyChatPlayerListener implements Listener {
|
||||
if (split.length > 1)
|
||||
message = StringMgmt.join(StringMgmt.remFirstArg(split), " ");
|
||||
|
||||
// Check if they used a channel command or alias
|
||||
Channel channel = plugin.getChannelsHandler().getChannel(player, command);
|
||||
if (channel != null) {
|
||||
|
||||
|
||||
/*
|
||||
* If there is no message toggle the chat mode.
|
||||
*/
|
||||
if (message.isEmpty()) {
|
||||
if (plugin.getTowny().hasPlayerMode(player, channel.getName()))
|
||||
plugin.getTowny().removePlayerMode(player);
|
||||
else
|
||||
if (plugin.getTowny().hasPlayerMode(player, channel.getName())) {
|
||||
// Find what the next channel is if any
|
||||
Channel nextChannel = null;
|
||||
if (plugin.getChannelsHandler().getDefaultChannel() != null && plugin.getChannelsHandler().getDefaultChannel().isPresent(player.getName())) {
|
||||
nextChannel = plugin.getChannelsHandler().getDefaultChannel();
|
||||
if (!nextChannel.getName().equalsIgnoreCase(channel.getName())) {
|
||||
TownyUtil.removeAndSetPlayerMode(plugin.getTowny(), player, channel.getName(), nextChannel.getName(), true);
|
||||
} else {
|
||||
// They're talking on default channel and want to leave but can't because they'll be put default again
|
||||
// Their only option out is to leave the channel if they have permission to do so.
|
||||
TownyMessaging.sendErrorMsg(player, "[TownyChat] You are already talking in the default channel. To switch to another channel use that channel's command.");
|
||||
}
|
||||
} else {
|
||||
plugin.getTowny().removePlayerMode(player);
|
||||
}
|
||||
|
||||
if (nextChannel == null) {
|
||||
nextChannel = plugin.getChannelsHandler().getActiveChannel(player, channelTypes.GLOBAL);
|
||||
}
|
||||
|
||||
// If the new channel is not us, announce it
|
||||
if (nextChannel != null && !channel.getName().equalsIgnoreCase(nextChannel.getName())) {
|
||||
TownyMessaging.sendMsg(player, "[TownyChat] You are now talking in " + Colors.White + nextChannel.getName());
|
||||
}
|
||||
}
|
||||
else {
|
||||
plugin.getTowny().setPlayerMode(player, new String[]{channel.getName()}, true);
|
||||
|
||||
TownyMessaging.sendMsg(player, "[TownyChat] You are now talking in " + Colors.White + channel.getName());
|
||||
}
|
||||
} else {
|
||||
// Notify player he is muted
|
||||
if (channel.isMuted(player.getName())) {
|
||||
TownyMessaging.sendErrorMsg(player, "You are currently muted in " + channel.getName() + "!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Flag this as directed chat and trigger a player chat event
|
||||
*/
|
||||
@@ -81,7 +148,7 @@ public class TownyChatPlayerListener implements Listener {
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
|
||||
// Check if essentials has this player muted.
|
||||
if (!isMuted(player)) {
|
||||
|
||||
@@ -98,6 +165,14 @@ public class TownyChatPlayerListener implements Listener {
|
||||
directedChat.remove(player);
|
||||
|
||||
if (channel != null) {
|
||||
// Notify player he is muted
|
||||
if (channel.isMuted(player.getName())) {
|
||||
TownyMessaging.sendErrorMsg(player, "You are currently muted in " + Colors.White + channel.getName() + Colors.Rose + "!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getLogger().info("onPlayerChat: Processing directed message for " + channel.getName());
|
||||
channel.chatProcess(event);
|
||||
return;
|
||||
}
|
||||
@@ -108,6 +183,12 @@ public class TownyChatPlayerListener implements Listener {
|
||||
*/
|
||||
for (Channel channel : plugin.getChannelsHandler().getAllChannels().values()) {
|
||||
if (plugin.getTowny().hasPlayerMode(player, channel.getName())) {
|
||||
// Notify player he is muted
|
||||
if (channel.isMuted(player.getName())) {
|
||||
TownyMessaging.sendErrorMsg(player, "You are currently muted in " + Colors.White + channel.getName() + Colors.Rose + "!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Channel Chat mode set
|
||||
* Process the chat
|
||||
@@ -118,13 +199,19 @@ public class TownyChatPlayerListener implements Listener {
|
||||
}
|
||||
|
||||
// Find a global channel this player has permissions for.
|
||||
Channel channel = plugin.getChannelsHandler().getChannel(player, channelTypes.GLOBAL);
|
||||
Channel channel = plugin.getChannelsHandler().getActiveChannel(player, channelTypes.GLOBAL);
|
||||
|
||||
if (channel != null) {
|
||||
// Notify player he is muted
|
||||
if (channel.isMuted(player.getName())) {
|
||||
TownyMessaging.sendErrorMsg(player, "You are currently muted in " + Colors.White + channel.getName() + Colors.Rose + "!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
channel.chatProcess(event);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -142,7 +229,6 @@ public class TownyChatPlayerListener implements Listener {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,4 +282,4 @@ public class TownyChatPlayerListener implements Listener {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.palmergames.bukkit.TownyChat.tasks;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
|
||||
/*
|
||||
*
|
||||
* Created by RocketRidah
|
||||
*
|
||||
*/
|
||||
|
||||
public class onPlayerJoinTask implements Runnable {
|
||||
|
||||
Chat plugin;
|
||||
Towny towny;
|
||||
String playerName;
|
||||
String mode;
|
||||
|
||||
public onPlayerJoinTask(Chat plugin, Player player, Channel defaultChannel) {
|
||||
super();
|
||||
this.plugin = plugin;
|
||||
this.towny = plugin.getTowny();
|
||||
this.playerName = player.getName();
|
||||
this.mode = defaultChannel.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.towny.isEnabled()) {
|
||||
if (!this.towny.isError()) {
|
||||
Player player = plugin.getServer().getPlayer(playerName);
|
||||
if (player != null) {
|
||||
towny.setPlayerMode(player, new String[] { mode }, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.palmergames.bukkit.TownyChat.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
|
||||
public class TownyUtil {
|
||||
|
||||
public TownyUtil() {
|
||||
}
|
||||
|
||||
public static boolean removePlayerMode(Towny towny, Player player, String mode, boolean notify) {
|
||||
if (!towny.hasPlayerMode(player, mode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> modes = towny.getPlayerMode(player);
|
||||
int newmodecount = modes.size();
|
||||
Iterator<String> iter = modes.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String s = iter.next();
|
||||
if (mode.equalsIgnoreCase(s)) {
|
||||
iter.remove();
|
||||
towny.setPlayerMode(player, modes.toArray(new String[newmodecount-1]), notify);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean addPlayerMode(Towny towny, Player player, String mode, boolean notify) {
|
||||
if (towny.hasPlayerMode(player, mode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> modes = towny.getPlayerMode(player);
|
||||
modes.add(mode);
|
||||
towny.setPlayerMode(player, modes.toArray(new String[modes.size()]), notify);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean removeAndSetPlayerMode(Towny towny, Player player, String removeMode, String addMode, boolean notify) {
|
||||
List<String> modes = towny.getPlayerMode(player);
|
||||
boolean modesChanged = false;
|
||||
if (removeMode != null && towny.hasPlayerMode(player, removeMode)) {
|
||||
Iterator<String> iter = modes.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String s = iter.next();
|
||||
if (s == null) continue;
|
||||
if (s.equalsIgnoreCase(removeMode)) {
|
||||
iter.remove();
|
||||
modesChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addMode != null) {
|
||||
modes.add(addMode);
|
||||
modesChanged = true;
|
||||
}
|
||||
if (modesChanged) {
|
||||
towny.setPlayerMode(player, modes.toArray(new String[modes.size()]), notify);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+25
-2
@@ -18,7 +18,30 @@ commands:
|
||||
aliases: []
|
||||
usage: /townychat reload
|
||||
permission: townychat.reload
|
||||
|
||||
channel:
|
||||
aliases: [ch]
|
||||
description: Channel leaving and joining
|
||||
usage: /<command> leave|join channel
|
||||
leave:
|
||||
description: Leaves a channel
|
||||
usage: /<command> channel
|
||||
join:
|
||||
description: Joins a channel
|
||||
usage: /<command> channel
|
||||
chmute:
|
||||
aliases: [mute]
|
||||
description: Mutes a player in a channel
|
||||
usage: /<command> channel player
|
||||
permission: townychat.mod.mute
|
||||
mutelist:
|
||||
description: Displays mute list for a channel
|
||||
usage: /<command> channel
|
||||
chunmute:
|
||||
aliases: [unmute]
|
||||
description: Unmutes a player in a channel
|
||||
usage: /<command> channel player
|
||||
permission: townychat.mod.unmute
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
# | Permissions | #
|
||||
@@ -27,4 +50,4 @@ commands:
|
||||
permissions:
|
||||
townychat.reload:
|
||||
description: Allows reloading of Townychat.
|
||||
default: op
|
||||
default: op
|
||||
Reference in new issue
Block a user