diff options
Diffstat (limited to 'src/main/java/com/encrox/zombie/Map.java')
-rwxr-xr-x | src/main/java/com/encrox/zombie/Map.java | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/src/main/java/com/encrox/zombie/Map.java b/src/main/java/com/encrox/zombie/Map.java new file mode 100755 index 0000000..8262ba7 --- /dev/null +++ b/src/main/java/com/encrox/zombie/Map.java @@ -0,0 +1,118 @@ +package com.encrox.zombie;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Item;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.util.BlockVector;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import com.encrox.zombie.interactable.Chest;
+import com.encrox.zombie.interactable.Lever;
+import com.encrox.zombie.interactable.Powerup;
+
+public class Map {
+
+ private Schematic schematic;
+ private String name;
+ private int players;
+ private BlockVector spawn;
+ private Chest[] chests;
+ private Mob[] mobs;
+ private Powerup[] powerups;
+ private Lever[] levers;
+
+ public Map(JSONObject descriptor) {
+ this.schematic = new Schematic(new File(Zombie.schematicsDirectory, descriptor.getString("file")));
+ this.name = descriptor.getString("name");
+ this.players = descriptor.getInt("players");
+ JSONArray spawnArray = descriptor.getJSONArray("spawn");
+ this.spawn = new BlockVector(spawnArray.getInt(0), spawnArray.getInt(1), spawnArray.getInt(2));
+ JSONArray leversArray = descriptor.getJSONArray("levers");
+ levers = new Lever[leversArray.length()];
+ for(int i = 0; i<levers.length; i++) {
+ JSONObject lever = leversArray.getJSONObject(i);
+ JSONArray position = lever.getJSONArray("position");
+ JSONArray othersLever = lever.getJSONArray("toggle");
+ Lever[] others = new Lever[othersLever.length()];
+ for(int x = 0; x<others.length; x++)
+ others[x] = levers[othersLever.getInt(x)];
+ levers[i] = new Lever(new BlockVector(position.getInt(0), position.getInt(1), position.getInt(2)), lever.getInt("cost"), others);
+ }
+ JSONArray mobsArray = descriptor.getJSONArray("mobs");
+ mobs = new Mob[mobsArray.length()];
+ for(int i = 0; i<mobs.length; i++) {
+ JSONObject mob = mobsArray.getJSONObject(i);
+ JSONArray position = mob.getJSONArray("position");
+ JSONArray leversMob = mob.getJSONArray("levers");
+ Lever[] levers = new Lever[leversMob.length()];
+ for(int x = 0; x<levers.length; x++)
+ levers[x] = this.levers[leversMob.getInt(x)];
+ mobs[i] = new Mob(EntityType.fromId(mob.getInt("type")), new BlockVector(position.getInt(0), position.getInt(1), position.getInt(2)), mob.getString("rounds"), levers);
+ }
+ JSONArray chestsArray = descriptor.getJSONArray("chests");
+ chests = new Chest[chestsArray.length()];
+ for(int i = 0; i<chests.length; i++) {
+ JSONObject chest = chestsArray.getJSONObject(i);
+ JSONArray position = chest.getJSONArray("position");
+ chests[i] = new Chest(new BlockVector(position.getInt(0), position.getInt(1), position.getInt(2)), chest.getInt("cost"), chest.getString("facing"));
+ }
+ JSONArray powerupsArray = descriptor.getJSONArray("powerups");
+ powerups = new Powerup[powerupsArray.length()];
+ for(int i = 0; i<powerups.length; i++) {
+ JSONObject powerup = powerupsArray.getJSONObject(i);
+ JSONArray position = powerup.getJSONArray("position");
+ JSONObject enchantment = powerup.getJSONObject("enchantment");
+ ItemStack item = new ItemStack(Material.getMaterial(powerup.getString("item")));
+ String enchStr = enchantment.getString("type");
+ if(!enchStr.equals("")) {
+ Enchantment ench = Enchantment.getByName(enchStr);
+ if(ench.canEnchantItem(item)) {
+ item.addEnchantment(ench, enchantment.getInt("level"));
+ } else {
+ Zombie.logger.warning(Zombie.lang.getProperty("plugin_enchantment"));
+ }
+ }
+ powerups[i] = new Powerup(new BlockVector(position.getInt(0), position.getInt(1), position.getInt(2)), item, powerup.getInt("cost"));
+ }
+ }
+
+ public int getPlayers() {
+ return players;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Schematic getSchematic() {
+ return schematic;
+ }
+
+ public BlockVector getSpawn() {
+ return spawn;
+ }
+
+ public Mob[] getMobs() {
+ return mobs;
+ }
+
+ public Chest[] getChests() {
+ return chests;
+ }
+
+ public Powerup[] getPowerups() {
+ return powerups;
+ }
+
+ public Lever[] getLevers() {
+ return levers;
+ }
+
+}
|