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

The following examples show how to use org.bukkit.block.Block#hasMetadata() . 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: CEListener.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void BlockBreakEvent(BlockBreakEvent e) {

    if (e.getBlock().hasMetadata("ce.Ice"))
        e.setCancelled(true);

    CEventHandler.handleEvent(e.getPlayer(), e, blockBroken);
    if (e.getBlock().hasMetadata("ce.mine")) {
        Block b = e.getBlock();
        b.removeMetadata("ce.mine", Main.plugin);
        Block[] blocks = { b.getRelative(0, 1, 0), b.getRelative(1, 0, 0), b.getRelative(-1, 0, 0), b.getRelative(0, 0, 1), b.getRelative(0, 0, -1) };

        for (Block block : blocks) {
            if (block.hasMetadata("ce.mine.secondary")) {
                String[] s = block.getMetadata("ce.mine.secondary").get(0).asString().split(" ");
                Location loc = new Location(e.getPlayer().getWorld(), Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2]));
                Location blockLoc = b.getLocation();
                if (loc.getBlockX() == blockLoc.getBlockX() && loc.getBlockY() == blockLoc.getBlockY() && loc.getBlockZ() == blockLoc.getBlockZ())
                    block.removeMetadata("ce.mine.secondary", Main.plugin);
            }
        }
    }

}
 
Example 2
Source File: MainListener.java    From ArmorStandTools with MIT License 5 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    Block b = event.getBlock();
    if((b.getType() == Material.PLAYER_HEAD && b.hasMetadata("protected")) || (b.getType() == Material.SIGN && b.hasMetadata("armorStand"))) {
        event.setCancelled(true);
    }
}
 
Example 3
Source File: SpigotListener.java    From ObsidianDestroyer with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onEntityExplode(BlockExplodeEvent event) {
    if (event == null || ChunkManager.getInstance().getDisabledWorlds().contains(event.getBlock().getLocation().getWorld().getName())) {
        return; // do not do anything in case explosions get cancelled
    }

    final Block detonatorBlock = event.getBlock();

    if (detonatorBlock == null) {
        return;
    }
    if (detonatorBlock.hasMetadata("ObbyEntity")) {
        return;
    }
    if (event.getYield() <= 0) {
        return;
    }

    // feeling batty?! Spawn a bat to tie onto the EntityExplodeEvent.
    try {
        Bat bat = (Bat) Bukkit.getWorld(detonatorBlock.getWorld().getName()).spawnEntity(detonatorBlock.getLocation(), EntityType.BAT);
        if (bat != null) {
            bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100, 1), true);
        }
        // Construct a new event but don't call it.
        EntityExplodeEvent entityExplodeEvent = new EntityExplodeEvent(bat, event.getBlock().getLocation(), event.blockList(), event.getYield());
        ChunkManager.getInstance().handleExplosion(entityExplodeEvent, event.getBlock().getLocation());
        if (bat != null) {
            bat.remove(); // bye
        }
    } catch (Exception e) {
        ObsidianDestroyer.debug(e.toString());
    }
}
 
Example 4
Source File: VoidFilter.java    From CardinalPGM with MIT License 5 votes vote down vote up
@Override
public FilterState evaluate(final Object... objects) {
    for (Object object : objects) {
        if (object instanceof Block) {
            Block check = new Location(GameHandler.getGameHandler().getMatchWorld(), ((Block) object).getX(), 0, ((Block) object).getZ()).getBlock();
            if (object.equals(check)) return ALLOW;
            return check.getType() == Material.AIR && !check.hasMetadata("block36") ? ALLOW : DENY;
        }
    }
    return (getParent() == null ? ABSTAIN : getParent().evaluate(objects));
}
 
Example 5
Source File: SeaLevelRise.java    From GlobalWarming with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Updates the sea level for the given chunk (up or down)
 * - BlockFromToEvent is the key to making this work:
 * - RISING SEAS: helps identify which blocks were created and which were pre-existing lakes, rivers, irrigation, etc.
 * - EBBING SEAS: prevents pending chunks from spilling into cleared chunks
 */
