diff --git a/bukkit/src/main/java/me/lucko/luckperms/BukkitConfig.java b/bukkit/src/main/java/me/lucko/luckperms/BukkitConfig.java index 5a847dcf..a916b257 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/BukkitConfig.java +++ b/bukkit/src/main/java/me/lucko/luckperms/BukkitConfig.java @@ -40,11 +40,6 @@ public class BukkitConfig implements LPConfiguration { return configuration.getString("server", "global"); } - @Override - public String getPrefix() { - return configuration.getString("prefix", "&7&l[&b&lL&a&lP&7&l] &c"); - } - @Override public int getSyncTime() { return configuration.getInt("sql.sync-minutes", 3); diff --git a/bukkit/src/main/java/me/lucko/luckperms/listeners/PlayerListener.java b/bukkit/src/main/java/me/lucko/luckperms/listeners/PlayerListener.java index 52ac0f5c..f4313040 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/listeners/PlayerListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/listeners/PlayerListener.java @@ -2,6 +2,7 @@ package me.lucko.luckperms.listeners; import lombok.AllArgsConstructor; import me.lucko.luckperms.LPBukkitPlugin; +import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.users.BukkitUser; import me.lucko.luckperms.users.User; import org.bukkit.ChatColor; @@ -20,8 +21,8 @@ public class PlayerListener implements Listener { @EventHandler public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) { if (!plugin.getDatastore().isAcceptingLogins()) { - e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, color(plugin.getConfiguration().getPrefix() + - "&cError whilst validating login with the network. \nPlease contact an administrator.")); + e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, + color(Util.PREFIX + "Error whilst validating login with the network. \nPlease contact an administrator.")); return; } plugin.getDatastore().loadOrCreateUser(e.getUniqueId(), e.getName()); @@ -33,8 +34,8 @@ public class PlayerListener implements Listener { User user = plugin.getUserManager().getUser(player.getUniqueId()); if (user == null) { - e.disallow(PlayerLoginEvent.Result.KICK_OTHER, color(plugin.getConfiguration().getPrefix() + - "&cUser data could not be loaded. Please contact an administrator.")); + e.disallow(PlayerLoginEvent.Result.KICK_OTHER, + color(Util.PREFIX + "User data could not be loaded. Please contact an administrator.")); return; } diff --git a/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUser.java b/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUser.java index 690240d6..3369205c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUser.java +++ b/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUser.java @@ -30,23 +30,25 @@ public class BukkitUser extends User { @Override public void refreshPermissions() { - Player player = Bukkit.getPlayer(getUuid()); - if (player == null) return; + plugin.doSync(() -> { + Player player = Bukkit.getPlayer(getUuid()); + if (player == null) return; - if (attachment == null) { - getPlugin().getLogger().warning("User " + getName() + " does not have a permissions attachment defined."); - setAttachment(player.addAttachment(plugin)); - } + if (attachment == null) { + getPlugin().getLogger().warning("User " + getName() + " does not have a permissions attachment defined."); + setAttachment(player.addAttachment(plugin)); + } - // Clear existing permissions - for (String p : attachment.getPermissions().keySet()) { - attachment.setPermission(p, false); - } + // Clear existing permissions + for (String p : attachment.getPermissions().keySet()) { + attachment.setPermission(p, false); + } - // Re-add all defined permissions for the user - Map local = getLocalPermissions(getPlugin().getConfiguration().getServer(), null); - for (String node : local.keySet()) { - attachment.setPermission(node, local.get(node)); - } + // Re-add all defined permissions for the user + Map local = getLocalPermissions(getPlugin().getConfiguration().getServer(), null); + for (String node : local.keySet()) { + attachment.setPermission(node, local.get(node)); + } + }); } } diff --git a/bukkit/src/main/resources/config.yml b/bukkit/src/main/resources/config.yml index 718ac0e4..cce75a73 100644 --- a/bukkit/src/main/resources/config.yml +++ b/bukkit/src/main/resources/config.yml @@ -9,8 +9,6 @@ default-group: default # If users on this server should have their global permissions/groups applied. include-global: true -prefix: '&7&l[&b&lL&a&lP&7&l] &c' - # Which storage method the plugin should use. # Currently supported: mysql, sqlite, flatfile # Fill out connection info below if you're using MySQL diff --git a/bungee/src/main/java/me/lucko/luckperms/BungeeConfig.java b/bungee/src/main/java/me/lucko/luckperms/BungeeConfig.java index c1d021c3..b3185f0a 100644 --- a/bungee/src/main/java/me/lucko/luckperms/BungeeConfig.java +++ b/bungee/src/main/java/me/lucko/luckperms/BungeeConfig.java @@ -41,17 +41,11 @@ public class BungeeConfig implements LPConfiguration { return cfg; } - @Override public String getServer() { return configuration.getString("server", "bungee"); } - @Override - public String getPrefix() { - return configuration.getString("prefix", "&7&l[&b&lL&a&lP&7&l] &c"); - } - @Override public int getSyncTime() { return configuration.getInt("sql.sync-minutes", 3); diff --git a/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java index 512cf8f2..1a088c1e 100644 --- a/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java @@ -6,7 +6,6 @@ import me.lucko.luckperms.data.Datastore; import me.lucko.luckperms.data.MySQLConfiguration; import me.lucko.luckperms.data.methods.FlatfileDatastore; import me.lucko.luckperms.data.methods.MySQLDatastore; -import me.lucko.luckperms.data.methods.SQLiteDatastore; import me.lucko.luckperms.groups.GroupManager; import me.lucko.luckperms.listeners.PlayerListener; import me.lucko.luckperms.runnables.UpdateTask; @@ -15,7 +14,6 @@ import me.lucko.luckperms.users.UserManager; import me.lucko.luckperms.utils.LPConfiguration; import net.md_5.bungee.api.plugin.Plugin; -import java.io.File; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -48,15 +46,12 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { 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")); } else if (storageMethod.equalsIgnoreCase("flatfile")) { 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."); - datastore = new SQLiteDatastore(this, new File(getDataFolder(), "luckperms.sqlite")); + getLogger().warning("Storage method '" + storageMethod + "' was not recognised. Using Flatfile as fallback."); + datastore = new FlatfileDatastore(this, getDataFolder()); } datastore.init(); diff --git a/bungee/src/main/java/me/lucko/luckperms/listeners/PlayerListener.java b/bungee/src/main/java/me/lucko/luckperms/listeners/PlayerListener.java index b20d53b5..82e5e681 100644 --- a/bungee/src/main/java/me/lucko/luckperms/listeners/PlayerListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/listeners/PlayerListener.java @@ -11,6 +11,9 @@ import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; +import java.lang.ref.WeakReference; +import java.util.concurrent.TimeUnit; + @AllArgsConstructor public class PlayerListener implements Listener { @@ -22,14 +25,21 @@ public class PlayerListener implements Listener { plugin.getDatastore().loadOrCreateUser(player.getUniqueId(), player.getName(), success -> { if (!success) { - e.getPlayer().sendMessage(new TextComponent(Util.color("&e&l[LP] &cPermissions data could not be loaded. Please contact an administrator."))); + WeakReference p = new WeakReference<>(player); + plugin.getProxy().getScheduler().schedule(plugin, () -> { + ProxiedPlayer pl = p.get(); + if (pl != null) { + pl.sendMessage(new TextComponent(Util.color(Util.PREFIX + "Permissions data could not be loaded. Please contact an administrator."))); + } + }, 3, TimeUnit.SECONDS); + } else { User user = plugin.getUserManager().getUser(player.getUniqueId()); user.refreshPermissions(); } }); - plugin.getDatastore().saveUUIDData(e.getPlayer().getName(), e.getPlayer().getUniqueId(), success -> {}); + plugin.getDatastore().saveUUIDData(player.getName(), player.getUniqueId(), success -> {}); } @EventHandler diff --git a/bungee/src/main/resources/config.yml b/bungee/src/main/resources/config.yml index 884bc44e..c0d59ce8 100644 --- a/bungee/src/main/resources/config.yml +++ b/bungee/src/main/resources/config.yml @@ -9,12 +9,10 @@ default-group: default # If users on this server should have their global permissions/groups applied. include-global: false -prefix: '&7&l[&b&lL&a&lP&7&l] &c' - # Which storage method the plugin should use. -# Currently supported: mysql, sqlite, flatfile +# Currently supported: mysql & flatfile # Fill out connection info below if you're using MySQL -storage-method: sqlite +storage-method: flatfile sql: address: localhost:3306 diff --git a/common/src/main/java/me/lucko/luckperms/commands/Util.java b/common/src/main/java/me/lucko/luckperms/commands/Util.java index b532172e..7289b588 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/Util.java +++ b/common/src/main/java/me/lucko/luckperms/commands/Util.java @@ -6,9 +6,10 @@ import java.util.UUID; public class Util { + public static final String PREFIX = "&7&l[&b&lL&a&lP&7&l] &c"; + public static void sendPluginMessage(Sender sender, String message) { - // TODO: Pull the prefix from the config somehow - sender.sendMessage(color("&7&l[&b&lL&a&lP&7&l] &c" + message)); + sender.sendMessage(color(PREFIX + message)); } public static String color(String s) { diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfoCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfoCommand.java index 00f308a1..0c40c558 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfoCommand.java @@ -16,7 +16,7 @@ public class GroupInfoCommand extends GroupSubCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List args) { - final String prefix = plugin.getConfiguration().getPrefix(); + final String prefix = Util.PREFIX; String sb = prefix + "&d-> &eGroup: &6" + group.getName() + "\n" + prefix + "&d-> &ePermissions: &6" + group.getNodes().keySet().size() + "\n" + prefix + "&d-> &bUse &a/perms group " + group.getName() + " listnodes &bto see all permissions."; diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfoCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfoCommand.java index 2c1e0feb..84abcbbf 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfoCommand.java @@ -16,7 +16,7 @@ public class UserInfoCommand extends UserSubCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List args) { - final String prefix = plugin.getConfiguration().getPrefix(); + final String prefix = Util.PREFIX; String sb = prefix + "&d-> &eUser: &6" + user.getName() + "\n" + prefix + "&d-> &eUUID: &6" + user.getUuid() + "\n" + prefix + "&d-> &eStatus: " + plugin.getPlayerStatus(user.getUuid()) + "\n" + diff --git a/common/src/main/java/me/lucko/luckperms/data/methods/FlatfileDatastore.java b/common/src/main/java/me/lucko/luckperms/data/methods/FlatfileDatastore.java index fcabe0ca..b939c94a 100644 --- a/common/src/main/java/me/lucko/luckperms/data/methods/FlatfileDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/data/methods/FlatfileDatastore.java @@ -176,7 +176,7 @@ public class FlatfileDatastore extends Datastore { }); // User updating and loading should be done sync as permission attachments are updated - if (success) plugin.doSync(() -> plugin.getUserManager().updateOrSetUser(user)); + if (success) plugin.getUserManager().updateOrSetUser(user); return success; } @@ -210,8 +210,7 @@ public class FlatfileDatastore extends Datastore { return true; }); - // User updating and loading should be done sync as permission attachments are updated - if (success) plugin.doSync(() -> plugin.getUserManager().updateOrSetUser(user)); + if (success) plugin.getUserManager().updateOrSetUser(user); return success; } diff --git a/common/src/main/java/me/lucko/luckperms/data/methods/SQLDatastore.java b/common/src/main/java/me/lucko/luckperms/data/methods/SQLDatastore.java index 85bc9aa8..bb7f6177 100644 --- a/common/src/main/java/me/lucko/luckperms/data/methods/SQLDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/data/methods/SQLDatastore.java @@ -149,7 +149,7 @@ abstract class SQLDatastore extends Datastore { }); // User updating and loading should be done sync as permission attachments are updated - if (success) plugin.doSync(() -> plugin.getUserManager().updateOrSetUser(user)); + if (success) plugin.getUserManager().updateOrSetUser(user); return success; } @@ -191,7 +191,7 @@ abstract class SQLDatastore extends Datastore { }); // User updating and loading should be done sync as permission attachments are updated - if (success) plugin.doSync(() -> plugin.getUserManager().updateOrSetUser(user)); + if (success) plugin.getUserManager().updateOrSetUser(user); return success; } diff --git a/common/src/main/java/me/lucko/luckperms/utils/LPConfiguration.java b/common/src/main/java/me/lucko/luckperms/utils/LPConfiguration.java index 422e167d..0e589053 100644 --- a/common/src/main/java/me/lucko/luckperms/utils/LPConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/utils/LPConfiguration.java @@ -3,7 +3,6 @@ package me.lucko.luckperms.utils; public interface LPConfiguration { String getServer(); - String getPrefix(); int getSyncTime(); String getDefaultGroupNode(); String getDefaultGroupName();