OOP is good.

This commit is contained in:
GJ 2013-05-21 15:56:09 -04:00
parent 9a5f4b638f
commit 663d54d31f
23 changed files with 144 additions and 146 deletions

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.api;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.chat.ChatManager; import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@ -22,7 +23,7 @@ public final class ChatAPI {
* @param message The message to send * @param message The message to send
*/ */
public static void sendPartyChat(Plugin plugin, String sender, String displayName, String party, String message) { public static void sendPartyChat(Plugin plugin, String sender, String displayName, String party, String message) {
ChatManager.handlePartyChat(plugin, PartyManager.getParty(party), sender, displayName, message); ChatManager.handlePartyChat(plugin, mcMMO.getPartyManager().getParty(party), sender, displayName, message);
} }
/** /**
@ -36,7 +37,7 @@ public final class ChatAPI {
* @param message The message to send * @param message The message to send
*/ */
public static void sendPartyChat(Plugin plugin, String sender, String party, String message) { public static void sendPartyChat(Plugin plugin, String sender, String party, String message) {
ChatManager.handlePartyChat(plugin, PartyManager.getParty(party), sender, sender, message); ChatManager.handlePartyChat(plugin, mcMMO.getPartyManager().getParty(party), sender, sender, message);
} }
/** /**

View File

@ -53,7 +53,7 @@ public final class PartyAPI {
* @return true if the two players are in the same party, false otherwise * @return true if the two players are in the same party, false otherwise
*/ */
public static boolean inSameParty(Player playera, Player playerb) { public static boolean inSameParty(Player playera, Player playerb) {
return PartyManager.inSameParty(playera, playerb); return mcMMO.getPartyManager().inSameParty(playera, playerb);
} }
/** /**
@ -64,7 +64,7 @@ public final class PartyAPI {
* @return the list of parties. * @return the list of parties.
*/ */
public static List<Party> getParties() { public static List<Party> getParties() {
return PartyManager.getParties(); return mcMMO.getPartyManager().getParties();
} }
/** /**
@ -76,7 +76,7 @@ public final class PartyAPI {
* @param partyName The party to add the player to * @param partyName The party to add the player to
*/ */
public static void addToParty(Player player, String partyName) { public static void addToParty(Player player, String partyName) {
Party party = PartyManager.getParty(partyName); Party party = mcMMO.getPartyManager().getParty(partyName);
if (party == null) { if (party == null) {
party = new Party(); party = new Party();
@ -84,7 +84,7 @@ public final class PartyAPI {
party.setLeader(player.getName()); party.setLeader(player.getName());
} }
PartyManager.addToParty(player, UserManager.getPlayer(player), party); mcMMO.getPartyManager().addToParty(player, party);
} }
/** /**
@ -95,7 +95,7 @@ public final class PartyAPI {
* @param player The player to remove * @param player The player to remove
*/ */
public static void removeFromParty(Player player) { public static void removeFromParty(Player player) {
PartyManager.removeFromParty(player, UserManager.getPlayer(player).getParty()); mcMMO.getPartyManager().removeFromParty(player, UserManager.getPlayer(player).getParty());
} }
/** /**
@ -107,7 +107,7 @@ public final class PartyAPI {
* @return the leader of the party * @return the leader of the party
*/ */
public static String getPartyLeader(String partyName) { public static String getPartyLeader(String partyName) {
return PartyManager.getPartyLeader(partyName); return mcMMO.getPartyManager().getPartyLeader(partyName);
} }
/** /**
@ -119,7 +119,7 @@ public final class PartyAPI {
* @param player The player to set as leader * @param player The player to set as leader
*/ */
public static void setPartyLeader(String partyName, String player) { public static void setPartyLeader(String partyName, String player) {
PartyManager.setPartyLeader(player, PartyManager.getParty(partyName)); mcMMO.getPartyManager().setPartyLeader(player, mcMMO.getPartyManager().getParty(partyName));
} }
/** /**
@ -134,7 +134,7 @@ public final class PartyAPI {
public static List<OfflinePlayer> getOnlineAndOfflineMembers(Player player) { public static List<OfflinePlayer> getOnlineAndOfflineMembers(Player player) {
List<OfflinePlayer> members = new ArrayList<OfflinePlayer>(); List<OfflinePlayer> members = new ArrayList<OfflinePlayer>();
for (String memberName : PartyManager.getAllMembers(player)) { for (String memberName : mcMMO.getPartyManager().getAllMembers(UserManager.getPlayer(player).getParty())) {
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName); OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
members.add(member); members.add(member);
} }
@ -150,7 +150,7 @@ public final class PartyAPI {
* @return all the player names in the player's party * @return all the player names in the player's party
*/ */
public static LinkedHashSet<String> getMembers(Player player) { public static LinkedHashSet<String> getMembers(Player player) {
return PartyManager.getAllMembers(player); return mcMMO.getPartyManager().getAllMembers(UserManager.getPlayer(player).getParty());
} }
/** /**
@ -162,7 +162,7 @@ public final class PartyAPI {
* @return all online players in this party * @return all online players in this party
*/ */
public static List<Player> getOnlineMembers(String partyName) { public static List<Player> getOnlineMembers(String partyName) {
return PartyManager.getOnlineMembers(partyName); return mcMMO.getPartyManager().getOnlineMembers(partyName);
} }
/** /**
@ -174,6 +174,6 @@ public final class PartyAPI {
* @return all online players in the player's party * @return all online players in the player's party
*/ */
public static List<Player> getOnlineMembers(Player player) { public static List<Player> getOnlineMembers(Player player) {
return PartyManager.getOnlineMembers(player); return mcMMO.getPartyManager().getOnlineMembers(UserManager.getPlayer(player).getParty().getName());
} }
} }

