Compare commits
4 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
3282e3870b | 1 week ago |
|
|
a84d6ece02 | 3 weeks ago |
|
|
7e91d400a4 | 4 weeks ago |
|
|
6461f94865 | 9 months ago |
2 changed files with 100 additions and 0 deletions
@ -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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue