mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
104 lines
3.5 KiB
Java
104 lines
3.5 KiB
Java
package me.youhavetrouble.preventstabby;
|
|
|
|
import me.youhavetrouble.preventstabby.commands.MainCommand;
|
|
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
|
import me.youhavetrouble.preventstabby.hooks.PlaceholderApiHook;
|
|
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
|
|
import me.youhavetrouble.preventstabby.data.PlayerListener;
|
|
import me.youhavetrouble.preventstabby.data.PlayerManager;
|
|
import me.youhavetrouble.preventstabby.listeners.EnvironmentalListener;
|
|
import me.youhavetrouble.preventstabby.listeners.PvpListener;
|
|
import me.youhavetrouble.preventstabby.listeners.UtilListener;
|
|
import me.youhavetrouble.preventstabby.util.*;
|
|
import org.bstats.bukkit.Metrics;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.PluginCommand;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import java.io.File;
|
|
|
|
public final class PreventStabby extends JavaPlugin {
|
|
|
|
private static PreventStabby plugin;
|
|
private ConfigCache configCache;
|
|
private PlayerManager playerManager;
|
|
private DatabaseSQLite sqLite;
|
|
private static boolean worldGuardHook;
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
plugin = this;
|
|
reloadPluginConfig();
|
|
File dbFile = new File("plugins/PreventStabby");
|
|
sqLite = new DatabaseSQLite("jdbc:sqlite:plugins/PreventStabby/database.db", dbFile, getLogger());
|
|
playerManager = new PlayerManager(this);
|
|
|
|
// Register listeners
|
|
getServer().getPluginManager().registerEvents(new UtilListener(), this);
|
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
getServer().getPluginManager().registerEvents(new EnvironmentalListener(this), this);
|
|
|
|
getServer().getPluginManager().registerEvents(new PvpListener(this), this);
|
|
|
|
// Register command
|
|
PluginCommand pvpCommand = getCommand("pvp");
|
|
if (pvpCommand == null) {
|
|
getLogger().severe("Error with registering commands.");
|
|
getLogger().severe("Plugin will now disable.");
|
|
getServer().getPluginManager().disablePlugin(this);
|
|
return;
|
|
}
|
|
MainCommand mainCommand = new MainCommand();
|
|
pvpCommand.setExecutor(mainCommand);
|
|
pvpCommand.setTabCompleter(mainCommand);
|
|
|
|
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
|
new PlaceholderApiHook(this).register();
|
|
}
|
|
|
|
Metrics metrics = new Metrics(this, 14074);
|
|
}
|
|
|
|
@Override
|
|
public void onLoad() {
|
|
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
|
|
try {
|
|
WorldGuardHook.init();
|
|
worldGuardHook = true;
|
|
} catch (NoClassDefFoundError e) {
|
|
worldGuardHook = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static boolean worldGuardHookEnabled() {
|
|
return worldGuardHook;
|
|
}
|
|
|
|
public void reloadPluginConfig() {
|
|
configCache = new ConfigCache(this);
|
|
}
|
|
|
|
public void reloadPluginConfig(CommandSender commandSender) {
|
|
getServer().getAsyncScheduler().runNow(this, (task) -> {
|
|
reloadPluginConfig();
|
|
PluginMessages.sendMessage(commandSender, "PreventStabby configuration reloaded.");
|
|
});
|
|
}
|
|
|
|
public ConfigCache getConfigCache() {
|
|
return configCache;
|
|
}
|
|
|
|
public PlayerManager getPlayerManager() {
|
|
return playerManager;
|
|
}
|
|
|
|
public DatabaseSQLite getSqLite() {return sqLite;}
|
|
|
|
public static PreventStabby getPlugin() {
|
|
return plugin;
|
|
}
|
|
|
|
}
|