Skip to content

Commit

Permalink
fix: interactive messages on Spigot not working
Browse files Browse the repository at this point in the history
Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com>
  • Loading branch information
Thatsmusic99 committed Feb 14, 2024
1 parent bfb1c42 commit 2ff3cd6
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public boolean onCommand(
return true;
}

final var audience = CustomMessages.asAudience(sender);
final var helpHeader =
MiniMessage.miniMessage()
.deserialize(
Expand All @@ -182,7 +181,7 @@ public boolean onCommand(
commandList.getTotalPages())))
.build());

audience.sendMessage(helpHeader);
CustomMessages.sendMessage(sender, helpHeader);

for (final String command : commandList.getContentsInPage(page)) {
var commandUsage = CustomMessages.getComponent("Usages." + command);
Expand All @@ -206,7 +205,7 @@ public boolean onCommand(
Tag.selfClosingInserting(description))
.build());

audience.sendMessage(finalMessage);
CustomMessages.sendMessage(sender, finalMessage);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.niestrat99.advancedteleport.config.MainConfig;
import io.github.niestrat99.advancedteleport.extensions.ExPermission;

import io.papermc.lib.PaperLib;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.TextComponent;
Expand All @@ -18,6 +19,7 @@
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;

import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -93,15 +95,9 @@ private void getHomes(CommandSender sender, OfflinePlayer target, ImmutableColle
return;
}

final TextComponent body =
(TextComponent)
Component.join(
JoinConfiguration.commas(true),
homes.stream()
.map(
home ->
new Object[] {
home,
final TextComponent body = (TextComponent) Component.join(JoinConfiguration.commas(true),
homes.stream().map(home ->
new Object[] {home,
atPlayer.canAccessHome(home)
|| ExPermission
.hasPermissionOrStar(
Expand Down Expand Up @@ -149,7 +145,9 @@ private void getHomes(CommandSender sender, OfflinePlayer target, ImmutableColle

if (!body.content().isEmpty() || !body.children().isEmpty()) {
String text = CustomMessages.config.getString("Info.homes") + "<homes>";
CustomMessages.asAudience(sender).sendMessage(CustomMessages.translate(text, Placeholder.component("homes", body)));
final var component = CustomMessages.translate(text, Placeholder.component("homes", body));

CustomMessages.sendMessage(sender, component);
} else
CustomMessages.sendMessage(
sender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean onCommand(
);

if (requests.getTotalPages() > 1) {
CustomMessages.asAudience(player).sendMessage(component);
CustomMessages.sendMessage(player, component);
CustomMessages.sendMessage(player, "Info.multipleRequestsList");
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void onSuccess(Boolean data) {

@Override
public void onFail(@NotNull final Component message) {
CustomMessages.asAudience(sender).sendMessage(message);
CustomMessages.sendMessage(sender, message);
}
});
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static void sendWithHeader(
));

CustomMessages.sendMessage(player, "Info.multipleRequestAccept");
CustomMessages.asAudience(player).sendMessage(body);
CustomMessages.sendMessage(player, body);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void onSuccess(Location data) {

@Override
public void onFail(@NotNull final Component message) {
CustomMessages.asAudience(sender).sendMessage(message);
CustomMessages.sendMessage(sender, message);
}
});
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static void sendWarps(CommandSender sender) {

if (!body.content().isEmpty() || !body.children().isEmpty()) {
String text = CustomMessages.config.getString("Info.warps") + "<warps>";
CustomMessages.asAudience(sender).sendMessage(CustomMessages.translate(text, Placeholder.component("warps", body)));
CustomMessages.sendMessage(sender, CustomMessages.translate(text, Placeholder.component("warps", body)));
} else CustomMessages.sendMessage(sender, "Error.noWarps");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.kyori.adventure.title.Title;
Expand Down Expand Up @@ -67,9 +68,9 @@ public CustomMessages() throws Exception {

populate();

if (!PaperLib.isPaper()) {
//if (!PaperLib.isPaper()) {
audience = BukkitAudiences.create(CoreClass.getInstance());
}
//}
}

@Override
Expand Down Expand Up @@ -969,7 +970,19 @@ public void run() {
component.append(get(path, placeholders));

if (component.content().isEmpty() && component.children().isEmpty()) return;
asAudience(sender).sendMessage(component);
sendMessage(sender, component.asComponent());
}

@Contract(pure = true)
public static void sendMessage(@NotNull final CommandSender sender,
@NotNull final Component component) {

if (PaperLib.isPaper()) {
asAudience(sender).sendMessage(component);
} else {
BungeeComponentSerializer serializer = BungeeComponentSerializer.get();
sender.spigot().sendMessage(serializer.serialize(component));
}
}

@Contract(pure = true)
Expand Down Expand Up @@ -1065,13 +1078,13 @@ public static void failable(
@ApiStatus.Internal // TODO: maybe cache this?
@Contract(pure = true)
public static @NotNull Audience asAudience(@NotNull final CommandSender sender) {
if (!PaperLib.isPaper()) {
//if (!PaperLib.isPaper()) {
if (sender instanceof Player player) {
return audience.player(player);
} else return audience.sender(sender);
}
//}

return sender; // Paper already implements Audience
//return sender; // Paper already implements Audience
}

@ApiStatus.Internal // TODO: I think this works, need to double check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static TeleportRequest teleportTests(Player player, String[] args, String

if (requests.getTotalPages() > 1) {
CustomMessages.sendMessage(player, "Info.multipleRequestsList");
CustomMessages.asAudience(player).sendMessage(body);
CustomMessages.sendMessage(player, body);
}
}

Expand Down

0 comments on commit 2ff3cd6

Please sign in to comment.