mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 09:08:01 +01:00
Add PAPI support to KeywordReplacer
PlaceholderAPI placeholders are now supported in: * Kits * Text commands (/customtext, /help, /motd etc.) * [info] signs * EssentialsX Spawn welcome messages
This commit is contained in:
parent
edaa4f6978
commit
395cc2a13c
@ -54,6 +54,12 @@
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.10.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
|
@ -7,7 +7,9 @@ import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.DescParseTickFormat;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -33,6 +35,7 @@ public class KeywordReplacer implements IText {
|
||||
private transient ExecuteTimer execTimer;
|
||||
private final transient boolean replaceSpacesWithUnderscores;
|
||||
private final EnumMap<KeywordType, Object> keywordCache = new EnumMap<KeywordType, Object>(KeywordType.class);
|
||||
private static Boolean isPAPIAvailable;
|
||||
|
||||
public KeywordReplacer(final IText input, final CommandSource sender, final IEssentials ess) {
|
||||
this.input = input;
|
||||
@ -73,14 +76,19 @@ public class KeywordReplacer implements IText {
|
||||
|
||||
for (int i = 0; i < input.getLines().size(); i++) {
|
||||
String line = input.getLines().get(i);
|
||||
final Matcher matcher = KEYWORD.matcher(line);
|
||||
|
||||
// Replace in-built keywords
|
||||
final Matcher matcher = KEYWORD.matcher(line);
|
||||
while (matcher.find()) {
|
||||
final String fullMatch = matcher.group(0);
|
||||
final String keywordMatch = matcher.group(1);
|
||||
final String[] matchTokens = KEYWORDSPLIT.split(keywordMatch);
|
||||
line = replaceLine(line, fullMatch, matchTokens, user);
|
||||
}
|
||||
|
||||
// Replace PlaceholderAPI placeholders if applicable
|
||||
line = replacePAPI(ess, sender, line);
|
||||
|
||||
replaced.add(line);
|
||||
}
|
||||
|
||||
@ -290,7 +298,18 @@ public class KeywordReplacer implements IText {
|
||||
}
|
||||
|
||||
line = line.replace(fullMatch, replacer);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
private static String replacePAPI(final IEssentials ess, CommandSource source, String line) {
|
||||
if (isPAPIAvailable == null) {
|
||||
isPAPIAvailable = ess.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||
}
|
||||
|
||||
if (isPAPIAvailable && source.isPlayer()) {
|
||||
line = PlaceholderAPI.setPlaceholders(source.getPlayer(), line);
|
||||
}
|
||||
|
||||
return line;
|
||||
|
@ -5,7 +5,7 @@ main: com.earth2me.essentials.Essentials
|
||||
version: ${full.version}
|
||||
website: http://tiny.cc/EssentialsCommands
|
||||
description: Provides an essential, core set of commands for Bukkit.
|
||||
softdepend: [Vault]
|
||||
softdepend: [Vault, PlaceholderAPI]
|
||||
authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits, md_5, Iaccidentally, drtshock, vemacs, SupaHam, md678685]
|
||||
api-version: 1.13
|
||||
commands:
|
||||
|
Loading…
Reference in New Issue
Block a user