本文整理汇总了Java中org.spongepowered.api.entity.Item类的典型用法代码示例。如果您正苦于以下问题:Java Item类的具体用法?Java Item怎么用?Java Item使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Item类属于org.spongepowered.api.entity包,在下文中一共展示了Item类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: give
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
public void give(Player player) {
this.checkCache();
for (ItemStackSnapshot iss : itemStacksCache) {
InventoryTransactionResult result = player.getInventory().offer(iss.createStack());
for (ItemStackSnapshot is : result.getRejectedItems()) {
Item item = (Item) player.getLocation().getExtent().createEntity(EntityTypes.ITEM, player.getLocation().getPosition());
item.offer(Keys.REPRESENTED_ITEM, is.copy());
player.getWorld().spawnEntity(item, Cause.of(NamedCause.source(player), NamedCause.owner("BetterKits")));
}
}
for (String command : this.getCommands()) {
try {
Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command.replace("%name", player.getName()).replace("%uuid", player.getUniqueId().toString()));
} catch (Throwable e) {
e.printStackTrace();
}
}
}
示例2: onItemDrop
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Dispense event, @Root Player player) {
PermHandler ph = PermHandler.getInstance();
event.filterEntities(entity -> {
if (entity.getType().equals(EntityTypes.ITEM)) {
Item item = (Item) entity;
ItemType itemType = item.getItemType();
String itemId = itemType.getId();
if (!ph.checkPerm(player, "protectionperms.item.drop." + itemId + ".dispense")) {
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to drop " + itemType.getName() + '!'));
return false;
}
}
return true;
});
}
示例3: spawnItem
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
public void spawnItem(Location<World> location, ItemStackSnapshot snapshot, Object notifier) {
World world = location.getExtent();
Item rejectedItem = (Item) world.createEntity(EntityTypes.ITEM, location.getPosition());
Cause cause = Cause.source(
EntitySpawnCause.builder()
.entity(rejectedItem)
.type(SpawnTypes.PLUGIN)
.build()
)
.owner(CustomItemLibrary.getInstance().getPluginContainer())
.notifier(notifier)
.build();
rejectedItem.offer(Keys.REPRESENTED_ITEM, snapshot);
world.spawnEntity(rejectedItem, cause);
}
示例4: spawnItem
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
private void spawnItem(World world) {
if (this.entityRef != null) {
this.itemStand = (ArmorStand) world.getEntity(this.entityRef).orElse(null);
this.entityRef = null;
if (this.itemStand != null) {
return;
}
}
this.itemStand = createStand(world, this.pos);
Item itemEntity = createItem(world, this.pos, this.stack, true);
if (!this.itemStand.addPassenger(itemEntity)) {
this.itemStand = null;
return; // Attach passenger failed
}
if (!world.spawnEntity(this.itemStand, WorldManager.SPAWN_CAUSE)) {
this.itemStand = null;
return; // Spawn stand failed
}
if (!world.spawnEntity(itemEntity, WorldManager.SPAWN_CAUSE)) {
this.itemStand = null;
return; // Spawn item failed
}
}
示例5: getLocationImprint
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
private Entity getLocationImprint() {
Chunk c = getChunk(castLocation);
for (Entity entity : c.getEntities()) {
if (entity.getLocation().getPosition().distanceSquared(castLocation.getPosition()) <= 4) {
if (entity.getType() == EntityTypes.ITEM) {
Item i = (Item) entity;
Location location = Utils.extractLocationFromItem(i);
if (location == null) {
continue;
}
setTargetLocation(location);
setPrinterCount(4);
return entity;
}
}
}
return null;
}
示例6: onDropItem
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
@Listener
public void onDropItem(DropItemEvent.Dispense event) {
event.getEntities().stream().filter(entity -> entity instanceof Item).forEach(entity -> {
ItemStack stack = ((EntityItem) entity).getEntityItem();
if (isZoneSlaveItem(stack)) {
Optional<Player> optPlayer = event.getCause().first(Player.class);
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
if (!notifyGroupOwner(stack, player, false)) {
// TODO Log this, as it shouldn't happen
}
player.sendMessage(
Text.of(TextColors.RED, "You've declined your group invite.")
);
}
entity.remove();
}
});
}
示例7: run
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
@Override
public void run(Living owner, Location<World> target) {
IntegratedRunnable vortex = new IntegratedRunnable() {
@Override
public boolean run(int times) {
ParticleGenerator.enderTeleport(target, 1);
getTargetEntities(target).stream().filter(e -> e instanceof Item).forEach(e -> {
e.setLocation(owner.getLocation());
});
return true;
}
@Override
public void end() {
}
};
TimedRunnable<IntegratedRunnable> runnable = new TimedRunnable<>(vortex, 3);
Task task = Task.builder().execute(runnable).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst());
runnable.setTask(task);
}
示例8: onEntityDrop
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
@Listener
public void onEntityDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) EntitySpawnCause spawnCause) {
Entity entity = spawnCause.getEntity();
if (!(entity instanceof Animal)) {
return;
}
Optional<TheButcherShopInstance> optInst = manager.getApplicableZone(entity);
if (!optInst.isPresent()) {
return;
}
event.getEntities().clear();
Item item = (Item) entity.getLocation().createEntity(EntityTypes.ITEM);
item.offer(Keys.REPRESENTED_ITEM, newItemStack("skree:unpackaged_meat").createSnapshot());
event.getEntities().add(item);
}
示例9: sweepFloor
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
public void sweepFloor() {
for (Item item : getContained(Item.class)) {
if (!contains(item)) {
continue;
}
ItemType id = item.getItemType();
for (ItemType aItem : ITEMS) {
if (aItem == id) {
ItemStackSnapshot snapshot = item.get(Keys.REPRESENTED_ITEM).get();
int newAmt = (int) (snapshot.getCount() * .8);
if (newAmt < 1) {
item.remove();
} else {
ItemStack newStack = snapshot.createStack();
newStack.setQuantity(newAmt);
item.offer(Keys.REPRESENTED_ITEM, newStack.createSnapshot());
}
break;
}
}
}
}
示例10: writeItem
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
/**
* Helper method for formatting item container data.
*
* @param item
*/
private void writeItem(Item item) {
checkNotNull(item);
DataContainer itemData = item.toContainer();
// Because item actions are not currently actionable, copy only what we need
Optional<DataView> position = itemData.getView(DataQueries.Position);
if (position.isPresent()) {
position.get().set(DataQueries.WorldUuid, itemData.get(DataQueries.WorldUuid).get());
data.set(DataQueries.Location, position.get());
}
String itemId = "";
int itemQty = 1;
Optional<DataView> optionalItem = itemData.getView(DataQueries.UnsafeData.then("Item"));
if (optionalItem.isPresent()) {
itemId = optionalItem.get().getString(DataQuery.of("id")).orElse("item");
itemQty = optionalItem.get().getInt(DataQuery.of("Count")).orElse(1);
}
data.set(DataQueries.Target, itemId);
data.set(DataQueries.Quantity, itemQty);
}
示例11: onDrop
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
@Listener
public void onDrop(DropItemEvent.Dispense event, @Root EntitySpawnCause cause) {
if (cause.getEntity() instanceof Player) {
//TODO exempt check
}
ModuleConfig config = Modules.BLACKLIST.get().getConfig().get();
CommentedConfigurationNode hnode = config.get();
for (Entity en : event.getEntities()) {
if (!(en instanceof Item)) continue;
Item item = (Item) en;
CommentedConfigurationNode node = hnode.getNode("items", item.getItemType().getId());
if (!node.isVirtual()) {
if (node.getNode("deny-drop").getBoolean()) {
event.setCancelled(true);
}
}
}
}
示例12: CCLService
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
public CCLService() {
checks = new HashMap<>();
Predicate playerPredicate = o -> !(o instanceof Player);
Predicate<Item> whitelistCheck = item -> !CatClearLag.instance.getCclConfig().whitelist.contains(item.getItemType().getBlock().map(blockType -> blockType.getDefaultState().getId()).orElseGet(() -> item.getItemType().getId()));
checks.put(Type.HOSTILE, playerPredicate.and(o -> o instanceof Hostile));
checks.put(Type.ITEM, playerPredicate.and(o -> o instanceof Item).and(whitelistCheck));
checks.put(Type.ALL, playerPredicate.and(Entity.class::isInstance));
checks.put(Type.LIVING, playerPredicate.and(o -> o instanceof Living));
checks.put(Type.XP, playerPredicate.and(o -> o instanceof ExperienceOrb));
}
示例13: alterItem
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
@Override
public Item alterItem(BlockSnapshot block, Item item, EventInformation eventInformation) {
if ( ! Config.get().allowChestAsBackpack) return item;
if ( item.getItemType() != ItemTypes.CHEST && item.getItemType() != ItemTypes.TRAPPED_CHEST) return item;
/*
String backpackId = UUID.randomUUID().toString();
item.offer(Keys.DISPLAY_NAME, CriteriaBackpack.BACKPACK_NAME);
item.offer(SilkTouchKeys.BACKPACK, Optional.of(backpackId));
Inventory inventory = null;
// Create a backpack
Backpack backpack = new Backpack();
int i = 0;
while (i < 30) {
Optional<ItemStack> slotContents = inventory.query(new SlotIndex(8)).peek();
if (slotContents.isPresent()) {
backpack.put(i, slotContents.get());
}
i++;
}
Data.get().backpackStore(backpackId, backpack);
eventInformation.setClearDrops(true);
*/
return item;
}
示例14: alterItem
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
@Override
public Item alterItem(BlockSnapshot block, Item item, EventInformation eventInformation) {
if (item.getItemType() != ItemTypes.MOB_SPAWNER) return item;
// TODO: Pending https://github.com/SpongePowered/SpongeCommon/pull/710
//item.offer(Keys.SPAWNER_ENTITIES, block.get(Keys.SPAWNER_ENTITIES).get());
//item.offer(Keys.SPAWNER_NEXT_ENTITY_TO_SPAWN, block.get(Keys.SPAWNER_NEXT_ENTITY_TO_SPAWN).get());
return item;
}
示例15: dropItem
import org.spongepowered.api.entity.Item; //导入依赖的package包/类
/**
* Faire drop un item pied du joueur
* @param itemstack L'itemstack
*/
public void dropItem(final ItemStack itemstack) {
Entity entity = this.getWorld().createEntity(EntityTypes.ITEM, this.getLocation().getPosition());
if (entity instanceof Item) {
Item item = (Item) entity;
item.offer(Keys.REPRESENTED_ITEM, itemstack.createSnapshot());
this.getWorld().spawnEntity(item, Cause.source(this.getPlayer().get()).build());
}
}