org.bukkit.Material#AIR源码实例Demo

下面列出了org.bukkit.Material#AIR 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Sentinel   文件: SentinelItemHelper.java
/**
 * 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);
        }
    }
}
 
源代码2 项目: Skript   文件: ItemData.java
/**
 * 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;
}
 
源代码3 项目: Slimefun4   文件: AncientAltarCraftEvent.java
/**
 * 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;
}
 
源代码4 项目: NBTEditor   文件: InventoryForItems.java
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);
	}
}
 
源代码5 项目: Skript   文件: EvtMoveOn.java
@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();
	}
}
 
源代码6 项目: QuickShop-Reremake   文件: FileEnvelope.java
@NotNull
@Override
public ItemStack getCustomItemStack(@NotNull String path) {
    try {
        return Util.deserialize(path);
    } catch (Exception exception) {
        return new ItemStack(Material.AIR);
    }
}
 
源代码7 项目: HubBasics   文件: ItemListener.java
@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
}
 
源代码8 项目: EnchantmentsEnhance   文件: GUIListener.java
@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();
        }
    }
}
 
源代码9 项目: Item-NBT-API   文件: MergeTileSubCompoundTest.java
@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);
		}
	}
}
 
源代码10 项目: PGM   文件: KitParser.java
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);
}
 
源代码11 项目: PlayerSQL   文件: PacketDataSerializer.java
@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);
}
 
源代码12 项目: Skript   文件: ItemType.java
/**
 * 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;
}
 
源代码13 项目: Civs   文件: PortMenu.java
@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);
}
 
源代码14 项目: ProjectAres   文件: LaneMatchModule.java
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);
}
 
源代码15 项目: Hawk   文件: BlockInteractOcclusion.java
@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;
            }
        }
    }
}
 
源代码16 项目: ProjectAres   文件: FallingBlocksRule.java
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();
}
 
源代码17 项目: FunnyGuilds   文件: MxcBase.java
@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);
}
 
源代码18 项目: PGM   文件: InventoryUtils.java
public static boolean isNothing(ItemStack stack) {
  return stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0;
}
 
源代码19 项目: FunnyGuilds   文件: AxcMove.java
@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()));
}
 
源代码20 项目: Civs   文件: RepairEffect.java
@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);
}
 
 方法所在类
 同类方法