LuckPerms-DBA/bukkit/src/main/java/me/lucko/luckperms/LPBukkitPlugin.java

131 lines
4.5 KiB
Java
Raw Normal View History

2016-05-22 08:57:10 +08:00
package me.lucko.luckperms;
import lombok.Getter;
import me.lucko.luckperms.data.Datastore;
2016-06-22 23:47:54 +08:00
import me.lucko.luckperms.data.MySQLConfiguration;
2016-06-23 23:37:29 +08:00
import me.lucko.luckperms.data.methods.FlatfileDatastore;
2016-06-22 23:47:54 +08:00
import me.lucko.luckperms.data.methods.MySQLDatastore;
import me.lucko.luckperms.data.methods.SQLiteDatastore;
2016-05-22 08:57:10 +08:00
import me.lucko.luckperms.groups.GroupManager;
import me.lucko.luckperms.listeners.PlayerListener;
import me.lucko.luckperms.runnables.UpdateTask;
2016-07-16 05:44:25 +08:00
import me.lucko.luckperms.tracks.TrackManager;
2016-05-22 08:57:10 +08:00
import me.lucko.luckperms.users.BukkitUserManager;
import me.lucko.luckperms.users.UserManager;
import me.lucko.luckperms.utils.LPConfiguration;
import me.lucko.luckperms.vaulthooks.VaultHook;
2016-05-22 08:57:10 +08:00
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
2016-06-22 23:47:54 +08:00
import java.io.File;
2016-05-22 08:57:10 +08:00
import java.util.Arrays;
import java.util.UUID;
@Getter
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
public static final String VERSION = "v1.0";
private LPConfiguration configuration;
private UserManager userManager;
private GroupManager groupManager;
2016-07-16 05:44:25 +08:00
private TrackManager trackManager;
2016-05-22 08:57:10 +08:00
private Datastore datastore;
@Override
public void onEnable() {
configuration = new BukkitConfig(this);
// register events
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new PlayerListener(this), this);
// register commands
CommandManagerBukkit commandManager = new CommandManagerBukkit(this);
PluginCommand main = getServer().getPluginCommand("luckperms");
main.setExecutor(commandManager);
main.setAliases(Arrays.asList("perms", "lp", "permissions", "p", "perm"));
2016-06-22 23:47:54 +08:00
final String storageMethod = configuration.getStorageMethod();
if (storageMethod.equalsIgnoreCase("mysql")) {
getLogger().info("Using MySQL as storage method.");
datastore = new MySQLDatastore(this, new MySQLConfiguration(
configuration.getDatabaseValue("address"),
configuration.getDatabaseValue("database"),
configuration.getDatabaseValue("username"),
configuration.getDatabaseValue("password")
));
} else if (storageMethod.equalsIgnoreCase("sqlite")) {
getLogger().info("Using SQLite as storage method.");
datastore = new SQLiteDatastore(this, new File(getDataFolder(), "luckperms.sqlite"));
2016-06-23 23:37:29 +08:00
} else if (storageMethod.equalsIgnoreCase("flatfile")) {
getLogger().info("Using Flatfile (JSON) as storage method.");
datastore = new FlatfileDatastore(this, getDataFolder());
2016-06-22 23:47:54 +08:00
} else {
getLogger().warning("Storage method '" + storageMethod + "' was not recognised. Using SQLite as fallback.");
datastore = new SQLiteDatastore(this, new File(getDataFolder(), "luckperms.sqlite"));
}
datastore.init();
2016-05-22 08:57:10 +08:00
userManager = new BukkitUserManager(this);
groupManager = new GroupManager(this);
2016-07-16 05:44:25 +08:00
trackManager = new TrackManager(this);
2016-05-22 08:57:10 +08:00
// Run update task to refresh any online users
runUpdateTask();
2016-05-22 08:57:10 +08:00
int mins = getConfiguration().getSyncTime();
if (mins > 0) {
long ticks = mins * 60 * 20;
getServer().getScheduler().runTaskTimerAsynchronously(this, new UpdateTask(this), ticks, ticks);
2016-05-22 08:57:10 +08:00
}
// Provide vault support
if (getServer().getPluginManager().isPluginEnabled("Vault")) {
VaultHook.hook(this);
getLogger().info("Registered Vault permission & chat hook.");
} else {
getLogger().info("Vault not found.");
2016-05-22 08:57:10 +08:00
}
}
@Override
public void onDisable() {
datastore.shutdown();
}
2016-05-22 08:57:10 +08:00
@Override
public void doAsync(Runnable r) {
Bukkit.getScheduler().runTaskAsynchronously(this, r);
}
@Override
public void doSync(Runnable r) {
Bukkit.getScheduler().runTask(this, r);
}
@Override
public String getVersion() {
return VERSION;
}
@Override
public String getPlayerStatus(UUID uuid) {
2016-06-29 22:35:57 +08:00
return getServer().getPlayer(uuid) != null ? "&aOnline" : "&cOffline";
2016-05-22 08:57:10 +08:00
}
@Override
public int getPlayerCount() {
return getServer().getOnlinePlayers().size();
}
@Override
public void runUpdateTask() {
getServer().getScheduler().runTaskAsynchronously(this, new UpdateTask(this));
2016-05-22 08:57:10 +08:00
}
}