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;
|
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-02-02 06:09:47 +01:00
|
|
|
import com.gmail.nossr50.chat.ChatManager;
|
2013-02-03 16:27:59 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2012-04-22 21:36:48 +02:00
|
|
|
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
|
|
|
|
2013-02-06 23:57:16 +01:00
|
|
|
public class PartyChatCommand implements CommandExecutor {
|
2012-04-22 21:36:48 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2013-02-03 16:27:59 +01:00
|
|
|
McMMOPlayer mcMMOPlayer;
|
2012-04-22 21:36:48 +02:00
|
|
|
|
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
2013-02-06 23:57:16 +01:00
|
|
|
if (!(sender instanceof Player)) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-22 21:36:48 +02:00
|
|
|
|
2013-02-06 23:57:16 +01:00
|
|
|
mcMMOPlayer = Users.getPlayer((Player) sender);
|
2012-04-22 21:36:48 +02:00
|
|
|
|
2013-02-06 23:57:16 +01:00
|
|
|
// Can't have both party & admin chat at the same time.
|
|
|
|
if (mcMMOPlayer.getAdminChatMode()) {
|
|
|
|
mcMMOPlayer.toggleAdminChat();
|
|
|
|
}
|
2012-04-22 21:36:48 +02:00
|
|
|
|
2013-02-06 23:57:16 +01:00
|
|
|
mcMMOPlayer.togglePartyChat();
|
|
|
|
|
|
|
|
if (mcMMOPlayer.getPartyChatMode()) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.Chat.On"));
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-02-06 23:57:16 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Off"));
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2013-02-06 23:57:16 +01:00
|
|
|
if (args.length == 1) {
|
|
|
|
if (!(sender instanceof Player)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mcMMOPlayer = Users.getPlayer((Player) sender);
|
|
|
|
|
|
|
|
if (args[0].equalsIgnoreCase("on")) {
|
|
|
|
mcMMOPlayer.setAdminChat(false);
|
|
|
|
mcMMOPlayer.setPartyChat(true);
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.Chat.On"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[0].equalsIgnoreCase("off")) {
|
|
|
|
mcMMOPlayer.setPartyChat(false);
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Off"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-22 21:36:48 +02:00
|
|
|
if (sender instanceof Player) {
|
|
|
|
Player player = (Player) sender;
|
2013-02-03 16:27:59 +01:00
|
|
|
Party party = Users.getPlayer(player).getParty();
|
2012-04-22 21:36:48 +02:00
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
if (party == null) {
|
2013-02-06 23:57:16 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
2012-04-22 21:36:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-31 00:58:31 +01:00
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
builder.append(args[0]);
|
2012-04-22 21:36:48 +02:00
|
|
|
|
|
|
|
for (int i = 1; i < args.length; i++) {
|
2013-01-31 00:58:31 +01:00
|
|
|
builder.append(" ");
|
|
|
|
builder.append(args[i]);
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
|
2013-01-31 00:58:31 +01:00
|
|
|
String message = builder.toString();
|
2013-02-06 23:57:16 +01:00
|
|
|
ChatManager.handlePartyChat(mcMMO.p, party, player.getName(), player.getDisplayName(), message);
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (args.length < 2) {
|
2013-02-06 23:57:16 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Party.Specify"));
|
2012-04-22 21:36:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-02 00:59:22 +01:00
|
|
|
Party party = PartyManager.getParty(args[0]);
|
|
|
|
|
|
|
|
if (party == null) {
|
2012-04-27 11:47:11 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));
|
2012-04-22 21:36:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-31 00:58:31 +01:00
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
builder.append(args[1]);
|
2012-04-22 21:36:48 +02:00
|
|
|
|
|
|
|
for (int i = 2; i < args.length; i++) {
|
2013-01-31 00:58:31 +01:00
|
|
|
builder.append(" ");
|
|
|
|
builder.append(args[i]);
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
|
2013-02-06 23:57:16 +01:00
|
|
|
String consoleSender = LocaleLoader.getString("Commands.Chat.Console");
|
2013-01-31 00:58:31 +01:00
|
|
|
String message = builder.toString();
|
2012-07-05 15:21:07 +02:00
|
|
|
|
2013-02-06 23:57:16 +01:00
|
|
|
ChatManager.handlePartyChat(mcMMO.p, party, consoleSender, consoleSender, message);
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|