View File

@ -35,7 +35,7 @@ public class PartyChatCommand extends ChatCommand {
return; return;
} }
Party party = PartyManager.getParty(args[0]); Party party = mcMMO.getPartyManager().getParty(args[0]);
if (party == null) { if (party == null) {
sender.sendMessage(LocaleLoader.getString("Party.InvalidName")); sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));

View File

@ -5,6 +5,7 @@ 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.mcMMO;
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;
@ -24,11 +25,11 @@ public class PartyAcceptCommand implements CommandExecutor {
} }
// Changing parties // Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), mcMMOPlayer.getPartyInvite().getName())) { if (!mcMMO.getPartyManager().changeOrJoinParty(mcMMOPlayer, mcMMOPlayer.getPartyInvite().getName())) {
return true; return true;
} }
PartyManager.joinInvitedParty(player, mcMMOPlayer); mcMMO.getPartyManager().joinInvitedParty(player);
return true; return true;
default: default:

View File

@ -4,6 +4,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
@ -21,7 +22,7 @@ public class PartyChangeOwnerCommand implements CommandExecutor {
return true; return true;
} }
PartyManager.setPartyLeader(args[1], playerParty); mcMMO.getPartyManager().setPartyLeader(args[1], playerParty);
return true; return true;
default: default:

View File

@ -5,7 +5,7 @@ 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.mcMMO;
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,22 +17,20 @@ 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]);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName()); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
Player player = mcMMOPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
// 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 (mcMMO.getPartyManager().checkPartyExistence(player, args[1])) {
return true; return true;
} }
// Changing parties // Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), args[1])) { if (!mcMMO.getPartyManager().changeOrJoinParty(mcMMOPlayer, args[1])) {
return true; return true;
} }
PartyManager.createParty(player, mcMMOPlayer, args[1], getPassword(args)); mcMMO.getPartyManager().createParty(player, args[1], getPassword(args));
return true; return true;
default: default:

View File

@ -5,6 +5,7 @@ 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.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
@ -20,14 +21,14 @@ public class PartyDisbandCommand implements CommandExecutor {
String partyName = playerParty.getName(); String partyName = playerParty.getName();
for (Player member : playerParty.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
if (!PartyManager.handlePartyChangeEvent(member, partyName, null, EventReason.KICKED_FROM_PARTY)) { if (!mcMMO.getPartyManager().handlePartyChangeEvent(member, partyName, null, EventReason.KICKED_FROM_PARTY)) {
return true; return true;
} }
member.sendMessage(LocaleLoader.getString("Party.Disband")); member.sendMessage(LocaleLoader.getString("Party.Disband"));
} }
PartyManager.disbandParty(playerParty); mcMMO.getPartyManager().disbandParty(playerParty);
return true; return true;
default: default:

View File

@ -104,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 = mcMMO.getPartyManager().getNearbyPartyMembers(player, Config.getInstance().getPartyShareRange()).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"));

View File

