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 21:36:48 +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.McMMOPartyChatEvent;
|
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
|
|
|
|
|
|
|
public class PCommand implements CommandExecutor {
|
2012-06-07 00:02:22 +02:00
|
|
|
private final mcMMO plugin;
|
2012-04-21 00:09:50 +02:00
|
|
|
|
2012-06-07 00:02:22 +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
|
|
|
|
2012-04-22 21:36:48 +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-23 01:34:34 +02:00
|
|
|
String usage = ChatColor.RED + "Proper usage is /p <party-name> <message>"; //TODO: Needs more locale.
|
2012-04-22 21:36:48 +02:00
|
|
|
|
|
|
|
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
|
|
|
if (sender instanceof Player) {
|
2012-07-03 16:04:04 +02:00
|
|
|
profile = Users.getProfile((Player) sender);
|
2012-04-22 21:36:48 +02:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
if (profile.getAdminChatMode()) {
|
|
|
|
profile.toggleAdminChat();
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.togglePartyChat();
|
2012-04-22 21:36:48 +02:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
if (profile.getPartyChatMode()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.Chat.On"));
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-04-27 11:47:11 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Off"));
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sender.sendMessage(usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (sender instanceof Player) {
|
|
|
|
Player player = (Player) sender;
|
2012-06-08 23:48:41 +02:00
|
|
|
Party party = Users.getProfile(player).getParty();
|
2012-04-22 21:36:48 +02:00
|
|
|
|
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"));
|
2012-04-22 21:36:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String message = args[0];
|
|
|
|
|
|
|
|
for (int i = 1; i < args.length; i++) {
|
|
|
|
message = message + " " + args [i];
|
|
|
|
}
|
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(player.getName(), party.getName(), message);
|
2012-05-30 17:13:34 +02:00
|
|
|
plugin.getServer().getPluginManager().callEvent(chatEvent);
|
|
|
|
|
|
|
|
if (chatEvent.isCancelled()) {
|
|
|
|
return true;
|
2012-04-23 02:00:31 +02:00
|
|
|
}
|
2012-05-30 17:13:34 +02:00
|
|
|
|
|
|
|
message = chatEvent.getMessage();
|
|
|
|
String prefix = ChatColor.GREEN + "(" + ChatColor.WHITE + player.getName() + ChatColor.GREEN + ") ";
|
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
plugin.getLogger().info("[P](" + party.getName() + ")" + "<" + player.getName() + "> " + message);
|
2012-05-30 17:13:34 +02:00
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
for (Player member : party.getOnlineMembers()) {
|
|
|
|
member.sendMessage(prefix + message);
|
2012-04-23 02:00:31 +02:00
|
|
|
}
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (args.length < 2) {
|
|
|
|
sender.sendMessage(usage);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
if (!PartyManager.getInstance().isParty(args[0])) {
|
2012-04-27 11:47:11 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));
|
2012-04-22 21:36:48 +02:00
|
|
|
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);
|
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
for (Player member : PartyManager.getInstance().getOnlineMembers(args[0])) {
|
|
|
|
member.sendMessage(prefix + message);
|
2012-04-22 21:36:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|