70 lines
2.3 KiB
Java
Raw Normal View History

2012-01-09 11:00:13 -08: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;
import com.gmail.nossr50.mcMMO;
2012-04-22 02:55:58 -04:00
import com.gmail.nossr50.commands.CommandHelper;
2012-01-09 11:00:13 -08:00
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party;
public class InviteCommand implements CommandExecutor {
2012-04-22 02:55:58 -04:00
private final mcMMO plugin;
2012-01-09 11:00:13 -08:00
2012-04-22 02:55:58 -04:00
public InviteCommand(mcMMO instance) {
this.plugin = instance;
}
2012-01-09 11:00:13 -08:00
2012-04-22 02:55:58 -04:00
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String usage = ChatColor.RED + "Proper usage is /invite <playername>"; //TODO: Needs more locale.
2012-01-09 11:00:13 -08:00
2012-04-22 02:55:58 -04:00
if (CommandHelper.noConsoleUsage(sender)) {
return true;
}
2012-01-09 11:00:13 -08:00
2012-04-22 02:55:58 -04:00
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party")) {
return true;
}
2012-01-09 11:00:13 -08:00
2012-04-22 02:55:58 -04:00
switch (args.length) {
case 1:
Player player = (Player) sender;
PlayerProfile PP = Users.getProfile(player);
2012-01-09 11:00:13 -08:00
2012-04-22 02:55:58 -04:00
Party partyInstance = Party.getInstance();
2012-01-09 11:00:13 -08:00
2012-04-22 02:55:58 -04:00
if (!PP.inParty()) {
player.sendMessage(mcLocale.getString("Commands.Party.None"));
return true;
}
2012-01-09 11:00:13 -08:00
2012-04-22 02:55:58 -04:00
Player target = plugin.getServer().getPlayer(args[0]);
2012-01-09 11:00:13 -08:00
2012-04-22 02:55:58 -04:00
if (target != null) {
if (partyInstance.canInvite(player, PP)) {
PlayerProfile PPt = Users.getProfile(target);
PPt.modifyInvite(PP.getParty());
player.sendMessage(mcLocale.getString("Commands.Invite.Success"));
target.sendMessage(mcLocale.getString("Commands.Party.Invite.0", new Object[] { PPt.getInvite(), player.getName() }));
target.sendMessage(mcLocale.getString("Commands.Party.Invite.1"));
}
else {
player.sendMessage(mcLocale.getString("Party.Locked"));
return true;
}
}
default:
sender.sendMessage(usage);
return true;
}
}
2012-01-09 11:00:13 -08:00
}