Java源码示例:org.spongepowered.api.event.item.inventory.ChangeInventoryEvent

示例1
@Listener(order = Order.LAST, beforeModifications = true)
public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {
    if (!GDFlags.ITEM_PICKUP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_PICKUP.getName(), event.getTargetEntity(), player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_PICKUP_ITEM_EVENT.startTimingIfSync();
    final World world = player.getWorld();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, player.getUniqueId());
    Location<World> location = player.getLocation();
    GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_PICKUP, player, event.getTargetEntity(), player, true) == Tristate.FALSE) {
        event.setCancelled(true);
    }

    GDTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
}
 
示例2
@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());
			}
		}
	}
}
 
示例3
@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());
			}
		}
	}
}
 
示例4
@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());
			}
		}
	}
}
 
示例5
@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();
            CommentedConfigurationNode node = hnode.getNode("items", item.getType().getKey());
            if (!node.isVirtual()) {
                if (node.getNode("deny-possession").getBoolean()) {
                    s.poll();
                }
            }
        }
    } catch (Exception ignore) {
    }
}
 
示例6
/**
 * Saves event records when a player picks up an item off of the ground.
 *
 * @param event  ChangeInventoryEvent.Pickup
 * @param player Player
 */
@Listener(order = Order.POST)
public void onChangeInventoryPickup(ChangeInventoryEvent.Pickup event, @Root Player player) {
    if (event.getTransactions().isEmpty() || !Prism.getInstance().getConfig().getEventCategory().isItemPickup()) {
        return;
    }

    for (SlotTransaction transaction : event.getTransactions()) {
        ItemStackSnapshot itemStack = transaction.getFinal();
        int quantity = itemStack.getQuantity();
        if (transaction.getOriginal().getType() != ItemTypes.NONE) {
            quantity -= transaction.getOriginal().getQuantity();
        }

        Prism.getInstance().getLogger().debug("Inventory pickup - {} x{}", itemStack.getType().getId(), quantity);

        PrismRecord.create()
                .source(event.getCause())
                .event(PrismEvents.ITEM_PICKUP)
                .itemStack(itemStack, quantity)
                .location(player.getLocation())
                .buildAndSave();
    }
}
 
示例7
@Listener
public void onPickup(ChangeInventoryEvent.Pickup event, @First Player p) {
    ModuleConfig config = Modules.BLACKLIST.get().getConfig().get();
    CommentedConfigurationNode hnode = config.get();
    for(SlotTransaction trans : event.getTransactions()){
        ItemStack item = trans.getSlot().peek();
        CommentedConfigurationNode node = hnode.getNode("items", item.getType().getId());
        if (!node.isVirtual()) {
            if (node.getNode("deny-drop").getBoolean()) {
                trans.setValid(false);
            }
        }
    }
}
 
示例8
@Listener
public void onPickup(ChangeInventoryEvent.Pickup event, @First Player p) {
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);
    if (!up.get(VanishKeys.VANISH).get()) {
        return;
    }
    ModuleConfig config = Modules.VANISH.get().getConfig().get();
    if (!config.get().getNode("events", "pickup").getBoolean()) {
        event.setCancelled(true);
    }
}
 
示例9
@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;
    }
    if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_PICKUP.toString(), event.getTargetEntity(), 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, TrustType.ACCESSOR, true) == Tristate.FALSE) {
        event.setCancelled(true);
        GPTimings.PLAYER_PICKUP_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();
}
 
示例10
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerItemPickup(ChangeInventoryEvent.Pickup pickupItemEvent, @Root Player player) {
    checkLoginStatus(pickupItemEvent, player);
}
 
示例11
@Exclude(NumberPress.class)
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInventoryChange(ChangeInventoryEvent changeInventoryEvent, @First Player player) {
    checkLoginStatus(changeInventoryEvent, player);
}