Java Code Examples for org.bukkit.block.Block#setMetadata()
The following examples show how to use
org.bukkit.block.Block#setMetadata() .
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: PricklyBlock.java From ce with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean effect(Event event, Player player) { if(event instanceof BlockPlaceEvent) { BlockPlaceEvent e = (BlockPlaceEvent) event; Block b = e.getBlock(); b.setMetadata("ce.mine", new FixedMetadataValue(main, getOriginalName())); String coord = b.getX() + " " + b.getY() + " " + b.getZ(); b.getRelative(0,1,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord)); b.getRelative(0,-1,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord)); b.getRelative(1,0,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord)); b.getRelative(0,0,1).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord)); b.getRelative(0,0,-1).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord)); b.getRelative(-1,0,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord)); } else if(event instanceof PlayerMoveEvent) { if(!player.getGameMode().equals(GameMode.CREATIVE) && !player.hasPotionEffect(PotionEffectType.CONFUSION)) { player.damage(Damage); player.sendMessage(ChatColor.DARK_GREEN + "A nearbly Block is hurting you!"); player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, NauseaDuration, NauseaLevel)); } } return false; }
Example 2
Source File: Main.java From ArmorStandTools with MIT License | 5 votes |
void setName(Player p, ArmorStand as) { Block b = Utils.findAnAirBlock(p.getLocation()); if(b == null) { p.sendMessage(ChatColor.RED + Config.noAirError); return; } b.setType(Material.SIGN); nms.openSign(p, b); b.setMetadata("armorStand", new FixedMetadataValue(this, as.getUniqueId())); b.setMetadata("setName", new FixedMetadataValue(this, true)); }
Example 3
Source File: Main.java From ArmorStandTools with MIT License | 5 votes |
void setPlayerSkull(Player p, ArmorStand as) { Block b = Utils.findAnAirBlock(p.getLocation()); if(b == null) { p.sendMessage(ChatColor.RED + Config.noAirError); return; } b.setType(Material.SIGN); nms.openSign(p, b); b.setMetadata("armorStand", new FixedMetadataValue(this, as.getUniqueId())); b.setMetadata("setSkull", new FixedMetadataValue(this, true)); }
Example 4
Source File: BlockListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onPlace(BlockPlaceEvent event) { Block block = event.getBlock(); block.setMetadata("blockPlaced", new FixedMetadataValue(MineTinker.getPlugin(), System.currentTimeMillis())); }
Example 5
Source File: SeaLevelRise.java From GlobalWarming with GNU Lesser General Public License v3.0 | 4 votes |
private void addTaggedBlock(String s, Block block) { block.setMetadata(SEALEVEL_BLOCK, BLOCK_TAG); taggedBlocks.computeIfAbsent(s, k -> new HashSet<>()).add(block.getLocation()); }
Example 6
Source File: Transporter.java From AnnihilationPro with MIT License | 4 votes |
public void setBlockOwner(Block b, UUID player) { MetadataValue val = new FixedMetadataValue(AnnihilationMain.getInstance(), player.toString()); b.setMetadata("Owner", val); }
Example 7
Source File: MainListener.java From ArmorStandTools with MIT License | 4 votes |
@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); } }
Example 8
Source File: CratesPlus.java From CratesPlus with GNU General Public License v3.0 | 4 votes |
private void loadMetaData() { if (!getStorageHandler().getFlatConfig().isSet("Crate Locations")) return; for (String name : getStorageHandler().getFlatConfig().getConfigurationSection("Crate Locations").getKeys(false)) { final Crate crate = configHandler.getCrate(name.toLowerCase()); if (crate == null) continue; if (!(crate instanceof KeyCrate)) continue; KeyCrate keyCrate = (KeyCrate) crate; String path = "Crate Locations." + name; List<String> locations = getStorageHandler().getFlatConfig().getStringList(path); for (String location : locations) { List<String> strings = Arrays.asList(location.split("\\|")); if (strings.size() < 4) continue; // Somethings broke? if (strings.size() > 4) { // Somethings broke? But we'll try and fix it! for (int i = 0; i < strings.size(); i++) { if (strings.get(i).isEmpty() || strings.get(i).equals("")) { strings.remove(i); } } } Location locationObj; try { locationObj = new Location(Bukkit.getWorld(strings.get(0)), Double.parseDouble(strings.get(1)), Double.parseDouble(strings.get(2)), Double.parseDouble(strings.get(3))); Block block = locationObj.getBlock(); if (block == null || block.getType().equals(Material.AIR)) { getLogger().warning("No block found at " + location + " removing from data.yml"); keyCrate.removeFromConfig(locationObj); continue; } Location location1 = locationObj.getBlock().getLocation().add(0.5, 0.5, 0.5); keyCrate.loadHolograms(location1); final CratesPlus cratesPlus = this; block.setMetadata("CrateType", new MetadataValue() { @Override public Object value() { return crate.getName(false); } @Override public int asInt() { return 0; } @Override public float asFloat() { return 0; } @Override public double asDouble() { return 0; } @Override public long asLong() { return 0; } @Override public short asShort() { return 0; } @Override public byte asByte() { return 0; } @Override public boolean asBoolean() { return false; } @Override public String asString() { return value().toString(); } @Override public Plugin getOwningPlugin() { return cratesPlus; } @Override public void invalidate() { } }); } catch (Exception ignored) { } } } }