Add more guis
This commit is contained in:
parent
4579f50a66
commit
3d254575bc
@ -6,7 +6,7 @@ minecraft_version=1.21.1
|
||||
yarn_mappings=1.21.1+build.3
|
||||
loader_version=0.16.2
|
||||
# Mod Properties
|
||||
mod_version=1.3.1
|
||||
mod_version=1.4.0
|
||||
maven_group=systems.brn
|
||||
archives_base_name=servershop
|
||||
# Dependencies
|
||||
|
@ -6,15 +6,16 @@ import net.minecraft.command.argument.EntityArgumentType;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import systems.brn.servershop.screens.BalanceScreen;
|
||||
|
||||
import static systems.brn.servershop.ServerShop.balanceStorage;
|
||||
|
||||
public class BalanceCommand {
|
||||
public static int others(CommandContext<ServerCommandSource> ctx) {
|
||||
public static int getOthers(CommandContext<ServerCommandSource> ctx) {
|
||||
try {
|
||||
ServerCommandSource playerObj = ctx.getSource();
|
||||
ServerPlayerEntity player = ctx.getSource().getPlayer();
|
||||
ServerPlayerEntity target = EntityArgumentType.getPlayer(ctx, "recipient");
|
||||
ServerPlayerEntity target = EntityArgumentType.getPlayer(ctx, "target");
|
||||
if (player != null && target != null) {
|
||||
long senderBalance = balanceStorage.getBalance(target);
|
||||
playerObj.sendFeedback(() -> Text.translatable("message.servershop.balance.other", target.getName(), senderBalance), false);
|
||||
@ -25,6 +26,16 @@ public class BalanceCommand {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int list(CommandContext<ServerCommandSource> ctx) {
|
||||
ServerPlayerEntity player = ctx.getSource().getPlayer();
|
||||
if (player != null) {
|
||||
BalanceScreen balanceScreen = new BalanceScreen(player);
|
||||
balanceScreen.open();
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int self(CommandContext<ServerCommandSource> ctx) {
|
||||
try {
|
||||
ServerCommandSource playerObj = ctx.getSource();
|
||||
|
@ -16,6 +16,9 @@ public class CommandRegistry {
|
||||
public static void commandRegister(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) {
|
||||
dispatcher.register(
|
||||
literal("shop")
|
||||
.then(literal("edit")
|
||||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
|
||||
.executes(ShopCommands::edit))
|
||||
.then(literal("load")
|
||||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
|
||||
.executes(ShopCommands::load))
|
||||
@ -25,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())
|
||||
.then(argument("sellprice", IntegerArgumentType.integer())
|
||||
.then(argument("buyprice", IntegerArgumentType.integer(-1))
|
||||
.then(argument("sellprice", IntegerArgumentType.integer(-1))
|
||||
.executes(ShopCommands::set)
|
||||
)
|
||||
)
|
||||
@ -34,8 +37,8 @@ public class CommandRegistry {
|
||||
)
|
||||
.then(literal("setHand")
|
||||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
|
||||
.then(argument("buyprice", IntegerArgumentType.integer())
|
||||
.then(argument("sellprice", IntegerArgumentType.integer())
|
||||
.then(argument("buyprice", IntegerArgumentType.integer(-1))
|
||||
.then(argument("sellprice", IntegerArgumentType.integer(-1))
|
||||
.executes(ShopCommands::setHand)
|
||||
)
|
||||
)
|
||||
@ -51,7 +54,7 @@ public class CommandRegistry {
|
||||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
|
||||
.executes(AuctionCommands::save))
|
||||
.then(literal("create")
|
||||
.then(argument("sellprice", IntegerArgumentType.integer())
|
||||
.then(argument("sellprice", IntegerArgumentType.integer(1))
|
||||
.executes(AuctionCommands::createHand)
|
||||
)
|
||||
.executes(AuctionCommands::create)
|
||||
@ -67,17 +70,24 @@ public class CommandRegistry {
|
||||
);
|
||||
dispatcher.register(
|
||||
literal("balance")
|
||||
.then(argument("recipient", EntityArgumentType.player()
|
||||
.then(argument("target", EntityArgumentType.player()
|
||||
)
|
||||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
|
||||
.executes(BalanceCommand::others)
|
||||
.executes(BalanceCommand::getOthers)
|
||||
|
||||
)
|
||||
.then(literal("load").executes(BalanceCommand::load))
|
||||
.then(literal("save").executes(BalanceCommand::save))
|
||||
.then(literal("load")
|
||||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
|
||||
.executes(BalanceCommand::load))
|
||||
.then(literal("save")
|
||||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
|
||||
.executes(BalanceCommand::save))
|
||||
.then(literal("list")
|
||||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
|
||||
.executes(BalanceCommand::list))
|
||||
.then(literal("set")
|
||||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
|
||||
.then(argument("balance", LongArgumentType.longArg(1))
|
||||
.then(argument("balance", LongArgumentType.longArg(0))
|
||||
.executes(BalanceCommand::selfSet)
|
||||
.then(argument("recipient", EntityArgumentType.player())
|
||||
.executes(BalanceCommand::othersSet))
|
||||
@ -88,14 +98,14 @@ public class CommandRegistry {
|
||||
|
||||
dispatcher.register(literal("buy")
|
||||
.then(argument("item", ItemStackArgumentType.itemStack(commandRegistryAccess))
|
||||
.then(argument("count", IntegerArgumentType.integer())
|
||||
.then(argument("count", IntegerArgumentType.integer(1, 64))
|
||||
.executes(StoreCommands::buyCount))
|
||||
.executes(StoreCommands::buyOne)
|
||||
)
|
||||
);
|
||||
dispatcher.register(literal("sell")
|
||||
.then(argument("item", ItemStackArgumentType.itemStack(commandRegistryAccess))
|
||||
.then(argument("count", IntegerArgumentType.integer())
|
||||
.then(argument("count", IntegerArgumentType.integer(1, 64))
|
||||
.executes(StoreCommands::sellCount))
|
||||
.executes(StoreCommands::sellOne)
|
||||
)
|
||||
|
@ -8,6 +8,7 @@ import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import systems.brn.servershop.ServerShop;
|
||||
import systems.brn.servershop.screens.ShopEditorScreen;
|
||||
import systems.brn.servershop.screens.ShopScreen;
|
||||
|
||||
public class ShopCommands {
|
||||
@ -18,6 +19,13 @@ public class ShopCommands {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int edit(CommandContext<ServerCommandSource> serverCommandSourceCommandContext) {
|
||||
ServerPlayerEntity player = serverCommandSourceCommandContext.getSource().getPlayer();
|
||||
ShopEditorScreen shopEditorScreen = new ShopEditorScreen(player);
|
||||
shopEditorScreen.open();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int load(CommandContext<ServerCommandSource> ctx) {
|
||||
boolean success = ServerShop.priceStorage.load();
|
||||
ctx.getSource().sendFeedback(() ->
|
||||
|
@ -28,6 +28,31 @@ public abstract class PagedGui extends SimpleGui {
|
||||
public static final String GUI_NEXT_PAGE_BLOCKED = "ewogICJ0aW1lc3RhbXAiIDogMTY0MDYxNjExMDQ4OCwKICAicHJvZmlsZUlkIiA6ICIxZjEyNTNhYTVkYTQ0ZjU5YWU1YWI1NmFhZjRlNTYxNyIsCiAgInByb2ZpbGVOYW1lIiA6ICJOb3RNaUt5IiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzdlNTc3MjBhNDg3OGM4YmNhYjBlOWM5YzQ3ZDllNTUxMjhjY2Q3N2JhMzQ0NWE1NGE5MWUzZTFlMWEyNzM1NmUiLAogICAgICAibWV0YWRhdGEiIDogewogICAgICAgICJtb2RlbCIgOiAic2xpbSIKICAgICAgfQogICAgfQogIH0KfQ==";
|
||||
public static final String GUI_QUESTION_MARK = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmM4ZWExZjUxZjI1M2ZmNTE0MmNhMTFhZTQ1MTkzYTRhZDhjM2FiNWU5YzZlZWM4YmE3YTRmY2I3YmFjNDAifX19";
|
||||
public static final String GUI_PLUS = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjBiNTVmNzQ2ODFjNjgyODNhMWMxY2U1MWYxYzgzYjUyZTI5NzFjOTFlZTM0ZWZjYjU5OGRmMzk5MGE3ZTcifX19";
|
||||
public static final String GUI_SETTINGS = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTRkNDliYWU5NWM3OTBjM2IxZmY1YjJmMDEwNTJhNzE0ZDYxODU0ODFkNWIxYzg1OTMwYjNmOTlkMjMyMTY3NCJ9fX0=";
|
||||
public static final String GUI_BUY_FILTER_NORMAL_SHOW = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzQ3ODk5ZDUxMWJhM2EzYmZlMTQ1NDFhNmE0Yjc3YjAzM2U0NGFjZDk1Njg5NmU3YjY1Njc0MjliZjE4ZDgzYyJ9fX0="; // Green B
|
||||
public static final String GUI_BUY_FILTER_NORMAL_HIDE = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDE1OTU3NzMwNDhkZTljNDExODk2ZmFlOWJhOWQ0OGQ1NWI3MTY3NzE5OTcwMTA2NDk4NGI0MmNkMmExN2Q4In19fQ=="; // Green H
|
||||
public static final String GUI_BUY_FILTER_NOT_BUYABLE_SHOW = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDJkZGViMTliNGMxMjIxNzg0ZTc5ZjViNjE1ZTk0ZmJiZTc0MmI1Yjk3MmIzY2M4ZTdmNjcyZDQyNDI0NjgyYyJ9fX0="; // Red U
|
||||
public static final String GUI_BUY_FILTER_NOT_BUYABLE_HIDE = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGQ5ZTMzZDc0M2VlMzQyMjQzMzEyMjkxY2NkY2ZmZDdmY2NhNWJkYzhhNmE4NDU5ZWU4ZTYyY2U1N2FkZDcifX19"; // Red H
|
||||
public static final String GUI_BUY_FILTER_DISABLED_SHOW = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmNlZjMzM2FhYmEyNDJjNmYyOGY0OWU5NjY4OWFiNGJmMmJjMTI2YmJjMjk4NTU1YjkzZGE3OTMyODQxOWQ4In19fQ=="; // Gray S
|
||||
public static final String GUI_BUY_FILTER_DISABLED_HIDE = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGY1Yjg3MWFlNDdlYmExNDZiNWI0Y2Y4OWZjMjBkYzMyMzY5NTJhN2VhODY3ODk4YmVjMWYzYjcxOTcxMmEifX19"; // Gray H
|
||||
public static final String GUI_SELL_FILTER_NORMAL_SHOW = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTcyOWQwM2Y3YjY0M2VjNmZiMjVlMzkyYTg4ZjA1OWU2NjM5YjZkYzU5M2UwYmE4NDU4NzlmY2VjZjMzOWJlIn19fQ=="; // Blue S
|
||||
public static final String GUI_SELL_FILTER_NORMAL_HIDE = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTBiNGFkZGJjOGFkYmE2ZWViYTQ5ZGU1NTM3MTlhZWEzNjRhMmVhNjdjYjJjYTUyNGEzMjBjMTAxMjU0In19fQ=="; // Blue H
|
||||
public static final String GUI_SELL_FILTER_NOT_SELLABLE_SHOW = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjBmNWQwMTU3ZTY3Mjg5YTdmMDFjZWNkMTRhZWM0YWFjNmFmZGQ4YzM1ZTliODc0Y2IyN2QwYjg1ZTc4Y2UifX19"; // Orange U
|
||||
public static final String GUI_SELL_FILTER_NOT_SELLABLE_HIDE = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGFjZGE4ODczODVhNzBkNTI2NzQ4MDg5ZTNhZWU0NjU4NjdjZWY5ZDM3ZGI0ZDZjNWQyMWRiOGU3NzVhMiJ9fX0="; // Orange H
|
||||
public static final String GUI_SELL_FILTER_DISABLED_SHOW = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDg2YzcxYWQ5NjUyOTQ2YjdlYmYyZDVhMjYyZjhiNzNlNDQ0NThhOGRjNzQzYTc4MmRjYTU3OGFkOTU0ZTE0In19fQ=="; // Purple D
|
||||
public static final String GUI_SELL_FILTER_DISABLED_HIDE = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjkyZGJjYjA0YTZkMzE1ODEzOGM5ZDYyZjIyODJhZTI4NTg0MTdjYmZlZmJmNjQ0NzY5NjVhN2Q3NjdkMzgifX19"; // Purple H
|
||||
public static final String GUI_SORT_ALPHABETICAL_ITEM_NAME_ASCENDING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGU0MTc0ODEyMTYyNmYyMmFlMTZhNGM2NjRjNzMwMWE5ZjhlYTU5MWJmNGQyOTg4ODk1NzY4MmE5ZmRhZiJ9fX0=";
|
||||
public static final String GUI_SORT_ALPHABETICAL_ITEM_NAME_DESCENDING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzBkNDRmZWUwMzAzZjZkMzdmYWNhN2U5YzMxNTMwOTU1NmZhM2RmMzc5YmRkNTgyMzE3YWEzNjhhYTg0M2UifX19";
|
||||
public static final String GUI_SORT_ALPHABETICAL_PLAYER_NAME_ASCENDING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTdkZDM0OTI0ZDJiNmEyMTNhNWVkNDZhZTU3ODNmOTUzNzNhOWVmNWNlNWM4OGY5ZDczNjcwNTk4M2I5NyJ9fX0=";
|
||||
public static final String GUI_SORT_ALPHABETICAL_PLAYER_NAME_DESCENDING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzk5MmM3NTNiZjljNjI1ODUzY2UyYTBiN2IxNzRiODlhNmVjMjZiYjVjM2NjYjQ3M2I2YTIwMTI0OTYzMTIifX19";
|
||||
public static final String GUI_SORT_PLAYER_BALANCE_ASCENDING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGJhN2Q0OTIzM2VhYzBjNGY2NjQ5NjdhZGIyN2ZkZTFkMmRjNjc5MzdjZjdkNGVjZjg1NGE5NmJhMThmNWIwYyJ9fX0=";
|
||||
public static final String GUI_SORT_PLAYER_BALANCE_DESCENDING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGU3NGQ2NDcyZjgxMWVlN2U1ZTgwNWVhOTNkN2I0Yzc2MWM2NmE2NGU1OTM3MDJmYzgwNzNkYjM1N2YwNDY0ZCJ9fX0=";
|
||||
public static final String GUI_SORT_ITEM_PRICE_BUY_ASCENDING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTk5YWY0ODZjZTcyYmJiMWQ0ZmU5NWJiY2ZjZGY1OTY2ODFkOWQ2MTA4YjU2MzJmYjg5OTNkZmU5ZGJmMzI5MyJ9fX0=";
|
||||
public static final String GUI_SORT_ITEM_PRICE_BUY_DESCENDING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjg1NmNjYWI2ZjcyYjZmMzczMzI4NDBhMjc3OWJiNDI3NThiYmIyYzAxNWY1NGNlNTM3NDBjYjBmMWNiNGNhMSJ9fX0=";
|
||||
public static final String GUI_SORT_ITEM_PRICE_SELL_ASCENDING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDllOTA2OGQxNWI0ZDhhNGI2NGZiYjA2NzQ0MTBkYjM0OWE2YzZhYWQ3OWZlOGE1YWI3MWU5NGRhMjQwZmZmNiJ9fX0=";
|
||||
public static final String GUI_SORT_ITEM_PRICE_SELL_DESCENDING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOWYyNjI4NzA4NjZlMzYxNzU3ZWQ4ZGNmYWJkMTAzZWJkNjRkNTczODQ1NWQwYzkyOWIyNjYyNzRlN2M0YzdkYyJ9fX0=";
|
||||
|
||||
public static final String GUI_ERROR = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmViNTg4YjIxYTZmOThhZDFmZjRlMDg1YzU1MmRjYjA1MGVmYzljYWI0MjdmNDYwNDhmMThmYzgwMzQ3NWY3In19fQ==";
|
||||
|
||||
public static final int PAGE_SIZE = 9 * 5;
|
||||
protected final Runnable closeCallback;
|
||||
@ -106,6 +131,8 @@ public abstract class PagedGui extends SimpleGui {
|
||||
case 0 -> DisplayElement.previousPage(this);
|
||||
case 1 -> this.search();
|
||||
case 2 -> this.create();
|
||||
case 3 -> this.settings();
|
||||
case 4 -> this.sort();
|
||||
case 7 -> DisplayElement.nextPage(this);
|
||||
case 8 -> DisplayElement.of(
|
||||
new GuiElementBuilder(Items.STRUCTURE_VOID)
|
||||
@ -124,10 +151,18 @@ public abstract class PagedGui extends SimpleGui {
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
protected DisplayElement settings(){
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
protected DisplayElement create(){
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
protected DisplayElement sort(){
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
public record DisplayElement(@Nullable GuiElementInterface element, @Nullable Slot slot) {
|
||||
private static final DisplayElement EMPTY = DisplayElement.of(new GuiElement(ItemStack.EMPTY, GuiElementInterface.EMPTY_CALLBACK));
|
||||
private static final DisplayElement FILLER = DisplayElement.of(
|
||||
|
@ -0,0 +1,5 @@
|
||||
package systems.brn.servershop.lib;
|
||||
|
||||
public interface SearchableInterface {
|
||||
void doSearch(String query);
|
||||
}
|
@ -5,7 +5,9 @@ import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.LoreComponent;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.*;
|
||||
@ -17,13 +19,25 @@ import systems.brn.servershop.ServerShop;
|
||||
import systems.brn.servershop.lib.records.AuctionRecord;
|
||||
import systems.brn.servershop.lib.records.ItemPriceRecord;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class Util {
|
||||
|
||||
public static final List<String> priceKeys = List.of(
|
||||
"gui.servershop.item.buy_price",
|
||||
"gui.servershop.shop.editor.item.buy_price",
|
||||
"gui.servershop.shop.editor.item.buy_price_disabled",
|
||||
"gui.servershop.shop.editor.item.buy_price_not_buyable",
|
||||
"gui.servershop.item.sell_price",
|
||||
"gui.servershop.shop.editor.item.sell_price",
|
||||
"gui.servershop.shop.editor.item.sell_price_disabled",
|
||||
"gui.servershop.shop.editor.item.sell_price_not_sellable",
|
||||
"gui.servershop.item.stack_info",
|
||||
"gui.servershop.item.seller_me",
|
||||
"gui.servershop.item.seller",
|
||||
"gui.servershop.balance.editor.value"
|
||||
);
|
||||
|
||||
public static Identifier id(String path) {
|
||||
return Identifier.of(ServerShop.MOD_ID, path);
|
||||
}
|
||||
@ -116,6 +130,24 @@ public class Util {
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static boolean hasPrices(ItemStack stack) {
|
||||
LoreComponent oldLore = stack.get(DataComponentTypes.LORE);
|
||||
if (oldLore != null) {
|
||||
for (Text text : oldLore.styledLines()) {
|
||||
if (text instanceof MutableText mutableText) {
|
||||
TextContent textContent = mutableText.getContent();
|
||||
if (textContent instanceof TranslatableTextContent translatableTextContent) {
|
||||
String key = translatableTextContent.getKey();
|
||||
if (priceKeys.contains(key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ItemStack removePrices(ItemStack stack) {
|
||||
LoreComponent oldLore = stack.get(DataComponentTypes.LORE);
|
||||
|
||||
@ -127,12 +159,7 @@ public class Util {
|
||||
TextContent textContent = mutableText.getContent();
|
||||
if (textContent instanceof TranslatableTextContent translatableTextContent) {
|
||||
String key = translatableTextContent.getKey();
|
||||
if (!key.equals("gui.servershop.item.buy_price") &&
|
||||
!key.equals("gui.servershop.item.sell_price") &&
|
||||
!key.equals("gui.servershop.item.stack_info") &&
|
||||
!key.equals("gui.servershop.item.seller_me") &&
|
||||
!key.equals("gui.servershop.item.seller")
|
||||
) {
|
||||
if (!priceKeys.contains(key)) {
|
||||
filteredLines.add(text);
|
||||
}
|
||||
}
|
||||
@ -160,13 +187,25 @@ public class Util {
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
public static ItemStack addPricesEditor(ItemPriceRecord price) {
|
||||
ItemStack stack = price.stack();
|
||||
int buyPrice = price.buyPrice();
|
||||
int sellPrice = price.sellPrice();
|
||||
int count = stack.getCount();
|
||||
if (count > 0) {
|
||||
return addLore(buyPrice, sellPrice, stack, true, null, false);
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack addPrices(ItemPriceRecord price) {
|
||||
ItemStack stack = price.stack();
|
||||
int buyPrice = price.buyPrice();
|
||||
int sellPrice = price.sellPrice();
|
||||
int count = stack.getCount();
|
||||
if (count > 0) {
|
||||
return addLore(buyPrice, sellPrice, stack, null, false);
|
||||
return addLore(buyPrice, sellPrice, stack, false, null, false);
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
@ -178,16 +217,16 @@ public class Util {
|
||||
int sellPrice = 0;
|
||||
int count = stack.getCount();
|
||||
if (count > 0) {
|
||||
return addLore(buyPrice, sellPrice, stack, 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()));
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ItemStack addLore(int buyPrice, int sellPrice, ItemStack stack, String sellerName, boolean me) {
|
||||
Text buyLine = Text.translatable("gui.servershop.item.buy_price", buyPrice).setStyle(Style.EMPTY.withColor(Formatting.DARK_GREEN).withItalic(true));
|
||||
Text sellLine = Text.translatable("gui.servershop.item.sell_price", sellPrice).setStyle(Style.EMPTY.withColor(Formatting.AQUA).withItalic(true));
|
||||
private static ItemStack addLore(int buyPrice, int 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.item.stack_info").setStyle(Style.EMPTY.withColor(Formatting.YELLOW).withItalic(true));
|
||||
Text sellerLine;
|
||||
if (me) {
|
||||
@ -205,16 +244,16 @@ public class Util {
|
||||
loreList = new ArrayList<>(lore.lines());
|
||||
}
|
||||
if (sellerName == null || sellerName.isEmpty()) {
|
||||
if (buyPrice > 0 || sellPrice > 0) {
|
||||
if (!isEditor && (buyPrice > 0 || sellPrice > 0)) {
|
||||
loreList.addFirst(infoLine);
|
||||
}
|
||||
} else {
|
||||
loreList.addFirst(sellerLine);
|
||||
}
|
||||
if (sellPrice > 0) {
|
||||
if (sellPrice > 0 || isEditor) {
|
||||
loreList.addFirst(sellLine);
|
||||
}
|
||||
if (buyPrice > 0) {
|
||||
if (buyPrice > 0 || isEditor) {
|
||||
loreList.addFirst(buyLine);
|
||||
}
|
||||
newLore = new LoreComponent(loreList);
|
||||
@ -222,4 +261,186 @@ public class Util {
|
||||
newStack.set(DataComponentTypes.LORE, newLore);
|
||||
return newStack;
|
||||
}
|
||||
|
||||
private static @NotNull TreeMap<ItemStack, ItemPriceRecord> getPricesTreeMap(Map<ItemStack, ItemPriceRecord> priceRecordMap, int sortMode) {
|
||||
TreeMap<ItemStack, ItemPriceRecord> sortedMap;
|
||||
|
||||
if (sortMode == 4 || sortMode == 5) {
|
||||
// Sort alphabetically by item name
|
||||
sortedMap = new TreeMap<>((o1, o2) -> {
|
||||
String name1 = String.valueOf(o1.getItem());
|
||||
String name2 = String.valueOf(o2.getItem());
|
||||
if (sortMode == 4) {
|
||||
return name1.compareToIgnoreCase(name2);
|
||||
} else {
|
||||
return name2.compareToIgnoreCase(name1);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Sort by count in descending order
|
||||
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();
|
||||
int countCompare;
|
||||
if (sortMode == 0) {
|
||||
countCompare = Integer.compare(buyPrice1, buyPrice2);
|
||||
} else if (sortMode == 1) {
|
||||
countCompare = Integer.compare(buyPrice2, buyPrice1);
|
||||
} else if (sortMode == 2) {
|
||||
countCompare = Integer.compare(sellPrice1, sellPrice2);
|
||||
} else { //sortmode 3
|
||||
countCompare = Integer.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;
|
||||
});
|
||||
}
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
private static @NotNull TreeMap<UUID, Long> getBalancesTreeMap(Map<UUID, Long> balanceRecordMap, MinecraftServer server, int sortMode) {
|
||||
TreeMap<UUID, Long> sortedMap;
|
||||
|
||||
if (sortMode == 2 || sortMode == 3) {
|
||||
// Sort alphabetically by player name
|
||||
sortedMap = new TreeMap<>((o1, o2) -> {
|
||||
String name1 = getGameProfile(o1, server).getName();
|
||||
String name2 = getGameProfile(o2, server).getName();
|
||||
if (sortMode == 2) {
|
||||
return name1.compareToIgnoreCase(name2);
|
||||
} else {
|
||||
return name2.compareToIgnoreCase(name1);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Sort by count in descending order
|
||||
sortedMap = new TreeMap<>((o1, o2) -> {
|
||||
Long balance1 = balanceRecordMap.get(o1);
|
||||
Long balance2 = balanceRecordMap.get(o2);
|
||||
int countCompare;
|
||||
if (sortMode == 0) {
|
||||
countCompare = Long.compare(balance1, balance2);
|
||||
} else {
|
||||
countCompare = Long.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;
|
||||
});
|
||||
}
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
private static @NotNull TreeSet<AuctionRecord> getAuctionsTreeSet(MinecraftServer server, int sortMode) {
|
||||
TreeSet<AuctionRecord> sortedSet;
|
||||
|
||||
if (sortMode == 2 || sortMode == 3 || sortMode == 4 || sortMode == 5) {
|
||||
// Sort alphabetically by item name
|
||||
sortedSet = new TreeSet<>((record1, record2) -> {
|
||||
String name1;
|
||||
String name2;
|
||||
if (sortMode == 2 || sortMode == 3) {
|
||||
name1 = String.valueOf(record1.stack().getItem());
|
||||
name2 = String.valueOf(record2.stack().getItem());
|
||||
} else {
|
||||
name1 = record1.getProfile(server).getName();
|
||||
name2 = record2.getProfile(server).getName();
|
||||
}
|
||||
if (sortMode == 2 || sortMode == 4) {
|
||||
return name1.compareToIgnoreCase(name2);
|
||||
} else {
|
||||
return name2.compareToIgnoreCase(name1);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Sort by count in descending order
|
||||
sortedSet = new TreeSet<>((record1, record2) -> {
|
||||
int buyPrice1 = record1.buyPrice();
|
||||
int buyPrice2 = record2.buyPrice();
|
||||
int countCompare;
|
||||
if (sortMode == 0) {
|
||||
countCompare = Integer.compare(buyPrice1, buyPrice2);
|
||||
} else {
|
||||
countCompare = Integer.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;
|
||||
});
|
||||
}
|
||||
return sortedSet;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<AuctionRecord> sortAndFilterAuctions(List<AuctionRecord> auctionRecords, MinecraftServer server, int sortMode, String query) {
|
||||
TreeSet<AuctionRecord> sortedList = getAuctionsTreeSet(server, sortMode);
|
||||
|
||||
ArrayList<AuctionRecord> filteredList = new ArrayList<>();
|
||||
for (AuctionRecord entry : auctionRecords) {
|
||||
if (entry.buyPrice() > 0) {
|
||||
if (query == null || query.isEmpty() || query.equals("*") || query.equals("Filter not set") || filterItem(entry.stack().getItem(), query) || entry.getProfile(server).getName().toLowerCase().contains(query.toLowerCase())) {
|
||||
filteredList.add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
sortedList.addAll(filteredList);
|
||||
return new ArrayList<>((sortedList));
|
||||
}
|
||||
|
||||
public static TreeMap<ItemStack, ItemPriceRecord> sortAndFilterPrices(Map<ItemStack, ItemPriceRecord> itemStackMap, int sortMode, String query) {
|
||||
return sortAndFilterPrices(itemStackMap, sortMode, query, false, false, true, false, false, true);
|
||||
}
|
||||
|
||||
|
||||
public static TreeMap<ItemStack, ItemPriceRecord> sortAndFilterPrices(Map<ItemStack, ItemPriceRecord> itemStackMap, int sortMode, String query, boolean showDisabledBuy, boolean showNotBuyable, boolean showNormalBuy, boolean showDisabledSell, boolean showNotSellable, boolean showNormalSell) {
|
||||
TreeMap<ItemStack, ItemPriceRecord> sortedMap = getPricesTreeMap(itemStackMap, sortMode);
|
||||
|
||||
|
||||
Map<ItemStack, ItemPriceRecord> filteredMap = new HashMap<>();
|
||||
for (Map.Entry<ItemStack, ItemPriceRecord> entry : itemStackMap.entrySet()) {
|
||||
ItemPriceRecord price = entry.getValue();
|
||||
if (
|
||||
(price.buyPrice() == -1 && showDisabledBuy) ||
|
||||
(price.buyPrice() == 0 && showNotBuyable) ||
|
||||
(price.buyPrice() > 0 && showNormalBuy) ||
|
||||
(price.sellPrice() == -1 && showDisabledSell) ||
|
||||
(price.sellPrice() == 0 && showNotSellable) ||
|
||||
(price.sellPrice() > 0 && showNormalSell)
|
||||
) {
|
||||
if (query == null || query.isEmpty() || query.equals("*") || query.equals("Filter not set") || filterItem(entry.getKey().getItem(), query)) {
|
||||
ItemStack stack = entry.getKey();
|
||||
filteredMap.put(stack, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
sortedMap.putAll(filteredMap);
|
||||
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);
|
||||
|
||||
|
||||
Map<UUID, Long> filteredMap = new HashMap<>();
|
||||
for (Map.Entry<UUID, Long> 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())) {
|
||||
UUID stack = entry.getKey();
|
||||
filteredMap.put(stack, entry.getValue());
|
||||
}
|
||||
}
|
||||
sortedMap.putAll(filteredMap);
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
private static boolean filterItem(Item item, String query) {
|
||||
if (item != null) {
|
||||
String itemName = String.valueOf(item);
|
||||
return itemName == null || itemName.toLowerCase().contains(query.toLowerCase());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class BalanceStorage {
|
||||
private final ConcurrentHashMap<UUID, Long> balances = new ConcurrentHashMap<>();
|
||||
public final ConcurrentHashMap<UUID, Long> balances = new ConcurrentHashMap<>();
|
||||
public final MinecraftServer server;
|
||||
private final File balanceStorageFile;
|
||||
private final File balanceStorageCSVFile;
|
||||
|
@ -11,17 +11,21 @@ import net.minecraft.text.Text;
|
||||
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.AuctionRecord;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static systems.brn.servershop.lib.Util.addPrices;
|
||||
import static systems.brn.servershop.lib.Util.*;
|
||||
|
||||
public class AuctionBrowserScreen extends PagedGui {
|
||||
public class AuctionBrowserScreen extends PagedGui implements SearchableInterface {
|
||||
|
||||
public String searchQuery = "";
|
||||
public int sortMode = 0;
|
||||
public int maxSortMode = 5;
|
||||
|
||||
final public ArrayList<AuctionRecord> filteredAuctions = new ArrayList<>();
|
||||
public ArrayList<AuctionRecord> filteredAuctions;
|
||||
|
||||
public AuctionBrowserScreen(ServerPlayerEntity player) {
|
||||
super(player, null);
|
||||
@ -36,23 +40,10 @@ public class AuctionBrowserScreen extends PagedGui {
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
filterAuctions();
|
||||
filteredAuctions = sortAndFilterAuctions(ServerShop.auctionStorage.auctions, player.getServer(), sortMode, searchQuery);
|
||||
super.updateDisplay();
|
||||
}
|
||||
|
||||
public void filterAuctions() {
|
||||
filteredAuctions.clear();
|
||||
for (AuctionRecord auctionRecord : ServerShop.auctionStorage.auctions) {
|
||||
String itemName = auctionRecord.stack().getItem().toString();
|
||||
String sellerName = auctionRecord.getProfile(player.getServer()).getName();
|
||||
if (itemName.contains(searchQuery) || sellerName.contains(searchQuery)) {
|
||||
if (auctionRecord.buyPrice() > 0) {
|
||||
filteredAuctions.add(auctionRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void doSearch(String query) {
|
||||
searchQuery = query;
|
||||
updateDisplay();
|
||||
@ -67,7 +58,7 @@ public class AuctionBrowserScreen extends PagedGui {
|
||||
@Override
|
||||
public boolean onClick(int index, ClickType type, SlotActionType action, GuiElementInterface element) {
|
||||
if (index < filteredAuctions.size()) {
|
||||
if (type.isLeft) {
|
||||
if (type.isLeft && hasPrices(element.getItemStack())) {
|
||||
AuctionRecord auctionRecord = filteredAuctions.get(index);
|
||||
ServerShop.auctionStorage.buyAuction(player, auctionRecord);
|
||||
updateDisplay();
|
||||
@ -90,7 +81,7 @@ public class AuctionBrowserScreen extends PagedGui {
|
||||
|
||||
@Override
|
||||
protected DisplayElement search() {
|
||||
if (searchQuery == null || searchQuery.isEmpty() || searchQuery.equals("*")) {
|
||||
if (searchQuery == null || searchQuery.isEmpty() || searchQuery.equals("Filter not set") || searchQuery.equals("*")) {
|
||||
searchQuery = "Filter not set";
|
||||
}
|
||||
return DisplayElement.of(
|
||||
@ -126,4 +117,35 @@ public class AuctionBrowserScreen extends PagedGui {
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement sort() {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable(switch (sortMode) {
|
||||
case 0 -> "gui.servershop.sort.price.buy.ascending";
|
||||
case 1 -> "gui.servershop.sort.price.buy.descending";
|
||||
case 2 -> "gui.servershop.sort.name.item.ascending";
|
||||
case 3 -> "gui.servershop.sort.name.item.descending";
|
||||
case 4 -> "gui.servershop.sort.name.player.ascending";
|
||||
case 5 -> "gui.servershop.sort.name.player.descending";
|
||||
default -> "gui.servershop.sort.unknown";
|
||||
}))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(switch (sortMode) {
|
||||
case 0 -> GUI_SORT_ITEM_PRICE_BUY_ASCENDING;
|
||||
case 1 -> GUI_SORT_ITEM_PRICE_BUY_DESCENDING;
|
||||
case 2 -> GUI_SORT_ALPHABETICAL_ITEM_NAME_ASCENDING;
|
||||
case 3 -> GUI_SORT_ALPHABETICAL_ITEM_NAME_DESCENDING;
|
||||
case 4 -> GUI_SORT_ALPHABETICAL_PLAYER_NAME_ASCENDING;
|
||||
case 5 -> GUI_SORT_ALPHABETICAL_PLAYER_NAME_DESCENDING;
|
||||
default -> GUI_ERROR;
|
||||
})
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
sortMode = (sortMode + 1) % (maxSortMode + 1);
|
||||
updateDisplay();
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
143
src/main/java/systems/brn/servershop/screens/BalanceScreen.java
Normal file
143
src/main/java/systems/brn/servershop/screens/BalanceScreen.java
Normal file
@ -0,0 +1,143 @@
|
||||
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;
|
||||
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 {
|
||||
|
||||
public String searchQuery = "";
|
||||
public int sortMode = 0;
|
||||
public final int maxSortMode = 3;
|
||||
|
||||
public TreeMap<UUID, Long> filteredBalances;
|
||||
|
||||
public BalanceScreen(ServerPlayerEntity player) {
|
||||
super(player, null);
|
||||
setTitle(Text.translatable("gui.servershop.balances.title"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean open() {
|
||||
updateDisplay();
|
||||
return super.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
filteredBalances = sortaAndFilterBalances(ServerShop.balanceStorage.balances, player.getServer(), sortMode, searchQuery);
|
||||
super.updateDisplay();
|
||||
}
|
||||
|
||||
|
||||
public void doSearch(String query) {
|
||||
searchQuery = query;
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPageAmount() {
|
||||
return Math.ceilDivExact(filteredBalances.size(), PAGE_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertItem(ItemStack stack, int startIndex, int endIndex, boolean fromLast) {
|
||||
sell(stack, player, true);
|
||||
return super.insertItem(stack, startIndex, endIndex, fromLast);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement getElement(int id) {
|
||||
MinecraftServer server = player.getServer();
|
||||
if (server != null) {
|
||||
List<Map.Entry<UUID, Long>> list = new ArrayList<>(filteredBalances.entrySet());
|
||||
if (id < list.size()) {
|
||||
Map.Entry<UUID, Long> balanceEntry = list.get(id);
|
||||
UUID targetUUID = balanceEntry.getKey();
|
||||
Long targetBalance = balanceEntry.getValue();
|
||||
GameProfile targetProfile = getGameProfile(targetUUID, server);
|
||||
GuiElementBuilder elementBuilder = new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setSkullOwner(targetProfile, server)
|
||||
.setName(Text.literal(targetProfile.getName()))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.addLoreLine(Text.translatable("gui.servershop.balance.editor.value", targetBalance))
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (clickType.isLeft) {
|
||||
BalanceSetScreen balanceSetScreen = new BalanceSetScreen(this, targetUUID);
|
||||
balanceSetScreen.open();
|
||||
}
|
||||
});
|
||||
return DisplayElement.of(elementBuilder);
|
||||
}
|
||||
}
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement search() {
|
||||
if (searchQuery == null || searchQuery.isEmpty() || searchQuery.equals("*")) {
|
||||
searchQuery = "Filter not set";
|
||||
}
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.literal(searchQuery).formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(GUI_QUESTION_MARK)
|
||||
.setCallback((x, y, z) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (y.isRight) {
|
||||
doSearch("");
|
||||
} else if (y.isLeft) {
|
||||
SearchScreen searchScreen = new SearchScreen(this, "");
|
||||
searchScreen.open();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement sort() {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable(switch (sortMode) {
|
||||
case 0 -> "gui.servershop.sort.balance.player.ascending";
|
||||
case 1 -> "gui.servershop.sort.balance.player.descending";
|
||||
case 2 -> "gui.servershop.sort.name.player.ascending";
|
||||
case 3 -> "gui.servershop.sort.name.player.descending";
|
||||
default -> "gui.servershop.sort.unknown";
|
||||
}))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(switch (sortMode) {
|
||||
case 0 -> GUI_SORT_PLAYER_BALANCE_ASCENDING;
|
||||
case 1 -> GUI_SORT_PLAYER_BALANCE_DESCENDING;
|
||||
case 2 -> GUI_SORT_ALPHABETICAL_PLAYER_NAME_ASCENDING;
|
||||
case 3 -> GUI_SORT_ALPHABETICAL_PLAYER_NAME_DESCENDING;
|
||||
default -> GUI_ERROR;
|
||||
})
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
sortMode = (sortMode + 1) % (maxSortMode + 1);
|
||||
updateDisplay();
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package systems.brn.servershop.screens;
|
||||
|
||||
import eu.pb4.sgui.api.gui.AnvilInputGui;
|
||||
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 final UUID targetUUID;
|
||||
|
||||
public BalanceSetScreen(SimpleGui parentScreen, UUID targetUUID) {
|
||||
super(parentScreen.getPlayer(), false);
|
||||
this.parentScreen = parentScreen;
|
||||
this.targetUUID = targetUUID;
|
||||
balance = balanceStorage.getBalance(targetUUID);
|
||||
|
||||
MinecraftServer server = getPlayer().getServer();
|
||||
setTitle(Text.translatable("gui.servershop.balance.editor.title", server == null ? targetUUID : getGameProfile(targetUUID, server).getName()));
|
||||
this.setDefaultInputValue(String.valueOf(balance));
|
||||
parentScreen.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
if (parentScreen != null) {
|
||||
parentScreen.open();
|
||||
balance = Long.parseLong(this.getInput());
|
||||
balanceStorage.setBalance(targetUUID, balance);
|
||||
if (parentScreen instanceof PagedGui pagedGui) {
|
||||
pagedGui.updateDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package systems.brn.servershop.screens;
|
||||
import eu.pb4.sgui.api.gui.AnvilInputGui;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import net.minecraft.text.Text;
|
||||
import systems.brn.servershop.lib.SearchableInterface;
|
||||
|
||||
public class SearchScreen extends AnvilInputGui {
|
||||
|
||||
@ -21,8 +22,8 @@ public class SearchScreen extends AnvilInputGui {
|
||||
super.onClose();
|
||||
parentScreen.open();
|
||||
String query = this.getInput();
|
||||
if (parentScreen instanceof ShopScreen shopScreen) {
|
||||
shopScreen.doSearch(query);
|
||||
if (parentScreen instanceof SearchableInterface searchableInterface) {
|
||||
searchableInterface.doSearch(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
108
src/main/java/systems/brn/servershop/screens/SettingsScreen.java
Normal file
108
src/main/java/systems/brn/servershop/screens/SettingsScreen.java
Normal file
@ -0,0 +1,108 @@
|
||||
package systems.brn.servershop.screens;
|
||||
|
||||
import eu.pb4.sgui.api.ClickType;
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.elements.GuiElementInterface;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.slot.SlotActionType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.servershop.lib.PagedGui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SettingsScreen extends PagedGui {
|
||||
|
||||
private final SimpleGui parentScreen;
|
||||
|
||||
private final ArrayList<DisplayElement> settingsList;
|
||||
|
||||
public SettingsScreen(@Nullable SimpleGui parentScreen, ServerPlayerEntity player) {
|
||||
super(player, null);
|
||||
this.parentScreen = parentScreen;
|
||||
settingsList = new ArrayList<>();
|
||||
this.setTitle(Text.translatable("mco.configure.world.buttons.settings"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen() {
|
||||
this.updateDisplay();
|
||||
super.onOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
if (parentScreen != null) {
|
||||
if (parentScreen instanceof ShopEditorScreen shopEditorScreen) {
|
||||
shopEditorScreen.updateSettings();
|
||||
}
|
||||
}
|
||||
super.updateDisplay();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onClick(int index, ClickType type, SlotActionType action, GuiElementInterface element) {
|
||||
if (index < settingsList.size()) {
|
||||
updateDisplay();
|
||||
}
|
||||
return super.onClick(index, type, action, element);
|
||||
}
|
||||
|
||||
public SettingsScreen(SimpleGui parentScreen) {
|
||||
this(parentScreen, parentScreen.getPlayer());
|
||||
}
|
||||
|
||||
public void addSetting(DisplayElement setting) {
|
||||
this.settingsList.add(setting);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
if (parentScreen != null) {
|
||||
if (parentScreen instanceof PagedGui pagedGui) {
|
||||
pagedGui.updateDisplay();
|
||||
}
|
||||
parentScreen.open();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPageAmount() {
|
||||
return Math.ceilDivExact(settingsList.size(), PAGE_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement getElement(int id) {
|
||||
if (id >= 0 && id < settingsList.size()) {
|
||||
return settingsList.get(id);
|
||||
} else {
|
||||
return DisplayElement.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public DisplayElement getItem() {
|
||||
if (settingsList.isEmpty()) {
|
||||
return DisplayElement.filler();
|
||||
} else {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("mco.configure.world.settings.title").formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(GUI_SETTINGS)
|
||||
.setCallback((x, y, z) -> {
|
||||
playClickSound(getPlayer());
|
||||
this.open();
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearSettings() {
|
||||
settingsList.clear();
|
||||
}
|
||||
}
|
@ -0,0 +1,245 @@
|
||||
package systems.brn.servershop.screens;
|
||||
|
||||
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.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
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.ServerShop.priceStorage;
|
||||
import static systems.brn.servershop.lib.Util.*;
|
||||
|
||||
public class ShopEditorScreen extends PagedGui implements SearchableInterface {
|
||||
|
||||
public String searchQuery = "";
|
||||
|
||||
public boolean showNormalBuy = true;
|
||||
public boolean showNotBuyable = false;
|
||||
public boolean showDisabledBuy = false;
|
||||
|
||||
public boolean showNormalSell = false;
|
||||
public boolean showNotSellable = false;
|
||||
public boolean showDisabledSell = false;
|
||||
|
||||
public int sortMode = 0;
|
||||
public final int maxSortMode = 5;
|
||||
|
||||
public final SettingsScreen settingsScreen;
|
||||
|
||||
|
||||
public TreeMap<ItemStack, ItemPriceRecord> filteredPrices;
|
||||
|
||||
public ShopEditorScreen(ServerPlayerEntity player) {
|
||||
super(player, null);
|
||||
settingsScreen = new SettingsScreen(this);
|
||||
setTitle(Text.translatable("gui.servershop.shop.editor.title"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean open() {
|
||||
updateDisplay();
|
||||
return super.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
filteredPrices = sortAndFilterPrices(ServerShop.priceStorage.prices, sortMode, searchQuery, showDisabledBuy, showNotBuyable, showNormalBuy, showDisabledSell, showNotSellable, showNormalSell);
|
||||
super.updateDisplay();
|
||||
}
|
||||
|
||||
public void doSearch(String query) {
|
||||
searchQuery = query;
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPageAmount() {
|
||||
return Math.ceilDivExact(filteredPrices.size(), PAGE_SIZE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onClick(int index, ClickType type, SlotActionType action, GuiElementInterface element) {
|
||||
ItemStack cursorStack = getPlayer().currentScreenHandler.getCursorStack();
|
||||
if (!cursorStack.isEmpty()) {
|
||||
ShopPriceSetScreen shopPriceSetScreenBuy = new ShopPriceSetScreen(this, cursorStack.copy(), 2);
|
||||
shopPriceSetScreenBuy.open();
|
||||
} else if (hasPrices(element.getItemStack())) {
|
||||
ItemStack itemStack = removePrices(element.getItemStack());
|
||||
ShopPriceSetScreen shopPriceSetScreen = new ShopPriceSetScreen(this, itemStack.copy(), type.isLeft ? 0 : 1);
|
||||
shopPriceSetScreen.open();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertItem(ItemStack stack, int startIndex, int endIndex, boolean fromLast) {
|
||||
ShopPriceSetScreen shopPriceSetScreenBuy = new ShopPriceSetScreen(this, stack.copy(), 2);
|
||||
shopPriceSetScreenBuy.open();
|
||||
return super.insertItem(stack, startIndex, endIndex, fromLast);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement getElement(int id) {
|
||||
List<Map.Entry<ItemStack, ItemPriceRecord>> list = new ArrayList<>(filteredPrices.entrySet());
|
||||
if (id < list.size()) {
|
||||
Map.Entry<ItemStack, ItemPriceRecord> itemPriceEntry = list.get(id);
|
||||
ItemStack stack = addPricesEditor(itemPriceEntry.getValue());
|
||||
GuiElementBuilder elementBuilder = new GuiElementBuilder(stack);
|
||||
return DisplayElement.of(elementBuilder);
|
||||
|
||||
}
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
public void updateSettings() {
|
||||
settingsScreen.clearSettings();
|
||||
settingsScreen.addSetting(DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("gui.servershop.shop.editor.filtering.buy.normal" + (showNormalBuy ? ".show" : ".hide")).formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(showNormalBuy ? GUI_BUY_FILTER_NORMAL_SHOW : GUI_BUY_FILTER_NORMAL_HIDE)
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (clickType.isLeft) {
|
||||
showNormalBuy = !showNormalBuy;
|
||||
}
|
||||
})
|
||||
));
|
||||
|
||||
settingsScreen.addSetting(DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("gui.servershop.shop.editor.filtering.buy.not_buyable" + (showNotBuyable ? ".show" : ".hide")).formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(showNotBuyable ? GUI_BUY_FILTER_NOT_BUYABLE_SHOW : GUI_BUY_FILTER_NOT_BUYABLE_HIDE)
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (clickType.isLeft) {
|
||||
showNotBuyable = !showNotBuyable;
|
||||
}
|
||||
})
|
||||
));
|
||||
|
||||
settingsScreen.addSetting(DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("gui.servershop.shop.editor.filtering.buy.disabled" + (showDisabledBuy ? ".show" : ".hide")).formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(showDisabledBuy ? GUI_BUY_FILTER_DISABLED_SHOW : GUI_BUY_FILTER_DISABLED_HIDE)
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (clickType.isLeft) {
|
||||
showDisabledBuy = !showDisabledBuy;
|
||||
}
|
||||
})
|
||||
));
|
||||
|
||||
settingsScreen.addSetting(DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("gui.servershop.shop.editor.filtering.sell.normal" + (showNormalSell ? ".show" : ".hide")).formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(showNormalSell ? GUI_SELL_FILTER_NORMAL_SHOW : GUI_SELL_FILTER_NORMAL_HIDE)
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (clickType.isLeft) {
|
||||
showNormalSell = !showNormalSell;
|
||||
}
|
||||
})
|
||||
));
|
||||
|
||||
settingsScreen.addSetting(DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("gui.servershop.shop.editor.filtering.sell.not_selling" + (showNotSellable ? ".show" : ".hide")).formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(showNotSellable ? GUI_SELL_FILTER_NOT_SELLABLE_SHOW : GUI_SELL_FILTER_NOT_SELLABLE_HIDE)
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (clickType.isLeft) {
|
||||
showNotSellable = !showNotSellable;
|
||||
}
|
||||
})
|
||||
));
|
||||
|
||||
settingsScreen.addSetting(DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("gui.servershop.shop.editor.filtering.sell.disabled" + (showDisabledSell ? ".show" : ".hide")).formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(showDisabledSell ? GUI_SELL_FILTER_DISABLED_SHOW : GUI_SELL_FILTER_DISABLED_HIDE)
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (clickType.isLeft) {
|
||||
showDisabledSell = !showDisabledSell;
|
||||
}
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement settings() {
|
||||
updateSettings();
|
||||
settingsScreen.updateDisplay();
|
||||
return settingsScreen.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement search() {
|
||||
if (searchQuery == null || searchQuery.isEmpty() || searchQuery.equals("*")) {
|
||||
searchQuery = "Filter not set";
|
||||
}
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.literal(searchQuery).formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(GUI_QUESTION_MARK)
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (clickType.isRight) {
|
||||
doSearch("");
|
||||
} else if (clickType.isLeft) {
|
||||
SearchScreen searchScreen = new SearchScreen(this, "");
|
||||
searchScreen.open();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement sort() {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable(switch (sortMode) {
|
||||
case 0 -> "gui.servershop.sort.price.buy.ascending";
|
||||
case 1 -> "gui.servershop.sort.price.buy.descending";
|
||||
case 2 -> "gui.servershop.sort.price.sell.ascending";
|
||||
case 3 -> "gui.servershop.sort.price.sell.descending";
|
||||
case 4 -> "gui.servershop.sort.name.item.ascending";
|
||||
case 5 -> "gui.servershop.sort.name.item.descending";
|
||||
default -> "gui.servershop.sort.unknown";
|
||||
}))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(switch (sortMode) {
|
||||
case 0 -> GUI_SORT_ITEM_PRICE_BUY_ASCENDING;
|
||||
case 1 -> GUI_SORT_ITEM_PRICE_BUY_DESCENDING;
|
||||
case 2 -> GUI_SORT_ITEM_PRICE_SELL_ASCENDING;
|
||||
case 3 -> GUI_SORT_ITEM_PRICE_SELL_DESCENDING;
|
||||
case 4 -> GUI_SORT_ALPHABETICAL_ITEM_NAME_ASCENDING;
|
||||
case 5 -> GUI_SORT_ALPHABETICAL_ITEM_NAME_DESCENDING;
|
||||
default -> GUI_ERROR;
|
||||
})
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
sortMode = (sortMode + 1) % (maxSortMode + 1);
|
||||
updateDisplay();
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package systems.brn.servershop.screens;
|
||||
|
||||
import eu.pb4.sgui.api.gui.AnvilInputGui;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import systems.brn.servershop.lib.PagedGui;
|
||||
import systems.brn.servershop.lib.records.ItemPriceRecord;
|
||||
|
||||
import static systems.brn.servershop.ServerShop.priceStorage;
|
||||
|
||||
public class ShopPriceSetScreen extends AnvilInputGui {
|
||||
|
||||
private final SimpleGui parentScreen;
|
||||
private int buyPrice;
|
||||
private int sellPrice;
|
||||
private final int priceMode;
|
||||
private final ItemStack itemStack;
|
||||
private boolean isBuyPrice;
|
||||
|
||||
public ShopPriceSetScreen(SimpleGui parentScreen, ItemStack itemStack, int priceMode) {
|
||||
super(parentScreen.getPlayer(), false);
|
||||
this.parentScreen = parentScreen;
|
||||
this.priceMode = priceMode;
|
||||
this.itemStack = itemStack;
|
||||
|
||||
isBuyPrice = priceMode == 0 || priceMode == 2;
|
||||
|
||||
ItemPriceRecord price = priceStorage.getPrices(itemStack);
|
||||
buyPrice = price.buyPrice();
|
||||
sellPrice = price.sellPrice();
|
||||
updateDisplay();
|
||||
parentScreen.close();
|
||||
}
|
||||
|
||||
private void updateDisplay() {
|
||||
setTitle(Text.translatable("gui.servershop.shop.editor.item." + (isBuyPrice ? "buy" : "sell") + "_price.title"));
|
||||
this.setDefaultInputValue(String.valueOf(isBuyPrice ? buyPrice : sellPrice));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
if (parentScreen != null) {
|
||||
int input = Integer.parseInt(this.getInput());
|
||||
if (isBuyPrice) {
|
||||
buyPrice = input;
|
||||
} else {
|
||||
sellPrice = input;
|
||||
}
|
||||
if (priceMode != 2 || !isBuyPrice) {
|
||||
priceStorage.setPrices(itemStack, buyPrice, sellPrice);
|
||||
if (parentScreen instanceof PagedGui pagedGui) {
|
||||
pagedGui.updateDisplay();
|
||||
}
|
||||
parentScreen.open();
|
||||
} else {
|
||||
isBuyPrice = false;
|
||||
updateDisplay();
|
||||
this.open();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import net.minecraft.screen.slot.SlotActionType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import systems.brn.servershop.lib.SearchableInterface;
|
||||
import systems.brn.servershop.lib.records.ItemPriceRecord;
|
||||
import systems.brn.servershop.ServerShop;
|
||||
import systems.brn.servershop.lib.PagedGui;
|
||||
@ -19,11 +20,13 @@ 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 ShopScreen extends PagedGui {
|
||||
public class ShopScreen extends PagedGui implements SearchableInterface {
|
||||
|
||||
public String searchQuery = "";
|
||||
public int sortMode = 0;
|
||||
public final int maxSortMode = 5;
|
||||
|
||||
final public HashMap<ItemStack, ItemPriceRecord> filteredPrices = new HashMap<>();
|
||||
public TreeMap<ItemStack, ItemPriceRecord> filteredPrices;
|
||||
|
||||
public ShopScreen(ServerPlayerEntity player) {
|
||||
super(player, null);
|
||||
@ -38,22 +41,10 @@ public class ShopScreen extends PagedGui {
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
filterPrices();
|
||||
filteredPrices = sortAndFilterPrices(ServerShop.priceStorage.prices, sortMode, searchQuery);
|
||||
super.updateDisplay();
|
||||
}
|
||||
|
||||
public void filterPrices() {
|
||||
filteredPrices.clear();
|
||||
for (ItemStack stack : ServerShop.priceStorage.prices.keySet()) {
|
||||
String itemName = stack.getItem().toString();
|
||||
if (itemName.contains(searchQuery)) {
|
||||
ItemPriceRecord price = ServerShop.priceStorage.getPrices(stack);
|
||||
if (price.buyPrice() > 0 || price.sellPrice() > 0) {
|
||||
filteredPrices.put(stack, price);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void doSearch(String query) {
|
||||
searchQuery = query;
|
||||
@ -71,7 +62,7 @@ public class ShopScreen extends PagedGui {
|
||||
ItemStack cursorStack = getPlayer().currentScreenHandler.getCursorStack();
|
||||
if (!cursorStack.isEmpty()) {
|
||||
sell(cursorStack, player, true);
|
||||
} else {
|
||||
} else if (hasPrices(element.getItemStack())) {
|
||||
ItemStack itemStack = removePrices(element.getItemStack());
|
||||
if (type.shift) {
|
||||
itemStack.setCount(itemStack.getMaxCount());
|
||||
@ -126,4 +117,35 @@ public class ShopScreen extends PagedGui {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement sort() {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable(switch (sortMode) {
|
||||
case 0 -> "gui.servershop.sort.price.buy.ascending";
|
||||
case 1 -> "gui.servershop.sort.price.buy.descending";
|
||||
case 2 -> "gui.servershop.sort.price.sell.ascending";
|
||||
case 3 -> "gui.servershop.sort.price.sell.descending";
|
||||
case 4 -> "gui.servershop.sort.name.item.ascending";
|
||||
case 5 -> "gui.servershop.sort.name.item.descending";
|
||||
default -> "gui.servershop.sort.unknown";
|
||||
}))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(switch (sortMode) {
|
||||
case 0 -> GUI_SORT_ITEM_PRICE_BUY_ASCENDING;
|
||||
case 1 -> GUI_SORT_ITEM_PRICE_BUY_DESCENDING;
|
||||
case 2 -> GUI_SORT_ITEM_PRICE_SELL_ASCENDING;
|
||||
case 3 -> GUI_SORT_ITEM_PRICE_SELL_DESCENDING;
|
||||
case 4 -> GUI_SORT_ALPHABETICAL_ITEM_NAME_ASCENDING;
|
||||
case 5 -> GUI_SORT_ALPHABETICAL_ITEM_NAME_DESCENDING;
|
||||
default -> GUI_ERROR;
|
||||
})
|
||||
.setCallback((index, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
sortMode = (sortMode + 1) % (maxSortMode + 1);
|
||||
updateDisplay();
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,46 @@
|
||||
"gui.servershop.auction.title": "Auction",
|
||||
"gui.servershop.auction.create": "Create auction",
|
||||
"gui.servershop.search.title": "Search",
|
||||
"gui.servershop.balance.editor.title" : "Enter new balance of %s",
|
||||
"gui.servershop.balance.editor.value" : "Balance: %d",
|
||||
"gui.servershop.balances.title": "Player balances",
|
||||
"gui.servershop.item.seller_me": "Sold by you(%s)",
|
||||
"gui.servershop.item.seller": "Sold by %s",
|
||||
"gui.servershop.sort.unknown": "Bad sort id",
|
||||
"gui.servershop.sort.name.item.ascending": "Sorting by item name ascending",
|
||||
"gui.servershop.sort.name.item.descending": "Sorting by item name descending",
|
||||
"gui.servershop.sort.name.player.ascending": "Sorting by player name ascending",
|
||||
"gui.servershop.sort.name.player.descending": "Sorting by player name descending",
|
||||
"gui.servershop.sort.balance.player.ascending": "Sorting by player balance ascending",
|
||||
"gui.servershop.sort.balance.player.descending": "Sorting by player balance descending",
|
||||
"gui.servershop.sort.price.sell.ascending": "Sorting by sell price ascending",
|
||||
"gui.servershop.sort.price.sell.descending": "Sorting by sell price descending",
|
||||
"gui.servershop.sort.price.buy.ascending": "Sorting by buy price ascending",
|
||||
"gui.servershop.sort.price.buy.descending": "Sorting by buy price descending",
|
||||
"gui.servershop.shop.editor.title": "Price editor",
|
||||
"gui.servershop.auction.create.title": "Type price, insert item",
|
||||
"gui.servershop.item.buy_price": "Buy for %d with left click",
|
||||
"gui.servershop.item.sell_price": "Sell for %d with right click",
|
||||
"gui.servershop.shop.editor.item.buy_price": "Can be bought for %d, edit with left click",
|
||||
"gui.servershop.shop.editor.item.sell_price": "Can be sold for %d, edit with right click",
|
||||
"gui.servershop.shop.editor.item.buy_price_disabled": "Buying is disabled, edit with left click",
|
||||
"gui.servershop.shop.editor.item.buy_price_not_buyable": "Cannot be bought, edit with left click",
|
||||
"gui.servershop.shop.editor.item.sell_price_disabled": "Selling is disabled, edit with right click",
|
||||
"gui.servershop.shop.editor.item.sell_price_not_sellable": "Cannot be sold, edit with right click",
|
||||
"gui.servershop.shop.editor.filtering.buy.not_buyable.show": "Show unbuyable items",
|
||||
"gui.servershop.shop.editor.filtering.buy.not_buyable.hide": "Hide unbuyable items",
|
||||
"gui.servershop.shop.editor.filtering.buy.disabled.show": "Hide disabled items for buying",
|
||||
"gui.servershop.shop.editor.filtering.buy.disabled.hide": "Show disabled items for buying ",
|
||||
"gui.servershop.shop.editor.filtering.buy.normal.show": "Show buyable items",
|
||||
"gui.servershop.shop.editor.filtering.buy.normal.hide": "Hide buyable items",
|
||||
"gui.servershop.shop.editor.filtering.sell.normal.show": "Show sellable items",
|
||||
"gui.servershop.shop.editor.filtering.sell.normal.hide": "Hide sellable items",
|
||||
"gui.servershop.shop.editor.filtering.sell.not_selling.show": "Show unsellable items",
|
||||
"gui.servershop.shop.editor.filtering.sell.not_selling.hide": "Hide unsellable items",
|
||||
"gui.servershop.shop.editor.filtering.sell.disabled.show": "Show disabled items for selling",
|
||||
"gui.servershop.shop.editor.filtering.sell.disabled.hide": "Hide disabled items for selling",
|
||||
"gui.servershop.shop.editor.item.buy_price.title": "Enter buy price",
|
||||
"gui.servershop.shop.editor.item.sell_price.title": "Enter sell price",
|
||||
"gui.servershop.item.stack_info": "Holding shift tries to do a stack",
|
||||
"message.servershop.prices.load": "Loaded prices from disk",
|
||||
"message.servershop.prices.load_fail": "Failed loading prices from disk",
|
||||
|
Loading…
Reference in New Issue
Block a user