mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-28 18:45:10 +01:00
start converting from bukkit to hytale
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package at.helpch.placeholderapi.configuration;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record BooleanValue(@NotNull String trueValue, @NotNull String falseValue) {
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package at.helpch.placeholderapi.configuration;
|
||||
|
||||
import at.helpch.placeholderapi.PlaceholderAPIBootstrap;
|
||||
import com.google.gson.FieldNamingPolicy;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.hypixel.hytale.logger.HytaleLogger;
|
||||
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class ConfigManager {
|
||||
private static final Yaml YAML = new Yaml();
|
||||
private static final Gson GSON = new GsonBuilder()
|
||||
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
|
||||
.create();
|
||||
// .registerTypeAdapter()
|
||||
|
||||
private final JavaPlugin main;
|
||||
private final HytaleLogger logger;
|
||||
private PlaceholderAPIConfig config;
|
||||
|
||||
public ConfigManager(@NotNull final JavaPlugin main) {
|
||||
this.main = main;
|
||||
this.logger = main.getLogger();
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
final String content;
|
||||
|
||||
try {
|
||||
final Path file = createFile("/config.yml", main.getDataDirectory().toString() + "/config.yml");
|
||||
|
||||
if (file != null) {
|
||||
content = Files.readString(file);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<String, Object> data = YAML.load(content);
|
||||
config = GSON.fromJson(GSON.toJsonTree(data), PlaceholderAPIConfig.class);
|
||||
}
|
||||
|
||||
public PlaceholderAPIConfig config() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Path createFile(@NotNull final String internalPath, @NotNull final String externalPath) {
|
||||
final Path file = Paths.get(externalPath);
|
||||
|
||||
if (Files.exists(file)) {
|
||||
return file;
|
||||
}
|
||||
|
||||
final Optional<Path> parent = Optional.ofNullable(file.getParent());
|
||||
|
||||
try {
|
||||
if (parent.isPresent()) {
|
||||
Files.createDirectories(parent.get());
|
||||
}
|
||||
|
||||
Files.createFile(file);
|
||||
} catch (IOException e) {
|
||||
logger.atSevere().log("Something went wrong when trying to craete ", file);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (exportResource(internalPath, externalPath)) {
|
||||
return file;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean exportResource(@NotNull final String internalPath, @NotNull final String externalPath) {
|
||||
try {
|
||||
Files.copy(PlaceholderAPIBootstrap.class.getResourceAsStream(internalPath), Paths.get(externalPath),
|
||||
StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.atSevere().log("Something went wrong when moving internal: ", internalPath, " to ", externalPath);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PlaceholderAPI is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package at.helpch.placeholderapi.configuration;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import at.helpch.placeholderapi.expansion.cloud.CloudExpansion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public enum ExpansionSort implements Comparator<CloudExpansion> {
|
||||
|
||||
NAME(Comparator.comparing(CloudExpansion::getName)),
|
||||
AUTHOR(Comparator.comparing(CloudExpansion::getAuthor)),
|
||||
LATEST(Comparator.comparing(CloudExpansion::getLastUpdate).reversed());
|
||||
|
||||
|
||||
@NotNull
|
||||
private final Comparator<CloudExpansion> comparator;
|
||||
|
||||
ExpansionSort(@NotNull final Comparator<CloudExpansion> comparator) {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final int compare(final CloudExpansion expansion1, final CloudExpansion expansion2) {
|
||||
return comparator.compare(expansion1, expansion2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of PlaceholderAPI
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (c) 2015 - 2026 PlaceholderAPI Team
|
||||
*
|
||||
* PlaceholderAPI free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PlaceholderAPI is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package at.helpch.placeholderapi.configuration;
|
||||
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record PlaceholderAPIConfig(boolean cloudEnabled, boolean debugMode, @NotNull ExpansionSort cloudSorting,
|
||||
@NotNull BooleanValue booleanValue, @NotNull String dateFormat) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user