mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 17:18:37 +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>
|
<version>1.7</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.10.3</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc</groupId>
|
<groupId>io.papermc</groupId>
|
||||||
<artifactId>paperlib</artifactId>
|
<artifactId>paperlib</artifactId>
|
||||||
|
@ -7,7 +7,9 @@ import com.earth2me.essentials.User;
|
|||||||
import com.earth2me.essentials.utils.DateUtil;
|
import com.earth2me.essentials.utils.DateUtil;
|
||||||
import com.earth2me.essentials.utils.DescParseTickFormat;
|
import com.earth2me.essentials.utils.DescParseTickFormat;
|
||||||
import com.earth2me.essentials.utils.NumberUtil;
|
import com.earth2me.essentials.utils.NumberUtil;
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
|
import net.ess3.api.IUser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -33,6 +35,7 @@ public class KeywordReplacer implements IText {
|
|||||||
private transient ExecuteTimer execTimer;
|
private transient ExecuteTimer execTimer;
|
||||||
private final transient boolean replaceSpacesWithUnderscores;
|
private final transient boolean replaceSpacesWithUnderscores;
|
||||||
private final EnumMap<KeywordType, Object> keywordCache = new EnumMap<KeywordType, Object>(KeywordType.class);
|
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) {
|
public KeywordReplacer(final IText input, final CommandSource sender, final IEssentials ess) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
@ -73,14 +76,19 @@ public class KeywordReplacer implements IText {
|
|||||||
|
|
||||||
for (int i = 0; i < input.getLines().size(); i++) {
|
for (int i = 0; i < input.getLines().size(); i++) {
|
||||||
String line = input.getLines().get(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()) {
|
while (matcher.find()) {
|
||||||
final String fullMatch = matcher.group(0);
|
final String fullMatch = matcher.group(0);
|
||||||
final String keywordMatch = matcher.group(1);
|
final String keywordMatch = matcher.group(1);
|
||||||
final String[] matchTokens = KEYWORDSPLIT.split(keywordMatch);
|
final String[] matchTokens = KEYWORDSPLIT.split(keywordMatch);
|
||||||
line = replaceLine(line, fullMatch, matchTokens, user);
|
line = replaceLine(line, fullMatch, matchTokens, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace PlaceholderAPI placeholders if applicable
|
||||||
|
line = replacePAPI(ess, sender, line);
|
||||||
|
|
||||||
replaced.add(line);
|
replaced.add(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +298,18 @@ public class KeywordReplacer implements IText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
line = line.replace(fullMatch, replacer);
|
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;
|
return line;
|
||||||
|
@ -5,7 +5,7 @@ main: com.earth2me.essentials.Essentials
|
|||||||
version: ${full.version}
|
version: ${full.version}
|
||||||
website: http://tiny.cc/EssentialsCommands
|
website: http://tiny.cc/EssentialsCommands
|
||||||
description: Provides an essential, core set of commands for Bukkit.
|
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]
|
authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits, md_5, Iaccidentally, drtshock, vemacs, SupaHam, md678685]
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
commands:
|
commands:
|
||||||
|
4
pom.xml
4
pom.xml
@ -35,6 +35,10 @@
|
|||||||
<id>paper-repo</id>
|
<id>paper-repo</id>
|
||||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>papi-repo</id>
|
||||||
|
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
Loading…
Reference in New Issue
Block a user