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

268 lines
11 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.mcMMO;
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;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.locale.LocaleLoader;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.party.Party;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.util.Users;
2012-01-09 20:00:13 +01:00
public class PartyCommand implements CommandExecutor {
private final mcMMO plugin;
2012-04-21 00:09:50 +02:00
public PartyCommand (mcMMO plugin) {
2012-04-21 00:09:50 +02:00
this.plugin = plugin;
}
2012-04-22 08:55:58 +02:00
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) {
return true;
}
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
return true;
}
Player player = (Player) sender;
String playerName = player.getName();
PlayerProfile PP = Users.getProfile(player);
Party partyInstance = Party.getInstance();
boolean inParty = PP.inParty();
String partyName = PP.getParty();
boolean isLeader = partyInstance.isPartyLeader(playerName, partyName);
if (PP.inParty() && (!partyInstance.isParty(PP.getParty()) || !partyInstance.isInParty(player, PP))) {
partyInstance.addToParty(player, PP, PP.getParty(), false, null);
}
switch (args.length) {
case 0:
if (!inParty) {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
2012-04-22 08:55:58 +02:00
}
else {
String tempList = "";
for (Player p : partyInstance.getAllMembers(player)) {
if (p.equals(partyInstance.getPartyLeader(partyName))) {
tempList += ChatColor.GOLD;
2012-04-22 08:55:58 +02:00
}
else {
tempList += ChatColor.WHITE;
2012-04-22 08:55:58 +02:00
}
tempList += p.getName() + " ";
2012-04-22 08:55:58 +02:00
}
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Commands.Party.InParty", new Object[] { partyName }));
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", new Object[] { tempList }));
2012-04-22 08:55:58 +02:00
}
return true;
2012-04-22 08:55:58 +02:00
case 1:
if (args[0].equalsIgnoreCase("q")) {
if (inParty) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, partyName, null, EventReason.LEFT_PARTY);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
partyInstance.removeFromParty(player, PP);
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
2012-04-22 08:55:58 +02:00
}
else {
player.sendMessage("Commands.Party.None");
}
}
else if (args[0].equals("?")) {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.Help.3"));
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
player.sendMessage(LocaleLoader.getString("Party.Help.4"));
player.sendMessage(LocaleLoader.getString("Party.Help.5"));
player.sendMessage(LocaleLoader.getString("Party.Help.6"));
player.sendMessage(LocaleLoader.getString("Party.Help.7"));
2012-04-22 08:55:58 +02:00
}
else if (args[0].equalsIgnoreCase("lock")) {
if (inParty) {
if (isLeader) {
if (partyInstance.isPartyLocked(partyName)) {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.IsLocked"));
2012-04-22 08:55:58 +02:00
}
else {
partyInstance.lockParty(partyName);
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.Locked"));
2012-04-22 08:55:58 +02:00
}
}
else {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
2012-04-22 08:55:58 +02:00
}
}
else {
player.sendMessage("Commands.Party.None");
}
}
else if (args[0].equalsIgnoreCase("unlock")) {
if (inParty) {
if (isLeader) {
if (!partyInstance.isPartyLocked(partyName)) {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.IsntLocked"));
2012-04-22 08:55:58 +02:00
}
else {
partyInstance.unlockParty(partyName);
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.Unlocked"));
2012-04-22 08:55:58 +02:00
}
}
else {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
2012-04-22 08:55:58 +02:00
}
}
else {
player.sendMessage("Commands.Party.None");
}
}
else {
if (inParty) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, partyName, args[0], EventReason.CHANGED_PARTIES);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
partyInstance.removeFromParty(player, PP);
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, args[0], EventReason.JOINED_PARTY);
2012-04-21 00:09:50 +02:00
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
2012-04-22 08:55:58 +02:00
}
partyInstance.addToParty(player, PP, args[0], false, null);
}
return true;
case 2:
if (PP.inParty()) {
if (args[0].equalsIgnoreCase("password")) {
if (isLeader) {
if (!partyInstance.isPartyLocked(partyName)) {
partyInstance.lockParty(partyName);
}
partyInstance.setPartyPassword(partyName, args[1]);
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.PasswordSet", new Object[] { args[1] }));
2012-04-22 08:55:58 +02:00
}
else {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
2012-04-22 08:55:58 +02:00
}
}
else if (args[0].equalsIgnoreCase("kick")) {
if (isLeader) {
Player target = plugin.getServer().getPlayer(args[1]);
if (target == null) {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
2012-04-22 08:55:58 +02:00
return true;
}
PlayerProfile PPt = Users.getProfile(target);
String targetName = target.getName();
2012-06-05 15:57:10 +02:00
if (!partyInstance.inSameParty(player, target)) {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] { targetName }));
2012-04-22 08:55:58 +02:00
return true;
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, partyName, null, EventReason.KICKED_FROM_PARTY);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
partyInstance.removeFromParty(target, PPt);
2012-04-27 11:47:11 +02:00
target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", new Object[] { partyName }));
2012-04-22 08:55:58 +02:00
}
}
else {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
2012-04-22 08:55:58 +02:00
}
}
else if (args[0].equalsIgnoreCase("owner")) {
if (isLeader) {
Player target = plugin.getServer().getPlayer(args[1]);
if (target == null) {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
2012-04-22 08:55:58 +02:00
return true;
}
String targetName = target.getName();
2012-06-05 15:57:10 +02:00
if (!partyInstance.inSameParty(player, target)) {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] { targetName }));
2012-04-22 08:55:58 +02:00
return true;
}
else {
partyInstance.setPartyLeader(partyName, targetName);
}
}
else {
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
2012-04-22 08:55:58 +02:00
}
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, partyName, args[0], EventReason.CHANGED_PARTIES);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
partyInstance.removeFromParty(player, PP);
partyInstance.addToParty(player, PP, args[0], false, args[1]);
}
}
else {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, args[0], EventReason.JOINED_PARTY);
2012-04-21 00:09:50 +02:00
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
2012-04-22 08:55:58 +02:00
partyInstance.addToParty(player, PP, args[0], false, args[1]);
}
2012-01-09 20:00:13 +01:00
2012-04-22 08:55:58 +02:00
return true;
default:
2012-04-27 11:47:11 +02:00
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
2012-04-22 08:55:58 +02:00
return true;
}
}
2012-01-09 20:00:13 +01:00
}