Skip to content

Commit

Permalink
Gradle and formatting tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus committed May 23, 2024
1 parent d1e76de commit b0287eb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ plugins {
id 'java'
}

group 'io.github.apickledwalrus'
version '1.6.0'

compileJava.options.encoding = 'UTF-8'

java {
Expand Down
6 changes: 6 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ensure formatting is consistent across systems.
org.gradle.jvmargs=-Dfile.encoding=UTF-8

groupid=io.github.apickledwalrus
name=skript-placeholders
version=1.7.0
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum PlaceholderPlugin {
private final char[] illegalCharacters = new char[]{'%', '{', '}', '_'};

@Override
public @Nullable String isValidPrefix(String prefix) {
public @Nullable String validatePrefix(String prefix) {
if (StringUtils.isBlank(prefix)) {
return "A prefix cannot be blank";
}
Expand All @@ -42,18 +42,23 @@ public PlaceholderListener registerPlaceholder(PlaceholderEvaluator evaluator, S

@Override
public @Nullable String parsePlaceholder(String placeholder, @Nullable OfflinePlayer player) {
if (placeholder.indexOf('%') == -1) // Try to add percentage signs manually
if (placeholder.indexOf('%') == -1) { // Try to add percentage signs manually
placeholder = "%" + placeholder + "%";
}
String value = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, placeholder);
if (value.isEmpty() || value.equalsIgnoreCase(placeholder))
if (value.isEmpty() || value.equalsIgnoreCase(placeholder)) {
return null;
}
return value;
}
},
MVDW_PLACEHOLDER_API("MVdWPlaceholderAPI", Skript.classExists("be.maximvdw.placeholderapi.PlaceholderAPI")) {
@Override
public @Nullable String isValidPrefix(String prefix) {
return StringUtils.isBlank(prefix) ? "A placeholder cannot be blank" : null;
public @Nullable String validatePrefix(String prefix) {
if (StringUtils.isBlank(prefix)) {
return "A placeholder cannot be blank";
}
return null;
}

@Override
Expand All @@ -67,8 +72,9 @@ public PlaceholderListener registerPlaceholder(PlaceholderEvaluator evaluator, S
public @Nullable String parsePlaceholder(String placeholder, @Nullable OfflinePlayer player) {
if (placeholder.charAt(0) == '{' && placeholder.charAt(placeholder.length() - 1) == '}') {
String value = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, placeholder);
if (value.isEmpty() || value.equalsIgnoreCase(placeholder))
if (value.isEmpty() || value.equalsIgnoreCase(placeholder)) {
return null;
}
return value;
}
return null;
Expand Down Expand Up @@ -110,9 +116,9 @@ public final boolean isInstalled() {

/**
* @param prefix The prefix to validate.
* @return Null, or an error message detailing why the prefix is invalid.
* @return Null if the prefix is valid, or an error message detailing why the prefix is invalid.
*/
public abstract @Nullable String isValidPrefix(String prefix);
public abstract @Nullable String validatePrefix(String prefix);

/**
* Registers a new placeholder with this plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNul

@Override
protected String @NotNull [] get(@NotNull Event event) {
if (!(event instanceof PlaceholderEvent))
if (!(event instanceof PlaceholderEvent)) {
return new String[0];
}
PlaceholderEvent placeholderEvent = (PlaceholderEvent) event;
switch (part) {
case PLACEHOLDER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public class StructPlaceholder extends Structure implements PlaceholderEvaluator
EventValues.registerEventValue(PlaceholderEvent.class, Player.class, new Getter<Player, PlaceholderEvent>() {
@Override
public Player get(PlaceholderEvent event) {
if (event.getPlayer() != null && event.getPlayer().isOnline())
return (Player) event.getPlayer();
return null;
OfflinePlayer player = event.getPlayer();
return player != null ? player.getPlayer() : null;
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(PlaceholderEvent.class, OfflinePlayer.class, new Getter<OfflinePlayer, PlaceholderEvent>() {
Expand Down Expand Up @@ -86,7 +85,7 @@ public boolean init(Literal<?> @NotNull [] args, int matchedPattern, @NotNull Pa
List<String> placeholders = new ArrayList<>();
//noinspection unchecked - Skript guarantees this will be a Literal<String>
for (String placeholder : ((Literal<String>) args[0]).getAll()) {
String error = plugin.isValidPrefix(placeholder);
String error = plugin.validatePrefix(placeholder);
if (error != null) {
Skript.error(error);
return false;
Expand Down

0 comments on commit b0287eb

Please sign in to comment.