@ -5,6 +5,7 @@ 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.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; 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;
@ -32,14 +33,14 @@ public class PartyInviteCommand implements CommandExecutor {
return true; return true;
} }
if (PartyManager.inSameParty(player, target)) { if (mcMMO.getPartyManager().inSameParty(player, target)) {
sender.sendMessage(LocaleLoader.getString("Party.Player.InSameParty", target.getName())); sender.sendMessage(LocaleLoader.getString("Party.Player.InSameParty", target.getName()));
return true; return true;
} }
Party playerParty = mcMMOPlayer.getParty(); Party playerParty = mcMMOPlayer.getParty();
if (!PartyManager.canInvite(player, playerParty)) { if (!mcMMO.getPartyManager().canInvite(player)) {
player.sendMessage(LocaleLoader.getString("Party.Locked")); player.sendMessage(LocaleLoader.getString("Party.Locked"));
return true; return true;
} }

View File

@ -5,6 +5,7 @@ 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.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; 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;
@ -37,16 +38,16 @@ public class PartyJoinCommand implements CommandExecutor {
String password = getPassword(args); String password = getPassword(args);
// Make sure party passwords match // Make sure party passwords match
if (!PartyManager.checkPartyPassword(player, targetParty, password)) { if (!mcMMO.getPartyManager().checkPartyPassword(player, targetParty, password)) {
return true; return true;
} }
// Changing parties // Changing parties
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, playerParty, targetParty.getName())) { if (!mcMMO.getPartyManager().changeOrJoinParty(mcMMOPlayer, targetParty.getName())) {
return true; return true;
} }
PartyManager.joinParty(player, mcMMOPlayer, targetParty, password); mcMMO.getPartyManager().joinParty(player, targetParty, password);
return true; return true;
default: default:

View File

@ -30,14 +30,14 @@ public class PartyKickCommand implements CommandExecutor {
Player onlineTarget = target.getPlayer(); Player onlineTarget = target.getPlayer();
String partyName = playerParty.getName(); String partyName = playerParty.getName();
if (!PartyManager.handlePartyChangeEvent(onlineTarget, partyName, null, EventReason.KICKED_FROM_PARTY)) { if (!mcMMO.getPartyManager().handlePartyChangeEvent(onlineTarget, partyName, null, EventReason.KICKED_FROM_PARTY)) {
return true; return true;
} }
onlineTarget.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName)); onlineTarget.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName));
} }
PartyManager.removeFromParty(target, playerParty); mcMMO.getPartyManager().removeFromParty(target, playerParty);
return true; return true;
default: default:

View File

@ -5,6 +5,7 @@ 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.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
@ -19,11 +20,11 @@ public class PartyQuitCommand implements CommandExecutor {
Player player = (Player) sender; Player player = (Player) sender;
Party playerParty = UserManager.getPlayer(player).getParty(); Party playerParty = UserManager.getPlayer(player).getParty();
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), null, EventReason.LEFT_PARTY)) { if (!mcMMO.getPartyManager().handlePartyChangeEvent(player, playerParty.getName(), null, EventReason.LEFT_PARTY)) {
return true; return true;
} }
PartyManager.removeFromParty(player, playerParty); mcMMO.getPartyManager().removeFromParty(player, playerParty);
sender.sendMessage(LocaleLoader.getString("Commands.Party.Leave")); sender.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
return true; return true;

View File

@ -5,6 +5,7 @@ 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.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; 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.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
@ -30,17 +31,16 @@ 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 (mcMMO.getPartyManager().checkPartyExistence(player, newPartyName)) {
return true; return true;
} }
String leaderName = playerParty.getLeader(); String leaderName = playerParty.getLeader();
for (Player member : playerParty.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
if (!PartyManager.handlePartyChangeEvent(member, oldPartyName, newPartyName, EventReason.CHANGED_PARTIES)) { if (!mcMMO.getPartyManager().handlePartyChangeEvent(member, oldPartyName, newPartyName, EventReason.CHANGED_PARTIES)) {
return true; return true;
} }

View File

@ -146,7 +146,7 @@ public class PtpCommand implements TabExecutor {
return false; return false;
} }
if (!PartyManager.inSameParty(player, target)) { if (!mcMMO.getPartyManager().inSameParty(player, target)) {
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName)); player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName));
return false; return false;
} }

View File

