Cleanup & multiple small fixes
This commit is contained in:
@@ -10,30 +10,20 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class BungeeConfig implements LPConfiguration {
|
||||
private final LPBungeePlugin plugin;
|
||||
class BungeeConfig extends LPConfiguration<LPBungeePlugin> {
|
||||
private Configuration configuration;
|
||||
|
||||
public BungeeConfig(LPBungeePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
reload();
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
try {
|
||||
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(makeFile("config.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
BungeeConfig(LPBungeePlugin plugin) {
|
||||
super(plugin, "bungee", false, "flatfile");
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private File makeFile(String file) throws IOException {
|
||||
File cfg = new File(plugin.getDataFolder(), file);
|
||||
File cfg = new File(getPlugin().getDataFolder(), file);
|
||||
|
||||
if (!cfg.exists()) {
|
||||
plugin.getDataFolder().mkdir();
|
||||
try (InputStream is = plugin.getResourceAsStream(file)) {
|
||||
getPlugin().getDataFolder().mkdir();
|
||||
try (InputStream is = getPlugin().getResourceAsStream(file)) {
|
||||
Files.copy(is, cfg.toPath());
|
||||
}
|
||||
}
|
||||
@@ -42,37 +32,31 @@ public class BungeeConfig implements LPConfiguration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
return configuration.getString("server", "bungee");
|
||||
protected void init() {
|
||||
try {
|
||||
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(makeFile("config.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSyncTime() {
|
||||
return configuration.getInt("sql.sync-minutes", 3);
|
||||
protected void set(String path, Object value) {
|
||||
configuration.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultGroupNode() {
|
||||
return "group." + configuration.getString("default-group", "default");
|
||||
protected String getString(String path, String def) {
|
||||
return configuration.getString(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultGroupName() {
|
||||
return configuration.getString("default-group", "default");
|
||||
protected int getInt(String path, int def) {
|
||||
return configuration.getInt(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalPerms() {
|
||||
return configuration.getBoolean("include-global", false);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,19 +33,21 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("Loading configuration...");
|
||||
configuration = new BungeeConfig(this);
|
||||
|
||||
// register events
|
||||
getProxy().getPluginManager().registerListener(this, new PlayerListener(this));
|
||||
|
||||
// register commands
|
||||
getLogger().info("Registering commands...");
|
||||
getProxy().getPluginManager().registerCommand(this, new MainCommand(new CommandManager(this)));
|
||||
|
||||
// disable the default Bungee /perms command so it gets handled by the Bukkit plugin
|
||||
getProxy().getDisabledCommands().add("perms");
|
||||
|
||||
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(
|
||||
@@ -58,20 +60,28 @@ public class LPBungeePlugin extends Plugin 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 Flatfile as fallback.");
|
||||
getLogger().severe("Storage method '" + storageMethod + "' was not recognised. Using Flatfile as fallback.");
|
||||
datastore = new FlatfileDatastore(this, getDataFolder());
|
||||
}
|
||||
|
||||
getLogger().info("Initialising datastore...");
|
||||
datastore.init();
|
||||
|
||||
getLogger().info("Loading internal permission managers...");
|
||||
userManager = new BungeeUserManager(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();
|
||||
if (mins > 0) {
|
||||
getProxy().getScheduler().schedule(this, new UpdateTask(this), mins, mins, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
getLogger().info("Successfully loaded.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,6 @@ class MainCommand extends Command implements TabExecutor {
|
||||
public MainCommand(CommandManager manager) {
|
||||
super("luckpermsbungee", null, "bperms", "lpb", "bpermissions", "bp", "bperm");
|
||||
this.manager = manager;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,9 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
private static final TextComponent WARN_MESSAGE = new TextComponent(Util.color(
|
||||
Message.PREFIX + "Permissions data could not be loaded. Please contact an administrator.")
|
||||
);
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
@EventHandler
|
||||
@@ -25,12 +27,13 @@ public class PlayerListener implements Listener {
|
||||
final ProxiedPlayer player = e.getPlayer();
|
||||
final WeakReference<ProxiedPlayer> p = new WeakReference<>(player);
|
||||
|
||||
// Create user async and at post login. We're not concerned if data couldn't be loaded, the player won't be kicked.
|
||||
plugin.getDatastore().loadOrCreateUser(player.getUniqueId(), player.getName(), success -> {
|
||||
if (!success) {
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
final ProxiedPlayer pl = p.get();
|
||||
if (pl != null) {
|
||||
pl.sendMessage(new TextComponent(Util.color(Message.PREFIX + "Permissions data could not be loaded. Please contact an administrator.")));
|
||||
pl.sendMessage(WARN_MESSAGE);
|
||||
}
|
||||
}, 3, TimeUnit.SECONDS);
|
||||
|
||||
@@ -48,10 +51,10 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerDisconnectEvent e) {
|
||||
ProxiedPlayer player = e.getPlayer();
|
||||
final ProxiedPlayer 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user