Merge branch 'master' into master

This commit is contained in:
PiggyPiglet
2026-02-12 20:33:19 +08:00
committed by GitHub
8 changed files with 93 additions and 10 deletions

View File

@@ -22,7 +22,6 @@ package me.clip.placeholderapi.replacer;
import java.util.Locale;
import java.util.function.Function;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;

View File

@@ -26,8 +26,8 @@ import java.net.URL;
import java.util.Arrays;
import javax.net.ssl.HttpsURLConnection;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
import me.clip.placeholderapi.util.Msg;
@@ -66,7 +66,7 @@ public class UpdateChecker implements Listener {
try {
HttpsURLConnection con = (HttpsURLConnection) new URL(MODRINTH_URL).openConnection();
con.setRequestMethod("GET");
final JsonElement json = JsonParser.parseReader(new BufferedReader(new InputStreamReader(con.getInputStream())));
final JsonElement json = new Gson().fromJson(new BufferedReader(new InputStreamReader(con.getInputStream())), JsonElement.class);
modrinthVersion = json.getAsJsonArray().get(0).getAsJsonObject().get("version_number").getAsString();
} catch (Exception ex) {
plugin.getLogger().info("Failed to check for updates on modrinth.");

View File

@@ -55,9 +55,18 @@ public final class ExpansionSafetyCheck {
}
final Set<String> maliciousPaths = new HashSet<>();
final File[] files = expansionsFolder.listFiles();
for (File file : expansionsFolder.listFiles()) {
if (files == null) {
return false;
}
for (File file : files) {
try {
if (!file.isFile()) {
continue;
}
final String hash = Hashing.sha256().hashBytes(Files.asByteSource(file).read()).toString();
if (knownMaliciousExpansions.contains(hash)) {

View File

@@ -30,6 +30,8 @@ import org.jetbrains.annotations.Nullable;
public interface Values {
String NO_ARGUMENTS_PLACEHOLDER = "%player%";
String EMPTY_ARGUMENT_PLACEHOLDER = "%player_%";
String SMALL_TEXT = "My name is %player_name%";
String LARGE_TEXT = "My name is %player_name% and my location is (%player_x%, %player_y%, %player_z%), this placeholder is invalid %server_name%";
@@ -43,6 +45,7 @@ public interface Values {
final class MockPlayerPlaceholderExpansion extends PlaceholderExpansion {
public static final String EMPTY_ARGUMENT = "Empty Argument";
public static final String PLAYER_X = "10";
public static final String PLAYER_Y = "20";
public static final String PLAYER_Z = "30";
@@ -83,6 +86,8 @@ public interface Values {
return PLAYER_Y;
case "z":
return PLAYER_Z;
case "":
return EMPTY_ARGUMENT;
}
return null;

View File

@@ -24,6 +24,7 @@ import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYE
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_X;
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_Y;
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_Z;
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.EMPTY_ARGUMENT;
import static org.junit.jupiter.api.Assertions.assertEquals;
import me.clip.placeholderapi.Values;
@@ -37,6 +38,18 @@ public final class ReplacerUnitTester {
Values.CHARS_REPLACER.apply("%player_name%", null, Values.PLACEHOLDERS::get));
}
@Test
void charsReplacersDoesNotParsePlaceholdersWithNoArguments() {
assertEquals(Values.NO_ARGUMENTS_PLACEHOLDER,
Values.CHARS_REPLACER.apply(Values.NO_ARGUMENTS_PLACEHOLDER, null, Values.PLACEHOLDERS::get));
}
@Test
void charsReplacersParsesPlaceholdersWithOneArgumentThatIsEmpty() {
assertEquals(EMPTY_ARGUMENT,
Values.CHARS_REPLACER.apply(Values.EMPTY_ARGUMENT_PLACEHOLDER, null, Values.PLACEHOLDERS::get));
}
@Test
void testCharsReplacerProducesExpectedSentence() {
assertEquals(String.format(