Skip to content

Commit e6747ca

Browse files
committed
Refactor configuration management and enhance logging
1 parent fcf37cc commit e6747ca

File tree

6 files changed

+42
-36
lines changed

6 files changed

+42
-36
lines changed

bukkit/src/main/java/it/renvins/serverpulse/bukkit/ServerPulseBukkitLoader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public ServerPulseBukkitLoader(ServerPulseBukkit plugin) {
6868
}
6969
this.diskRetriever = new DiskRetriever(plugin.getDataFolder());
7070
this.pingRetriever = new BukkitPingRetriever();
71+
72+
LOGGER.info("ServerPulse for Bukkit/Paper initialized - waiting for server starting...");
7173
}
7274

7375
@Override

bukkit/src/main/java/it/renvins/serverpulse/bukkit/config/BukkitConfiguration.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,11 @@ public class BukkitConfiguration {
1616
private File file;
1717
@Getter private YamlConfiguration config;
1818

19-
/**
20-
* Constructs a new CustomConfig manager.
21-
*
22-
* @param plugin The main ServerPulsePlugin instance.
23-
* @param name The name of the configuration file (e.g., "config.yml").
24-
*/
2519
public BukkitConfiguration(ServerPulseBukkit plugin, String name) {
2620
this.plugin = plugin;
2721
this.name = name;
2822
}
2923

30-
/**
31-
* Loads the configuration file. If the file doesn't exist,
32-
* it saves the default resource from the plugin JAR.
33-
*/
3424
public void load() {
3525
if (!plugin.getDataFolder().exists()) {
3626
plugin.getDataFolder().mkdir();
@@ -42,10 +32,6 @@ public void load() {
4232
config = YamlConfiguration.loadConfiguration(file);
4333
}
4434

45-
/**
46-
* Saves the current configuration state back to the file.
47-
* Logs an error if saving fails.
48-
*/
4935
public void save() {
5036
try {
5137
config.save(file);
@@ -54,12 +40,6 @@ public void save() {
5440
}
5541
}
5642

57-
/**
58-
* Reloads the configuration file, reloading the YamlConfiguration.
59-
* Logs an error if the file is null.
60-
*
61-
* @return true if the reload was successful, false otherwise.
62-
*/
6343
public boolean reload() {
6444
if (file == null) {
6545
ServerPulseBukkitLoader.LOGGER.log(Level.SEVERE, "File is null, cannot reload configuration.");

bukkit/src/main/java/it/renvins/serverpulse/bukkit/platform/BukkitPlatform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public boolean isEnabled() {
2323

2424
@Override
2525
public void disable() {
26-
plugin.getServer().getPluginManager().disablePlugin(plugin);
26+
plugin.getServer().shutdown();
2727
}
2828

2929
@Override

fabric/src/main/java/it/renvins/serverpulse/fabric/ServerPulseFabric.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public void onInitialize() {
8080
}
8181

8282
private void onServerStarting(MinecraftServer server) {
83-
LOGGER.info("ServerPulse is starting...");
8483
this.server = server;
8584

85+
LOGGER.info("Loading configuration...");
8686
config.load();
8787

8888
ServerPulseProvider.register(new ServerPulseFabricAPI(databaseService, metricsService, tpsRetriever, diskRetriever, pingRetriever));
@@ -98,8 +98,6 @@ private void onServerStarting(MinecraftServer server) {
9898
}
9999

100100
private void onServerStopped(MinecraftServer server) {
101-
LOGGER.info("ServerPulse is stopping...");
102-
103101
databaseService.unload();
104102
metricsService.unload();
105103

velocity/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ tasks.withType<ShadowJar> {
4141
relocate("okhttp3", "$relocatePath.okhttp3")
4242
relocate("okio", "$relocatePath.okio")
4343
relocate("org.jetbrains", "$relocatePath.jetbrains")
44-
relocate("com.google", "$relocatePath.google")
4544
relocate("io.reactivex", "$relocatePath.reactivex")
4645
relocate("javax.annotation", "$relocatePath.annotation")
4746
relocate("org.apache", "$relocatePath.apache")
@@ -50,4 +49,6 @@ tasks.withType<ShadowJar> {
5049
relocate("retrofit2", "$relocatePath.retrofit2")
5150
relocate("kotlin", "$relocatePath.kotlin") // Relocate instead of exclude
5251
relocate("org.jetbrains.kotlin", "$relocatePath.jetbrains.kotlin") // Relocate instead of exclude
52+
relocate("org.simpleyaml", "$relocatePath.simpleyaml")
53+
relocate("org.yaml", "$relocatePath.yaml")
5354
}

velocity/src/main/java/it/renvins/serverpulse/velocity/ServerPulseVelocity.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.velocitypowered.api.command.CommandMeta;
77
import com.velocitypowered.api.event.Subscribe;
88
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
9+
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
910
import com.velocitypowered.api.plugin.Plugin;
1011
import com.velocitypowered.api.plugin.annotation.DataDirectory;
1112
import com.velocitypowered.api.proxy.ProxyServer;
@@ -38,29 +39,36 @@
3839
public class ServerPulseVelocity {
3940

4041
@Getter private final ProxyServer server;
41-
private final PulseLogger logger;
42+
private final Logger logger;
43+
private final Path dataDirectory;
4244

43-
private final VelocityConfiguration config;
45+
private PulseLogger pulseLogger;
4446

45-
private final IDiskRetriever diskRetriever;
46-
private final IPingRetriever pingRetriever;
47+
private VelocityConfiguration config;
48+
49+
private IDiskRetriever diskRetriever;
50+
private IPingRetriever pingRetriever;
4751

4852
private IDatabaseService databaseService;
4953
private IMetricsService metricsService;
5054

5155
@Inject
52-
public ServerPulseVelocity(ProxyServer server, @DataDirectory Path dataDirectory, Logger logger) {
56+
public ServerPulseVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
5357
this.server = server;
58+
this.logger = logger;
59+
this.dataDirectory = dataDirectory;
60+
61+
logger.info("ServerPulse for Fabric initialized - waiting for proxy starting...");
62+
}
5463

55-
this.logger = new VelocityLogger(logger);
64+
@Subscribe
65+
public void onProxyInitialization(ProxyInitializeEvent event) {
66+
this.pulseLogger = new VelocityLogger(logger);
5667
this.config = new VelocityConfiguration(logger, dataDirectory, "config.yml");
5768

5869
this.diskRetriever = new DiskRetriever(dataDirectory.toFile());
5970
this.pingRetriever = new VelocityPingRetriever(this);
60-
}
6171

62-
@Subscribe
63-
public void onProxyInitialization(ProxyInitializeEvent event) {
6472
logger.info("Loading configuration file...");
6573
config.load();
6674

@@ -70,8 +78,8 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
7078
Platform platform = new VelocityPlatform(this);
7179
TaskScheduler scheduler = new VelocityTaskScheduler(this);
7280

73-
this.databaseService = new DatabaseService(logger, platform, dbConfig, scheduler);
74-
this.metricsService = new MetricsService(logger, platform, metricsConfig, scheduler);
81+
this.databaseService = new DatabaseService(pulseLogger, platform, dbConfig, scheduler);
82+
this.metricsService = new MetricsService(pulseLogger, platform, metricsConfig, scheduler);
7583

7684
ServerPulseProvider.register(new ServerPulseVelocityAPI(databaseService, metricsService, diskRetriever, pingRetriever));
7785

@@ -86,4 +94,21 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
8694
.plugin(this).aliases("spv").build();
8795
server.getCommandManager().register(meta, new ServerPulseCommand(config).createCommand());
8896
}
97+
98+
@Subscribe
99+
public void onProxyShutdown(ProxyShutdownEvent event) {
100+
if (databaseService != null) {
101+
databaseService.unload();
102+
}
103+
if (metricsService != null) {
104+
metricsService.unload();
105+
}
106+
107+
try {
108+
ServerPulseProvider.unregister();
109+
} catch (IllegalStateException e) {
110+
// API might already be unregistered, that's okay
111+
}
112+
logger.info("ServerPulse for Velocity has been shut down.");
113+
}
89114
}

0 commit comments

Comments
 (0)