forked from MagicBane/Server
New collection created in handled and loaded from db
This commit is contained in:
@@ -427,7 +427,6 @@ public class dbBuildingHandler extends dbHandlerBase {
|
|||||||
|
|
||||||
public void LOAD_BUILDING_FRIENDS() {
|
public void LOAD_BUILDING_FRIENDS() {
|
||||||
|
|
||||||
|
|
||||||
try (Connection connection = DbManager.getConnection();
|
try (Connection connection = DbManager.getConnection();
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_friends`")) {
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_friends`")) {
|
||||||
|
|
||||||
@@ -458,6 +457,38 @@ public class dbBuildingHandler extends dbHandlerBase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void LOAD_BUILDING_CONDEMNED() {
|
||||||
|
|
||||||
|
try (Connection connection = DbManager.getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_condemned`")) {
|
||||||
|
|
||||||
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
|
||||||
|
Condemned condemned = new Condemned(rs);
|
||||||
|
|
||||||
|
// Create map if it does not yet exist
|
||||||
|
|
||||||
|
if (!BuildingManager._buildingCondemned.containsKey(condemned.buildingUUID))
|
||||||
|
BuildingManager._buildingCondemned.put(condemned.buildingUUID, new ConcurrentHashMap<>());
|
||||||
|
|
||||||
|
switch (condemned.friendType) {
|
||||||
|
case 2:
|
||||||
|
BuildingManager._buildingCondemned.get(condemned.buildingUUID).put(condemned.playerUID, condemned);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
case 5:
|
||||||
|
BuildingManager._buildingCondemned.get(condemned.buildingUUID).put(condemned.guildUID, condemned);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void LOAD_ALL_CONDEMNED_FOR_BUILDING(Building building) {
|
public void LOAD_ALL_CONDEMNED_FOR_BUILDING(Building building) {
|
||||||
|
|
||||||
if (building == null)
|
if (building == null)
|
||||||
@@ -471,13 +502,13 @@ public class dbBuildingHandler extends dbHandlerBase {
|
|||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
Condemned condemned = new Condemned(rs);
|
Condemned condemned = new Condemned(rs);
|
||||||
switch (condemned.getFriendType()) {
|
switch (condemned.friendType) {
|
||||||
case 2:
|
case 2:
|
||||||
building.getCondemned().put(condemned.getPlayerUID(), condemned);
|
building.getCondemned().put(condemned.playerUID, condemned);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
case 5:
|
case 5:
|
||||||
building.getCondemned().put(condemned.getGuildUID(), condemned);
|
building.getCondemned().put(condemned.guildUID, condemned);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -725,10 +756,10 @@ public class dbBuildingHandler extends dbHandlerBase {
|
|||||||
+ "WHERE`buildingUID` = ? AND `playerUID` = ? AND `guildUID` = ? AND `friendType` = ?")) {
|
+ "WHERE`buildingUID` = ? AND `playerUID` = ? AND `guildUID` = ? AND `friendType` = ?")) {
|
||||||
|
|
||||||
preparedStatement.setBoolean(1, active);
|
preparedStatement.setBoolean(1, active);
|
||||||
preparedStatement.setInt(2, condemn.getParent());
|
preparedStatement.setInt(2, condemn.buildingUUID);
|
||||||
preparedStatement.setInt(3, condemn.getPlayerUID());
|
preparedStatement.setInt(3, condemn.playerUID);
|
||||||
preparedStatement.setInt(4, condemn.getGuildUID());
|
preparedStatement.setInt(4, condemn.guildUID);
|
||||||
preparedStatement.setInt(5, condemn.getFriendType());
|
preparedStatement.setInt(5, condemn.friendType);
|
||||||
|
|
||||||
return (preparedStatement.executeUpdate() > 0);
|
return (preparedStatement.executeUpdate() > 0);
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public enum BuildingManager {
|
|||||||
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations = new HashMap<>();
|
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations = new HashMap<>();
|
||||||
|
|
||||||
public static HashMap<Integer, ConcurrentHashMap<Integer, BuildingFriends>> _buildingFriends = new HashMap<>();
|
public static HashMap<Integer, ConcurrentHashMap<Integer, BuildingFriends>> _buildingFriends = new HashMap<>();
|
||||||
|
public static HashMap<Integer, ConcurrentHashMap<Integer, Condemned>> _buildingCondemned = new HashMap<>();
|
||||||
public static int getAvailableSlot(Building building) {
|
public static int getAvailableSlot(Building building) {
|
||||||
|
|
||||||
ArrayList<BuildingLocation> slotLocations = _slotLocations.get(building.meshUUID);
|
ArrayList<BuildingLocation> slotLocations = _slotLocations.get(building.meshUUID);
|
||||||
@@ -497,18 +497,18 @@ public enum BuildingManager {
|
|||||||
|
|
||||||
Condemned condemn = building.getCondemned().get(player.getObjectUUID());
|
Condemned condemn = building.getCondemned().get(player.getObjectUUID());
|
||||||
|
|
||||||
if (condemn != null && condemn.isActive())
|
if (condemn != null && condemn.active)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (player.getGuild() != null) {
|
if (player.getGuild() != null) {
|
||||||
|
|
||||||
Condemned guildCondemn = building.getCondemned().get(player.getGuild().getObjectUUID());
|
Condemned guildCondemn = building.getCondemned().get(player.getGuild().getObjectUUID());
|
||||||
|
|
||||||
if (guildCondemn != null && guildCondemn.isActive())
|
if (guildCondemn != null && guildCondemn.active)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Condemned nationCondemn = building.getCondemned().get(player.getGuild().getNation().getObjectUUID());
|
Condemned nationCondemn = building.getCondemned().get(player.getGuild().getNation().getObjectUUID());
|
||||||
return nationCondemn != null && nationCondemn.isActive() && nationCondemn.getFriendType() == Condemned.NATION;
|
return nationCondemn != null && nationCondemn.active && nationCondemn.friendType == Condemned.NATION;
|
||||||
} else {
|
} else {
|
||||||
//TODO ADD ERRANT KOS CHECK
|
//TODO ADD ERRANT KOS CHECK
|
||||||
}
|
}
|
||||||
@@ -516,18 +516,18 @@ public enum BuildingManager {
|
|||||||
|
|
||||||
Condemned condemn = building.getCondemned().get(player.getObjectUUID());
|
Condemned condemn = building.getCondemned().get(player.getObjectUUID());
|
||||||
|
|
||||||
if (condemn != null && condemn.isActive())
|
if (condemn != null && condemn.active)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (player.getGuild() != null) {
|
if (player.getGuild() != null) {
|
||||||
|
|
||||||
Condemned guildCondemn = building.getCondemned().get(player.getGuild().getObjectUUID());
|
Condemned guildCondemn = building.getCondemned().get(player.getGuild().getObjectUUID());
|
||||||
|
|
||||||
if (guildCondemn != null && guildCondemn.isActive())
|
if (guildCondemn != null && guildCondemn.active)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Condemned nationCondemn = building.getCondemned().get(player.getGuild().getNation().getObjectUUID());
|
Condemned nationCondemn = building.getCondemned().get(player.getGuild().getNation().getObjectUUID());
|
||||||
return nationCondemn == null || !nationCondemn.isActive() || nationCondemn.getFriendType() != Condemned.NATION;
|
return nationCondemn == null || !nationCondemn.active || nationCondemn.friendType != Condemned.NATION;
|
||||||
} else {
|
} else {
|
||||||
//TODO ADD ERRANT KOS CHECK
|
//TODO ADD ERRANT KOS CHECK
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1175,17 +1175,17 @@ public class MobAI {
|
|||||||
|
|
||||||
//target is listed individually
|
//target is listed individually
|
||||||
|
|
||||||
if (entry.getValue().getPlayerUID() == target.getObjectUUID() && entry.getValue().isActive())
|
if (entry.getValue().playerUID == target.getObjectUUID() && entry.getValue().active)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//target's guild is listed
|
//target's guild is listed
|
||||||
|
|
||||||
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild())
|
if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//target's nation is listed
|
//target's nation is listed
|
||||||
|
|
||||||
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild().getNation())
|
if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild().getNation())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -1197,17 +1197,17 @@ public class MobAI {
|
|||||||
|
|
||||||
//target is listed individually
|
//target is listed individually
|
||||||
|
|
||||||
if (entry.getValue().getPlayerUID() == target.getObjectUUID() && entry.getValue().isActive())
|
if (entry.getValue().playerUID == target.getObjectUUID() && entry.getValue().active)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
//target's guild is listed
|
//target's guild is listed
|
||||||
|
|
||||||
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild())
|
if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
//target's nation is listed
|
//target's nation is listed
|
||||||
|
|
||||||
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild().getNation())
|
if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild().getNation())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler {
|
|||||||
if (removeCondemn == null)
|
if (removeCondemn == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!DbManager.BuildingQueries.REMOVE_FROM_CONDEMNED_LIST(removeCondemn.getParent(), removeCondemn.getPlayerUID(), removeCondemn.getGuildUID(), removeCondemn.getFriendType()))
|
if (!DbManager.BuildingQueries.REMOVE_FROM_CONDEMNED_LIST(removeCondemn.buildingUUID, removeCondemn.playerUID, removeCondemn.guildUID, removeCondemn.friendType))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
sourceBuilding.getCondemned().remove(msg.getRemoveFriendID());
|
sourceBuilding.getCondemned().remove(msg.getRemoveFriendID());
|
||||||
@@ -175,7 +175,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
condemn.setActive(msg.isReverseKOS());
|
condemn.setActive(msg.isReverseKOS());
|
||||||
openFriendsCondemnListMsg.setReverseKOS(condemn.isActive());
|
openFriendsCondemnListMsg.setReverseKOS(condemn.active);
|
||||||
dispatch = Dispatch.borrow(player, msg);
|
dispatch = Dispatch.borrow(player, msg);
|
||||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -513,17 +513,17 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg {
|
|||||||
|
|
||||||
writer.put((byte) 1);
|
writer.put((byte) 1);
|
||||||
|
|
||||||
switch (condemned.getFriendType()) {
|
switch (condemned.friendType) {
|
||||||
case 2:
|
case 2:
|
||||||
PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getObject(engine.Enum.GameObjectType.PlayerCharacter, condemned.getPlayerUID());
|
PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getObject(engine.Enum.GameObjectType.PlayerCharacter, condemned.playerUID);
|
||||||
|
|
||||||
|
|
||||||
guild = playerCharacter.getGuild();
|
guild = playerCharacter.getGuild();
|
||||||
writer.putInt(GameObjectType.PlayerCharacter.ordinal());
|
writer.putInt(GameObjectType.PlayerCharacter.ordinal());
|
||||||
writer.putInt(condemned.getPlayerUID());
|
writer.putInt(condemned.playerUID);
|
||||||
writer.putInt(condemned.getFriendType());
|
writer.putInt(condemned.friendType);
|
||||||
writer.putInt(GameObjectType.PlayerCharacter.ordinal());
|
writer.putInt(GameObjectType.PlayerCharacter.ordinal());
|
||||||
writer.putInt(condemned.getPlayerUID());
|
writer.putInt(condemned.playerUID);
|
||||||
writer.putInt(0);
|
writer.putInt(0);
|
||||||
writer.putInt(0);
|
writer.putInt(0);
|
||||||
writer.putInt(GameObjectType.Guild.ordinal());
|
writer.putInt(GameObjectType.Guild.ordinal());
|
||||||
@@ -531,9 +531,9 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg {
|
|||||||
writer.putInt(guild.getObjectUUID());
|
writer.putInt(guild.getObjectUUID());
|
||||||
else
|
else
|
||||||
writer.putInt(0);
|
writer.putInt(0);
|
||||||
writer.put(condemned.isActive() ? (byte) 1 : (byte) 0);
|
writer.put(condemned.active ? (byte) 1 : (byte) 0);
|
||||||
writer.put((byte) 0);
|
writer.put((byte) 0);
|
||||||
writer.put(condemned.isActive() ? (byte) 1 : (byte) 0);
|
writer.put(condemned.active ? (byte) 1 : (byte) 0);
|
||||||
|
|
||||||
if (playerCharacter != null)
|
if (playerCharacter != null)
|
||||||
writer.putString(playerCharacter.getFirstName());
|
writer.putString(playerCharacter.getFirstName());
|
||||||
@@ -547,16 +547,16 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
guild = Guild.getGuild(condemned.getGuildUID());
|
guild = Guild.getGuild(condemned.guildUID);
|
||||||
writer.putInt(GameObjectType.Guild.ordinal());
|
writer.putInt(GameObjectType.Guild.ordinal());
|
||||||
writer.putInt(condemned.getGuildUID());
|
writer.putInt(condemned.guildUID);
|
||||||
writer.putInt(condemned.getFriendType());
|
writer.putInt(condemned.friendType);
|
||||||
writer.putLong(0);
|
writer.putLong(0);
|
||||||
writer.putInt(GameObjectType.Guild.ordinal());
|
writer.putInt(GameObjectType.Guild.ordinal());
|
||||||
writer.putInt(condemned.getGuildUID());
|
writer.putInt(condemned.guildUID);
|
||||||
writer.putLong(0);
|
writer.putLong(0);
|
||||||
writer.put((byte) 0);
|
writer.put((byte) 0);
|
||||||
writer.put(condemned.isActive() ? (byte) 1 : (byte) 0);
|
writer.put(condemned.active ? (byte) 1 : (byte) 0);
|
||||||
writer.put((byte) 0);
|
writer.put((byte) 0);
|
||||||
if (guild != null)
|
if (guild != null)
|
||||||
writer.putString(guild.getName());
|
writer.putString(guild.getName());
|
||||||
@@ -570,17 +570,17 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg {
|
|||||||
GuildTag._serializeForDisplay(GuildTag.ERRANT, writer);
|
GuildTag._serializeForDisplay(GuildTag.ERRANT, writer);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
guild = Guild.getGuild(condemned.getGuildUID());
|
guild = Guild.getGuild(condemned.guildUID);
|
||||||
writer.putInt(GameObjectType.Guild.ordinal());
|
writer.putInt(GameObjectType.Guild.ordinal());
|
||||||
writer.putInt(condemned.getGuildUID());
|
writer.putInt(condemned.guildUID);
|
||||||
writer.putInt(condemned.getFriendType());
|
writer.putInt(condemned.friendType);
|
||||||
writer.putLong(0);
|
writer.putLong(0);
|
||||||
writer.putLong(0);
|
writer.putLong(0);
|
||||||
writer.putInt(GameObjectType.Guild.ordinal());
|
writer.putInt(GameObjectType.Guild.ordinal());
|
||||||
writer.putInt(condemned.getGuildUID());
|
writer.putInt(condemned.guildUID);
|
||||||
writer.put((byte) 0);
|
writer.put((byte) 0);
|
||||||
writer.put((byte) 0);
|
writer.put((byte) 0);
|
||||||
writer.put(condemned.isActive() ? (byte) 1 : (byte) 0);
|
writer.put(condemned.active ? (byte) 1 : (byte) 0);
|
||||||
if (guild != null)
|
if (guild != null)
|
||||||
writer.putString(guild.getName());
|
writer.putString(guild.getName());
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -14,72 +14,45 @@ import engine.gameManager.DbManager;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
|
||||||
public class Condemned {
|
public class Condemned {
|
||||||
|
|
||||||
public static final int INDIVIDUAL = 2;
|
public static final int INDIVIDUAL = 2;
|
||||||
public static final int GUILD = 4;
|
public static final int GUILD = 4;
|
||||||
public static final int NATION = 5;
|
public static final int NATION = 5;
|
||||||
private int ID;
|
|
||||||
private int playerUID;
|
|
||||||
private int parent;
|
|
||||||
private int guildUID;
|
|
||||||
private int friendType;
|
|
||||||
private boolean active;
|
|
||||||
|
|
||||||
|
public int playerUID;
|
||||||
|
public int buildingUUID;
|
||||||
|
public int guildUID;
|
||||||
|
public int friendType;
|
||||||
|
public boolean active;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ResultSet Constructor
|
* ResultSet Constructor
|
||||||
*/
|
*/
|
||||||
public Condemned(ResultSet rs) throws SQLException {
|
public Condemned(ResultSet rs) throws SQLException {
|
||||||
this.playerUID = rs.getInt("playerUID");
|
this.playerUID = rs.getInt("playerUID");
|
||||||
this.parent = rs.getInt("buildingUID");
|
this.buildingUUID = rs.getInt("buildingUID");
|
||||||
this.guildUID = rs.getInt("guildUID");
|
this.guildUID = rs.getInt("guildUID");
|
||||||
this.friendType = rs.getInt("friendType");
|
this.friendType = rs.getInt("friendType");
|
||||||
this.active = rs.getBoolean("active");
|
this.active = rs.getBoolean("active");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Condemned(int playerUID, int buildingUUID, int guildUID, int friendType) {
|
||||||
public Condemned(int playerUID, int parent, int guildUID, int friendType) {
|
|
||||||
super();
|
super();
|
||||||
this.playerUID = playerUID;
|
this.playerUID = playerUID;
|
||||||
this.parent = parent;
|
this.buildingUUID = buildingUUID;
|
||||||
this.guildUID = guildUID;
|
this.guildUID = guildUID;
|
||||||
this.friendType = friendType;
|
this.friendType = friendType;
|
||||||
this.active = false;
|
this.active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getPlayerUID() {
|
|
||||||
return playerUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getParent() {
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getGuildUID() {
|
|
||||||
return guildUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getFriendType() {
|
|
||||||
return friendType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isActive() {
|
|
||||||
return active;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean setActive(boolean active) {
|
public boolean setActive(boolean active) {
|
||||||
|
|
||||||
if (!DbManager.BuildingQueries.updateActiveCondemn(this, active))
|
if (!DbManager.BuildingQueries.updateActiveCondemn(this, active))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this.active = active;
|
this.active = active;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,6 +321,9 @@ public class WorldServer {
|
|||||||
Logger.info("Initializing Building Friends");
|
Logger.info("Initializing Building Friends");
|
||||||
DbManager.BuildingQueries.LOAD_BUILDING_FRIENDS();
|
DbManager.BuildingQueries.LOAD_BUILDING_FRIENDS();
|
||||||
|
|
||||||
|
Logger.info("Initializing Building Condemned");
|
||||||
|
DbManager.BuildingQueries.LOAD_BUILDING_CONDEMNED();
|
||||||
|
|
||||||
Logger.info("Initializing NPC Profits");
|
Logger.info("Initializing NPC Profits");
|
||||||
DbManager.NPCQueries.LOAD_NPC_PROFITS();
|
DbManager.NPCQueries.LOAD_NPC_PROFITS();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user