mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-09-09 12:38:01 +02:00
Update to expect Velocity shading text 3
This reverts the reflection workaround implemented in f49446011a
This commit is contained in:
parent
f49446011a
commit
d0c5d89e91
@ -59,6 +59,5 @@ subprojects {
|
||||
mavenCentral()
|
||||
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
|
||||
maven { url 'https://repo.lucko.me/' }
|
||||
mavenLocal()
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven { url 'https://repo.potestas.xyz/main/' }
|
||||
}
|
||||
|
||||
|
@ -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'
|
||||
|
@ -94,9 +94,15 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin {
|
||||
@Override
|
||||
protected Set<Dependency> getGlobalDependencies() {
|
||||
Set<Dependency> 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;
|
||||
}
|
||||
|
||||
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* 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.
|
||||
*
|
||||
* <p>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.</p>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -67,7 +67,7 @@ public class VelocitySenderFactory extends SenderFactory<CommandSource> {
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSource source, Component message) {
|
||||
VelocityComponentUtils.sendMessage(source, message);
|
||||
source.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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(() -> {
|
||||
|
Loading…
Reference in New Issue
Block a user