mcMMO/src/main/java/com/gmail/nossr50/commands/party/ACommand.java

97 lines
3.0 KiB
Java
Raw Normal View History

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;
import com.gmail.nossr50.Users;
2012-04-21 00:09:50 +02:00
import com.gmail.nossr50.mcMMO;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.mcPermissions;
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-01-09 20:00:13 +01:00
import com.gmail.nossr50.locale.mcLocale;
public class ACommand implements CommandExecutor {
2012-04-21 00:09:50 +02:00
private final mcMMO plugin;
2012-01-09 20:00:13 +01:00
2012-04-21 00:09:50 +02:00
public ACommand (mcMMO plugin) {
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-04-22 08:55:58 +02:00
PlayerProfile PP;
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) {
PP = Users.getProfile((Player) sender);
2012-04-18 19:01:07 +02:00
2012-04-22 08:55:58 +02:00
if (PP.getPartyChatMode()) {
PP.togglePartyChat();
}
2012-01-09 20:00:13 +01:00
2012-04-22 08:55:58 +02:00
PP.toggleAdminChat();
2012-01-09 20:00:13 +01:00
2012-04-22 08:55:58 +02:00
if (PP.getAdminChatMode()) {
sender.sendMessage(mcLocale.getString("Commands.AdminChat.On"));
}
else {
sender.sendMessage(mcLocale.getString("Commands.AdminChat.Off"));
}
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:
String message = 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++) {
message = message + " " + args [i];
}
2012-01-09 20:00:13 +01:00
2012-04-22 08:55:58 +02:00
if (sender instanceof Player) {
Player player = (Player) sender;
PP = Users.getProfile(player);
2012-01-09 20:00:13 +01:00
2012-04-22 08:55:58 +02:00
PP.toggleAdminChat();
player.chat(message);
PP.toggleAdminChat();
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-22 08:55:58 +02:00
if (chatEvent.isCancelled()) {
return true;
}
message = chatEvent.getMessage();
2012-04-21 00:09:50 +02:00
2012-04-22 08:55:58 +02:00
String prefix = ChatColor.AQUA + "{" + ChatColor.WHITE + "*Console*" + ChatColor.AQUA + "} ";
plugin.getLogger().info("[A]<*Console*> " + message);
for (Player player : plugin.getServer().getOnlinePlayers()) {
if (mcPermissions.getInstance().adminChat(player) || player.isOp()) {
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
}