76 lines
2.3 KiB
Java
76 lines
2.3 KiB
Java
package net.kuraczyk.banhammer;
|
|
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import net.kuraczyk.banhammer.utils.*;
|
|
import net.kuraczyk.banhammer.cmds.*;
|
|
import net.kuraczyk.banhammer.events.*;
|
|
import org.yaml.snakeyaml.Yaml;
|
|
|
|
import java.io.File;
|
|
|
|
public final class BanHammer extends JavaPlugin {
|
|
|
|
public FileConfiguration config;
|
|
public FileConfiguration translations;
|
|
public DBManager db;
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
saveDefaultConfig();
|
|
config = getConfig();
|
|
|
|
saveResource("translations.yml", false);
|
|
translations = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "translations.yml"));
|
|
|
|
try {
|
|
Class.forName("net.kuraczyk.libs.postgresql.Driver");
|
|
} catch (ClassNotFoundException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
db = new DBManager(
|
|
config.getString("database.host"),
|
|
config.getInt("database.port"),
|
|
config.getString("database.user"),
|
|
config.getString("database.pass"),
|
|
config.getString("database.database"),
|
|
this.getClassLoader()
|
|
);
|
|
String error = db.connect();
|
|
if(error != null){
|
|
getLogger().severe(
|
|
"Failed to connect to DB!!!!\n"
|
|
+error
|
|
);
|
|
getServer().getPluginManager().disablePlugin(this);
|
|
}
|
|
|
|
getLogger().info(ChatColor.translateAlternateColorCodes('&', "&a&b+&r&8 | &aBan&7Hammer"));
|
|
|
|
new Ban(this);
|
|
new Unban(this);
|
|
new BanIP(this);
|
|
new UnbanIP(this);
|
|
new BHConfig(this);
|
|
|
|
getServer().getPluginManager().registerEvents(new PlayerPreLogin(this), this);
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
if(db != null){
|
|
String error = db.disconnect();
|
|
if(error != null) {
|
|
getLogger().severe(
|
|
"Error occured while disconnecting from from DB!!!!\n"
|
|
+error
|
|
);
|
|
}
|
|
}
|
|
|
|
getLogger().info(ChatColor.translateAlternateColorCodes('&', "&c&b-&r&8 | &aBan&7Hammer"));
|
|
}
|
|
}
|