aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-API-Patches/0026-Add-sender-name-to-commands.yml-replacement.patch
blob: 26a3c3334fc182f01300c8ff06a7a3de008308cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From 21d5ec9b192521a3502ad03fdc32d217651ab129 Mon Sep 17 00:00:00 2001
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
index f89ad07..a3e9c63 100644
--- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java
+++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
@@ -2,6 +2,8 @@ package org.bukkit.command;
 
 import java.util.ArrayList;
 import java.util.logging.Level;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.bukkit.Bukkit;
 import org.bukkit.entity.Player;
@@ -24,7 +26,7 @@ public class FormattedCommandAlias extends Command {
         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());
@@ -42,7 +44,10 @@ public class FormattedCommandAlias extends Command {
         return result;
     }
 
-    private String buildCommand(String formatString, String[] args) {
+    private String buildCommand(CommandSender sender, String formatString, String[] args) { // Paper
+        if (formatString.contains("$sender")) { // Paper
+            formatString = formatString.replaceAll(Pattern.quote("$sender"), Matcher.quoteReplacement(sender.getName())); // Paper
+        } // Paper
         int index = formatString.indexOf("$");
         while (index != -1) {
             int start = index;
-- 
2.8.0