Advertisement
ZP4RKER

Untitled

Sep 19th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. package zplugin.znexusfactions.listeners;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.Material;
  5. import org.bukkit.block.Block;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.event.EventHandler;
  8. import org.bukkit.event.Listener;
  9. import org.bukkit.event.block.BlockPlaceEvent;
  10. import org.bukkit.inventory.ItemStack;
  11. import org.bukkit.inventory.meta.ItemMeta;
  12. import zplugin.znexusfactions.api.Nexus;
  13. import zplugin.znexusfactions.api.Vault;
  14. import zplugin.znexusfactions.zNexusFactions;
  15.  
  16. import java.util.HashMap;
  17.  
  18. public class BlockPlaceListener implements Listener {
  19.  
  20. private zNexusFactions plugin;
  21.  
  22. public BlockPlaceListener(zNexusFactions plugin) {
  23. this.plugin = plugin;
  24. }
  25.  
  26. @EventHandler
  27. public void onBlockPlace(BlockPlaceEvent event) {
  28.  
  29. if (isNexus(event.getBlock(), event.getPlayer())) {
  30.  
  31. Location block = event.getBlock().getLocation();
  32.  
  33. // Nexus Generation
  34. block.getBlock().setType(Material.AIR);
  35.  
  36. Nexus nexus = new Nexus(block);
  37. Vault vault = nexus.createVault(event.getPlayer());
  38.  
  39. } else {
  40. ItemStack stack = new ItemStack(Material.EMERALD_BLOCK);
  41. ItemMeta meta = stack.getItemMeta();
  42. meta.setDisplayName("§5Nexus");
  43. stack.setItemMeta(meta);
  44. event.getPlayer().getInventory().addItem(stack);
  45. }
  46.  
  47. }
  48.  
  49. public boolean isNexus(Block block, Player player) {
  50. return (block.getType() == Material.EMERALD_BLOCK &&
  51. player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§5Nexus"));
  52. }
  53.  
  54. }
  55.  
  56.  
  57. package zplugin.znexusfactions.api;
  58.  
  59. import org.bukkit.Bukkit;
  60. import org.bukkit.Location;
  61. import org.bukkit.Material;
  62. import org.bukkit.entity.EntityType;
  63. import org.bukkit.entity.Player;
  64. import org.bukkit.plugin.Plugin;
  65.  
  66. import java.util.ArrayList;
  67. import java.util.List;
  68.  
  69. public class Nexus {
  70.  
  71. private Location nexus;
  72. public boolean hasVault;
  73. private Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("zNexusFactions");
  74. public int createVault;
  75.  
  76. public Nexus(Location nexus) {
  77. this.nexus = nexus;
  78. }
  79.  
  80. public Location getNexus() {
  81. return nexus;
  82. }
  83.  
  84. public Vault createVault(Player player) {
  85.  
  86. if (!hasVault) {
  87.  
  88. List<Location> wholeVault = new ArrayList<>();
  89. final List<Location> vault = new ArrayList<>();
  90.  
  91. int maxX, maxZ, maxY, minX, minY, minZ;
  92. maxX = nexus.getBlockX() + 3;
  93. maxZ = nexus.getBlockZ() + 3;
  94. maxY = nexus.getBlockY() + 3;
  95.  
  96. for (minX = nexus.getBlockX() - 3; minX <= maxX; minX++) {
  97. for (minY = nexus.getBlockY() - 1; minY <= maxY; minY++) {
  98. for (minZ = nexus.getBlockZ() - 3; minZ <= maxZ; minZ++) {
  99. wholeVault.add(new Location(nexus.getWorld(), minX, minY, minZ));
  100. }
  101. }
  102. }
  103.  
  104. for (Location loc : wholeVault) {
  105. vault.add(loc);
  106. }
  107.  
  108. maxX -= 1;
  109. maxY -= 1;
  110. maxZ -= 1;
  111.  
  112. for (minX = nexus.getBlockX() - 2; minX <= maxX; minX++) {
  113. for (minY = nexus.getBlockY(); minY <= maxY; minY++) {
  114. for (minZ = nexus.getBlockZ() - 2; minZ <= maxZ; minZ++) {
  115. vault.remove(new Location(nexus.getWorld(), minX, minY, minZ));
  116. }
  117. }
  118. }
  119.  
  120. // Door Ways
  121. vault.remove(nexus.clone().add(3, 0, 0));
  122. vault.remove(nexus.clone().add(3, 1, 0));
  123. vault.remove(nexus.clone().add(-3, 0, 0));
  124. vault.remove(nexus.clone().add(-3, 1, 0));
  125. vault.remove(nexus.clone().add(0, 0, 3));
  126. vault.remove(nexus.clone().add(0, 1, 3));
  127. vault.remove(nexus.clone().add(0, 0, -3));
  128. vault.remove(nexus.clone().add(0, 1, -3));
  129.  
  130. for (int i = 0; i < vault.size(); i++) {
  131. final int I = i;
  132. createVault = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
  133. public void run() {
  134. vault.get(I).getBlock().setType(Material.STONE);
  135. if (I + 1 == vault.size()) {
  136. player.sendMessage("§5Nexus §6created!");
  137. cancelTask();
  138. }
  139. }
  140. }, i * 1, 0);
  141. }
  142.  
  143. nexus.getWorld().spawnEntity(nexus.clone().add(.5, .75, .5), EntityType.ENDER_CRYSTAL);
  144.  
  145. return new Vault(this, wholeVault);
  146.  
  147. }
  148.  
  149. return null;
  150.  
  151. }
  152.  
  153. private void cancelTask() {
  154. Bukkit.getScheduler().cancelTask(createVault);
  155. }
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement