Add GUI option to collect all sales balance
This commit is contained in:
parent
440ab3dae5
commit
c6e2709e6c
|
|
@ -29,6 +29,7 @@ public enum GuiIcon {
|
||||||
MANAGE_SHOP_TYPE,
|
MANAGE_SHOP_TYPE,
|
||||||
MANAGE_SHOP_AMOUNT,
|
MANAGE_SHOP_AMOUNT,
|
||||||
MANAGE_SHOP_PRICE,
|
MANAGE_SHOP_PRICE,
|
||||||
|
MANAGE_SHOP_COLLECT_SALES,
|
||||||
|
|
||||||
HOME_LIST_OWN_SHOPS,
|
HOME_LIST_OWN_SHOPS,
|
||||||
HOME_LIST_PLAYERS,
|
HOME_LIST_PLAYERS,
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,13 @@ package com.alttd.playershops.gui;
|
||||||
import com.alttd.playershops.PlayerShops;
|
import com.alttd.playershops.PlayerShops;
|
||||||
import com.alttd.playershops.config.MessageConfig;
|
import com.alttd.playershops.config.MessageConfig;
|
||||||
import com.alttd.playershops.shop.PlayerShop;
|
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.ShopUtil;
|
||||||
import com.alttd.playershops.utils.Util;
|
import com.alttd.playershops.utils.Util;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
@ -19,9 +20,11 @@ import java.util.UUID;
|
||||||
public class ListShopsGui extends AbstractGui {
|
public class ListShopsGui extends AbstractGui {
|
||||||
|
|
||||||
List<PlayerShop> shops;
|
List<PlayerShop> shops;
|
||||||
|
UUID playerToList;
|
||||||
|
|
||||||
public ListShopsGui(UUID uuid, UUID playerToList) {
|
public ListShopsGui(UUID uuid, UUID playerToList) {
|
||||||
super(uuid);
|
super(uuid);
|
||||||
|
this.playerToList = playerToList;
|
||||||
this.shops = PlayerShops.getInstance().getShopHandler().getShops(playerToList);
|
this.shops = PlayerShops.getInstance().getShopHandler().getShops(playerToList);
|
||||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerToList);
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerToList);
|
||||||
|
|
||||||
|
|
@ -29,8 +32,17 @@ public class ListShopsGui extends AbstractGui {
|
||||||
Placeholder.unparsed("playername", offlinePlayer.hasPlayedBefore() ? offlinePlayer.getName() : "error")
|
Placeholder.unparsed("playername", offlinePlayer.hasPlayedBefore() ? offlinePlayer.getName() : "error")
|
||||||
);
|
);
|
||||||
this.inventory = Bukkit.createInventory(this, INV_SIZE, Util.parseMiniMessage(MessageConfig.GUI_LIST_SHOPS_TITLE, placeholders));
|
this.inventory = Bukkit.createInventory(this, INV_SIZE, Util.parseMiniMessage(MessageConfig.GUI_LIST_SHOPS_TITLE, placeholders));
|
||||||
initInvContents();
|
|
||||||
makeMenuBar();
|
makeMenuBar();
|
||||||
|
initInvContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void makeMenuBar() {
|
||||||
|
super.makeMenuBar();
|
||||||
|
if (!uuid.equals(playerToList) && getPlayer().hasPermission("playershops.shop.collectall"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
inventory.setItem(GuiIcon.MANAGE_SHOP_COLLECT_SALES.getSlot(), GuiIcon.MANAGE_SHOP_COLLECT_SALES.getItemStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -61,6 +73,32 @@ public class ListShopsGui extends AbstractGui {
|
||||||
public void onClick(int slot, ItemStack item) {
|
public void onClick(int slot, ItemStack item) {
|
||||||
super.onClick(slot, 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;
|
||||||
|
for (PlayerShop playerShop : shops) {
|
||||||
|
if (!ShopUtil.canManageShop(player, playerShop))
|
||||||
|
continue;
|
||||||
|
if (!playerShop.getType().equals(ShopType.SELL))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
double balance = playerShop.getBalance();
|
||||||
|
if (balance == 0)
|
||||||
|
continue;
|
||||||
|
playerShop.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(count > 0 ? "<green>You have collected <balance> from <count> shops." : "<red>No shops to be collected from.", placeholders);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (slot >= 45)
|
if (slot >= 45)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user