summaryrefslogtreecommitdiff
path: root/src/main/java/com/encrox/zombie/Map.java
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2022-04-25 18:50:36 +0200
committerLeonard Kugis <leonard@kug.is>2022-04-25 18:50:36 +0200
commit9e2ddeb55321b09086a5a27254197d783847e6e3 (patch)
tree620e4a7b326df2a77fff51aff390e0a6bef43631 /src/main/java/com/encrox/zombie/Map.java
Initial commitHEADmaster
Diffstat (limited to 'src/main/java/com/encrox/zombie/Map.java')
-rwxr-xr-xsrc/main/java/com/encrox/zombie/Map.java118
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;
+ }
+
+}