parent
50191c1964
commit
d1b691cbf0
3 changed files with 159 additions and 7 deletions
@ -0,0 +1,137 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.commands; |
||||||
|
|
||||||
|
import com.mojang.brigadier.arguments.FloatArgumentType; |
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType; |
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
||||||
|
import com.mojang.brigadier.context.CommandContext; |
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack; |
||||||
|
import io.papermc.paper.command.brigadier.Commands; |
||||||
|
import io.papermc.paper.command.brigadier.argument.ArgumentTypes; |
||||||
|
import org.bukkit.command.CommandSender; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import xyz.soukup.ecoCraftCore.objects.Account; |
||||||
|
import xyz.soukup.ecoCraftCore.objects.Transaction; |
||||||
|
|
||||||
|
public class MoneyCommand { |
||||||
|
public static LiteralArgumentBuilder<CommandSourceStack> createCommand() { |
||||||
|
return Commands.literal("money") |
||||||
|
.then(Commands.literal("send") |
||||||
|
.requires(source -> source.getSender() instanceof Player) |
||||||
|
.then(Commands.argument("player", ArgumentTypes.player()) |
||||||
|
.then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) |
||||||
|
.executes(MoneyCommand::sendMoney)))) |
||||||
|
.then(Commands.literal("give") |
||||||
|
.requires(source -> source.getExecutor().hasPermission("ecc.money.give")) |
||||||
|
.then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) |
||||||
|
.requires(source -> source.getSender() instanceof Player) |
||||||
|
.executes(MoneyCommand::giveMoneySelf)) |
||||||
|
.then(Commands.argument("player", ArgumentTypes.player()) |
||||||
|
.then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) |
||||||
|
.executes(MoneyCommand::giveMoneyPlayer))) |
||||||
|
.then(Commands.argument("type", StringArgumentType.word()) |
||||||
|
.then(Commands.argument("owner", StringArgumentType.word()) |
||||||
|
.then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) |
||||||
|
.executes(MoneyCommand::giveMoneyOther))))) |
||||||
|
.then(Commands.literal("remove") |
||||||
|
.requires(source -> source.getExecutor().hasPermission("ecc.money.remove")) |
||||||
|
.then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) |
||||||
|
.requires(source -> source.getSender() instanceof Player) |
||||||
|
.executes(MoneyCommand::removeMoneySelf)) |
||||||
|
.then(Commands.argument("player", ArgumentTypes.player()) |
||||||
|
.then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) |
||||||
|
.executes(MoneyCommand::removeMoneyPlayer))) |
||||||
|
.then(Commands.argument("type", StringArgumentType.word()) |
||||||
|
.then(Commands.argument("owner", StringArgumentType.word()) |
||||||
|
.then(Commands.argument("amount", FloatArgumentType.floatArg(0.1F)) |
||||||
|
.executes(MoneyCommand::removeMoneyOther))))) |
||||||
|
.executes(MoneyCommand::getBalance); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static int getBalance(CommandContext<CommandSourceStack> context){ |
||||||
|
if (!(context.getSource().getSender() instanceof Player player)){ |
||||||
|
return 0; |
||||||
|
} |
||||||
|
Account account = Account.getOrCreate(player); |
||||||
|
player.sendPlainMessage(String.format("Tvuj balanc: %.2f", account.getBalance())); |
||||||
|
return 1; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private static int sendMoney(CommandContext<CommandSourceStack> context){ |
||||||
|
Player sender = (Player) context.getSource().getSender(); |
||||||
|
Player receiver = context.getArgument("player", Player.class); |
||||||
|
Float amount = context.getArgument("amount", Float.class); |
||||||
|
|
||||||
|
Account senderAccount = Account.getOrCreate(sender); |
||||||
|
|
||||||
|
if (amount > senderAccount.getBalance()){ |
||||||
|
sender.sendPlainMessage("nemáš mony!"); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
Transaction transaction = new Transaction(amount,"player", sender.getName(), "player", receiver.getName(), "player"); |
||||||
|
transaction.process(); |
||||||
|
|
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
private static int giveMoneyPlayer(CommandContext<CommandSourceStack> context){ |
||||||
|
CommandSender commandSender = context.getSource().getSender(); |
||||||
|
Player receiver = context.getArgument("player", Player.class); |
||||||
|
Float amount = context.getArgument("amount", Float.class); |
||||||
|
|
||||||
|
Transaction transaction = new Transaction(amount,"admin", commandSender.getName(), "player", receiver.getName(), "admin"); |
||||||
|
transaction.process(); |
||||||
|
|
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
private static int giveMoneySelf(CommandContext<CommandSourceStack> 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.process(); |
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
private static int giveMoneyOther(CommandContext<CommandSourceStack> 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.process(); |
||||||
|
return 1; |
||||||
|
} |
||||||
|
private static int removeMoneyPlayer(CommandContext<CommandSourceStack> context){ |
||||||
|
CommandSender commandSender = context.getSource().getSender(); |
||||||
|
Player sender = context.getArgument("player", Player.class); |
||||||
|
Float amount = context.getArgument("amount", Float.class); |
||||||
|
|
||||||
|
Transaction transaction = new Transaction(amount, "player", sender.getName(),"admin", commandSender.getName(), "admin"); |
||||||
|
transaction.process(); |
||||||
|
return 1; |
||||||
|
} |
||||||
|
private static int removeMoneySelf(CommandContext<CommandSourceStack> 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.process(); |
||||||
|
return 1; |
||||||
|
} |
||||||
|
private static int removeMoneyOther(CommandContext<CommandSourceStack> 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.process(); |
||||||
|
return 1; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue