159 lines
4.8 KiB
Java
159 lines
4.8 KiB
Java
package xyz.etztech.deluxegroups;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.OfflinePlayer;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
import org.dynmap.DynmapAPI;
|
|
import xyz.etztech.core.api.IMinecraftManager;
|
|
import xyz.etztech.deluxegroups.command.CommandGroup;
|
|
import xyz.etztech.deluxegroups.command.CommandMain;
|
|
import xyz.etztech.deluxegroups.listeners.AsyncPlayerChatListener;
|
|
import xyz.etztech.deluxegroups.listeners.SessionListener;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.PrintWriter;
|
|
import java.util.*;
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
public class DeluxeGroups extends JavaPlugin {
|
|
|
|
private static DeluxeGroups instance;
|
|
|
|
public static FileConfiguration config;
|
|
private Logger log = Logger.getLogger( "Minecraft" );
|
|
private static Database database;
|
|
|
|
// Objects that can be reloaded
|
|
private AsyncPlayerChatListener chatListener;
|
|
|
|
// Dynmap API
|
|
private static DynmapAPI dynmap = null;
|
|
|
|
// MinecraftManager API
|
|
private static IMinecraftManager minecraftManager = null;
|
|
|
|
|
|
|
|
public void onEnable() {
|
|
|
|
instance = this;
|
|
database = new Database(this);
|
|
saveDefaultConfig();
|
|
reloadConfig();
|
|
|
|
try {
|
|
File logs = new File(getDataFolder().getAbsolutePath()+"/logs/");
|
|
logs.mkdir();
|
|
} catch (Exception e) {}
|
|
|
|
|
|
if (isEnabled()) {
|
|
|
|
// Dynmap integration
|
|
if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) {
|
|
dynmap = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap");
|
|
DeluxeUtil.setupDynmap(dynmap);
|
|
getServer().getPluginManager().registerEvents(new SessionListener(), this);
|
|
}
|
|
|
|
// MCM integration
|
|
if (Bukkit.getPluginManager().isPluginEnabled("MinecraftManager")) {
|
|
minecraftManager = (IMinecraftManager) Bukkit.getPluginManager().getPlugin("MinecraftManager");
|
|
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "IMPORTANT: Disabling MinecraftManager global logging. All global logging will be handled by DeluxeGroups.");
|
|
minecraftManager.logOverride(true);
|
|
}
|
|
|
|
// Add Commands
|
|
CommandMain cmdMain = new CommandMain(this);
|
|
this.getCommand("deluxegroups").setExecutor(cmdMain);
|
|
CommandGroup cmdGroup = new CommandGroup(this);
|
|
this.getCommand("group").setExecutor(cmdGroup);
|
|
|
|
|
|
|
|
// Add Listeners
|
|
chatListener = new AsyncPlayerChatListener(this);
|
|
getServer().getPluginManager().registerEvents(chatListener, this);
|
|
}
|
|
}
|
|
|
|
public void onDisable() {}
|
|
|
|
public void loadConfig() {
|
|
config = Bukkit.getPluginManager().getPlugin("DeluxeGroups").getConfig();
|
|
}
|
|
|
|
@Override
|
|
public void reloadConfig() {
|
|
super.reloadConfig();
|
|
loadConfig();
|
|
convertConfig();
|
|
if (chatListener != null) {
|
|
chatListener.reload();
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public boolean convertConfig() {
|
|
File groupf = new File(getDataFolder(), "groups.yml");
|
|
|
|
if (!groupf.exists()) {
|
|
return false;
|
|
}
|
|
log("Converting old groups.yml to H2.");
|
|
FileConfiguration groupConfig = new YamlConfiguration();
|
|
|
|
try {
|
|
groupConfig.load(groupf);
|
|
int loaded = 0;
|
|
DeluxeGroup group;
|
|
for (String key : groupConfig.getKeys(false)) {
|
|
group = new DeluxeGroup();
|
|
group.setName(groupConfig.getString(key + ".name"));
|
|
group.setPassword(groupConfig.getString(key + ".password"));
|
|
group.setPermanent(groupConfig.getBoolean(key + ".permanent"));
|
|
int id = database.addGroup(group);
|
|
for (String uuid : groupConfig.getStringList(key + ".players")) {
|
|
database.addPlayer(uuid, id);
|
|
}
|
|
loaded++;
|
|
}
|
|
log("Converted " + loaded + " groups to H2! The groups.yml will be deleted next time the server is stopped.");
|
|
groupf.deleteOnExit();
|
|
return true;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
public void log(String message) {
|
|
log.info( "[DeluxeGroups]: " + message );
|
|
}
|
|
|
|
public static DeluxeGroups getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
public static Database getDatabase() {
|
|
return database;
|
|
}
|
|
|
|
public static DynmapAPI getDynmap() {
|
|
return dynmap;
|
|
}
|
|
|
|
public static IMinecraftManager getMinecraftManager() {
|
|
return minecraftManager;
|
|
}
|
|
|
|
}
|
|
|