mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-27 01:51:21 +01:00
Cleaned up a few things in PartyCommand - removed unnecessary else
statements & function args, removed accidental usage of Bukkit.getServer() command, fixed some spacing issues. Added new CommandHelper function to take a player when checking permissions to avoid double-checking when it's already been verified that the sender is a player.
This commit is contained in:
parent
088d4ac14a
commit
0692dd82ad
@ -33,6 +33,15 @@ public final class CommandHelper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean noCommandPermissions(Player player, String permission) {
|
||||||
|
if (!Permissions.hasPermission(player, permission)) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean noConsoleUsage(CommandSender sender) {
|
public static boolean noConsoleUsage(CommandSender sender) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.NoConsole"));
|
sender.sendMessage(LocaleLoader.getString("Commands.NoConsole"));
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.gmail.nossr50.party.commands;
|
package com.gmail.nossr50.party.commands;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -19,6 +18,9 @@ import com.gmail.nossr50.party.PartyManager;
|
|||||||
import com.gmail.nossr50.util.Users;
|
import com.gmail.nossr50.util.Users;
|
||||||
|
|
||||||
public class PartyCommand implements CommandExecutor {
|
public class PartyCommand implements CommandExecutor {
|
||||||
|
private Player player;
|
||||||
|
private PlayerProfile playerProfile;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (CommandHelper.noConsoleUsage(sender)) {
|
if (CommandHelper.noConsoleUsage(sender)) {
|
||||||
@ -29,85 +31,77 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
this.player = (Player) sender;
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
this.playerProfile = Users.getProfile(player);
|
||||||
|
|
||||||
if (args.length < 1) {
|
if (args.length < 1 || args[0].equalsIgnoreCase("info")) {
|
||||||
return party(sender);
|
return party();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("join")) {
|
if (args[0].equalsIgnoreCase("join")) {
|
||||||
return join(sender, args);
|
return join(args);
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("accept")) {
|
else if (args[0].equalsIgnoreCase("accept")) {
|
||||||
return accept(sender, args);
|
return accept();
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("create")) {
|
else if (args[0].equalsIgnoreCase("create")) {
|
||||||
return create(sender, args);
|
return create(args);
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("info")) {
|
|
||||||
return party(sender);
|
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) {
|
else if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) {
|
||||||
return printHelp(sender, args);
|
return printHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerProfile.inParty()) {
|
if (playerProfile.inParty()) {
|
||||||
if(args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) {
|
if (args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) {
|
||||||
return quit(sender, args);
|
return quit();
|
||||||
}
|
}
|
||||||
else if(args[0].equalsIgnoreCase("expshare")) {
|
else if (args[0].equalsIgnoreCase("expshare")) {
|
||||||
return shareExp(sender, args);
|
return shareExp();
|
||||||
}
|
}
|
||||||
else if(args[0].equalsIgnoreCase("itemshare")) {
|
else if (args[0].equalsIgnoreCase("itemshare")) {
|
||||||
return shareItem(sender, args);
|
return shareItem();
|
||||||
}
|
}
|
||||||
else if(args[0].equalsIgnoreCase("invite")) {
|
else if (args[0].equalsIgnoreCase("invite")) {
|
||||||
return invite(sender, args);
|
return invite(args);
|
||||||
}
|
}
|
||||||
else if(args[0].equalsIgnoreCase("kick")) {
|
else if (args[0].equalsIgnoreCase("kick")) {
|
||||||
return kick(sender, args);
|
return kick(args[1]);
|
||||||
}
|
}
|
||||||
else if(args[0].equalsIgnoreCase("disband")) {
|
else if (args[0].equalsIgnoreCase("disband")) {
|
||||||
return disband(sender, args);
|
return disband();
|
||||||
}
|
}
|
||||||
else if(args[0].equalsIgnoreCase("owner")) {
|
else if (args[0].equalsIgnoreCase("owner")) {
|
||||||
return changeOwner(sender, args);
|
return changeOwner(args);
|
||||||
}
|
}
|
||||||
else if(args[0].equalsIgnoreCase("lock")) {
|
else if (args[0].equalsIgnoreCase("lock")) {
|
||||||
return lock(sender, args);
|
return lock();
|
||||||
}
|
}
|
||||||
else if(args[0].equalsIgnoreCase("unlock")) {
|
else if (args[0].equalsIgnoreCase("unlock")) {
|
||||||
return unlock(sender, args);
|
return unlock();
|
||||||
}
|
}
|
||||||
else if(args[0].equalsIgnoreCase("password")) {
|
else if (args[0].equalsIgnoreCase("password")) {
|
||||||
return changePassword(sender, args);
|
return changePassword(args);
|
||||||
}
|
}
|
||||||
else if(args[0].equalsIgnoreCase("rename")) {
|
else if (args[0].equalsIgnoreCase("rename")) {
|
||||||
return rename(sender, args);
|
return rename(args);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return printUsage(sender);
|
return printUsage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
||||||
return printUsage(sender);
|
return printUsage();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean printUsage(CommandSender sender) {
|
private boolean printUsage() {
|
||||||
Player player = (Player) sender;
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.2"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean party(CommandSender sender) {
|
private boolean party() {
|
||||||
Player player = (Player) sender;
|
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
|
|
||||||
if (playerProfile.inParty()) {
|
if (playerProfile.inParty()) {
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
|
|
||||||
@ -139,89 +133,83 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", new Object[] {tempList}));
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Members", new Object[] {tempList}));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return printUsage(sender);
|
return printUsage();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean join(CommandSender sender, String[] args) {
|
private boolean join(String[] args) {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.join")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.join")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
|
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.0"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Player target = Bukkit.getServer().getPlayer(args[1]);
|
|
||||||
|
|
||||||
if (target == null) {
|
Player target = mcMMO.p.getServer().getPlayer(args[1]);
|
||||||
player.sendMessage(LocaleLoader.getString("Party.NotOnline", new Object[] {args[1]}));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Users.getProfile(target).inParty()) {
|
if (target == null) {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", new Object[] {args[1]}));
|
player.sendMessage(LocaleLoader.getString("Party.NotOnline", new Object[] {args[1]}));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.equals(target)) {
|
if (!Users.getProfile(target).inParty()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Join.Self"));
|
player.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", new Object[] {args[1]}));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.equals(target)) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Party.Join.Self"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String password = null;
|
||||||
|
|
||||||
|
if (args.length > 2) {
|
||||||
|
password = args[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
String partyTarget = PartyManager.getPlayerParty(target.getName()).getName();
|
||||||
|
Party newParty = PartyManager.getParty(args[0]);
|
||||||
|
|
||||||
|
// Check to see if the party exists, and if it does, can the player join it?
|
||||||
|
if (newParty != null && !PartyManager.checkJoinability(player, newParty, null)) {
|
||||||
|
return true; // End before any event is fired.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (party != null) {
|
||||||
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), partyTarget, EventReason.CHANGED_PARTIES);
|
||||||
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String password = null;
|
PartyManager.removeFromParty(playerName, party);
|
||||||
|
|
||||||
if(args.length > 2) {
|
|
||||||
password = args[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
String partyTarget = PartyManager.getPlayerParty(target.getName()).getName();
|
|
||||||
Party newParty = PartyManager.getParty(args[0]);
|
|
||||||
|
|
||||||
// Check to see if the party exists, and if it does, can the player join it?
|
|
||||||
if (newParty != null && !PartyManager.checkJoinability(player, newParty, null)) {
|
|
||||||
return true; // End before any event is fired.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (party != null) {
|
|
||||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), partyTarget, EventReason.CHANGED_PARTIES);
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
PartyManager.removeFromParty(playerName, party);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyTarget, EventReason.JOINED_PARTY);
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PartyManager.joinParty(player, playerProfile, partyTarget, password);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyTarget, EventReason.JOINED_PARTY);
|
||||||
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PartyManager.joinParty(player, playerProfile, partyTarget, password);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean accept(CommandSender sender, String[] args) {
|
private boolean accept() {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.accept")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.accept")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
|
|
||||||
if (playerProfile.hasPartyInvite()) {
|
if (playerProfile.hasPartyInvite()) {
|
||||||
if (playerProfile.inParty()) {
|
if (playerProfile.inParty()) {
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
@ -253,68 +241,66 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean create(CommandSender sender, String[] args) {
|
private boolean create(String[] args) {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.create")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.create")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
|
|
||||||
if(args.length < 2) {
|
if (args.length < 2) {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String partyname = args[1];
|
||||||
|
String password = null;
|
||||||
|
|
||||||
|
if (args.length > 2) {
|
||||||
|
password = args[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
Party newParty = PartyManager.getParty(partyname);
|
||||||
|
// Check to see if the party exists, and if it does cancel creating a new party
|
||||||
|
if (newParty != null) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", new Object[] {partyname}));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playerProfile.inParty()) {
|
||||||
|
String oldPartyName = party.getName();
|
||||||
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, partyname, EventReason.CHANGED_PARTIES);
|
||||||
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PartyManager.removeFromParty(playerName, party);
|
||||||
|
PartyManager.createParty(player, playerProfile, partyname, password);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
String partyname = args[1];
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyname, EventReason.JOINED_PARTY);
|
||||||
String password = null;
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
if(args.length > 2) password = args[2];
|
|
||||||
|
|
||||||
Party newParty = PartyManager.getParty(partyname);
|
if (event.isCancelled()) {
|
||||||
// Check to see if the party exists, and if it does cancel creating a new party
|
|
||||||
if (newParty != null) {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", new Object[] {partyname}));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerProfile.inParty()) {
|
PartyManager.createParty(player, playerProfile, partyname, password);
|
||||||
String oldPartyName = party.getName();
|
return true;
|
||||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, partyname, EventReason.CHANGED_PARTIES);
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
PartyManager.removeFromParty(playerName, party);
|
|
||||||
PartyManager.createParty(player, playerProfile, partyname, password);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyname, EventReason.JOINED_PARTY);
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
PartyManager.createParty(player, playerProfile, partyname, password);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean quit(CommandSender sender, String[] args) {
|
private boolean quit() {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.quit")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.quit")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
|
|
||||||
if (party != null) {
|
if (party != null) {
|
||||||
@ -334,16 +320,15 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shareExp(CommandSender sender, String[] args) {
|
private boolean shareExp() {
|
||||||
return (!CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.expshare"));
|
return (!CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.expshare"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shareItem(CommandSender sender, String[] args) {
|
private boolean shareItem() {
|
||||||
return (!CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.itemshare"));
|
return (!CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.itemshare"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean printHelp(CommandSender sender, String[] args) {
|
private boolean printHelp() {
|
||||||
Player player = (Player) sender;
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.3"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.3"));
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.4"));
|
player.sendMessage(LocaleLoader.getString("Party.Help.4"));
|
||||||
@ -354,16 +339,13 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean invite(CommandSender sender, String[] args) {
|
private boolean invite(String[] args) {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.invite")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.invite")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 2:
|
case 2:
|
||||||
Player player = (Player) sender;
|
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
|
|
||||||
if (!playerProfile.inParty()) {
|
if (!playerProfile.inParty()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
||||||
return true;
|
return true;
|
||||||
@ -394,7 +376,7 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "invite", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"}));
|
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "invite", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"}));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -402,23 +384,21 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
/**
|
/**
|
||||||
* Kick a party member
|
* Kick a party member
|
||||||
*/
|
*/
|
||||||
private boolean kick(CommandSender sender, String[] args) {
|
private boolean kick(String targetName) {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.kick")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.kick")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
|
|
||||||
if (party.getLeader().equals(playerName)) {
|
if (party.getLeader().equals(playerName)) {
|
||||||
if (!party.getMembers().contains(args[1])) {
|
if (!party.getMembers().contains(targetName)) {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {args[1]}));
|
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", new Object[] {targetName}));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player target = mcMMO.p.getServer().getOfflinePlayer(args[1]).getPlayer();
|
Player target = mcMMO.p.getServer().getOfflinePlayer(targetName).getPlayer();
|
||||||
|
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
String partyName = party.getName();
|
String partyName = party.getName();
|
||||||
@ -433,7 +413,7 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", new Object[] {partyName}));
|
target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", new Object[] {partyName}));
|
||||||
}
|
}
|
||||||
|
|
||||||
PartyManager.removeFromParty(args[1], party);
|
PartyManager.removeFromParty(targetName, party);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
||||||
@ -445,14 +425,12 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
/**
|
/**
|
||||||
* Disband the current party, kicks out all party members.
|
* Disband the current party, kicks out all party members.
|
||||||
*/
|
*/
|
||||||
private boolean disband(CommandSender sender, String[] args) {
|
private boolean disband() {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.disband")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.disband")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
|
|
||||||
if (party.getLeader().equals(playerName)) {
|
if (party.getLeader().equals(playerName)) {
|
||||||
@ -479,18 +457,16 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
/**
|
/**
|
||||||
* Change the owner of the current party
|
* Change the owner of the current party
|
||||||
*/
|
*/
|
||||||
private boolean changeOwner(CommandSender sender, String[] args) {
|
private boolean changeOwner(String[] args) {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.owner")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.owner")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
|
|
||||||
if(args.length < 2) {
|
if (args.length < 2) {
|
||||||
player.sendMessage("Usage: /party owner [player]");
|
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "owner", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"}));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -509,14 +485,12 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
/**
|
/**
|
||||||
* Lock the current party
|
* Lock the current party
|
||||||
*/
|
*/
|
||||||
private boolean lock(CommandSender sender, String[] args) {
|
private boolean lock() {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.lock")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.lock")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
|
|
||||||
if (party != null) {
|
if (party != null) {
|
||||||
@ -543,14 +517,12 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
/**
|
/**
|
||||||
* Unlock the current party
|
* Unlock the current party
|
||||||
*/
|
*/
|
||||||
private boolean unlock(CommandSender sender, String[] args) {
|
private boolean unlock() {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.unlock")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.unlock")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
|
|
||||||
if (party != null) {
|
if (party != null) {
|
||||||
@ -574,14 +546,12 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean changePassword(CommandSender sender, String[] args) {
|
private boolean changePassword(String[] args) {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.password")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.password")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
|
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
@ -604,14 +574,12 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
/**
|
/**
|
||||||
* Rename the current party
|
* Rename the current party
|
||||||
*/
|
*/
|
||||||
private boolean rename(CommandSender sender, String[] args) {
|
private boolean rename(String[] args) {
|
||||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.party.rename")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.rename")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
PlayerProfile playerProfile = Users.getProfile(player);
|
|
||||||
Party party = playerProfile.getParty();
|
Party party = playerProfile.getParty();
|
||||||
String leader = party.getLeader();
|
String leader = party.getLeader();
|
||||||
|
|
||||||
@ -620,37 +588,36 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "rename", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">"}));
|
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", new Object[] {"party", "rename", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">"}));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
String newPartyName = args[1];
|
|
||||||
|
|
||||||
// This is to prevent party leaders from spamming other players with the rename message
|
String newPartyName = args[1];
|
||||||
if (!party.getName().equals(newPartyName)) {
|
|
||||||
Party newParty = PartyManager.getParty(newPartyName);
|
|
||||||
|
|
||||||
// Check to see if the party exists, and if it does cancel renaming the party
|
// This is to prevent party leaders from spamming other players with the rename message
|
||||||
if (newParty != null) {
|
if (!party.getName().equals(newPartyName)) {
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", new Object[] {newPartyName}));
|
Party newParty = PartyManager.getParty(newPartyName);
|
||||||
|
|
||||||
|
// Check to see if the party exists, and if it does cancel renaming the party
|
||||||
|
if (newParty != null) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", new Object[] {newPartyName}));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player onlineMembers : party.getOnlineMembers()) {
|
||||||
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMembers, party.getName(), newPartyName, EventReason.CHANGED_PARTIES);
|
||||||
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Player onlineMembers : party.getOnlineMembers()) {
|
if (!onlineMembers.getName().equals(leader)) {
|
||||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMembers, party.getName(), newPartyName, EventReason.CHANGED_PARTIES);
|
onlineMembers.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", new Object[] {leader, newPartyName}));
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!onlineMembers.getName().equals(leader)) {
|
|
||||||
onlineMembers.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", new Object[] {leader, newPartyName}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
party.setName(newPartyName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Rename", new Object[] {newPartyName}));
|
party.setName(newPartyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Rename", new Object[] {newPartyName}));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
||||||
|
Loading…
Reference in New Issue
Block a user