2020-05-02 00:03:47 +02:00
|
|
|
From 76eaf0d523ba97558aa23fd1b744d9e70c9978d4 Mon Sep 17 00:00:00 2001
|
2016-03-18 05:29:35 +01:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Wed, 22 Jul 2015 18:50:41 -0400
|
|
|
|
Subject: [PATCH] Add sender name to commands.yml replacement
|
|
|
|
|
|
|
|
This allows you to use $sender in commands.yml definitions to make
|
|
|
|
commands that auto target self.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/command/FormattedCommandAlias.java b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
|
2020-04-02 23:07:06 +02:00
|
|
|
index a6ad94ef9..9d4f553c0 100644
|
2016-03-18 05:29:35 +01:00
|
|
|
--- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java
|
|
|
|
+++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
|
2019-04-23 06:47:07 +02:00
|
|
|
@@ -1,6 +1,9 @@
|
2017-11-08 17:13:57 +01:00
|
|
|
package org.bukkit.command;
|
2016-03-18 05:29:35 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2019-03-20 01:28:15 +01:00
|
|
|
+import java.util.regex.Matcher; // Paper
|
|
|
|
+import java.util.regex.Pattern; // Paper
|
2019-04-23 06:47:07 +02:00
|
|
|
+
|
2016-03-18 05:29:35 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2019-03-20 01:28:15 +01:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2019-04-23 06:47:07 +02:00
|
|
|
|
|
|
|
@@ -19,7 +22,7 @@ public class FormattedCommandAlias extends Command {
|
2016-03-18 05:29:35 +01:00
|
|
|
ArrayList<String> commands = new ArrayList<String>();
|
|
|
|
for (String formatString : formatStrings) {
|
|
|
|
try {
|
|
|
|
- commands.add(buildCommand(formatString, args));
|
|
|
|
+ commands.add(buildCommand(sender, formatString, args)); // Paper
|
|
|
|
} catch (Throwable throwable) {
|
|
|
|
if (throwable instanceof IllegalArgumentException) {
|
|
|
|
sender.sendMessage(throwable.getMessage());
|
2019-04-23 06:47:07 +02:00
|
|
|
@@ -37,7 +40,10 @@ public class FormattedCommandAlias extends Command {
|
2016-03-18 05:29:35 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-03-20 01:28:15 +01:00
|
|
|
- private String buildCommand(@NotNull String formatString, @NotNull String[] args) {
|
|
|
|
+ private String buildCommand(@NotNull CommandSender sender, @NotNull String formatString, @NotNull String[] args) { // Paper
|
2016-03-18 05:29:35 +01:00
|
|
|
+ if (formatString.contains("$sender")) { // Paper
|
|
|
|
+ formatString = formatString.replaceAll(Pattern.quote("$sender"), Matcher.quoteReplacement(sender.getName())); // Paper
|
|
|
|
+ } // Paper
|
2017-11-08 17:13:57 +01:00
|
|
|
int index = formatString.indexOf('$');
|
2016-03-18 05:29:35 +01:00
|
|
|
while (index != -1) {
|
|
|
|
int start = index;
|
|
|
|
--
|
2020-05-02 00:03:47 +02:00
|
|
|
2.26.2
|
2016-03-18 05:29:35 +01:00
|
|
|
|