Merge branch 'hytale' into hytale-curseforge

This commit is contained in:
PiggyPiglet
2026-02-14 18:09:35 +08:00
8 changed files with 86 additions and 12 deletions

View File

@@ -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;

View File

@@ -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);
} }

View File

@@ -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.
// * // *

View File

@@ -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&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 @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);

View File

@@ -26,10 +26,7 @@ import com.google.gson.reflect.TypeToken;
import java.io.*; import java.io.*;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.URI; import java.net.*;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -50,11 +47,31 @@ import java.util.stream.Collectors;
import at.helpch.placeholderapi.expansion.PlaceholderExpansion; import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
import at.helpch.placeholderapi.expansion.cloud.CloudExpansion; import at.helpch.placeholderapi.expansion.cloud.CloudExpansion;
import com.hypixel.hytale.common.plugin.PluginIdentifier;
import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.logger.HytaleLogger;
import com.hypixel.hytale.server.core.HytaleServer;
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable; import org.jetbrains.annotations.Unmodifiable;
public final class CloudExpansionManager { public final class CloudExpansionManager {
public static final String USER_AGENT;
static {
String userAgent;
try (final InputStream in = PlaceholderAPIPlugin.class.getResourceAsStream("/user-agent.txt")) {
if (in == null) {
userAgent = "PlaceholderAPI-Bukkit-null";
} else {
userAgent = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).readLine();
}
} catch (IOException e) {
userAgent = "PlaceholderAPI-Bukkit-null";
}
USER_AGENT = userAgent;
}
@NotNull @NotNull
private static final String API_URL = "https://ecloud.placeholderapi.com/api/v3/?platform=hytale"; private static final String API_URL = "https://ecloud.placeholderapi.com/api/v3/?platform=hytale";
@@ -182,6 +199,7 @@ public final class CloudExpansionManager {
try { try {
final URI uri = new URI(API_URL); final URI uri = new URI(API_URL);
final URLConnection connection = uri.toURL().openConnection(); final URLConnection connection = uri.toURL().openConnection();
connection.setRequestProperty("User-Agent", USER_AGENT);
final String json; final String json;
try (final InputStream input = connection.getInputStream()) { try (final InputStream input = connection.getInputStream()) {
@@ -264,10 +282,14 @@ public final class CloudExpansionManager {
"Expansion-" + toIndexName(expansion) + ".jar"); "Expansion-" + toIndexName(expansion) + ".jar");
final CompletableFuture<File> download = CompletableFuture.supplyAsync(() -> { final CompletableFuture<File> download = CompletableFuture.supplyAsync(() -> {
try (final ReadableByteChannel source = Channels.newChannel(new URL(version.getUrl()) try {
.openStream()); final FileOutputStream target = new FileOutputStream(file)) { final URLConnection connection = new URI(version.getUrl()).toURL().openConnection();
target.getChannel().transferFrom(source, 0, Long.MAX_VALUE); connection.setRequestProperty("User-Agent", USER_AGENT);
} catch (final IOException ex) {
try (final ReadableByteChannel source = Channels.newChannel(connection.getInputStream()); final FileOutputStream target = new FileOutputStream(file)) {
target.getChannel().transferFrom(source, 0, Long.MAX_VALUE);
}
} catch (final IOException | URISyntaxException ex) {
throw new CompletionException(ex); throw new CompletionException(ex);
} }
return file; return file;

View File

@@ -24,6 +24,8 @@ import at.helpch.placeholderapi.PlaceholderAPIPlugin;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
@@ -444,7 +446,10 @@ public final class LocalExpansionManager /*implements Listener*/ {
throw ((LinkageError) ex.getCause()); throw ((LinkageError) ex.getCause());
} }
logger.atWarning().log("There was an issue with loading an expansion."); final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
logger.atWarning().log("There was an issue with loading an expansion: " + clazz + "\n%s", sw.toString());
return null; return 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

View File

@@ -0,0 +1 @@
PlaceholderAPI-Hytale-${version}