mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 17:07:43 +01:00
Upstream has released updates that appears to apply and compile correctly Paper Changes: b75eeca0 Boost light task priority to ensure it doesnt hold up chunk loads 3d2bc848 Ensure VillagerTrades doesn't load async - fixes #3495 e470f1ef Add more information to Timing Reports f4a47db6 Improve Thread Pool usage to allow single threads for single cpu servers a4fe910f Fix sounds when using worldedit regen command 70ad51a8 Updated Upstream (Bukkit/CraftBukkit) d7cfa4fa Improve legacy format serialization more
131 lines
6.6 KiB
Diff
131 lines
6.6 KiB
Diff
From adb43d0023fe0bc1e3fbb46cf03f342b13c8a7b3 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 | 33 +++++++++++++++++++
|
|
src/main/resources/purpur.lang | 1 +
|
|
5 files changed, 41 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 2d512aa4f9..5aa10d16bc 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) {
|
|
@@ -106,6 +106,7 @@ public class CommandDispatcher {
|
|
CommandIdleTimeout.a(this.b);
|
|
CommandStop.a(this.b);
|
|
CommandWhitelist.a(this.b);
|
|
+ net.pl3x.purpur.command.PingCommand.register(getDispatcher()); // Purpur
|
|
}
|
|
|
|
this.b.findAmbiguities((commandnode, commandnode1, commandnode2, collection) -> {
|
|
@@ -332,10 +333,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 c988c929f1..5c980b70cd 100644
|
|
--- a/src/main/java/net/minecraft/server/CommandListenerWrapper.java
|
|
+++ b/src/main/java/net/minecraft/server/CommandListenerWrapper.java
|
|
@@ -178,6 +178,7 @@ public class CommandListenerWrapper implements ICompletionProvider, com.destroys
|
|
}
|
|
}
|
|
|
|
+ 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..dac3083bf0
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/command/PingCommand.java
|
|
@@ -0,0 +1,33 @@
|
|
+package net.pl3x.purpur.command;
|
|
+
|
|
+import net.minecraft.server.ArgumentEntity;
|
|
+import net.minecraft.server.CommandDispatcher;
|
|
+import net.minecraft.server.CommandListenerWrapper;
|
|
+import net.minecraft.server.EntityPlayer;
|
|
+import net.minecraft.server.LocaleLanguage;
|
|
+
|
|
+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);
|
|
+ })
|
|
+ .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"));
|
|
+ }))
|
|
+ ).setPermission("bukkit.command.ping");
|
|
+ }
|
|
+
|
|
+ private static int execute(CommandListenerWrapper sender, Collection<EntityPlayer> targets) {
|
|
+ for (EntityPlayer player : targets) {
|
|
+ sender.sendMessage(LocaleLanguage.translate("commands.purpur.ping", player.getScoreboardDisplayName(), player.ping), false);
|
|
+ }
|
|
+ return targets.size();
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/resources/purpur.lang b/src/main/resources/purpur.lang
|
|
index e925e1374d..e81beea7fa 100644
|
|
--- a/src/main/resources/purpur.lang
|
|
+++ b/src/main/resources/purpur.lang
|
|
@@ -1,5 +1,6 @@
|
|
{
|
|
"cannot.ride.mob": "You cannot mount that mob",
|
|
+ "commands.purpur.ping": "§a%s's ping is %sms",
|
|
"idle.timeout.broadcast.away": "§e§o%s is now AFK",
|
|
"idle.timeout.broadcast.back": "§e§o%s is no longer AFK"
|
|
}
|
|
--
|
|
2.24.0
|
|
|