Commit 8cfb9c91 authored by Kenix Whisperwind's avatar Kenix Whisperwind

PartyManager is now a non-static class member of World

parent 8aeea43d
......@@ -79,6 +79,14 @@ public final class Constants {
* Size of Regions in RegionManager
*/
public static final int REGION_SIZE = 48;
/**
* Maximum number of clan members
*/
public static final int MAX_CLAN_SIZE = 150;
/**
* Maximum number of users of a party
*/
public static final int MAX_PARTY_SIZE = 5;
//public static final class Skillcapes {
// public static final int ATTACK_CAPE = 2111;
......
package com.openrsc.server.content.clan;
import com.openrsc.server.constants.Constants;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.rsc.ActionSender;
import com.openrsc.server.util.rsc.MessageType;
......@@ -17,7 +18,7 @@ public class Clan {
private int clanPoints;
public ClanPlayer addPlayer(Player player) {
if (getPlayers().size() < ClanManager.MAX_CLAN_SIZE) {
if (getPlayers().size() < Constants.MAX_CLAN_SIZE) {
player.setClan(this);
ClanPlayer clanMember = new ClanPlayer(player.getUsername());
......
package com.openrsc.server.content.clan;
import com.openrsc.server.Server;
import com.openrsc.server.constants.Constants;
import com.openrsc.server.event.SingleEvent;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.rsc.ActionSender;
......@@ -46,7 +47,7 @@ public class ClanInvite {
}
}
if (player.getClan().getPlayers().size() >= ClanManager.MAX_CLAN_SIZE) {
if (player.getClan().getPlayers().size() >= Constants.MAX_CLAN_SIZE) {
player.message("Your clan has reached the maximum clan members limit");
return;
}
......
......@@ -14,7 +14,6 @@ import java.util.Comparator;
public class ClanManager {
static final int MAX_CLAN_SIZE = 150;
public final static ClanRankComparator CLAN_COMPERATOR = new ClanRankComparator();
/**
* The asynchronous logger.
......
package com.openrsc.server.content.party;
import com.openrsc.server.constants.Constants;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.model.world.World;
import com.openrsc.server.net.rsc.ActionSender;
import com.openrsc.server.util.rsc.MessageType;
......@@ -16,8 +18,14 @@ public class Party {
private int[] partySetting = new int[3];
private int partyPoints;
private final World world;
public Party (World world) {
this.world = world;
}
public PartyPlayer addPlayer(Player player) {
if (getPlayers().size() < PartyManager.MAX_PARTY_SIZE) {
if (getPlayers().size() < Constants.MAX_PARTY_SIZE) {
player.setParty(this);
PartyPlayer partyMember = new PartyPlayer(player.getUsername());
......@@ -37,7 +45,7 @@ public class Party {
ActionSender.sendPartySetting(partyMember.getPlayerReference());
if (getPlayers().size() > 1) {
PartyManager.savePartyChanges(this);
getWorld().getPartyManager().savePartyChanges(this);
}
return partyMember;
}
......@@ -69,9 +77,9 @@ public class Party {
ActionSender.sendParty(getPlayers().get(0).getPlayerReference());
getPlayers().get(0).getPlayerReference().getParty().updatePartySettings();
}
PartyManager.savePartyChanges(this);
getWorld().getPartyManager().savePartyChanges(this);
} else if (getPlayers().size() == 0) {
PartyManager.deleteParty(this);
getWorld().getPartyManager().deleteParty(this);
}
updatePartyGUI();
}
......@@ -94,7 +102,7 @@ public class Party {
getLeader().setRank(PartyRank.LEADER);
messagePartyInfo("@red@Your party leader has passed the leadership!");
messagePartyInfo("@yel@" + getLeader().getUsername() + " is the new party leader!");
PartyManager.savePartyChanges(this);
getWorld().getPartyManager().savePartyChanges(this);
ActionSender.sendPartySetting(player);
} else {
if (newRank == 2) {
......@@ -103,7 +111,7 @@ public class Party {
messagePartyInfo(member.getUsername() + " has been put back to " + PartyRank.getRankFor(newRank).name().toLowerCase() + " rank.");
}
member.setRank(setRank);
PartyManager.updatePartyRankPlayer(member);
getWorld().getPartyManager().updatePartyRankPlayer(member);
}
updatePartyGUI();
if (member.isOnline()) {
......@@ -239,4 +247,8 @@ public class Party {
public void setPartyPoints(int p) {
this.partyPoints = p;
}
public World getWorld() {
return world;
}
}
package com.openrsc.server.content.party;
import com.openrsc.server.Server;
import com.openrsc.server.constants.Constants;
import com.openrsc.server.event.SingleEvent;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.rsc.ActionSender;
......@@ -21,7 +22,7 @@ public class PartyInvite {
if (player.getParty() == null) {
return;
}
if (player.getParty().getPlayers().size() >= PartyManager.MAX_PARTY_SIZE) {
if (player.getParty().getPlayers().size() >= Constants.MAX_PARTY_SIZE) {
player.message("Your party has reached the maximum party members limit");
return;
}
......
......@@ -2,6 +2,7 @@ package com.openrsc.server.content.party;
import com.openrsc.server.Server;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.model.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -12,31 +13,47 @@ import java.util.Comparator;
public class PartyManager {
static final int MAX_PARTY_SIZE = 5;
private static class PartyRankComparator implements Comparator<Party> {
public int compare(Party o1, Party o2) {
if (o1.getPartyPoints() == o2.getPartyPoints()) {
return o1.getPartyName().compareTo(o2.getPartyName());
}
return o1.getPartyPoints() > o2.getPartyPoints() ? -1 : 1;
}
}
public final static PartyRankComparator PARTY_COMPERATOR = new PartyRankComparator();
/**
* The asynchronous logger.
*/
private static final Logger LOGGER = LogManager.getLogger();
public static ArrayList<Party> parties = new ArrayList<>();
public static void createParty(Party party) {
public ArrayList<Party> parties = new ArrayList<>();
private final World world;
public PartyManager (World world) {
this.world = world;
}
public void createParty(Party party) {
parties.add(party);
//databaseCreateParty(party);
}
static void deleteParty(Party party) {
public void deleteParty(Party party) {
//databaseDeleteParty(party);
parties.remove(party);
}
public static void init() {
public void initialize() {
//LOGGER.info("Loading Partys...");
//loadParties();
//LOGGER.info("Loaded " + partys.size() + " partys");
}
public static Party getParty(String exist) {
public Party getParty(String exist) {
for (Party t : parties) {
if (t.getPartyName().equalsIgnoreCase(exist))
return t;
......@@ -46,7 +63,7 @@ public class PartyManager {
return null;
}
public static void checkAndAttachToParty(Player player) {
public void checkAndAttachToParty(Player player) {
for (Party p : parties) {
PartyPlayer partyMember = p.getPlayer(player.getUsername());
if (partyMember != null) {
......@@ -59,6 +76,50 @@ public class PartyManager {
}
}
public void updatePartyRankPlayer(PartyPlayer cp) {
try {
PreparedStatement statement = cp.getPlayerReference().getWorld().getServer().getDatabaseConnection()
.prepareStatement("UPDATE `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX + "party_players` SET `rank`=? WHERE `username`=?");
statement.setInt(1, cp.getRank().getRankIndex());
statement.setString(2, cp.getUsername());
statement.executeUpdate();
} catch (SQLException e) {
LOGGER.error("Unable to update rank for party player: " + cp.getUsername());
LOGGER.catching(e);
}
}
public void checkAndUnattachFromParty(Player player) {
for (Party p : parties) {
PartyPlayer cp = p.getPlayer(player.getUsername());
if (cp != null) {
cp.setPlayerReference(null);
p.updatePartyGUI();
break;
}
}
}
public void saveParties() {
for (Party t : parties) {
savePartyChanges(t);
}
}
public void savePartyChanges(Party party) {
//updateParty(party);
//deletePartyPlayer(party);
//savePartyPlayer(party);
//saveBank(team);
}
public World getWorld() {
return world;
}
/*private static void loadParties() throws SQLException {
PreparedStatement statement = DatabaseConnection.getDatabase().prepareStatement("SELECT `id`, `name`, `tag`, `kick_setting`, `invite_setting`, `allow_search_join`, `party_points` FROM `" + getServer().getConfig().MYSQL_TABLE_PREFIX + "party`");
ResultSet result = statement.executeQuery();
......@@ -186,53 +247,4 @@ public class PartyManager {
LOGGER.catching(e);
}
}*/
static void updatePartyRankPlayer(PartyPlayer cp) {
try {
PreparedStatement statement = cp.getPlayerReference().getWorld().getServer().getDatabaseConnection()
.prepareStatement("UPDATE `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX + "party_players` SET `rank`=? WHERE `username`=?");
statement.setInt(1, cp.getRank().getRankIndex());
statement.setString(2, cp.getUsername());
statement.executeUpdate();
} catch (SQLException e) {
LOGGER.error("Unable to update rank for party player: " + cp.getUsername());
LOGGER.catching(e);
}
}
public static void checkAndUnattachFromParty(Player player) {
for (Party p : parties) {
PartyPlayer cp = p.getPlayer(player.getUsername());
if (cp != null) {
cp.setPlayerReference(null);
p.updatePartyGUI();
break;
}
}
}
public static void saveParties() {
for (Party t : parties) {
savePartyChanges(t);
}
}
static void savePartyChanges(Party party) {
//updateParty(party);
//deletePartyPlayer(party);
//savePartyPlayer(party);
//saveBank(team);
}
private static class PartyRankComparator implements Comparator<Party> {
public int compare(Party o1, Party o2) {
if (o1.getPartyPoints() == o2.getPartyPoints()) {
return o1.getPartyName().compareTo(o2.getPartyName());
}
return o1.getPartyPoints() > o2.getPartyPoints() ? -1 : 1;
}
}
}
......@@ -10,7 +10,6 @@ import com.openrsc.server.content.clan.ClanManager;
import com.openrsc.server.content.minigame.fishingtrawler.FishingTrawler;
import com.openrsc.server.content.party.Party;
import com.openrsc.server.content.party.PartyInvite;
import com.openrsc.server.content.party.PartyManager;
import com.openrsc.server.event.DelayedEvent;
import com.openrsc.server.event.custom.BatchEvent;
import com.openrsc.server.event.rsc.impl.*;
......@@ -39,7 +38,6 @@ import com.openrsc.server.net.rsc.handlers.WalkRequest;
import com.openrsc.server.plugins.Functions;
import com.openrsc.server.plugins.QuestInterface;
import com.openrsc.server.plugins.menu.Menu;
import com.openrsc.server.sql.GameLogger;
import com.openrsc.server.sql.query.logs.GenericLog;
import com.openrsc.server.sql.query.logs.LiveFeedLog;
import com.openrsc.server.util.rsc.DataConversions;
......@@ -2017,7 +2015,7 @@ public final class Player extends Mob {
}
ClanManager.checkAndUnattachFromClan(this);
PartyManager.checkAndUnattachFromParty(this);
getWorld().getPartyManager().checkAndUnattachFromParty(this);
Server.getServer().getPlayerDataProcessor().addRemoveRequest(this);
}
......
......@@ -82,12 +82,13 @@ public final class World implements SimpleSubscriber<FishingTrawler> {
private final List<Shop> shops;
private final Map<TrawlerBoat, FishingTrawler> fishingTrawler;
private final TileValue[][] tiles;
private final PartyManager partyManager;
private final Market market;
private final WorldLoader worldLoader;
private Map<Player, Boolean> playerUnderAttackMap = new HashMap<Player, Boolean>();
private Map<Npc, Boolean> npcUnderAttackMap = new HashMap<Npc, Boolean>();
private Map<Player, Boolean> playerUnderAttackMap;
private Map<Npc, Boolean> npcUnderAttackMap;
public DropTable gemTable;
public DropTable standardTable;
......@@ -108,11 +109,14 @@ public final class World implements SimpleSubscriber<FishingTrawler> {
minigames = new LinkedList<MiniGameInterface>();
shopData = new ArrayList<Shop>();
shops = new ArrayList<Shop>();
playerUnderAttackMap = new HashMap<Player, Boolean>();
npcUnderAttackMap = new HashMap<Npc, Boolean>();
fishingTrawler = new HashMap<TrawlerBoat, FishingTrawler>();
tiles = new TileValue[MAX_WIDTH][MAX_HEIGHT];
snapshots = new LinkedList<Snapshot>();
tiles = new TileValue[MAX_WIDTH][MAX_HEIGHT];
worldLoader = new WorldLoader(this);
regionManager = new RegionManager(this);
partyManager = new PartyManager(this);
market = getServer().getConfig().SPAWN_AUCTION_NPCS ? new Market(this) : null;
}
......@@ -401,7 +405,8 @@ public final class World implements SimpleSubscriber<FishingTrawler> {
public void load() {
try {
ClanManager.init();
PartyManager.init();
getWorld().getPartyManager().initialize();
worldInstance.getWorldLoader().loadWorld();
worldInstance.getWorldLoader().getWorldPopulator().populateWorld();
shutdownCheck();
......@@ -575,7 +580,7 @@ public final class World implements SimpleSubscriber<FishingTrawler> {
other.getSocial().alertOfLogin(player);
}
ClanManager.checkAndAttachToClan(player);
PartyManager.checkAndAttachToParty(player);
getWorld().getPartyManager().checkAndAttachToParty(player);
LOGGER.info("Registered " + player.getUsername() + " to server");
return true;
}
......@@ -949,4 +954,8 @@ public final class World implements SimpleSubscriber<FishingTrawler> {
public Market getMarket() {
return market;
}
public PartyManager getPartyManager() {
return partyManager;
}
}
......@@ -1369,10 +1369,10 @@ public class ActionSender {
public static void sendParties(Player p) {
PacketBuilder pb = new PacketBuilder(Opcode.SEND_PARTY.opcode);
pb.writeByte(4);
pb.writeShort(PartyManager.parties.size());
pb.writeShort(p.getWorld().getPartyManager().parties.size());
int rank = 1;
PartyManager.parties.sort(PartyManager.PARTY_COMPERATOR);
for (Party c : PartyManager.parties) {
p.getWorld().getPartyManager().parties.sort(PartyManager.PARTY_COMPERATOR);
for (Party c : p.getWorld().getPartyManager().parties) {
pb.writeShort(c.getPartyID());
pb.writeString(c.getPartyName());
pb.writeString(c.getPartyTag());
......
......@@ -410,7 +410,7 @@ public class InterfaceOptionHandler implements PacketHandler {
return;
}
Party party = new Party();
Party party = new Party(player.getWorld());
//party.setPartyName(partyName);
//party.setPartyTag(partyTag);
......@@ -418,7 +418,7 @@ public class InterfaceOptionHandler implements PacketHandler {
partyMember.setRank(PartyRank.LEADER);
party.setLeader(partyMember);
PartyManager.createParty(party);
player.getWorld().getPartyManager().createParty(party);
player.message("You have created a party: ");
break;
......@@ -436,7 +436,7 @@ public class InterfaceOptionHandler implements PacketHandler {
if (player.getParty() == null) {
String partyName = p.readString();
String partyTag = p.readString();
Party party1 = new Party();
Party party1 = new Party(player.getWorld());
party1.setPartyName(partyName);
party1.setPartyTag(partyTag);
......@@ -444,7 +444,7 @@ public class InterfaceOptionHandler implements PacketHandler {
partyMember1.setRank(PartyRank.LEADER);
party1.setLeader(partyMember1);
PartyManager.createParty(party1);
player.getWorld().getPartyManager().createParty(party1);
player.message("You have created a party: ");
}
if (player.getParty().getInviteSetting() == 1 && !player.getParty().getLeader().getUsername().equalsIgnoreCase(player.getUsername())) {
......@@ -578,7 +578,7 @@ public class InterfaceOptionHandler implements PacketHandler {
} else {
String partyName = p.readString();
String partyTag = p.readString();
Party party1 = new Party();
Party party1 = new Party(player.getWorld());
party1.setPartyName(partyName);
party1.setPartyTag(partyTag);
......@@ -586,7 +586,7 @@ public class InterfaceOptionHandler implements PacketHandler {
partyMember1.setRank(PartyRank.LEADER);
party1.setLeader(partyMember1);
PartyManager.createParty(party1);
player.getWorld().getPartyManager().createParty(party1);
player.message("You have created a party: ");
}
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment