Java Code Examples for org.bukkit.block.Block#getType()

The following examples show how to use org.bukkit.block.Block#getType() . 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: FallingBlocksMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Return the number of unsupported blocks connected to any blocks neighboring the given location.
 * An air block is placed there temporarily if it is not already air. The search may bail out
 * early when the count is >= the given limit, though this cannot be guaranteed.
 */
public int countUnsupportedNeighbors(Block block, int limit) {
  BlockState state = null;
  if (block.getType() != Material.AIR) {
    state = block.getState();
    block.setTypeIdAndData(0, (byte) 0, false);
  }

  int count = countUnsupportedNeighbors(encodePos(block), limit);

  if (state != null) {
    block.setTypeIdAndData(state.getTypeId(), state.getRawData(), false);
  }

  return count;
}
 
Example 2
Source File: AncientAltarListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
    if (altar == null || altar.isDisabled()) {
        return;
    }

    Block pedestal = e.getBlockPlaced().getRelative(BlockFace.DOWN);

    if (pedestal.getType() == Material.DISPENSER) {
        String id = BlockStorage.checkID(pedestal);

        if (id != null && id.equals(SlimefunItems.ANCIENT_PEDESTAL.getItemId())) {
            SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "messages.cannot-place", true);
            e.setCancelled(true);
        }
    }
}
 
Example 3
Source File: HuntEffect.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
public static Location findNearbyLocationForTeleport(Location location, int radius, Player player) {
    int times = 0;
    Block targetBlock;
    do {
        times++;
        int xRadius = (int) (Math.random()*radius);
        if (Math.random() > .5) {
            xRadius = xRadius *-1;
        }
        int x = location.getBlockX() + xRadius;
        int zRadius = (int) ((Math.sqrt(radius*radius - xRadius*xRadius)));
        if (Math.random() > .5) {
            zRadius = zRadius *-1;
        }
        int z = location.getBlockZ() + zRadius;
        targetBlock = location.getWorld().getHighestBlockAt(x, z);
    } while (times < 5 && (targetBlock.getType() == Material.LAVA));

    if (times == 5) {
        return null;
    }


    return targetBlock.getLocation();
}
 
Example 4
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPrimeTNT(ExplosionPrimeEvent event) {
  if (event.getEntity() instanceof TNTPrimed) {
    Block block = event.getEntity().getLocation().getBlock();
    if (block.getType() == Material.TNT) {
      ParticipantState player;
      if (event instanceof ExplosionPrimeByEntityEvent) {
        player = Trackers.getOwner(((ExplosionPrimeByEntityEvent) event).getPrimer());
      } else {
        player = null;
      }
      callEvent(event, block.getState(), BlockStates.toAir(block), player);
    }
  }
}
 
Example 5
Source File: WarRegen.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public static void destroyThisBlock(Block blk, Town town) {
	
	WarRegen.saveBlock(blk, town.getName(), false);
			
	switch (blk.getType()) {
	case TRAPPED_CHEST:
		((Chest)blk.getState()).getBlockInventory().clear();
		break;
	case CHEST:
		((Chest)blk.getState()).getBlockInventory().clear();
		break;
	case DISPENSER:
		((Dispenser)blk.getState()).getInventory().clear();
		break;
	case BURNING_FURNACE:
	case FURNACE:
		((Furnace)blk.getState()).getInventory().clear();
		break;
	case DROPPER:
		((Dropper)blk.getState()).getInventory().clear();
		break;
	case HOPPER:
		((Hopper)blk.getState()).getInventory().clear();
		break;
	default:
		break;
	}
	
	ItemManager.setTypeId(blk, CivData.AIR);
	ItemManager.setData(blk, 0x0, true);
	
}
 
Example 6
Source File: WrappedBlock7.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
private boolean isReallySolid(Block b) {
    boolean reallySolid = block.getMaterial().isSolid();
    if (b.getType() == Material.CARPET || b.getType() == Material.WATER_LILY) {
        reallySolid = true;
    }
    return reallySolid;
}
 
Example 7
Source File: Transporter.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true)
public void TeleporterProtect(BlockBreakEvent event)
{
	Player player = event.getPlayer();
	Block b = event.getBlock();
	if(b.getType() == Material.QUARTZ_ORE)
	{
		event.setCancelled(true);
		AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
		if(p != null)
		{
			UUID owner = getBlocksOwner(b);
			if(owner == null)
				return;
			
			Teleporter tele = teleporters.get(owner);
			if(p.getID().equals(owner))
			{
				tele.clear();
			}
			else if(p.getTeam() != tele.getOwner().getTeam())
			{
				tele.clear();
				tele.getOwner().sendMessage(ChatColor.AQUA+"Your teleporter was broken by "+p.getTeam().getColor()+p.getName());
			}
		}
	}
}
 
