From a6887f7cc7cc7614e79e126c1aa6f7bcd01dbbca Mon Sep 17 00:00:00 2001 From: Aesthetiful <62633768+DrChic0@users.noreply.github.com> Date: Sat, 24 Aug 2024 20:45:36 -0700 Subject: [PATCH] Init --- pom.xml | 40 +++++++++ .../BungeeVersionModifier.java | 81 +++++++++++++++++++ src/main/resources/config.yml | 1 + 3 files changed, 122 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/aesthetiful/BungeeVersionModifier/BungeeVersionModifier.java create mode 100644 src/main/resources/config.yml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4fb0831 --- /dev/null +++ b/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + + com.aesthetiful + BungeeVersionModifier + 1.0-SNAPSHOT + + + + net.md-5 + bungeecord-api + 1.16-R0.4 + provided + + + + + + + src/main/resources + + **/*.yml + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + diff --git a/src/main/java/com/aesthetiful/BungeeVersionModifier/BungeeVersionModifier.java b/src/main/java/com/aesthetiful/BungeeVersionModifier/BungeeVersionModifier.java new file mode 100644 index 0000000..92c1ccc --- /dev/null +++ b/src/main/java/com/aesthetiful/BungeeVersionModifier/BungeeVersionModifier.java @@ -0,0 +1,81 @@ +package com.aesthetiful.BungeeVersionModifier; + +import net.md_5.bungee.api.plugin.Plugin; +import net.md_5.bungee.config.Configuration; +import net.md_5.bungee.config.ConfigurationProvider; +import net.md_5.bungee.config.YamlConfiguration; +import net.md_5.bungee.api.event.ProxyPingEvent; +import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.api.plugin.Listener; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + +public class BungeeVersionModifier extends Plugin implements Listener { + + private Configuration config; + + @Override + public void onEnable() { + + if (!getDataFolder().exists()) { + getDataFolder().mkdir(); + } + + // Save the default config.yml + saveDefaultConfig(); + + // Load the configuration file + loadConfig(); + + // Register the event listener + getProxy().getPluginManager().registerListener(this, this); + } + + private void loadConfig() { + // Create the plugin's data folder if it doesn't exist + if (!getDataFolder().exists()) { + getDataFolder().mkdir(); + } + + // Define the configuration file + File configFile = new File(getDataFolder(), "config.yml"); + + // Copy the default config.yml from resources to the plugin's data folder if it doesn't exist + if (!configFile.exists()) { + try { + Files.copy(getResourceAsStream("config.yml"), configFile.toPath()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // Load the configuration + try { + config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void saveDefaultConfig() { + File configFile = new File(getDataFolder(), "config.yml"); + + if (!configFile.exists()) { + try { + Files.copy(getResourceAsStream("config.yml"), configFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + getLogger().severe("Could not save default config.yml: " + e.getMessage()); + } + } + } + + @EventHandler + public void onProxyPing(ProxyPingEvent event) { + // Get the server version from the config.yml file, or use a default value if not specified + String version = config.getString("server-version", "1.8.x-1.21.x (BungeeCord)"); + event.getResponse().getVersion().setName(version); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..fcf60db --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1 @@ +server-version: "1.8.x-1.21.x (BungeeCord)" \ No newline at end of file