Skip to content

Commit

Permalink
Only use paper message sender when adventure is not relocated
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs committed Nov 18, 2024
1 parent a0a582c commit 4739e45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
publishData {
addRepo(Repo.main("", "", false))
addRepo(Repo.snapshot("SNAPSHOT", "", false))
publishingVersion = "2.1.6"
publishingVersion = "2.1.7"
}
version = publishData.getVersion()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public static boolean isPaper() {
return hasClass("com.destroystokyo.paper.PaperConfig") || hasClass("io.papermc.paper.configuration.Configuration");
}

public static boolean isRelocated() {
String packageName = ReflectionUtil.class.getPackageName();
return packageName.startsWith(String.join("de", "eldoria", "eldoutilities"));
}

public static boolean hasClass(String clazz) {
try {
Class.forName(clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
import de.eldoria.eldoutilities.localization.ILocalizer;
import de.eldoria.eldoutilities.messages.impl.PaperMessageSender;
import de.eldoria.eldoutilities.messages.impl.SpigotMessageSender;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import org.bukkit.plugin.Plugin;
Expand All @@ -31,9 +28,9 @@
public class MessageSenderBuilder {
private final MiniMessage.Builder miniMessage = MiniMessage.builder();
private final TagResolver.Builder messageTagResolver = TagResolver.builder()
.tag("default", Tag.styling(NamedTextColor.GREEN));
.tag("default", Tag.styling(NamedTextColor.GREEN));
private final TagResolver.Builder errorTagResolver = TagResolver.builder()
.tag("default", Tag.styling(NamedTextColor.RED));
.tag("default", Tag.styling(NamedTextColor.RED));
private final TagResolver.Builder defaultTagResolver = TagResolver.builder();

@Nullable
Expand Down Expand Up @@ -65,7 +62,7 @@ public MessageSenderBuilder prefix(Component prefix) {

public MessageSenderBuilder prefix(String prefix) {
return prefix(MiniMessage.miniMessage()
.deserialize(prefix));
.deserialize(prefix));
}

public MessageSenderBuilder messageColor(TextColor color) {
Expand Down Expand Up @@ -120,24 +117,28 @@ public MessageSender register() {
.resolver(StandardTags.defaults())
.build();
MessageSender messageSender;
if (!isPaper()) {
if (!isPaper() || hasRelocatedAdventure()) {
messageSender = new SpigotMessageSender(plugin,
miniMessage.tags(defaultResolver)
.preProcessor(in -> preProcessor.apply(localizer.localize(in)))
.build(),
.preProcessor(in -> preProcessor.apply(localizer.localize(in)))
.build(),
TagResolver.resolver(defaultResolver, messageTagResolver.build()),
TagResolver.resolver(defaultResolver, errorTagResolver.build()),
prefix);
} else {
messageSender = new PaperMessageSender(plugin,
miniMessage.tags(defaultResolver)
.preProcessor(in -> preProcessor.apply(localizer.localize(in)))
.build(),
.preProcessor(in -> preProcessor.apply(localizer.localize(in)))
.build(),
TagResolver.resolver(defaultResolver, messageTagResolver.build()),
TagResolver.resolver(defaultResolver, errorTagResolver.build()),
prefix);
}
MessageSender.register(messageSender);
return messageSender;
}

public static boolean hasRelocatedAdventure() {
return !Component.class.getPackageName().startsWith(String.join("net", "kyori", "adventure", "text"));
}
}

0 comments on commit 4739e45

Please sign in to comment.