diff options
Diffstat (limited to 'src/main/java/com/encrox')
-rwxr-xr-x | src/main/java/com/encrox/zombie/Commander.java | 56 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/Constants.java | 59 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/Game.java | 294 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/GameListener.java | 159 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/Lobby.java | 72 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/Map.java | 118 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/Misc.java | 12 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/Mob.java | 41 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/Schematic.java | 117 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/Zombie.java | 245 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/ZombieWorld.java | 79 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/interactable/Chest.java | 27 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/interactable/Interactable.java | 23 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/interactable/Lever.java | 38 | ||||
-rwxr-xr-x | src/main/java/com/encrox/zombie/interactable/Powerup.java | 22 |
15 files changed, 1362 insertions, 0 deletions
diff --git a/src/main/java/com/encrox/zombie/Commander.java b/src/main/java/com/encrox/zombie/Commander.java new file mode 100755 index 0000000..40e77eb --- /dev/null +++ b/src/main/java/com/encrox/zombie/Commander.java @@ -0,0 +1,56 @@ +package com.encrox.zombie;
+
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class Commander implements CommandExecutor {
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) {
+ try {
+ if(sender instanceof Player) {
+ Player player = (Player)sender;
+ switch(args[0]) {
+ case "lobby":
+ switch(args[1]) {
+ case "create":
+ if(player.hasPermission("zombie.create")) {
+ player.sendMessage(Zombie.createLobby(player, args[2], args[3]));
+ } else {
+ player.sendMessage(ChatColor.RED + Zombie.lang.getProperty("no_permission"));
+ }
+ break;
+ case "join":
+ if(player.hasPermission("zombie.join")) {
+ if(args.length == 3) {
+ player.sendMessage(Zombie.joinLobby(player, args[2]));
+ } else {
+ player.sendMessage(Zombie.listLobbies());
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + Zombie.lang.getProperty("no_permission"));
+ }
+ break;
+ case "leave":
+ player.sendMessage(Zombie.removePlayer(player));
+ break;
+ case "start":
+ player.sendMessage(Zombie.start(player));
+ break;
+ }
+ break;
+ }
+ } else {
+ sender.sendMessage(Zombie.lang.getProperty("no_player"));
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/Constants.java b/src/main/java/com/encrox/zombie/Constants.java new file mode 100755 index 0000000..50e7491 --- /dev/null +++ b/src/main/java/com/encrox/zombie/Constants.java @@ -0,0 +1,59 @@ +package com.encrox.zombie;
+
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
+
+import com.sk89q.worldedit.blocks.ItemType;
+
+public class Constants {
+
+ public static class Game {
+
+ public static final Material[] ITEMSET = new Material[] {
+ Material.WOOD_HOE,
+ Material.WOOD_PICKAXE,
+ Material.WOOD_SPADE,
+ Material.WOOD_SWORD,
+ Material.STONE_AXE,
+ Material.STONE_HOE,
+ Material.STONE_PICKAXE,
+ Material.STONE_SPADE,
+ Material.STONE_SWORD,
+ Material.IRON_AXE,
+ Material.IRON_HOE,
+ Material.IRON_PICKAXE,
+ Material.IRON_SPADE,
+ Material.IRON_SWORD,
+ Material.GOLD_AXE,
+ Material.GOLD_HOE,
+ Material.GOLD_PICKAXE,
+ Material.GOLD_SPADE,
+ Material.GOLD_SWORD,
+ Material.DIAMOND_AXE,
+ Material.DIAMOND_HOE,
+ Material.DIAMOND_PICKAXE,
+ Material.DIAMOND_SPADE,
+ Material.DIAMOND_SWORD,
+ Material.BOW,
+ Material.ARROW,
+ Material.LEATHER_HELMET,
+ Material.LEATHER_CHESTPLATE,
+ Material.LEATHER_LEGGINGS,
+ Material.LEATHER_BOOTS,
+ Material.GOLD_HELMET,
+ Material.GOLD_CHESTPLATE,
+ Material.GOLD_LEGGINGS,
+ Material.GOLD_BOOTS,
+ Material.IRON_HELMET,
+ Material.IRON_CHESTPLATE,
+ Material.IRON_LEGGINGS,
+ Material.IRON_BOOTS,
+ Material.CHAINMAIL_HELMET,
+ Material.CHAINMAIL_CHESTPLATE,
+ Material.CHAINMAIL_LEGGINGS,
+ Material.CHAINMAIL_BOOTS
+ };
+
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/Game.java b/src/main/java/com/encrox/zombie/Game.java new file mode 100755 index 0000000..ae6ff4a --- /dev/null +++ b/src/main/java/com/encrox/zombie/Game.java @@ -0,0 +1,294 @@ +package com.encrox.zombie;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.Sign;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.PlayerDeathEvent;
+import org.bukkit.material.MaterialData;
+import org.bukkit.util.BlockVector;
+
+import com.encrox.instancedregions.InstancedProtectedCuboidRegion;
+import com.encrox.zombie.interactable.Chest;
+import com.encrox.zombie.interactable.Interactable;
+import com.encrox.zombie.interactable.Lever;
+import com.encrox.zombie.interactable.Powerup;
+
+public class Game {
+
+ private volatile ArrayList<Player> players, frozen;
+ private volatile Map map;
+ private volatile HashMap<Player,Integer> stats;
+ private volatile InstancedProtectedCuboidRegion region;
+ private volatile Mob[] mobs;
+ private volatile ArrayList<Mob> mobsRound;
+ public volatile ArrayList<Integer> watchdog;
+ private volatile int round;
+ private volatile boolean done;
+ private volatile Interactable[] inters;
+ private volatile com.sk89q.worldedit.BlockVector min;
+
+ public Game(ArrayList<Player> players, Map map) {
+ this.players = players;
+ this.map = map;
+ stats = new HashMap<Player,Integer>();
+ region = Zombie.zombieWorld.allocate(map.getSchematic());
+ mobs = map.getMobs();
+ mobsRound = new ArrayList<Mob>();
+ watchdog = new ArrayList<Integer>();
+ frozen = new ArrayList<Player>();
+ BlockVector spawn = map.getSpawn();
+ min = region.getMinimumPoint();
+ Powerup[] powerups = map.getPowerups();
+ Lever[] levers = map.getLevers();
+ inters = new Interactable[powerups.length+levers.length+1];
+ for(int i = 0; i<levers.length; i++) {
+ inters[i] = levers[i];
+ }
+ for(int i = 0; i<powerups.length; i++) {
+ BlockVector bv = powerups[i].getBlockVector();
+ Block block = Zombie.zombieWorld.getWorld().getBlockAt(min.getBlockX()+bv.getBlockX(), 64+bv.getBlockY(), min.getBlockZ()+bv.getBlockZ());
+ inters[powerups.length+i] = powerups[i];
+ block.setType(Material.SIGN_POST);
+ Sign sign = (Sign)block.getState();
+ //sign.setData(new MaterialData(Material.WALL_SIGN));
+ sign.setLine(0, "[ZombieItem]");
+ String itemStr = powerups[i].getItem().toString();
+ sign.setLine(1, itemStr);
+ int len1 = itemStr.length(), len2 = sign.getLine(1).length();
+ if(len2 < len1)
+ sign.setLine(2, itemStr.substring(len2));
+ if((len2 += sign.getLine(2).length()) < len1)
+ sign.setLine(3, itemStr.substring(len2));
+ sign.update();
+ }
+ Chest relChest = (Chest)Misc.random(map.getChests());
+ inters[inters.length-1] = relChest;
+ BlockVector bv = relChest.getBlockVector();
+ Block block = Zombie.zombieWorld.getWorld().getBlockAt(min.getBlockX()+bv.getBlockX(), 64+bv.getBlockY(), min.getBlockZ()+bv.getBlockZ());
+ block.setType(Material.CHEST);
+ org.bukkit.material.Chest c = new org.bukkit.material.Chest();
+ c.setFacingDirection(relChest.getFacing());
+ block.setData(c.getData());
+ block.getState().update();
+ region.apply();
+ Player player;
+ for(int i = 0, size = players.size(); i<size; i++) {
+ player = players.get(i);
+ stats.put(player, 1000000);
+ region.addPlayer(player);
+ player.teleport(new Location(Zombie.zombieWorld.getWorld(), -1000, 64, -1000));
+ Bukkit.getScheduler().runTaskLater(Zombie.plugin, new Runnable() {
+ Player player;
+ @Override
+ public void run() {
+ player.teleport(new Location(Zombie.zombieWorld.getWorld(), min.getBlockX()+spawn.getBlockX()+.5, 64+spawn.getBlockY(), min.getBlockZ()+spawn.getBlockZ()+.5));
+ }
+ public Runnable setPlayer(Player player) {
+ this.player = player;
+ return this;
+ }
+ }.setPlayer(player), 120L);
+ }
+ /*
+ Bukkit.getScheduler().runTask(Zombie.plugin, new Runnable() {
+ @Override
+ public void run() {
+ Mob current;
+ int amount = 1;
+ com.sk89q.worldedit.BlockVector min = region.getMinimumPoint();
+ LivingEntity entity;
+ for(int round = 1; round < Integer.MAX_VALUE; round++) {
+ announce(ChatColor.YELLOW + Zombie.lang.getProperty("game_round").replace("%round%", ""+round));
+ for(int i = 0, size = mobs.size(); i<size; i++) {
+ current = mobs.get(i);
+ if(current.spawn(round)) {
+ mobsRound.add(current);
+ }
+ }
+ for(int i = 0; i<amount; i++) {
+ for(int x = 0, size = mobsRound.size(); x<size; x++) {
+ current = mobsRound.get(x);
+ entity = Zombie.zombieWorld.getWorld().spawnCreature(new Location(Zombie.zombieWorld.getWorld(), min.getBlockX()+current.bv.getBlockX(), 64+current.bv.getBlockY(), min.getBlockZ()+current.bv.getBlockZ()), current.type);
+ entity.setMaxHealth(entity.getMaxHealth() + round);
+ entity.setHealth(entity.getMaxHealth());
+ watchdog.add(entity.getEntityId());
+ }
+ }
+ while(!watchdog.isEmpty());
+ }
+ }
+ });
+ */
+
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ Mob current;
+ com.sk89q.worldedit.BlockVector min = region.getMinimumPoint();
+ for(round = 1; round < Integer.MAX_VALUE; round++) {
+ announce(ChatColor.YELLOW + Zombie.lang.getProperty("game_round").replace("%round%", ""+round));
+ mobsRound.clear();
+ for(int i = 0; i<mobs.length; i++) {
+ if(mobs[i].spawn(round)) {
+ mobsRound.add(mobs[i]);
+ }
+ }
+ done = false;
+ Bukkit.getScheduler().runTask(Zombie.plugin, new Runnable() {
+ @Override
+ public void run() {
+ LivingEntity entity;
+ Mob current;
+ for(int i = 0, amount = 10 + round; i<amount; i++) {
+ for(int x = 0, size = mobsRound.size(); x<size; x++) {
+ current = mobsRound.get(x);
+ entity = Zombie.zombieWorld.getWorld().spawnCreature(new Location(Zombie.zombieWorld.getWorld(), min.getBlockX()+current.bv.getBlockX(), 64+current.bv.getBlockY(), min.getBlockZ()+current.bv.getBlockZ()), current.type);
+ entity.setMaxHealth(entity.getMaxHealth() + round);
+ entity.setHealth(entity.getMaxHealth());
+ watchdog.add(entity.getEntityId());
+ }
+ }
+ done = true;
+ }
+ });
+ while(!done);
+ while(!watchdog.isEmpty());
+ }
+ }
+ }).start();
+
+ }
+
+ public ArrayList<Player> getPlayers() {
+ return players;
+ }
+
+ public void playerDeath(Player player) {
+ if(!frozen.contains(player)) {
+ announce(ChatColor.RED + Zombie.lang.getProperty("game_player_fell").replace("%player%", player.getName()));
+ player.teleport(player.getLocation().add(0, -1, 0));
+ player.setHealth(.5);
+ frozen.add(player);
+ Bukkit.getScheduler().runTaskTimer(Zombie.plugin, new Runnable() {
+ int t = 30;
+ @Override
+ public void run() {
+ if(frozen.contains(player)) {
+ if(t == 0) {
+ announce(ChatColor.RED + Zombie.lang.getProperty("game_player_died").replace("%player%", player.getName()));
+ frozen.remove(player);
+ players.remove(player);
+ player.setHealth(player.getMaxHealth());
+ //TODO: Teleport back outta dungeon
+ } else {
+ announce(ChatColor.YELLOW + Zombie.lang.getProperty("game_revive_countdown").replace("%player%", player.getName()).replace("%seconds%", ""+t));
+ t-=5;
+ }
+ }
+ }
+ }, 0, 100);
+ }
+ }
+
+ public boolean isFrozen(Player player) {
+ return frozen.contains(player);
+ }
+
+ public void revive(Player from, Player to) {
+ if(frozen.contains(to)) {
+ frozen.remove(to);
+ to.teleport(to.getLocation().add(0, -1, 0));
+ to.setHealth(to.getMaxHealth());
+ }
+ }
+
+ public void randomizeChest() {
+ Block block = Zombie.zombieWorld.getWorld().getBlockAt(getAbsoluteLocation(inters[inters.length-1].getBlockVector()));
+ block.setType(Material.AIR);
+ block.getState().update();
+ Chest relChest = (Chest)Misc.random(map.getChests());
+ inters[inters.length-1] = relChest;
+ block = Zombie.zombieWorld.getWorld().getBlockAt(getAbsoluteLocation(relChest.getBlockVector()));
+ block.setType(Material.CHEST);
+ org.bukkit.material.Chest c = new org.bukkit.material.Chest();
+ c.setFacingDirection(relChest.getFacing());
+ block.setData(c.getData());
+ block.getState().update();
+ }
+
+ public void announce(String text) {
+ for(int i = 0, size = players.size(); i<size; i++) {
+ players.get(i).sendMessage(text);
+ }
+ }
+
+ public void addPoints(Player player, int amount) {
+ int newPoints = stats.get(player)+amount;
+ stats.put(player, newPoints);
+ player.sendMessage(ChatColor.YELLOW + Zombie.lang.getProperty("game_points").replace("%points%", ""+newPoints));
+ }
+
+ public void substractPoints(Player player, int amount) {
+ int newPoints = stats.get(player)-amount;
+ stats.put(player, newPoints);
+ player.sendMessage(ChatColor.YELLOW + Zombie.lang.getProperty("game_points").replace("%points%", ""+newPoints));
+ }
+
+ public void addPoints(int amount) {
+ stats.forEach((k,v) -> stats.put(k, v+amount));
+ }
+
+ public int getPoints(Player player) {
+ if(stats.containsKey(player))
+ return stats.get(player);
+ return -1;
+ }
+
+ public Location getAbsoluteLocation(BlockVector relative) {
+ return new Location(Zombie.zombieWorld.getWorld(), min.getX()+relative.getBlockX(), 64+relative.getBlockY(), min.getBlockZ()+relative.getBlockZ());
+ }
+
+ /*
+ public Powerup getPowerup(Block block) {
+ for(int i = 0; i<powerups.length; i++) {
+ if(Zombie.zombieWorld.getWorld().getBlockAt(min.getBlockX()+powerups[i].bv.getBlockX(), 64+powerups[i].bv.getBlockY(), min.getBlockZ()+powerups[i].bv.getBlockZ()).equals(block)) {
+ return powerups[i];
+ }
+ }
+ return null;
+ }
+
+ public Lever getLever(Block block) {
+ for(int i = 0; i<levers.length; i++) {
+ if(Zombie.zombieWorld.getWorld().getBlockAt(min.getBlockX()+levers[i].bv.getBlockX(), 64+levers[i].bv.getBlockY(), min.getBlockZ()+levers[i].bv.getBlockZ()).equals(block)) {
+ return levers[i];
+ }
+ }
+ return null;
+ }
+ */
+
+ public Interactable getInteractable(Block block) {
+ BlockVector bv;
+ for(int i = 0; i<inters.length; i++) {
+ bv = inters[i].getBlockVector();
+ if(Zombie.zombieWorld.getWorld().getBlockAt(min.getBlockX()+bv.getBlockX(), 64+bv.getBlockY(), min.getBlockZ()+bv.getBlockZ()).equals(block)) {
+ return inters[i];
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/GameListener.java b/src/main/java/com/encrox/zombie/GameListener.java new file mode 100755 index 0000000..4d88aba --- /dev/null +++ b/src/main/java/com/encrox/zombie/GameListener.java @@ -0,0 +1,159 @@ +package com.encrox.zombie;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Random;
+
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityDeathEvent;
+import org.bukkit.event.entity.PlayerDeathEvent;
+import org.bukkit.event.player.PlayerInteractEntityEvent;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.event.player.PlayerMoveEvent;
+import org.bukkit.inventory.ItemStack;
+
+import com.encrox.zombie.interactable.Chest;
+import com.encrox.zombie.interactable.Interactable;
+import com.encrox.zombie.interactable.Lever;
+import com.encrox.zombie.interactable.Powerup;
+
+public class GameListener implements Listener {
+
+ @EventHandler
+ public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
+ if(e.getEntity() instanceof Player) {
+ Player player = (Player)e.getEntity();
+ if(player.getHealth() <= e.getDamage()) {
+ Game current;
+ for(int i = 0, size = Zombie.games.size(); i<size; i++) {
+ current = Zombie.games.get(i);
+ if(current.getPlayers().contains(player)) {
+ current.playerDeath(player);
+ e.setCancelled(true);
+ }
+ }
+ }
+ } else {
+ if(e.getDamager() instanceof Player) {
+ int id = e.getEntity().getEntityId();
+ Player player = (Player)e.getDamager();
+ Game current;
+ for(int i = 0, size = Zombie.games.size(); i<size; i++) {
+ current = Zombie.games.get(i);
+ if(current.watchdog.contains(id)) {
+ if(current.getPlayers().contains(player)) {
+ int amount = (int)Math.round(e.getFinalDamage());
+ current.addPoints(player, amount);
+ player.sendMessage(ChatColor.GREEN + Zombie.lang.getProperty("game_points_gained").replace("%points%", ""+amount));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @EventHandler
+ public void onPlayerMove(PlayerMoveEvent e) {
+ for(int i = 0, size = Zombie.games.size(); i<size; i++) {
+ if(Zombie.games.get(i).isFrozen(e.getPlayer())) {
+ e.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler
+ public void onPlayerInteract(PlayerInteractEvent e) {
+ try {
+ Player player = e.getPlayer();
+ Game current;
+ if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
+ for(int i = 0, size = Zombie.games.size(); i<size; i++) {
+ current = Zombie.games.get(i);
+ if(current.getPlayers().contains(player)) {
+ Block block = e.getClickedBlock();
+ Interactable inter = current.getInteractable(block);
+ if(inter != null) {
+ int cost = inter.getCost();
+ if(current.getPoints(player) >= cost) {
+ player.sendMessage(ChatColor.YELLOW + Zombie.lang.getProperty("game_paid").replace("%amount%", ""+cost));
+ current.substractPoints(player, cost);
+ if(inter instanceof Chest) {
+ if(Math.random() > 0.25) {
+ ItemStack item = new ItemStack((Material)Misc.random(Constants.Game.ITEMSET));
+ Enchantment ench;
+ while(!(ench = (Enchantment)Misc.random(Enchantment.values())).canEnchantItem(item));
+ item.addEnchantment(ench, 1+(new Random().nextInt(Integer.MAX_VALUE)%(ench.getMaxLevel()-1)));
+ player.getInventory().addItem(item);
+ } else {
+ player.getInventory().addItem(new ItemStack(Material.SKULL_ITEM));
+ current.randomizeChest();
+ }
+ e.setCancelled(true);
+ } else if(inter instanceof Powerup) {
+ Powerup powerup = (Powerup)inter;
+ player.getInventory().addItem(powerup.getItem());
+ } else if(inter instanceof Lever) {
+ Lever lever = (Lever)inter;
+ if(lever.isToggled()) {
+ player.sendMessage(ChatColor.RED + Zombie.lang.getProperty("game_impossible"));
+ current.addPoints(player, cost);
+ e.setCancelled(true);
+ } else {
+ lever.toggle();
+ }
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + Zombie.lang.getProperty("game_no_points").replace("%amount%", ""+cost));
+ e.setCancelled(true);
+ }
+ }
+ }
+ }
+ }
+ } catch(Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ @EventHandler
+ public void onPlayerInteractEntity(PlayerInteractEntityEvent e) {
+ Game current;
+ Player from = e.getPlayer();
+ if(e.getRightClicked() instanceof Player) {
+ Player to = (Player)e.getRightClicked();
+ for(int i = 0, size = Zombie.games.size(); i<size; i++) {
+ current = Zombie.games.get(i);
+ if(current.getPlayers().contains(from) && current.getPlayers().contains(to)) {
+ if(current.isFrozen(to)) {
+ current.revive(from, to);
+ }
+ }
+ }
+ }
+ }
+
+ @EventHandler
+ public void onEntityDeath(EntityDeathEvent e) {
+ int id = e.getEntity().getEntityId();
+ Game current;
+ for(int i = 0, size = Zombie.games.size(); i<size; i++) {
+ current = Zombie.games.get(i);
+ if(current.watchdog.contains(id)) {
+ current.addPoints(1000);
+ current.watchdog.remove((Integer)id);
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/Lobby.java b/src/main/java/com/encrox/zombie/Lobby.java new file mode 100755 index 0000000..c33c3c3 --- /dev/null +++ b/src/main/java/com/encrox/zombie/Lobby.java @@ -0,0 +1,72 @@ +package com.encrox.zombie;
+
+import java.util.ArrayList;
+
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
+
+public class Lobby {
+
+ private ArrayList<Player> players;
+ private Player creator;
+ private String identifier;
+ private Map map;
+
+ public Lobby(Player creator, String identifier, Map map) {
+ this.creator = creator;
+ this.identifier = identifier;
+ this.map = map;
+ players = new ArrayList<Player>();
+ players.add(creator);
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public Player getCreator() {
+ return creator;
+ }
+
+ public boolean containsPlayer(Player player) {
+ if(creator.equals(player)) return true;
+ return players.contains(player);
+ }
+
+ public void removePlayer(Player player) {
+ if(creator.equals(player)) {
+ for(int i = 0, size = players.size(); i<size; i++) {
+ players.get(i).sendMessage(ChatColor.YELLOW + Zombie.lang.getProperty("lobby_disbanded"));
+ }
+ Zombie.lobbies.remove(this);
+ return;
+ }
+ if(players.contains(player)) {
+ for(int i = 0, size = players.size(); i<size; i++) {
+ players.get(i).sendMessage(ChatColor.YELLOW + Zombie.lang.getProperty("lobby_left").replace("%player%", player.getName()));
+ }
+ players.remove(player);
+ }
+ }
+
+ public void addPlayer(Player player) {
+ players.add(player);
+ for(int i = 0, size = players.size(); i<size; i++) {
+ players.get(i).sendMessage(ChatColor.YELLOW + Zombie.lang.getProperty("lobby_joined").replace("%player%", player.getName()));
+ }
+ }
+
+ public int getMax() {
+ return map.getPlayers();
+ }
+
+ public int getCurrent() {
+ return players.size();
+ }
+
+ public void start() {
+ Zombie.games.add(new Game(players, map));
+ Zombie.lobbies.remove(this);
+ }
+
+}
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;
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/Misc.java b/src/main/java/com/encrox/zombie/Misc.java new file mode 100755 index 0000000..feeab8b --- /dev/null +++ b/src/main/java/com/encrox/zombie/Misc.java @@ -0,0 +1,12 @@ +package com.encrox.zombie;
+
+import java.util.Random;
+
+public class Misc {
+
+ public static Object random(Object[] arr) {
+ int rnd = new Random().nextInt(arr.length);
+ return arr[rnd];
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/Mob.java b/src/main/java/com/encrox/zombie/Mob.java new file mode 100755 index 0000000..82958a3 --- /dev/null +++ b/src/main/java/com/encrox/zombie/Mob.java @@ -0,0 +1,41 @@ +package com.encrox.zombie;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
+import org.bukkit.entity.EntityType;
+import org.bukkit.util.BlockVector;
+
+import com.encrox.zombie.interactable.Lever;
+
+public class Mob {
+
+ public EntityType type;
+ public BlockVector bv;
+ public String rounds;
+ public Lever[] levers;
+
+ public Mob(EntityType type, BlockVector bv, String rounds, Lever[] levers) {
+ this.type = type;
+ this.bv = bv;
+ this.rounds = rounds;
+ this.levers = levers;
+ }
+
+ public boolean spawn(int round) {
+ for(int i = 0; i<levers.length; i++) {
+ if(!levers[i].isToggled())
+ return false;
+ }
+ ScriptEngineManager factory = new ScriptEngineManager();
+ ScriptEngine engine = factory.getEngineByName("JavaScript");
+ try {
+ return (boolean)engine.eval(rounds.replace("%round%", ""+round));
+ } catch (ScriptException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/Schematic.java b/src/main/java/com/encrox/zombie/Schematic.java new file mode 100755 index 0000000..16d4f5b --- /dev/null +++ b/src/main/java/com/encrox/zombie/Schematic.java @@ -0,0 +1,117 @@ +/*
+ * Dynamic Schematic object
+ *
+ * Currently not supporting entities.
+ */
+
+package com.encrox.zombie;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.bukkit.Material;
+import org.jnbt.ByteArrayTag;
+import org.jnbt.CompoundTag;
+import org.jnbt.ListTag;
+import org.jnbt.NBTInputStream;
+import org.jnbt.ShortTag;
+import org.jnbt.StringTag;
+import org.jnbt.Tag;
+
+public class Schematic {
+
+ public int width, height, length, dataReadIndex, dataWriteIndex, blockReadIndex, blockWriteIndex;
+ public String materials;
+ public byte[] blocks, data;
+ public List<Tag> entities, tileEntities;
+ public File file;
+
+ public Schematic(int width, int height, int length, String materials, byte[] blocks, byte[] data, List<Tag> entities, List<Tag> tileEntities) {
+ this.width = width;
+ this.height = height;
+ this.length = length;
+ this.materials = materials;
+ this.blocks = blocks;
+ this.data = data;
+ this.entities = entities;
+ this.tileEntities = tileEntities;
+ blockReadIndex = 0;
+ blockWriteIndex = 0;
+ dataReadIndex = 0;
+ dataWriteIndex = 0;
+ }
+
+ public Schematic(File file) {
+ this.file = file;
+ CompoundTag schematicTag = null;
+ try {
+ NBTInputStream in = new NBTInputStream(new FileInputStream(file));
+ schematicTag = (CompoundTag)in.readTag();
+ in.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Map<String,Tag> schematic = schematicTag.getValue();
+ width = ((ShortTag)schematic.get("Width")).getValue();
+ height = ((ShortTag)schematic.get("Height")).getValue();
+ length = ((ShortTag)schematic.get("Length")).getValue();
+ materials = ((StringTag)schematic.get("Materials")).getValue();
+ blocks = ((ByteArrayTag)schematic.get("Blocks")).getValue();
+ data = ((ByteArrayTag)schematic.get("Data")).getValue();
+ entities = ((ListTag)schematic.get("Entities")).getValue();
+ tileEntities = ((ListTag)schematic.get("TileEntities")).getValue();
+ blockReadIndex = 0;
+ blockWriteIndex = 0;
+ dataReadIndex = 0;
+ dataWriteIndex = 0;
+ }
+
+ public byte getBlockIdAt(int x, int y, int z) {
+ return blocks[(y*length + z)*width + x];
+ }
+
+ public byte getNextBlock() {
+ return blocks[blockReadIndex++];
+ }
+
+ public byte getDataAt(int x, int y, int z) {
+ return data[(y*length + z)*width + x];
+ }
+
+ public byte getNextData() {
+ return data[dataReadIndex++];
+ }
+
+ public void setBlockIdAt(int x, int y, int z, byte blockId) {
+ blocks[(y*length + z)*width + x] = blockId;
+ }
+
+ public void setNextBlock(byte blockId) {
+ blocks[blockWriteIndex++] = blockId;
+ }
+
+ public void setDataAt(int x, int y, int z, byte newData) {
+ data[(y*length + z)*width + x] = newData;
+ }
+
+ public void setNextData(byte newData) {
+ data[dataWriteIndex++] = newData;
+ }
+
+ public void write(File file) {
+
+ }
+
+ public void reset() {
+ blockReadIndex = 0;
+ blockWriteIndex = 0;
+ dataReadIndex = 0;
+ dataWriteIndex = 0;
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/Zombie.java b/src/main/java/com/encrox/zombie/Zombie.java new file mode 100755 index 0000000..d687f6e --- /dev/null +++ b/src/main/java/com/encrox/zombie/Zombie.java @@ -0,0 +1,245 @@ +package com.encrox.zombie;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import com.sk89q.worldedit.EditSession;
+import com.sk89q.worldedit.bukkit.WorldEditPlugin;
+
+public class Zombie extends JavaPlugin {
+
+ public static Plugin plugin;
+ public static Logger logger;
+ public static PluginDescriptionFile pdf;
+ public static Properties lang;
+ public static JSONObject config;
+ public static JSONArray schematicDescriptors;
+ public static File schematicsDirectory;
+ public static WorldEditPlugin we;
+ public static ArrayList<Map> maps;
+ public static ArrayList<Lobby> lobbies;
+ public static ArrayList<Game> games;
+ public static ZombieWorld zombieWorld;
+ public static Commander commander;
+
+ public void onEnable() {
+ pdf = getDescription();
+ logger = Logger.getLogger("Minecraft");
+ if(setupMyself() && setupWorldEdit()) {
+ plugin = this;
+ commander = new Commander();
+ getCommand("zombie").setExecutor(commander);
+ logger.info(pdf.getName() + " " + pdf.getVersion() + " has been enabled.");
+ } else {
+ logger.info(pdf.getName() + " " + pdf.getVersion() + " has been disabled.");
+ }
+ }
+
+ public boolean setupWorldEdit() {
+ we = (WorldEditPlugin)Bukkit.getPluginManager().getPlugin("WorldEdit");
+ return (we != null);
+ }
+
+ public boolean setupMyself() {
+ if(!this.getDataFolder().exists())
+ this.getDataFolder().mkdirs();
+ schematicsDirectory = new File(this.getDataFolder(), "schematics");
+ if(!schematicsDirectory.exists())
+ schematicsDirectory.mkdirs();
+ File configFile = new File(this.getDataFolder(), "config.json");
+ if(!configFile.exists()) {
+ BufferedInputStream bis;
+ FileOutputStream out;
+ try {
+ bis = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("config.json"));
+ out = new FileOutputStream(configFile);
+ int current;
+ while((current = bis.read()) != -1) {
+ out.write(current);
+ }
+ bis.close();
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ BufferedReader br;
+ StringBuilder sb = new StringBuilder();
+ String line;
+ try {
+ br = new BufferedReader(new FileReader(configFile));
+ while((line = br.readLine()) != null)
+ sb.append(line);
+ br.close();
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ return false;
+ }
+ config = new JSONObject(sb.toString());
+ zombieWorld = new ZombieWorld(this, Bukkit.getWorld(config.getString("world")));
+ File schematicDescriptorFile = new File(schematicsDirectory, "descriptor.json");
+ if(!schematicDescriptorFile.exists()) {
+ int current;
+ try {
+ BufferedInputStream bis = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("descriptor.json"));
+ FileOutputStream out = new FileOutputStream(schematicDescriptorFile);
+ while((current = bis.read()) != -1) {
+ out.write(current);
+ }
+ bis.close();
+ out.close();
+ } catch(Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ try {
+ BufferedInputStream bis = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("schematics/test.schematic"));
+ FileOutputStream out = new FileOutputStream(new File(schematicsDirectory, "test.schematic"));
+ while((current = bis.read()) != -1) {
+ out.write(current);
+ }
+ bis.close();
+ out.close();
+ } catch(Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ sb = new StringBuilder();
+ try {
+ br = new BufferedReader(new FileReader(schematicDescriptorFile));
+ while((line = br.readLine()) != null)
+ sb.append(line);
+ br.close();
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ return false;
+ }
+ schematicDescriptors = new JSONArray(sb.toString());
+ lang = new Properties();
+ try {
+ //TODO
+ lang.load(getClass().getClassLoader().getResourceAsStream("lang/" + config.getString("locale") + ".properties"));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ return false;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ maps = new ArrayList<Map>();
+ lobbies = new ArrayList<Lobby>();
+ games = new ArrayList<Game>();
+ for(int i = 0, len = schematicDescriptors.length(); i<len; i++) {
+ maps.add(new Map(schematicDescriptors.getJSONObject(i)));
+ }
+ Bukkit.getPluginManager().registerEvents(new GameListener(), this);
+ return true;
+ }
+
+ public void onDisable() {
+ logger.info(pdf.getName() + " " + pdf.getVersion() + " has been disabled.");
+ }
+
+ public static String createLobby(Player creator, String identifier, String map) {
+ for(int i = 0, size = lobbies.size(); i<size; i++) {
+ if(lobbies.get(i).getIdentifier().equals(identifier)) {
+ return (ChatColor.RED + Zombie.lang.getProperty("lobby_create_identifier"));
+ }
+ if(lobbies.get(i).containsPlayer(creator)) {
+ return (ChatColor.RED + Zombie.lang.getProperty("lobby_create_membership"));
+ }
+ }
+ for(int i = 0, size = maps.size(); i<size; i++) {
+ if(maps.get(i).getName().equals(map)) {
+ lobbies.add(new Lobby(creator, identifier, maps.get(i)));
+ return (ChatColor.GREEN + Zombie.lang.getProperty("lobby_create_success"));
+ }
+ }
+ return (ChatColor.RED + Zombie.lang.getProperty("lobby_create_map"));
+ }
+
+ public static String removePlayer(Player player) {
+ for(int i = 0, size = lobbies.size(); i<size; i++) {
+ if(lobbies.get(i).containsPlayer(player)) {
+ lobbies.get(i).removePlayer(player);
+ return (ChatColor.GREEN + Zombie.lang.getProperty("lobby_leave_success"));
+ }
+ }
+ return (ChatColor.RED + Zombie.lang.getProperty("lobby_leave_membership"));
+ }
+
+ public static String joinLobby(Player player, String identifier) {
+ int size = lobbies.size();
+ Lobby current;
+ for(int i = 0; i<size; i++) {
+ current = lobbies.get(i);
+ if(current.containsPlayer(player)) {
+ current.removePlayer(player);
+ }
+ }
+ for(int i = 0; i<size; i++) {
+ current = lobbies.get(i);
+ if(current.getIdentifier().equals(identifier)) {
+ if(current.getCurrent() < current.getMax()) {
+ current.addPlayer(player);
+ return (ChatColor.GREEN + Zombie.lang.getProperty("lobby_join_success"));
+ }
+ return (ChatColor.RED + Zombie.lang.getProperty("lobby_join_full"));
+ }
+ }
+ return (ChatColor.RED + Zombie.lang.getProperty("lobby_join_identifier"));
+ }
+
+ public static String listLobbies() {
+ String out = ChatColor.WHITE + lang.getProperty("lobby_list") + "\n";
+ Lobby current;
+ for(int i = 0, size = lobbies.size(); i<size; i++) {
+ current = lobbies.get(i);
+ if(current.getCurrent() < current.getMax()) {
+ out += ChatColor.GREEN;
+ } else {
+ out += ChatColor.RED;
+ }
+ out += current.getIdentifier() + ChatColor.WHITE + ", ";
+ }
+ return out;
+ }
+
+ public static String start(Player player) {
+ Lobby current;
+ for(int i = 0, size = lobbies.size(); i<size; i++) {
+ current = lobbies.get(i);
+ if(current.getCreator().equals(player)) {
+ current.start();
+ return (ChatColor.GREEN + lang.getProperty("lobby_start_success"));
+ }
+ }
+ return (ChatColor.GREEN + lang.getProperty("lobby_start_failed"));
+ }
+
+}
\ No newline at end of file diff --git a/src/main/java/com/encrox/zombie/ZombieWorld.java b/src/main/java/com/encrox/zombie/ZombieWorld.java new file mode 100755 index 0000000..52ddea8 --- /dev/null +++ b/src/main/java/com/encrox/zombie/ZombieWorld.java @@ -0,0 +1,79 @@ +package com.encrox.zombie;
+
+import java.util.ArrayList;
+
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.plugin.Plugin;
+
+import com.encrox.instancedregions.InstancedProtectedCuboidRegion;
+import com.sk89q.worldedit.BlockVector;
+import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
+import com.sk89q.worldguard.protection.regions.ProtectedRegion;
+
+public class ZombieWorld {
+
+ private Plugin plugin;
+ private World world;
+ private ArrayList<ProtectedRegion> regions;
+ private int lastX;
+
+ public ZombieWorld(Plugin plugin, World world) {
+ this.world = world;
+ this.plugin = plugin;
+ regions = new ArrayList<ProtectedRegion>();
+ lastX = 0;
+ }
+
+ public InstancedProtectedCuboidRegion allocate(int width, int length) {
+ BlockVector min, max;
+ InstancedProtectedCuboidRegion region;
+ for(int i = 0; true; i+=16) {
+ if(new ProtectedCuboidRegion("current", (min = new BlockVector(lastX+i, 0, 0)), (max = new BlockVector(lastX+i+width, 255, length))).getIntersectingRegions(regions).isEmpty()) {
+ region = new InstancedProtectedCuboidRegion(plugin, world, ""+min.getBlockX(), min, max);
+ regions.add(region);
+ return region;
+ }
+ }
+ }
+
+ public InstancedProtectedCuboidRegion allocate(Schematic schematic) {
+ BlockVector min, max;
+ InstancedProtectedCuboidRegion region;
+ for(int i = 0; true; i+=16) {
+ if(new ProtectedCuboidRegion("current", (min = new BlockVector(lastX+i, 0, 0)), (max = new BlockVector(lastX+i+schematic.width, 255, schematic.length))).getIntersectingRegions(regions).isEmpty()) {
+ region = new InstancedProtectedCuboidRegion(plugin, world, ""+min.getBlockX(), min, max);
+ schematic.reset();
+ for(int y = 0; y<schematic.height; y++) {
+ for(int z = 0; z<schematic.length; z++) {
+ for(int x = 0; x<schematic.width; x++) {
+ //System.out.println("block set at: (" + (min.getBlockX()+x) + ", " + (64+y) + ", " + (min.getBlockZ()+z) + ")");
+ world.getBlockAt(min.getBlockX()+x, 64+y, min.getBlockZ()+z).setType(Material.getMaterial(schematic.getBlockIdAt(x, y, z)));
+ world.getBlockAt(min.getBlockX()+x, 64+y, min.getBlockZ()+z).setData(schematic.getDataAt(x, y, z));;
+ }
+ }
+ }
+ regions.add(region);
+ return region;
+ }
+ }
+ }
+
+ //YOU STILL HAVE TO DISPOSE THE INSTANCED REGION MANUALLY!
+ public void deallocate(InstancedProtectedCuboidRegion region) {
+ BlockVector min = region.getMinimumPoint(), max = region.getMaximumPoint();
+ for(int y = min.getBlockY(), ymax = max.getBlockY(); y<ymax; y++) {
+ for(int z = min.getBlockZ(), zmax = max.getBlockZ(); z<zmax; z++) {
+ for(int x = min.getBlockX(), xmax = max.getBlockX(); x<xmax; x++) {
+ world.getBlockAt(x, y, z).setType(Material.AIR);
+ }
+ }
+ }
+ regions.remove(region);
+ }
+
+ public World getWorld() {
+ return world;
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/interactable/Chest.java b/src/main/java/com/encrox/zombie/interactable/Chest.java new file mode 100755 index 0000000..10045a2 --- /dev/null +++ b/src/main/java/com/encrox/zombie/interactable/Chest.java @@ -0,0 +1,27 @@ +package com.encrox.zombie.interactable;
+
+import org.bukkit.block.BlockFace;
+import org.bukkit.util.BlockVector;
+
+public class Chest extends Interactable {
+
+ private BlockFace facing;
+
+ public Chest(BlockVector bv, int cost, BlockFace facing) {
+ super(bv, cost);
+ this.facing = facing;
+ }
+
+ public Chest(BlockVector bv, int cost, String facing) {
+ this(bv, cost, BlockFace.valueOf(facing));
+ }
+
+ public Chest(BlockVector bv, int cost) {
+ this(bv, cost, BlockFace.NORTH);
+ }
+
+ public BlockFace getFacing() {
+ return facing;
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/interactable/Interactable.java b/src/main/java/com/encrox/zombie/interactable/Interactable.java new file mode 100755 index 0000000..9bc4dc3 --- /dev/null +++ b/src/main/java/com/encrox/zombie/interactable/Interactable.java @@ -0,0 +1,23 @@ +package com.encrox.zombie.interactable;
+
+import org.bukkit.util.BlockVector;
+
+public abstract class Interactable {
+
+ private BlockVector bv;
+ private int cost;
+
+ public Interactable(BlockVector bv, int cost) {
+ this.bv = bv;
+ this.cost = cost;
+ }
+
+ public int getCost() {
+ return cost;
+ }
+
+ public BlockVector getBlockVector() {
+ return bv;
+ }
+
+}
diff --git a/src/main/java/com/encrox/zombie/interactable/Lever.java b/src/main/java/com/encrox/zombie/interactable/Lever.java new file mode 100755 index 0000000..4776f39 --- /dev/null +++ b/src/main/java/com/encrox/zombie/interactable/Lever.java @@ -0,0 +1,38 @@ +package com.encrox.zombie.interactable;
+
+import org.bukkit.util.BlockVector;
+
+public class Lever extends Interactable {
+
+ private boolean toggle;
+ private Lever[] others;
+
+ public Lever(BlockVector bv, int cost, boolean toggle, Lever[] others) {
+ super(bv, cost);
+ this.toggle = toggle;
+ this.others = others;
+ }
+
+ public Lever(BlockVector bv, int cost, Lever[] others) {
+ this(bv, cost, false, others);
+ }
+
+ public Lever(BlockVector bv, int cost, boolean toggle) {
+ this(bv, cost, toggle, new Lever[0]);
+ }
+
+ public Lever(BlockVector bv, int cost) {
+ this(bv, cost, false);
+ }
+
+ public void toggle() {
+ toggle = !toggle;
+ for(int i = 0; i<others.length; i++)
+ others[i].toggle();
+ }
+
+ public boolean isToggled() {
+ return toggle;
+ }
+
+}
\ No newline at end of file diff --git a/src/main/java/com/encrox/zombie/interactable/Powerup.java b/src/main/java/com/encrox/zombie/interactable/Powerup.java new file mode 100755 index 0000000..e1ca0d2 --- /dev/null +++ b/src/main/java/com/encrox/zombie/interactable/Powerup.java @@ -0,0 +1,22 @@ +package com.encrox.zombie.interactable;
+
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.util.BlockVector;
+
+public class Powerup extends Interactable {
+
+ private ItemStack item;
+
+ public Powerup(BlockVector bv, ItemStack item, int cost) {
+ super(bv, cost);
+ this.item = item;
+ }
+
+ public ItemStack getItem() {
+ return item;
+ }
+
+}
|