keep config.yml header on save, show all pages on ecloud list all, deprecate getExpansionConfig for Configurable#getConfig

This commit is contained in:
PiggyPiglet
2026-02-11 19:46:20 +08:00
parent 458188d728
commit a6b08d8e25
5 changed files with 49 additions and 3 deletions

View File

@@ -175,7 +175,7 @@ public final class CommandECloudExpansionList extends PlaceholderCommand {
// right.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page + 1)));
// }
message = message.insert(Message.raw(" - " + page + " - ").color(Color.GREEN));
message = message.insert(Message.raw(" - " + page + " of " + limit + " - ").color(Color.GREEN));
}
return message;

View File

@@ -12,13 +12,17 @@ import org.jetbrains.annotations.Nullable;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public final class ConfigManager {
private static final Yaml YAML;
@@ -56,7 +60,7 @@ public final class ConfigManager {
return;
}
} catch (Exception e) {
e.printStackTrace();
logger.atSevere().log("Something went wrong when getting the file content of config.yml", e);
return;
}
@@ -69,11 +73,22 @@ public final class ConfigManager {
}
public void save() {
String headerString = null;
try (final InputStream in = PlaceholderAPIPlugin.class.getResourceAsStream("/header.txt")) {
if (in != null) {
headerString = new BufferedReader(new InputStreamReader(in)).lines()
.collect(Collectors.joining("\n"));
}
} catch (IOException e) {
logger.atWarning().log("Failed to write internal header.txt to config.yml.", e);
}
try {
final Map<String, Object> map = GSON.fromJson(GSON.toJsonTree(config), new TypeToken<Map<String, Object>>(){}.getType());
final String yaml = YAML.dump(map);
final Path path = Paths.get(main.getDataDirectory().toString() + "/config.yml");
Files.write(path, Arrays.asList(LINE_DELIMITER.split(yaml)), StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING);
Files.write(path, Arrays.asList(LINE_DELIMITER.split((headerString == null ? "" : headerString + '\n') + yaml)), StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING);
} catch (Exception e) {
logger.atSevere().log("Something went wrong when saving config.yml: ", e);
}

View File

@@ -20,6 +20,7 @@
package at.helpch.placeholderapi.expansion;
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
@@ -49,6 +50,15 @@ public interface Configurable<T> {
@NotNull
T provideDefault();
@NotNull
default T getConfig() {
if (this instanceof PlaceholderExpansion exp) {
return (T) PlaceholderAPIPlugin.instance().configManager().config().expansions().getOrDefault(exp.getIdentifier(), provideDefault());
}
return provideDefault();
}
// /**
// * The map returned by this method will be used to set config options in PlaceholderAPI's config.yml.
// *

View File

@@ -211,6 +211,17 @@ public abstract class PlaceholderExpansion implements PlaceholderHook {
// return (Map<String, Object>) getPlaceholderAPI().configManager().config().expansions().getOrDefault(getIdentifier(), new HashMap<>());
// }
/**
* Get expansion config for this expansion (must implement Configurable&lt;T&gt;).
* Returns null if expansion config is not found.
* Deprecated, please see {@link Configurable#getConfig()}}.
*
* @param configurableType Class extending Configurable&lt;T&gt;
* @return T
* @param <T> Your expansion config type
*/
@SuppressWarnings("unchecked")
@Deprecated
@Nullable
public final <T> T getExpansionConfig(@NotNull final Class<? extends Configurable<T>> configurableType) {
return (T) getPlaceholderAPI().configManager().config().expansions().getOrDefault(getIdentifier(), null);

View File

@@ -0,0 +1,10 @@
# PlaceholderAPI - Hytale Edition!
# Version: ${version}
# Created by: HelpChat
# Contributors: https://github.com/PlaceholderAPI/PlaceholderAPI/graphs/contributors
# Issues: https://github.com/PlaceholderAPI/PlaceholderAPI/issues
# Expansions: https://placeholderapi.com/ecloud
# Wiki: https://wiki.placeholderapi.com/
# Discord: https://helpch.at/discord
# No placeholders are provided with this plugin by default.
# Download placeholders: /papi ecloud