mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-02 01:46:45 +01:00
OOP is good.
This commit is contained in:
parent
9a5f4b638f
commit
663d54d31f
@ -3,6 +3,7 @@ package com.gmail.nossr50.api;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.chat.ChatManager;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
@ -22,7 +23,7 @@ public final class ChatAPI {
|
||||
* @param message The message to send
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +53,7 @@ public final class PartyAPI {
|
||||
* @return true if the two players are in the same party, false otherwise
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public static void addToParty(Player player, String partyName) {
|
||||
Party party = PartyManager.getParty(partyName);
|
||||
Party party = mcMMO.getPartyManager().getParty(partyName);
|
||||
|
||||
if (party == null) {
|
||||
party = new Party();
|
||||
@ -84,7 +84,7 @@ public final class PartyAPI {
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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) {
|
||||
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);
|
||||
members.add(member);
|
||||
}
|
||||
@ -150,7 +150,7 @@ public final class PartyAPI {
|
||||
* @return all the player names in the player's party
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public static List<Player> getOnlineMembers(Player player) {
|
||||
return PartyManager.getOnlineMembers(player);
|
||||
return mcMMO.getPartyManager().getOnlineMembers(UserManager.getPlayer(player).getParty().getName());
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class PartyChatCommand extends ChatCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
Party party = PartyManager.getParty(args[0]);
|
||||
Party party = mcMMO.getPartyManager().getParty(args[0]);
|
||||
|
||||
if (party == null) {
|
||||
sender.sendMessage(LocaleLoader.getString("Party.InvalidName"));
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
@ -24,11 +25,11 @@ public class PartyAcceptCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
// Changing parties
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), mcMMOPlayer.getPartyInvite().getName())) {
|
||||
if (!mcMMO.getPartyManager().changeOrJoinParty(mcMMOPlayer, mcMMOPlayer.getPartyInvite().getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PartyManager.joinInvitedParty(player, mcMMOPlayer);
|
||||
mcMMO.getPartyManager().joinInvitedParty(player);
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
@ -21,7 +22,7 @@ public class PartyChangeOwnerCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
PartyManager.setPartyLeader(args[1], playerParty);
|
||||
mcMMO.getPartyManager().setPartyLeader(args[1], playerParty);
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
@ -5,7 +5,7 @@ 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.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
@ -17,22 +17,20 @@ public class PartyCreateCommand implements CommandExecutor {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
case 3:
|
||||
Party newParty = PartyManager.getParty(args[1]);
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Changing parties
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, mcMMOPlayer.getParty(), args[1])) {
|
||||
if (!mcMMO.getPartyManager().changeOrJoinParty(mcMMOPlayer, args[1])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PartyManager.createParty(player, mcMMOPlayer, args[1], getPassword(args));
|
||||
mcMMO.getPartyManager().createParty(player, args[1], getPassword(args));
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -20,14 +21,14 @@ public class PartyDisbandCommand implements CommandExecutor {
|
||||
String partyName = playerParty.getName();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
member.sendMessage(LocaleLoader.getString("Party.Disband"));
|
||||
}
|
||||
|
||||
PartyManager.disbandParty(playerParty);
|
||||
mcMMO.getPartyManager().disbandParty(playerParty);
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
@ -104,7 +104,7 @@ public class PartyInfoCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -32,14 +33,14 @@ public class PartyInviteCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PartyManager.inSameParty(player, target)) {
|
||||
if (mcMMO.getPartyManager().inSameParty(player, target)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Party.Player.InSameParty", target.getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
Party playerParty = mcMMOPlayer.getParty();
|
||||
|
||||
if (!PartyManager.canInvite(player, playerParty)) {
|
||||
if (!mcMMO.getPartyManager().canInvite(player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Locked"));
|
||||
return true;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -37,16 +38,16 @@ public class PartyJoinCommand implements CommandExecutor {
|
||||
String password = getPassword(args);
|
||||
|
||||
// Make sure party passwords match
|
||||
if (!PartyManager.checkPartyPassword(player, targetParty, password)) {
|
||||
if (!mcMMO.getPartyManager().checkPartyPassword(player, targetParty, password)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Changing parties
|
||||
if (!PartyManager.changeOrJoinParty(mcMMOPlayer, player, playerParty, targetParty.getName())) {
|
||||
if (!mcMMO.getPartyManager().changeOrJoinParty(mcMMOPlayer, targetParty.getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PartyManager.joinParty(player, mcMMOPlayer, targetParty, password);
|
||||
mcMMO.getPartyManager().joinParty(player, targetParty, password);
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
@ -30,14 +30,14 @@ public class PartyKickCommand implements CommandExecutor {
|
||||
Player onlineTarget = target.getPlayer();
|
||||
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;
|
||||
}
|
||||
|
||||
onlineTarget.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName));
|
||||
}
|
||||
|
||||
PartyManager.removeFromParty(target, playerParty);
|
||||
mcMMO.getPartyManager().removeFromParty(target, playerParty);
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -19,11 +20,11 @@ public class PartyQuitCommand implements CommandExecutor {
|
||||
Player player = (Player) sender;
|
||||
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;
|
||||
}
|
||||
|
||||
PartyManager.removeFromParty(player, playerParty);
|
||||
mcMMO.getPartyManager().removeFromParty(player, playerParty);
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
|
||||
return true;
|
||||
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
||||
@ -30,17 +31,16 @@ 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 (mcMMO.getPartyManager().checkPartyExistence(player, newPartyName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String leaderName = playerParty.getLeader();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ public class PtpCommand implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PartyManager.inSameParty(player, target)) {
|
||||
if (!mcMMO.getPartyManager().inSameParty(player, target)) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName));
|
||||
return false;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public class McMMOPlayer {
|
||||
|
||||
this.player = player;
|
||||
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),
|
||||
|
@ -155,7 +155,7 @@ public class EntityListener implements Listener {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public class mcMMO extends JavaPlugin {
|
||||
private static ChunkManager placeStore;
|
||||
private static RepairableManager repairableManager;
|
||||
private static DatabaseManager databaseManager;
|
||||
private static PartyManager partyManager;
|
||||
|
||||
/* File Paths */
|
||||
private static String mainDirectory;
|
||||
@ -114,7 +115,7 @@ public class mcMMO extends JavaPlugin {
|
||||
registerEvents();
|
||||
registerCustomRecipes();
|
||||
|
||||
PartyManager.loadParties();
|
||||
partyManager = new PartyManager(this);
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
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() {
|
||||
try {
|
||||
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.cleanUp(); // Cleanup empty metadata stores
|
||||
}
|
||||
@ -235,6 +236,10 @@ public class mcMMO extends JavaPlugin {
|
||||
return repairableManager;
|
||||
}
|
||||
|
||||
public static PartyManager getPartyManager() {
|
||||
return partyManager;
|
||||
}
|
||||
|
||||
public static boolean isSpoutEnabled() {
|
||||
return spoutEnabled;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
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.player.UserManager;
|
||||
|
||||
public final class PartyManager {
|
||||
private static String partiesFilePath = mcMMO.getFlatFileDirectory() + "parties.yml";
|
||||
private static List<Party> parties = new ArrayList<Party>();
|
||||
private static File partyFile = new File(partiesFilePath);
|
||||
public class PartyManager {
|
||||
private final mcMMO plugin;
|
||||
private final String partiesFilePath = mcMMO.getFlatFileDirectory() + "parties.yml";
|
||||
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) {
|
||||
if (party == null) {
|
||||
loadParties();
|
||||
}
|
||||
|
||||
public boolean checkPartyExistence(Player player, String partyName) {
|
||||
if (getParty(partyName) == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -34,8 +40,12 @@ public final class PartyManager {
|
||||
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()) {
|
||||
Party oldParty = mcMMOPlayer.getParty();
|
||||
|
||||
if (!handlePartyChangeEvent(player, oldParty.getName(), newPartyName, EventReason.CHANGED_PARTIES)) {
|
||||
return false;
|
||||
}
|
||||
@ -56,7 +66,7 @@ public final class PartyManager {
|
||||
* @param secondPlayer The second player
|
||||
* @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 secondMcMMOPlayer = UserManager.getPlayer(secondPlayer);
|
||||
|
||||
@ -81,15 +91,20 @@ public final class PartyManager {
|
||||
* @param range The distance
|
||||
* @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>();
|
||||
Party party = UserManager.getPlayer(player).getParty();
|
||||
|
||||
if (party != null) {
|
||||
Location playerLocation = player.getLocation();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nearMembers;
|
||||
}
|
||||
|
||||
@ -99,9 +114,7 @@ public final class PartyManager {
|
||||
* @param player The player to check
|
||||
* @return all the players in the player's party
|
||||
*/
|
||||
public static LinkedHashSet<String> getAllMembers(Player player) {
|
||||
Party party = UserManager.getPlayer(player).getParty();
|
||||
|
||||
public LinkedHashSet<String> getAllMembers(Party party) {
|
||||
if (party == null) {
|
||||
return null;
|
||||
}
|
||||
@ -115,7 +128,7 @@ public final class PartyManager {
|
||||
* @param partyName The party to check
|
||||
* @return all online players in this party
|
||||
*/
|
||||
public static List<Player> getOnlineMembers(String partyName) {
|
||||
public List<Player> getOnlineMembers(String partyName) {
|
||||
Party party = getParty(partyName);
|
||||
|
||||
if (party == null) {
|
||||
@ -125,29 +138,13 @@ public final class PartyManager {
|
||||
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
|
||||
*
|
||||
* @param partyName The party name
|
||||
* @return the existing party, null otherwise
|
||||
*/
|
||||
public static Party getParty(String partyName) {
|
||||
public Party getParty(String partyName) {
|
||||
for (Party party : parties) {
|
||||
if (party.getName().equals(partyName)) {
|
||||
return party;
|
||||
@ -163,7 +160,7 @@ public final class PartyManager {
|
||||
* @param playerName The member name
|
||||
* @return the existing party, null otherwise
|
||||
*/
|
||||
public static Party getPlayerParty(String playerName) {
|
||||
public Party getPlayerParty(String playerName) {
|
||||
for (Party party : parties) {
|
||||
for (String memberName : party.getMembers()) {
|
||||
if (memberName.equalsIgnoreCase(playerName)) {
|
||||
@ -180,7 +177,7 @@ public final class PartyManager {
|
||||
*
|
||||
* @return the list of parties.
|
||||
*/
|
||||
public static List<Party> getParties() {
|
||||
public List<Party> getParties() {
|
||||
return parties;
|
||||
}
|
||||
|
||||
@ -190,7 +187,7 @@ public final class PartyManager {
|
||||
* @param player The player to remove
|
||||
* @param party The party
|
||||
*/
|
||||
public static void removeFromParty(OfflinePlayer player, Party party) {
|
||||
public void removeFromParty(OfflinePlayer player, Party party) {
|
||||
LinkedHashSet<String> members = party.getMembers();
|
||||
|
||||
members.remove(player.getName());
|
||||
@ -201,20 +198,13 @@ public final class PartyManager {
|
||||
else {
|
||||
// If the leaving player was the party leader, appoint a new leader from the party members
|
||||
if (party.getLeader().equalsIgnoreCase(player.getName())) {
|
||||
String newLeader = members.iterator().next();
|
||||
party.setLeader(newLeader);
|
||||
party.setLeader(members.iterator().next());
|
||||
}
|
||||
|
||||
informPartyMembersQuit(player, party);
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player.getName());
|
||||
|
||||
if (mcMMOPlayer != null) {
|
||||
mcMMOPlayer.removeParty();
|
||||
mcMMOPlayer.setPartyChat(false);
|
||||
mcMMOPlayer.setItemShareModifier(10);
|
||||
}
|
||||
processPlayerLeaving(UserManager.getPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -222,17 +212,11 @@ public final class PartyManager {
|
||||
*
|
||||
* @param party The party to remove
|
||||
*/
|
||||
public static void disbandParty(Party party) {
|
||||
public void disbandParty(Party party) {
|
||||
LinkedHashSet<String> members = party.getMembers();
|
||||
|
||||
for (String memberName : members) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(memberName);
|
||||
|
||||
if (mcMMOPlayer != null) {
|
||||
mcMMOPlayer.removeParty();
|
||||
mcMMOPlayer.setPartyChat(false);
|
||||
mcMMOPlayer.setItemShareModifier(10);
|
||||
}
|
||||
processPlayerLeaving(UserManager.getPlayer(memberName));
|
||||
}
|
||||
|
||||
members.clear();
|
||||
@ -243,11 +227,10 @@ public final class PartyManager {
|
||||
* Create a new 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 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(".", "");
|
||||
Party party = getParty(partyName);
|
||||
|
||||
@ -271,7 +254,7 @@ public final class PartyManager {
|
||||
}
|
||||
|
||||
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 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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mcMMOPlayer.getParty() == party) {
|
||||
return;
|
||||
}
|
||||
// // Pretty sure this isn't possible.
|
||||
// if (mcMMOPlayer.getParty() == party) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
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
|
||||
* @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
|
||||
if (party.isLocked()) {
|
||||
String partyPassword = party.getPassword();
|
||||
@ -333,20 +317,22 @@ public final class PartyManager {
|
||||
* @param Player The plaer 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();
|
||||
|
||||
if (mcMMOPlayer.getParty() == invite) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parties.contains(invite)) {
|
||||
parties.add(invite);
|
||||
}
|
||||
// // Pretty sure this isn't possible
|
||||
// if (!parties.contains(invite)) {
|
||||
// parties.add(invite);
|
||||
// }
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", invite.getName()));
|
||||
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 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) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parties.contains(party)) {
|
||||
parties.add(party);
|
||||
}
|
||||
|
||||
informPartyMembersJoin(player, party);
|
||||
mcMMOPlayer.setParty(party);
|
||||
|
||||
@ -373,7 +365,7 @@ public final class PartyManager {
|
||||
* @param partyName The party name
|
||||
* @return the leader of the party
|
||||
*/
|
||||
public static String getPartyLeader(String partyName) {
|
||||
public String getPartyLeader(String partyName) {
|
||||
Party party = getParty(partyName);
|
||||
|
||||
if (party == null) {
|
||||
@ -389,7 +381,7 @@ public final class PartyManager {
|
||||
* @param playerName The name of the player to set as leader
|
||||
* @param party The party
|
||||
*/
|
||||
public static void setPartyLeader(String playerName, Party party) {
|
||||
public void setPartyLeader(String playerName, Party party) {
|
||||
String leaderName = party.getLeader();
|
||||
|
||||
for (Player member : party.getOnlineMembers()) {
|
||||
@ -414,7 +406,9 @@ public final class PartyManager {
|
||||
* @param mcMMOPlayer The player to check
|
||||
* @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())) {
|
||||
return false;
|
||||
}
|
||||
@ -422,26 +416,10 @@ public final class PartyManager {
|
||||
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.
|
||||
*/
|
||||
public static void loadParties() {
|
||||
private void loadParties() {
|
||||
if (!partyFile.exists()) {
|
||||
return;
|
||||
}
|
||||
@ -472,7 +450,7 @@ public final class PartyManager {
|
||||
/**
|
||||
* Save party file.
|
||||
*/
|
||||
public static void saveParties() {
|
||||
public void saveParties() {
|
||||
if (partyFile.exists()) {
|
||||
partyFile.delete();
|
||||
}
|
||||
@ -516,7 +494,7 @@ public final class PartyManager {
|
||||
* @param reason The reason for changing parties
|
||||
* @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);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
@ -529,7 +507,7 @@ public final class PartyManager {
|
||||
* @param player The player that joins
|
||||
* @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()) {
|
||||
if (!member.equals(player)) {
|
||||
member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", player.getName()));
|
||||
@ -543,11 +521,21 @@ public final class PartyManager {
|
||||
* @param player The player that quits
|
||||
* @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()) {
|
||||
if (!member.equals(player)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.party.ItemWeightConfig;
|
||||
import com.gmail.nossr50.datatypes.party.ItemShareType;
|
||||
@ -53,12 +54,10 @@ public final class ShareHandler {
|
||||
* @return True is the xp has been shared
|
||||
*/
|
||||
public static boolean handleXpShare(float xp, McMMOPlayer mcMMOPlayer, SkillType skillType) {
|
||||
Party party = mcMMOPlayer.getParty();
|
||||
|
||||
switch (party.getXpShareMode()) {
|
||||
switch (mcMMOPlayer.getParty().getXpShareMode()) {
|
||||
case EQUAL:
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
nearMembers = mcMMO.getPartyManager().getNearbyPartyMembers(player, Config.getInstance().getPartyShareRange());
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
@ -112,7 +111,7 @@ public final class ShareHandler {
|
||||
switch (party.getItemShareMode()) {
|
||||
case EQUAL:
|
||||
McMMOPlayer mcMMOTarget;
|
||||
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
nearMembers = mcMMO.getPartyManager().getNearbyPartyMembers(player, Config.getInstance().getPartyShareRange());
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
@ -159,7 +158,7 @@ public final class ShareHandler {
|
||||
return true;
|
||||
|
||||
case RANDOM:
|
||||
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
nearMembers = mcMMO.getPartyManager().getNearbyPartyMembers(player, Config.getInstance().getPartyShareRange());
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
|
@ -19,6 +19,6 @@ public class SaveTimerTask extends BukkitRunnable {
|
||||
count++;
|
||||
}
|
||||
|
||||
PartyManager.saveParties();
|
||||
mcMMO.getPartyManager().saveParties();
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.commands.party.teleport.PtpCommand;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
@ -37,7 +38,7 @@ public class TeleportationWarmup extends BukkitRunnable {
|
||||
|
||||
mcMMOPlayer.setTeleportCommenceLocation(null);
|
||||
|
||||
if (!PartyManager.inSameParty(teleportingPlayer, targetPlayer)) {
|
||||
if (!mcMMO.getPartyManager().inSameParty(teleportingPlayer, targetPlayer)) {
|
||||
teleportingPlayer.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetPlayer.getName()));
|
||||
return;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class PartyAutoKickTask extends BukkitRunnable {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
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();
|
||||
|
||||
for (String memberName : party.getMembers()) {
|
||||
@ -44,7 +44,7 @@ public class PartyAutoKickTask extends BukkitRunnable {
|
||||
}
|
||||
|
||||
for (Entry<OfflinePlayer, Party> entry : toRemove.entrySet()) {
|
||||
PartyManager.removeFromParty(entry.getKey(), entry.getValue());
|
||||
mcMMO.getPartyManager().removeFromParty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ public final class CombatUtils {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -589,7 +589,7 @@ public final class CombatUtils {
|
||||
if (tamer instanceof Player) {
|
||||
Player owner = (Player) tamer;
|
||||
|
||||
if (owner == attacker || PartyManager.inSameParty(attacker, owner)) {
|
||||
if (owner == attacker || mcMMO.getPartyManager().inSameParty(attacker, owner)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user