mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-02-19 03:21:20 +01:00
Make Admin Shops use containers if available (Resolves #402)
Admin Shops can now be stocked the same way as player shops if a valid shop container is nearby. If no container is nearby it will just work as an unlimited shop. This behaviour can be disabled with the FORCE_UNLIMITED_ADMIN_SHOP config option so that an admin shop is unlimited even though a valid container is next to it.
This commit is contained in:
parent
9843e92525
commit
ba47b82ba1
@ -170,6 +170,9 @@ public class Properties {
|
||||
@ConfigurationComment("First line of your Admin Shop's sign should look like this:")
|
||||
public static String ADMIN_SHOP_NAME = "Admin Shop";
|
||||
|
||||
@ConfigurationComment("Make all admin shops be unlimited even if they have a shop container at the sign")
|
||||
public static boolean FORCE_UNLIMITED_ADMIN_SHOP = false;
|
||||
|
||||
@ConfigurationComment("The name of the economy account which Admin Shops should use and to which all taxes will go")
|
||||
public static String SERVER_ECONOMY_ACCOUNT = "";
|
||||
|
||||
|
@ -6,6 +6,8 @@ import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
@ -17,7 +19,7 @@ public class BuildPermissionEvent extends Event implements Cancellable {
|
||||
|
||||
private boolean allowed = true;
|
||||
|
||||
public BuildPermissionEvent(Player player, Location chest, Location sign) {
|
||||
public BuildPermissionEvent(Player player, @Nullable Location chest, Location sign) {
|
||||
this.player = player;
|
||||
this.chest = chest;
|
||||
this.sign = sign;
|
||||
@ -27,7 +29,7 @@ public class BuildPermissionEvent extends Event implements Cancellable {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Location getChest() {
|
||||
public @Nullable Location getChest() {
|
||||
return chest;
|
||||
}
|
||||
|
||||
|
@ -165,11 +165,7 @@ public class SignBreak implements Listener {
|
||||
}
|
||||
|
||||
public static void sendShopDestroyedEvent(Sign sign, Player player) {
|
||||
Container connectedContainer = null;
|
||||
|
||||
if (!ChestShopSign.isAdminShop(sign)) {
|
||||
connectedContainer = uBlock.findConnectedContainer(sign.getBlock());
|
||||
}
|
||||
Container connectedContainer = uBlock.findConnectedContainer(sign.getBlock());
|
||||
|
||||
Event event = new ShopDestroyedEvent(player, sign, connectedContainer);
|
||||
ChestShop.callEvent(event);
|
||||
|
@ -46,7 +46,8 @@ public class StockCounterModule implements Listener {
|
||||
event.setSignLine(QUANTITY_LINE, Integer.toString(quantity));
|
||||
}
|
||||
|
||||
if (!Properties.USE_STOCK_COUNTER || ChestShopSign.isAdminShop(event.getSignLine(NAME_LINE))) {
|
||||
if (!Properties.USE_STOCK_COUNTER
|
||||
|| (Properties.FORCE_UNLIMITED_ADMIN_SHOP && ChestShopSign.isAdminShop(event.getSignLine(NAME_LINE)))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -71,11 +72,8 @@ public class StockCounterModule implements Listener {
|
||||
}
|
||||
|
||||
for (Sign shopSign : uBlock.findConnectedShopSigns(event.getInventory().getHolder())) {
|
||||
if (ChestShopSign.isAdminShop(shopSign)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Properties.USE_STOCK_COUNTER) {
|
||||
if (!Properties.USE_STOCK_COUNTER
|
||||
|| (Properties.FORCE_UNLIMITED_ADMIN_SHOP && ChestShopSign.isAdminShop(shopSign))) {
|
||||
if (QuantityUtil.quantityLineContainsCounter(shopSign.getLine(QUANTITY_LINE))) {
|
||||
removeCounterFromQuantityLine(shopSign);
|
||||
}
|
||||
@ -111,7 +109,7 @@ public class StockCounterModule implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ChestShopSign.isAdminShop(event.getSign())) {
|
||||
if (Properties.FORCE_UNLIMITED_ADMIN_SHOP && ChestShopSign.isAdminShop(event.getSign())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,7 @@ import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -232,7 +230,11 @@ public class PlayerInteract implements Listener {
|
||||
|
||||
ItemStack[] items = InventoryUtil.getItemsStacked(item);
|
||||
|
||||
if (adminShop) {
|
||||
// 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)) {
|
||||
ownerInventory = new AdminInventory(action == buy ? Arrays.stream(items).map(ItemStack::clone).toArray(ItemStack[]::new) : new ItemStack[0]);
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,13 @@ public class EmptyShopDeleter implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory ownerInventory = event.getOwnerInventory();
|
||||
Sign sign = event.getSign();
|
||||
Container connectedContainer = uBlock.findConnectedContainer(sign);
|
||||
|
||||
if (ChestShopSign.isAdminShop(sign)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory ownerInventory = event.getOwnerInventory();
|
||||
|
||||
if (!shopShouldBeRemoved(ownerInventory, event.getStock())) {
|
||||
return;
|
||||
@ -39,6 +43,8 @@ public class EmptyShopDeleter implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Container connectedContainer = uBlock.findConnectedContainer(sign);
|
||||
|
||||
ShopDestroyedEvent destroyedEvent = new ShopDestroyedEvent(null, event.getSign(), connectedContainer);
|
||||
ChestShop.callEvent(destroyedEvent);
|
||||
|
||||
@ -62,7 +68,7 @@ public class EmptyShopDeleter implements Listener {
|
||||
}
|
||||
|
||||
private static boolean shopShouldBeRemoved(Inventory inventory, ItemStack[] stock) {
|
||||
if (Properties.REMOVE_EMPTY_SHOPS && !ChestShopSign.isAdminShop(inventory)) {
|
||||
if (Properties.REMOVE_EMPTY_SHOPS) {
|
||||
if (Properties.ALLOW_PARTIAL_TRANSACTIONS) {
|
||||
for (ItemStack itemStack : stock) {
|
||||
if (inventory.containsAtLeast(itemStack, 1)) {
|
||||
|
@ -25,14 +25,12 @@ public class ChestChecker implements Listener {
|
||||
public static void onPreShopCreation(PreShopCreationEvent event) {
|
||||
String nameLine = event.getSignLine(NAME_LINE);
|
||||
|
||||
if (ChestShopSign.isAdminShop(nameLine)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Container connectedContainer = uBlock.findConnectedContainer(event.getSign().getBlock());
|
||||
|
||||
if (connectedContainer == null) {
|
||||
event.setOutcome(NO_CHEST);
|
||||
if (!ChestShopSign.isAdminShop(nameLine)) {
|
||||
event.setOutcome(NO_CHEST);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,7 @@ package com.Acrobot.ChestShop.Listeners.PreShopCreation;
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
||||
import com.Acrobot.ChestShop.Events.Protection.BuildPermissionEvent;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.Acrobot.ChestShop.Security;
|
||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Container;
|
||||
@ -14,8 +12,6 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.NO_PERMISSION_FOR_TERRAIN;
|
||||
import static com.Acrobot.ChestShop.Permission.ADMIN;
|
||||
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
@ -24,18 +20,8 @@ public class TerrainChecker implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public static void onPreShopCreation(PreShopCreationEvent event) {
|
||||
String nameLine = event.getSignLine(NAME_LINE);
|
||||
|
||||
if (ChestShopSign.isAdminShop(nameLine)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (Permission.has(player, ADMIN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Security.canPlaceSign(player, event.getSign())) {
|
||||
event.setOutcome(NO_PERMISSION_FOR_TERRAIN);
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user