diff --git a/api/src/main/java/com/lishid/openinv/internal/IAnySilentContainer.java b/api/src/main/java/com/lishid/openinv/internal/IAnySilentContainer.java index 8c59530..f87ac6b 100644 --- a/api/src/main/java/com/lishid/openinv/internal/IAnySilentContainer.java +++ b/api/src/main/java/com/lishid/openinv/internal/IAnySilentContainer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2022 lishid. All rights reserved. + * Copyright (C) 2011-2023 lishid. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,6 @@ package com.lishid.openinv.internal; -import org.bukkit.Material; import org.bukkit.block.Barrel; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -148,13 +147,20 @@ public interface IAnySilentContainer { * @return true if the type is a supported container */ default boolean isAnySilentContainer(@NotNull Block block) { - if (block.getType() == Material.ENDER_CHEST) { - return true; - } - BlockState state = block.getState(); - return state instanceof org.bukkit.block.Chest - || state instanceof org.bukkit.block.ShulkerBox - || state instanceof org.bukkit.block.Barrel; + return isAnySilentContainer(block.getState()); + } + + /** + * Check if the given {@link BlockState} is a container which can be unblocked or silenced. + * + * @param blockState the potential container + * @return true if the type is a supported container + */ + default boolean isAnySilentContainer(@NotNull BlockState blockState) { + return blockState instanceof org.bukkit.block.EnderChest + || blockState instanceof org.bukkit.block.Chest + || blockState instanceof org.bukkit.block.ShulkerBox + || blockState instanceof org.bukkit.block.Barrel; } } diff --git a/internal/v1_18_R2/src/main/java/com/lishid/openinv/internal/v1_18_R2/AnySilentContainer.java b/internal/v1_18_R2/src/main/java/com/lishid/openinv/internal/v1_18_R2/AnySilentContainer.java index 7fae7c5..77aac17 100644 --- a/internal/v1_18_R2/src/main/java/com/lishid/openinv/internal/v1_18_R2/AnySilentContainer.java +++ b/internal/v1_18_R2/src/main/java/com/lishid/openinv/internal/v1_18_R2/AnySilentContainer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2022 lishid. All rights reserved. + * Copyright (C) 2011-2023 lishid. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,12 +50,12 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.Statistic; import org.bukkit.block.ShulkerBox; import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -231,21 +231,10 @@ public class AnySilentContainer implements IAnySilentContainer { @Override public void deactivateContainer(@NotNull final Player bukkitPlayer) { - if (this.serverPlayerGameModeGameType == null) { + if (this.serverPlayerGameModeGameType == null || bukkitPlayer.getGameMode() == GameMode.SPECTATOR) { return; } - InventoryView view = bukkitPlayer.getOpenInventory(); - switch (view.getType()) { - case CHEST: - case ENDER_CHEST: - case SHULKER_BOX: - case BARREL: - break; - default: - return; - } - ServerPlayer player = PlayerDataManager.getHandle(bukkitPlayer); // Force game mode change without informing plugins or players. diff --git a/internal/v1_19_R1/src/main/java/com/lishid/openinv/internal/v1_19_R1/AnySilentContainer.java b/internal/v1_19_R1/src/main/java/com/lishid/openinv/internal/v1_19_R1/AnySilentContainer.java index df53746..9d4be84 100644 --- a/internal/v1_19_R1/src/main/java/com/lishid/openinv/internal/v1_19_R1/AnySilentContainer.java +++ b/internal/v1_19_R1/src/main/java/com/lishid/openinv/internal/v1_19_R1/AnySilentContainer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2022 lishid. All rights reserved. + * Copyright (C) 2011-2023 lishid. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,12 +50,12 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.Statistic; import org.bukkit.block.ShulkerBox; import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -231,21 +231,10 @@ public class AnySilentContainer implements IAnySilentContainer { @Override public void deactivateContainer(@NotNull final Player bukkitPlayer) { - if (this.serverPlayerGameModeGameType == null) { + if (this.serverPlayerGameModeGameType == null || bukkitPlayer.getGameMode() == GameMode.SPECTATOR) { return; } - InventoryView view = bukkitPlayer.getOpenInventory(); - switch (view.getType()) { - case CHEST: - case ENDER_CHEST: - case SHULKER_BOX: - case BARREL: - break; - default: - return; - } - ServerPlayer player = PlayerDataManager.getHandle(bukkitPlayer); // Force game mode change without informing plugins or players. diff --git a/internal/v1_19_R2/src/main/java/com/lishid/openinv/internal/v1_19_R2/AnySilentContainer.java b/internal/v1_19_R2/src/main/java/com/lishid/openinv/internal/v1_19_R2/AnySilentContainer.java index 3abd77a..37f1325 100644 --- a/internal/v1_19_R2/src/main/java/com/lishid/openinv/internal/v1_19_R2/AnySilentContainer.java +++ b/internal/v1_19_R2/src/main/java/com/lishid/openinv/internal/v1_19_R2/AnySilentContainer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2022 lishid. All rights reserved. + * Copyright (C) 2011-2023 lishid. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,12 +50,12 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.Statistic; import org.bukkit.block.ShulkerBox; import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -227,21 +227,10 @@ public class AnySilentContainer implements IAnySilentContainer { @Override public void deactivateContainer(@NotNull final Player bukkitPlayer) { - if (this.serverPlayerGameModeGameType == null) { + if (this.serverPlayerGameModeGameType == null || bukkitPlayer.getGameMode() == GameMode.SPECTATOR) { return; } - InventoryView view = bukkitPlayer.getOpenInventory(); - switch (view.getType()) { - case CHEST: - case ENDER_CHEST: - case SHULKER_BOX: - case BARREL: - break; - default: - return; - } - ServerPlayer player = PlayerDataManager.getHandle(bukkitPlayer); // Force game mode change without informing plugins or players. diff --git a/plugin/src/main/java/com/lishid/openinv/InventoryListener.java b/plugin/src/main/java/com/lishid/openinv/InventoryListener.java index 61a08a4..cf59582 100644 --- a/plugin/src/main/java/com/lishid/openinv/InventoryListener.java +++ b/plugin/src/main/java/com/lishid/openinv/InventoryListener.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2022 lishid. All rights reserved. + * Copyright (C) 2011-2023 lishid. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import org.bukkit.GameMode; +import org.bukkit.block.Container; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -53,7 +54,9 @@ record InventoryListener(OpenInv plugin) implements Listener { return; } - if (this.plugin.getSilentContainerStatus(player)) { + if (this.plugin.getSilentContainerStatus(player) + && event.getInventory().getHolder() instanceof Container container + && this.plugin.getAnySilentContainer().isAnySilentContainer(container)) { this.plugin.getAnySilentContainer().deactivateContainer(player); }