forked from MagicBane/Server
Project cleanup pre merge.
This commit is contained in:
+122
-123
@@ -18,154 +18,153 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Heraldry {
|
||||
public class Heraldry {
|
||||
|
||||
public int playerUID;
|
||||
public int characterUUID;
|
||||
public int characterType;
|
||||
|
||||
public static HashMap <Integer,HashMap<Integer,Integer>> HeraldyMap = new HashMap<>();
|
||||
public static HashMap<Integer, HashMap<Integer, Integer>> HeraldyMap = new HashMap<>();
|
||||
public int playerUID;
|
||||
public int characterUUID;
|
||||
public int characterType;
|
||||
|
||||
/**
|
||||
* ResultSet Constructor
|
||||
*/
|
||||
/**
|
||||
* ResultSet Constructor
|
||||
*/
|
||||
|
||||
public Heraldry(ResultSet rs) throws SQLException {
|
||||
this.playerUID = rs.getInt("playerUID");
|
||||
this.characterUUID = rs.getInt("characterUID");
|
||||
this.characterType = rs.getInt("characterType");
|
||||
|
||||
//cache player friends.
|
||||
//hashset already created, just add to set.
|
||||
if (HeraldyMap.containsKey(playerUID)){
|
||||
HashMap<Integer,Integer> playerHeraldySet = HeraldyMap.get(playerUID);
|
||||
playerHeraldySet.put(characterUUID,characterType);
|
||||
//hashset not yet created, create new set, and add to map.
|
||||
}else{
|
||||
HashMap<Integer,Integer> playerHeraldySet = new HashMap<>();
|
||||
playerHeraldySet.put(characterUUID,characterType);
|
||||
HeraldyMap.put(this.playerUID, playerHeraldySet);
|
||||
}
|
||||
|
||||
}
|
||||
public Heraldry(ResultSet rs) throws SQLException {
|
||||
this.playerUID = rs.getInt("playerUID");
|
||||
this.characterUUID = rs.getInt("characterUID");
|
||||
this.characterType = rs.getInt("characterType");
|
||||
|
||||
public Heraldry(int playerUID, int friendUID) {
|
||||
super();
|
||||
this.playerUID = playerUID;
|
||||
this.characterUUID = friendUID;
|
||||
}
|
||||
//cache player friends.
|
||||
//hashset already created, just add to set.
|
||||
if (HeraldyMap.containsKey(playerUID)) {
|
||||
HashMap<Integer, Integer> playerHeraldySet = HeraldyMap.get(playerUID);
|
||||
playerHeraldySet.put(characterUUID, characterType);
|
||||
//hashset not yet created, create new set, and add to map.
|
||||
} else {
|
||||
HashMap<Integer, Integer> playerHeraldySet = new HashMap<>();
|
||||
playerHeraldySet.put(characterUUID, characterType);
|
||||
HeraldyMap.put(this.playerUID, playerHeraldySet);
|
||||
}
|
||||
|
||||
public int getPlayerUID() {
|
||||
return playerUID;
|
||||
}
|
||||
|
||||
public static boolean AddToHeraldy(int playerID, AbstractWorldObject character){
|
||||
HashMap<Integer,Integer> characters = HeraldyMap.get(playerID);
|
||||
|
||||
if (characters != null){
|
||||
//already in friends list, don't do anything.
|
||||
if (characters.containsKey(character.getObjectUUID()))
|
||||
return false;
|
||||
|
||||
DbManager.PlayerCharacterQueries.ADD_HERALDY(playerID, character);
|
||||
characters.put(character.getObjectUUID(),character.getObjectType().ordinal());
|
||||
}else{
|
||||
characters = new HashMap<>();
|
||||
DbManager.PlayerCharacterQueries.ADD_HERALDY(playerID, character);
|
||||
characters.put(character.getObjectUUID(),character.getObjectType().ordinal());
|
||||
HeraldyMap.put(playerID, characters);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean RemoveFromHeraldy(int playerID, int characterID){
|
||||
|
||||
if (!CanRemove(playerID, characterID))
|
||||
return false;
|
||||
|
||||
HashMap<Integer,Integer> characters = HeraldyMap.get(playerID);
|
||||
|
||||
if (characters != null){
|
||||
DbManager.PlayerCharacterQueries.REMOVE_HERALDY(playerID, characterID);
|
||||
characters.remove(characterID);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean CanRemove(int playerID, int toRemove){
|
||||
if (HeraldyMap.get(playerID) == null)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HeraldyMap.get(playerID).isEmpty())
|
||||
return false;
|
||||
public Heraldry(int playerUID, int friendUID) {
|
||||
super();
|
||||
this.playerUID = playerUID;
|
||||
this.characterUUID = friendUID;
|
||||
}
|
||||
|
||||
if (!HeraldyMap.get(playerID).containsKey(toRemove))
|
||||
return false;
|
||||
public static boolean AddToHeraldy(int playerID, AbstractWorldObject character) {
|
||||
HashMap<Integer, Integer> characters = HeraldyMap.get(playerID);
|
||||
|
||||
return true;
|
||||
}
|
||||
if (characters != null) {
|
||||
//already in friends list, don't do anything.
|
||||
if (characters.containsKey(character.getObjectUUID()))
|
||||
return false;
|
||||
|
||||
public static void AuditHeraldry() {
|
||||
DbManager.PlayerCharacterQueries.ADD_HERALDY(playerID, character);
|
||||
characters.put(character.getObjectUUID(), character.getObjectType().ordinal());
|
||||
} else {
|
||||
characters = new HashMap<>();
|
||||
DbManager.PlayerCharacterQueries.ADD_HERALDY(playerID, character);
|
||||
characters.put(character.getObjectUUID(), character.getObjectType().ordinal());
|
||||
HeraldyMap.put(playerID, characters);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
HashMap<Integer, Integer> characterMap;
|
||||
ArrayList<Integer> purgeList = new ArrayList<>();
|
||||
public static boolean RemoveFromHeraldy(int playerID, int characterID) {
|
||||
|
||||
for (int playerID : Heraldry.HeraldyMap.keySet()) {
|
||||
if (!CanRemove(playerID, characterID))
|
||||
return false;
|
||||
|
||||
characterMap = Heraldry.HeraldyMap.get(playerID);
|
||||
HashMap<Integer, Integer> characters = HeraldyMap.get(playerID);
|
||||
|
||||
if (characterMap == null || characterMap.isEmpty())
|
||||
continue;
|
||||
if (characters != null) {
|
||||
DbManager.PlayerCharacterQueries.REMOVE_HERALDY(playerID, characterID);
|
||||
characters.remove(characterID);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Loop through map adding deleted characters to our purge map
|
||||
public static boolean CanRemove(int playerID, int toRemove) {
|
||||
if (HeraldyMap.get(playerID) == null)
|
||||
return false;
|
||||
|
||||
purgeList.clear();
|
||||
if (HeraldyMap.get(playerID).isEmpty())
|
||||
return false;
|
||||
|
||||
for (int characterID : characterMap.keySet()) {
|
||||
if (!HeraldyMap.get(playerID).containsKey(toRemove))
|
||||
return false;
|
||||
|
||||
int characterType = characterMap.get(characterID);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (characterType != GameObjectType.PlayerCharacter.ordinal())
|
||||
continue;
|
||||
public static void AuditHeraldry() {
|
||||
|
||||
// Player is deleted, add to purge list
|
||||
HashMap<Integer, Integer> characterMap;
|
||||
ArrayList<Integer> purgeList = new ArrayList<>();
|
||||
|
||||
if (PlayerCharacter.getFromCache(characterID) == null)
|
||||
purgeList.add(characterID);
|
||||
for (int playerID : Heraldry.HeraldyMap.keySet()) {
|
||||
|
||||
}
|
||||
characterMap = Heraldry.HeraldyMap.get(playerID);
|
||||
|
||||
// Run purge
|
||||
if (characterMap == null || characterMap.isEmpty())
|
||||
continue;
|
||||
|
||||
for (int uuid : purgeList) {
|
||||
// Loop through map adding deleted characters to our purge map
|
||||
|
||||
if (!Heraldry.RemoveFromHeraldy(playerID, uuid))
|
||||
continue;
|
||||
purgeList.clear();
|
||||
|
||||
Logger.info("Removed Deleted Character ID " + uuid + " from PlayerID " + playerID + " heraldry.");
|
||||
for (int characterID : characterMap.keySet()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
int characterType = characterMap.get(characterID);
|
||||
|
||||
if (characterType != GameObjectType.PlayerCharacter.ordinal())
|
||||
continue;
|
||||
|
||||
// Player is deleted, add to purge list
|
||||
|
||||
if (PlayerCharacter.getFromCache(characterID) == null)
|
||||
purgeList.add(characterID);
|
||||
|
||||
}
|
||||
|
||||
// Run purge
|
||||
|
||||
for (int uuid : purgeList) {
|
||||
|
||||
if (!Heraldry.RemoveFromHeraldy(playerID, uuid))
|
||||
continue;
|
||||
|
||||
Logger.info("Removed Deleted Character ID " + uuid + " from PlayerID " + playerID + " heraldry.");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ValidateHeraldry(int playerUUID) {
|
||||
|
||||
HashMap<Integer, Integer> heraldryMap = Heraldry.HeraldyMap.get(playerUUID);
|
||||
|
||||
if (heraldryMap == null || heraldryMap.isEmpty())
|
||||
return;
|
||||
|
||||
for (int characterID : heraldryMap.keySet()) {
|
||||
int characterType = heraldryMap.get(characterID);
|
||||
|
||||
GameObjectType objectType = GameObjectType.values()[characterType];
|
||||
|
||||
AbstractGameObject ago = DbManager.getFromCache(objectType, characterID);
|
||||
|
||||
if (ago == null)
|
||||
heraldryMap.remove(characterID);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public int getPlayerUID() {
|
||||
return playerUID;
|
||||
}
|
||||
|
||||
public static void ValidateHeraldry(int playerUUID) {
|
||||
|
||||
HashMap<Integer,Integer> heraldryMap = Heraldry.HeraldyMap.get(playerUUID);
|
||||
|
||||
if (heraldryMap == null || heraldryMap.isEmpty())
|
||||
return;
|
||||
|
||||
for (int characterID : heraldryMap.keySet()){
|
||||
int characterType = heraldryMap.get(characterID);
|
||||
|
||||
GameObjectType objectType = GameObjectType.values()[characterType];
|
||||
|
||||
AbstractGameObject ago = DbManager.getFromCache(objectType, characterID);
|
||||
|
||||
if (ago == null)
|
||||
heraldryMap.remove(characterID);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user