Java Code Examples for org.bukkit.Material#AIR
The following examples show how to use
org.bukkit.Material#AIR .
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: SentinelItemHelper.java From Sentinel with MIT License | 6 votes |
/** * Takes one item from the NPC's held items (for consumables). */ public void takeOne() { ItemStack toSet; ItemStack item = getHeldItem(); if (item != null && item.getType() != Material.AIR) { if (item.getAmount() > 1) { item.setAmount(item.getAmount() - 1); toSet = item; } else { toSet = null; } if (getLivingEntity().getEquipment() == null) { return; } if (SentinelVersionCompat.v1_9) { getLivingEntity().getEquipment().setItemInMainHand(toSet); } else { getLivingEntity().getEquipment().setItemInHand(toSet); } } }
Example 2
Source File: ItemData.java From Skript with GNU General Public License v3.0 | 6 votes |
/** * Tests whether the given item is of this type. * * @param item * @return Whether the given item is of this type. */ public boolean isOfType(@Nullable ItemStack item) { if (item == null) return type == Material.AIR; if (type != item.getType()) return false; // Obvious mismatch if (itemFlags != 0) { // Either stack has tags (or durability) if (ItemUtils.getDamage(stack) != ItemUtils.getDamage(item)) return false; // On 1.12 and below, damage is not in meta if (stack.hasItemMeta() == item.hasItemMeta()) // Compare ItemMeta as in isSimilar() of ItemStack return stack.hasItemMeta() ? itemFactory.equals(stack.getItemMeta(), item.getItemMeta()) : true; else return false; } return true; }
Example 3
Source File: GUIListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onClick(InventoryClickEvent e) { // Handles invalid clicks. if (e.getSlot() < 0) { return; } // Handles invalid entity. if (!(e.getWhoClicked() instanceof Player)) { return; } // Handles empty slot. if (e.getCurrentItem() != null && e.getCurrentItem().getType() == (Material.AIR)) { return; } // Handles non-gui inventory. if (e.getRawSlot() > 53) { return; } Player player = (Player) e.getWhoClicked(); String playerName = player.getName(); GUIAbstract gui = GUIManager.getMap().get(playerName); if (gui != null && gui.getInventory().equals(e.getInventory())) { e.setCancelled(true); GUIAbstract.GUIAction action = gui.getActions().get(e.getSlot()); if (action != null) { action.click(e.getClick()); gui.update(); } } else { if (isCreatedGUI(e.getInventory())) { e.setCancelled(true); player.closeInventory(); } } }
Example 4
Source File: BlockInteractOcclusion.java From Hawk with GNU General Public License v3.0 | 5 votes |
@Override protected void check(InteractWorldEvent e) { HawkPlayer pp = e.getHawkPlayer(); Vector eyePos = pp.getPosition().clone().add(new Vector(0, pp.isSneaking() ? 1.54 : 1.62, 0)); Vector direction = MathPlus.getDirection(pp.getYaw(), pp.getPitch()); Location bLoc = e.getTargetedBlockLocation(); Block b = bLoc.getBlock(); WrappedBlock bNMS = WrappedBlock.getWrappedBlock(b, pp.getClientVersion()); AABB targetAABB = new AABB(bNMS.getHitBox().getMin(), bNMS.getHitBox().getMax()); double distance = targetAABB.distanceToPosition(eyePos); BlockIterator iter = new BlockIterator(pp.getWorld(), eyePos, direction, 0, (int) distance + 2); while (iter.hasNext()) { Block bukkitBlock = iter.next(); if (bukkitBlock.getType() == Material.AIR || bukkitBlock.isLiquid()) continue; if (bukkitBlock.getLocation().equals(bLoc)) break; WrappedBlock iterBNMS = WrappedBlock.getWrappedBlock(bukkitBlock, pp.getClientVersion()); AABB checkIntersection = new AABB(iterBNMS.getHitBox().getMin(), iterBNMS.getHitBox().getMax()); Vector occludeIntersection = checkIntersection.intersectsRay(new Ray(eyePos, direction), 0, Float.MAX_VALUE); if (occludeIntersection != null) { if (occludeIntersection.distance(eyePos) < distance) { Placeholder ph = new Placeholder("type", iterBNMS.getBukkitBlock().getType()); punishAndTryCancelAndBlockRespawn(pp, 1, e, ph); return; } } } }
Example 5
Source File: LaneMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private static Vector getSafeLocationUnder(Block block) { World world = block.getWorld(); for(int y = block.getY() - 2; y >= 0; y--) { Block feet = world.getBlockAt(block.getX(), y, block.getZ()); Block head = world.getBlockAt(block.getX(), y + 1, block.getZ()); if(feet.getType() == Material.AIR && head.getType() == Material.AIR) { return new Vector(block.getX() + 0.5, y, block.getZ() + 0.5); } } return new Vector(block.getX() + 0.5, -2, block.getZ() + 0.5); }
Example 6
Source File: PortMenu.java From Civs with GNU General Public License v3.0 | 5 votes |
@Override public ItemStack createItemStack(Civilian civilian, MenuIcon menuIcon, int count) { if ("ports".equals(menuIcon.getKey())) { List<Region> regions = (List<Region>) MenuManager.getData(civilian.getUuid(), "ports"); int page = (int) MenuManager.getData(civilian.getUuid(), "page"); int startIndex = page * menuIcon.getIndex().size(); Region[] regionArray = new Region[regions.size()]; regionArray = regions.toArray(regionArray); if (regionArray.length <= startIndex + count) { return new ItemStack(Material.AIR); } Region region = regionArray[startIndex + count]; RegionType regionType = (RegionType) ItemManager.getInstance().getItemType(region.getType()); CVItem cvItem = regionType.getShopIcon(civilian.getLocale()); cvItem.setDisplayName(LocaleManager.getInstance().getTranslation(civilian.getLocale(), region.getType() + "-name")); cvItem.getLore().clear(); cvItem.getLore().add(ChatColor.BLACK + region.getId()); cvItem.getLore().add(region.getLocation().getWorld().getName() + " " + ((int) region.getLocation().getX()) + "x " + ((int) region.getLocation().getY()) + "y " + ((int) region.getLocation().getZ()) + "z "); Town town = TownManager.getInstance().getTownAt(region.getLocation()); if (town != null) { cvItem.getLore().add(town.getName()); } ItemStack itemStack = cvItem.createItemStack(); if (MenuManager.getData(civilian.getUuid(), "region") != null) { ArrayList<String> actionStrings = new ArrayList<>(); actionStrings.add("set-teleport"); putActionList(civilian, itemStack, actionStrings); } else { putActions(civilian, menuIcon, itemStack, count); } return itemStack; } return super.createItemStack(civilian, menuIcon, count); }
Example 7
Source File: ItemType.java From Skript with GNU General Public License v3.0 | 5 votes |
/** * Adds this ItemType to the given item stack * * @param item * @return The passed ItemStack or a new one if the passed is null or air */ @Nullable public ItemStack addTo(final @Nullable ItemStack item) { if (item == null || item.getType() == Material.AIR) return getRandom(); if (isOfType(item)) item.setAmount(Math.min(item.getAmount() + getAmount(), item.getMaxStackSize())); return item; }
Example 8
Source File: PacketDataSerializer.java From PlayerSQL with GNU General Public License v2.0 | 5 votes |
@SneakyThrows public void write(ItemStack input) { if (input == null || input.getType() == Material.AIR) { return; } CraftItemStack item = input instanceof CraftItemStack ? ((CraftItemStack) input) : CraftItemStack.asCraftCopy(input); net.minecraft.server.v1_13_R1.ItemStack nms = (net.minecraft.server.v1_13_R1.ItemStack) handle.get(item); buf.a(nms); }
Example 9
Source File: KitParser.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public ItemStack parseItem(Element el, boolean allowAir) throws InvalidXMLException { if (el == null) return null; org.jdom2.Attribute attrMaterial = el.getAttribute("material"); String name = attrMaterial != null ? attrMaterial.getValue() : el.getValue(); Material type = Materials.parseMaterial(name); if (type == null || (type == Material.AIR && !allowAir)) { throw new InvalidXMLException("Invalid material type '" + name + "'", el); } return parseItem(el, type); }
Example 10
Source File: MergeTileSubCompoundTest.java From Item-NBT-API with MIT License | 5 votes |
@Override public void test() throws Exception { if (!NBTInjector.isInjected()) return; if (!Bukkit.getWorlds().isEmpty()) { World world = Bukkit.getWorlds().get(0); try { boolean failed = false; Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 255, world.getSpawnLocation().getBlockZ()); if (block.getType() == Material.AIR) { block.setType(Material.CHEST); NBTCompound comp = NBTInjector.getNbtData(block.getState()); comp.addCompound("subcomp").setString("hello", "world"); NBTContainer cont = new NBTContainer(); cont.mergeCompound(comp.getCompound("subcomp")); if (!(cont.hasKey("hello") && "world".equals(cont.getString("hello")))) { failed = true; } block.setType(Material.AIR); if(failed) { throw new NbtApiException("Data was not correct! " + cont); } } } catch (Exception ex) { throw new NbtApiException("Wasn't able to use NBTTiles!", ex); } } }
Example 11
Source File: AncientAltarCraftEvent.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
/** * This method will change the item that would be dropped by the {@link AncientAltar} * * @param output * being the {@link ItemStack} you want to change the item to. */ public void setItem(ItemStack output) { if (output == null || output.getType() == Material.AIR) { throw new IllegalArgumentException("An Ancient Altar cannot drop 'null' items"); } this.output = output; }
Example 12
Source File: ItemListener.java From HubBasics with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onItemDrop(PlayerDropItemEvent event) { ItemStack currentItem = event.getItemDrop().getItemStack(); if (currentItem.getType() == Material.AIR) return; NBTItem nbtItem = new NBTItem(currentItem); if (!nbtItem.hasKey("HubBasics")) return; CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics")); if (item == null) { currentItem.setType(Material.AIR); // Destroy old item return; } if (!item.getAllowDrop()) event.setCancelled(true); // Call setCancelled only when needed to not conflict with other plugins }
Example 13
Source File: FileEnvelope.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
@NotNull @Override public ItemStack getCustomItemStack(@NotNull String path) { try { return Util.deserialize(path); } catch (Exception exception) { return new ItemStack(Material.AIR); } }
Example 14
Source File: EvtMoveOn.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override public void execute(final @Nullable Listener l, final @Nullable Event event) throws EventException { if (event == null) return; final PlayerMoveEvent e = (PlayerMoveEvent) event; final Location from = e.getFrom(), to = e.getTo(); if (!itemTypeTriggers.isEmpty()) { final Block block = getOnBlock(to); if (block == null || block.getType() == Material.AIR) return; final Material id = block.getType(); final List<Trigger> ts = itemTypeTriggers.get(id); if (ts == null) return; final int y = getBlockY(to.getY(), id); if (to.getWorld().equals(from.getWorld()) && to.getBlockX() == from.getBlockX() && to.getBlockZ() == from.getBlockZ() && y == getBlockY(from.getY(), getOnBlock(from).getType()) && getOnBlock(from).getType() == id) return; SkriptEventHandler.logEventStart(e); triggersLoop: for (final Trigger t : ts) { final EvtMoveOn se = (EvtMoveOn) t.getEvent(); for (final ItemType i : se.types) { if (i.isOfType(block)) { SkriptEventHandler.logTriggerStart(t); t.execute(e); SkriptEventHandler.logTriggerEnd(t); continue triggersLoop; } } } SkriptEventHandler.logEventEnd(); } }
Example 15
Source File: InventoryForItems.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
public InventoryForItems(Player owner, BaseNBT wrapper, ItemsVariable variable) { super(owner, wrapper, variable); ItemStack[] items = _variable.getItems(); int i = 0; for (; i < _variable.count(); i++) { if (items[i] != null && items[i].getType() != Material.AIR) { setItem(i, items[i]); } else { setPlaceholder(i, createPlaceholder(Material.PAPER, "ยง6" + _variable.getDescription(i))); } } for (; i < 9; i++) { setItem(i, ITEM_FILLER); } }
Example 16
Source File: RepairEffect.java From Civs with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { if (event.getClickedBlock() == null || event.getHand() == null) { return; } if ((!event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && !event.getAction().equals(Action.LEFT_CLICK_BLOCK)) || (!event.getClickedBlock().getType().equals(Material.IRON_BLOCK)) || event.getHand().equals(EquipmentSlot.HAND)) { return; } Region r = RegionManager.getInstance().getRegionAt(event.getClickedBlock().getLocation()); if (r == null || !r.getEffects().containsKey(KEY)) { return; } Player player = event.getPlayer(); ItemStack item = player.getInventory().getItemInMainHand(); ItemMeta itemMeta = item.getItemMeta(); if (!(itemMeta instanceof Damageable)) { return; } Damageable damageable = (Damageable) itemMeta; if (getRequiredReagent(item.getType()).isEmpty()) { return; } if (item.getType() == Material.AIR) { player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player, "hold-repair-item")); return; } if (!damageable.hasDamage()) { return; } repairItem(event, player, item); }
Example 17
Source File: AxcMove.java From FunnyGuilds with Apache License 2.0 | 4 votes |
@Override public void execute(CommandSender sender, String[] args) { MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration(); PluginConfiguration config = FunnyGuilds.getInstance().getPluginConfiguration(); Player player = (Player) sender; if (!config.regionsEnabled) { player.sendMessage(messages.regionsDisabled); return; } if (args.length < 1) { player.sendMessage(messages.generalNoTagGiven); return; } Guild guild = GuildUtils.getByTag(args[0]); if (guild == null) { player.sendMessage(messages.generalNoGuildFound); return; } Location location = player.getLocation(); if (config.createCenterY != 0) { location.setY(config.createCenterY); } int distance = config.regionSize + config.createDistance; if (config.enlargeItems != null) { distance = config.enlargeItems.size() * config.enlargeSize + distance; } if (distance > player.getWorld().getSpawnLocation().distance(location)) { player.sendMessage(messages.createSpawn.replace("{DISTANCE}", Integer.toString(distance))); return; } if (RegionUtils.isNear(location)) { player.sendMessage(messages.createIsNear); return; } User admin = User.get(player); if (!SimpleEventHandler.handle(new GuildMoveEvent(EventCause.ADMIN, admin, guild, location))) { return; } Region region = guild.getRegion(); if (region == null) { region = new Region(guild, location, config.regionSize); } else { if (config.createEntityType != null) { GuildEntityHelper.despawnGuildHeart(guild); } else if (config.createMaterial != null && config.createMaterial.getLeft() != Material.AIR) { Block block = region.getCenter().getBlock().getRelative(BlockFace.DOWN); Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> { if (block.getLocation().getBlockY() > 1) { block.setType(Material.AIR); } }); } region.setCenter(location); } if (config.createCenterSphere) { List<Location> sphere = SpaceUtils.sphere(location, 3, 3, false, true, 0); for (Location locationInSphere : sphere) { if (locationInSphere.getBlock().getType() != Material.BEDROCK) { locationInSphere.getBlock().setType(Material.AIR); } } } GuildUtils.spawnHeart(guild); player.sendMessage(messages.adminGuildRelocated.replace("{GUILD}", guild.getName()).replace("{REGION}", region.getName())); }
Example 18
Source File: InventoryUtils.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
public static boolean isNothing(ItemStack stack) { return stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0; }
Example 19
Source File: MxcBase.java From FunnyGuilds with Apache License 2.0 | 4 votes |
@Override public void execute(CommandSender sender, String[] args) { MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration(); Player player = (Player) sender; User user = User.get(player); if (! FunnyGuilds.getInstance().getPluginConfiguration().regionsEnabled) { player.sendMessage(messages.regionsDisabled); return; } if (!user.hasGuild()) { player.sendMessage(messages.generalHasNoGuild); return; } if (!user.isOwner() && !user.isDeputy()) { player.sendMessage(messages.generalIsNotOwner); return; } Guild guild = user.getGuild(); Region region = RegionUtils.get(guild.getName()); Location loc = player.getLocation(); if (!region.isIn(loc)) { player.sendMessage(messages.setbaseOutside); return; } if (!SimpleEventHandler.handle(new GuildBaseChangeEvent(EventCause.USER, user, guild, loc))) { return; } guild.setHome(loc); if (guild.getHome().getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) { for (int i = guild.getHome().getBlockY(); i > 0; i--) { guild.getHome().setY(i); if (guild.getHome().getBlock().getType() != Material.AIR) { break; } } } player.sendMessage(messages.setbaseDone); }
Example 20
Source File: FallingBlocksRule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public boolean canSupport(Block supporter) { // Supportive air would be pointless since nothing could ever fall return supporter.getType() != Material.AIR && stick.query(new BlockQuery(supporter)).isAllowed(); }