mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-26 11:08:13 +01:00
Fix concurrency issue, remove sqlite from Bungee version and fix join message
This commit is contained in:
parent
d35774b401
commit
d855be1c65
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<String, Boolean> 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<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), null);
|
||||
for (String node : local.keySet()) {
|
||||
attachment.setPermission(node, local.get(node));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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<ProxiedPlayer> 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
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -16,7 +16,7 @@ public class GroupInfoCommand extends GroupSubCommand {
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> 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.";
|
||||
|
@ -16,7 +16,7 @@ public class UserInfoCommand extends UserSubCommand {
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> 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" +
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package me.lucko.luckperms.utils;
|
||||
public interface LPConfiguration {
|
||||
|
||||
String getServer();
|
||||
String getPrefix();
|
||||
int getSyncTime();
|
||||
String getDefaultGroupNode();
|
||||
String getDefaultGroupName();
|
||||
|
Loading…
Reference in New Issue
Block a user