diff --git a/pom.xml b/pom.xml
index 4468d7c..547330f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -136,7 +136,7 @@
io.papermc.paper
paper-api
- 1.21.3-R0.1-SNAPSHOT
+ 1.21.1-R0.1-SNAPSHOT
provided
diff --git a/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java b/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java
index 20a6fa8..bc8ecb4 100644
--- a/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java
+++ b/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java
@@ -73,7 +73,7 @@ public final class EcoCraftCore extends JavaPlugin {
}
private void prepareDatabase() throws SQLException {
- String databaseUrl = "jdbc:mysql://soukup.xyz:3306/ecc";
+ String databaseUrl = "jdbc:mysql://localhost:3306/ecc";
connectionSource = new JdbcConnectionSource(databaseUrl, "ecc", "ecc");
Logger.getLogger("com.j256.ormlite.table.TableUtils").setLevel(Level.OFF);
diff --git a/src/main/java/xyz/soukup/ecoCraftCore/commands/MoneyCommand.java b/src/main/java/xyz/soukup/ecoCraftCore/commands/MoneyCommand.java
index a938632..af7b9c6 100644
--- a/src/main/java/xyz/soukup/ecoCraftCore/commands/MoneyCommand.java
+++ b/src/main/java/xyz/soukup/ecoCraftCore/commands/MoneyCommand.java
@@ -1,10 +1,8 @@
package xyz.soukup.ecoCraftCore.commands;
-import com.mojang.brigadier.LiteralMessage;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
-import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.papermc.paper.command.brigadier.CommandSourceStack;
@@ -20,71 +18,66 @@ import xyz.soukup.ecoCraftCore.utilities.PHHM;
@SuppressWarnings("UnstableApiUsage")
public class MoneyCommand {
- public static LiteralArgumentBuilder createCommand() {
-
- RequiredArgumentBuilder playerArgument = Commands.argument("player", ArgumentTypes.player());
- RequiredArgumentBuilder amountArgument = Commands.argument("amount", FloatArgumentType.floatArg(0.1F));
- RequiredArgumentBuilder ownerArgument = Commands.argument("owner", StringArgumentType.word());
- RequiredArgumentBuilder typeArgument = Commands.argument("type", StringArgumentType.word());
-
+ public static LiteralArgumentBuilder createCommand() {
+ // 1. Send Branch
LiteralArgumentBuilder send = Commands.literal("send")
.requires(source -> source.getSender() instanceof Player)
- .then(playerArgument.then(amountArgument.executes(MoneyCommand::sendMoney)));
-
-
- RequiredArgumentBuilder selfGive = amountArgument
- .requires(source -> source.getSender() instanceof Player)
- .executes(MoneyCommand::giveMoneySelf);
-
- RequiredArgumentBuilder playerGive = playerArgument
- .then(amountArgument.executes(MoneyCommand::giveMoneyPlayer));
-
- RequiredArgumentBuilder giveOther = typeArgument.then(ownerArgument.then(amountArgument.executes(MoneyCommand::giveMoneyOther)));
+ .then(Commands.argument("player", ArgumentTypes.player())
+ .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F))
+ .executes(MoneyCommand::sendMoney)));
+ // 2. Give Branch
LiteralArgumentBuilder give = Commands.literal("give")
- .then(selfGive)
- .then(playerGive)
- .then(giveOther);
-
-
- RequiredArgumentBuilder removeSelf = amountArgument
- .requires(source -> source.getSender() instanceof Player)
- .executes(MoneyCommand::removeMoneySelf);
-
- RequiredArgumentBuilder removePlayer = playerArgument
- .then(amountArgument.executes(MoneyCommand::removeMoneyPlayer));
-
- RequiredArgumentBuilder removeOther = typeArgument
- .then(ownerArgument
- .then(amountArgument.executes(MoneyCommand::removeMoneyOther)));
-
+ // Case: /money give
+ .then(Commands.argument("player", ArgumentTypes.player())
+ .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F))
+ .executes(MoneyCommand::giveMoneyPlayer)))
+ // Case: /money give (Self)
+ .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F))
+ .requires(source -> source.getSender() instanceof Player)
+ .executes(MoneyCommand::giveMoneySelf))
+ // Case: /money give
+ .then(Commands.argument("type", StringArgumentType.word())
+ .then(Commands.argument("owner", StringArgumentType.word())
+ .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F))
+ .executes(MoneyCommand::giveMoneyOther))));
+
+ // 3. Remove Branch
LiteralArgumentBuilder remove = Commands.literal("remove")
- .then(removeSelf)
- .then(removePlayer)
- .then(removeOther);
-
+ // Case: /money remove
+ .then(Commands.argument("player", ArgumentTypes.player())
+ .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F))
+ .executes(MoneyCommand::removeMoneyPlayer)))
+ // Case: /money remove (Self)
+ .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F))
+ .requires(source -> source.getSender() instanceof Player)
+ .executes(MoneyCommand::removeMoneySelf))
+ // Case: /money remove
+ .then(Commands.argument("type", StringArgumentType.word())
+ .then(Commands.argument("owner", StringArgumentType.word())
+ .then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F))
+ .executes(MoneyCommand::removeMoneyOther))));
+
+ // Main command: /money
return Commands.literal("money")
.then(send)
.then(give)
.then(remove)
.executes(MoneyCommand::getBalance);
-
}
- private static int getBalance(CommandContext context){
+ private static int getBalance(CommandContext context) {
CommandSender commandSender = context.getSource().getSender();
- if (!(commandSender instanceof Player player)){
+ if (!(commandSender instanceof Player player)) {
Messages.send(commandSender, "generic.error.not-player");
return 0;
}
Account account = Account.getOrCreate(player);
Messages.send(player, "money.balance.self", PHHM.get(account));
return 1;
-
}
-
private static int sendMoney(CommandContext context) throws CommandSyntaxException {
PlayerSelectorArgumentResolver receiverResolver = context.getArgument("player", PlayerSelectorArgumentResolver.class);
Player receiver = receiverResolver.resolve(context.getSource()).getFirst();
@@ -94,12 +87,12 @@ public class MoneyCommand {
Account senderAccount = Account.getOrCreate(sender);
- if (amount > senderAccount.getBalance()){
+ if (amount > senderAccount.getBalance()) {
Messages.send(sender, "generic.error.no-funds");
return 0;
}
- Transaction transaction = new Transaction(amount,"player", sender.getName(), "player", receiver.getName(), "player");
+ Transaction transaction = new Transaction(amount, "player", sender.getName(), "player", receiver.getName(), "player");
transaction.process();
Messages.send(sender, "money.send.player", PHHM.get(transaction));
@@ -110,82 +103,75 @@ public class MoneyCommand {
private static int giveMoneyPlayer(CommandContext context) throws CommandSyntaxException {
CommandSender commandSender = context.getSource().getSender();
-
PlayerSelectorArgumentResolver receiverResolver = context.getArgument("player", PlayerSelectorArgumentResolver.class);
Player receiver = receiverResolver.resolve(context.getSource()).getFirst();
-
Float amount = context.getArgument("amount", Float.class);
- Transaction transaction = new Transaction(amount,"admin", commandSender.getName(), "player", receiver.getName(), "admin");
+ Transaction transaction = new Transaction(amount, "admin", commandSender.getName(), "player", receiver.getName(), "admin");
transaction.process();
Messages.send(commandSender, "money.give.player", PHHM.get(transaction));
-
return 1;
}
- private static int giveMoneySelf(CommandContext context){
+ private static int giveMoneySelf(CommandContext context) {
Player player = (Player) context.getSource().getSender();
Float amount = context.getArgument("amount", Float.class);
- Transaction transaction = new Transaction(amount,"admin", player.getName(), "player", player.getName(), "admin");
+ Transaction transaction = new Transaction(amount, "admin", player.getName(), "player", player.getName(), "admin");
transaction.process();
Messages.send(player, "money.give.self", PHHM.get(transaction));
-
return 1;
}
- private static int giveMoneyOther(CommandContext context){
+ private static int giveMoneyOther(CommandContext context) {
CommandSender commandSender = context.getSource().getSender();
Float amount = context.getArgument("amount", Float.class);
String owner = context.getArgument("owner", String.class);
String type = context.getArgument("type", String.class);
- Transaction transaction = new Transaction(amount,"admin", commandSender.getName(), type, owner, "admin");
+ Transaction transaction = new Transaction(amount, "admin", commandSender.getName(), type, owner, "admin");
transaction.process();
Messages.send(commandSender, "money.give.other", PHHM.get(transaction));
-
return 1;
}
+
private static int removeMoneyPlayer(CommandContext context) throws CommandSyntaxException {
CommandSender commandSender = context.getSource().getSender();
-
PlayerSelectorArgumentResolver senderResolver = context.getArgument("player", PlayerSelectorArgumentResolver.class);
Player sender = senderResolver.resolve(context.getSource()).getFirst();
-
Float amount = context.getArgument("amount", Float.class);
- Transaction transaction = new Transaction(amount, "player", sender.getName(),"admin", commandSender.getName(), "admin");
+ Transaction transaction = new Transaction(amount, "player", sender.getName(), "admin", commandSender.getName(), "admin");
transaction.process();
Messages.send(commandSender, "money.remove.player", PHHM.get(transaction));
-
return 1;
}
- private static int removeMoneySelf(CommandContext context){
+
+ private static int removeMoneySelf(CommandContext context) {
Player player = (Player) context.getSource().getSender();
Float amount = context.getArgument("amount", Float.class);
- Transaction transaction = new Transaction(amount,"player", player.getName(),"admin", player.getName(), "admin");
+ Transaction transaction = new Transaction(amount, "player", player.getName(), "admin", player.getName(), "admin");
transaction.process();
Messages.send(player, "money.remove.self", PHHM.get(transaction));
-
return 1;
}
- private static int removeMoneyOther(CommandContext context){
+
+ private static int removeMoneyOther(CommandContext context) {
CommandSender commandSender = context.getSource().getSender();
Float amount = context.getArgument("amount", Float.class);
String owner = context.getArgument("owner", String.class);
String type = context.getArgument("type", String.class);
- Transaction transaction = new Transaction(amount, type, owner,"admin", commandSender.getName(), "admin");
+ Transaction transaction = new Transaction(amount, type, owner, "admin", commandSender.getName(), "admin");
transaction.process();
Messages.send(commandSender, "money.remove.other", PHHM.get(transaction));
-
return 1;
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/xyz/soukup/ecoCraftCore/commands/ShopCommand.java b/src/main/java/xyz/soukup/ecoCraftCore/commands/ShopCommand.java
index d2f5997..78a3656 100644
--- a/src/main/java/xyz/soukup/ecoCraftCore/commands/ShopCommand.java
+++ b/src/main/java/xyz/soukup/ecoCraftCore/commands/ShopCommand.java
@@ -18,88 +18,89 @@ import xyz.soukup.ecoCraftCore.utilities.PDC;
@SuppressWarnings("UnstableApiUsage")
public class ShopCommand {
- public static LiteralArgumentBuilder createCommand() {
-
- FloatArgumentType floatArgType = FloatArgumentType.floatArg(0.1F);
-
-
- LiteralArgumentBuilder buy = Commands.literal("buy")
- .then(Commands.argument("buy_price", floatArgType).executes(ShopCommand::createShop));
- LiteralArgumentBuilder sell = Commands.literal("sell")
- .then(Commands.argument("sell_price", floatArgType).executes(ShopCommand::createShop));
+ public static LiteralArgumentBuilder createCommand() {
+ // Define the argument types
+ var amountArg = Commands.argument("amount", IntegerArgumentType.integer(1));
+ var buyPriceArg = Commands.argument("buy_price", FloatArgumentType.floatArg(0.0F));
+ var sellPriceArg = Commands.argument("sell_price", FloatArgumentType.floatArg(0.0F));
+ // Path: /shop ...
return Commands.literal("shop")
- .then(Commands.argument("amount", IntegerArgumentType.integer(1))
- .then(buy.then(sell))
- .then(sell.then(buy)));
-
-
+ .then(amountArg
+ // Branch 1: ... buy [sell ]
+ .then(Commands.literal("buy")
+ .then(buyPriceArg
+ .executes(ShopCommand::createShop)
+ .then(Commands.literal("sell")
+ .then(sellPriceArg.executes(ShopCommand::createShop)))))
+
+ // Branch 2: ... sell [buy ]
+ .then(Commands.literal("sell")
+ .then(sellPriceArg
+ .executes(ShopCommand::createShop)
+ .then(Commands.literal("buy")
+ .then(buyPriceArg.executes(ShopCommand::createShop))))));
}
- private static int createShop(CommandContext ctx){
+ private static int createShop(CommandContext ctx) {
CommandSourceStack source = ctx.getSource();
- if (!(source.getSender() instanceof Player player)){
+ if (!(source.getSender() instanceof Player player)) {
Messages.send(source.getSender(), "generic.error.not-player");
return 0;
}
+ // 1. Check if blocks are marked
Chest chest = RulerMarking.chests.get(player);
Sign sign = RulerMarking.signs.get(player);
- Integer amount = ctx.getArgument("amount", Integer.class);
-
- Float buyPrice;
- try {
- buyPrice = ctx.getArgument("buy_price", Float.class);
- } catch (IllegalArgumentException e) {
- buyPrice = (Float) 0F;
- }
-
- Float sellPrice;
- try {
- sellPrice = ctx.getArgument("sell_price", Float.class);
- }catch (IllegalArgumentException e){
- sellPrice = (Float) 0F;
- }
-
-
- if (sign == null || chest == null){
+ if (sign == null || chest == null) {
Messages.send(player, "shop.error.not-marked");
return 0;
}
+ // 2. Validate Item in Hand
ItemStack item = player.getInventory().getItemInMainHand();
-
- if (item.isEmpty()){
+ if (item.isEmpty()) {
Messages.send(player, "shop.error.empty-hand");
return 0;
}
- if (PDC.getInteger(sign, "shop") != null){
+ // 3. Check if already a shop
+ if (PDC.getInteger(sign, "shop") != null) {
Messages.send(player, "shop.error.already-shop");
return 0;
}
+ // 4. Parse Arguments Safely
+ int amount = ctx.getArgument("amount", Integer.class);
- VirtualChest virtualChest = VirtualChest.getOrCreate(chest);
- virtualChest.databaseSave();
+ float buyPrice = 0.0F;
+ try {
+ buyPrice = ctx.getArgument("buy_price", Float.class);
+ } catch (IllegalArgumentException ignored) {}
+ float sellPrice = 0.0F;
+ try {
+ sellPrice = ctx.getArgument("sell_price", Float.class);
+ } catch (IllegalArgumentException ignored) {}
- PDC.set(chest, "virtual", Integer.valueOf(virtualChest.getId()));
+ // 5. Database and PDC Logic
+ VirtualChest virtualChest = VirtualChest.getOrCreate(chest);
+ virtualChest.databaseSave();
+ PDC.set(chest, "virtual", virtualChest.getId());
+ // 6. Inventory Calculations
int freeSpace = InventoryUtils.getSpaceLeft(chest.getInventory(), item);
int stock = InventoryUtils.getCount(chest.getInventory(), item);
+ // 7. Final Creation
Shop shop = new Shop(player, item, stock, freeSpace, amount, buyPrice, sellPrice, virtualChest.getId());
shop.save();
shop.writeIntoSign(sign);
Messages.send(player, "shop.created");
-
-
return 1;
}
-
-}
+}
\ No newline at end of file
diff --git a/src/main/java/xyz/soukup/ecoCraftCore/events/ShopLogic.java b/src/main/java/xyz/soukup/ecoCraftCore/events/ShopLogic.java
index a166176..97d3b22 100644
--- a/src/main/java/xyz/soukup/ecoCraftCore/events/ShopLogic.java
+++ b/src/main/java/xyz/soukup/ecoCraftCore/events/ShopLogic.java
@@ -3,6 +3,9 @@ package xyz.soukup.ecoCraftCore.events;
import dev.triumphteam.gui.builder.item.ItemBuilder;
import dev.triumphteam.gui.guis.Gui;
import dev.triumphteam.gui.guis.GuiItem;
+import io.papermc.paper.dialog.Dialog;
+import io.papermc.paper.registry.data.dialog.DialogBase;
+import io.papermc.paper.registry.data.dialog.type.DialogType;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -25,6 +28,7 @@ import xyz.soukup.ecoCraftCore.utilities.PDC;
import java.util.HashMap;
+@SuppressWarnings("UnstableApiUsage")
public class ShopLogic implements Listener {
@EventHandler
@@ -64,6 +68,10 @@ public class ShopLogic implements Listener {
//ZDE Přídat otevíraní shop edit gui
+ if (shop.getOwnerType().equals("player") && shop.getOwner().equals(player.getName())){
+
+ return;
+ }
Gui gui = buildShopGui(player, shop);
@@ -160,6 +168,13 @@ public class ShopLogic implements Listener {
return gui;
}
+ public static Dialog editDialog(){
+ return Dialog.create(builder -> builder.empty()
+ .base(DialogBase.builder(Messages.get("gui.shop-edit.title")).build())
+ .type(DialogType.notice())
+ );
+ }
+
public static void buy(Shop shop, Player player, int multiplier){
if (VirtualChestLogic.openedChests.containsKey(shop.getVirtualChestID())){
diff --git a/src/main/java/xyz/soukup/ecoCraftCore/objects/Transaction.java b/src/main/java/xyz/soukup/ecoCraftCore/objects/Transaction.java
index c2bff31..f831595 100644
--- a/src/main/java/xyz/soukup/ecoCraftCore/objects/Transaction.java
+++ b/src/main/java/xyz/soukup/ecoCraftCore/objects/Transaction.java
@@ -81,11 +81,14 @@ public class Transaction {
this.receiverType = receiverType;
this.receiver = receiver;
this.type = type;
+ this.primaryInfo = "";
+ this.secondaryInfo = "";
}
public Transaction(float amount, String senderType, String sender, String receiverType, String receiver, String type, String primaryInfo) {
this(amount, senderType, sender, receiverType, receiver, type);
this.primaryInfo = primaryInfo;
+ this.secondaryInfo = "";
}
public Transaction(float amount, String senderType, String sender, String receiverType, String receiver, String type, String primaryInfo, String secondaryInfo) {
diff --git a/src/main/java/xyz/soukup/ecoCraftCore/utilities/DaoRegistry.java b/src/main/java/xyz/soukup/ecoCraftCore/utilities/DaoRegistry.java
index 812aa14..3ccffd1 100644
--- a/src/main/java/xyz/soukup/ecoCraftCore/utilities/DaoRegistry.java
+++ b/src/main/java/xyz/soukup/ecoCraftCore/utilities/DaoRegistry.java
@@ -6,7 +6,7 @@ import xyz.soukup.ecoCraftCore.objects.Shop;
import xyz.soukup.ecoCraftCore.objects.Transaction;
import xyz.soukup.ecoCraftCore.objects.VirtualChest;
-public class DaoRegistry {
+public class DaoRegistry {
private static Dao shopDao;
private static Dao transactionDao;
private static Dao virtualChestDao;
diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml
index 2651e95..d3ad7c0 100644
--- a/src/main/resources/messages.yml
+++ b/src/main/resources/messages.yml
@@ -49,6 +49,8 @@ menu:
sell: "Prodat ks za $"
gui:
all: "Seznam guis: <1>, <2>"
+ shop-edit:
+ title: "Editace Obchodu"
shopadmin:
title: "GUI - Shop Admin"
items: