@Override public String toString() { return Material.getMaterial(getItemTypeId()).toString() + (isStem() ? "{STEM}" : getPaintedFaces()); }
@Utility public Map<String, Object> serialize() { Map<String, Object> result = new LinkedHashMap<String, Object>(); result.put("type", getType().name()); if (getDurability() != 0) { result.put("damage", getDurability()); } if (getAmount() != 1) { result.put("amount", getAmount()); } ItemMeta meta = getItemMeta(); if (!Bukkit.getItemFactory().equals(meta, null)) { result.put("meta", meta); } return result; }
/** * An item stack with no extra data * * @param type item material * @param amount stack size */ public ItemStack(final Material type, final int amount) { this(type.getId(), amount); }
private void createData(final byte data) { Material mat = Material.getMaterial(type); if (mat == null) { this.data = new MaterialData(type, data); } else { this.data = mat.getNewData(data); } }
@Override public List<String> tabCompleteInternalMaterialName(String token, List<String> completions) { List<String> materialNames = new ArrayList<>(Material.values().length); for (Material mat : Material.values()) { materialNames.add(mat.name().toLowerCase()); } return StringUtil.copyPartialMatches(token, materialNames, completions); }
/** * Converts a Material to a BlockType * * @param material The material * @return The blocktype */ public static BlockType asBlockType(Material material) { checkNotNull(material); if (!material.isBlock()) { throw new IllegalArgumentException(material.getKey().toString() + " is not a block!"); } return BlockTypes.get(material.getKey().toString()); }
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onBlockBreak(BlockBreakEvent evt) { Block b = evt.getBlock(); if(b == null) return; /* Work around for stupid mods.... */ Location l = b.getLocation(); core.listenerManager.processBlockEvent(EventType.BLOCK_BREAK, b.getType().getId(), getWorld(l.getWorld()).getName(), l.getBlockX(), l.getBlockY(), l.getBlockZ()); } }, DynmapPlugin.this);
private Location getSafeLocation(Location loc) { int blockY = loc.getBlockY(); World world = loc.getWorld(); if (blockY > world.getHighestBlockYAt(loc)) { blockY = world.getHighestBlockYAt(loc) + 1; Block current = world.getBlockAt(loc.getBlockX(), blockY, loc.getBlockZ()); if (current.isEmpty() && current.getRelative(BlockFace.UP).isEmpty()) { hadSpace = true; } else if (hadSpace) { if (current.getType().isSolid()) { found = true; blockY++;
/** * Find a a Location obove or below the specified Location, which is on ground. * * <p>The returned Location will be at the center of the block, X and Y wise. * * @param spawn The Location a safe spawn position should be found at. * @return The location to spawn the player at. */ private static Location findSafeSpawnLocation(Location spawn) { World world = spawn.getWorld(); int blockX = spawn.getBlockX(); int blockY = spawn.getBlockY(); int blockZ = spawn.getBlockZ(); int highestY = world.getHighestBlockYAt(blockX, blockZ); int y = blockY; boolean wasPreviousSafe = false; for (; y <= highestY; y++) { Material type = world.getBlockAt(blockX, y, blockZ).getType(); boolean safe = Material.AIR.equals(type); if (wasPreviousSafe && safe) { y--; break; } wasPreviousSafe = safe; } return new Location(world, blockX + 0.5, y, blockZ + 0.5); }
/** * Prevent fire spread * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public boolean onBlockSpread(BlockSpreadEvent e) { return e.getSource().getType().equals(Material.FIRE) && checkFire(e, e.getBlock().getLocation(), Flags.FIRE_SPREAD); }
@EventHandler public void onFillAcidBucket(PlayerBucketFillEvent event) { Player p = event.getPlayer(); if (!p.getWorld().getName().equals("Skaro")) { return; } Material type = event.getBlockClicked().getType(); ItemStack bucket = event.getItemStack(); ItemMeta im = bucket.getItemMeta(); if (type.equals(Material.WATER)) { im.setDisplayName("Acid Bucket"); } if (type.equals(Material.LAVA)) { im.setDisplayName("Rust Bucket"); } bucket.setItemMeta(im); p.updateInventory(); } }
@Override public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) { if (SlimefunManager.isItemSimiliar(e.getPlayer().getInventory().getItemInMainHand(), SlimefunItems.PICKAXE_OF_VEIN_MINING, true)) { if (e.getBlock().getType().toString().endsWith("_ORE")) { List<Location> blocks = new ArrayList<Location>(); Vein.calculate(e.getBlock().getLocation(), e.getBlock().getLocation(), blocks, 16); for (Location block: blocks) { Block b = block.getBlock(); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); for (ItemStack drop: b.getDrops()) { b.getWorld().dropItemNaturally(b.getLocation(), drop.getType().isBlock() ? drop: new CustomItem(drop, fortune)); } b.setType(Material.AIR); } } return true; } else return false; } });
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onTropicalFishScooping(final PlayerInteractEntityEvent e) { if (e.getRightClicked() instanceof TropicalFish && e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.WATER_BUCKET)) { checkIsland(e, e.getRightClicked().getLocation(), Flags.FISH_SCOOPING); } } }
@EventHandler(ignoreCancelled = true) public void onTelepathicCircuitPlace(BlockPlaceEvent event) { ItemStack is = event.getItemInHand(); if (!is.getType().equals(Material.DAYLIGHT_DETECTOR) || !is.hasItemMeta()) { return; } ItemMeta im = is.getItemMeta(); if (im.hasDisplayName() && im.getDisplayName().equals("TARDIS Telepathic Circuit")) { UUID uuid = event.getPlayer().getUniqueId(); String l = event.getBlock().getLocation().toString(); plugin.getTrackerKeeper().getTelepathicPlacements().put(uuid, l); } } }
Material material = Material.matchMaterial(args[1]); ItemStack stack = new ItemStack(material, amount, data); stack = Bukkit.getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(args).subList(4, args.length))); } catch (Throwable t) { player.sendMessage("Not a valid tag"); return true; player.getInventory().addItem(stack); Command.broadcastCommandMessage(sender, "Gave " + player.getName() + " some " + material.getId() + " (" + material + ")"); } else { sender.sendMessage("There's no item called " + args[1]);
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onSmelt(FurnaceSmeltEvent e) { if (BlockStorage.check(e.getBlock()) != null && BlockStorage.check(e.getBlock()) instanceof EnhancedFurnace) { EnhancedFurnace furnace = (EnhancedFurnace) BlockStorage.check(e.getBlock()); Furnace f = (Furnace) e.getBlock().getState(); int amount = f.getInventory().getSmelting().getType().toString().endsWith("_ORE") ? furnace.getOutput(): 1; ItemStack output = RecipeCalculator.getSmeltedOutput(f.getInventory().getSmelting().getType()); ItemStack result = f.getInventory().getResult(); if (result != null) result = result.clone(); f.getInventory().setResult(null); if (result != null) f.getInventory().setResult(new CustomItem(result, result.getAmount() + amount > result.getMaxStackSize() ? result.getMaxStackSize(): result.getAmount() + amount)); else f.getInventory().setResult(new CustomItem(output, output.getAmount() + amount > output.getType().getMaxStackSize() ? output.getType().getMaxStackSize(): output.getAmount() + amount)); } }
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); if (!shouldIncreaseBeTakenIntoAccountNoPermissions(player)) { return; } Block block = event.getBlock(); MultipleAchievements category = MultipleAchievements.PLACES; String blockName = block.getType().name().toLowerCase(); if (!player.hasPermission(category.toPermName() + '.' + blockName)) { return; } Set<String> foundAchievements = findAchievementsByCategoryAndName( category, blockName + ':' + block.getState().getData().toItemStack(0).getDurability()); foundAchievements.addAll(findAchievementsByCategoryAndName(category, blockName)); foundAchievements.forEach(achievement -> updateStatisticAndAwardAchievementsIfAvailable(player, category, achievement, 1)); } }
@Override @Utility public String toString() { StringBuilder toString = new StringBuilder("ItemStack{").append(getType().name()).append(" x ").append(getAmount()); if (hasItemMeta()) { toString.append(", ").append(getItemMeta()); } return toString.append('}').toString(); }
private void kill(boolean dropArmorStand) { active = false; ((GlowWorld) location.getWorld()) .showParticle(location.clone().add(0, 1.317, 0), Effect.TILE_DUST, Material.WOOD.getId(), 0, 0.125f, 0.494f, 0.125f, 0.1f, 10, 10); for (ItemStack stack : equipment.getArmorContents()) { if (InventoryUtil.isEmpty(stack)) { continue; } getWorld().dropItemNaturally(location, stack); } if (dropArmorStand) { getWorld().dropItemNaturally(location, new ItemStack(Material.ARMOR_STAND)); } }
final Set<Material> blockedMaterials) { Map<Vector, Double> neighbors = new HashMap<>(); final Vector start = location.toVector(); final Material materialAt = location.getWorld().getBlockAt( neighbor.toLocation(location.getWorld())).getType(); if (materialAt.equals(Material.AIR) && location.getWorld().getBlockAt( neighbor.add(new Vector(0, -1, 0)).toLocation( location.getWorld())).getType().equals(Material.AIR)) { continue; if (materialAt.isSolid() && location.getWorld().getBlockAt( neighbor.add(new Vector(0, 1, 0)).toLocation( location.getWorld())).getType().isSolid()) { continue;