This commit is contained in:
Bruno Rybársky 2024-11-03 20:41:12 +01:00
parent 33695e80ba
commit 6f1dc2e8b4
No known key found for this signature in database
GPG Key ID: 6C9206A821C70598
22 changed files with 105 additions and 120 deletions

@ -6,7 +6,7 @@ minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2 yarn_mappings=1.21.3+build.2
loader_version=0.16.9 loader_version=0.16.9
# Mod Properties # Mod Properties
mod_version=1.5.1 mod_version=1.5.2
maven_group=systems.brn maven_group=systems.brn
archives_base_name=servershop archives_base_name=servershop
# Dependencies # Dependencies

@ -1,7 +1,5 @@
package systems.brn.servershop; package systems.brn.servershop;
import eu.pb4.placeholders.api.PlaceholderHandler;
import eu.pb4.placeholders.api.PlaceholderResult;
import eu.pb4.placeholders.api.Placeholders; import eu.pb4.placeholders.api.Placeholders;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;

@ -1,6 +1,6 @@
package systems.brn.servershop.commands; package systems.brn.servershop.commands;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.DoubleArgumentType;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
@ -43,7 +43,7 @@ public class AuctionCommands {
} }
public static int createHand(CommandContext<ServerCommandSource> ctx) { public static int createHand(CommandContext<ServerCommandSource> ctx) {
int sellPrice = IntegerArgumentType.getInteger(ctx, "sellprice"); double sellPrice = DoubleArgumentType.getDouble(ctx, "sellprice");
ServerPlayerEntity player = ctx.getSource().getPlayer(); ServerPlayerEntity player = ctx.getSource().getPlayer();
if (player != null) { if (player != null) {
ItemStack itemStack = player.getMainHandStack(); ItemStack itemStack = player.getMainHandStack();

@ -1,6 +1,6 @@
package systems.brn.servershop.commands; package systems.brn.servershop.commands;
import com.mojang.brigadier.arguments.LongArgumentType; import com.mojang.brigadier.arguments.DoubleArgumentType;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
@ -17,7 +17,7 @@ public class BalanceCommand {
ServerPlayerEntity player = ctx.getSource().getPlayer(); ServerPlayerEntity player = ctx.getSource().getPlayer();
ServerPlayerEntity target = EntityArgumentType.getPlayer(ctx, "target"); ServerPlayerEntity target = EntityArgumentType.getPlayer(ctx, "target");
if (player != null && target != null) { if (player != null && target != null) {
long senderBalance = balanceStorage.getBalance(target); double senderBalance = balanceStorage.getBalance(target);
playerObj.sendFeedback(() -> Text.translatable("message.servershop.balance.other", target.getName(), senderBalance), false); playerObj.sendFeedback(() -> Text.translatable("message.servershop.balance.other", target.getName(), senderBalance), false);
} }
} catch (Exception ignored) { } catch (Exception ignored) {
@ -41,7 +41,7 @@ public class BalanceCommand {
ServerCommandSource playerObj = ctx.getSource(); ServerCommandSource playerObj = ctx.getSource();
ServerPlayerEntity player = ctx.getSource().getPlayer(); ServerPlayerEntity player = ctx.getSource().getPlayer();
if (player != null) { if (player != null) {
long senderBalance = balanceStorage.getBalance(player); double senderBalance = balanceStorage.getBalance(player);
playerObj.sendFeedback(() -> Text.translatable("message.servershop.balance.self", senderBalance), false); playerObj.sendFeedback(() -> Text.translatable("message.servershop.balance.self", senderBalance), false);
} }
} catch (Exception ignored) { } catch (Exception ignored) {
@ -53,7 +53,7 @@ public class BalanceCommand {
public static int selfSet(CommandContext<ServerCommandSource> ctx) { public static int selfSet(CommandContext<ServerCommandSource> ctx) {
try { try {
ServerPlayerEntity player = ctx.getSource().getPlayer(); ServerPlayerEntity player = ctx.getSource().getPlayer();
long senderBalance = LongArgumentType.getLong(ctx, "balance"); double senderBalance = DoubleArgumentType.getDouble(ctx, "balance");
if (player != null) { if (player != null) {
balanceStorage.setBalance(player, senderBalance); balanceStorage.setBalance(player, senderBalance);
} }
@ -67,7 +67,7 @@ public class BalanceCommand {
try { try {
ServerCommandSource playerObj = ctx.getSource(); ServerCommandSource playerObj = ctx.getSource();
ServerPlayerEntity player = ctx.getSource().getPlayer(); ServerPlayerEntity player = ctx.getSource().getPlayer();
long senderBalance = LongArgumentType.getLong(ctx, "balance"); double senderBalance = DoubleArgumentType.getDouble(ctx, "balance");
ServerPlayerEntity target = EntityArgumentType.getPlayer(ctx, "recipient"); ServerPlayerEntity target = EntityArgumentType.getPlayer(ctx, "recipient");
if (player != null && target != null) { if (player != null && target != null) {
balanceStorage.setBalance(target, senderBalance); balanceStorage.setBalance(target, senderBalance);

@ -1,8 +1,8 @@
package systems.brn.servershop.commands; package systems.brn.servershop.commands;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.DoubleArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.LongArgumentType;
import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.argument.ItemStackArgumentType; import net.minecraft.command.argument.ItemStackArgumentType;
@ -28,8 +28,8 @@ public class CommandRegistry {
.then(literal("set") .then(literal("set")
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2)) .requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
.then(argument("item", ItemStackArgumentType.itemStack(commandRegistryAccess)) .then(argument("item", ItemStackArgumentType.itemStack(commandRegistryAccess))
.then(argument("buyprice", IntegerArgumentType.integer(-1)) .then(argument("buyprice", DoubleArgumentType.doubleArg(-1))
.then(argument("sellprice", IntegerArgumentType.integer(-1)) .then(argument("sellprice", DoubleArgumentType.doubleArg(-1))
.executes(ShopCommands::set) .executes(ShopCommands::set)
) )
) )
@ -37,8 +37,8 @@ public class CommandRegistry {
) )
.then(literal("setHand") .then(literal("setHand")
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2)) .requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
.then(argument("buyprice", IntegerArgumentType.integer(-1)) .then(argument("buyprice", DoubleArgumentType.doubleArg(-1))
.then(argument("sellprice", IntegerArgumentType.integer(-1)) .then(argument("sellprice", DoubleArgumentType.doubleArg(-1))
.executes(ShopCommands::setHand) .executes(ShopCommands::setHand)
) )
) )
@ -54,7 +54,7 @@ public class CommandRegistry {
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2)) .requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
.executes(AuctionCommands::save)) .executes(AuctionCommands::save))
.then(literal("create") .then(literal("create")
.then(argument("sellprice", IntegerArgumentType.integer(1)) .then(argument("sellprice", DoubleArgumentType.doubleArg(1))
.executes(AuctionCommands::createHand) .executes(AuctionCommands::createHand)
) )
.executes(AuctionCommands::create) .executes(AuctionCommands::create)
@ -63,7 +63,7 @@ public class CommandRegistry {
dispatcher.register( dispatcher.register(
literal("pay") literal("pay")
.then(argument("recipient", EntityArgumentType.player()) .then(argument("recipient", EntityArgumentType.player())
.then(argument("amount", IntegerArgumentType.integer(1)) .then(argument("amount", DoubleArgumentType.doubleArg(1))
.executes(PayCommand::run) .executes(PayCommand::run)
) )
) )
@ -87,7 +87,7 @@ public class CommandRegistry {
.executes(BalanceCommand::list)) .executes(BalanceCommand::list))
.then(literal("set") .then(literal("set")
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2)) .requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
.then(argument("balance", LongArgumentType.longArg(0)) .then(argument("balance", DoubleArgumentType.doubleArg(0))
.executes(BalanceCommand::selfSet) .executes(BalanceCommand::selfSet)
.then(argument("recipient", EntityArgumentType.player()) .then(argument("recipient", EntityArgumentType.player())
.executes(BalanceCommand::othersSet)) .executes(BalanceCommand::othersSet))

@ -1,6 +1,6 @@
package systems.brn.servershop.commands; package systems.brn.servershop.commands;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.DoubleArgumentType;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
@ -15,9 +15,9 @@ public class PayCommand {
ServerCommandSource senderObj = ctx.getSource(); ServerCommandSource senderObj = ctx.getSource();
ServerPlayerEntity sender = ctx.getSource().getPlayer(); ServerPlayerEntity sender = ctx.getSource().getPlayer();
ServerPlayerEntity target = EntityArgumentType.getPlayer(ctx, "recipient"); ServerPlayerEntity target = EntityArgumentType.getPlayer(ctx, "recipient");
int amount = IntegerArgumentType.getInteger(ctx, "amount"); double amount = DoubleArgumentType.getDouble(ctx, "amount");
if (sender != null) { if (sender != null) {
long senderBalance = balanceStorage.getBalance(sender); double senderBalance = balanceStorage.getBalance(sender);
if (senderBalance >= amount && amount > 0) { if (senderBalance >= amount && amount > 0) {
balanceStorage.removeBalance(sender, amount); balanceStorage.removeBalance(sender, amount);
balanceStorage.addBalance(target, amount); balanceStorage.addBalance(target, amount);

@ -22,8 +22,8 @@ public class PriceCommand {
private static int runStack(CommandContext<ServerCommandSource> ctx, ItemStack stack) { private static int runStack(CommandContext<ServerCommandSource> ctx, ItemStack stack) {
ItemPriceRecord itemPriceRecord = priceStorage.getPrices(stack); ItemPriceRecord itemPriceRecord = priceStorage.getPrices(stack);
ServerCommandSource src = ctx.getSource(); ServerCommandSource src = ctx.getSource();
int buyPrice = itemPriceRecord.buyPrice(); double buyPrice = itemPriceRecord.buyPrice();
int sellPrice = itemPriceRecord.sellPrice(); double sellPrice = itemPriceRecord.sellPrice();
String itemName = stack.getItem().toString(); String itemName = stack.getItem().toString();
Text text = getText(buyPrice, sellPrice, itemName); Text text = getText(buyPrice, sellPrice, itemName);
src.sendFeedback(() -> text, false); src.sendFeedback(() -> text, false);
@ -39,7 +39,7 @@ public class PriceCommand {
return 1; return 1;
} }
private static @NotNull Text getText(int buyPrice, int sellPrice, String itemName) { private static @NotNull Text getText(double buyPrice, double sellPrice, String itemName) {
Text text; Text text;
if (buyPrice > 0 && sellPrice > 0) { if (buyPrice > 0 && sellPrice > 0) {
text = Text.translatable("message.servershop.price.both", itemName, buyPrice, sellPrice); text = Text.translatable("message.servershop.price.both", itemName, buyPrice, sellPrice);

@ -1,6 +1,6 @@
package systems.brn.servershop.commands; package systems.brn.servershop.commands;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.DoubleArgumentType;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import net.minecraft.command.argument.ItemStackArgumentType; import net.minecraft.command.argument.ItemStackArgumentType;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -59,8 +59,8 @@ public class ShopCommands {
private static int setStack(CommandContext<ServerCommandSource> ctx, ItemStack stack) { private static int setStack(CommandContext<ServerCommandSource> ctx, ItemStack stack) {
String itemName = stack.getItem().toString(); String itemName = stack.getItem().toString();
int buyPrice = IntegerArgumentType.getInteger(ctx, "buyprice"); double buyPrice = DoubleArgumentType.getDouble(ctx, "buyprice");
int sellPrice = IntegerArgumentType.getInteger(ctx, "sellprice"); double sellPrice = DoubleArgumentType.getDouble(ctx, "sellprice");
ServerShop.priceStorage.setPrices(stack, buyPrice, sellPrice); ServerShop.priceStorage.setPrices(stack, buyPrice, sellPrice);
ctx.getSource().sendFeedback(() -> Text.translatable("message.servershop.prices.set", itemName, buyPrice, sellPrice), false); ctx.getSource().sendFeedback(() -> Text.translatable("message.servershop.prices.set", itemName, buyPrice, sellPrice), false);
return 0; return 0;

@ -6,7 +6,6 @@ import eu.pb4.placeholders.api.PlaceholderResult;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import systems.brn.servershop.lib.storages.PriceStorage;
import static systems.brn.servershop.ServerShop.balanceStorage; import static systems.brn.servershop.ServerShop.balanceStorage;
@ -14,7 +13,7 @@ public class BalancePlaceholder implements PlaceholderHandler {
@Override @Override
public PlaceholderResult onPlaceholderRequest(PlaceholderContext context, @Nullable String argument) { public PlaceholderResult onPlaceholderRequest(PlaceholderContext context, @Nullable String argument) {
ServerPlayerEntity player = context.player(); ServerPlayerEntity player = context.player();
long balance = 0; double balance = 0;
if (balanceStorage != null && player != null) { if (balanceStorage != null && player != null) {
balance = balanceStorage.getBalance(player); balance = balanceStorage.getBalance(player);
} }

@ -187,7 +187,7 @@ public abstract class PagedGui extends SimpleGui {
if (gui.canNextPage()) { if (gui.canNextPage()) {
return DisplayElement.of( return DisplayElement.of(
new GuiElementBuilder(Items.PLAYER_HEAD) new GuiElementBuilder(Items.PLAYER_HEAD)
.setName(Text.translatable("createWorld.customize.custom.next").formatted(Formatting.WHITE)) .setName(Text.translatable("spectatorMenu.next_page").formatted(Formatting.WHITE))
.hideDefaultTooltip().noDefaults() .hideDefaultTooltip().noDefaults()
.setSkullOwner(GUI_NEXT_PAGE) .setSkullOwner(GUI_NEXT_PAGE)
.setCallback((x, y, z) -> { .setCallback((x, y, z) -> {
@ -198,7 +198,7 @@ public abstract class PagedGui extends SimpleGui {
} else { } else {
return DisplayElement.of( return DisplayElement.of(
new GuiElementBuilder(Items.PLAYER_HEAD) new GuiElementBuilder(Items.PLAYER_HEAD)
.setName(Text.translatable("createWorld.customize.custom.next").formatted(Formatting.DARK_GRAY)) .setName(Text.translatable("spectatorMenu.next_page").formatted(Formatting.DARK_GRAY))
.hideDefaultTooltip().noDefaults() .hideDefaultTooltip().noDefaults()
.setSkullOwner(GUI_NEXT_PAGE_BLOCKED) .setSkullOwner(GUI_NEXT_PAGE_BLOCKED)
); );
@ -209,7 +209,7 @@ public abstract class PagedGui extends SimpleGui {
if (gui.canPreviousPage()) { if (gui.canPreviousPage()) {
return DisplayElement.of( return DisplayElement.of(
new GuiElementBuilder(Items.PLAYER_HEAD) new GuiElementBuilder(Items.PLAYER_HEAD)
.setName(Text.translatable("createWorld.customize.custom.prev").formatted(Formatting.WHITE)) .setName(Text.translatable("spectatorMenu.previous_page").formatted(Formatting.WHITE))
.hideDefaultTooltip().noDefaults() .hideDefaultTooltip().noDefaults()
.setSkullOwner(GUI_PREVIOUS_PAGE) .setSkullOwner(GUI_PREVIOUS_PAGE)
.setCallback((x, y, z) -> { .setCallback((x, y, z) -> {
@ -220,7 +220,7 @@ public abstract class PagedGui extends SimpleGui {
} else { } else {
return DisplayElement.of( return DisplayElement.of(
new GuiElementBuilder(Items.PLAYER_HEAD) new GuiElementBuilder(Items.PLAYER_HEAD)
.setName(Text.translatable("createWorld.customize.custom.prev").formatted(Formatting.DARK_GRAY)) .setName(Text.translatable("spectatorMenu.previous_page").formatted(Formatting.DARK_GRAY))
.hideDefaultTooltip().noDefaults() .hideDefaultTooltip().noDefaults()
.setSkullOwner(GUI_PREVIOUS_PAGE_BLOCKED) .setSkullOwner(GUI_PREVIOUS_PAGE_BLOCKED)
); );

@ -15,16 +15,16 @@ public class ShopFunctions {
ItemStack itemStack = itemStackIn.copy(); ItemStack itemStack = itemStackIn.copy();
PlayerInventory playerInventory = player.getInventory(); PlayerInventory playerInventory = player.getInventory();
ItemPriceRecord price = priceStorage.getPrices(itemStack); ItemPriceRecord price = priceStorage.getPrices(itemStack);
long playerBalance = balanceStorage.getBalance(player); double playerBalance = balanceStorage.getBalance(player);
if (price.buyPrice() > 0) { if (price.buyPrice() > 0) {
int count = Math.min(itemStack.getCount(), maxInsertionAmount(playerInventory, itemStack.copy())); int count = Math.min(itemStack.getCount(), maxInsertionAmount(playerInventory, itemStack.copy()));
itemStack.setCount(count); itemStack.setCount(count);
int buyPrice = price.buyPrice() * itemStack.getCount(); double buyPrice = price.buyPrice() * itemStack.getCount();
if (playerBalance >= buyPrice) { if (playerBalance >= buyPrice) {
ItemStack remaining = insertStackIntoInventory(playerInventory, itemStack.copy()); ItemStack remaining = insertStackIntoInventory(playerInventory, itemStack.copy());
int boughtCount = itemStack.getCount() - remaining.getCount(); int boughtCount = itemStack.getCount() - remaining.getCount();
if (boughtCount > 0) { if (boughtCount > 0) {
int toDeduce = price.buyPrice() * boughtCount; double toDeduce = price.buyPrice() * boughtCount;
balanceStorage.removeBalance(player, toDeduce); balanceStorage.removeBalance(player, toDeduce);
playerBalance = balanceStorage.getBalance(player); playerBalance = balanceStorage.getBalance(player);
player.sendMessage(Text.translatable("message.servershop.buy.success", boughtCount, itemStack.getName(), toDeduce, playerBalance), overlay); player.sendMessage(Text.translatable("message.servershop.buy.success", boughtCount, itemStack.getName(), toDeduce, playerBalance), overlay);
@ -43,7 +43,7 @@ public class ShopFunctions {
PlayerInventory playerInventory = player.getInventory(); PlayerInventory playerInventory = player.getInventory();
ItemStack itemStack = itemStackIn.copy(); ItemStack itemStack = itemStackIn.copy();
ItemPriceRecord price = priceStorage.getPrices(itemStack); ItemPriceRecord price = priceStorage.getPrices(itemStack);
int sellPrice = price.sellPrice(); double sellPrice = price.sellPrice();
if (sellPrice > 0) { if (sellPrice > 0) {
int remaining; int remaining;
if (!isCursorStack) { if (!isCursorStack) {
@ -52,13 +52,13 @@ public class ShopFunctions {
remaining = 0; remaining = 0;
itemStackIn.setCount(0); itemStackIn.setCount(0);
} }
int toAdd = sellPrice * (itemStack.getCount() - remaining); double toAdd = sellPrice * (itemStack.getCount() - remaining);
int soldCount = itemStack.getCount() - remaining; int soldCount = itemStack.getCount() - remaining;
balanceStorage.addBalance(player, toAdd); balanceStorage.addBalance(player, toAdd);
if (soldCount == 0) { if (soldCount == 0) {
player.sendMessage(Text.translatable("message.servershop.sell.not_enough"), overlay); player.sendMessage(Text.translatable("message.servershop.sell.not_enough"), overlay);
} else { } else {
long playerBalance = balanceStorage.getBalance(player); double playerBalance = balanceStorage.getBalance(player);
player.sendMessage(Text.translatable("message.servershop.sell.success", soldCount, itemStack.getName(), toAdd, playerBalance), overlay); player.sendMessage(Text.translatable("message.servershop.sell.success", soldCount, itemStack.getName(), toAdd, playerBalance), overlay);
} }
} else { } else {

@ -188,8 +188,8 @@ public class Util {
public static ItemStack addPricesEditor(ItemPriceRecord price) { public static ItemStack addPricesEditor(ItemPriceRecord price) {
ItemStack stack = price.stack(); ItemStack stack = price.stack();
int buyPrice = price.buyPrice(); double buyPrice = price.buyPrice();
int sellPrice = price.sellPrice(); double sellPrice = price.sellPrice();
int count = stack.getCount(); int count = stack.getCount();
if (count > 0) { if (count > 0) {
return addLore(buyPrice, sellPrice, stack, true, null, false); return addLore(buyPrice, sellPrice, stack, true, null, false);
@ -200,8 +200,8 @@ public class Util {
public static ItemStack addPrices(ItemPriceRecord price) { public static ItemStack addPrices(ItemPriceRecord price) {
ItemStack stack = price.stack(); ItemStack stack = price.stack();
int buyPrice = price.buyPrice(); double buyPrice = price.buyPrice();
int sellPrice = price.sellPrice(); double sellPrice = price.sellPrice();
int count = stack.getCount(); int count = stack.getCount();
if (count > 0) { if (count > 0) {
return addLore(buyPrice, sellPrice, stack, false, null, false); return addLore(buyPrice, sellPrice, stack, false, null, false);
@ -212,8 +212,8 @@ public class Util {
public static ItemStack addPrices(AuctionRecord auctionRecord, ServerPlayerEntity looker) { public static ItemStack addPrices(AuctionRecord auctionRecord, ServerPlayerEntity looker) {
ItemStack stack = auctionRecord.stack(); ItemStack stack = auctionRecord.stack();
int buyPrice = auctionRecord.buyPrice(); double buyPrice = auctionRecord.buyPrice();
int sellPrice = 0; double sellPrice = 0;
int count = stack.getCount(); int count = stack.getCount();
if (count > 0) { if (count > 0) {
return addLore(buyPrice, sellPrice, stack, false, auctionRecord.getProfile(looker.getServer()).getName(), auctionRecord.sellerUUID().equals(looker.getUuid())); return addLore(buyPrice, sellPrice, stack, false, auctionRecord.getProfile(looker.getServer()).getName(), auctionRecord.sellerUUID().equals(looker.getUuid()));
@ -223,7 +223,7 @@ public class Util {
} }
@NotNull @NotNull
private static ItemStack addLore(int buyPrice, int sellPrice, ItemStack stack, boolean isEditor, String sellerName, boolean me) { private static ItemStack addLore(double buyPrice, double sellPrice, ItemStack stack, boolean isEditor, String sellerName, boolean me) {
Text buyLine = Text.translatable("gui.servershop." + (isEditor ? "shop.editor." : "") + "item.buy_price" + (buyPrice == 0 ? "_not_buyable" : "") + (buyPrice == -1 ? "_disabled" : ""), buyPrice).setStyle(Style.EMPTY.withColor(Formatting.DARK_GREEN).withItalic(true)); Text buyLine = Text.translatable("gui.servershop." + (isEditor ? "shop.editor." : "") + "item.buy_price" + (buyPrice == 0 ? "_not_buyable" : "") + (buyPrice == -1 ? "_disabled" : ""), buyPrice).setStyle(Style.EMPTY.withColor(Formatting.DARK_GREEN).withItalic(true));
Text sellLine = Text.translatable("gui.servershop." + (isEditor ? "shop.editor." : "") + "item.sell_price" + (sellPrice == 0 ? "_not_sellable" : "") + (sellPrice == -1 ? "_disabled" : ""), sellPrice).setStyle(Style.EMPTY.withColor(Formatting.AQUA).withItalic(true)); Text sellLine = Text.translatable("gui.servershop." + (isEditor ? "shop.editor." : "") + "item.sell_price" + (sellPrice == 0 ? "_not_sellable" : "") + (sellPrice == -1 ? "_disabled" : ""), sellPrice).setStyle(Style.EMPTY.withColor(Formatting.AQUA).withItalic(true));
Text infoLine = Text.translatable("gui.servershop." + (isEditor ? "shop.editor." : "") + "item.stack_info").setStyle(Style.EMPTY.withColor(Formatting.YELLOW).withItalic(true)); Text infoLine = Text.translatable("gui.servershop." + (isEditor ? "shop.editor." : "") + "item.stack_info").setStyle(Style.EMPTY.withColor(Formatting.YELLOW).withItalic(true));
@ -280,19 +280,19 @@ public class Util {
sortedMap = new TreeMap<>((o1, o2) -> { sortedMap = new TreeMap<>((o1, o2) -> {
ItemPriceRecord record1 = priceRecordMap.get(o1); ItemPriceRecord record1 = priceRecordMap.get(o1);
ItemPriceRecord record2 = priceRecordMap.get(o2); ItemPriceRecord record2 = priceRecordMap.get(o2);
int buyPrice1 = record1.buyPrice(); double buyPrice1 = record1.buyPrice();
int sellPrice1 = record1.sellPrice(); double sellPrice1 = record1.sellPrice();
int buyPrice2 = record2.buyPrice(); double buyPrice2 = record2.buyPrice();
int sellPrice2 = record2.sellPrice(); double sellPrice2 = record2.sellPrice();
int countCompare; int countCompare;
if (sortMode == 0) { if (sortMode == 0) {
countCompare = Integer.compare(buyPrice1, buyPrice2); countCompare = Double.compare(buyPrice1, buyPrice2);
} else if (sortMode == 1) { } else if (sortMode == 1) {
countCompare = Integer.compare(buyPrice2, buyPrice1); countCompare = Double.compare(buyPrice2, buyPrice1);
} else if (sortMode == 2) { } else if (sortMode == 2) {
countCompare = Integer.compare(sellPrice1, sellPrice2); countCompare = Double.compare(sellPrice1, sellPrice2);
} else { //sortmode 3 } else { //sortmode 3
countCompare = Integer.compare(sellPrice2, sellPrice1); countCompare = Double.compare(sellPrice2, sellPrice1);
} }
// If counts are equal, compare items alphabetically by name // If counts are equal, compare items alphabetically by name
return countCompare == 0 ? String.valueOf(o1.getItem()).compareToIgnoreCase(String.valueOf(o2.getItem())) : countCompare; return countCompare == 0 ? String.valueOf(o1.getItem()).compareToIgnoreCase(String.valueOf(o2.getItem())) : countCompare;
@ -301,8 +301,8 @@ public class Util {
return sortedMap; return sortedMap;
} }
private static @NotNull TreeMap<UUID, Long> getBalancesTreeMap(Map<UUID, Long> balanceRecordMap, MinecraftServer server, int sortMode) { private static @NotNull TreeMap<UUID, Double> getBalancesTreeMap(Map<UUID, Double> balanceRecordMap, MinecraftServer server, int sortMode) {
TreeMap<UUID, Long> sortedMap; TreeMap<UUID, Double> sortedMap;
if (sortMode == 2 || sortMode == 3) { if (sortMode == 2 || sortMode == 3) {
// Sort alphabetically by player name // Sort alphabetically by player name
@ -318,13 +318,13 @@ public class Util {
} else { } else {
// Sort by count in descending order // Sort by count in descending order
sortedMap = new TreeMap<>((o1, o2) -> { sortedMap = new TreeMap<>((o1, o2) -> {
Long balance1 = balanceRecordMap.get(o1); Double balance1 = balanceRecordMap.get(o1);
Long balance2 = balanceRecordMap.get(o2); Double balance2 = balanceRecordMap.get(o2);
int countCompare; int countCompare;
if (sortMode == 0) { if (sortMode == 0) {
countCompare = Long.compare(balance1, balance2); countCompare = Double.compare(balance1, balance2);
} else { } else {
countCompare = Long.compare(balance2, balance1); countCompare = Double.compare(balance2, balance1);
} }
// If counts are equal, compare items alphabetically by name // If counts are equal, compare items alphabetically by name
return countCompare == 0 ? getGameProfile(o1, server).getName().compareToIgnoreCase(getGameProfile(o2, server).getName()) : countCompare; return countCompare == 0 ? getGameProfile(o1, server).getName().compareToIgnoreCase(getGameProfile(o2, server).getName()) : countCompare;
@ -357,13 +357,13 @@ public class Util {
} else { } else {
// Sort by count in descending order // Sort by count in descending order
sortedSet = new TreeSet<>((record1, record2) -> { sortedSet = new TreeSet<>((record1, record2) -> {
int buyPrice1 = record1.buyPrice(); double buyPrice1 = record1.buyPrice();
int buyPrice2 = record2.buyPrice(); double buyPrice2 = record2.buyPrice();
int countCompare; int countCompare;
if (sortMode == 0) { if (sortMode == 0) {
countCompare = Integer.compare(buyPrice1, buyPrice2); countCompare = Double.compare(buyPrice1, buyPrice2);
} else { } else {
countCompare = Integer.compare(buyPrice2, buyPrice1); countCompare = Double.compare(buyPrice2, buyPrice1);
} }
// If counts are equal, compare items alphabetically by name // If counts are equal, compare items alphabetically by name
return countCompare == 0 ? String.valueOf(record1.stack().getItem()).compareToIgnoreCase(String.valueOf(record2.stack().getItem())) : countCompare; return countCompare == 0 ? String.valueOf(record1.stack().getItem()).compareToIgnoreCase(String.valueOf(record2.stack().getItem())) : countCompare;
@ -418,12 +418,12 @@ public class Util {
return sortedMap; return sortedMap;
} }
public static TreeMap<UUID, Long> sortaAndFilterBalances(Map<UUID, Long> balancesMap, MinecraftServer server, int sortMode, String query) { public static TreeMap<UUID, Double> sortaAndFilterBalances(Map<UUID, Double> balancesMap, MinecraftServer server, int sortMode, String query) {
TreeMap<UUID, Long> sortedMap = getBalancesTreeMap(balancesMap, server, sortMode); TreeMap<UUID, Double> sortedMap = getBalancesTreeMap(balancesMap, server, sortMode);
Map<UUID, Long> filteredMap = new HashMap<>(); Map<UUID, Double> filteredMap = new HashMap<>();
for (Map.Entry<UUID, Long> entry : balancesMap.entrySet()) { for (Map.Entry<UUID, Double> entry : balancesMap.entrySet()) {
UUID uuid = entry.getKey(); UUID uuid = entry.getKey();
GameProfile profile = getGameProfile(uuid, server); GameProfile profile = getGameProfile(uuid, server);
if (query == null || query.isEmpty() || query.equals("*") || query.equals("Filter not set") || profile.getName().toLowerCase().contains(query.toLowerCase())) { if (query == null || query.isEmpty() || query.equals("*") || query.equals("Filter not set") || profile.getName().toLowerCase().contains(query.toLowerCase())) {

@ -12,12 +12,12 @@ import java.util.UUID;
import static systems.brn.servershop.lib.Util.getGameProfile; import static systems.brn.servershop.lib.Util.getGameProfile;
public record AuctionRecord(int buyPrice, ItemStack stack, UUID sellerUUID) { public record AuctionRecord(double buyPrice, ItemStack stack, UUID sellerUUID) {
public NbtCompound toNbt(RegistryWrapper.WrapperLookup wrapperLookup) { public NbtCompound toNbt(RegistryWrapper.WrapperLookup wrapperLookup) {
NbtCompound nbt = new NbtCompound(); NbtCompound nbt = new NbtCompound();
nbt.putInt("BuyPrice", this.buyPrice); nbt.putDouble("BuyPrice", this.buyPrice);
nbt.putUuid("SellerUUID", sellerUUID); nbt.putUuid("SellerUUID", sellerUUID);
// Serialize the ItemStack to NBT and add it to the compound // Serialize the ItemStack to NBT and add it to the compound
@ -32,7 +32,7 @@ public record AuctionRecord(int buyPrice, ItemStack stack, UUID sellerUUID) {
} }
public static AuctionRecord fromNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) { public static AuctionRecord fromNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
int buyPrice = nbt.getInt("BuyPrice"); double buyPrice = nbt.getFloat("BuyPrice");
UUID sellerUUID = nbt.getUuid("SellerUUID"); UUID sellerUUID = nbt.getUuid("SellerUUID");
// Deserialize the ItemStack from the NBT // Deserialize the ItemStack from the NBT

@ -7,13 +7,13 @@ import net.minecraft.registry.RegistryWrapper;
import java.util.Optional; import java.util.Optional;
public record ItemPriceRecord(int buyPrice, int sellPrice, ItemStack stack) { public record ItemPriceRecord(double buyPrice, double sellPrice, ItemStack stack) {
public NbtCompound toNbt(RegistryWrapper.WrapperLookup wrapperLookup) { public NbtCompound toNbt(RegistryWrapper.WrapperLookup wrapperLookup) {
NbtCompound nbt = new NbtCompound(); NbtCompound nbt = new NbtCompound();
nbt.putInt("BuyPrice", this.buyPrice); nbt.putDouble("BuyPrice", this.buyPrice);
nbt.putInt("SellPrice", this.sellPrice); nbt.putDouble("SellPrice", this.sellPrice);
// Serialize the ItemStack to NBT and add it to the compound // Serialize the ItemStack to NBT and add it to the compound
if (stack != null && !stack.isEmpty()) { if (stack != null && !stack.isEmpty()) {
@ -26,8 +26,8 @@ public record ItemPriceRecord(int buyPrice, int sellPrice, ItemStack stack) {
} }
public static ItemPriceRecord fromNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) { public static ItemPriceRecord fromNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
int buyPrice = nbt.getInt("BuyPrice"); double buyPrice = nbt.getFloat("BuyPrice");
int sellPrice = nbt.getInt("SellPrice"); double sellPrice = nbt.getFloat("SellPrice");
if (sellPrice > buyPrice && buyPrice != 0) { if (sellPrice > buyPrice && buyPrice != 0) {
buyPrice = sellPrice; buyPrice = sellPrice;
@ -36,7 +36,7 @@ public record ItemPriceRecord(int buyPrice, int sellPrice, ItemStack stack) {
NbtElement stackElement = nbt.get("ItemStack"); NbtElement stackElement = nbt.get("ItemStack");
Optional<ItemStack> stack = ItemStack.fromNbt(wrapperLookup, stackElement); Optional<ItemStack> stack = ItemStack.fromNbt(wrapperLookup, stackElement);
int finalBuyPrice = buyPrice; double finalBuyPrice = buyPrice;
return stack.map(itemStack -> new ItemPriceRecord(finalBuyPrice, sellPrice, itemStack)).orElse(null); return stack.map(itemStack -> new ItemPriceRecord(finalBuyPrice, sellPrice, itemStack)).orElse(null);
} }

@ -1,6 +1,5 @@
package systems.brn.servershop.lib.storages; package systems.brn.servershop.lib.storages;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.*; import net.minecraft.nbt.*;
@ -39,7 +38,7 @@ public class AuctionStorage {
load(); load();
} }
public void addAuction(ServerPlayerEntity seller, int price, ItemStack itemStack, boolean fromCursorStack) { public void addAuction(ServerPlayerEntity seller, double price, ItemStack itemStack, boolean fromCursorStack) {
PlayerInventory playerInventory = seller.getInventory(); PlayerInventory playerInventory = seller.getInventory();
if (itemStack.isEmpty()) { if (itemStack.isEmpty()) {
seller.sendMessage(Text.translatable("message.servershop.auction.empty"), true); seller.sendMessage(Text.translatable("message.servershop.auction.empty"), true);
@ -73,14 +72,14 @@ public class AuctionStorage {
public void buyAuction(ServerPlayerEntity buyer, AuctionRecord auction) { public void buyAuction(ServerPlayerEntity buyer, AuctionRecord auction) {
PlayerInventory playerInventory = buyer.getInventory(); PlayerInventory playerInventory = buyer.getInventory();
ItemStack itemStack = removePrices(auction.stack()); ItemStack itemStack = removePrices(auction.stack());
int buyPrice = auction.buyPrice() * itemStack.getCount(); double buyPrice = auction.buyPrice() * itemStack.getCount();
long playerBalance = balanceStorage.getBalance(buyer); double playerBalance = balanceStorage.getBalance(buyer);
if (buyPrice > 0 && auctions.contains(auction)) { if (buyPrice > 0 && auctions.contains(auction)) {
if (playerBalance >= buyPrice || buyer.getUuid().equals(auction.sellerUUID())) { if (playerBalance >= buyPrice || buyer.getUuid().equals(auction.sellerUUID())) {
ItemStack remaining = insertStackIntoInventory(playerInventory, itemStack.copy()); ItemStack remaining = insertStackIntoInventory(playerInventory, itemStack.copy());
int boughtCount = itemStack.getCount() - remaining.getCount(); int boughtCount = itemStack.getCount() - remaining.getCount();
if (boughtCount > 0) { if (boughtCount > 0) {
int toDeduce = auction.buyPrice() * boughtCount; double toDeduce = auction.buyPrice() * boughtCount;
if (!buyer.getUuid().equals(auction.sellerUUID())) { if (!buyer.getUuid().equals(auction.sellerUUID())) {
balanceStorage.removeBalance(buyer, toDeduce); balanceStorage.removeBalance(buyer, toDeduce);
balanceStorage.addBalance(auction.sellerUUID(), toDeduce); balanceStorage.addBalance(auction.sellerUUID(), toDeduce);
@ -88,7 +87,7 @@ public class AuctionStorage {
buyer.sendMessage(Text.translatable("message.servershop.buy.success", boughtCount, itemStack.getName(), toDeduce, playerBalance), true); buyer.sendMessage(Text.translatable("message.servershop.buy.success", boughtCount, itemStack.getName(), toDeduce, playerBalance), true);
ServerPlayerEntity seller = server.getPlayerManager().getPlayer(auction.sellerUUID()); ServerPlayerEntity seller = server.getPlayerManager().getPlayer(auction.sellerUUID());
if (seller != null && !seller.isDisconnected()) { if (seller != null && !seller.isDisconnected()) {
long sellerBalance = balanceStorage.getBalance(seller); double sellerBalance = balanceStorage.getBalance(seller);
seller.sendMessage(Text.translatable("message.servershop.buy.other", buyer.getName(), boughtCount, itemStack.getName(), toDeduce, sellerBalance), true); seller.sendMessage(Text.translatable("message.servershop.buy.other", buyer.getName(), boughtCount, itemStack.getName(), toDeduce, sellerBalance), true);
} }
} else { } else {

@ -13,7 +13,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
public class BalanceStorage { public class BalanceStorage {
public final ConcurrentHashMap<UUID, Long> balances = new ConcurrentHashMap<>(); public final ConcurrentHashMap<UUID, Double> balances = new ConcurrentHashMap<>();
public final MinecraftServer server; public final MinecraftServer server;
private final File balanceStorageFile; private final File balanceStorageFile;
private final File balanceStorageCSVFile; private final File balanceStorageCSVFile;
@ -26,40 +26,40 @@ public class BalanceStorage {
loadBalances(); loadBalances();
} }
public long getBalance(UUID uuid) { public double getBalance(UUID uuid) {
return balances.getOrDefault(uuid, 0L); return balances.getOrDefault(uuid, (double) 0);
} }
public long getBalance(ServerPlayerEntity player) { public double getBalance(ServerPlayerEntity player) {
return getBalance(player.getUuid()); return getBalance(player.getUuid());
} }
public void addBalance(UUID uuid, long amount) { public void addBalance(UUID uuid, double amount) {
balances.put(uuid, getBalance(uuid) + amount); balances.put(uuid, getBalance(uuid) + amount);
saveBalances(); saveBalances();
} }
public void addBalance(ServerPlayerEntity player, long amount) { public void addBalance(ServerPlayerEntity player, double amount) {
addBalance(player.getUuid(), amount); addBalance(player.getUuid(), amount);
announceBalance(player, true); announceBalance(player, true);
} }
public void removeBalance(UUID uuid, long amount) { public void removeBalance(UUID uuid, double amount) {
balances.put(uuid, getBalance(uuid) - amount); balances.put(uuid, getBalance(uuid) - amount);
saveBalances(); saveBalances();
} }
public void setBalance(UUID uuid, long amount) { public void setBalance(UUID uuid, double amount) {
balances.put(uuid, amount); balances.put(uuid, amount);
saveBalances(); saveBalances();
} }
public void setBalance(ServerPlayerEntity player, long amount) { public void setBalance(ServerPlayerEntity player, double amount) {
setBalance(player.getUuid(), amount); setBalance(player.getUuid(), amount);
announceBalance(player, true); announceBalance(player, true);
} }
public void removeBalance(ServerPlayerEntity player, long amount) { public void removeBalance(ServerPlayerEntity player, double amount) {
removeBalance(player.getUuid(), amount); removeBalance(player.getUuid(), amount);
announceBalance(player, true); announceBalance(player, true);
} }
@ -71,7 +71,7 @@ public class BalanceStorage {
for (UUID uuid : balances.keySet()) { for (UUID uuid : balances.keySet()) {
NbtCompound nbtCompound = new NbtCompound(); NbtCompound nbtCompound = new NbtCompound();
nbtCompound.putUuid("UUID", uuid); nbtCompound.putUuid("UUID", uuid);
nbtCompound.putLong("Balance", balances.get(uuid)); nbtCompound.putDouble("Balance", balances.get(uuid));
nbtList.add(nbtCompound); nbtList.add(nbtCompound);
} }
@ -102,7 +102,7 @@ public class BalanceStorage {
for (NbtElement element : nbtList) { for (NbtElement element : nbtList) {
if (element instanceof NbtCompound nbt) { if (element instanceof NbtCompound nbt) {
UUID uuid = nbt.getUuid("UUID"); UUID uuid = nbt.getUuid("UUID");
long balance = nbt.getLong("Balance"); double balance = nbt.getDouble("Balance");
balances.put(uuid, balance); balances.put(uuid, balance);
} }
} }
@ -134,7 +134,7 @@ public class BalanceStorage {
String[] lineParts = line.split(","); String[] lineParts = line.split(",");
if (lineParts.length == 2) { if (lineParts.length == 2) {
UUID uuid = UUID.fromString(lineParts[0]); UUID uuid = UUID.fromString(lineParts[0]);
Long amount = Long.parseLong(lineParts[1]); double amount = Double.parseDouble(lineParts[1]);
balances.put(uuid, amount); balances.put(uuid, amount);
} }
} }
@ -150,7 +150,7 @@ public class BalanceStorage {
public void announceBalance(ServerPlayerEntity player, boolean overlay) { public void announceBalance(ServerPlayerEntity player, boolean overlay) {
UUID uuid = player.getUuid(); UUID uuid = player.getUuid();
long balance = balances.getOrDefault(uuid, 0L); double balance = balances.getOrDefault(uuid, (double) 0);
player.sendMessage(Text.translatable("message.servershop.balance.self", balance), overlay); player.sendMessage(Text.translatable("message.servershop.balance.self", balance), overlay);
} }
} }

@ -51,7 +51,7 @@ public class PriceStorage {
} }
} }
public void setPrices(ItemStack inStack, int buyPrice, int sellPrice) { public void setPrices(ItemStack inStack, double buyPrice, double sellPrice) {
boolean found = false; boolean found = false;
for (ItemStack priceStack : prices.keySet()) { for (ItemStack priceStack : prices.keySet()) {
if (ItemStack.areItemsAndComponentsEqual(inStack, priceStack)) { if (ItemStack.areItemsAndComponentsEqual(inStack, priceStack)) {
@ -157,8 +157,8 @@ public class PriceStorage {
String[] itemIdentifierParts = itemName.split(":"); String[] itemIdentifierParts = itemName.split(":");
if (itemIdentifierParts.length == 2) { if (itemIdentifierParts.length == 2) {
Identifier itemIdentifier = Identifier.of(itemIdentifierParts[0], itemIdentifierParts[1]); Identifier itemIdentifier = Identifier.of(itemIdentifierParts[0], itemIdentifierParts[1]);
int buyPrice = Integer.parseInt(lineParts[1]); double buyPrice = Double.parseDouble(lineParts[1]);
int sellPrice = Integer.parseInt(lineParts[2]); double sellPrice = Double.parseDouble(lineParts[2]);
Item item = Registries.ITEM.get(itemIdentifier); Item item = Registries.ITEM.get(itemIdentifier);
prices.put(item.getDefaultStack(), new ItemPriceRecord(buyPrice, sellPrice, item.getDefaultStack())); prices.put(item.getDefaultStack(), new ItemPriceRecord(buyPrice, sellPrice, item.getDefaultStack()));
} }

@ -15,7 +15,6 @@ import systems.brn.servershop.lib.SearchableInterface;
import systems.brn.servershop.lib.records.AuctionRecord; import systems.brn.servershop.lib.records.AuctionRecord;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.TreeSet;
import static systems.brn.servershop.lib.Util.*; import static systems.brn.servershop.lib.Util.*;
@ -23,7 +22,7 @@ public class AuctionBrowserScreen extends PagedGui implements SearchableInterfac
public String searchQuery = ""; public String searchQuery = "";
public int sortMode = 0; public int sortMode = 0;
public int maxSortMode = 5; public final int maxSortMode = 5;
public ArrayList<AuctionRecord> filteredAuctions; public ArrayList<AuctionRecord> filteredAuctions;

@ -1,12 +1,8 @@
package systems.brn.servershop.screens; package systems.brn.servershop.screens;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import eu.pb4.sgui.api.ClickType;
import eu.pb4.sgui.api.elements.GuiElementBuilder; import eu.pb4.sgui.api.elements.GuiElementBuilder;
import eu.pb4.sgui.api.elements.GuiElementInterface;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -14,12 +10,9 @@ import net.minecraft.util.Formatting;
import systems.brn.servershop.ServerShop; import systems.brn.servershop.ServerShop;
import systems.brn.servershop.lib.PagedGui; import systems.brn.servershop.lib.PagedGui;
import systems.brn.servershop.lib.SearchableInterface; import systems.brn.servershop.lib.SearchableInterface;
import systems.brn.servershop.lib.records.ItemPriceRecord;
import java.util.*; import java.util.*;
import static systems.brn.servershop.lib.ShopFunctions.buy;
import static systems.brn.servershop.lib.ShopFunctions.sell;
import static systems.brn.servershop.lib.Util.*; import static systems.brn.servershop.lib.Util.*;
public class BalanceScreen extends PagedGui implements SearchableInterface { public class BalanceScreen extends PagedGui implements SearchableInterface {
@ -28,7 +21,7 @@ public class BalanceScreen extends PagedGui implements SearchableInterface {
public int sortMode = 0; public int sortMode = 0;
public final int maxSortMode = 3; public final int maxSortMode = 3;
public TreeMap<UUID, Long> filteredBalances; public TreeMap<UUID, Double> filteredBalances;
public BalanceScreen(ServerPlayerEntity player) { public BalanceScreen(ServerPlayerEntity player) {
super(player, null); super(player, null);
@ -63,11 +56,11 @@ public class BalanceScreen extends PagedGui implements SearchableInterface {
protected DisplayElement getElement(int id) { protected DisplayElement getElement(int id) {
MinecraftServer server = player.getServer(); MinecraftServer server = player.getServer();
if (server != null) { if (server != null) {
List<Map.Entry<UUID, Long>> list = new ArrayList<>(filteredBalances.entrySet()); List<Map.Entry<UUID, Double>> list = new ArrayList<>(filteredBalances.entrySet());
if (id < list.size()) { if (id < list.size()) {
Map.Entry<UUID, Long> balanceEntry = list.get(id); Map.Entry<UUID, Double> balanceEntry = list.get(id);
UUID targetUUID = balanceEntry.getKey(); UUID targetUUID = balanceEntry.getKey();
Long targetBalance = balanceEntry.getValue(); Double targetBalance = balanceEntry.getValue();
GameProfile targetProfile = getGameProfile(targetUUID, server); GameProfile targetProfile = getGameProfile(targetUUID, server);
GuiElementBuilder elementBuilder = new GuiElementBuilder(Items.PLAYER_HEAD) GuiElementBuilder elementBuilder = new GuiElementBuilder(Items.PLAYER_HEAD)
.setSkullOwner(targetProfile, server) .setSkullOwner(targetProfile, server)

@ -5,18 +5,16 @@ import eu.pb4.sgui.api.gui.SimpleGui;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import systems.brn.servershop.lib.PagedGui; import systems.brn.servershop.lib.PagedGui;
import systems.brn.servershop.lib.records.ItemPriceRecord;
import java.util.UUID; import java.util.UUID;
import static systems.brn.servershop.ServerShop.balanceStorage; import static systems.brn.servershop.ServerShop.balanceStorage;
import static systems.brn.servershop.ServerShop.priceStorage;
import static systems.brn.servershop.lib.Util.getGameProfile; import static systems.brn.servershop.lib.Util.getGameProfile;
public class BalanceSetScreen extends AnvilInputGui { public class BalanceSetScreen extends AnvilInputGui {
private final SimpleGui parentScreen; private final SimpleGui parentScreen;
private long balance; private double balance;
private final UUID targetUUID; private final UUID targetUUID;
public BalanceSetScreen(SimpleGui parentScreen, UUID targetUUID) { public BalanceSetScreen(SimpleGui parentScreen, UUID targetUUID) {
@ -36,7 +34,7 @@ public class BalanceSetScreen extends AnvilInputGui {
super.onClose(); super.onClose();
if (parentScreen != null) { if (parentScreen != null) {
parentScreen.open(); parentScreen.open();
balance = Long.parseLong(this.getInput()); balance = Double.parseDouble(this.getInput());
balanceStorage.setBalance(targetUUID, balance); balanceStorage.setBalance(targetUUID, balance);
if (parentScreen instanceof PagedGui pagedGui) { if (parentScreen instanceof PagedGui pagedGui) {
pagedGui.updateDisplay(); pagedGui.updateDisplay();

@ -16,7 +16,6 @@ import systems.brn.servershop.lib.records.ItemPriceRecord;
import java.util.*; import java.util.*;
import static systems.brn.servershop.ServerShop.priceStorage;
import static systems.brn.servershop.lib.Util.*; import static systems.brn.servershop.lib.Util.*;
public class ShopEditorScreen extends PagedGui implements SearchableInterface { public class ShopEditorScreen extends PagedGui implements SearchableInterface {

@ -12,8 +12,8 @@ import static systems.brn.servershop.ServerShop.priceStorage;
public class ShopPriceSetScreen extends AnvilInputGui { public class ShopPriceSetScreen extends AnvilInputGui {
private final SimpleGui parentScreen; private final SimpleGui parentScreen;
private int buyPrice; private double buyPrice;
private int sellPrice; private double sellPrice;
private final int priceMode; private final int priceMode;
private final ItemStack itemStack; private final ItemStack itemStack;
private boolean isBuyPrice; private boolean isBuyPrice;