PaperMC/Spigot-API-Patches/0024-Add-sender-name-to-commands.yml-replacement.patch
Spottedleaf 5c7081fecc Update upstream & fix some chunk related issues (#2177)
* Updated Upstream (Bukkit/CraftBukkit)

Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
45690fe9 SPIGOT-5047: Correct slot types for 1.14 inventories

CraftBukkit Changes:
4090d01f SPIGOT-5047: Correct slot types for 1.14 inventories
e8c08362 SPIGOT-5046: World#getLoadedChunks returning inaccessible cached chunks.
d445af3b SPIGOT-5067: Add item meta for 1.14 spawn eggs

* Bring Chunk load checks in-line with spigot

As of the last upstream merge spigot now checks ticket level status
when returning loaded chunks for a world from api. Now our checks
will respect that decision.

* Fix spawn ticket levels

Vanilla would keep the inner chunks of spawn available for ticking,
however my changes made all chunks non-ticking. Resolve by changing
ticket levels for spawn chunks inside the border to respect this
behavior.


* Make World#getChunkIfLoadedImmediately return only entity ticking chunks

Mojang appears to be using chunks with level > 33 (non-ticking chunks)
as cached chunks and not actually loaded chunks.

* Bring all loaded checks in line with spigot

Loaded chunks must be at least border  chunks, or level <= 33
2019-06-14 03:27:40 +01:00

46 lines
2 KiB
Diff

From 7aa10c0e4606c992367eaed629d6362f46234744 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 a6ad94ef9..9d4f553c0 100644
--- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java
+++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
@@ -1,6 +1,9 @@
package org.bukkit.command;
import java.util.ArrayList;
+import java.util.regex.Matcher; // Paper
+import java.util.regex.Pattern; // Paper
+
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
@@ -19,7 +22,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());
@@ -37,7 +40,10 @@ public class FormattedCommandAlias extends Command {
return result;
}
- private String buildCommand(@NotNull String formatString, @NotNull String[] args) {
+ private String buildCommand(@NotNull CommandSender sender, @NotNull String formatString, @NotNull 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.21.0