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