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

116 lines
3.7 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;
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.McMMOPartyChatEvent;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party;
2012-01-09 20:00:13 +01:00
public class PCommand implements CommandExecutor {
2012-04-21 00:09:50 +02:00
private final mcMMO plugin;
public PCommand (mcMMO plugin) {
this.plugin = plugin;
}
2012-01-09 20:00:13 +01:00
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile PP;
String usage = ChatColor.RED + "Proper usage is /p <partyname> <message>"; //TODO: Needs more locale.
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
return true;
}
switch (args.length) {
case 0:
if (sender instanceof Player) {
PP = Users.getProfile((Player) sender);
if (PP.getAdminChatMode()) {
PP.toggleAdminChat();
}
PP.togglePartyChat();
if (PP.getPartyChatMode()) {
sender.sendMessage(mcLocale.getString("Commands.Party.Chat.On"));
}
else {
sender.sendMessage(mcLocale.getString("Commands.Party.Chat.Off"));
}
}
else {
sender.sendMessage(usage);
}
return true;
default:
if (sender instanceof Player) {
Player player = (Player) sender;
PP = Users.getProfile(player);
if (!PP.inParty()) {
player.sendMessage(mcLocale.getString("Commands.Party.None"));
return true;
}
String message = args[0];
for (int i = 1; i < args.length; i++) {
message = message + " " + args [i];
}
PP.togglePartyChat();
player.chat(message);
PP.togglePartyChat();
}
else {
if (args.length < 2) {
sender.sendMessage(usage);
return true;
}
if (!Party.getInstance().getParties().contains(args[0])) {
sender.sendMessage(mcLocale.getString("Party.InvalidName"));
return true;
}
String message = args[1];
for (int i = 2; i < args.length; i++) {
message = message + " " + args [i];
}
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], message);
plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) {
return true;
}
message = chatEvent.getMessage();
String prefix = ChatColor.GREEN + "(" + ChatColor.WHITE + "*Console*" + ChatColor.GREEN + ") ";
plugin.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + message);
for (Player player : Party.getInstance().getOnlineMembers(args[0])) {
player.sendMessage(prefix + message);
}
}
return true;
}
}
2012-01-09 20:00:13 +01:00
}