private void updateChunk(ChunkSnapshot snapshot) {
    //Setup:
    World world = Bukkit.getWorld(snapshot.getWorldName());
    WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(world.getUID());
    final int deltaSeaLevel = (int) seaMap.getValue(climateEngine.getTemperature());
    final int customSeaLevel = baseSeaLevel + deltaSeaLevel;
    final int maxHeight = baseSeaLevel + (int) seaMap.getValue(maxTemperature);

    GChunk chunk = new GChunk(snapshot);
    if (waterLevel.containsKey(chunk)) {
        int seaLevel = waterLevel.get(chunk);
        if (seaLevel == customSeaLevel) {
            return;
        }
    }
    waterLevel.put(chunk, customSeaLevel);

    //Scan chunk-blocks within the sea-level's range:
    for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
            for (int y = baseSeaLevel; y < maxHeight; y++) {
                //--------------------------------------------------------------------------------------------------
                //  TYPE  |  SEALEVEL  |  REPAIR  | TASK
                //--------------------------------------------------------------------------------------------------
                //    W   |   (ABOVE)  |     T    | [1] Set to AIR, clear tag
                //    W   |   (ABOVE)  |     F    | [2] If owner, set to air, clear tag
                //    W   |   [BELOW]  |     T    | [3] If not base-sea-level, set to air, clear tag
                //    W   |   [BELOW]  |     F    | [4] If owner and sea-level == 0, set to air, clear tag
                //    A   |   (ABOVE)  |     T    | Ignore
                //    A   |   (ABOVE)  |     F    | Ignore
                //    A   |   [BELOW]  |     T    | Ignore
                //    A   |   [BELOW]  |     F    | [5] If sea-level > 0, set to water, add tag
                //--------------------------------------------------------------------------------------------------
                Block block = world.getChunkAt(snapshot.getX(), snapshot.getZ()).getBlock(x, y, z);
                if (replaceOnRise.contains(block.getType())) {
                    if (deltaSeaLevel > 0 && y <= customSeaLevel && !isOverride) {
                        //Set any air-blocks below-and-at sea-level to water
                        //as long as the sea-level is above normal [5]
                        block.setType(WATER, true);
                        addTaggedBlock(world.getUID().toString(), block);
                    }
                } else if (replaceOnFall.contains(block.getType())) {
                    if ((block.hasMetadata(SEALEVEL_BLOCK) && (y > customSeaLevel || deltaSeaLevel == 0))
                            || (isOverride && y > baseSeaLevel)) {
                        //Set water-to-air when:
                        // - Repairing, except the base-sea-level [1, 3]
                        // - Owner of block above sea-level [2]
                        // - Owner of block below sea-level when sea-level is normal [4]
                        block.setType(AIR, true);
                        removeTaggedBlock(world.getUID().toString(), block);
                    }
                }
            }
        }
    }
}
 
Example 6
Source File: MainListener.java    From ArmorStandTools with MIT License 4 votes vote down vote up
@EventHandler
public void onSignChange(final SignChangeEvent event) {
    if(event.getBlock().hasMetadata("armorStand")) {
        final Block b = event.getBlock();
        final ArmorStand as = getArmorStand(b);
        if (as != null) {
            StringBuilder sb = new StringBuilder();
            for (String line : event.getLines()) {
                if (line != null && line.length() > 0) {
                    sb.append(ChatColor.translateAlternateColorCodes('&', line));
                }
            }
            String input = sb.toString();
            if(b.hasMetadata("setName")) {
                if (input.length() > 0) {
                    as.setCustomName(input);
                    as.setCustomNameVisible(true);
                } else {
                    as.setCustomName("");
                    as.setCustomNameVisible(false);
                    as.setCustomNameVisible(false);
                }
            } else if(b.hasMetadata("setSkull")) {
                if(MC_USERNAME_PATTERN.matcher(input).matches()) {
                    b.setMetadata("protected", new FixedMetadataValue(plugin, true));
                    event.getPlayer().sendMessage(ChatColor.GOLD + Config.pleaseWait);
                    String cmd = "minecraft:give " + event.getPlayer().getName() + " minecraft:player_head{SkullOwner:\"" + input + "\"} 1";
                    String current = b.getWorld().getGameRuleValue("sendCommandFeedback");
                    b.getWorld().setGameRuleValue("sendCommandFeedback", "false");
                    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd);
                    b.getWorld().setGameRuleValue("sendCommandFeedback", current);
                    boolean found = false;
                    for(int slot : event.getPlayer().getInventory().all(Material.PLAYER_HEAD).keySet()) {
                        ItemStack skull = event.getPlayer().getInventory().getItem(slot);
                        SkullMeta sm = (SkullMeta) skull.getItemMeta();
                        if(sm.hasOwner() && input.equalsIgnoreCase(sm.getOwningPlayer().getName())) {
                            as.setHelmet(skull);
                            event.getPlayer().sendMessage(ChatColor.GREEN + Config.appliedHead + ChatColor.GOLD + " " + input);
                            event.getPlayer().getInventory().setItem(slot, null);
                            found = true;
                            break;
                        }
                    }
                    if(!found) {
                        event.getPlayer().sendMessage(ChatColor.GOLD + Config.headFailed);
                    }
                } else {
                    event.getPlayer().sendMessage(ChatColor.RED + input + " " + Config.invalidName);
                }
            }
        }
        event.setCancelled(true);
        b.removeMetadata("armorStand", plugin);
        b.removeMetadata("setName", plugin);
        b.removeMetadata("setSkull", plugin);
        b.setType(Material.AIR);
    }
}