mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Cleaning up PartyManager
This commit is contained in:
parent
2cd9a5658e
commit
94a5bef62c
@ -24,7 +24,7 @@ public class PartyAcceptCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
// Changing parties
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), mcMMOPlayer.getPartyInvite().getName())) {
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, mcMMOPlayer.getPartyInvite().getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
@ -17,18 +16,16 @@ public class PartyCreateCommand implements CommandExecutor {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
case 3:
|
||||
Party newParty = PartyManager.getParty(args[1]);
|
||||
|
||||
Player player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
// Check to see if the party exists, and if it does cancel creating a new party
|
||||
if (PartyManager.checkPartyExistence(player, newParty, args[1])) {
|
||||
if (PartyManager.checkPartyExistence(player, args[1])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Changing parties
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), args[1])) {
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, args[1])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
public class PartyInfoCommand implements CommandExecutor {
|
||||
private McMMOPlayer mcMMOPlayer;
|
||||
private Player player;
|
||||
private Party playerParty;
|
||||
|
||||
@ -25,7 +26,7 @@ public class PartyInfoCommand implements CommandExecutor {
|
||||
case 0:
|
||||
case 1:
|
||||
player = (Player) sender;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
mcMMOPlayer = UserManager.getPlayer(player);
|
||||
playerParty = mcMMOPlayer.getParty();
|
||||
|
||||
displayPartyHeader();
|
||||
@ -103,7 +104,7 @@ public class PartyInfoCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
private void displayMemberInfo() {
|
||||
int membersNear = PartyManager.getNearMembers(player, playerParty, Config.getInstance().getPartyShareRange()).size();
|
||||
int membersNear = PartyManager.getNearMembers(mcMMOPlayer).size();
|
||||
int membersOnline = playerParty.getOnlineMembers().size() - 1;
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
|
||||
|
@ -20,7 +20,6 @@ public class PartyJoinCommand implements CommandExecutor {
|
||||
|
||||
private McMMOPlayer mcMMOPlayer;
|
||||
private Player player;
|
||||
private Party playerParty;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
@ -43,7 +42,7 @@ public class PartyJoinCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
// Changing parties
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, playerParty, targetParty.getName())) {
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, targetParty.getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -81,11 +80,9 @@ public class PartyJoinCommand implements CommandExecutor {
|
||||
|
||||
player = (Player) sender;
|
||||
mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
playerParty = mcMMOPlayer.getParty();
|
||||
targetParty = mcMMOTarget.getParty();
|
||||
|
||||
if (player.equals(target) || (mcMMOPlayer.inParty() && playerParty.equals(targetParty))) {
|
||||
if (player.equals(target) || (mcMMOPlayer.inParty() && mcMMOPlayer.getParty().equals(targetParty))) {
|
||||
sender.sendMessage(LocaleLoader.getString("Party.Join.Self"));
|
||||
return false;
|
||||
}
|
||||
|
@ -30,10 +30,9 @@ public class PartyRenameCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
Party newParty = PartyManager.getParty(newPartyName);
|
||||
|
||||
// Check to see if the party exists, and if it does cancel renaming the party
|
||||
if (PartyManager.checkPartyExistence(player, newParty, newPartyName)) {
|
||||
if (PartyManager.checkPartyExistence(player, newPartyName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.party.ItemShareType;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@ -28,8 +29,15 @@ public final class PartyManager {
|
||||
|
||||
private PartyManager() {}
|
||||
|
||||
public static boolean checkPartyExistence(Player player, Party party, String partyName) {
|
||||
if (party == null) {
|
||||
/**
|
||||
* Check if a party with a given name already exists.
|
||||
*
|
||||
* @param player The player to notify
|
||||
* @param partyName The name of the party to check
|
||||
* @return true if a party with that name exists, false otherwise
|
||||
*/
|
||||
public static boolean checkPartyExistence(Player player, String partyName) {
|
||||
if (getParty(partyName) == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -37,8 +45,19 @@ public final class PartyManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean changeOrJoinParty(McMMOPlayer mcMMOPlayer, Player player, Party oldParty, String newPartyName) {
|
||||
/**
|
||||
* Attempt to change parties or join a new party.
|
||||
*
|
||||
* @param mcMMOPlayer The player changing or joining parties
|
||||
* @param newPartyName The name of the party being joined
|
||||
* @return true if the party was joined successfully, false otherwise
|
||||
*/
|
||||
public static boolean changeOrJoinParty(McMMOPlayer mcMMOPlayer, String newPartyName) {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (mcMMOPlayer.inParty()) {
|
||||
Party oldParty = mcMMOPlayer.getParty();
|
||||
|
||||
if (!handlePartyChangeEvent(player, oldParty.getName(), newPartyName, EventReason.CHANGED_PARTIES)) {
|
||||
return false;
|
||||
}
|
||||
@ -60,27 +79,31 @@ public final class PartyManager {
|
||||
* @return true if they are in the same party, false otherwise
|
||||
*/
|
||||
public static boolean inSameParty(Player firstPlayer, Player secondPlayer) {
|
||||
McMMOPlayer firstMcMMOPlayer = UserManager.getPlayer(firstPlayer);
|
||||
McMMOPlayer secondMcMMOPlayer = UserManager.getPlayer(secondPlayer);
|
||||
Party firstParty = UserManager.getPlayer(firstPlayer).getParty();
|
||||
Party secondParty = UserManager.getPlayer(secondPlayer).getParty();
|
||||
|
||||
if (firstMcMMOPlayer.getParty() == null || secondMcMMOPlayer.getParty() == null) {
|
||||
if (firstParty == null || secondParty == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return firstMcMMOPlayer.getParty().equals(secondMcMMOPlayer.getParty());
|
||||
return firstParty.equals(secondParty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the near party members.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param mcMMOPlayer The player to check
|
||||
* @param range The distance
|
||||
* @return the near party members
|
||||
*/
|
||||
public static List<Player> getNearMembers(Player player, Party party, double range) {
|
||||
public static List<Player> getNearMembers(McMMOPlayer mcMMOPlayer) {
|
||||
List<Player> nearMembers = new ArrayList<Player>();
|
||||
Party party = mcMMOPlayer.getParty();
|
||||
|
||||
if (party != null) {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
double range = Config.getInstance().getPartyShareRange();
|
||||
|
||||
for (Player member : party.getOnlineMembers()) {
|
||||
if (!player.equals(member) && member.isValid() && Misc.isNear(player.getLocation(), member.getLocation(), range)) {
|
||||
nearMembers.add(member);
|
||||
|
@ -34,14 +34,13 @@ public final class ShareHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
List<Player> nearMembers = PartyManager.getNearMembers(mcMMOPlayer);
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nearMembers.add(player);
|
||||
nearMembers.add(mcMMOPlayer.getPlayer());
|
||||
|
||||
int partySize = nearMembers.size();
|
||||
double shareBonus = Math.min(Config.getInstance().getPartyShareBonusBase() + (partySize * Config.getInstance().getPartyShareBonusIncrease()), Config.getInstance().getPartyShareBonusCap());
|
||||
@ -81,8 +80,7 @@ public final class ShareHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
List<Player> nearMembers = PartyManager.getNearMembers(mcMMOPlayer);
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
@ -91,7 +89,7 @@ public final class ShareHandler {
|
||||
Player winningPlayer = null;
|
||||
ItemStack newStack = itemStack.clone();
|
||||
|
||||
nearMembers.add(player);
|
||||
nearMembers.add(mcMMOPlayer.getPlayer());
|
||||
int partySize = nearMembers.size();
|
||||
|
||||
drop.remove();
|
||||
|
Loading…
Reference in New Issue
Block a user