Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zplugin.znexusfactions.listeners;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockPlaceEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import zplugin.znexusfactions.api.Nexus;
- import zplugin.znexusfactions.api.Vault;
- import zplugin.znexusfactions.zNexusFactions;
- import java.util.HashMap;
- public class BlockPlaceListener implements Listener {
- private zNexusFactions plugin;
- public BlockPlaceListener(zNexusFactions plugin) {
- this.plugin = plugin;
- }
- @EventHandler
- public void onBlockPlace(BlockPlaceEvent event) {
- if (isNexus(event.getBlock(), event.getPlayer())) {
- Location block = event.getBlock().getLocation();
- // Nexus Generation
- block.getBlock().setType(Material.AIR);
- Nexus nexus = new Nexus(block);
- Vault vault = nexus.createVault(event.getPlayer());
- } else {
- ItemStack stack = new ItemStack(Material.EMERALD_BLOCK);
- ItemMeta meta = stack.getItemMeta();
- meta.setDisplayName("§5Nexus");
- stack.setItemMeta(meta);
- event.getPlayer().getInventory().addItem(stack);
- }
- }
- public boolean isNexus(Block block, Player player) {
- return (block.getType() == Material.EMERALD_BLOCK &&
- player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§5Nexus"));
- }
- }
- package zplugin.znexusfactions.api;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.Plugin;
- import java.util.ArrayList;
- import java.util.List;
- public class Nexus {
- private Location nexus;
- public boolean hasVault;
- private Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("zNexusFactions");
- public int createVault;
- public Nexus(Location nexus) {
- this.nexus = nexus;
- }
- public Location getNexus() {
- return nexus;
- }
- public Vault createVault(Player player) {
- if (!hasVault) {
- List<Location> wholeVault = new ArrayList<>();
- final List<Location> vault = new ArrayList<>();
- int maxX, maxZ, maxY, minX, minY, minZ;
- maxX = nexus.getBlockX() + 3;
- maxZ = nexus.getBlockZ() + 3;
- maxY = nexus.getBlockY() + 3;
- for (minX = nexus.getBlockX() - 3; minX <= maxX; minX++) {
- for (minY = nexus.getBlockY() - 1; minY <= maxY; minY++) {
- for (minZ = nexus.getBlockZ() - 3; minZ <= maxZ; minZ++) {
- wholeVault.add(new Location(nexus.getWorld(), minX, minY, minZ));
- }
- }
- }
- for (Location loc : wholeVault) {
- vault.add(loc);
- }
- maxX -= 1;
- maxY -= 1;
- maxZ -= 1;
- for (minX = nexus.getBlockX() - 2; minX <= maxX; minX++) {
- for (minY = nexus.getBlockY(); minY <= maxY; minY++) {
- for (minZ = nexus.getBlockZ() - 2; minZ <= maxZ; minZ++) {
- vault.remove(new Location(nexus.getWorld(), minX, minY, minZ));
- }
- }
- }
- // Door Ways
- vault.remove(nexus.clone().add(3, 0, 0));
- vault.remove(nexus.clone().add(3, 1, 0));
- vault.remove(nexus.clone().add(-3, 0, 0));
- vault.remove(nexus.clone().add(-3, 1, 0));
- vault.remove(nexus.clone().add(0, 0, 3));
- vault.remove(nexus.clone().add(0, 1, 3));
- vault.remove(nexus.clone().add(0, 0, -3));
- vault.remove(nexus.clone().add(0, 1, -3));
- for (int i = 0; i < vault.size(); i++) {
- final int I = i;
- createVault = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
- public void run() {
- vault.get(I).getBlock().setType(Material.STONE);
- if (I + 1 == vault.size()) {
- player.sendMessage("§5Nexus §6created!");
- cancelTask();
- }
- }
- }, i * 1, 0);
- }
- nexus.getWorld().spawnEntity(nexus.clone().add(.5, .75, .5), EntityType.ENDER_CRYSTAL);
- return new Vault(this, wholeVault);
- }
- return null;
- }
- private void cancelTask() {
- Bukkit.getScheduler().cancelTask(createVault);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement