Compare commits

...

4 Commits

Author SHA1 Message Date
Pygot 3282e3870b Merge branch 'master' of https://git.soukup.xyz/EcoCraft/plugin into dev_gioth 1 week ago
Pygot a84d6ece02 Merge remote-tracking branch 'origin/ble' into dev_gioth 3 weeks ago
jakub 7e91d400a4 Merge remote-tracking branch 'origin/ble' into ble 4 weeks ago
Gioth8281 6461f94865 WIP Shop Edit - Issue #9 9 months ago
  1. 95
      src/main/java/xyz/soukup/ecoCraftCore/commands/ShopEditCommand.java
  2. 5
      src/main/resources/messages.yml

@ -0,0 +1,95 @@
package xyz.soukup.ecoCraftCore.commands;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import io.papermc.paper.command.brigadier.Commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.soukup.ecoCraftCore.objects.Shop;
import xyz.soukup.ecoCraftCore.utilities.Messages;
public class ShopEditCommand {
public static LiteralArgumentBuilder<CommandSourceStack> createCommand() {
RequiredArgumentBuilder<CommandSourceStack, Integer> shopId = Commands.argument("shop-id", IntegerArgumentType.integer());
RequiredArgumentBuilder<CommandSourceStack, Integer> amount = Commands.argument("amount", IntegerArgumentType.integer());
RequiredArgumentBuilder<CommandSourceStack, Integer> price = Commands.argument("price", IntegerArgumentType.integer());
LiteralArgumentBuilder<CommandSourceStack> changePriceSell = Commands.literal("change-price-sell");
LiteralArgumentBuilder<CommandSourceStack> changePriceBuy = Commands.literal("change-price-buy");
LiteralArgumentBuilder<CommandSourceStack> changeItemAmount = Commands.literal("change-item-amount");
return Commands.literal("shop-edit")
.then(shopId
.then(changePriceSell.then(price.executes(ShopEditCommand::changePriceSell)))
.then(changePriceBuy.then(price.executes(ShopEditCommand::changePriceBuy)))
.then(changeItemAmount.then(amount.executes(ShopEditCommand::changeItemAmount))));
}
private static int changePriceSell(CommandContext<CommandSourceStack> context) {
CommandSender commandSender = context.getSource().getSender();
Integer shopId = context.getArgument("shop-id", Integer.class);
Integer price = context.getArgument("price", Integer.class);
if (!(commandSender instanceof Player)){
Messages.send(commandSender, "generic.error.not-player");
return 0;
}
Shop shop = Shop.findById(shopId);
if (shop == null){
Messages.send(commandSender, "shop.error.not-found");
return 0;
}
shop.setPriceSell(price);
Messages.send(commandSender, "shop.edit.price-sell-changed");
return 1;
}
private static int changePriceBuy(CommandContext<CommandSourceStack> context) {
CommandSender commandSender = context.getSource().getSender();
Integer shopId = context.getArgument("shop-id", Integer.class);
Integer price = context.getArgument("price", Integer.class);
if (!(commandSender instanceof Player)){
Messages.send(commandSender, "generic.error.not-player");
return 0;
}
Shop shop = Shop.findById(shopId);
if (shop == null){
Messages.send(commandSender, "shop.error.not-found");
return 0;
}
shop.setPriceBuy(price);
Messages.send(commandSender, "shop.edit.price-buy-changed");
return 1;
}
private static int changeItemAmount(CommandContext<CommandSourceStack> context) {
CommandSender commandSender = context.getSource().getSender();
Integer shopId = context.getArgument("shop-id", Integer.class);
Integer amount = context.getArgument("amount", Integer.class);
if (!(commandSender instanceof Player)){
Messages.send(commandSender, "generic.error.not-player");
return 0;
}
Shop shop = Shop.findById(shopId);
if (shop == null){
Messages.send(commandSender, "shop.error.not-found");
return 0;
}
shop.setAmount(amount);
Messages.send(commandSender, "shop.edit.item-amount-changed");
return 1;
}
}

@ -16,6 +16,11 @@ shop:
not-marked: "<red>Musíš označit ceduly a chestku, aby jsi mohl vytvořit obchod" not-marked: "<red>Musíš označit ceduly a chestku, aby jsi mohl vytvořit obchod"
empty-hand: "<red>Nedržíš v ruce žádný item" empty-hand: "<red>Nedržíš v ruce žádný item"
chest-open: "<red>Nelze obchodovat, když je chestka obchodu otevřena." chest-open: "<red>Nelze obchodovat, když je chestka obchodu otevřena."
not-found: "<red>Obchod nenalezen."
edit:
price-sell-changed: "<green>Změnil jsi prodávající cenu v obchodě."
price-buy-changed: "<green>Změnil jsi kupující cenu v obchodě."
item-amount-changed: "<green>Změnil jsi množství itemu v obchodě."
buy: "<green>Koupil jsi <count>x <item> za <price>$" buy: "<green>Koupil jsi <count>x <item> za <price>$"
sell: "<green>Prodal jsi <count>x <item> za <price>$" sell: "<green>Prodal jsi <count>x <item> za <price>$"
created: "<green>Obchod vytvořen." created: "<green>Obchod vytvořen."

Loading…
Cancel
Save