Example 8
Source File: CutCleanListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent e){

    if (isActivated(Scenario.TRIPLEORES) || (isActivated(Scenario.VEINMINER) && e.getPlayer().isSneaking())){
        return;
    }

    Block block = e.getBlock();

    if (checkTool && !UniversalMaterial.isCorrectTool(block.getType(), e.getPlayer().getItemInHand().getType())){
        return;
    }

    Location loc = e.getBlock().getLocation().add(0.5, 0, 0.5);

    switch (block.getType()){
        case IRON_ORE:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc,new ItemStack(Material.IRON_INGOT));
            UhcItems.spawnExtraXp(loc,2);
            break;
        case GOLD_ORE:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc,new ItemStack(Material.GOLD_INGOT));
            if (isActivated(Scenario.DOUBLEGOLD)){
                loc.getWorld().dropItem(loc,new ItemStack(Material.GOLD_INGOT));
            }
            UhcItems.spawnExtraXp(loc,3);
            break;
        case SAND:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc,new ItemStack(Material.GLASS));
            break;
        case GRAVEL:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc,new ItemStack(Material.FLINT));
            break;
    }
}
 
Example 9
Source File: Flag.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean canDropAt(Location location) {
  Block block = location.getBlock();
  Block below = block.getRelative(BlockFace.DOWN);
  if (!canDropOn(below.getState())) return false;
  if (block.getRelative(BlockFace.UP).getType() != Material.AIR) return false;

  switch (block.getType()) {
    case AIR:
    case LONG_GRASS:
      return true;
    default:
      return false;
  }
}
 
Example 10
Source File: MailboxListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onRightClickChest(PlayerInteractEvent ev) {
    if (callbackMap.containsKey(ev.getPlayer()) && ev.hasBlock() && ev.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Block b = ev.getClickedBlock();
        if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
            callbackMap.remove(ev.getPlayer()).accept(b.getLocation());
            if (timeoutListener.containsKey(ev.getPlayer()))
                timeoutListener.remove(ev.getPlayer()).cancel();
            ev.setCancelled(true);
        }
    }

}
 
Example 11
Source File: ExprSpawnerType.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public EntityData convert(final Block b) {
	if (b.getType() != MATERIAL_SPAWNER)
		return null;
	return toSkriptEntityData(((CreatureSpawner) b.getState()).getSpawnedType());
}
 
Example 12
Source File: CommandNBTTile.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected TileNBTWrapper getWrapper(Player player) throws MyCommandException {
	Block block = UtilsMc.getTargetBlock(player, 5);
	if (block.getType() == Material.AIR) {
		throw new MyCommandException("§cNo tile in sight!");
	}
	try {
		if (block.getType() == Material.SPAWNER) {
			return new SpawnerNBTWrapper(block);
		}
		return new TileNBTWrapper(block);
	} catch (RuntimeException e) {
		throw new MyCommandException("§cCannot edit that tile!");
	}
}
 
