本文整理汇总了Java中org.spongepowered.api.event.item.inventory.ChangeInventoryEvent类的典型用法代码示例。如果您正苦于以下问题:Java ChangeInventoryEvent类的具体用法?Java ChangeInventoryEvent怎么用?Java ChangeInventoryEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChangeInventoryEvent类属于org.spongepowered.api.event.item.inventory包,在下文中一共展示了ChangeInventoryEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pickupItem
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener(order = Order.POST)
@Exclude({ChangeInventoryEvent.Pickup.Pre.class})
public void pickupItem(ChangeInventoryEvent.Pickup event, @Root Player player) {
List<SlotTransaction> transactions = event.getTransactions();
if (transactions.isEmpty()) {
return;
}
int itemQuantity = transactions.get(0).getFinal().getQuantity() - transactions.get(0).getOriginal().getQuantity();
// Sometimes it's 0 for some odd reason
if (itemQuantity == 0) {
return;
}
processEvent(event, player, itemQuantity);
}
示例2: tryInteract
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Override
public BehaviorResult tryInteract(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
final LanternPlayer player = (LanternPlayer) context.requireContext(ContextKeys.PLAYER);
final ItemStack itemStack = context.requireContext(ContextKeys.USED_ITEM_STACK);
final PeekedOfferTransactionResult peekResult = player.getInventory().getEquipment().peekOffer(itemStack.copy());
if (peekResult.isSuccess()) {
final List<SlotTransaction> transactions = new ArrayList<>(peekResult.getTransactions());
final AbstractSlot slot = (AbstractSlot) context.getContext(ContextKeys.USED_SLOT).orElse(null);
if (slot != null) {
transactions.add(new SlotTransaction(
slot, itemStack.createSnapshot(), LanternItemStack.toSnapshot(peekResult.getRejectedItem().orElse(null))));
}
final ChangeInventoryEvent.Equipment event = SpongeEventFactory.createChangeInventoryEventEquipment(
context.getCurrentCause(), player.getInventory(), transactions);
if (event.isCancelled()) {
return BehaviorResult.CONTINUE;
}
event.getTransactions().stream().filter(Transaction::isValid).forEach(slotTransaction ->
slotTransaction.getSlot().set(slotTransaction.getFinal().createStack()));
return BehaviorResult.SUCCESS;
}
return BehaviorResult.CONTINUE;
}
示例3: finishInventoryEvent
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
private void finishInventoryEvent(ChangeInventoryEvent event) {
final List<SlotTransaction> slotTransactions = event.getTransactions();
Sponge.getEventManager().post(event);
if (!event.isCancelled()) {
if (!(event instanceof ClickInventoryEvent.Creative) && event instanceof ClickInventoryEvent) {
final Transaction<ItemStackSnapshot> cursorTransaction = ((ClickInventoryEvent) event).getCursorTransaction();
if (cursorTransaction.isValid()) {
setCursorItem(cursorTransaction.getFinal().createStack());
}
}
slotTransactions.stream().filter(Transaction::isValid).forEach(
transaction -> transaction.getSlot().set(transaction.getFinal().createStack()));
if (event instanceof SpawnEntityEvent) {
LanternWorld.finishSpawnEntityEvent((SpawnEntityEvent) event);
}
}
}
示例4: onChangeHeldItem
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener
public void onChangeHeldItem(ChangeInventoryEvent.Held event, @Root Player player)
{
if (!player.hasPermission("essentialcmds.blacklist.bypass"))
{
for (SlotTransaction transaction : event.getTransactions())
{
if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
{
if (Utils.areBlacklistMsgsEnabled())
player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));
transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
}
}
}
}
示例5: onChangeEquipment
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener
public void onChangeEquipment(ChangeInventoryEvent.Equipment event, @Root Player player)
{
if (!player.hasPermission("essentialcmds.blacklist.bypass"))
{
for (SlotTransaction transaction : event.getTransactions())
{
if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
{
if (Utils.areBlacklistMsgsEnabled())
player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));
transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
}
}
}
}
示例6: onPickupItem
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener
public void onPickupItem(ChangeInventoryEvent.Pickup event, @Root Player player)
{
if (!player.hasPermission("essentialcmds.blacklist.bypass"))
{
for (SlotTransaction transaction : event.getTransactions())
{
if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
{
if (Utils.areBlacklistMsgsEnabled())
player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));
transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
}
}
}
}
示例7: onChange
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener
public void onChange(ChangeInventoryEvent event, @First Player p) {
ModuleConfig config = Modules.BLACKLIST.get().getConfig().get();
CommentedConfigurationNode hnode = config.get();
try {
for (Inventory s : event.getTargetInventory().slots()) {
ItemStack item = s.peek().orElse(null);
if (item == null) continue;
CommentedConfigurationNode node = hnode.getNode("items", item.getItem().getId());
if (!node.isVirtual()) {
if (node.getNode("deny-possession").getBoolean()) {
s.poll();
}
}
}
} catch (Exception ignore) {
}
}
示例8: onPlayerItemPickUp
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener
public void onPlayerItemPickUp(ChangeInventoryEvent.Pickup event, @First Player player) {
if (!Config.Values.Synchronize.getEnableInventory())
return;
synchronized (waitingPlayers) {
if (waitingPlayers.containsKey(player.getUniqueId())) {
event.setCancelled(true);
}
}
}
示例9: onChangeInventory
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener(order = Order.POST)
public void onChangeInventory(ChangeInventoryEvent event) {
if (event.getTargetInventory() instanceof CarriedInventory<?>) {
Optional<?> carrier = ((CarriedInventory) event.getTargetInventory()).getCarrier();
if (carrier.isPresent() && carrier.get() instanceof TileEntityCarrier) {
checkBlockChange(((TileEntityCarrier) carrier.get()).getLocation().createSnapshot());
}
}
}
示例10: onPlayerChangeInventory
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener
public void onPlayerChangeInventory(ChangeInventoryEvent event, @First Player player_sponge) {
EPlayer player = this.plugin.getEServer().getEPlayer(player_sponge);
// AFK
player.updateLastActivated();
}
示例11: onItemPickup
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener
public void onItemPickup(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {
ItemType itemType = event.getOriginalStack().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.pickup." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to pick up " + itemType.getName() + '!'));
}
}
示例12: onPlayerPickupItem
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener(order = Order.LAST, beforeModifications = true)
public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {
if (!GPFlags.ITEM_PICKUP || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
return;
}
GPTimings.PLAYER_PICKUP_ITEM_EVENT.startTimingIfSync();
final World world = player.getWorld();
GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, player.getUniqueId());
Location<World> location = player.getLocation();
GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_PICKUP, player, event.getTargetEntity(), player, true) == Tristate.FALSE) {
event.setCancelled(true);
GPTimings.PLAYER_USE_ITEM_EVENT.stopTimingIfSync();
return;
}
// the rest of this code is specific to pvp worlds
if (claim.pvpRulesApply()) {
// if we're preventing spawn camping and the player was previously empty handed...
if (GriefPreventionPlugin.getActiveConfig(world.getProperties()).getConfig().pvp.protectFreshSpawns && PlayerUtils.hasItemInOneHand(player, ItemTypes.NONE)) {
// if that player is currently immune to pvp
if (playerData.pvpImmune) {
// if it's been less than 10 seconds since the last time he spawned, don't pick up the item
long now = Calendar.getInstance().getTimeInMillis();
long elapsedSinceLastSpawn = now - playerData.lastSpawn;
if (elapsedSinceLastSpawn < 10000) {
event.setCancelled(true);
GPTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
return;
}
// otherwise take away his immunity. he may be armed now. at least, he's worth killing for some loot
playerData.pvpImmune = false;
GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.pvpImmunityEnd.toText());
}
}
}
GPTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
}
示例13: onChangeInventory
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
@Listener
public void onChangeInventory(ChangeInventoryEvent event, @First Player player,
@Getter("getTargetInventory") CarriedInventory<?> container) {
if (!container.getName().get().equals("Furnace")) {
return;
}
final Carrier carrier = container.getCarrier().orElse(null);
if (!(carrier instanceof Furnace)) {
return;
}
final Furnace furnace = (Furnace) carrier;
final int passed = furnace.passedBurnTime().get();
final int max = furnace.maxBurnTime().get();
if (max <= 0 || passed >= max) {
return;
}
for (SlotTransaction transaction : event.getTransactions()) {
if (container.getInventoryProperty(transaction.getSlot(), SlotIndex.class).get().getValue() == 0) {
if (transaction.getFinal().getType() == ItemTypes.DIRT) {
player.getProgress(this.cookDirtAdvancement).grant();
} else if (this.suicidalAdvancement != null && (transaction.getFinal().getType() == ItemTypes.TNT ||
transaction.getFinal().getType() == ItemTypes.TNT_MINECART)) {
player.getProgress(this.suicidalAdvancement).grant();
/*
final Explosion explosion = Explosion.builder()
.location(furnace.getLocation())
.shouldBreakBlocks(true)
.canCauseFire(true)
.shouldDamageEntities(true)
.radius(7)
.build();
explosion.getWorld().triggerExplosion(explosion);
*/
}
}
}
}
示例14: handle
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Override
public void handle(NetworkContext context, MessagePlayInSwapHandItems message) {
final LanternPlayer player = context.getSession().getPlayer();
final LanternPlayerInventory inventory = player.getInventory();
final AbstractSlot hotbarSlot = inventory.getHotbar().getSelectedSlot();
final AbstractSlot offHandSlot = inventory.getOffhand();
final ItemStackSnapshot hotbarItem = hotbarSlot.peek().map(ItemStack::createSnapshot).orElse(ItemStackSnapshot.NONE);
final ItemStackSnapshot offHandItem = offHandSlot.peek().map(ItemStack::createSnapshot).orElse(ItemStackSnapshot.NONE);
final List<SlotTransaction> transactions = new ArrayList<>();
transactions.add(new SlotTransaction(hotbarSlot, hotbarItem, offHandItem));
transactions.add(new SlotTransaction(offHandSlot, offHandItem, hotbarItem));
try (CauseStack.Frame frame = CauseStack.current().pushCauseFrame()) {
frame.addContext(EventContextKeys.PLAYER, player);
frame.pushCause(player);
final ChangeInventoryEvent.SwapHand event = SpongeEventFactory.createChangeInventoryEventSwapHand(
frame.getCurrentCause(), inventory, transactions);
Sponge.getEventManager().post(event);
if (!event.isCancelled()) {
transactions.stream().filter(Transaction::isValid).forEach(
transaction -> transaction.getSlot().set(transaction.getFinal().createStack()));
final PlayerInventoryContainer inventoryContainer = context.getSession().getPlayer().getInventoryContainer();
inventoryContainer.getClientContainer().queueSilentSlotChange(hotbarSlot);
}
}
}
示例15: onItemCraft
import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; //导入依赖的package包/类
@Listener
@Exclude(value = ChangeInventoryEvent.Held.class)
public void onItemCraft(ChangeInventoryEvent event) {
event.getTransactions().forEach((t) -> {
if (blockedItems.contains(t.getFinal().getType().getId())) {
Optional<Player> optPlayer = event.getCause().first(Player.class);
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
player.sendMessage(Text.of(TextColors.RED, "This item has been disabled."));
}
event.setCancelled(true);
}
});
}