Files
src
manifest.kod
pom.xml
Code
38 3,155
src/main/java/com/sshome/SSHomePlugin.java
package com.sshome;
import com.sshome.commands.DelHomeCommand;
import com.sshome.commands.HomeCommand;
import com.sshome.commands.SetHomeCommand;
import com.sshome.commands.SSHomeCommand;
import com.sshome.inventory.gui.GUIListener;
import com.sshome.inventory.gui.GUIManager;
import com.sshome.managers.ConfigManager;
import com.sshome.managers.HomeManager;
import com.sshome.managers.TeleportManager;
import com.sshome.storage.StorageProvider;
import com.sshome.storage.impl.SQLiteStorage;
import com.sshome.storage.impl.YAMLStorage;
import com.sshome.util.PlaceholderExpansion;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public class SSHomePlugin extends JavaPlugin {
private ConfigManager configManager;
private StorageProvider storageProvider;
private HomeManager homeManager;
private TeleportManager teleportManager;
private GUIManager guiManager;
@Override
public void onEnable() {
this.configManager = new ConfigManager(this);
this.configManager.loadConfigs();
this.initializeStorage();
this.homeManager = new HomeManager(this);
this.teleportManager = new TeleportManager(this);
this.guiManager = new GUIManager();
this.registerCommands();
this.registerListeners();
this.registerPlaceholders();
getLogger().info("ssHome has been enabled!");
}
@Override
public void onDisable() {
if (this.teleportManager != null) {
this.teleportManager.cancelAllTeleports();
}
if (this.storageProvider != null) {
this.storageProvider.close();
}
getLogger().info("ssHome has been disabled!");
}
private void initializeStorage() {
String storageType = getConfig().getString("storage.type", "SQLITE").toUpperCase();
if (storageType.equals("YAML")) {
this.storageProvider = new YAMLStorage(this);
} else {
this.storageProvider = new SQLiteStorage(this);
}
this.storageProvider.initialize();
}
private void registerCommands() {
getCommand("home").setExecutor(new HomeCommand(this));
getCommand("homes").setExecutor(new com.sshome.commands.HomesCommand(this));
getCommand("sethome").setExecutor(new SetHomeCommand(this));
getCommand("delhome").setExecutor(new DelHomeCommand(this));
getCommand("sshome").setExecutor(new SSHomeCommand(this));
}
private void registerListeners() {
Bukkit.getPluginManager().registerEvents(new GUIListener(this.guiManager), this);
Bukkit.getPluginManager().registerEvents(new com.sshome.listeners.PlayerMoveListener(this), this);
}
private void registerPlaceholders() {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
if (getConfig().getBoolean("placeholderapi.enabled", true)) {
new PlaceholderExpansion(this).register();
getLogger().info("PlaceholderAPI expansion registered!");
}
}
}
public void reload() {
this.configManager.loadConfigs();
if (this.storageProvider != null) {
this.storageProvider.close();
}
this.initializeStorage();
this.homeManager = new HomeManager(this);
}
}