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;
|
2016-06-30 03:09:34 +08:00
|
|
|
import me.lucko.luckperms.vaulthooks.VaultHook;
|
2016-05-22 08:57:10 +08:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.PluginCommand;
|
2016-07-17 20:18:43 +08:00
|
|
|
import org.bukkit.entity.Player;
|
2016-05-22 08:57:10 +08:00
|
|
|
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;
|
2016-07-17 20:18:43 +08:00
|
|
|
import java.util.List;
|
2016-05-22 08:57:10 +08:00
|
|
|
import java.util.UUID;
|
2016-07-17 20:18:43 +08:00
|
|
|
import java.util.stream.Collectors;
|
2016-05-22 08:57:10 +08:00
|
|
|
|
|
|
|
@Getter
|
|
|
|
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
2016-07-19 20:01:58 +08:00
|
|
|
public static final String VERSION = "v1.2";
|
2016-05-22 08:57:10 +08:00
|
|
|
|
|
|
|
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);
|
2016-07-17 20:18:43 +08:00
|
|
|
main.setTabCompleter(commandManager);
|
2016-05-22 08:57:10 +08:00
|
|
|
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
|
|
|
|
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
|
2016-06-30 03:09:34 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
|
2016-07-17 20:18:43 +08:00
|
|
|
@Override
|
|
|
|
public List<String> getPlayerList() {
|
|
|
|
return getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
|
2016-05-22 08:57:10 +08:00
|
|
|
@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
|
|
|
}
|
|
|
|
}
|