2012-06-08 15:28:36 +02:00
|
|
|
package com.Acrobot.ChestShop.Listeners.Player;
|
|
|
|
|
2013-02-11 16:55:04 +01:00
|
|
|
import com.Acrobot.Breeze.Utils.*;
|
2021-02-15 17:28:33 +01:00
|
|
|
import com.Acrobot.ChestShop.ChestShop;
|
2019-09-16 13:56:30 +02:00
|
|
|
import com.Acrobot.ChestShop.Commands.AccessToggle;
|
2012-11-23 21:04:13 +01:00
|
|
|
import com.Acrobot.ChestShop.Configuration.Messages;
|
|
|
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
2012-08-10 19:01:34 +02:00
|
|
|
import com.Acrobot.ChestShop.Containers.AdminInventory;
|
2017-07-01 18:14:41 +02:00
|
|
|
import com.Acrobot.ChestShop.Database.Account;
|
2019-05-07 00:49:16 +02:00
|
|
|
import com.Acrobot.ChestShop.Events.AccountQueryEvent;
|
2018-07-11 19:09:07 +02:00
|
|
|
import com.Acrobot.ChestShop.Events.Economy.AccountCheckEvent;
|
2019-01-17 19:50:47 +01:00
|
|
|
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
2012-07-07 19:24:06 +02:00
|
|
|
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
2021-02-15 17:28:33 +01:00
|
|
|
import com.Acrobot.ChestShop.Events.ShopInfoEvent;
|
2012-08-10 19:01:34 +02:00
|
|
|
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.ChestShop.Permission;
|
|
|
|
import com.Acrobot.ChestShop.Security;
|
|
|
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
2021-01-03 01:55:01 +01:00
|
|
|
import com.Acrobot.ChestShop.Utils.ItemUtil;
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
2012-07-07 19:24:06 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2018-01-07 02:11:59 +01:00
|
|
|
import org.bukkit.ChatColor;
|
2013-02-10 15:29:40 +01:00
|
|
|
import org.bukkit.GameMode;
|
2012-06-08 15:28:36 +02:00
|
|
|
import org.bukkit.block.Block;
|
2018-10-23 20:04:18 +02:00
|
|
|
import org.bukkit.block.Container;
|
2012-06-08 15:28:36 +02:00
|
|
|
import org.bukkit.block.Sign;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.block.Action;
|
2018-01-07 02:11:59 +01:00
|
|
|
import org.bukkit.event.block.SignChangeEvent;
|
2012-06-08 15:28:36 +02:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
import org.bukkit.inventory.Inventory;
|
2012-08-10 19:01:34 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2019-04-25 19:44:22 +02:00
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.MathContext;
|
2019-04-07 14:48:16 +02:00
|
|
|
import java.util.Arrays;
|
2019-03-19 19:08:53 +01:00
|
|
|
import java.util.logging.Level;
|
|
|
|
|
2021-01-28 17:18:42 +01:00
|
|
|
import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getState;
|
2013-01-24 22:35:28 +01:00
|
|
|
import static com.Acrobot.Breeze.Utils.BlockUtil.isSign;
|
2012-08-10 19:01:34 +02:00
|
|
|
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType;
|
2013-01-24 22:35:28 +01:00
|
|
|
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
|
|
|
|
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.SELL;
|
2018-11-19 21:10:48 +01:00
|
|
|
import static com.Acrobot.ChestShop.Permission.OTHER_NAME_CREATE;
|
2012-08-10 19:01:34 +02:00
|
|
|
import static com.Acrobot.ChestShop.Signs.ChestShopSign.*;
|
2012-06-08 15:28:36 +02:00
|
|
|
import static org.bukkit.event.block.Action.LEFT_CLICK_BLOCK;
|
|
|
|
import static org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class PlayerInteract implements Listener {
|
2012-12-26 21:42:22 +01:00
|
|
|
|
2014-03-20 16:57:48 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2018-05-07 16:32:51 +02:00
|
|
|
public static void onInteract(PlayerInteractEvent event) {
|
2012-12-26 21:42:22 +01:00
|
|
|
Block block = event.getClickedBlock();
|
2016-10-13 18:11:23 +02:00
|
|
|
if (block == null)
|
2012-12-26 21:42:22 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
Action action = event.getAction();
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
2021-02-15 17:28:33 +01:00
|
|
|
if (Properties.USE_BUILT_IN_PROTECTION && uBlock.couldBeShopContainer(block)) {
|
|
|
|
Sign sign = uBlock.getConnectedSign(block);
|
|
|
|
if (sign != null) {
|
2012-12-26 21:42:22 +01:00
|
|
|
|
2021-05-16 01:31:33 +02:00
|
|
|
if (!Security.canView(player, block, Properties.TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY)) {
|
2021-02-15 17:28:33 +01:00
|
|
|
if (Permission.has(player, Permission.SHOPINFO)) {
|
|
|
|
ChestShop.callEvent(new ShopInfoEvent(player, sign));
|
2021-05-16 01:06:01 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
} else if (!Properties.TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY) {
|
2021-02-15 17:28:33 +01:00
|
|
|
Messages.ACCESS_DENIED.send(player);
|
2021-05-16 01:06:01 +02:00
|
|
|
event.setCancelled(true);
|
2021-02-15 17:28:33 +01:00
|
|
|
}
|
|
|
|
}
|
2012-12-26 21:42:22 +01:00
|
|
|
|
2021-02-15 17:28:33 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-12-26 21:42:22 +01:00
|
|
|
}
|
|
|
|
|
2020-07-08 22:38:54 +02:00
|
|
|
if (!isSign(block) || player.getInventory().getItemInMainHand().getType().name().contains("SIGN")) // Blocking accidental sign edition
|
2012-12-26 21:42:22 +01:00
|
|
|
return;
|
|
|
|
|
2021-01-28 17:18:42 +01:00
|
|
|
Sign sign = (Sign) getState(block, false);
|
2012-12-26 21:42:22 +01:00
|
|
|
if (!ChestShopSign.isValid(sign)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-26 20:35:42 +01:00
|
|
|
if (Properties.ALLOW_AUTO_ITEM_FILL && ChatColor.stripColor(ChestShopSign.getItem(sign)).equals(AUTOFILL_CODE)) {
|
2018-11-19 21:10:48 +01:00
|
|
|
if (ChestShopSign.hasPermission(player, OTHER_NAME_CREATE, sign)) {
|
2018-01-07 02:11:59 +01:00
|
|
|
ItemStack item = player.getInventory().getItemInMainHand();
|
2018-04-02 18:41:45 +02:00
|
|
|
if (!MaterialUtil.isEmpty(item)) {
|
2019-03-19 19:08:53 +01:00
|
|
|
String itemCode;
|
|
|
|
try {
|
2021-01-03 01:55:01 +01:00
|
|
|
itemCode = ItemUtil.getSignName(item);
|
2019-03-19 19:08:53 +01:00
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
player.sendMessage(ChatColor.RED + "Error while generating shop sign item name. Please contact an admin or take a look at the console/log!");
|
|
|
|
com.Acrobot.ChestShop.ChestShop.getPlugin().getLogger().log(Level.SEVERE, "Error while generating shop sign item name", e);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-07 02:11:59 +01:00
|
|
|
String[] lines = sign.getLines();
|
|
|
|
lines[ITEM_LINE] = itemCode;
|
2018-05-07 16:32:51 +02:00
|
|
|
|
2018-01-07 02:11:59 +01:00
|
|
|
SignChangeEvent changeEvent = new SignChangeEvent(block, player, lines);
|
|
|
|
com.Acrobot.ChestShop.ChestShop.callEvent(changeEvent);
|
|
|
|
if (!changeEvent.isCancelled()) {
|
|
|
|
for (byte i = 0; i < changeEvent.getLines().length; ++i) {
|
|
|
|
sign.setLine(i, changeEvent.getLine(i));
|
|
|
|
}
|
|
|
|
sign.update();
|
2021-04-16 22:03:37 +02:00
|
|
|
} else {
|
|
|
|
event.setCancelled(true);
|
2018-01-07 02:11:59 +01:00
|
|
|
}
|
|
|
|
} else {
|
2020-06-28 19:00:09 +02:00
|
|
|
Messages.NO_ITEM_IN_HAND.sendWithPrefix(player);
|
2018-01-07 02:11:59 +01:00
|
|
|
}
|
|
|
|
} else {
|
2020-06-28 19:00:09 +02:00
|
|
|
Messages.ACCESS_DENIED.sendWithPrefix(player);
|
2018-01-07 02:11:59 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2018-05-07 16:32:51 +02:00
|
|
|
|
2019-09-16 13:56:30 +02:00
|
|
|
if (!AccessToggle.isIgnoring(player) && ChestShopSign.canAccess(player, sign) && !ChestShopSign.isAdminShop(sign)) {
|
2019-03-08 22:52:08 +01:00
|
|
|
if (Properties.IGNORE_ACCESS_PERMS || ChestShopSign.isOwner(player, sign)) {
|
2021-10-13 00:30:49 +02:00
|
|
|
if ((player.getInventory().getItemInMainHand().getType().name().endsWith("DYE")
|
|
|
|
|| player.getInventory().getItemInMainHand().getType().name().endsWith("INK_SAC"))
|
|
|
|
&& action == RIGHT_CLICK_BLOCK) {
|
|
|
|
if (Properties.SIGN_DYING) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2019-03-08 22:52:08 +01:00
|
|
|
if (Properties.ALLOW_SIGN_CHEST_OPEN && !(Properties.IGNORE_CREATIVE_MODE && player.getGameMode() == GameMode.CREATIVE)) {
|
|
|
|
if (player.isSneaking() || player.isInsideVehicle()
|
2020-06-24 17:00:16 +02:00
|
|
|
|| (Properties.ALLOW_LEFT_CLICK_DESTROYING && action == LEFT_CLICK_BLOCK)) {
|
2019-03-08 22:52:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.setCancelled(true);
|
|
|
|
showChestGUI(player, block, sign);
|
2018-11-19 21:10:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// don't allow owners or people with access to buy/sell at this shop
|
2020-10-31 20:55:48 +01:00
|
|
|
Messages.TRADE_DENIED_ACCESS_PERMS.sendWithPrefix(player);
|
2018-11-19 21:10:48 +01:00
|
|
|
return;
|
2012-12-26 21:42:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action == RIGHT_CLICK_BLOCK) {
|
|
|
|
event.setCancelled(true);
|
2020-07-03 19:56:29 +02:00
|
|
|
} else if (action == LEFT_CLICK_BLOCK && !Properties.TURN_OFF_SIGN_PROTECTION && !ChestShopSign.canAccess(player, sign)) {
|
2020-06-24 17:00:16 +02:00
|
|
|
event.setCancelled(true);
|
2012-12-26 21:42:22 +01:00
|
|
|
}
|
|
|
|
|
2020-06-18 18:01:52 +02:00
|
|
|
if (Properties.CHECK_ACCESS_FOR_SHOP_USE && !Security.canAccess(player, block, true)) {
|
2020-06-28 19:00:09 +02:00
|
|
|
Messages.TRADE_DENIED.sendWithPrefix(player);
|
2020-06-18 18:01:52 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-13 18:11:23 +02:00
|
|
|
//Bukkit.getLogger().info("ChestShop - DEBUG - "+block.getWorld().getName()+": "+block.getLocation().getBlockX()+", "+block.getLocation().getBlockY()+", "+block.getLocation().getBlockZ());
|
2012-12-26 21:42:22 +01:00
|
|
|
PreTransactionEvent pEvent = preparePreTransactionEvent(sign, player, action);
|
2016-10-13 18:11:23 +02:00
|
|
|
if (pEvent == null)
|
2013-01-29 21:01:30 +01:00
|
|
|
return;
|
|
|
|
|
2012-12-26 21:42:22 +01:00
|
|
|
Bukkit.getPluginManager().callEvent(pEvent);
|
2016-10-13 18:11:23 +02:00
|
|
|
if (pEvent.isCancelled())
|
2012-12-26 21:42:22 +01:00
|
|
|
return;
|
|
|
|
|
2012-08-10 19:01:34 +02:00
|
|
|
TransactionEvent tEvent = new TransactionEvent(pEvent, sign);
|
|
|
|
Bukkit.getPluginManager().callEvent(tEvent);
|
|
|
|
}
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2012-08-10 19:01:34 +02:00
|
|
|
private static PreTransactionEvent preparePreTransactionEvent(Sign sign, Player player, Action action) {
|
2022-01-26 20:35:42 +01:00
|
|
|
String name = ChestShopSign.getOwner(sign);
|
|
|
|
String prices = ChestShopSign.getPrice(sign);
|
|
|
|
String material = ChestShopSign.getItem(sign);
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2019-05-07 00:49:16 +02:00
|
|
|
AccountQueryEvent accountQueryEvent = new AccountQueryEvent(name);
|
|
|
|
Bukkit.getPluginManager().callEvent(accountQueryEvent);
|
|
|
|
Account account = accountQueryEvent.getAccount();
|
2018-01-27 17:12:34 +01:00
|
|
|
if (account == null) {
|
2020-06-28 19:00:09 +02:00
|
|
|
Messages.PLAYER_NOT_FOUND.sendWithPrefix(player);
|
2016-09-20 21:45:18 +02:00
|
|
|
return null;
|
2018-01-27 17:12:34 +01:00
|
|
|
}
|
2014-04-12 17:27:16 +02:00
|
|
|
|
2017-07-26 15:11:46 +02:00
|
|
|
boolean adminShop = ChestShopSign.isAdminShop(sign);
|
|
|
|
|
2016-10-13 18:11:23 +02:00
|
|
|
// check if player exists in economy
|
2018-07-11 19:09:07 +02:00
|
|
|
if (!adminShop) {
|
|
|
|
AccountCheckEvent event = new AccountCheckEvent(account.getUuid(), player.getWorld());
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
if(!event.hasAccount()) {
|
2020-06-28 19:00:09 +02:00
|
|
|
Messages.NO_ECONOMY_ACCOUNT.sendWithPrefix(player);
|
2018-07-11 19:09:07 +02:00
|
|
|
return null;
|
|
|
|
}
|
2018-01-27 17:12:34 +01:00
|
|
|
}
|
2016-10-13 18:11:23 +02:00
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
Action buy = Properties.REVERSE_BUTTONS ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK;
|
2019-04-25 19:44:22 +02:00
|
|
|
BigDecimal price = (action == buy ? PriceUtil.getExactBuyPrice(prices) : PriceUtil.getExactSellPrice(prices));
|
2012-07-07 19:24:06 +02:00
|
|
|
|
2018-10-23 20:04:18 +02:00
|
|
|
Container shopBlock = uBlock.findConnectedContainer(sign);
|
2019-04-05 16:17:15 +02:00
|
|
|
Inventory ownerInventory = shopBlock != null ? shopBlock.getInventory() : null;
|
2012-07-07 19:24:06 +02:00
|
|
|
|
2019-01-17 19:50:47 +01:00
|
|
|
ItemParseEvent parseEvent = new ItemParseEvent(material);
|
|
|
|
Bukkit.getPluginManager().callEvent(parseEvent);
|
|
|
|
ItemStack item = parseEvent.getItem();
|
2020-03-24 00:31:08 +01:00
|
|
|
if (item == null) {
|
2020-06-28 19:00:09 +02:00
|
|
|
Messages.INVALID_SHOP_DETECTED.sendWithPrefix(player);
|
2013-01-29 21:01:30 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-03-24 00:31:08 +01:00
|
|
|
int amount = -1;
|
|
|
|
try {
|
2022-01-26 20:35:42 +01:00
|
|
|
amount = ChestShopSign.getQuantity(sign);
|
2020-03-24 00:31:08 +01:00
|
|
|
} catch (NumberFormatException notANumber) {}
|
2012-09-12 12:35:48 +02:00
|
|
|
|
2020-03-24 00:31:08 +01:00
|
|
|
if (amount < 1 || amount > Properties.MAX_SHOP_AMOUNT) {
|
2020-06-28 19:00:09 +02:00
|
|
|
Messages.INVALID_SHOP_PRICE.sendWithPrefix(player);
|
2020-03-24 00:31:08 +01:00
|
|
|
return null;
|
2012-10-16 17:03:45 +02:00
|
|
|
}
|
|
|
|
|
2019-04-30 17:02:01 +02:00
|
|
|
if (Properties.SHIFT_SELLS_IN_STACKS && player.isSneaking() && !price.equals(PriceUtil.NO_PRICE) && isAllowedForShift(action == buy)) {
|
2019-04-05 16:17:15 +02:00
|
|
|
int newAmount = adminShop ? InventoryUtil.getMaxStackSize(item) : getStackAmount(item, ownerInventory, player, action);
|
2012-09-12 12:35:48 +02:00
|
|
|
if (newAmount > 0) {
|
2019-04-30 17:02:01 +02:00
|
|
|
price = price.divide(BigDecimal.valueOf(amount), MathContext.DECIMAL128).multiply(BigDecimal.valueOf(newAmount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
|
2012-09-12 12:35:48 +02:00
|
|
|
amount = newAmount;
|
|
|
|
}
|
2020-05-31 15:50:53 +02:00
|
|
|
} else if (Properties.SHIFT_SELLS_EVERYTHING && player.isSneaking() && !price.equals(PriceUtil.NO_PRICE) && isAllowedForShift(action == buy)) {
|
|
|
|
if (action != buy) {
|
|
|
|
int newAmount = InventoryUtil.getAmount(item, player.getInventory());
|
|
|
|
if (newAmount > 0) {
|
|
|
|
price = price.divide(BigDecimal.valueOf(amount), MathContext.DECIMAL128).multiply(BigDecimal.valueOf(newAmount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
|
|
|
|
amount = newAmount;
|
|
|
|
}
|
|
|
|
} else if (!adminShop && ownerInventory != null) {
|
|
|
|
int newAmount = InventoryUtil.getAmount(item, ownerInventory);
|
|
|
|
if (newAmount > 0) {
|
|
|
|
price = price.divide(BigDecimal.valueOf(amount), MathContext.DECIMAL128).multiply(BigDecimal.valueOf(newAmount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
|
|
|
|
amount = newAmount;
|
|
|
|
}
|
|
|
|
}
|
2012-09-12 12:35:48 +02:00
|
|
|
}
|
|
|
|
|
2012-08-10 19:01:34 +02:00
|
|
|
item.setAmount(amount);
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2017-09-06 15:19:34 +02:00
|
|
|
ItemStack[] items = InventoryUtil.getItemsStacked(item);
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2021-01-24 23:33:36 +01:00
|
|
|
// Create virtual admin inventory if
|
|
|
|
// - it's an admin shop
|
|
|
|
// - there is no container for the shop sign
|
|
|
|
// - the config doesn't force unlimited admin shop stock
|
|
|
|
if (adminShop && (ownerInventory == null || Properties.FORCE_UNLIMITED_ADMIN_SHOP)) {
|
2019-04-07 14:48:16 +02:00
|
|
|
ownerInventory = new AdminInventory(action == buy ? Arrays.stream(items).map(ItemStack::clone).toArray(ItemStack[]::new) : new ItemStack[0]);
|
2019-04-05 16:17:15 +02:00
|
|
|
}
|
|
|
|
|
2012-08-10 19:01:34 +02:00
|
|
|
TransactionType transactionType = (action == buy ? BUY : SELL);
|
2017-10-29 23:50:24 +01:00
|
|
|
return new PreTransactionEvent(ownerInventory, player.getInventory(), items, price, player, account, sign, transactionType);
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
|
2013-03-30 15:58:06 +01:00
|
|
|
private static boolean isAllowedForShift(boolean buyTransaction) {
|
|
|
|
String allowed = Properties.SHIFT_ALLOWS;
|
|
|
|
|
|
|
|
if (allowed.equalsIgnoreCase("ALL")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return allowed.equalsIgnoreCase(buyTransaction ? "BUY" : "SELL");
|
|
|
|
}
|
|
|
|
|
2013-04-05 14:17:34 +02:00
|
|
|
private static int getStackAmount(ItemStack item, Inventory inventory, Player player, Action action) {
|
2012-11-23 21:04:13 +01:00
|
|
|
Action buy = Properties.REVERSE_BUTTONS ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK;
|
2013-04-05 14:17:34 +02:00
|
|
|
Inventory checkedInventory = (action == buy ? inventory : player.getInventory());
|
2012-09-12 12:35:48 +02:00
|
|
|
|
2017-09-06 15:19:34 +02:00
|
|
|
if (checkedInventory.containsAtLeast(item, InventoryUtil.getMaxStackSize(item))) {
|
|
|
|
return InventoryUtil.getMaxStackSize(item);
|
2012-09-12 12:35:48 +02:00
|
|
|
} else {
|
2013-04-05 14:17:34 +02:00
|
|
|
return InventoryUtil.getAmount(item, checkedInventory);
|
2012-09-12 12:35:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-19 21:10:48 +01:00
|
|
|
/**
|
|
|
|
* @deprecated Use {@link ChestShopSign#hasPermission(Player, Permission, Sign)} with {@link Permission#OTHER_NAME_ACCESS}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2012-09-12 12:35:48 +02:00
|
|
|
public static boolean canOpenOtherShops(Player player) {
|
2018-11-19 21:10:48 +01:00
|
|
|
return Permission.has(player, Permission.OTHER_NAME_ACCESS + ".*");
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
|
2018-11-19 21:10:48 +01:00
|
|
|
private static void showChestGUI(Player player, Block signBlock, Sign sign) {
|
|
|
|
Container container = uBlock.findConnectedContainer(sign);
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2018-10-23 20:04:18 +02:00
|
|
|
if (container == null) {
|
2020-06-28 19:00:09 +02:00
|
|
|
Messages.NO_CHEST_DETECTED.sendWithPrefix(player);
|
2012-06-08 15:28:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-19 21:10:48 +01:00
|
|
|
if (!Security.canAccess(player, signBlock)) {
|
2012-06-08 15:28:36 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-09-10 15:32:34 +02:00
|
|
|
|
|
|
|
if (!Security.canAccess(player, container.getBlock())) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2018-10-23 20:04:18 +02:00
|
|
|
BlockUtil.openBlockGUI(container, player);
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
}
|