Skip to content

Commit

Permalink
1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus committed May 5, 2020
1 parent eefac53 commit e2991be
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ repositories {
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT'
compileOnly 'com.github.SkriptLang:Skript:2.3'
compileOnly 'me.clip:placeholderapi:2.10.4'
compileOnly 'me.clip:placeholderapi:2.10.6'
compileOnly('be.maximvdw:MVdWPlaceholderAPI:3.0.1-SNAPSHOT') {
exclude group: 'org.spigotmc'
}
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
//compileOnly fileTree(dir: 'libs', include: '*.jar')
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,40 @@
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import io.github.apickledwalrus.placeholderaddon.Main;
import me.clip.placeholderapi.PlaceholderAPI;

import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;

import java.util.ArrayList;
import java.util.List;

@Name("Value of Placeholder")
@Description("Returns the value of a PlaceholderAPI/MVdWPlaceholderAPI placeholder.")
@Description({"Returns the value of a PlaceholderAPI/MVdWPlaceholderAPI placeholder.",
"Note: The 'without color' option is only applicable for PlaceholderAPI placeholders."})
@Examples({"command /ping <player>:",
"\ttrigger:",
"\t\tset {_ping} to placeholder \"player_ping\" from arg-1 # PlaceholderAPI",
"\t\tset {_ping} to placeholder \"{ping}\" from arg-1 # MVdWPlaceholderAPI",
"\t\tsend \"Ping of %arg-1%: %{_ping}%\" to player"})
@Since("1.0 - PAPI Placeholders, 1.2 - MVdW Placeholders, 1.3 - Updated Syntax")
@Since("1.0 - PAPI Placeholders, 1.2 - MVdW Placeholders, 1.3 - Updated Syntax, 1.4 - Colorize Option")
public class ExprParsePlaceholder extends SimpleExpression<String> {

static {
Skript.registerExpression(ExprParsePlaceholder.class, String.class, ExpressionType.SIMPLE,
"[the] ([value of] placeholder[s]|placeholder [value] [of]) %strings% [from %players%]",
"parse placeholder[s] %strings% [(for|as) %players%]");
"[the] ([value of] placeholder[s]|placeholder [value] [of]) %strings% [from %-players/offlineplayers%] [(1¦without color)]",
"parse placeholder[s] %strings% [(for|as) %-players/offlineplayers%] [(1¦without color)]");
}

private Expression<String> placeholders;
private Expression<Player> players;
private Expression<OfflinePlayer> players;

private boolean colorize;

private String formatPlaceholder(String placeholder) {
if (placeholder == null) {
Expand All @@ -50,44 +55,50 @@ private String formatPlaceholder(String placeholder) {
return "%" + placeholder + "%";
}

private String getPlaceholder(String placeholder, Player player) {
private String getPlaceholder(String placeholder, OfflinePlayer player) {
String value;

if (Main.hasMVdW()) {
if (placeholder.charAt(0) == '{' && placeholder.charAt(placeholder.length() - 1) == '}') {
value = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, placeholder);
if (value.equals(placeholder)) // MVdW placeholders return the input if no MVdW plugins are installed.
return null;
return value;
return value.equals(placeholder) ? null : value;
}
}

if (Main.hasPapi()) {
placeholder = formatPlaceholder(placeholder);
if (PlaceholderAPI.containsPlaceholders(placeholder)) {
value = PlaceholderAPI.setPlaceholders(player, placeholder);
if (value == null || value.equals(placeholder))
return null;
return value;

if (player != null && player.isOnline()) {
value = PlaceholderAPI.setPlaceholders((Player) player, placeholder, !colorize);
} else {
value = PlaceholderAPI.setPlaceholders(player, placeholder, !colorize);
}

return value.equals(placeholder) ? null : value;
}
}

return null;
}

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
placeholders = (Expression<String>) exprs[0];
players = (Expression<Player>) exprs[1];
players = (Expression<OfflinePlayer>) exprs[1];
colorize = parseResult.mark == 1;
return true;
}

@Override
protected String[] get(final Event e) {
String[] placeholders = this.placeholders.getArray(e);
Player[] players = this.players.getArray(e);
OfflinePlayer[] players = this.players.getArray(e);
List<String> values = new ArrayList<>();
if (players.length != 0) {
for (String pl : placeholders) {
for (Player p : players) {
for (OfflinePlayer p : players) {
values.add(getPlaceholder(pl, p));
}
}
Expand All @@ -101,7 +112,7 @@ protected String[] get(final Event e) {

@Override
public boolean isSingle() {
return placeholders.isSingle() && players.isSingle();
return players != null ? (placeholders.isSingle() && players.isSingle()) : placeholders.isSingle();
}

@Override
Expand All @@ -111,7 +122,7 @@ public Class<? extends String> getReturnType() {

@Override
public String toString(Event e, boolean debug) {
return "the value of placeholder " + placeholders.toString(e, debug) + " from " + players.toString(e, debug);
return "the value of placeholder(s) " + placeholders.toString(e, debug) + " from " + players.toString(e, debug);
}

}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: skript-placeholders
main: io.github.apickledwalrus.placeholderaddon.Main
version: 1.3.1
version: 1.4
authors: [Pikachu, APickledWalrus]
description: Allows using and registering placeholders with PlaceholderAPI and MVdWPlaceholderAPI in Skript.
website: https://github.com/APickledWalrus/skript-placeholders
Expand Down

0 comments on commit e2991be

Please sign in to comment.