Java Code Examples for org.spongepowered.api.event.item.inventory.InteractInventoryEvent#Close

The following examples show how to use org.spongepowered.api.event.item.inventory.InteractInventoryEvent#Close . 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.FIRST, beforeModifications = true)
public void onPlayerInteractInventoryClose(InteractInventoryEvent.Close event, @Root Player player) {
    final ItemStackSnapshot cursor = event.getCursorTransaction().getOriginal();
    if (cursor == ItemStackSnapshot.NONE || !GDFlags.ITEM_DROP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_DROP.getName(), cursor, player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.startTimingIfSync();
    final Location<World> location = player.getLocation();
    final GDClaim claim = this.dataStore.getClaimAt(location);
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_DROP, player, cursor, player, TrustTypes.ACCESSOR, true) == Tristate.FALSE) {
        final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ITEM_DROP,
                ImmutableMap.of(
                "player", claim.getOwnerName(),
                "item", cursor.getType().getId()));
        GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message);
        event.setCancelled(true);
    }

    GDTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.stopTimingIfSync();
}
 
Example 2
Source File: VirtualChestInventory.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void fireCloseEvent(InteractInventoryEvent.Close e)
{
    Optional<Player> optional = Sponge.getServer().getPlayer(playerUniqueId);
    if (optional.isPresent())
    {
        Player player = optional.get();
        UUID actionUUID = UUID.randomUUID();
        ClassToInstanceMap<Context> context = getContextMap(player, actionUUID);
        boolean record = recordManager.filter(name, VirtualChestInventory.this);
        if (record)
        {
            recordManager.recordClose(actionUUID, name, player);
            logger.debug("Player {} closes the chest GUI", player.getName());
        }
        plugin.getVirtualChestActions().submitCommands(player, parsedCloseAction.stream(), context, record);

        actionIntervalManager.onClosingInventory(player);
    }
}
 
Example 3
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteractInventoryClose(InteractInventoryEvent.Close event, @Root Player player) {
    final ItemStackSnapshot cursor = event.getCursorTransaction().getOriginal();
    if (cursor == ItemStackSnapshot.NONE || !GPFlags.ITEM_DROP || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }
    if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_DROP.toString(), cursor, player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.startTimingIfSync();
    final Location<World> location = player.getLocation();
    final GPClaim claim = this.dataStore.getClaimAt(location);
    if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_DROP, player, cursor, player, TrustType.ACCESSOR, true) == Tristate.FALSE) {
        Text message = GriefPreventionPlugin.instance.messageData.permissionItemDrop
                .apply(ImmutableMap.of(
                "owner", claim.getOwnerName(),
                "item", cursor.getType().getId())).build();
        GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message);
        event.setCancelled(true);
    }

    GPTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.stopTimingIfSync();
}
 
Example 4
Source File: ItemFlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onCloseInventory(InteractInventoryEvent.Close event) {
    if (event.getTargetInventory().getName().get().equals(this.player.getInventory().getName().get())) {
        return;
    }

    StringBuilder str = new StringBuilder();

    event.getTargetInventory().forEach(inv -> {
        if (inv.capacity() == 54) {
            StreamSupport.stream(inv.slots().spliterator(), false)
                    .filter(i -> i.peek().isPresent()).map(i -> i.peek().get().getItem().getName()).distinct()
                    .forEach(i -> str.append(i).append(","));
        }
    });

    if (str.length() > 0) {
        region.setFlag(RedProtect.get().getVersionHelper().getCause(this.player), flag, str.toString().substring(0, str.toString().length() - 1));
        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.region.flag.set").replace("{flag}", "'" + flag + "'") + " " + region.getFlagString(flag));
        RedProtect.get().logger.addLog("(World " + region.getWorld() + ") Player " + player.getName() + " SET FLAG " + flag + " of region " + region.getName() + " to " + region.getFlagString(flag));
    } else {
        region.removeFlag(flag);
        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.region.flag.removed").replace("{flag}", flag).replace("{region}", region.getName()));
        RedProtect.get().logger.addLog("(World " + region.getWorld() + ") Player " + player.getName() + " REMOVED FLAG " + flag + " of region " + region.getName());
    }

    close(false);
}
 
Example 5
Source File: FlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onCloseInventory(InteractInventoryEvent.Close event) {
    if (event.getTargetInventory().getName().get().equals(this.inv.getName().get())) {
        if (this.editable) {
            for (int i = 0; i < this.size; i++) {
                try {
                    int line = 0;
                    int slot = i;
                    if (i > 8) {
                        line = i / 9;
                        slot = i - (line * 9);
                    }
                    if (RedProtect.get().getVersionHelper().query(event.getTargetInventory(), slot, line).peek().isPresent()) {
                        final int fi = i;
                        ItemStack stack = RedProtect.get().getVersionHelper().query(event.getTargetInventory(), slot, line).peek().get();
                        stack.get(Keys.ITEM_LORE).ifPresent(ls -> {
                            String flag = ls.get(1).toPlain().replace("ยง0", "");
                            if (RedProtect.get().config.getDefFlags().contains(flag))
                                RedProtect.get().config.setGuiSlot(flag, fi);
                        });
                    }
                } catch (Exception e) {
                    RedProtect.get().lang.sendMessage(this.player, "gui.edit.error");
                    close(false);
                    CoreUtil.printJarVersion();
                    e.printStackTrace();
                    return;
                }
            }
            RedProtect.get().config.saveGui();
            RedProtect.get().lang.sendMessage(this.player, "gui.edit.ok");
        }
        close(false);
    }
}
 
