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

109 lines
3.6 KiB
Java
Raw Normal View History

2013-02-02 06:09:47 +01:00
package com.gmail.nossr50.chat.commands;
2012-01-09 20:00:13 +01:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
2013-02-02 06:09:47 +01:00
import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.McMMOPlayer;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
2012-06-08 23:48:41 +02:00
import com.gmail.nossr50.party.PartyManager;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.util.Users;
2012-01-09 20:00:13 +01:00
public class PCommand implements CommandExecutor {
private final mcMMO plugin;
2012-04-21 00:09:50 +02:00
public PCommand (mcMMO plugin) {
2012-04-21 00:09:50 +02:00
this.plugin = plugin;
}
2012-01-09 20:00:13 +01:00
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
McMMOPlayer mcMMOPlayer;
2013-02-02 08:55:49 +01:00
String usage = LocaleLoader.getString("Commands.Usage.2", "p", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">", "<" + LocaleLoader.getString("Commands.Usage.Message") + ">");
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
return true;
}
switch (args.length) {
case 0:
if (sender instanceof Player) {
mcMMOPlayer = Users.getPlayer((Player) sender);
if (mcMMOPlayer.getAdminChatMode()) {
mcMMOPlayer.toggleAdminChat();
}
mcMMOPlayer.togglePartyChat();
if (mcMMOPlayer.getPartyChatMode()) {
2012-04-27 11:47:11 +02:00
sender.sendMessage(LocaleLoader.getString("Commands.Party.Chat.On"));
}
else {
2012-04-27 11:47:11 +02:00
sender.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Off"));
}
}
else {
sender.sendMessage(usage);
}
return true;
default:
if (sender instanceof Player) {
Player player = (Player) sender;
Party party = Users.getPlayer(player).getParty();
2012-06-08 23:48:41 +02:00
if (party == null) {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return true;
}
2013-01-31 00:58:31 +01:00
StringBuilder builder = new StringBuilder();
builder.append(args[0]);
for (int i = 1; i < args.length; i++) {
2013-01-31 00:58:31 +01:00
builder.append(" ");
builder.append(args[i]);
}
2013-01-31 00:58:31 +01:00
String message = builder.toString();
ChatManager.handlePartyChat(plugin, party, player.getName(), player.getDisplayName(), message);
}
else {
if (args.length < 2) {
sender.sendMessage(usage);
return true;
}
Party party = PartyManager.getParty(args[0]);
if (party == null) {
2012-04-27 11:47:11 +02:00
sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));
return true;
}
2013-01-31 00:58:31 +01:00
StringBuilder builder = new StringBuilder();
builder.append(args[1]);
for (int i = 2; i < args.length; i++) {
2013-01-31 00:58:31 +01:00
builder.append(" ");
builder.append(args[i]);
}
String ssender = LocaleLoader.getString("Commands.Chat.Console");
2013-01-31 00:58:31 +01:00
String message = builder.toString();
ChatManager.handlePartyChat(plugin, party, ssender, ssender, message);
}
return true;
}
}
2012-01-09 20:00:13 +01:00
}