Create service classes

This commit is contained in:
Ryder Belserion 2024-03-05 18:56:50 -05:00
parent cced985f58
commit 44ef839651
No known key found for this signature in database
3 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package com.ryderbelserion.crazyauctions;
import ch.jalu.configme.SettingsManager;
import ch.jalu.configme.SettingsManagerBuilder;
import ch.jalu.configme.resource.YamlFileResourceOptions;
import com.ryderbelserion.crazyauctions.platform.impl.Config;
import com.ryderbelserion.crazyauctions.platform.Server;
import java.io.File;
public class CrazyAuctions {
private final Server server;
private final SettingsManager config;
public CrazyAuctions(Server server) {
this.server = server;
// Create config files
YamlFileResourceOptions builder = YamlFileResourceOptions.builder().indentationSize(2).build();
this.config = SettingsManagerBuilder
.withYamlFile(new File(server.getFolder(), "config.yml"), builder)
.useDefaultMigrationService()
.configurationData(Config.class)
.create();
// Register provider.
CrazyProvider.register(this);
}
public void reload() {
// Reload the config.
this.config.reload();
}
public void disable() {
// Save the config.
this.config.save();
// Unregister provider.
CrazyProvider.unregister();
}
public Server getServer() {
return this.server;
}
public SettingsManager getConfig() {
return this.config;
}
}

View File

@ -0,0 +1,26 @@
package com.ryderbelserion.crazyauctions;
public final class CrazyProvider {
private static CrazyAuctions instance;
private CrazyProvider() {
throw new UnsupportedOperationException("This class cannot be instantiated");
}
public static CrazyAuctions get() {
if (instance == null) {
throw new IllegalStateException("CrazyAuctions is not loaded.");
}
return instance;
}
static void register(final CrazyAuctions instance) {
CrazyProvider.instance = instance;
}
static void unregister() {
CrazyProvider.instance = null;
}
}

View File

@ -0,0 +1,25 @@
package com.ryderbelserion.crazyauctions;
import com.ryderbelserion.crazyauctions.platform.PaperServer;
import org.bukkit.plugin.java.JavaPlugin;
public class CrazyAuctionsPaper extends JavaPlugin {
private CrazyAuctions crazyAuctions;
@Override
public void onEnable() {
this.crazyAuctions = new CrazyAuctions(new PaperServer());
}
@Override
public void onDisable() {
if (this.crazyAuctions != null) {
this.crazyAuctions.disable();
}
}
public CrazyAuctions getCrazyAuctions() {
return this.crazyAuctions;
}
}