/gc, /heal
This commit is contained in:
@@ -1,122 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: AlphaKR93 <dev@alpha93.kr>
|
||||
Date: Wed, 25 Dec 2024 19:07:19 +0900
|
||||
Subject: [PATCH] Add heal command
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
|
||||
index c416b1eaf27699de59aaa6b352ff1aa991d3f660..90ecfc550324521a7aece274bab330f8dc2de3f3 100644
|
||||
--- a/src/main/java/net/minecraft/commands/Commands.java
|
||||
+++ b/src/main/java/net/minecraft/commands/Commands.java
|
||||
@@ -180,6 +180,7 @@ public class Commands {
|
||||
org.purpurmc.purpur.command.CompassCommand.register(this.dispatcher); // Purpur
|
||||
org.purpurmc.purpur.command.RamBarCommand.register(this.dispatcher); // Purpur - Implement ram and rambar commands
|
||||
org.purpurmc.purpur.command.RamCommand.register(this.dispatcher); // Purpur - Implement ram and rambar commands
|
||||
+ org.plazmamc.plazma.commands.HealCommand.register(this.dispatcher); // Plazma - Add heal command
|
||||
}
|
||||
|
||||
if (environment.includeIntegrated) {
|
||||
diff --git a/src/main/java/org/plazmamc/plazma/commands/HealCommand.java b/src/main/java/org/plazmamc/plazma/commands/HealCommand.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..b10725af7ec4433e98557cfbafb563822cd4f908
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/plazmamc/plazma/commands/HealCommand.java
|
||||
@@ -0,0 +1,66 @@
|
||||
+package org.plazmamc.plazma.commands;
|
||||
+
|
||||
+import com.mojang.brigadier.CommandDispatcher;
|
||||
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
+import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
+import io.papermc.paper.adventure.PaperAdventure;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import net.kyori.adventure.text.TextComponent;
|
||||
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
+import net.minecraft.commands.CommandSourceStack;
|
||||
+import net.minecraft.commands.Commands;
|
||||
+import net.minecraft.commands.arguments.EntityArgument;
|
||||
+import net.minecraft.world.entity.Entity;
|
||||
+import net.minecraft.world.entity.LivingEntity;
|
||||
+import net.minecraft.world.entity.player.Player;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+import org.jetbrains.annotations.Contract;
|
||||
+import org.plazmamc.plazma.configurations.GlobalConfiguration;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.Collection;
|
||||
+import java.util.Collections;
|
||||
+
|
||||
+import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public class HealCommand {
|
||||
+
|
||||
+ public static void register(final CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
+ dispatcher.register(Commands.literal("heal")
|
||||
+ .requires(source -> source.hasPermission(2, "bukkit.command.heal"))
|
||||
+ .executes(ctx -> execute(ctx.getSource(), Collections.singleton(ctx.getSource().getEntityOrException())))
|
||||
+ .then(Commands.argument("targets", EntityArgument.entities())
|
||||
+ .requires(source -> source.hasPermission(3, "bukkit.command.heal.others"))
|
||||
+ .executes(ctx -> execute(ctx.getSource(), EntityArgument.getEntities(ctx, "targets")))
|
||||
+ )
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ @Contract(pure = true)
|
||||
+ private static int execute(final CommandSourceStack sender, Collection<? extends Entity> targets) throws CommandSyntaxException {
|
||||
+ final ArrayList<Component> success = new ArrayList<>();
|
||||
+
|
||||
+ for (Entity target : targets) {
|
||||
+ if (!(target instanceof LivingEntity entity)) continue;
|
||||
+ if (entity.isDeadOrDying()) continue;
|
||||
+
|
||||
+ entity.heal(entity.getMaxHealth());
|
||||
+ success.add(PaperAdventure.asAdventure(entity.getDisplayName()));
|
||||
+
|
||||
+ if (!(entity instanceof Player player)) continue;
|
||||
+ player.getFoodData().setFoodLevel(20);
|
||||
+ player.getFoodData().setSaturation(5.0F);
|
||||
+ }
|
||||
+
|
||||
+ if (success.isEmpty()) {
|
||||
+ throw new SimpleCommandExceptionType(PaperAdventure.asVanilla(miniMessage().deserialize(GlobalConfiguration.get().messages.heal.noTargets))).create();
|
||||
+ }
|
||||
+
|
||||
+ final Component successJoined = success.stream().reduce((a, b) -> a.append(Component.text(", ").append(b))).orElseThrow();
|
||||
+
|
||||
+ sender.sendSuccess(miniMessage().deserialize(GlobalConfiguration.get().messages.heal.healed, Placeholder.component("targets", successJoined)));
|
||||
+ return success.size();
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
||||
index 898f9e6ec6f306a15639ee0d03bcfe7bf55e2c6c..02a164ff2c855864e246dcaaf8186274421edea7 100644
|
||||
--- a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
||||
+++ b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
||||
@@ -31,6 +31,13 @@ public class GlobalConfiguration extends ConfigurationPart {
|
||||
public Messages messages;
|
||||
public class Messages extends ConfigurationPart {
|
||||
|
||||
+ public Heal heal;
|
||||
+ public class Heal extends ConfigurationPart {
|
||||
+
|
||||
+ public String healed = "Healed %s";
|
||||
+ public String noTargets = "No targets matched selector";
|
||||
+
|
||||
+ }
|
||||
|
||||
}
|
||||
|
||||
diff --git a/src/test/java/io/papermc/paper/permissions/MinecraftCommandPermissionsTest.java b/src/test/java/io/papermc/paper/permissions/MinecraftCommandPermissionsTest.java
|
||||
index 180c0a532bbac10a8280b63eb7aa783a1bfbb237..75ddd1a811d0a07c6fe5431a527b3a74e52ad53a 100644
|
||||
--- a/src/test/java/io/papermc/paper/permissions/MinecraftCommandPermissionsTest.java
|
||||
+++ b/src/test/java/io/papermc/paper/permissions/MinecraftCommandPermissionsTest.java
|
||||
@@ -78,7 +78,8 @@ public class MinecraftCommandPermissionsTest {
|
||||
"minecraft.command.gamemode.survival",
|
||||
"minecraft.command.gamemode.survival.other",
|
||||
// Purpur end
|
||||
- "minecraft.command.selector"
|
||||
+ "minecraft.command.selector",
|
||||
+ "minecraft.command.heal" // Plazma
|
||||
);
|
||||
|
||||
private static Set<String> collectMinecraftCommandPerms() {
|
||||
@@ -101,3 +101,12 @@
|
||||
if (selection.includeDedicated) {
|
||||
DebugConfigCommand.register(this.dispatcher);
|
||||
}
|
||||
@@ -258,6 +_,8 @@
|
||||
org.purpurmc.purpur.command.CompassCommand.register(this.dispatcher); // Purpur - Add compass command
|
||||
org.purpurmc.purpur.command.RamBarCommand.register(this.dispatcher); // Purpur - Add rambar command
|
||||
org.purpurmc.purpur.command.RamCommand.register(this.dispatcher); // Purpur - Add ram command
|
||||
+ org.plazmamc.plazma.command.HealCommand.register(this.dispatcher); // Plazma - Add heal command
|
||||
+ org.plazmamc.plazma.command.GCCommand.register(this.dispatcher); // Plazma - Add gc command
|
||||
}
|
||||
|
||||
if (selection.includeIntegrated) {
|
||||
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Completely remove Timings
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
||||
index 7ce9ebba8ce304d1f3f21d4f15ee5f3560d7700b..7db570ec86a18566131f2df61a64971510fad2ba 100644
|
||||
index 18ea722b693bf3ee526a2aea54237cf05afc10d2..5315ab035fe4501812ccefa13189b9a4c086d48e 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
||||
@@ -1,6 +1,6 @@
|
||||
@@ -16,7 +16,7 @@ index 7ce9ebba8ce304d1f3f21d4f15ee5f3560d7700b..7db570ec86a18566131f2df61a649715
|
||||
import com.destroystokyo.paper.event.server.ServerExceptionEvent;
|
||||
import com.destroystokyo.paper.exception.ServerEventException;
|
||||
import com.google.common.collect.Sets;
|
||||
@@ -95,7 +95,7 @@ class PaperEventManager {
|
||||
@@ -97,7 +97,7 @@ class PaperEventManager {
|
||||
throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled");
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ index 7ce9ebba8ce304d1f3f21d4f15ee5f3560d7700b..7db570ec86a18566131f2df61a649715
|
||||
this.getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
|
||||
}
|
||||
|
||||
@@ -182,8 +182,8 @@ class PaperEventManager {
|
||||
@@ -184,8 +184,8 @@ class PaperEventManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
--- a/src/test/java/io/papermc/paper/permissions/MinecraftCommandPermissionsTest.java
|
||||
+++ b/src/test/java/io/papermc/paper/permissions/MinecraftCommandPermissionsTest.java
|
||||
@@ -78,6 +_,13 @@
|
||||
"minecraft.command.gamemode.survival",
|
||||
"minecraft.command.gamemode.survival.other",
|
||||
// Purpur end - Skip junit tests for purpur commands
|
||||
+
|
||||
+ // Plazma start - Skip junit tests for plazma commands
|
||||
+ "minecraft.command.gc",
|
||||
+ "minecraft.command.heal",
|
||||
+ "minecraft.command.heal.other",
|
||||
+ // Plazma end - Skip junit tests for plazma commands
|
||||
+
|
||||
"minecraft.command.selector"
|
||||
);
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
--- a/src/main/java/org/purpurmc/purpur/command/CompassCommand.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/command/CompassCommand.java
|
||||
@@ -6,7 +_,7 @@
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.purpurmc.purpur.task.CompassTask;
|
||||
|
||||
-public class CompassCommand {
|
||||
+public interface CompassCommand { // Plazma
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(Commands.literal("compass")
|
||||
.requires(listener -> listener.hasPermission(2, "bukkit.command.compass"))
|
||||
@@ -22,6 +_,24 @@
|
||||
}
|
||||
return 1;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/src/main/java/org/purpurmc/purpur/command/RamCommand.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/command/RamCommand.java
|
||||
@@ -9,7 +_,7 @@
|
||||
import org.purpurmc.purpur.PurpurConfig;
|
||||
import org.purpurmc.purpur.task.RamBarTask;
|
||||
|
||||
-public class RamCommand {
|
||||
+public interface RamCommand { // Plazma
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(Commands.literal("ram")
|
||||
.requires(listener -> listener.hasPermission(2, "bukkit.command.ram"))
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.plazmamc.plazma.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.plazmamc.plazma.Options;
|
||||
|
||||
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
|
||||
|
||||
public interface GCCommand {
|
||||
|
||||
static void register(final @NonNull CommandDispatcher<@NonNull CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(Commands.literal("gc")
|
||||
.requires(source -> source.hasPermission(4, "bukkit.command.gc"))
|
||||
.executes(source -> {
|
||||
System.gc();
|
||||
source.getSource().sendSuccess(miniMessage().deserialize(Options.global().messages.runGc), true);
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.plazmamc.plazma.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.plazmamc.plazma.Options;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
|
||||
|
||||
public final class HealCommand {
|
||||
|
||||
@Contract(value = " -> fail", pure = true)
|
||||
private HealCommand() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static void register(final @NonNull CommandDispatcher<@NonNull CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(Commands.literal("heal")
|
||||
.requires(source -> source.hasPermission(2, "bukkit.command.heal"))
|
||||
.executes(ctx -> execute(ctx.getSource(), Collections.singleton(ctx.getSource().getEntityOrException())))
|
||||
.then(Commands.argument("targets", EntityArgument.entities())
|
||||
.requires(source -> source.hasPermission(3, "bukkit.command.heal.others"))
|
||||
.executes(ctx -> execute(ctx.getSource(), EntityArgument.getEntities(ctx, "targets")))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
private static int execute(final @NonNull CommandSourceStack sender, final @NonNull Collection<? extends Entity> targets) throws CommandSyntaxException {
|
||||
final ArrayList<Component> success = new ArrayList<>();
|
||||
|
||||
for (Entity target : targets) {
|
||||
if (!(target instanceof LivingEntity entity)) continue;
|
||||
if (entity.isDeadOrDying()) continue;
|
||||
|
||||
entity.heal(entity.getMaxHealth());
|
||||
success.add(PaperAdventure.asAdventure(entity.getDisplayName()));
|
||||
|
||||
if (!(entity instanceof Player player)) continue;
|
||||
player.getFoodData().setFoodLevel(20);
|
||||
player.getFoodData().setSaturation(5.0F);
|
||||
}
|
||||
|
||||
if (success.isEmpty()) {
|
||||
throw new SimpleCommandExceptionType(PaperAdventure.asVanilla(miniMessage().deserialize(Options.global().messages.heal.noTargets))).create();
|
||||
}
|
||||
|
||||
final Component successJoined = success.stream().reduce((a, b) -> a.append(Component.text(", ").append(b))).orElseThrow();
|
||||
|
||||
sender.sendSuccess(miniMessage().deserialize(Options.global().messages.heal.healed, Placeholder.component("targets", successJoined)));
|
||||
return success.size();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,6 +39,21 @@ public final class GlobalConfiguration extends ConfigurationPart {
|
||||
|
||||
}
|
||||
|
||||
public Messages messages;
|
||||
public class Messages extends ConfigurationPart {
|
||||
|
||||
public String runGc = "Executed garbage collectors";
|
||||
|
||||
public Heal heal;
|
||||
public class Heal extends ConfigurationPart {
|
||||
|
||||
public String healed = "Healed <targets>";
|
||||
public String noTargets = "No targets matched selector";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ConsoleLogs consoleLogs;
|
||||
public class ConsoleLogs extends ConfigurationPart {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user