Add option to collect all balance from a single shop.

This commit is contained in:
Len 2024-08-04 10:54:10 +02:00 committed by destro174
parent 74e0f8c5b5
commit 7cfd147f1e
2 changed files with 28 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import com.alttd.playershops.config.ShopTypeConfig;
import com.alttd.playershops.conversation.ConversationManager;
import com.alttd.playershops.conversation.ConversationType;
import com.alttd.playershops.shop.PlayerShop;
import com.alttd.playershops.shop.ShopType;
import com.alttd.playershops.utils.EconomyUtils;
import com.alttd.playershops.utils.ShopUtil;
import com.alttd.playershops.utils.Util;
@ -59,6 +60,7 @@ public class ShopManagementGui extends AbstractGui {
inventory.setItem(GuiIcon.MANAGE_SHOP.getSlot(), shopIcon);
inventory.setItem(GuiIcon.MANAGE_SHOP_BALANCE_ADD.getSlot(), GuiIcon.MANAGE_SHOP_BALANCE_ADD.getItemStack());
inventory.setItem(GuiIcon.MANAGE_SHOP_BALANCE_REMOVE.getSlot(), GuiIcon.MANAGE_SHOP_BALANCE_REMOVE.getItemStack());
inventory.setItem(GuiIcon.MANAGE_SHOP_COLLECT_SALES.getSlot(), GuiIcon.MANAGE_SHOP_COLLECT_SALES.getItemStack());
inventory.setItem(GuiIcon.MANAGE_SHOP_SALES.getSlot(), GuiIcon.MANAGE_SHOP_SALES.getItemStack());
inventory.setItem(GuiIcon.MANAGE_SHOP_ITEM.getSlot(), GuiIcon.MANAGE_SHOP_ITEM.getItemStack());
inventory.setItem(GuiIcon.MANAGE_SHOP_TYPE.getSlot(), GuiIcon.MANAGE_SHOP_TYPE.getItemStack());
@ -75,6 +77,31 @@ public class ShopManagementGui extends AbstractGui {
public void onClick(int slot, ItemStack item) {
super.onClick(slot, item);
if (slot == GuiIcon.MANAGE_SHOP_COLLECT_SALES.getSlot() && GuiIcon.MANAGE_SHOP_COLLECT_SALES.getItemStack().equals(item)) {
Player player = getPlayer();
double d = 0;
int count = 0;
if (!ShopUtil.canManageShop(player, this.shop))
return;
if (!this.shop.getType().equals(ShopType.SELL))
return;
double balance = this.shop.getBalance();
if (balance == 0)
return;
this.shop.removeBalance(balance);
EconomyUtils.addFunds(player, balance);
d += balance;
count++;
TagResolver placeholders = TagResolver.resolver(
Placeholder.parsed("balance", String.valueOf(d)),
Placeholder.parsed("count", String.valueOf(count))
);
player.sendMiniMessage("<green>You have collected <balance> from <count> shops.", placeholders);
return;
}
if (slot >= 45)
return;

View File

@ -135,6 +135,7 @@ public class ShopHandler {
}
return null;
}
public List<PlayerShop> getShopsInRadius(int x, int z, int radius) {
ArrayList<PlayerShop> shops = new ArrayList<>();
int bottomX = x - radius;