Cleanup & multiple small fixes
This commit is contained in:
@@ -7,66 +7,49 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BukkitConfig implements LPConfiguration {
|
||||
private final LPBukkitPlugin plugin;
|
||||
class BukkitConfig extends LPConfiguration<LPBukkitPlugin> {
|
||||
private YamlConfiguration configuration;
|
||||
|
||||
public BukkitConfig(LPBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
create();
|
||||
BukkitConfig(LPBukkitPlugin plugin) {
|
||||
super(plugin, "global", true, "sqlite");
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private void create() {
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
@Override
|
||||
protected void init() {
|
||||
File configFile = new File(getPlugin().getDataFolder(), "config.yml");
|
||||
|
||||
if (!configFile.exists()) {
|
||||
configFile.getParentFile().mkdirs();
|
||||
plugin.saveResource("config.yml", false);
|
||||
getPlugin().saveResource("config.yml", false);
|
||||
}
|
||||
|
||||
configuration = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
configuration.load(configFile);
|
||||
|
||||
} catch (InvalidConfigurationException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
return configuration.getString("server", "global");
|
||||
protected void set(String path, Object value) {
|
||||
configuration.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSyncTime() {
|
||||
return configuration.getInt("sql.sync-minutes", 3);
|
||||
protected String getString(String path, String def) {
|
||||
return configuration.getString(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultGroupNode() {
|
||||
return "group." + configuration.getString("default-group", "default");
|
||||
protected int getInt(String path, int def) {
|
||||
return configuration.getInt(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultGroupName() {
|
||||
return configuration.getString("default-group", "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalPerms() {
|
||||
return configuration.getBoolean("include-global", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDatabaseValue(String value) {
|
||||
return configuration.getString("sql." + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStorageMethod() {
|
||||
return configuration.getString("storage-method", "sqlite");
|
||||
protected boolean getBoolean(String path, boolean def) {
|
||||
return configuration.getBoolean(path, def);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("Loading configuration...");
|
||||
configuration = new BukkitConfig(this);
|
||||
|
||||
// register events
|
||||
@@ -45,14 +46,15 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
pm.registerEvents(new PlayerListener(this), this);
|
||||
|
||||
// register commands
|
||||
getLogger().info("Registering commands...");
|
||||
CommandManagerBukkit commandManager = new CommandManagerBukkit(this);
|
||||
PluginCommand main = getServer().getPluginCommand("luckperms");
|
||||
main.setExecutor(commandManager);
|
||||
main.setTabCompleter(commandManager);
|
||||
main.setAliases(Arrays.asList("perms", "lp", "permissions", "p", "perm"));
|
||||
|
||||
getLogger().info("Detecting storage method...");
|
||||
final String storageMethod = configuration.getStorageMethod();
|
||||
|
||||
if (storageMethod.equalsIgnoreCase("mysql")) {
|
||||
getLogger().info("Using MySQL as storage method.");
|
||||
datastore = new MySQLDatastore(this, new MySQLConfiguration(
|
||||
@@ -68,17 +70,20 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
getLogger().info("Using Flatfile (JSON) as storage method.");
|
||||
datastore = new FlatfileDatastore(this, getDataFolder());
|
||||
} else {
|
||||
getLogger().warning("Storage method '" + storageMethod + "' was not recognised. Using SQLite as fallback.");
|
||||
getLogger().severe("Storage method '" + storageMethod + "' was not recognised. Using SQLite as fallback.");
|
||||
datastore = new SQLiteDatastore(this, new File(getDataFolder(), "luckperms.sqlite"));
|
||||
}
|
||||
|
||||
getLogger().info("Initialising datastore...");
|
||||
datastore.init();
|
||||
|
||||
getLogger().info("Loading internal permission managers...");
|
||||
userManager = new BukkitUserManager(this);
|
||||
groupManager = new GroupManager(this);
|
||||
trackManager = new TrackManager(this);
|
||||
trackManager = new TrackManager();
|
||||
|
||||
// Run update task to refresh any online users
|
||||
getLogger().info("Scheduling Update Task to refresh any online users.");
|
||||
runUpdateTask();
|
||||
|
||||
int mins = getConfiguration().getSyncTime();
|
||||
@@ -88,13 +93,20 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
// Provide vault support
|
||||
if (getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||
VaultHook.hook(this);
|
||||
getLogger().info("Registered Vault permission & chat hook.");
|
||||
} else {
|
||||
getLogger().info("Vault not found.");
|
||||
getLogger().info("Attempting to hook into Vault...");
|
||||
try {
|
||||
if (getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||
VaultHook.hook(this);
|
||||
getLogger().info("Registered Vault permission & chat hook.");
|
||||
} else {
|
||||
getLogger().info("Vault not found.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getLogger().severe("Error occurred whilst hooking into Vault.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
getLogger().info("Successfully loaded.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,13 +16,14 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class PlayerListener implements Listener {
|
||||
private static final String KICK_MESSAGE = Util.color(Message.PREFIX + "User data could not be loaded. Please contact an administrator.");
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) {
|
||||
if (!plugin.getDatastore().isAcceptingLogins()) {
|
||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
|
||||
Util.color(Message.PREFIX + "Error whilst validating login with the network. \nPlease contact an administrator."));
|
||||
// Datastore is disabled, prevent players from joining the server
|
||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, KICK_MESSAGE);
|
||||
return;
|
||||
}
|
||||
plugin.getDatastore().loadOrCreateUser(e.getUniqueId(), e.getName());
|
||||
@@ -30,12 +31,11 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
User user = plugin.getUserManager().getUser(player.getUniqueId());
|
||||
final Player player = e.getPlayer();
|
||||
final User user = plugin.getUserManager().getUser(player.getUniqueId());
|
||||
|
||||
if (user == null) {
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||
Util.color(Message.PREFIX + "User data could not be loaded. Please contact an administrator."));
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, KICK_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PlayerListener implements Listener {
|
||||
// Save UUID data for the player
|
||||
plugin.getDatastore().saveUUIDData(e.getPlayer().getName(), e.getPlayer().getUniqueId(), success -> {});
|
||||
|
||||
User user = plugin.getUserManager().getUser(e.getPlayer().getUniqueId());
|
||||
final User user = plugin.getUserManager().getUser(e.getPlayer().getUniqueId());
|
||||
if (user != null) {
|
||||
// Refresh permissions again
|
||||
user.refreshPermissions();
|
||||
@@ -62,10 +62,10 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
final Player player = e.getPlayer();
|
||||
|
||||
// Unload the user from memory when they disconnect
|
||||
User user = plugin.getUserManager().getUser(player.getUniqueId());
|
||||
final User user = plugin.getUserManager().getUser(player.getUniqueId());
|
||||
plugin.getUserManager().unloadUser(user);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package me.lucko.luckperms.users;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
@@ -31,7 +30,7 @@ public class BukkitUser extends User {
|
||||
@Override
|
||||
public void refreshPermissions() {
|
||||
plugin.doSync(() -> {
|
||||
Player player = Bukkit.getPlayer(getUuid());
|
||||
final Player player = plugin.getServer().getPlayer(getUuid());
|
||||
if (player == null) return;
|
||||
|
||||
if (attachment == null) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package me.lucko.luckperms.users;
|
||||
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -22,7 +21,7 @@ public class BukkitUserManager extends UserManager {
|
||||
BukkitUser u = (BukkitUser) user;
|
||||
|
||||
if (u.getAttachment() != null) {
|
||||
Player player = Bukkit.getPlayer(u.getUuid());
|
||||
Player player = plugin.getServer().getPlayer(u.getUuid());
|
||||
|
||||
if (player != null) {
|
||||
player.removeAttachment(u.getAttachment());
|
||||
@@ -37,7 +36,7 @@ public class BukkitUserManager extends UserManager {
|
||||
|
||||
@Override
|
||||
public void cleanupUser(User user) {
|
||||
if (Bukkit.getPlayer(user.getUuid()) == null) {
|
||||
if (plugin.getServer().getPlayer(user.getUuid()) == null) {
|
||||
unloadUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user