org.bukkit.block.Beacon Java Examples

The following examples show how to use org.bukkit.block.Beacon. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GameMap.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
private void ChunkIterator(boolean message, Player sender) {
	World chunkWorld;
	chunkWorld = SkyWarsReloaded.get().getServer().getWorld(name);
	int mapSize = SkyWarsReloaded.getCfg().getMaxMapSize();
	int max1 = mapSize/2;
	int min1 = -mapSize/2;
	Block min = chunkWorld.getBlockAt(min1, 0, min1);
	Block max = chunkWorld.getBlockAt(max1, 0, max1);
	Chunk cMin = min.getChunk();
	Chunk cMax = max.getChunk();
	teamCards.clear();
	chests.clear();
	
	for(int cx = cMin.getX(); cx < cMax.getX(); cx++) {
		for(int cz = cMin.getZ(); cz < cMax.getZ(); cz++) {
	           Chunk currentChunk = chunkWorld.getChunkAt(cx, cz);
	           currentChunk.load(true);

	           for(BlockState te : currentChunk.getTileEntities()) {
	               	if(te instanceof Beacon){
		                  Beacon beacon = (Beacon) te;
		                  Block block = beacon.getBlock().getRelative(0, -1, 0);
		                  if(!block.getType().equals(Material.GOLD_BLOCK) && !block.getType().equals(Material.IRON_BLOCK) 
		                		  && !block.getType().equals(Material.DIAMOND_BLOCK)&& !block.getType().equals(Material.EMERALD_BLOCK)) {
			                  Location loc = beacon.getLocation();
			                  addTeamCard(loc);
			                  if (message) {
			                  	sender.sendMessage(new Messaging.MessageFormatter().setVariable("num", "" + getMaxPlayers()).setVariable("mapname", getDisplayName()).format("maps.addSpawn"));
							  }
		                  }
		            } else if (te instanceof Chest) {
						Chest chest = (Chest) te;
						addChest(chest, ChestPlacementType.NORMAL);
						if (message) {
							sender.sendMessage(new Messaging.MessageFormatter().setVariable("mapname", getDisplayName()).format("maps.addChest"));
						}
		            } 
	           }
	        }
     }
}
 
Example #2
Source File: ObserverModule.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onInteraction(PlayerInteractEvent event) {
    if (testObserver(event.getPlayer())) {
        event.setCancelled(true);
        if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && (event.getPlayer().getInventory().getItemInMainHand() != null && event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.WRITTEN_BOOK))){
            event.setUseInteractedBlock(Event.Result.DENY);
            event.setUseItemInHand(Event.Result.ALLOW);
        }
        if (event.getClickedBlock() != null && !event.getPlayer().isSneaking() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if (event.getClickedBlock().getType().equals(Material.CHEST) || event.getClickedBlock().getType().equals(Material.TRAPPED_CHEST)) {
                Inventory chest = Bukkit.createInventory(null, ((Chest) event.getClickedBlock().getState()).getInventory().getSize());
                for (int i = 0; i < ((Chest) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    chest.setItem(i, ((Chest) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(chest);
            }
            if (event.getClickedBlock().getType().equals(Material.FURNACE) || event.getClickedBlock().getType().equals(Material.BURNING_FURNACE)) {
                Inventory furnace = Bukkit.createInventory(null, InventoryType.FURNACE);
                for (int i = 0; i < ((Furnace) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    furnace.setItem(i, ((Furnace) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(furnace);
            }
            if (event.getClickedBlock().getType().equals(Material.DISPENSER)) {
                Inventory dispenser = Bukkit.createInventory(null, InventoryType.DISPENSER);
                for (int i = 0; i < ((Dispenser) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    dispenser.setItem(i, ((Dispenser) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(dispenser);
            }
            if (event.getClickedBlock().getType().equals(Material.DROPPER)) {
                Inventory dropper = Bukkit.createInventory(null, InventoryType.DROPPER);
                for (int i = 0; i < ((Dropper) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    dropper.setItem(i, ((Dropper) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(dropper);
            }
            if (event.getClickedBlock().getType().equals(Material.HOPPER)) {
                Inventory hopper = Bukkit.createInventory(null, InventoryType.HOPPER);
                for (int i = 0; i < ((Hopper) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    hopper.setItem(i, ((Hopper) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(hopper);
            }
            if (event.getClickedBlock().getType().equals(Material.BREWING_STAND)) {
                Inventory brewingStand = Bukkit.createInventory(null, InventoryType.BREWING);
                for (int i = 0; i < ((BrewingStand) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    brewingStand.setItem(i, ((BrewingStand) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(brewingStand);
            }
            if (event.getClickedBlock().getType().equals(Material.BEACON)) {
                Inventory beacon = Bukkit.createInventory(null, InventoryType.BEACON);
                for (int i = 0; i < ((Beacon) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    beacon.setItem(i, ((Beacon) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(beacon);
            }
        }
    }
}