2012-01-09 20:00:13 +01:00
|
|
|
package com.gmail.nossr50.commands.party;
|
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-04-22 08:55:58 +02:00
|
|
|
import com.gmail.nossr50.commands.CommandHelper;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-04-18 19:01:07 +02:00
|
|
|
import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
public class ACommand implements CommandExecutor {
|
2012-06-07 00:02:22 +02:00
|
|
|
private final mcMMO plugin;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
public ACommand (mcMMO plugin) {
|
2012-04-21 00:09:50 +02:00
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-04-21 00:09:50 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile;
|
2012-04-22 21:36:48 +02:00
|
|
|
String usage = ChatColor.RED + "Proper usage is /a <message>"; //TODO: Needs more locale.
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
if (CommandHelper.noCommandPermissions(sender, "mcmmo.chat.adminchat")) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-18 19:01:07 +02:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
|
|
|
if (sender instanceof Player) {
|
2012-07-03 16:04:04 +02:00
|
|
|
profile = Users.getProfile((Player) sender);
|
2012-04-18 19:01:07 +02:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
if (profile.getPartyChatMode()) {
|
|
|
|
profile.togglePartyChat();
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.toggleAdminChat();
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
if (profile.getAdminChatMode()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.AdminChat.On"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-04-27 11:47:11 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.AdminChat.Off"));
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2012-04-21 00:09:50 +02:00
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
else {
|
|
|
|
sender.sendMessage(usage);
|
|
|
|
}
|
|
|
|
|
2012-04-21 00:09:50 +02:00
|
|
|
return true;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
default:
|
2012-07-05 15:21:07 +02:00
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
|
buffer.append(args[0]);
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
for (int i = 1; i < args.length; i++) {
|
2012-07-05 15:21:07 +02:00
|
|
|
buffer.append(" ");
|
|
|
|
buffer.append(args[i]);
|
2012-04-22 08:55:58 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-07-05 15:21:07 +02:00
|
|
|
String message = buffer.toString();
|
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
if (sender instanceof Player) {
|
|
|
|
Player player = (Player) sender;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-05-30 17:18:25 +02:00
|
|
|
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(player.getName(), message);
|
|
|
|
plugin.getServer().getPluginManager().callEvent(chatEvent);
|
|
|
|
|
|
|
|
if (chatEvent.isCancelled()) {
|
|
|
|
return true;
|
2012-04-23 02:00:31 +02:00
|
|
|
}
|
2012-05-30 17:18:25 +02:00
|
|
|
|
|
|
|
message = chatEvent.getMessage();
|
|
|
|
String prefix = ChatColor.AQUA + "{" + ChatColor.WHITE + player.getName() + ChatColor.AQUA + "} ";
|
|
|
|
|
|
|
|
plugin.getLogger().info("[A]<" + player.getName() + "> " + message);
|
|
|
|
|
2012-06-25 21:34:13 +02:00
|
|
|
for (Player otherPlayer : plugin.getServer().getOnlinePlayers()) {
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.adminChat(otherPlayer) || otherPlayer.isOp()) {
|
2012-06-25 21:34:13 +02:00
|
|
|
otherPlayer.sendMessage(prefix + message);
|
2012-05-30 17:18:25 +02:00
|
|
|
}
|
2012-04-23 02:00:31 +02:00
|
|
|
}
|
2012-04-21 00:09:50 +02:00
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
else {
|
|
|
|
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent("Console", message);
|
|
|
|
plugin.getServer().getPluginManager().callEvent(chatEvent);
|
2012-04-11 04:14:09 +02:00
|
|
|
|
2012-04-22 08:55:58 +02:00
|
|
|
if (chatEvent.isCancelled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
message = chatEvent.getMessage();
|
|
|
|
String prefix = ChatColor.AQUA + "{" + ChatColor.WHITE + "*Console*" + ChatColor.AQUA + "} ";
|
|
|
|
|
|
|
|
plugin.getLogger().info("[A]<*Console*> " + message);
|
|
|
|
|
|
|
|
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.adminChat(player) || player.isOp()) {
|
2012-04-22 08:55:58 +02:00
|
|
|
player.sendMessage(prefix + message);
|
|
|
|
}
|
|
|
|
}
|
2012-04-21 00:09:50 +02:00
|
|
|
}
|
2012-04-22 08:55:58 +02:00
|
|
|
|
|
|
|
return true;
|
2012-04-21 00:09:50 +02:00
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|