mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
133 lines
7.1 KiB
Diff
133 lines
7.1 KiB
Diff
From ca4d608c6e987a44f467fae90f5bf036763ad3a4 Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
|
Date: Fri, 13 Mar 2020 22:29:10 -0500
|
|
Subject: [PATCH] Add /ping command
|
|
|
|
---
|
|
.../net/minecraft/server/ArgumentEntity.java | 2 ++
|
|
.../minecraft/server/CommandDispatcher.java | 5 ++-
|
|
.../server/CommandListenerWrapper.java | 1 +
|
|
.../net/pl3x/purpur/command/PingCommand.java | 34 +++++++++++++++++++
|
|
.../assets/minecraft/lang/en_us.json | 1 +
|
|
5 files changed, 42 insertions(+), 1 deletion(-)
|
|
create mode 100644 src/main/java/net/pl3x/purpur/command/PingCommand.java
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ArgumentEntity.java b/src/main/java/net/minecraft/server/ArgumentEntity.java
|
|
index 39a6a9ac00..5568649b7e 100644
|
|
--- a/src/main/java/net/minecraft/server/ArgumentEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/ArgumentEntity.java
|
|
@@ -69,10 +69,12 @@ public class ArgumentEntity implements ArgumentType<EntitySelector> {
|
|
return ((EntitySelector) commandcontext.getArgument(s, EntitySelector.class)).c((CommandListenerWrapper) commandcontext.getSource());
|
|
}
|
|
|
|
+ public static ArgumentEntity players() { return d(); } // Purpur - OBFHELPER
|
|
public static ArgumentEntity d() {
|
|
return new ArgumentEntity(false, true);
|
|
}
|
|
|
|
+ public static Collection<EntityPlayer> getPlayers(CommandContext<CommandListenerWrapper> commandcontext, String s) throws CommandSyntaxException { return f(commandcontext, s); } // Purpur - OBFHELPER
|
|
public static Collection<EntityPlayer> f(CommandContext<CommandListenerWrapper> commandcontext, String s) throws CommandSyntaxException {
|
|
List<EntityPlayer> list = ((EntitySelector) commandcontext.getArgument(s, EntitySelector.class)).d((CommandListenerWrapper) commandcontext.getSource());
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/CommandDispatcher.java b/src/main/java/net/minecraft/server/CommandDispatcher.java
|
|
index c9d1f94100..3b15f953bc 100644
|
|
--- a/src/main/java/net/minecraft/server/CommandDispatcher.java
|
|
+++ b/src/main/java/net/minecraft/server/CommandDispatcher.java
|
|
@@ -30,7 +30,7 @@ import org.bukkit.event.server.ServerCommandEvent;
|
|
public class CommandDispatcher {
|
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
- private final com.mojang.brigadier.CommandDispatcher<CommandListenerWrapper> b = new com.mojang.brigadier.CommandDispatcher();
|
|
+ private final com.mojang.brigadier.CommandDispatcher<CommandListenerWrapper> b = new com.mojang.brigadier.CommandDispatcher(); private com.mojang.brigadier.CommandDispatcher<CommandListenerWrapper> getDispatcher() { return b; } // Purpur - OBFHELPER
|
|
|
|
// CraftBukkit start
|
|
public final CommandDispatcher init(boolean flag) {
|
|
@@ -107,6 +107,7 @@ public class CommandDispatcher {
|
|
CommandStop.a(this.b);
|
|
CommandWhitelist.a(this.b);
|
|
net.pl3x.purpur.command.MSPTCommand.register(getDispatcher()); // Purpur
|
|
+ net.pl3x.purpur.command.PingCommand.register(getDispatcher()); // Purpur
|
|
}
|
|
|
|
this.b.findAmbiguities((commandnode, commandnode1, commandnode2, collection) -> {
|
|
@@ -316,10 +317,12 @@ public class CommandDispatcher {
|
|
|
|
}
|
|
|
|
+ public static LiteralArgumentBuilder<CommandListenerWrapper> register(String s) { return a(s); } // Purpur - OBFHELPER
|
|
public static LiteralArgumentBuilder<CommandListenerWrapper> a(String s) {
|
|
return LiteralArgumentBuilder.literal(s);
|
|
}
|
|
|
|
+ public static <T> RequiredArgumentBuilder<CommandListenerWrapper, T> argument(String s, ArgumentType<T> argumenttype) { return a(s, argumenttype); } // Purpur - OBFHELPER
|
|
public static <T> RequiredArgumentBuilder<CommandListenerWrapper, T> a(String s, ArgumentType<T> argumenttype) {
|
|
return RequiredArgumentBuilder.argument(s, argumenttype);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/CommandListenerWrapper.java b/src/main/java/net/minecraft/server/CommandListenerWrapper.java
|
|
index 0b23a0548d..ab0cf8b561 100644
|
|
--- a/src/main/java/net/minecraft/server/CommandListenerWrapper.java
|
|
+++ b/src/main/java/net/minecraft/server/CommandListenerWrapper.java
|
|
@@ -159,6 +159,7 @@ public class CommandListenerWrapper implements ICompletionProvider {
|
|
}
|
|
}
|
|
|
|
+ public EntityPlayer getPlayerOrException() throws CommandSyntaxException { return h(); } // Purpur - OBFHELPER
|
|
public EntityPlayer h() throws CommandSyntaxException {
|
|
if (!(this.k instanceof EntityPlayer)) {
|
|
throw CommandListenerWrapper.a.create();
|
|
diff --git a/src/main/java/net/pl3x/purpur/command/PingCommand.java b/src/main/java/net/pl3x/purpur/command/PingCommand.java
|
|
new file mode 100644
|
|
index 0000000000..3aea2a76db
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/command/PingCommand.java
|
|
@@ -0,0 +1,34 @@
|
|
+package net.pl3x.purpur.command;
|
|
+
|
|
+
|
|
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
+import net.minecraft.server.ArgumentEntity;
|
|
+import net.minecraft.server.ChatMessage;
|
|
+import net.minecraft.server.CommandDispatcher;
|
|
+import net.minecraft.server.CommandListenerWrapper;
|
|
+import net.minecraft.server.EntityPlayer;
|
|
+
|
|
+import java.util.Collection;
|
|
+import java.util.Collections;
|
|
+
|
|
+public class PingCommand {
|
|
+ public static void register(com.mojang.brigadier.CommandDispatcher<CommandListenerWrapper> dispatcher) {
|
|
+ dispatcher.register(CommandDispatcher.register("ping")
|
|
+ .requires((listener) -> {
|
|
+ return listener.hasPermission(2, "bukkit.command.ping");
|
|
+ })
|
|
+ .executes((context) -> {
|
|
+ return execute(context.getSource(), Collections.singleton(context.getSource().getPlayerOrException()));
|
|
+ })
|
|
+ .then(CommandDispatcher.argument("targets", ArgumentEntity.players()).executes((context) -> {
|
|
+ return execute(context.getSource(), ArgumentEntity.getPlayers(context, "targets"));
|
|
+ })));
|
|
+ }
|
|
+
|
|
+ private static int execute(CommandListenerWrapper sender, Collection<EntityPlayer> targets) throws CommandSyntaxException {
|
|
+ for (EntityPlayer player : targets) {
|
|
+ sender.sendMessage(new ChatMessage("commands.purpur.ping", player.getScoreboardDisplayName(), player.ping), false);
|
|
+ }
|
|
+ return targets.size();
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/resources/assets/minecraft/lang/en_us.json b/src/main/resources/assets/minecraft/lang/en_us.json
|
|
index 09816cedfc..e6b0c86b03 100644
|
|
--- a/src/main/resources/assets/minecraft/lang/en_us.json
|
|
+++ b/src/main/resources/assets/minecraft/lang/en_us.json
|
|
@@ -4073,6 +4073,7 @@
|
|
"commands.spectate.self": "Cannot spectate yourself",
|
|
"commands.purpur.mspt": "§6Server tick times §e(§7avg§e/§7min§e/§7max§e)§6 from last 5s§7,§6 10s§7,§6 1m§e:",
|
|
"commands.purpur.mspt.times": "§6◴ %s§7/%s§7/%s§e, %s§7/%s§7/%s§e, %s§7/%s§7/%s",
|
|
+ "commands.purpur.ping": "§a%s's ping is %sms",
|
|
"argument.range.empty": "Expected value or range of values",
|
|
"argument.range.ints": "Only whole numbers allowed, not decimals",
|
|
"argument.range.swapped": "Min cannot be bigger than max",
|
|
--
|
|
2.24.0
|
|
|