Skip to content

Commit

Permalink
Added flags for Loom, stonecutter, cartography, smithing, grinding
Browse files Browse the repository at this point in the history
Fixes #2194 and #2193
  • Loading branch information
tastybento committed Oct 7, 2023
1 parent 8b78aff commit e6ccce4
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,27 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.AbstractHorseInventory;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.BeaconInventory;
import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.CartographyInventory;
import org.bukkit.inventory.ChiseledBookshelfInventory;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.DoubleChestInventory;
import org.bukkit.inventory.EnchantingInventory;
import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.GrindstoneInventory;
import org.bukkit.inventory.HorseInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.JukeboxInventory;
import org.bukkit.inventory.LecternInventory;
import org.bukkit.inventory.LlamaInventory;
import org.bukkit.inventory.LoomInventory;
import org.bukkit.inventory.MerchantInventory;
import org.bukkit.inventory.SmithingInventory;
import org.bukkit.inventory.StonecutterInventory;

import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;
Expand Down Expand Up @@ -71,12 +90,10 @@ public void onInventoryClick(InventoryClickEvent e)
{
Player player = (Player) e.getWhoClicked();

// Enchanting
if (e.getInventory() instanceof EnchantingInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.ENCHANTING);
// Special inventory types
if (checkSpecificInventories(e, player, e.getInventory())) {
return;
}

// Inventory holders
InventoryHolder inventoryHolder = e.getInventory().getHolder();

Expand Down Expand Up @@ -149,6 +166,69 @@ else if (!(inventoryHolder instanceof Player))
}


private boolean checkSpecificInventories(InventoryClickEvent e, Player player, Inventory inventory) {
if (e.getInventory() instanceof AbstractHorseInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
return true;
} else if (e.getInventory() instanceof AnvilInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.ANVIL);
return true;
} else if (e.getInventory() instanceof BeaconInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.BEACON);
return true;
} else if (e.getInventory() instanceof BrewerInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.BREWING);
return true;
} else if (e.getInventory() instanceof CartographyInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.CARTOGRAPHY);
return true;
} else if (e.getInventory() instanceof ChiseledBookshelfInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.BOOKSHELF);
return true;
} else if (e.getInventory() instanceof CraftingInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.CRAFTING);
return true;
} else if (e.getInventory() instanceof DoubleChestInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.CHEST);
return true;
} else if (e.getInventory() instanceof EnchantingInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.ENCHANTING);
return true;
} else if (e.getInventory() instanceof FurnaceInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.FURNACE);
return true;
} else if (e.getInventory() instanceof GrindstoneInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.GRINDSTONE);
return true;
} else if (e.getInventory() instanceof HorseInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
return true;
} else if (e.getInventory() instanceof JukeboxInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.JUKEBOX);
return true;
} else if (e.getInventory() instanceof LecternInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.LECTERN);
return true;
} else if (e.getInventory() instanceof LlamaInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
return true;
} else if (e.getInventory() instanceof LoomInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.LOOM);
return true;
} else if (e.getInventory() instanceof MerchantInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.TRADING);
return true;
} else if (e.getInventory() instanceof SmithingInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.SMITHING);
return true;
} else if (e.getInventory() instanceof StonecutterInventory) {
this.checkIsland(e, player, e.getInventory().getLocation(), Flags.STONECUTTING);
return true;
}
return false;
}


/**
* This method runs check based on clicked chest type.
* @param l location of chest.
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/world/bentobox/bentobox/lists/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,15 @@ private Flags() {}
public static final Flag ITEM_FRAME = new Flag.Builder("ITEM_FRAME", Material.ITEM_FRAME).mode(Flag.Mode.ADVANCED).build();
public static final Flag CAKE = new Flag.Builder("CAKE", Material.CAKE).build();
public static final Flag HIVE = new Flag.Builder("HIVE", Material.HONEY_BOTTLE).type(Type.PROTECTION).build();
public static final Flag CARTOGRAPHY = new Flag.Builder("CARTOGRAPHY", Material.CARTOGRAPHY_TABLE).build();
public static final Flag GRINDSTONE = new Flag.Builder("GRINDSTONE", Material.GRINDSTONE).build();
public static final Flag SMITHING = new Flag.Builder("SMITHING", Material.SMITHING_TABLE).build();
public static final Flag STONECUTTING = new Flag.Builder("STONECUTTING", Material.STONECUTTER).build();
public static final Flag LOOM = new Flag.Builder("LOOM", Material.LOOM).build();

public static final Flag CONTAINER = new Flag.Builder("CONTAINER", Material.CHEST).mode(Flag.Mode.BASIC)
.subflags(BREWING, BARREL, CHEST, COMPOSTER, FLOWER_POT, SHULKER_BOX, TRAPPED_CHEST, FURNACE, JUKEBOX, DISPENSER, DROPPER, HOPPER, ITEM_FRAME, HIVE)
.subflags(BREWING, BARREL, CHEST, COMPOSTER, FLOWER_POT, SHULKER_BOX, TRAPPED_CHEST, FURNACE, JUKEBOX, DISPENSER,
DROPPER, HOPPER, ITEM_FRAME, HIVE)
.build();

/**
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ protection:
description: Toggle cake interaction
name: Cakes
hint: Cake eating disabled
CARTOGRAPHY:
name: Cartography tables
description: Toggle use
hint: Cartography table access disabled
CONTAINER:
name: All containers
description: |-
Expand Down Expand Up @@ -901,10 +905,18 @@ protection:
name: Composters
description: Toggle composter interaction
hint: Composter interaction disabled
LOOM:
name: Loom
description: Toggle use
hint: Loom access disabled
FLOWER_POT:
name: Flower pots
description: Toggle flower pot interaction
hint: Flower pot interaction disabled
GRINDSTONE:
name: Grindstone
description: Toggle use
hint: Grindstone access disabled
SHULKER_BOX:
name: Shulker boxes
description: Toggle shulker box interaction
Expand All @@ -914,6 +926,14 @@ protection:
&a Shulker can teleport
&a if active.
name: Shulker teleport
SMITHING:
name: Smithing
description: Toggle use
hint: Smithing access disabled
STONECUTTING:
name: Stonecutting
description: Toggle use
hint: Stonecutting access disabled
TRAPPED_CHEST:
name: Trapped chests
description: Toggle trapped chest interaction
Expand Down

0 comments on commit e6ccce4

Please sign in to comment.