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
loader_version=0.16.9
# Mod Properties
mod_version=1.5.1
mod_version=1.5.2
maven_group=systems.brn
archives_base_name=servershop
# Dependencies

@ -1,7 +1,5 @@
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.polymer.resourcepack.api.PolymerResourcePackUtils;
import net.fabricmc.api.ModInitializer;

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

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

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

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

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

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

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

@ -187,7 +187,7 @@ public abstract class PagedGui extends SimpleGui {
if (gui.canNextPage()) {
return DisplayElement.of(
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()
.setSkullOwner(GUI_NEXT_PAGE)
.setCallback((x, y, z) -> {
@ -198,7 +198,7 @@ public abstract class PagedGui extends SimpleGui {
} else {
return DisplayElement.of(
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()
.setSkullOwner(GUI_NEXT_PAGE_BLOCKED)
);
@ -209,7 +209,7 @@ public abstract class PagedGui extends SimpleGui {
if (gui.canPreviousPage()) {
return DisplayElement.of(
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()
.setSkullOwner(GUI_PREVIOUS_PAGE)
.setCallback((x, y, z) -> {
@ -220,7 +220,7 @@ public abstract class PagedGui extends SimpleGui {
} else {
return DisplayElement.of(
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()
.setSkullOwner(GUI_PREVIOUS_PAGE_BLOCKED)
);

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

@ -188,8 +188,8 @@ public class Util {
public static ItemStack addPricesEditor(ItemPriceRecord price) {
ItemStack stack = price.stack();
int buyPrice = price.buyPrice();
int sellPrice = price.sellPrice();
double buyPrice = price.buyPrice();
double sellPrice = price.sellPrice();
int count = stack.getCount();
if (count > 0) {
return addLore(buyPrice, sellPrice, stack, true, null, false);
@ -200,8 +200,8 @@ public class Util {
public static ItemStack addPrices(ItemPriceRecord price) {
ItemStack stack = price.stack();
int buyPrice = price.buyPrice();
int sellPrice = price.sellPrice();
double buyPrice = price.buyPrice();
double sellPrice = price.sellPrice();
int count = stack.getCount();
if (count > 0) {
return addLore(buyPrice, sellPrice, stack, false, null, false);
@ -212,8 +212,8 @@ public class Util {
public static ItemStack addPrices(AuctionRecord auctionRecord, ServerPlayerEntity looker) {
ItemStack stack = auctionRecord.stack();
int buyPrice = auctionRecord.buyPrice();
int sellPrice = 0;
double buyPrice = auctionRecord.buyPrice();
double sellPrice = 0;
int count = stack.getCount();
if (count > 0) {
return addLore(buyPrice, sellPrice, stack, false, auctionRecord.getProfile(looker.getServer()).getName(), auctionRecord.sellerUUID().equals(looker.getUuid()));
@ -223,7 +223,7 @@ public class Util {
}
@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 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));
@ -280,19 +280,19 @@ public class Util {
sortedMap = new TreeMap<>((o1, o2) -> {
ItemPriceRecord record1 = priceRecordMap.get(o1);
ItemPriceRecord record2 = priceRecordMap.get(o2);
int buyPrice1 = record1.buyPrice();
int sellPrice1 = record1.sellPrice();
int buyPrice2 = record2.buyPrice();
int sellPrice2 = record2.sellPrice();
double buyPrice1 = record1.buyPrice();
double sellPrice1 = record1.sellPrice();
double buyPrice2 = record2.buyPrice();
double sellPrice2 = record2.sellPrice();
int countCompare;
if (sortMode == 0) {
countCompare = Integer.compare(buyPrice1, buyPrice2);
countCompare = Double.compare(buyPrice1, buyPrice2);
} else if (sortMode == 1) {
countCompare = Integer.compare(buyPrice2, buyPrice1);
countCompare = Double.compare(buyPrice2, buyPrice1);
} else if (sortMode == 2) {
countCompare = Integer.compare(sellPrice1, sellPrice2);
countCompare = Double.compare(sellPrice1, sellPrice2);
} else { //sortmode 3
countCompare = Integer.compare(sellPrice2, sellPrice1);
countCompare = Double.compare(sellPrice2, sellPrice1);
}
// If counts are equal, compare items alphabetically by name
return countCompare == 0 ? String.valueOf(o1.getItem()).compareToIgnoreCase(String.valueOf(o2.getItem())) : countCompare;
@ -301,8 +301,8 @@ public class Util {
return sortedMap;
}
private static @NotNull TreeMap<UUID, Long> getBalancesTreeMap(Map<UUID, Long> balanceRecordMap, MinecraftServer server, int sortMode) {
TreeMap<UUID, Long> sortedMap;
private static @NotNull TreeMap<UUID, Double> getBalancesTreeMap(Map<UUID, Double> balanceRecordMap, MinecraftServer server, int sortMode) {
TreeMap<UUID, Double> sortedMap;
if (sortMode == 2 || sortMode == 3) {
// Sort alphabetically by player name
@ -318,13 +318,13 @@ public class Util {
} else {
// Sort by count in descending order
sortedMap = new TreeMap<>((o1, o2) -> {
Long balance1 = balanceRecordMap.get(o1);
Long balance2 = balanceRecordMap.get(o2);
Double balance1 = balanceRecordMap.get(o1);
Double balance2 = balanceRecordMap.get(o2);
int countCompare;
if (sortMode == 0) {
countCompare = Long.compare(balance1, balance2);
countCompare = Double.compare(balance1, balance2);
} else {
countCompare = Long.compare(balance2, balance1);
countCompare = Double.compare(balance2, balance1);
}
// If counts are equal, compare items alphabetically by name
return countCompare == 0 ? getGameProfile(o1, server).getName().compareToIgnoreCase(getGameProfile(o2, server).getName()) : countCompare;
@ -357,13 +357,13 @@ public class Util {
} else {
// Sort by count in descending order
sortedSet = new TreeSet<>((record1, record2) -> {
int buyPrice1 = record1.buyPrice();
int buyPrice2 = record2.buyPrice();
double buyPrice1 = record1.buyPrice();
double buyPrice2 = record2.buyPrice();
int countCompare;
if (sortMode == 0) {
countCompare = Integer.compare(buyPrice1, buyPrice2);
countCompare = Double.compare(buyPrice1, buyPrice2);
} else {
countCompare = Integer.compare(buyPrice2, buyPrice1);
countCompare = Double.compare(buyPrice2, buyPrice1);
}
// If counts are equal, compare items alphabetically by name
return countCompare == 0 ? String.valueOf(record1.stack().getItem()).compareToIgnoreCase(String.valueOf(record2.stack().getItem())) : countCompare;
@ -418,12 +418,12 @@ public class Util {
return sortedMap;
}
public static TreeMap<UUID, Long> sortaAndFilterBalances(Map<UUID, Long> balancesMap, MinecraftServer server, int sortMode, String query) {
TreeMap<UUID, Long> sortedMap = getBalancesTreeMap(balancesMap, server, sortMode);
public static TreeMap<UUID, Double> sortaAndFilterBalances(Map<UUID, Double> balancesMap, MinecraftServer server, int sortMode, String query) {
TreeMap<UUID, Double> sortedMap = getBalancesTreeMap(balancesMap, server, sortMode);
Map<UUID, Long> filteredMap = new HashMap<>();
for (Map.Entry<UUID, Long> entry : balancesMap.entrySet()) {
Map<UUID, Double> filteredMap = new HashMap<>();
for (Map.Entry<UUID, Double> entry : balancesMap.entrySet()) {
UUID uuid = entry.getKey();
GameProfile profile = getGameProfile(uuid, server);
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;
public record AuctionRecord(int buyPrice, ItemStack stack, UUID sellerUUID) {
public record AuctionRecord(double buyPrice, ItemStack stack, UUID sellerUUID) {
public NbtCompound toNbt(RegistryWrapper.WrapperLookup wrapperLookup) {
NbtCompound nbt = new NbtCompound();
nbt.putInt("BuyPrice", this.buyPrice);
nbt.putDouble("BuyPrice", this.buyPrice);
nbt.putUuid("SellerUUID", sellerUUID);
// 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) {
int buyPrice = nbt.getInt("BuyPrice");
double buyPrice = nbt.getFloat("BuyPrice");
UUID sellerUUID = nbt.getUuid("SellerUUID");
// Deserialize the ItemStack from the NBT

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

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

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

@ -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;
for (ItemStack priceStack : prices.keySet()) {
if (ItemStack.areItemsAndComponentsEqual(inStack, priceStack)) {
@ -157,8 +157,8 @@ public class PriceStorage {
String[] itemIdentifierParts = itemName.split(":");
if (itemIdentifierParts.length == 2) {
Identifier itemIdentifier = Identifier.of(itemIdentifierParts[0], itemIdentifierParts[1]);
int buyPrice = Integer.parseInt(lineParts[1]);
int sellPrice = Integer.parseInt(lineParts[2]);
double buyPrice = Double.parseDouble(lineParts[1]);
double sellPrice = Double.parseDouble(lineParts[2]);
Item item = Registries.ITEM.get(itemIdentifier);
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 java.util.ArrayList;
import java.util.TreeSet;
import static systems.brn.servershop.lib.Util.*;
@ -23,7 +22,7 @@ public class AuctionBrowserScreen extends PagedGui implements SearchableInterfac
public String searchQuery = "";
public int sortMode = 0;
public int maxSortMode = 5;
public final int maxSortMode = 5;
public ArrayList<AuctionRecord> filteredAuctions;

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

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

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

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