Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 84b4471fcb | |||
| 0134b768a8 |
@@ -3,7 +3,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "party.cybsec"
|
group = "party.cybsec"
|
||||||
version = "1.0.0"
|
version = "1.3.0"
|
||||||
description = "deterministic item-for-item chest barter"
|
description = "deterministic item-for-item chest barter"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package party.cybsec.oyeshops.listener;
|
package party.cybsec.oyeshops.listener;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.block.DoubleChest;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.inventory.DoubleChestInventory;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import party.cybsec.oyeshops.OyeShopsPlugin;
|
import party.cybsec.oyeshops.OyeShopsPlugin;
|
||||||
import party.cybsec.oyeshops.model.Shop;
|
import party.cybsec.oyeshops.model.Shop;
|
||||||
import party.cybsec.oyeshops.permission.PermissionManager;
|
import party.cybsec.oyeshops.permission.PermissionManager;
|
||||||
@@ -49,7 +54,7 @@ public class ShopProtectionListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find shop with this chest location
|
// find shop with this chest location (handles double chests)
|
||||||
Shop chestShop = findShopByChest(block);
|
Shop chestShop = findShopByChest(block);
|
||||||
if (chestShop != null) {
|
if (chestShop != null) {
|
||||||
if (canBreakShop(player, chestShop)) {
|
if (canBreakShop(player, chestShop)) {
|
||||||
@@ -88,17 +93,54 @@ public class ShopProtectionListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find shop by chest location
|
* find shop by chest location (handles double chests)
|
||||||
*/
|
*/
|
||||||
private Shop findShopByChest(Block chestBlock) {
|
private Shop findShopByChest(Block chestBlock) {
|
||||||
|
// first check this block directly
|
||||||
|
Shop shop = findShopOnBlock(chestBlock);
|
||||||
|
if (shop != null) {
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if this is a chest, check the other half of a double chest
|
||||||
|
if (chestBlock.getState() instanceof Chest chest) {
|
||||||
|
Inventory inv = chest.getInventory();
|
||||||
|
if (inv instanceof DoubleChestInventory doubleInv) {
|
||||||
|
DoubleChest doubleChest = doubleInv.getHolder();
|
||||||
|
if (doubleChest != null) {
|
||||||
|
// check both sides
|
||||||
|
Chest left = (Chest) doubleChest.getLeftSide();
|
||||||
|
Chest right = (Chest) doubleChest.getRightSide();
|
||||||
|
|
||||||
|
if (left != null) {
|
||||||
|
shop = findShopOnBlock(left.getBlock());
|
||||||
|
if (shop != null)
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
|
if (right != null) {
|
||||||
|
shop = findShopOnBlock(right.getBlock());
|
||||||
|
if (shop != null)
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find shop sign attached to a specific block
|
||||||
|
*/
|
||||||
|
private Shop findShopOnBlock(Block containerBlock) {
|
||||||
// check all adjacent blocks for wall signs
|
// check all adjacent blocks for wall signs
|
||||||
for (org.bukkit.block.BlockFace face : new org.bukkit.block.BlockFace[] {
|
for (BlockFace face : new BlockFace[] {
|
||||||
org.bukkit.block.BlockFace.NORTH,
|
BlockFace.NORTH,
|
||||||
org.bukkit.block.BlockFace.SOUTH,
|
BlockFace.SOUTH,
|
||||||
org.bukkit.block.BlockFace.EAST,
|
BlockFace.EAST,
|
||||||
org.bukkit.block.BlockFace.WEST
|
BlockFace.WEST
|
||||||
}) {
|
}) {
|
||||||
Block adjacent = chestBlock.getRelative(face);
|
Block adjacent = containerBlock.getRelative(face);
|
||||||
Shop shop = plugin.getShopRegistry().getShop(adjacent.getLocation());
|
Shop shop = plugin.getShopRegistry().getShop(adjacent.getLocation());
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
return shop;
|
return shop;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: oyeShops
|
name: oyeShops
|
||||||
version: 1.0.0
|
version: 1.3.0
|
||||||
main: party.cybsec.oyeshops.OyeShopsPlugin
|
main: party.cybsec.oyeshops.OyeShopsPlugin
|
||||||
api-version: '1.21'
|
api-version: '1.21'
|
||||||
description: deterministic item-for-item chest barter
|
description: deterministic item-for-item chest barter
|
||||||
|
|||||||
Reference in New Issue
Block a user