diff --git a/UPDATING.md b/UPDATING.md index 2ea4564ed..31fff489d 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -109,12 +109,13 @@ to make vane compatible with a new minecraft release. Enter the server. Now it is important to test those parts of vane which interface with the mojang mappings, since those are the most likely to break. - - `/customitem give sickle` should display as a sickle, should work when used on wheat. (Tests custom item registration and event dispatching) - - Take an elytra in your hand, run `/enchant angel 1`, test whether you can fly. (Tests custom enchantment registration) + - `/customitem give vane_trifles:golden_sickle` should display as a sickle, should work when used on wheat. (Tests custom item registration and event dispatching) + - Take an elytra in your hand, run `/enchant vane_enchantments:angel`, test whether you can accelerate by sneaking. (Tests custom enchantment registration) - Duplicate the elytra, go into survival mode (IMPORTANT!) then combine them on an anvil. You should get Angel II. + - Take a smithing table, combine the elytra with a netherite ingot. (Test's complex smithing recipe integration) - Put some random blocks and items in a chest, place a button next to it and press it. The chest should now be sorted. - Fix issues if necessary, make a new commit. + Fix issues and make a new commit if necessary. 12. Copy the generated resource pack to `docs/resourcepacks/.zip`, and update vane's version numer in `build.gradle.kts` (always bump minor version for mojang version updates). diff --git a/vane-regions/src/main/java/org/oddlama/vane/regions/Regions.java b/vane-regions/src/main/java/org/oddlama/vane/regions/Regions.java index 36646884a..3a8b3160e 100644 --- a/vane-regions/src/main/java/org/oddlama/vane/regions/Regions.java +++ b/vane-regions/src/main/java/org/oddlama/vane/regions/Regions.java @@ -122,6 +122,9 @@ public class Regions extends Module { @ConfigBoolean(def = false, desc = "Use economy via VaultAPI as currency provider.") public boolean config_economy_as_currency; + @ConfigBoolean(def = false, desc = "Enable this to prevent players without the conatiner permission from being able to view chests.") + public boolean config_prohibit_viewing_containers; + @ConfigInt( def = 0, min = -1, diff --git a/vane-regions/src/main/java/org/oddlama/vane/regions/event/RegionRoleSettingEnforcer.java b/vane-regions/src/main/java/org/oddlama/vane/regions/event/RegionRoleSettingEnforcer.java index eb0d750a7..02ec456e8 100644 --- a/vane-regions/src/main/java/org/oddlama/vane/regions/event/RegionRoleSettingEnforcer.java +++ b/vane-regions/src/main/java/org/oddlama/vane/regions/event/RegionRoleSettingEnforcer.java @@ -22,6 +22,7 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryInteractEvent; +import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; @@ -226,6 +227,31 @@ public void on_player_interact(final PlayerInteractEvent event) { } } + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void on_player_inventory_open(final InventoryOpenEvent event) { + // Only relevant if viewing should be prohibited, too. + if (!get_module().config_prohibit_viewing_containers) { + return; + } + + if (!(event.getPlayer() instanceof Player player)) { + return; + } + + final var inventory = event.getInventory(); + if (inventory.getLocation() == null || inventory.getHolder() == null) { + // Inventory is virtual / transient + return; + } + + final var holder = inventory.getHolder(); + if (holder instanceof DoubleChest || holder instanceof Container || holder instanceof Minecart) { + if (check_setting_at(inventory.getLocation(), player, RoleSetting.CONTAINER, false)) { + event.setCancelled(true); + } + } + } + public void on_player_inventory_interact(final InventoryInteractEvent event) { final var clicker = event.getWhoClicked(); if (!(clicker instanceof Player)) {