org.spongepowered.api.event.item.inventory.ChangeInventoryEvent Java Examples

The following examples show how to use org.spongepowered.api.event.item.inventory.ChangeInventoryEvent. 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: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@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();
}
 
Example #2
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@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());
			}
		}
	}
}
 
Example #3
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@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());
			}
		}
	}
}
 
Example #4
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@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());
			}
		}
	}
}
 
Example #5
Source File: ItemListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@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) {
    }
}
 
Example #6
Source File: InventoryListener.java    From Prism with MIT License 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #7
Source File: ItemListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@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);
            }
        }
    }
}
 
Example #8
Source File: VanishListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example #9
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@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();
}
 
Example #10
Source File: PreventListener.java    From FlexibleLogin with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerItemPickup(ChangeInventoryEvent.Pickup pickupItemEvent, @Root Player player) {
    checkLoginStatus(pickupItemEvent, player);
}
 
Example #11
Source File: PreventListener.java    From FlexibleLogin with MIT License 4 votes vote down vote up
@Exclude(NumberPress.class)
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInventoryChange(ChangeInventoryEvent changeInventoryEvent, @First Player player) {
    checkLoginStatus(changeInventoryEvent, player);
}