mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-04 06:28:57 +00:00
Initial support for channel leaving, joining, muting, unmuting
This commit is contained in:
1 parent
bbca144177
commit
4125e1ce6f
13 files changed
+850
-19
No files matched your search
@@ -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("mute").getExecutor().onCommand(sender, cmd, label, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("unmute")) {
|
||||||
|
return plugin.getCommand("unmute").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,84 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
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("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 &f" + 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 &f" + chan.getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chan.join(sender.getName())){
|
||||||
|
TownyMessaging.sendMsg(sender, "[TownyChat] You are already in &f" + chan.getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TownyMessaging.sendMsg(sender, "[TownyChat] You joined &f" + chan.getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
package com.palmergames.bukkit.TownyChat.Command;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
// Remove this channel from player modes
|
||||||
|
if (TownyUtil.removePlayerMode(plugin.getTowny(), player, chan.getName(), false)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Channel newchannel = null;
|
||||||
|
// Find us a new channel to speak on
|
||||||
|
newchannel = plugin.getChannelsHandler().getActiveChannel(player, channelTypes.GLOBAL);
|
||||||
|
if (newchannel == null) {
|
||||||
|
newchannel = plugin.getChannelsHandler().getActiveChannel(player, channelTypes.NATION);
|
||||||
|
if (newchannel == null) {
|
||||||
|
newchannel = plugin.getChannelsHandler().getActiveChannel(player, channelTypes.TOWN);
|
||||||
|
if (newchannel == null) {
|
||||||
|
newchannel = plugin.getChannelsHandler().getActiveChannel(player, channelTypes.DEFAULT);
|
||||||
|
if (newchannel == null) {
|
||||||
|
newchannel = plugin.getChannelsHandler().getActiveChannel(player, channelTypes.PRIVATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newchannel != null) {
|
||||||
|
TownyUtil.addPlayerMode(plugin.getTowny(), player, newchannel.getName(), true);
|
||||||
|
TownyMessaging.sendMsg(sender, "[TownyChat] You are now talking in " + Colors.White + newchannel.getName());
|
||||||
|
} else {
|
||||||
|
TownyMessaging.sendMsg(sender, "[TownyChat] You are now in blissful silence.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
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("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 name = null;
|
||||||
|
String mutee = null;
|
||||||
|
if (label.equalsIgnoreCase("mute")){
|
||||||
|
name = args[0];
|
||||||
|
mutee = args[1];
|
||||||
|
} else {
|
||||||
|
name = args[1];
|
||||||
|
mutee = args[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
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 an 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(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!chan.mute(name)) {
|
||||||
|
TownyMessaging.sendMsg(sender, "[TownyChat] Player is already muted in "+ Colors.White + chan.getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TownyMessaging.sendMsg(sender, "[TownyChat] " + Colors.White + name + Colors.Green +" is now muted in "+ Colors.White + chan.getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package com.palmergames.bukkit.TownyChat.Command;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
Iterator<String> iter = chan.getMuteList().iterator();
|
||||||
|
boolean first = true;
|
||||||
|
String players = "";
|
||||||
|
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,92 @@
|
|||||||
|
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("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 name = null;
|
||||||
|
String mutee = null;
|
||||||
|
if (label.equalsIgnoreCase("mute")){
|
||||||
|
name = args[0];
|
||||||
|
mutee = args[1];
|
||||||
|
} else {
|
||||||
|
name = args[1];
|
||||||
|
mutee = args[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
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(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!chan.mute(name)) {
|
||||||
|
TownyMessaging.sendMsg(sender, "[TownyChat] Player is not muted in "+ Colors.White + chan.getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TownyMessaging.sendMsg(sender, "[TownyChat] " + Colors.White + name + Colors.Green +" is now muted in "+ Colors.White + chan.getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
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.concurrent.ConcurrentHashMap;
|
||||||
|
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 {
|
||||||
@@ -9,8 +14,10 @@ public abstract class Channel {
|
|||||||
private String name;
|
private String name;
|
||||||
private List<String> commands;
|
private List<String> commands;
|
||||||
private channelTypes type;
|
private channelTypes type;
|
||||||
private String channelTag, messageColour, permission, craftIRCTag;
|
private String channelTag, messageColour, permission, leavePermission, craftIRCTag;
|
||||||
private double range;
|
private double range;
|
||||||
|
protected ConcurrentMap<String, Integer> absentPlayers = null;
|
||||||
|
protected ConcurrentMap<String, Integer> mutedPlayers = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -118,4 +125,97 @@ public abstract class Channel {
|
|||||||
*/
|
*/
|
||||||
public abstract void chatProcess(AsyncPlayerChatEvent event);
|
public abstract void chatProcess(AsyncPlayerChatEvent event);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Used to reset channel settings for a given player
|
||||||
|
*/
|
||||||
|
public void forgetPlayer(String name) {
|
||||||
|
join(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 Set<String> getMuteList() {
|
||||||
|
return mutedPlayers.keySet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -83,6 +83,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.
|
* Find a channel we are able to talk in, starting with the greatest range.
|
||||||
*
|
*
|
||||||
@@ -97,17 +140,16 @@ public class ChannelsHolder {
|
|||||||
Channel world = null;
|
Channel world = null;
|
||||||
|
|
||||||
for (Channel channel: channels.values()) {
|
for (Channel channel: channels.values()) {
|
||||||
if (channel.getType().equals(type)) {
|
if (!channel.getType().equals(type)) continue;
|
||||||
if (!plugin.getTowny().isPermissions()
|
if (!plugin.getTowny().isPermissions() ||
|
||||||
|| (plugin.getTowny().isPermissions() && ((TownyUniverse.getPermissionSource().has(player, channel.getPermission()))
|
(plugin.getTowny().isPermissions() && ((TownyUniverse.getPermissionSource().has(player, channel.getPermission())) ||
|
||||||
|| (channel.getPermission().isEmpty())))) {
|
(channel.getPermission().isEmpty())))) {
|
||||||
if (channel.getRange() == -1) {
|
if (channel.getRange() == -1) {
|
||||||
global = channel;
|
global = channel;
|
||||||
} else if (channel.getRange() == 0) {
|
} else if (channel.getRange() == 0) {
|
||||||
world = channel;
|
world = channel;
|
||||||
} else
|
} else
|
||||||
local = channel;
|
local = channel;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,5 +183,11 @@ public class ChannelsHolder {
|
|||||||
return perms;
|
return perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMutePermission() {
|
||||||
|
return "townychat.mod.mute";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUnmutePermission() {
|
||||||
|
return "townychat.mod.unmute";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,7 @@ public class StandardChannel extends Channel {
|
|||||||
this.plugin = instance;
|
this.plugin = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void chatProcess(AsyncPlayerChatEvent event) {
|
public void chatProcess(AsyncPlayerChatEvent event) {
|
||||||
|
|
||||||
@@ -52,7 +53,6 @@ public class StandardChannel extends Channel {
|
|||||||
// Not in a town/nation (doesn't matter which)
|
// Not in a town/nation (doesn't matter which)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieve the channel specific format
|
* Retrieve the channel specific format
|
||||||
* and compile a set of recipients
|
* and compile a set of recipients
|
||||||
@@ -209,7 +209,14 @@ public class StandardChannel extends Channel {
|
|||||||
// Failed to fetch user so ignore.
|
// 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);
|
recipients.add(test);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,5 +227,4 @@ public class StandardChannel extends Channel {
|
|||||||
|
|
||||||
return recipients;
|
return recipients;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
@@ -90,6 +90,10 @@ public class ConfigurationHandler {
|
|||||||
if (element instanceof String)
|
if (element instanceof String)
|
||||||
channel.setPermission(element.toString());
|
channel.setPermission(element.toString());
|
||||||
|
|
||||||
|
if (key.equalsIgnoreCase("leavepermission"))
|
||||||
|
if (element instanceof String)
|
||||||
|
channel.setLeavePermission(element.toString());
|
||||||
|
|
||||||
if (key.equalsIgnoreCase("craftIRCTag"))
|
if (key.equalsIgnoreCase("craftIRCTag"))
|
||||||
if (element instanceof String)
|
if (element instanceof String)
|
||||||
channel.setCraftIRCTag(element.toString());
|
channel.setCraftIRCTag(element.toString());
|
||||||
@@ -98,6 +102,10 @@ public class ConfigurationHandler {
|
|||||||
channel.setRange(Double.valueOf(element.toString()));
|
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);
|
plugin.getChannelsHandler().addChannel(channel);
|
||||||
|
|
||||||
//System.out.print("Channel: " + channel.getName() + " : Type : " + channel.getType().name());
|
//System.out.print("Channel: " + channel.getName() + " : Type : " + channel.getType().name());
|
||||||
|
|||||||
@@ -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.PlayerQuitEvent;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||||
@@ -20,6 +21,7 @@ import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
|||||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.util.Colors;
|
||||||
import com.palmergames.util.StringMgmt;
|
import com.palmergames.util.StringMgmt;
|
||||||
|
|
||||||
public class TownyChatPlayerListener implements Listener {
|
public class TownyChatPlayerListener implements Listener {
|
||||||
@@ -64,6 +66,13 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
plugin.getTowny().setPlayerMode(player, new String[]{channel.getName()}, true);
|
plugin.getTowny().setPlayerMode(player, new String[]{channel.getName()}, true);
|
||||||
|
|
||||||
} else {
|
} 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
|
* Flag this as directed chat and trigger a player chat event
|
||||||
*/
|
*/
|
||||||
@@ -77,11 +86,20 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||||
|
String name = event.getPlayer().getName();
|
||||||
|
for (Channel channel : plugin.getChannelsHandler().getAllChannels().values()) {
|
||||||
|
channel.forgetPlayer(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
String playerName = player.getName();
|
||||||
|
|
||||||
// Check if essentials has this player muted.
|
// Check if essentials has this player muted.
|
||||||
if (!isMuted(player)) {
|
if (!isMuted(player)) {
|
||||||
|
|
||||||
@@ -98,6 +116,17 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
directedChat.remove(player);
|
directedChat.remove(player);
|
||||||
|
|
||||||
if (channel != null) {
|
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;
|
||||||
|
}
|
||||||
|
// If player sends a message to a channel it had left
|
||||||
|
// tell the channel to add the player back
|
||||||
|
if (channel.isAbsent(playerName)) {
|
||||||
|
channel.forgetPlayer(playerName);
|
||||||
|
}
|
||||||
channel.chatProcess(event);
|
channel.chatProcess(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -108,6 +137,12 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
for (Channel channel : plugin.getChannelsHandler().getAllChannels().values()) {
|
for (Channel channel : plugin.getChannelsHandler().getAllChannels().values()) {
|
||||||
if (plugin.getTowny().hasPlayerMode(player, channel.getName())) {
|
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
|
* Channel Chat mode set
|
||||||
* Process the chat
|
* Process the chat
|
||||||
@@ -118,9 +153,16 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find a global channel this player has permissions for.
|
// 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) {
|
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);
|
channel.chatProcess(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
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 pos = 0;
|
||||||
|
Iterator<String> iter = modes.iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String s = iter.next();
|
||||||
|
if (mode.equalsIgnoreCase(s)) {
|
||||||
|
modes.remove(pos);
|
||||||
|
towny.setPlayerMode(player, modes.toArray(new String[modes.size()]), notify);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
-1
@@ -18,7 +18,31 @@ commands:
|
|||||||
aliases: []
|
aliases: []
|
||||||
usage: /townychat reload
|
usage: /townychat reload
|
||||||
permission: townychat.reload
|
permission: townychat.reload
|
||||||
|
channel:
|
||||||
|
aliases: [ch]
|
||||||
|
description: Channel leaving and joining
|
||||||
|
usage: /<command> leave|join channel
|
||||||
|
leave:
|
||||||
|
aliases: [ch leave]
|
||||||
|
description: Leaves a channel
|
||||||
|
usage: /<command> channel
|
||||||
|
join:
|
||||||
|
aliases: [ch join]
|
||||||
|
description: Joins a channel
|
||||||
|
usage: /<command> channel
|
||||||
|
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
|
||||||
|
permission: townychat.mod.list.mute
|
||||||
|
unmute:
|
||||||
|
description: Unmutes a player in a channel
|
||||||
|
usage: /<command> channel player
|
||||||
|
permission: townychat.mod.unmute
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# +------------------------------------------------------+ #
|
# +------------------------------------------------------+ #
|
||||||
# | Permissions | #
|
# | Permissions | #
|
||||||
|
|||||||
Reference in new issue
Block a user