mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-26 05:51:12 +01:00
Merge branch 'hytale' into hytale-curseforge
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)));
|
||||
// }
|
||||
|
||||
message = message.insert(Message.raw(" - " + page + " - ").color(Color.GREEN));
|
||||
message = message.insert(Message.raw(" - " + page + " of " + limit + " - ").color(Color.GREEN));
|
||||
}
|
||||
|
||||
return message;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
// *
|
||||
|
||||
@@ -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<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
|
||||
public final <T> T getExpansionConfig(@NotNull final Class<? extends Configurable<T>> configurableType) {
|
||||
return (T) getPlaceholderAPI().configManager().config().expansions().getOrDefault(getIdentifier(), null);
|
||||
|
||||
@@ -26,10 +26,7 @@ import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.*;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
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.cloud.CloudExpansion;
|
||||
import com.hypixel.hytale.common.plugin.PluginIdentifier;
|
||||
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.Unmodifiable;
|
||||
|
||||
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
|
||||
private static final String API_URL = "https://ecloud.placeholderapi.com/api/v3/?platform=hytale";
|
||||
@@ -182,6 +199,7 @@ public final class CloudExpansionManager {
|
||||
try {
|
||||
final URI uri = new URI(API_URL);
|
||||
final URLConnection connection = uri.toURL().openConnection();
|
||||
connection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
final String json;
|
||||
|
||||
try (final InputStream input = connection.getInputStream()) {
|
||||
@@ -264,10 +282,14 @@ public final class CloudExpansionManager {
|
||||
"Expansion-" + toIndexName(expansion) + ".jar");
|
||||
|
||||
final CompletableFuture<File> download = CompletableFuture.supplyAsync(() -> {
|
||||
try (final ReadableByteChannel source = Channels.newChannel(new URL(version.getUrl())
|
||||
.openStream()); final FileOutputStream target = new FileOutputStream(file)) {
|
||||
target.getChannel().transferFrom(source, 0, Long.MAX_VALUE);
|
||||
} catch (final IOException ex) {
|
||||
try {
|
||||
final URLConnection connection = new URI(version.getUrl()).toURL().openConnection();
|
||||
connection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
|
||||
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);
|
||||
}
|
||||
return file;
|
||||
|
||||
@@ -24,6 +24,8 @@ import at.helpch.placeholderapi.PlaceholderAPIPlugin;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
@@ -444,7 +446,10 @@ public final class LocalExpansionManager /*implements Listener*/ {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
1
src/main/resources/user-agent.txt
Normal file
1
src/main/resources/user-agent.txt
Normal file
@@ -0,0 +1 @@
|
||||
PlaceholderAPI-Hytale-${version}
|
||||
Reference in New Issue
Block a user