Search in sources :

Example 1 with OverlayMessageS2CPacket

use of net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket in project KahzerxMod by otakucraft.

the class BankCommand method register.

public void register(CommandDispatcher<ServerCommandSource> dispatcher, ShopExtension extension) {
    dispatcher.register(literal("bank").requires(server -> extension.extensionSettings().isEnabled()).then(literal("balance").executes(context -> {
        context.getSource().sendFeedback(new LiteralText("Balance: ").append(MarkEnum.OTAKU_COIN.appendMessage(String.valueOf(extension.getBalance(context.getSource().getPlayer())))), false);
        return 1;
    })).then(literal("transfer").then(argument("player", StringArgumentType.string()).suggests((c, b) -> suggestMatching(extension.getPlayers(), b)).then(argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
        String playerName = StringArgumentType.getString(context, "player");
        String playerUUID = extension.getPlayerUUID(playerName);
        int amount = IntegerArgumentType.getInteger(context, "amount");
        if (playerUUID == null) {
            context.getSource().sendFeedback(MarkEnum.CROSS.appendMessage("Este jugador no existe!"), false);
            return 1;
        }
        if (extension.getAccounts().get(context.getSource().getPlayer()).getCoins() < amount) {
            context.getSource().sendFeedback(MarkEnum.CROSS.appendMessage("No tienes balance suficiente!"), false);
            return 1;
        }
        extension.updateFounds(playerUUID, amount);
        extension.updateFounds(context.getSource().getPlayer(), amount * -1);
        extension.logTransfer(context.getSource().getPlayer(), playerUUID, playerName, amount);
        context.getSource().sendFeedback(MarkEnum.TICK.appendMessage("Transferencia de ").append(MarkEnum.OTAKU_COIN.appendMessage(String.format("%d a %s completada!", amount, playerName))), false);
        ServerPlayerEntity destPlayer = context.getSource().getServer().getPlayerManager().getPlayer(UUID.fromString(playerUUID));
        if (destPlayer != null) {
            destPlayer.networkHandler.sendPacket(new OverlayMessageS2CPacket(new LiteralText(context.getSource().getPlayer().getName().getString() + " te ha transferido ").append(MarkEnum.OTAKU_COIN.appendMessage(String.valueOf(amount)))));
        }
        return 1;
    })))));
}
Also used : LiteralText(net.minecraft.text.LiteralText) ShopExtension(com.kahzerx.kahzerxmod.extensions.shopExtension.ShopExtension) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) MarkEnum(com.kahzerx.kahzerxmod.utils.MarkEnum) UUID(java.util.UUID) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) CommandManager.argument(net.minecraft.server.command.CommandManager.argument) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CommandSource.suggestMatching(net.minecraft.command.CommandSource.suggestMatching) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) OverlayMessageS2CPacket(net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) OverlayMessageS2CPacket(net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ShopExtension (com.kahzerx.kahzerxmod.extensions.shopExtension.ShopExtension)1 MarkEnum (com.kahzerx.kahzerxmod.utils.MarkEnum)1 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)1 IntegerArgumentType (com.mojang.brigadier.arguments.IntegerArgumentType)1 StringArgumentType (com.mojang.brigadier.arguments.StringArgumentType)1 UUID (java.util.UUID)1 CommandSource.suggestMatching (net.minecraft.command.CommandSource.suggestMatching)1 OverlayMessageS2CPacket (net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket)1 CommandManager.argument (net.minecraft.server.command.CommandManager.argument)1 CommandManager.literal (net.minecraft.server.command.CommandManager.literal)1 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 LiteralText (net.minecraft.text.LiteralText)1