2016-05-22 08:57:10 +08:00
|
|
|
package me.lucko.luckperms;
|
|
|
|
|
2016-06-22 19:51:37 +08:00
|
|
|
import com.google.gson.Gson;
|
2016-05-22 08:57:10 +08:00
|
|
|
import lombok.Getter;
|
|
|
|
import me.lucko.luckperms.data.Datastore;
|
|
|
|
import me.lucko.luckperms.data.DatastoreConfiguration;
|
|
|
|
import me.lucko.luckperms.data.HikariDatastore;
|
|
|
|
import me.lucko.luckperms.groups.GroupManager;
|
|
|
|
import me.lucko.luckperms.listeners.PlayerListener;
|
|
|
|
import me.lucko.luckperms.runnables.UpdateTask;
|
|
|
|
import me.lucko.luckperms.users.BukkitUserManager;
|
|
|
|
import me.lucko.luckperms.users.UserManager;
|
|
|
|
import me.lucko.luckperms.utils.LPConfiguration;
|
|
|
|
import net.milkbowl.vault.permission.Permission;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.PluginCommand;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
import org.bukkit.plugin.ServicePriority;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
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;
|
|
|
|
private Datastore datastore;
|
2016-06-22 19:51:37 +08:00
|
|
|
private Gson gson;
|
2016-05-22 08:57:10 +08:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2016-06-22 19:51:37 +08:00
|
|
|
gson = new Gson();
|
2016-05-22 08:57:10 +08:00
|
|
|
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"));
|
|
|
|
|
|
|
|
datastore = new HikariDatastore(this);
|
|
|
|
datastore.init(new DatastoreConfiguration(
|
|
|
|
configuration.getDatabaseValue("address"),
|
|
|
|
configuration.getDatabaseValue("database"),
|
|
|
|
configuration.getDatabaseValue("username"),
|
|
|
|
configuration.getDatabaseValue("password")
|
|
|
|
));
|
|
|
|
|
|
|
|
userManager = new BukkitUserManager(this);
|
|
|
|
groupManager = new GroupManager(this);
|
|
|
|
|
2016-06-18 03:06:45 +08:00
|
|
|
// Run update task to refresh any online users
|
2016-06-18 06:23:28 +08:00
|
|
|
runUpdateTask();
|
2016-06-18 03:06:45 +08:00
|
|
|
|
2016-05-22 08:57:10 +08:00
|
|
|
int mins = getConfiguration().getSyncTime();
|
|
|
|
if (mins > 0) {
|
|
|
|
long ticks = mins * 60 * 20;
|
2016-06-18 06:23:28 +08:00
|
|
|
getServer().getScheduler().runTaskTimerAsynchronously(this, new UpdateTask(this), ticks, ticks);
|
2016-05-22 08:57:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Provide vault support
|
|
|
|
try {
|
|
|
|
if (getServer().getPluginManager().isPluginEnabled("Vault")) {
|
|
|
|
getServer().getServicesManager().register(Permission.class, new VaultHook(this), this, ServicePriority.High);
|
|
|
|
getLogger().info("Registered Vault permission hook.");
|
|
|
|
} else {
|
|
|
|
getLogger().info("Vault not found.");
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
getLogger().warning("Error whilst hooking into Vault.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-18 03:06:45 +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);
|
|
|
|
}
|
|
|
|
|
2016-06-22 19:51:37 +08:00
|
|
|
@Override
|
|
|
|
public Gson getGson() {
|
|
|
|
return gson;
|
|
|
|
}
|
|
|
|
|
2016-05-22 08:57:10 +08:00
|
|
|
@Override
|
|
|
|
public String getVersion() {
|
|
|
|
return VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getPlayerStatus(UUID uuid) {
|
|
|
|
if (getServer().getPlayer(uuid) != null) return "&aOnline";
|
|
|
|
return "&cOffline";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPlayerCount() {
|
|
|
|
return getServer().getOnlinePlayers().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void runUpdateTask() {
|
2016-06-18 06:23:28 +08:00
|
|
|
getServer().getScheduler().runTaskAsynchronously(this, new UpdateTask(this));
|
2016-05-22 08:57:10 +08:00
|
|
|
}
|
|
|
|
}
|