Example 13
Source File: SlimefunBootsListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onTrample(PlayerInteractEvent e) {
    if (e.getAction() == Action.PHYSICAL) {
        Block b = e.getClickedBlock();

        if (b != null && b.getType() == Material.FARMLAND) {
            ItemStack boots = e.getPlayer().getInventory().getBoots();

            if (SlimefunUtils.isItemSimilar(boots, SlimefunItems.FARMER_SHOES, true) && Slimefun.hasUnlocked(e.getPlayer(), boots, true)) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example 14
Source File: Gunnergoal.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
private boolean inLineOfSight(Entity target, boolean setTargetNullifSolid) {
	double diste = target.getLocation().distance(npc.getEntity().getLocation());
	if (!npc.isSpawned())
		return false;
	if (npc.getEntity() == null)
		return false;
	try {
		Block btemp = ((Player) npc.getEntity()).getTargetBlock(null, (int) diste);
		if (btemp == null || btemp.getType() == Material.AIR) {
			return true;
		}
	} catch (Error | Exception e4) {
	}
	Location test = ((Player) npc.getEntity()).getEyeLocation().clone();
	int stepi = 4;
	Vector step = npc.getEntity().getLocation().getDirection().normalize().multiply(1.0 / stepi);
	/*for (int dist = 0; dist < diste * stepi; dist++) {
		test.add(step);
		if (BoundingBoxUtil.closeEnough(target, test)) {
			break;
		}
		boolean solid = GunUtil.isSolid(test.getBlock(), test);
		if (solid /* || GunUtil.isBreakable(test.getBlock(), test) * /) {
			if (setTargetNullifSolid)
				target = null;
			return false;
		}
	}*/

	return true;
}
 
Example 15
Source File: CraftingProtect.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void cloneCraftingWindow(final PlayerInteractEvent event) {
    if(!AntiGrief.CraftProtect.enabled()) {
        return;
    }

    if(!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getPlayer().getOpenInventory().getType() == InventoryType.CRAFTING /* nothing open */) {
        Block block = event.getClickedBlock();
        if(block != null && block.getType() == Material.WORKBENCH && !event.getPlayer().isSneaking()) {
            // create the window ourself
            event.setCancelled(true);
            event.getPlayer().openWorkbench(null, true); // doesn't check reachable
        }
    }
}
 
Example 16
Source File: TutorialListener.java    From ServerTutorial with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    String name = player.getName();
    if (event.getAction() != Action.PHYSICAL) {
        if (TutorialManager.getManager().isInTutorial(name) && TutorialManager.getManager().getCurrentTutorial
                (name).getViewType() != ViewType.TIME) {
            if (TutorialManager.getManager().getCurrentTutorial(name).getTotalViews() == TutorialManager
                    .getManager().getCurrentView(name)) {
                plugin.getEndTutorial().endTutorial(player);
            } else {
                plugin.incrementCurrentView(name);
                TutorialUtils.getTutorialUtils().messageUtils(player);
                Caching.getCaching().setTeleport(player, true);
                player.teleport(TutorialManager.getManager().getTutorialView(name).getLocation());
            }
        }
    }
    if ((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) &&
            !TutorialManager.getManager().isInTutorial(name)) {
        Block block = event.getClickedBlock();
        if (block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN) {
            Sign sign = (Sign) block.getState();
            String match = ChatColor.stripColor(TutorialUtils.color(TutorialManager.getManager().getConfigs()
                    .signSetting()));
            if (sign.getLine(0).equalsIgnoreCase(match) && sign.getLine(1) != null) {
                plugin.startTutorial(sign.getLine(1), player);
            }
        }
    }
}
 
Example 17
Source File: Region.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public static RegionPoints hasRequiredBlocks(String type, Location location, boolean useCivItem) {
    ItemManager itemManager = ItemManager.getInstance();
    RegionType regionType = (RegionType) itemManager.getItemType(type);
    List<HashMap<Material, Integer>> itemCheck = cloneReqMap(regionType.getReqs());

    RegionPoints radii = new RegionPoints(0, 0, 0, 0, 0, 0);
    if (itemCheck.isEmpty()) {
        radiusCheck(radii, regionType);
        return radii;
    }

    World currentWorld = location.getWorld();
    int biggestXZRadius = Math.max(regionType.getBuildRadiusX(), regionType.getBuildRadiusZ());
    double xMax = location.getX() + biggestXZRadius * 1.5;
    double xMin = location.getX() - biggestXZRadius * 1.5;
    double yMax = location.getY() + regionType.getBuildRadiusY() * 1.5;
    double yMin = location.getY() - regionType.getBuildRadiusY() * 1.5;
    double zMax = location.getZ() + biggestXZRadius * 1.5;
    double zMin = location.getZ() - biggestXZRadius * 1.5;

    yMax = yMax > currentWorld.getMaxHeight() ? currentWorld.getMaxHeight() : yMax;
    yMin = yMin < 0 ? 0 : yMin;

    radii = addItemCheck(radii, location, currentWorld, xMin, xMax, yMin, yMax, zMin, zMax,
            itemCheck, regionType);
    boolean hasReqs = itemCheck.isEmpty();
    if (itemCheck.isEmpty() && useCivItem) {
        Block centerBlock = location.getBlock();
        if (regionType.getMat() != centerBlock.getType()) {
            hasReqs = false;
        }
    }

    if (!hasReqs) {
        radii.setValid(false);
    }
    return radii;
}
 
Example 18
Source File: WarRegen.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
private static String blockToString(Block blk, boolean save_as_air) {
	if (save_as_air) { 
		return blockAsAir(blk);
	}
	else {
		String str = blockBasicString(blk);
		
		Inventory inv = null;
		switch (blk.getType()) {
		case TRAPPED_CHEST:
		case CHEST:
			inv = ((Chest)blk.getState()).getBlockInventory();
			str += blockInventoryString(inv);
			break;
		case DISPENSER:
			inv = ((Dispenser)blk.getState()).getInventory();
			str += blockInventoryString(inv);
			break;
		case BURNING_FURNACE:
		case FURNACE:
			inv = ((Furnace)blk.getState()).getInventory();
			str += blockInventoryString(inv);
			break;
		case DROPPER:
			inv = ((Dropper)blk.getState()).getInventory();
			str += blockInventoryString(inv);
			break;
		case HOPPER:
			inv = ((Hopper)blk.getState()).getInventory();
			str += blockInventoryString(inv);
			break;
		case SIGN:
		case SIGN_POST:
		case WALL_SIGN:
			Sign sign = (Sign)blk.getState();
			str += blockSignString(sign);
			break;
		default:
			break;
		}
		
		return str;
	}
}
 
Example 19
Source File: RescuePlatform.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void createPlatform(boolean bre, int time, int dist, Material bMat) {
    canBreak = bre;
    breakingTime = time;
    buildingMaterial = bMat;
    platformBlocks = new ArrayList<>();

    Location center = player.getLocation().clone();
    center.setY(center.getY() - dist);

    for (BlockFace blockFace : BlockFace.values()) {
        if (blockFace.equals(BlockFace.DOWN) || blockFace.equals(BlockFace.UP)) {
            continue;
        }

        Block placedBlock = center.getBlock().getRelative(blockFace);
        if (placedBlock.getType() != Material.AIR) {
            continue;
        }

        ItemStack coloredStack = Main.applyColor(
                TeamColor.fromApiColor(team.getColor()), new ItemStack(buildingMaterial));
        if (Main.isLegacy()) {
            placedBlock.setType(coloredStack.getType());
            try {
                // The method is no longer in API, but in legacy versions exists
                Block.class.getMethod("setData", byte.class).invoke(placedBlock, (byte) coloredStack.getDurability());
            } catch (Exception e) {
            }
        } else {
            placedBlock.setType(coloredStack.getType());
        }
        addBlockToList(placedBlock);
    }

    if (breakingTime > 0) {
        game.registerSpecialItem(this);
        runTask();

        MiscUtils.sendActionBarMessage(player, i18nonly("specials_rescue_platform_created").replace("%time%", Integer.toString(breakingTime)));

        item.setAmount(item.getAmount() - 1);
        if (item.getAmount() > 1) {
    		item.setAmount(item.getAmount() - 1);
    	} else {
    		player.getInventory().remove(item);
    	}
        player.updateInventory();
    } else {
        game.registerSpecialItem(this);

        MiscUtils.sendActionBarMessage(player, i18nonly("specials_rescue_platform_created_unbreakable"));
        item.setAmount(item.getAmount() - 1);
        if (item.getAmount() > 1) {
    		item.setAmount(item.getAmount() - 1);
    	} else {
    		player.getInventory().remove(item);
    	}
        player.updateInventory();
    }
}
 
Example 20
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockPlaceEvent event!");

    Player p = e.getPlayer();
    Block b = e.getBlockPlaced();
    World w = p.getWorld();
    Material m = e.getItemInHand().getType();

    boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper;
    Region r = RedProtect.get().rm.getTopRegion(b.getLocation());

    if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass") && antih &&
            (m.equals(Material.HOPPER) || m.name().contains("RAIL"))) {
        int x = b.getX();
        int y = b.getY();
        int z = b.getZ();
        Block ib = w.getBlockAt(x, y + 1, z);
        if (!cont.canBreak(p, ib) || !cont.canBreak(p, b)) {
            RedProtect.get().lang.sendMessage(p, "blocklistener.container.chestinside");
            e.setCancelled(true);
            return;
        }
    }

    if (r == null && canPlaceList(p.getWorld(), b.getType().name())) {
        return;
    }

    if (r != null) {

        if (!r.canMinecart(p) && (m.name().contains("MINECART") || m.name().contains("BOAT"))) {
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace");
            e.setCancelled(true);
            return;
        }

        if ((b.getType().name().equals("MOB_SPAWNER") || b.getType().name().equals("SPAWNER")) && r.canPlaceSpawner(p)) {
            return;
        }

        if ((m.name().contains("_HOE") || r.canCrops(b)) && r.canCrops()) {
            return;
        }

        Material type = b.getType();
        if (!r.blockTransform() && type.isBlock() && (
                type.name().contains("SNOW") ||
                        type.name().contains("ICE") ||
                        type.name().contains("CORAL") ||
                        type.name().contains("POWDER"))) {
            b.setType(m);
        }

        if (!r.canBuild(p) && !r.canPlace(b.getType())) {
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild");
            e.setCancelled(true);
        }
    }
}