Skip to content

Commit

Permalink
feat: implement region config prohibit_viewing_containers
Browse files Browse the repository at this point in the history
  • Loading branch information
oddlama committed Mar 19, 2023
1 parent 827e427 commit d714de6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
7 changes: 4 additions & 3 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<new_version>.zip`, and update
vane's version numer in `build.gradle.kts` (always bump minor version for mojang version updates).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public class Regions extends Module<Regions> {
@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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit d714de6

Please sign in to comment.