diff --git a/build.gradle.kts b/build.gradle.kts index 4ef50d2..6a55deb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ apply() java { toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) + languageVersion.set(JavaLanguageVersion.of(21)) } } @@ -39,8 +39,13 @@ tasks { } dependencies { - implementation("com.alttd:Galaxy-API:1.20.4-R0.1-SNAPSHOT") + compileOnly("com.alttd.cosmos:cosmos-api:1.21.6-R0.1-SNAPSHOT") { + isChanging = true + } compileOnly("de.keyle:mypet:3.11-SNAPSHOT") + compileOnly("com.alttd:VillagerShopUI:1.1-SNAPSHOT") { + isChanging = true + } } fun gitCommit(): String { @@ -51,4 +56,4 @@ fun gitCommit(): String { standardOutput = os } return String(os.toByteArray()).trim() -} \ No newline at end of file +} diff --git a/settings.gradle.kts b/settings.gradle.kts index eb96a77..171f027 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,9 +1,20 @@ +import org.gradle.kotlin.dsl.maven + rootProject.name = "AFKDetector" dependencyResolutionManagement { repositories { mavenCentral() maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy + maven("https://repo.alttd.com/repository/alttd-snapshot/") + maven { + name = "nexus" + url = uri("https://repo.alttd.com/repository/alttd-snapshot/") + credentials { + username = providers.gradleProperty("alttdSnapshotUsername").get() + password = providers.gradleProperty("alttdSnapshotPassword").get() + } + } } repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) } diff --git a/src/main/java/com/alttd/afkdectector/AFKDetector.java b/src/main/java/com/alttd/afkdectector/AFKDetector.java index c952a18..b084168 100755 --- a/src/main/java/com/alttd/afkdectector/AFKDetector.java +++ b/src/main/java/com/alttd/afkdectector/AFKDetector.java @@ -186,7 +186,7 @@ public class AFKDetector extends JavaPlugin implements Listener { Config.reload(); MessagesConfig.reload(); if (sender != null) { - sender.sendMiniMessage("Configuration reloaded", null); + sender.sendRichMessage("Configuration reloaded"); } } } diff --git a/src/main/java/com/alttd/afkdectector/MessageTimer.java b/src/main/java/com/alttd/afkdectector/MessageTimer.java index a011aa3..d2a53a0 100755 --- a/src/main/java/com/alttd/afkdectector/MessageTimer.java +++ b/src/main/java/com/alttd/afkdectector/MessageTimer.java @@ -60,7 +60,7 @@ public class MessageTimer extends BukkitRunnable { miniMessage.deserialize(Messages.COUNT_DOWN_TITLE_2.getMessage())); //Title.Times.of(Config.FADEIN, Config.STAY, Config.STAY); player.showTitle(title); - player.sendMessage(miniMessage.deserialize(Messages.COUNT_DOWN_MESSAGE.getMessage())); + player.sendMessage(Messages.COUNT_DOWN_MESSAGE.getMessage()); } repeats = repeats - 1; diff --git a/src/main/java/com/alttd/afkdectector/config/AbstractConfig.java b/src/main/java/com/alttd/afkdectector/config/AbstractConfig.java new file mode 100644 index 0000000..705ff83 --- /dev/null +++ b/src/main/java/com/alttd/afkdectector/config/AbstractConfig.java @@ -0,0 +1,135 @@ +package com.alttd.afkdectector.config; + +import com.alttd.VillagerUI; +import com.alttd.util.Logger; +import com.google.common.collect.ImmutableMap; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@SuppressWarnings({"unused", "SameParameterValue"}) +abstract class AbstractConfig { + File file; + YamlConfiguration yaml; + + AbstractConfig(String filename) { + init(new File(VillagerUI.getInstance().getDataFolder(), filename), filename); + } + + AbstractConfig(File file, String filename) { + init(new File(file.getPath() + File.separator + filename), filename); + } + + private void init(File file, String filename) { + this.file = file; + this.yaml = new YamlConfiguration(); + try { + yaml.load(file); + } catch (IOException ignore) { + } catch (InvalidConfigurationException ex) { + Logger.severe(String.format("Could not load %s, please correct your syntax errors", filename)); + throw new RuntimeException(ex); + } + yaml.options().copyDefaults(true); + } + + void readConfig(Class clazz, Object instance) { + for (Method method : clazz.getDeclaredMethods()) { + if (Modifier.isPrivate(method.getModifiers())) { + if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) { + try { + method.setAccessible(true); + method.invoke(instance); + } catch (InvocationTargetException ex) { + throw new RuntimeException(ex.getCause()); + } catch (Exception ex) { + Logger.severe("Error invoking %.", method.toString()); + ex.printStackTrace(); + } + } + } + } + + save(); + } + + private void save() { + try { + yaml.save(file); + } catch (IOException ex) { + Logger.severe("Could not save %.", file.toString()); + ex.printStackTrace(); + } + } + + void set(String path, Object val) { + yaml.addDefault(path, val); + yaml.set(path, val); + save(); + } + + String getString(String path, String def) { + yaml.addDefault(path, def); + return yaml.getString(path, yaml.getString(path)); + } + + boolean getBoolean(String path, boolean def) { + yaml.addDefault(path, def); + return yaml.getBoolean(path, yaml.getBoolean(path)); + } + + int getInt(String path, int def) { + yaml.addDefault(path, def); + return yaml.getInt(path, yaml.getInt(path)); + } + + double getDouble(String path, double def) { + yaml.addDefault(path, def); + return yaml.getDouble(path, yaml.getDouble(path)); + } + + List getList(String path, T def) { + yaml.addDefault(path, def); + return yaml.getList(path, yaml.getList(path)); + } + + List getStringList(String path, List def) { + yaml.addDefault(path, def); + return yaml.getStringList(path); + } + + @NonNull + Map getMap(final @NonNull String path, final @Nullable Map def) { + final ImmutableMap.Builder builder = ImmutableMap.builder(); + if (def != null && yaml.getConfigurationSection(path) == null) { + yaml.addDefault(path, def.isEmpty() ? new HashMap<>() : def); + return def; + } + final ConfigurationSection section = yaml.getConfigurationSection(path); + if (section != null) { + for (String key : section.getKeys(false)) { + @SuppressWarnings("unchecked") + final T val = (T) section.get(key); + if (val != null) { + builder.put(key, val); + } + } + } + return builder.build(); + } + + ConfigurationSection getConfigurationSection(String path) { + return yaml.getConfigurationSection(path); + } +} diff --git a/src/main/java/com/alttd/afkdectector/config/Config.java b/src/main/java/com/alttd/afkdectector/config/Config.java index e67c993..54abfa3 100644 --- a/src/main/java/com/alttd/afkdectector/config/Config.java +++ b/src/main/java/com/alttd/afkdectector/config/Config.java @@ -1,13 +1,12 @@ package com.alttd.afkdectector.config; import com.alttd.afkdectector.AFKDetector; -import com.alttd.galaxy.configuration.AbstractConfiguration; import org.bukkit.Bukkit; import java.io.File; @SuppressWarnings("unused") -public class Config extends AbstractConfiguration { +public class Config extends AbstractConfig { private Config() { super(new File(File.separator + "mnt" + File.separator + "configs" + File.separator + AFKDetector.getInstance().getName()), "config"); diff --git a/src/main/java/com/alttd/afkdectector/config/MessagesConfig.java b/src/main/java/com/alttd/afkdectector/config/MessagesConfig.java index 5447396..a7e45c9 100644 --- a/src/main/java/com/alttd/afkdectector/config/MessagesConfig.java +++ b/src/main/java/com/alttd/afkdectector/config/MessagesConfig.java @@ -1,12 +1,11 @@ package com.alttd.afkdectector.config; import com.alttd.afkdectector.AFKDetector; -import com.alttd.galaxy.configuration.AbstractConfiguration; import java.io.File; @SuppressWarnings("unused") -public class MessagesConfig extends AbstractConfiguration { +public class MessagesConfig extends AbstractConfig { private MessagesConfig() { super(new File(File.separator + "mnt" + File.separator + "configs" + File.separator + AFKDetector.getInstance().getName()), "messages"); }