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;
})))));
}
Aggregations