commit f526c803fa5ef38b91e6ff3f91f9aee418e25f54 Author: Adrian Victor Date: Mon Mar 17 11:42:39 2025 -0300 First commit. diff --git a/libs/craftbukkit-1060.jar b/libs/craftbukkit-1060.jar new file mode 100644 index 0000000..83565a6 Binary files /dev/null and b/libs/craftbukkit-1060.jar differ diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..643f8ef --- /dev/null +++ b/plugin.yml @@ -0,0 +1,7 @@ +author: tenkuma +database: false +main: gd.rf.adrianvictor.lib.Main +name: tenkumaLib +startup: startup +url: https://adrianvictor.rf.gd +version: '1.0' \ No newline at end of file diff --git a/src/gd/rf/adrianvictor/lib/Color.java b/src/gd/rf/adrianvictor/lib/Color.java new file mode 100644 index 0000000..0ec68d2 --- /dev/null +++ b/src/gd/rf/adrianvictor/lib/Color.java @@ -0,0 +1,13 @@ +package gd.rf.adrianvictor.lib; + +public class Color { + public String formatColors(String message) { + return message.replaceAll("&([0-9a-fk-or])", "ยง$1"); + } + + public Object[] ignoreColors(String message) { + String parsed = message.replaceAll("&([0-9a-fk-or])", ""); + Boolean changed = parsed == message; + return new Object[] {parsed, changed}; + } +} \ No newline at end of file diff --git a/src/gd/rf/adrianvictor/lib/Configuration.java b/src/gd/rf/adrianvictor/lib/Configuration.java new file mode 100644 index 0000000..7943e93 --- /dev/null +++ b/src/gd/rf/adrianvictor/lib/Configuration.java @@ -0,0 +1,135 @@ +package gd.rf.adrianvictor.lib; + +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.util.config.Configuration; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; + +/** + * Utility class for managing plugin configuration files. + *

+ * This class extends {@link Configuration} to provide custom methods for loading, saving, and managing + * configuration files. It automatically handles the creation of parent directories and copies default configuration + * files from the plugin's resources if they do not exist. + *

+ * Note: This class allows for flexible management of multiple configuration files, specified by their file name. + */ +public class Configuration extends Configuration { + + private final File configFile; + private final String pluginName; + + /** + * Constructs a new instance of {@code ConfigUtil}. + * + * @param plugin the plugin instance using this configuration utility + * @param fileName the name of the configuration file to manage (e.g., "config.yml", "settings.yml") + */ + public Configuration(JavaPlugin plugin, String fileName) { + super(new File(plugin.getDataFolder(), fileName)); + this.configFile = new File(plugin.getDataFolder(), fileName); + this.pluginName = plugin.getDescription().getName(); + } + + /** + * Loads the configuration file. + *

+ */ + @Override + public void load() { + createParentDirectories(); + + if (!configFile.exists()) { + copyDefaultConfig(); + } + + try { + super.load(); + } catch (Exception e) { + Logger.severe(String.format("[%s] Failed to load config '%s': %s", pluginName, configFile.getName(), e.getMessage())); + } + } + + /** + * Creates the parent directories for the configuration file if they do not exist. + *

+ * Logs an error if the directories cannot be created. + */ + private void createParentDirectories() { + try { + Files.createDirectories(configFile.getParentFile().toPath()); + } catch (IOException e) { + Logger.severe(String.format("[%s] Failed to generate default config directory: %s", pluginName, e.getMessage())); + } + } + + /** + * Copies the default configuration file from the plugin's resources to the target location. + *

+ * This method looks for a file in the plugin's resources with the same name as the configuration file being managed. + * If found, it copies this file to the plugin's data folder. + *

+ * Logs an error if the default configuration file cannot be found or copied. + */ + private void copyDefaultConfig() { + // Adjust the path to ensure it's correct for your JAR structure + String resourcePath = "/" + configFile.getName(); + + try (InputStream input = getClass().getResourceAsStream(resourcePath)) { + if (input == null) { + Logger.severe(String.format("[%s] Default config '%s' wasn't found.", pluginName, configFile.getName())); + return; + } + + Files.copy(input, configFile.toPath()); + Logger.info(String.format("[%s] Default config '%s' generated successfully.", pluginName, configFile.getName())); + } catch (IOException e) { + Logger.severe(String.format("[%s] Failed to generate default config '%s': %s", pluginName, configFile.getName(), e.getMessage())); + } + } + + /** + * Loads the configuration file and logs the result. + *

+ * Logs a message indicating whether the configuration was loaded successfully. + */ + public void loadConfig() { + try { + this.load(); + Logger.info(String.format("[%s] Config '%s' loaded successfully.", pluginName, configFile.getName())); + } catch (Exception e) { + Logger.severe(String.format("[%s] Failed to load config '%s': %s", pluginName, configFile.getName(), e.getMessage())); + } + } + + /** + * Saves the configuration file and logs the result. + *

+ * Logs a message indicating whether the configuration was saved successfully. + */ + public void saveConfig() { + try { + this.save(); + Logger.info(String.format("[%s] Config '%s' saved successfully.", pluginName, configFile.getName())); + } catch (Exception e) { + Logger.severe(String.format("[%s] Failed to save config '%s': %s", pluginName, configFile.getName(), e.getMessage())); + } + } + + /** + * Returns the configuration file managed by this utility. + * + * @return the configuration file + */ + public File getConfig() { + return configFile; + } +} \ No newline at end of file diff --git a/src/gd/rf/adrianvictor/lib/Log.java b/src/gd/rf/adrianvictor/lib/Log.java new file mode 100644 index 0000000..f04ea93 --- /dev/null +++ b/src/gd/rf/adrianvictor/lib/Log.java @@ -0,0 +1,28 @@ +package gd.rf.adrianvictor.lib; +import static org.bukkit.Bukkit.getServer; + +public class Log { + public static void info(String message) { + getServer().getLogger().info(message); + } + + public static void infoc(String message) { + getServer().getLogger().info(message); + } + + public static void warning(String message) { + getServer().getLogger().warning(message); + } + + public static void warningc(String message) { + getServer().getLogger().warning(message); + } + + public static void severe(String message) { + getServer().getLogger().severe(message); + } + + public static void severec(String message) { + getServer().getLogger().severe(message); + } +} \ No newline at end of file diff --git a/src/gd/rf/adrianvictor/lib/Main.java b/src/gd/rf/adrianvictor/lib/Main.java new file mode 100644 index 0000000..c31100e --- /dev/null +++ b/src/gd/rf/adrianvictor/lib/Main.java @@ -0,0 +1,8 @@ +package gd.rf.adrianvictor.lib; +import org.bukkit.plugin.java.JavaPlugin; + +public class Main extends JavaPlugin { + public void onLoad() { + Log.info(this + " is loading."); + } +} \ No newline at end of file