@ -94,7 +94,7 @@ public class McMMOPlayer {
this.player = player; this.player = player;
profile = new PlayerProfile(playerName, true); profile = new PlayerProfile(playerName, true);
party = PartyManager.getPlayerParty(playerName); party = mcMMO.getPartyManager().getPlayerParty(playerName);
/* /*
* I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually), * I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually),

View File

@ -155,7 +155,7 @@ public class EntityListener implements Listener {
return; return;
} }
if (PartyManager.inSameParty(defendingPlayer, attackingPlayer) && !(Permissions.friendlyFire(attackingPlayer) && Permissions.friendlyFire(defendingPlayer))) { if (mcMMO.getPartyManager().inSameParty(defendingPlayer, attackingPlayer) && !(Permissions.friendlyFire(attackingPlayer) && Permissions.friendlyFire(defendingPlayer))) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }

View File

@ -57,6 +57,7 @@ public class mcMMO extends JavaPlugin {
private static ChunkManager placeStore; private static ChunkManager placeStore;
private static RepairableManager repairableManager; private static RepairableManager repairableManager;
private static DatabaseManager databaseManager; private static DatabaseManager databaseManager;
private static PartyManager partyManager;
/* File Paths */ /* File Paths */
private static String mainDirectory; private static String mainDirectory;
@ -114,7 +115,7 @@ public class mcMMO extends JavaPlugin {
registerEvents(); registerEvents();
registerCustomRecipes(); registerCustomRecipes();
PartyManager.loadParties(); partyManager = new PartyManager(this);
for (Player player : getServer().getOnlinePlayers()) { for (Player player : getServer().getOnlinePlayers()) {
UserManager.addUser(player); // In case of reload add all users back into UserManager UserManager.addUser(player); // In case of reload add all users back into UserManager
@ -156,7 +157,7 @@ public class mcMMO extends JavaPlugin {
public void onDisable() { public void onDisable() {
try { try {
UserManager.saveAll(); // Make sure to save player information if the server shuts down UserManager.saveAll(); // Make sure to save player information if the server shuts down
PartyManager.saveParties(); // Save our parties partyManager.saveParties(); // Save our parties
placeStore.saveAll(); // Save our metadata placeStore.saveAll(); // Save our metadata
placeStore.cleanUp(); // Cleanup empty metadata stores placeStore.cleanUp(); // Cleanup empty metadata stores
} }
@ -235,6 +236,10 @@ public class mcMMO extends JavaPlugin {
return repairableManager; return repairableManager;
} }
public static PartyManager getPartyManager() {
return partyManager;
}
public static boolean isSpoutEnabled() { public static boolean isSpoutEnabled() {
return spoutEnabled; return spoutEnabled;
} }

View File

@ -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 org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -18,15 +19,20 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public final class PartyManager { public class PartyManager {
private static String partiesFilePath = mcMMO.getFlatFileDirectory() + "parties.yml"; private final mcMMO plugin;
private static List<Party> parties = new ArrayList<Party>(); private final String partiesFilePath = mcMMO.getFlatFileDirectory() + "parties.yml";
private static File partyFile = new File(partiesFilePath); private final List<Party> parties = new ArrayList<Party>();
private final File partyFile = new File(partiesFilePath);
private PartyManager() {} public PartyManager(final mcMMO plugin) {
this.plugin = plugin;
public static boolean checkPartyExistence(Player player, Party party, String partyName) { loadParties();
if (party == null) { }
public boolean checkPartyExistence(Player player, String partyName) {
if (getParty(partyName) == null) {
return false; return false;
} }
@ -34,8 +40,12 @@ public final class PartyManager {
return true; return true;
} }
public static boolean changeOrJoinParty(McMMOPlayer mcMMOPlayer, Player player, Party oldParty, String newPartyName) { public 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;
} }
@ -56,7 +66,7 @@ public final class PartyManager {
* @param secondPlayer The second player * @param secondPlayer The second player
* @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 boolean inSameParty(Player firstPlayer, Player secondPlayer) {
McMMOPlayer firstMcMMOPlayer = UserManager.getPlayer(firstPlayer); McMMOPlayer firstMcMMOPlayer = UserManager.getPlayer(firstPlayer);
McMMOPlayer secondMcMMOPlayer = UserManager.getPlayer(secondPlayer); McMMOPlayer secondMcMMOPlayer = UserManager.getPlayer(secondPlayer);
@ -81,15 +91,20 @@ public final class PartyManager {
* @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 List<Player> getNearbyPartyMembers(Player player, double range) {
List<Player> nearMembers = new ArrayList<Player>(); List<Player> nearMembers = new ArrayList<Player>();
Party party = UserManager.getPlayer(player).getParty();
if (party != null) { if (party != null) {
Location playerLocation = player.getLocation();
for (Player member : party.getOnlineMembers()) { for (Player member : party.getOnlineMembers()) {
if (!player.getName().equalsIgnoreCase(member.getName()) && !member.isDead() && Misc.isNear(player.getLocation(), member.getLocation(), range)) { if (!player.equals(member) && !member.isValid() && Misc.isNear(playerLocation, member.getLocation(), range)) {
nearMembers.add(member); nearMembers.add(member);
} }
} }
} }
return nearMembers; return nearMembers;
} }
@ -99,9 +114,7 @@ public final class PartyManager {
* @param player The player to check * @param player The player to check
* @return all the players in the player's party * @return all the players in the player's party
*/ */
public static LinkedHashSet<String> getAllMembers(Player player) { public LinkedHashSet<String> getAllMembers(Party party) {
Party party = UserManager.getPlayer(player).getParty();
if (party == null) { if (party == null) {
return null; return null;
} }
@ -115,7 +128,7 @@ public final class PartyManager {
* @param partyName The party to check * @param partyName The party to check
* @return all online players in this party * @return all online players in this party
*/ */
public static List<Player> getOnlineMembers(String partyName) { public List<Player> getOnlineMembers(String partyName) {
Party party = getParty(partyName); Party party = getParty(partyName);
if (party == null) { if (party == null) {
@ -125,29 +138,13 @@ public final class PartyManager {
return party.getOnlineMembers(); return party.getOnlineMembers();
} }
/**
* Get a list of all online players in this party.
*
* @param player The player to check
* @return all online players in this party
*/
public static List<Player> getOnlineMembers(Player player) {
Party party = getPlayerParty(player.getName());
if (party == null) {
return null;
}
return getOnlineMembers(party.getName());
}
/** /**
* Retrieve a party by its name * Retrieve a party by its name
* *
* @param partyName The party name * @param partyName The party name
* @return the existing party, null otherwise * @return the existing party, null otherwise
*/ */
public static Party getParty(String partyName) { public Party getParty(String partyName) {
for (Party party : parties) { for (Party party : parties) {
if (party.getName().equals(partyName)) { if (party.getName().equals(partyName)) {
return party; return party;
@ -163,7 +160,7 @@ public final class PartyManager {
* @param playerName The member name * @param playerName The member name
* @return the existing party, null otherwise * @return the existing party, null otherwise
*/ */
public static Party getPlayerParty(String playerName) { public Party getPlayerParty(String playerName) {
for (Party party : parties) { for (Party party : parties) {
for (String memberName : party.getMembers()) { for (String memberName : party.getMembers()) {
if (memberName.equalsIgnoreCase(playerName)) { if (memberName.equalsIgnoreCase(playerName)) {
@ -180,7 +177,7 @@ public final class PartyManager {
* *
* @return the list of parties. * @return the list of parties.
*/ */
public static List<Party> getParties() { public List<Party> getParties() {
return parties; return parties;
} }
@ -190,7 +187,7 @@ public final class PartyManager {
* @param player The player to remove * @param player The player to remove
* @param party The party * @param party The party
*/ */
public static void removeFromParty(OfflinePlayer player, Party party) { public void removeFromParty(OfflinePlayer player, Party party) {
LinkedHashSet<String> members = party.getMembers(); LinkedHashSet<String> members = party.getMembers();
members.remove(player.getName()); members.remove(player.getName());
@ -201,20 +198,13 @@ public final class PartyManager {
else { else {
// If the leaving player was the party leader, appoint a new leader from the party members // If the leaving player was the party leader, appoint a new leader from the party members
if (party.getLeader().equalsIgnoreCase(player.getName())) { if (party.getLeader().equalsIgnoreCase(player.getName())) {
String newLeader = members.iterator().next(); party.setLeader(members.iterator().next());
party.setLeader(newLeader);
} }
informPartyMembersQuit(player, party); informPartyMembersQuit(player, party);
} }
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player.getName()); processPlayerLeaving(UserManager.getPlayer(player));
if (mcMMOPlayer != null) {
mcMMOPlayer.removeParty();
mcMMOPlayer.setPartyChat(false);
mcMMOPlayer.setItemShareModifier(10);
}
} }
/** /**
@ -222,17 +212,11 @@ public final class PartyManager {
* *
* @param party The party to remove * @param party The party to remove
*/ */
public static void disbandParty(Party party) { public void disbandParty(Party party) {
LinkedHashSet<String> members = party.getMembers(); LinkedHashSet<String> members = party.getMembers();
for (String memberName : members) { for (String memberName : members) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(memberName); processPlayerLeaving(UserManager.getPlayer(memberName));
if (mcMMOPlayer != null) {
mcMMOPlayer.removeParty();
mcMMOPlayer.setPartyChat(false);
mcMMOPlayer.setItemShareModifier(10);
}
} }
members.clear(); members.clear();
@ -243,11 +227,10 @@ public final class PartyManager {
* Create a new party * Create a new party
* *
* @param player The player to add to the party * @param player The player to add to the party
* @param mcMMOPlayer The player to add to the party
* @param partyName The party to add the player to * @param partyName The party to add the player to
* @param password The password for this party, null if there was no password * @param password The password for this party, null if there was no password
*/ */
public static void createParty(Player player, McMMOPlayer mcMMOPlayer, String partyName, String password) { public void createParty(Player player, String partyName, String password) {
partyName = partyName.replace(".", ""); partyName = partyName.replace(".", "");
Party party = getParty(partyName); Party party = getParty(partyName);
@ -271,7 +254,7 @@ public final class PartyManager {
} }
player.sendMessage(LocaleLoader.getString("Commands.Party.Create", party.getName())); player.sendMessage(LocaleLoader.getString("Commands.Party.Create", party.getName()));
addToParty(player, mcMMOPlayer, party); addToParty(player, party);
} }
/** /**
@ -282,17 +265,18 @@ public final class PartyManager {
* @param party The party to add the player to * @param party The party to add the player to
* @param password the password for this party, null if there was no password * @param password the password for this party, null if there was no password
*/ */
public static void joinParty(Player player, McMMOPlayer mcMMOPlayer, Party party, String password) { public void joinParty(Player player, Party party, String password) {
if (!checkPartyPassword(player, party, password)) { if (!checkPartyPassword(player, party, password)) {
return; return;
} }
if (mcMMOPlayer.getParty() == party) { // // Pretty sure this isn't possible.
return; // if (mcMMOPlayer.getParty() == party) {
} // return;
// }
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", party.getName())); player.sendMessage(LocaleLoader.getString("Commands.Party.Join", party.getName()));
addToParty(player, mcMMOPlayer, party); addToParty(player, party);
} }
/** /**
@ -303,7 +287,7 @@ public final class PartyManager {
* @param password The password provided by the player * @param password The password provided by the player
* @return true if the player can join the party * @return true if the player can join the party
*/ */
public static boolean checkPartyPassword(Player player, Party party, String password) { public boolean checkPartyPassword(Player player, Party party, String password) {
// Don't care about passwords if it isn't locked // Don't care about passwords if it isn't locked
if (party.isLocked()) { if (party.isLocked()) {
String partyPassword = party.getPassword(); String partyPassword = party.getPassword();
@ -333,20 +317,22 @@ public final class PartyManager {
* @param Player The plaer to add to the party * @param Player The plaer to add to the party
* @param mcMMOPlayer The player to add to the party * @param mcMMOPlayer The player to add to the party
*/ */
public static void joinInvitedParty(Player player, McMMOPlayer mcMMOPlayer) { public void joinInvitedParty(Player player) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
Party invite = mcMMOPlayer.getPartyInvite(); Party invite = mcMMOPlayer.getPartyInvite();
if (mcMMOPlayer.getParty() == invite) { if (mcMMOPlayer.getParty() == invite) {
return; return;
} }
if (!parties.contains(invite)) { // // Pretty sure this isn't possible
parties.add(invite); // if (!parties.contains(invite)) {
} // parties.add(invite);
// }
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", invite.getName())); player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", invite.getName()));
mcMMOPlayer.removePartyInvite(); mcMMOPlayer.removePartyInvite();
addToParty(player, mcMMOPlayer, invite); addToParty(player, invite);
} }
/** /**
@ -356,11 +342,17 @@ public final class PartyManager {
* @param mcMMOPlayer The player to add to the party * @param mcMMOPlayer The player to add to the party
* @param party The party * @param party The party
*/ */
public static void addToParty(OfflinePlayer player, McMMOPlayer mcMMOPlayer, Party party) { public void addToParty(OfflinePlayer player, Party party) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (mcMMOPlayer.getParty() == party) { if (mcMMOPlayer.getParty() == party) {
return; return;
} }
if (!parties.contains(party)) {
parties.add(party);
}
informPartyMembersJoin(player, party); informPartyMembersJoin(player, party);
mcMMOPlayer.setParty(party); mcMMOPlayer.setParty(party);
@ -373,7 +365,7 @@ public final class PartyManager {
* @param partyName The party name * @param partyName The party name
* @return the leader of the party * @return the leader of the party
*/ */
public static String getPartyLeader(String partyName) { public String getPartyLeader(String partyName) {
Party party = getParty(partyName); Party party = getParty(partyName);
if (party == null) { if (party == null) {
@ -389,7 +381,7 @@ public final class PartyManager {
* @param playerName The name of the player to set as leader * @param playerName The name of the player to set as leader
* @param party The party * @param party The party
*/ */
public static void setPartyLeader(String playerName, Party party) { public void setPartyLeader(String playerName, Party party) {
String leaderName = party.getLeader(); String leaderName = party.getLeader();
for (Player member : party.getOnlineMembers()) { for (Player member : party.getOnlineMembers()) {
@ -414,7 +406,9 @@ public final class PartyManager {
* @param mcMMOPlayer The player to check * @param mcMMOPlayer The player to check
* @return true if the player can invite * @return true if the player can invite
*/ */
public static boolean canInvite(Player player, Party party) { public boolean canInvite(Player player) {
Party party = getPlayerParty(player.getName());
if (party.isLocked() && !party.getLeader().equalsIgnoreCase(player.getName())) { if (party.isLocked() && !party.getLeader().equalsIgnoreCase(player.getName())) {
return false; return false;
} }
@ -422,26 +416,10 @@ public final class PartyManager {
return true; return true;
} }
/**
* Check if a string is a valid party name.
*
* @param partyName The party name to check
* @return true if this is a valid party, false otherwise
*/
public static boolean isParty(String partyName) {
for (Party party : parties) {
if (party.getName().equals(partyName)) {
return true;
}
}
return false;
}
/** /**
* Load party file. * Load party file.
*/ */
public static void loadParties() { private void loadParties() {
if (!partyFile.exists()) { if (!partyFile.exists()) {
return; return;
} }
@ -472,7 +450,7 @@ public final class PartyManager {
/** /**
* Save party file. * Save party file.
*/ */
public static void saveParties() { public void saveParties() {
if (partyFile.exists()) { if (partyFile.exists()) {
partyFile.delete(); partyFile.delete();
} }
@ -516,7 +494,7 @@ public final class PartyManager {
* @param reason The reason for changing parties * @param reason The reason for changing parties
* @return true if the change event was successful, false otherwise * @return true if the change event was successful, false otherwise
*/ */
public static boolean handlePartyChangeEvent(Player player, String oldPartyName, String newPartyName, EventReason reason) { public boolean handlePartyChangeEvent(Player player, String oldPartyName, String newPartyName, EventReason reason) {
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, newPartyName, reason); McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, newPartyName, reason);
mcMMO.p.getServer().getPluginManager().callEvent(event); mcMMO.p.getServer().getPluginManager().callEvent(event);
@ -529,7 +507,7 @@ public final class PartyManager {
* @param player The player that joins * @param player The player that joins
* @param party The concerned party * @param party The concerned party
*/ */
private static void informPartyMembersJoin(OfflinePlayer player, Party party) { private void informPartyMembersJoin(OfflinePlayer player, Party party) {
for (Player member : party.getOnlineMembers()) { for (Player member : party.getOnlineMembers()) {
if (!member.equals(player)) { if (!member.equals(player)) {
member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", player.getName())); member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", player.getName()));
@ -543,11 +521,21 @@ public final class PartyManager {
* @param player The player that quits * @param player The player that quits
* @param party The concerned party * @param party The concerned party
*/ */
private static void informPartyMembersQuit(OfflinePlayer player, Party party) { private void informPartyMembersQuit(OfflinePlayer player, Party party) {
for (Player member : party.getOnlineMembers()) { for (Player member : party.getOnlineMembers()) {
if (!member.equals(player)) { if (!member.equals(player)) {
member.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", player.getName())); member.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", player.getName()));
} }
} }
} }
private void processPlayerLeaving(McMMOPlayer mcMMOPlayer) {
if (mcMMOPlayer == null) {
return;
}
mcMMOPlayer.removeParty();
mcMMOPlayer.setPartyChat(false);
mcMMOPlayer.setItemShareModifier(10);
}
} }

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.party.ItemWeightConfig; import com.gmail.nossr50.config.party.ItemWeightConfig;
import com.gmail.nossr50.datatypes.party.ItemShareType; import com.gmail.nossr50.datatypes.party.ItemShareType;
@ -53,12 +54,10 @@ public final class ShareHandler {
* @return True is the xp has been shared * @return True is the xp has been shared
*/ */
public static boolean handleXpShare(float xp, McMMOPlayer mcMMOPlayer, SkillType skillType) { public static boolean handleXpShare(float xp, McMMOPlayer mcMMOPlayer, SkillType skillType) {
Party party = mcMMOPlayer.getParty(); switch (mcMMOPlayer.getParty().getXpShareMode()) {
switch (party.getXpShareMode()) {
case EQUAL: case EQUAL:
Player player = mcMMOPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()); nearMembers = mcMMO.getPartyManager().getNearbyPartyMembers(player, Config.getInstance().getPartyShareRange());
if (nearMembers.isEmpty()) { if (nearMembers.isEmpty()) {
return false; return false;
@ -112,7 +111,7 @@ public final class ShareHandler {
switch (party.getItemShareMode()) { switch (party.getItemShareMode()) {
case EQUAL: case EQUAL:
McMMOPlayer mcMMOTarget; McMMOPlayer mcMMOTarget;
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()); nearMembers = mcMMO.getPartyManager().getNearbyPartyMembers(player, Config.getInstance().getPartyShareRange());
if (nearMembers.isEmpty()) { if (nearMembers.isEmpty()) {
return false; return false;
@ -159,7 +158,7 @@ public final class ShareHandler {
return true; return true;
case RANDOM: case RANDOM:
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()); nearMembers = mcMMO.getPartyManager().getNearbyPartyMembers(player, Config.getInstance().getPartyShareRange());
if (nearMembers.isEmpty()) { if (nearMembers.isEmpty()) {
return false; return false;

View File

@ -19,6 +19,6 @@ public class SaveTimerTask extends BukkitRunnable {
count++; count++;
} }
PartyManager.saveParties(); mcMMO.getPartyManager().saveParties();
} }
} }

View File

@ -4,6 +4,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.party.teleport.PtpCommand; import com.gmail.nossr50.commands.party.teleport.PtpCommand;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@ -37,7 +38,7 @@ public class TeleportationWarmup extends BukkitRunnable {
mcMMOPlayer.setTeleportCommenceLocation(null); mcMMOPlayer.setTeleportCommenceLocation(null);
if (!PartyManager.inSameParty(teleportingPlayer, targetPlayer)) { if (!mcMMO.getPartyManager().inSameParty(teleportingPlayer, targetPlayer)) {
teleportingPlayer.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetPlayer.getName())); teleportingPlayer.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetPlayer.getName()));
return; return;
} }

View File

@ -27,7 +27,7 @@ public class PartyAutoKickTask extends BukkitRunnable {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
long kickTime = 24L * 60L * 60L * 1000L * Config.getInstance().getAutoPartyKickTime(); long kickTime = 24L * 60L * 60L * 1000L * Config.getInstance().getAutoPartyKickTime();
for (Iterator<Party> partyIterator = PartyManager.getParties().iterator(); partyIterator.hasNext();) { for (Iterator<Party> partyIterator = mcMMO.getPartyManager().getParties().iterator(); partyIterator.hasNext();) {
Party party = partyIterator.next(); Party party = partyIterator.next();
for (String memberName : party.getMembers()) { for (String memberName : party.getMembers()) {
@ -44,7 +44,7 @@ public class PartyAutoKickTask extends BukkitRunnable {
} }
for (Entry<OfflinePlayer, Party> entry : toRemove.entrySet()) { for (Entry<OfflinePlayer, Party> entry : toRemove.entrySet()) {
PartyManager.removeFromParty(entry.getKey(), entry.getValue()); mcMMO.getPartyManager().removeFromParty(entry.getKey(), entry.getValue());
} }
} }
} }

View File

@ -534,7 +534,7 @@ public final class CombatUtils {
return false; return false;
} }
if (PartyManager.inSameParty(player, defender) && !(Permissions.friendlyFire(player) && Permissions.friendlyFire(defender))) { if (mcMMO.getPartyManager().inSameParty(player, defender) && !(Permissions.friendlyFire(player) && Permissions.friendlyFire(defender))) {
return false; return false;
} }
@ -589,7 +589,7 @@ public final class CombatUtils {
if (tamer instanceof Player) { if (tamer instanceof Player) {
Player owner = (Player) tamer; Player owner = (Player) tamer;
if (owner == attacker || PartyManager.inSameParty(attacker, owner)) { if (owner == attacker || mcMMO.getPartyManager().inSameParty(attacker, owner)) {
return true; return true;
} }
} }