From d91434be7102b84ed87fe5851d22d7801f9618fb Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Mon, 13 Oct 2025 14:43:47 +0200 Subject: feat(commands): get hearts for operators --- README.md | 6 +++++- src/main/java/world/anhgelus/lifesteal/Commands.java | 18 ++++++++++++++++++ src/main/java/world/anhgelus/lifesteal/LifeSteal.java | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e187771..152cdd6 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ LifeSteal is a server-side mod recreating the LifeSteal SMP experience. +Players can withdraw hearts with `/withdraw `. + The number of maximum hearts can be set via the gamerule `lifesteal:maxHearts` (default: 20). The grace period is the period when the PvP is deactivated. @@ -13,4 +15,6 @@ Hearts cannot be crafted by a player at/above 10 hearts. You can disable this via the gamerule `lifesteal:canCraftHeartsAboveVanillaMax` (default: false). Hearts cannot be stored in ender chests. -You can disable this via the gamerule `lifesteal:canStoreHeartsInEC` (default: false). \ No newline at end of file +You can disable this via the gamerule `lifesteal:canStoreHeartsInEC` (default: false). + +Operators can use `/gethearts ` to get hearts. \ No newline at end of file diff --git a/src/main/java/world/anhgelus/lifesteal/Commands.java b/src/main/java/world/anhgelus/lifesteal/Commands.java index 5bf10c5..6accf8d 100644 --- a/src/main/java/world/anhgelus/lifesteal/Commands.java +++ b/src/main/java/world/anhgelus/lifesteal/Commands.java @@ -34,4 +34,22 @@ public class Commands { dispatcher.register(cmd); } + + public static void registerGetHearts(CommandDispatcher dispatcher) { + final var cmd = literal("gethearts") + .requires(s -> s.hasPermissionLevel(3)) + .then(argument("hearts", IntegerArgumentType.integer(1)) + .executes(context -> { + final var source = context.getSource(); + final var hearts = IntegerArgumentType.getInteger(context, "hearts"); + final var p = source.getPlayerOrThrow(); + final var lifeStealer = LifeStealer.Manager.getLifeStealer(p); + p.giveOrDropStack(lifeStealer.getHeart().copyWithCount(hearts)); + source.sendFeedback(() -> Text.of("Hearts given."), false); + return Command.SINGLE_SUCCESS; + }) + ); + + dispatcher.register(cmd); + } } diff --git a/src/main/java/world/anhgelus/lifesteal/LifeSteal.java b/src/main/java/world/anhgelus/lifesteal/LifeSteal.java index cc1b4eb..7fb5b33 100644 --- a/src/main/java/world/anhgelus/lifesteal/LifeSteal.java +++ b/src/main/java/world/anhgelus/lifesteal/LifeSteal.java @@ -78,6 +78,7 @@ public class LifeSteal implements ModInitializer { CommandRegistrationCallback.EVENT.register((CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) -> { Commands.registerWithdraw(dispatcher); + Commands.registerGetHearts(dispatcher); }); ServerLifecycleEvents.SERVER_STARTED.register(server -> { -- cgit v1.2.3