mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-26 05:51:12 +01:00
keep config.yml header on save, show all pages on ecloud list all, deprecate getExpansionConfig for Configurable#getConfig
This commit is contained in:
@@ -175,7 +175,7 @@ public final class CommandECloudExpansionList extends PlaceholderCommand {
|
|||||||
// right.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page + 1)));
|
// 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;
|
return message;
|
||||||
|
|||||||
@@ -12,13 +12,17 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class ConfigManager {
|
public final class ConfigManager {
|
||||||
private static final Yaml YAML;
|
private static final Yaml YAML;
|
||||||
@@ -56,7 +60,7 @@ public final class ConfigManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.atSevere().log("Something went wrong when getting the file content of config.yml", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,11 +73,22 @@ public final class ConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
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 {
|
try {
|
||||||
final Map<String, Object> map = GSON.fromJson(GSON.toJsonTree(config), new TypeToken<Map<String, Object>>(){}.getType());
|
final Map<String, Object> map = GSON.fromJson(GSON.toJsonTree(config), new TypeToken<Map<String, Object>>(){}.getType());
|
||||||
final String yaml = YAML.dump(map);
|
final String yaml = YAML.dump(map);
|
||||||
final Path path = Paths.get(main.getDataDirectory().toString() + "/config.yml");
|
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) {
|
} catch (Exception e) {
|
||||||
logger.atSevere().log("Something went wrong when saving config.yml: ", e);
|
logger.atSevere().log("Something went wrong when saving config.yml: ", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
package at.helpch.placeholderapi.expansion;
|
package at.helpch.placeholderapi.expansion;
|
||||||
|
|
||||||
|
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -49,6 +50,15 @@ public interface Configurable<T> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
T provideDefault();
|
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.
|
// * The map returned by this method will be used to set config options in PlaceholderAPI's config.yml.
|
||||||
// *
|
// *
|
||||||
|
|||||||
@@ -211,6 +211,17 @@ public abstract class PlaceholderExpansion implements PlaceholderHook {
|
|||||||
// return (Map<String, Object>) getPlaceholderAPI().configManager().config().expansions().getOrDefault(getIdentifier(), new HashMap<>());
|
// return (Map<String, Object>) getPlaceholderAPI().configManager().config().expansions().getOrDefault(getIdentifier(), new HashMap<>());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get expansion config for this expansion (must implement Configurable<T>).
|
||||||
|
* Returns null if expansion config is not found.
|
||||||
|
* Deprecated, please see {@link Configurable#getConfig()}}.
|
||||||
|
*
|
||||||
|
* @param configurableType Class extending Configurable<T>
|
||||||
|
* @return T
|
||||||
|
* @param <T> Your expansion config type
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Deprecated
|
||||||
@Nullable
|
@Nullable
|
||||||
public final <T> T getExpansionConfig(@NotNull final Class<? extends Configurable<T>> configurableType) {
|
public final <T> T getExpansionConfig(@NotNull final Class<? extends Configurable<T>> configurableType) {
|
||||||
return (T) getPlaceholderAPI().configManager().config().expansions().getOrDefault(getIdentifier(), null);
|
return (T) getPlaceholderAPI().configManager().config().expansions().getOrDefault(getIdentifier(), null);
|
||||||
|
|||||||
10
src/main/resources/header.txt
Normal file
10
src/main/resources/header.txt
Normal 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
|
||||||
Reference in New Issue
Block a user