mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-03 14:38:56 +00:00
Created createSieges()
This commit is contained in:
1 parent
850ea26171
commit
484db589b7
1 file changed
+22
-4
@@ -1,7 +1,9 @@
|
|||||||
package me.ShermansWorld.AlathraWar.data;
|
package me.ShermansWorld.AlathraWar.data;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
@@ -17,7 +19,7 @@ public class SiegeData
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Static Siege list for all active sieges
|
// Static Siege list for all active sieges
|
||||||
private static ArrayList<Siege> sieges = new ArrayList<Siege>();
|
private static HashSet<Siege> sieges = new HashSet<Siege>();
|
||||||
private final static String dataFolderPath = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
|
private final static String dataFolderPath = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
|
||||||
|
|
||||||
// Filter for only accessing yml files
|
// Filter for only accessing yml files
|
||||||
@@ -28,7 +30,7 @@ public class SiegeData
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static ArrayList<Siege> getSieges() {
|
public static HashSet<Siege> getSieges() {
|
||||||
return sieges;
|
return sieges;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +41,7 @@ public class SiegeData
|
|||||||
*/
|
*/
|
||||||
public static Siege getSiege(String name) {
|
public static Siege getSiege(String name) {
|
||||||
for (Siege siege : sieges) {
|
for (Siege siege : sieges) {
|
||||||
|
if (siege.getTown().getName().equalsIgnoreCase(name)) return siege;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -111,7 +113,7 @@ public class SiegeData
|
|||||||
public static HashMap<String, Object> siegeToMap(Siege siege) {
|
public static HashMap<String, Object> siegeToMap(Siege siege) {
|
||||||
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||||
// Shoves everything into a map.
|
// Shoves everything into a map.
|
||||||
returnMap.put("town", siege.getTown());
|
returnMap.put("town", siege.getTown().getName());
|
||||||
returnMap.put("siegeTicks", siege.getSiegeTicks());
|
returnMap.put("siegeTicks", siege.getSiegeTicks());
|
||||||
returnMap.put("attackerPoints", siege.getAttackerPoints());
|
returnMap.put("attackerPoints", siege.getAttackerPoints());
|
||||||
returnMap.put("defenderPoints", siege.getDefenderPoints());
|
returnMap.put("defenderPoints", siege.getDefenderPoints());
|
||||||
@@ -133,4 +135,20 @@ public class SiegeData
|
|||||||
return returnMap;
|
return returnMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Siege> createSieges(War war, Collection<HashMap<String, Object>> siegeMaps) {
|
||||||
|
ArrayList<Siege> returnList = new ArrayList<Siege>();
|
||||||
|
for (HashMap<String, Object> map : siegeMaps) {
|
||||||
|
Town town = TownyAPI.getInstance().getTown((String) map.get("town"));
|
||||||
|
if (town == null) continue;
|
||||||
|
|
||||||
|
Siege siege = new Siege(war, town, (war.getSide(town.getName()) == 2 ));
|
||||||
|
siege.addPointsToAttackers((int) map.get("attackerPoints"));
|
||||||
|
siege.addPointsToDefenders((int) map.get("defenderPoints"));
|
||||||
|
siege.resume((int) map.get("siegeTicks"));
|
||||||
|
returnList.add(siege);
|
||||||
|
|
||||||
|
}
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user