mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-26 15:03:26 +00:00
Add support for Velocity
This commit is contained in:
40 files changed
+2399
-154
No files matched your search
@@ -202,10 +202,6 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap {
|
||||
return this.spongeScheduler;
|
||||
}
|
||||
|
||||
public Path getConfigPath() {
|
||||
return this.configDirectory;
|
||||
}
|
||||
|
||||
public PluginContainer getPluginContainer() {
|
||||
return this.pluginContainer;
|
||||
}
|
||||
|
||||
@@ -222,10 +222,10 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
|
||||
}
|
||||
|
||||
private Path resolveConfig() {
|
||||
Path path = this.bootstrap.getConfigPath().resolve("luckperms.conf");
|
||||
Path path = this.bootstrap.getConfigDirectory().resolve("luckperms.conf");
|
||||
if (!Files.exists(path)) {
|
||||
try {
|
||||
MoreFiles.createDirectoriesIfNotExists(this.bootstrap.getConfigPath());
|
||||
MoreFiles.createDirectoriesIfNotExists(this.bootstrap.getConfigDirectory());
|
||||
try (InputStream is = getClass().getClassLoader().getResourceAsStream("luckperms.conf")) {
|
||||
Files.copy(is, path);
|
||||
}
|
||||
|
||||
@@ -25,98 +25,23 @@
|
||||
|
||||
package me.lucko.luckperms.sponge;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.common.config.adapter.AbstractConfigurationAdapter;
|
||||
import me.lucko.luckperms.common.config.adapter.ConfigurateConfigAdapter;
|
||||
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
||||
import ninja.leaping.configurate.loader.ConfigurationLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SpongeConfigAdapter extends AbstractConfigurationAdapter implements ConfigurationAdapter {
|
||||
|
||||
private final Path path;
|
||||
private ConfigurationNode root;
|
||||
|
||||
public class SpongeConfigAdapter extends ConfigurateConfigAdapter implements ConfigurationAdapter {
|
||||
public SpongeConfigAdapter(LuckPermsPlugin plugin, Path path) {
|
||||
super(plugin);
|
||||
this.path = path;
|
||||
reload();
|
||||
super(plugin, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(this.path).build();
|
||||
|
||||
try {
|
||||
this.root = loader.load();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurationNode resolvePath(String path) {
|
||||
if (this.root == null) {
|
||||
throw new RuntimeException("Config is not loaded.");
|
||||
}
|
||||
|
||||
return this.root.getNode(Splitter.on('.').splitToList(path).toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String path, String def) {
|
||||
return resolvePath(path).getString(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String path, int def) {
|
||||
return resolvePath(path).getInt(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String path, boolean def) {
|
||||
return resolvePath(path).getBoolean(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getList(String path, List<String> def) {
|
||||
ConfigurationNode node = resolvePath(path);
|
||||
if (node.isVirtual()) {
|
||||
return def;
|
||||
}
|
||||
|
||||
return node.getList(Object::toString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getKeys(String path, List<String> def) {
|
||||
ConfigurationNode node = resolvePath(path);
|
||||
if (node.isVirtual()) {
|
||||
return def;
|
||||
}
|
||||
|
||||
return node.getChildrenMap().keySet().stream().map(Object::toString).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, String> getMap(String path, Map<String, String> def) {
|
||||
ConfigurationNode node = resolvePath(path);
|
||||
if (node.isVirtual()) {
|
||||
return def;
|
||||
}
|
||||
|
||||
Map<String, Object> m = (Map<String, Object>) node.getValue(Collections.emptyMap());
|
||||
return m.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().toString()));
|
||||
protected ConfigurationLoader<? extends ConfigurationNode> createLoader(Path path) {
|
||||
return HoconConfigurationLoader.builder().setPath(path).build();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -47,7 +47,7 @@ import javax.annotation.Nonnull;
|
||||
/**
|
||||
* An implementation of {@link Messenger} using the plugin messaging channels.
|
||||
*/
|
||||
public class BungeeMessenger implements Messenger, RawDataListener {
|
||||
public class PluginMessageMessenger implements Messenger, RawDataListener {
|
||||
private static final String CHANNEL = "luckperms:update";
|
||||
|
||||
private final LPSpongePlugin plugin;
|
||||
@@ -55,7 +55,7 @@ public class BungeeMessenger implements Messenger, RawDataListener {
|
||||
|
||||
private ChannelBinding.RawDataChannel channel = null;
|
||||
|
||||
public BungeeMessenger(LPSpongePlugin plugin, IncomingMessageConsumer consumer) {
|
||||
public PluginMessageMessenger(LPSpongePlugin plugin, IncomingMessageConsumer consumer) {
|
||||
this.plugin = plugin;
|
||||
this.consumer = consumer;
|
||||
}
|
||||
+7
-7
@@ -42,9 +42,9 @@ public class SpongeMessagingFactory extends MessagingFactory<LPSpongePlugin> {
|
||||
|
||||
@Override
|
||||
protected InternalMessagingService getServiceFor(String messagingType) {
|
||||
if (messagingType.equals("bungee")) {
|
||||
if (messagingType.equals("pluginmsg") || messagingType.equals("bungee") || messagingType.equals("velocity")) {
|
||||
try {
|
||||
return new LuckPermsMessagingService(getPlugin(), new BungeeMessengerProvider());
|
||||
return new LuckPermsMessagingService(getPlugin(), new PluginMessageMessengerProvider());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -53,20 +53,20 @@ public class SpongeMessagingFactory extends MessagingFactory<LPSpongePlugin> {
|
||||
return super.getServiceFor(messagingType);
|
||||
}
|
||||
|
||||
private class BungeeMessengerProvider implements MessengerProvider {
|
||||
private class PluginMessageMessengerProvider implements MessengerProvider {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Bungee";
|
||||
return "PluginMessage";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Messenger obtain(@Nonnull IncomingMessageConsumer incomingMessageConsumer) {
|
||||
BungeeMessenger bungeeMessaging = new BungeeMessenger(getPlugin(), incomingMessageConsumer);
|
||||
bungeeMessaging.init();
|
||||
return bungeeMessaging;
|
||||
PluginMessageMessenger messenger = new PluginMessageMessenger(getPlugin(), incomingMessageConsumer);
|
||||
messenger.init();
|
||||
return messenger;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user