This commit is contained in:
Aesthetiful authored and GitHub committed 2024-08-24 20:45:36 -07:00
commit a6887f7cc7
3 files changed
+122

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aesthetiful</groupId>
<artifactId>BungeeVersionModifier</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.16-R0.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -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);
}
}
+1
View File
@@ -0,0 +1 @@
server-version: "1.8.x-1.21.x (BungeeCord)"