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

The following examples show how to use org.bukkit.block.Block#removeMetadata() . 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: SeaLevelRise.java    From GlobalWarming with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void removeTaggedBlock(String s, Block block) {
    block.removeMetadata(SEALEVEL_BLOCK, GlobalWarming.getInstance());
    taggedBlocks.computeIfAbsent(s, k -> new HashSet<>()).remove(block.getLocation());
}
 
Example 3
Source File: SeaLevelRise.java    From GlobalWarming with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Emptying a bucket (water or lava) will remove the adjacent block
 * from the tracked set
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
    Block adjacent = event.getBlockClicked().getRelative(event.getBlockFace());
    adjacent.removeMetadata(SEALEVEL_BLOCK, GlobalWarming.getInstance());
}
 
Example 4
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);
    }
}