diff --git a/build.gradle b/build.gradle index 00fe1c7a1..b09eba260 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,5 @@ subprojects { mavenCentral() maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } maven { url 'https://repo.lucko.me/' } - mavenLocal() } } diff --git a/nukkit/build.gradle b/nukkit/build.gradle index 2083a82d7..8e2c00327 100644 --- a/nukkit/build.gradle +++ b/nukkit/build.gradle @@ -3,6 +3,7 @@ plugins { } repositories { + mavenLocal() maven { url 'https://repo.potestas.xyz/main/' } } diff --git a/velocity/build.gradle b/velocity/build.gradle index b9f6a2f9a..3bf6bd768 100644 --- a/velocity/build.gradle +++ b/velocity/build.gradle @@ -10,12 +10,8 @@ repositories { dependencies { compile project(':common') - compileOnly('com.velocitypowered:velocity-api:1.0-SNAPSHOT') { - exclude(module: 'text') - } - annotationProcessor('com.velocitypowered:velocity-api:1.0-SNAPSHOT') { - exclude(module: 'text') - } + compileOnly 'com.velocitypowered:velocity-api:1.0-SNAPSHOT' + annotationProcessor 'com.velocitypowered:velocity-api:1.0-SNAPSHOT' } blossom { @@ -30,7 +26,7 @@ shadowJar { include(dependency('me.lucko.luckperms:.*')) } - relocate 'net.kyori.text', 'me.lucko.luckperms.lib.text' + //relocate 'net.kyori.text', 'me.lucko.luckperms.lib.text' relocate 'net.kyori.event', 'me.lucko.luckperms.lib.eventbus' relocate 'com.github.benmanes.caffeine', 'me.lucko.luckperms.lib.caffeine' relocate 'okio', 'me.lucko.luckperms.lib.okio' diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java b/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java index 5d81267f9..1018a2cf1 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java @@ -94,9 +94,15 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin { @Override protected Set getGlobalDependencies() { Set dependencies = super.getGlobalDependencies(); + // required for loading the LP config dependencies.add(Dependency.CONFIGURATE_CORE); dependencies.add(Dependency.CONFIGURATE_YAML); dependencies.add(Dependency.SNAKEYAML); + + // already included in the proxy + dependencies.remove(Dependency.TEXT); + dependencies.remove(Dependency.TEXT_SERIALIZER_GSON); + dependencies.remove(Dependency.TEXT_SERIALIZER_LEGACY); return dependencies; } diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityComponentUtils.java b/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityComponentUtils.java deleted file mode 100644 index 255a47bab..000000000 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityComponentUtils.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.velocity; - -import com.velocitypowered.api.command.CommandSource; -import com.velocitypowered.api.event.ResultedEvent; - -import net.kyori.text.Component; -import net.kyori.text.serializer.gson.GsonComponentSerializer; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * Utility for handling text components on Velocity. - * - *

Velocity bundles an old, incompatible version of the text library used by LuckPerms. - * The package remains the same - so we have to use this reflection hack to convert our - * relocated Component object to one Velocity will accept.

- */ -public class VelocityComponentUtils { - private static final String KYORI_TEXT_PACKAGE_NO_RELOCATION = "net#kyori#text#".replace("#", "."); - private static final Class COMPONENT_CLASS; - private static final Method DESERIALIZE_METHOD; - private static final Object SERIALIZER; - - private static final Method SEND_MESSAGE_METHOD; - private static final Method COMPONENT_RESULT_DENIED_CONSTRUCTOR; - - static { - try { - COMPONENT_CLASS = kyoriClass("Component"); - Class componentSerializerClass = kyoriClass("serializer.ComponentSerializer"); - Class componentSerializersClass = kyoriClass("serializer.ComponentSerializers"); - DESERIALIZE_METHOD = componentSerializerClass.getMethod("deserialize", Object.class); - Field jsonSerializerField = componentSerializersClass.getField("JSON"); - SERIALIZER = jsonSerializerField.get(null); - - SEND_MESSAGE_METHOD = CommandSource.class.getMethod("sendMessage", COMPONENT_CLASS); - COMPONENT_RESULT_DENIED_CONSTRUCTOR = ResultedEvent.ComponentResult.class.getMethod("denied", COMPONENT_CLASS); - } catch (Exception e) { - throw new ExceptionInInitializerError(e); - } - } - - private static Class kyoriClass(String name) throws ClassNotFoundException { - return Class.forName(KYORI_TEXT_PACKAGE_NO_RELOCATION + name); - } - - private static Object convertComponent(Component component) { - String json = GsonComponentSerializer.INSTANCE.serialize(component); - try { - return DESERIALIZE_METHOD.invoke(SERIALIZER, json); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } - - public static void sendMessage(CommandSource source, Component message) { - try { - SEND_MESSAGE_METHOD.invoke(source, convertComponent(message)); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } - - public static ResultedEvent.ComponentResult createDeniedResult(Component component) { - try { - return (ResultedEvent.ComponentResult) COMPONENT_RESULT_DENIED_CONSTRUCTOR.invoke(null, convertComponent(component)); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } - -} diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/VelocitySenderFactory.java b/velocity/src/main/java/me/lucko/luckperms/velocity/VelocitySenderFactory.java index 60ce43986..a1713f06e 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/VelocitySenderFactory.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/VelocitySenderFactory.java @@ -67,7 +67,7 @@ public class VelocitySenderFactory extends SenderFactory { @Override protected void sendMessage(CommandSource source, Component message) { - VelocityComponentUtils.sendMessage(source, message); + source.sendMessage(message); } @Override diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/VelocityConnectionListener.java b/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/VelocityConnectionListener.java index f87bd9260..8c77dd6be 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/VelocityConnectionListener.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/VelocityConnectionListener.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.velocity.listeners; import com.velocitypowered.api.event.PostOrder; +import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.LoginEvent; @@ -37,7 +38,6 @@ import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener; import me.lucko.luckperms.velocity.LPVelocityPlugin; -import me.lucko.luckperms.velocity.VelocityComponentUtils; import me.lucko.luckperms.velocity.service.PlayerPermissionProvider; import java.util.Collections; @@ -105,7 +105,7 @@ public class VelocityConnectionListener extends AbstractConnectionListener { @Subscribe(order = PostOrder.FIRST) public void onPlayerLogin(LoginEvent e) { if (this.deniedLogin.remove(e.getPlayer().getUniqueId())) { - e.setResult(VelocityComponentUtils.createDeniedResult(Message.LOADING_DATABASE_ERROR.asComponent(this.plugin.getLocaleManager()))); + e.setResult(ResultedEvent.ComponentResult.denied(Message.LOADING_DATABASE_ERROR.asComponent(this.plugin.getLocaleManager()))); } } @@ -133,7 +133,7 @@ public class VelocityConnectionListener extends AbstractConnectionListener { if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) { // disconnect the user - e.setResult(VelocityComponentUtils.createDeniedResult(Message.LOADING_STATE_ERROR.asComponent(this.plugin.getLocaleManager()))); + e.setResult(ResultedEvent.ComponentResult.denied(Message.LOADING_STATE_ERROR.asComponent(this.plugin.getLocaleManager()))); } else { // just send a message this.plugin.getBootstrap().getScheduler().asyncLater(() -> {