Example 6
Source File: MobFlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onCloseInventory(InteractInventoryEvent.Close event) {
    if (event.getTargetInventory().getName().get().equals(this.player.getInventory().getName().get())) {
        return;
    }

    StringBuilder str = new StringBuilder();

    event.getTargetInventory().forEach(inv -> {
        if (inv.capacity() == 54) {
            StreamSupport.stream(inv.slots().spliterator(), false)
                    .filter(i -> i.peek().isPresent()).map(i -> i.peek().get().getItem().getName()).distinct()
                    .forEach(i -> str.append(i).append(","));
        }
    });

    if (str.length() > 0) {
        region.setFlag(RedProtect.get().getVersionHelper().getCause(this.player), flag, str.toString().substring(0, str.toString().length() - 1));
        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.region.flag.set").replace("{flag}", "'" + flag + "'") + " " + region.getFlagString(flag));
        RedProtect.get().logger.addLog("(World " + region.getWorld() + ") Player " + player.getName() + " SET FLAG " + flag + " of region " + region.getName() + " to " + region.getFlagString(flag));
    } else {
        region.removeFlag(flag);
        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.region.flag.removed").replace("{flag}", flag).replace("{region}", region.getName()));
        RedProtect.get().logger.addLog("(World " + region.getWorld() + ") Player " + player.getName() + " REMOVED FLAG " + flag + " of region " + region.getName());
    }

    close(false);
}
 
Example 7
Source File: InventoryListener.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Saves event records when a player closes or opens an Inventory.
 *
 * @param event  InteractInventoryEvent
 * @param player Player
 */
@Listener(order = Order.POST)
public void onInteractInventory(InteractInventoryEvent event, @Root Player player) {
    if (!(event.getTargetInventory() instanceof CarriedInventory)
            || (!Prism.getInstance().getConfig().getEventCategory().isInventoryClose() && !Prism.getInstance().getConfig().getEventCategory().isInventoryOpen())) {
        return;
    }

    CarriedInventory<? extends Carrier> carriedInventory = (CarriedInventory<? extends Carrier>) event.getTargetInventory();
    if (carriedInventory.getCarrier().filter(Player.class::isInstance).isPresent()) {
        return;
    }

    // Get the location of the inventory otherwise fallback on the players location
    Location<World> location = carriedInventory.getCarrier()
            .filter(Locatable.class::isInstance)
            .map(Locatable.class::cast)
            .map(Locatable::getLocation)
            .orElse(player.getLocation());

    // Get the title of the inventory otherwise fallback on the class name
    String title = carriedInventory.getProperty(InventoryTitle.class, InventoryTitle.PROPERTY_NAME)
            .map(InventoryTitle::getValue)
            .map(Text::toPlain)
            .orElse(carriedInventory.getClass().getSimpleName());

    PrismRecord.EventBuilder eventBuilder = PrismRecord.create()
            .source(event.getCause())
            .container(title)
            .location(location);

    if (event instanceof InteractInventoryEvent.Close && Prism.getInstance().getConfig().getEventCategory().isInventoryClose()) {
        eventBuilder.event(PrismEvents.INVENTORY_CLOSE).buildAndSave();
    } else if (event instanceof InteractInventoryEvent.Open && Prism.getInstance().getConfig().getEventCategory().isInventoryOpen()) {
        eventBuilder.event(PrismEvents.INVENTORY_OPEN).buildAndSave();
    }
}
 
Example 8
Source File: WebHookService.java    From Web-API with MIT License 4 votes vote down vote up
@Listener(order = Order.POST)
public void onInteractInventory(InteractInventoryEvent.Close event) {
    notifyHooks(WebHookService.WebHookType.INVENTORY_CLOSE, event);
}
 
Example 9
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void PlayerMoveInv(InteractInventoryEvent.Close e, @Root Player p) {
    RedProtect.get().getVersionHelper().removeGuiItem(p);
}
 
Example 10
Source File: InventoryListener.java    From UltimateCore with MIT License 4 votes vote down vote up
@Listener
public void onCloseInventory(InteractInventoryEvent.Close event, @Root Player p) {
    //Player closed invsee
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);
    up.offer(InventoryKeys.INVSEE_TARGET, null);
}