Support for kick message
This commit is contained in:
parent
3b6160c91f
commit
2d10e77b6c
@ -16,18 +16,22 @@ public class MiniMessageUtils {
|
|||||||
private static final char SECTION_CHAR = '§';
|
private static final char SECTION_CHAR = '§';
|
||||||
private static final char AMPERSAND_CHAR = '&';
|
private static final char AMPERSAND_CHAR = '&';
|
||||||
private static final boolean HEX_SUPPORTED = Utils.MAJOR_VERSION >= 16;
|
private static final boolean HEX_SUPPORTED = Utils.MAJOR_VERSION >= 16;
|
||||||
|
private static Class<?> componentClass;
|
||||||
private static Method methodDisallow;
|
private static Method methodDisallow;
|
||||||
private static Method methodKick;
|
private static Method methodKick;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
Class<?> componentClass = Class.forName("net{}kyori{}adventure{}text{}Component".replace("{}", "."));
|
componentClass = Class.forName("net{}kyori{}adventure{}text{}Component".replace("{}", "."));
|
||||||
|
} catch (Exception e) {
|
||||||
|
componentClass = null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
methodDisallow = AsyncPlayerPreLoginEvent.class.getMethod("disallow", AsyncPlayerPreLoginEvent.Result.class, componentClass);
|
methodDisallow = AsyncPlayerPreLoginEvent.class.getMethod("disallow", AsyncPlayerPreLoginEvent.Result.class, componentClass);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
methodDisallow = null;
|
methodDisallow = null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Class<?> componentClass = Class.forName("net{}kyori{}adventure{}text{}Component".replace("{}", "."));
|
|
||||||
methodKick = Player.class.getMethod("kick", componentClass);
|
methodKick = Player.class.getMethod("kick", componentClass);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
methodKick = null;
|
methodKick = null;
|
||||||
@ -54,10 +58,17 @@ public class MiniMessageUtils {
|
|||||||
return miniMessage.deserialize(convertLegacyToMiniMessage(message, false, SECTION_CHAR, HEX_SUPPORTED));
|
return miniMessage.deserialize(convertLegacyToMiniMessage(message, false, SECTION_CHAR, HEX_SUPPORTED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kicks a player with the given message.
|
||||||
|
*
|
||||||
|
* @param player the player to kick
|
||||||
|
* @param message the message to send
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
public static void kickPlayer(Player player, Component message) {
|
public static void kickPlayer(Player player, Component message) {
|
||||||
if (methodKick != null) {
|
if (methodKick != null) {
|
||||||
try {
|
try {
|
||||||
methodKick.invoke(player, message);
|
methodKick.invoke(player, componentClass.cast((Object) message));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
player.kickPlayer(LegacyComponentSerializer.legacySection().serialize(message));
|
player.kickPlayer(LegacyComponentSerializer.legacySection().serialize(message));
|
||||||
}
|
}
|
||||||
@ -73,11 +84,12 @@ public class MiniMessageUtils {
|
|||||||
* @param result the event result to set
|
* @param result the event result to set
|
||||||
* @param message the denial message
|
* @param message the denial message
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
public static void disallowPreLoginEvent(AsyncPlayerPreLoginEvent event,
|
public static void disallowPreLoginEvent(AsyncPlayerPreLoginEvent event,
|
||||||
AsyncPlayerPreLoginEvent.Result result, Component message) {
|
AsyncPlayerPreLoginEvent.Result result, Component message) {
|
||||||
if (methodDisallow != null) {
|
if (methodDisallow != null) {
|
||||||
try {
|
try {
|
||||||
methodDisallow.invoke(event, result, message);
|
methodDisallow.invoke(event, result, componentClass.cast((Object) message));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
event.disallow(result, LegacyComponentSerializer.legacySection().serialize(message));
|
event.disallow(result, LegacyComponentSerializer.legacySection().serialize(message));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user