forked from ChomeNS/chomens-bot-java
nullpointer netmsg fix?
This commit is contained in:
parent
257cbfcaed
commit
ef17bad953
1 changed files with 28 additions and 27 deletions
|
@ -4,7 +4,6 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
|
|||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -39,35 +38,37 @@ public class NetMessageCommand implements Command {
|
|||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
final Bot bot = context.bot();
|
||||
final List<Bot> bots = bot.bots();
|
||||
try {
|
||||
final Bot bot = context.bot();
|
||||
final List<Bot> bots = bot.bots();
|
||||
|
||||
final String hostAndPort = bot.host() + ":" + bot.port();
|
||||
final String hostAndPort = bot.host() + ":" + bot.port();
|
||||
|
||||
final Component component = Component.translatable(
|
||||
"[%s]%s%s%s› %s",
|
||||
Component
|
||||
.text(hostAndPort)
|
||||
.color(NamedTextColor.GRAY)
|
||||
.clickEvent(ClickEvent.copyToClipboard(hostAndPort))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.empty()
|
||||
.append(Component.text(hostAndPort).color(NamedTextColor.GRAY))
|
||||
.append(Component.newline())
|
||||
.append(Component.text("Click here to copy the server host and port to your clipboard").color(NamedTextColor.GREEN))
|
||||
)
|
||||
),
|
||||
Component.text(" "),
|
||||
context.sender().displayName().color(NamedTextColor.GRAY),
|
||||
Component.text(" "),
|
||||
Component.text(String.join(" ", args)).color(NamedTextColor.GRAY)
|
||||
).color(NamedTextColor.DARK_GRAY);
|
||||
final Component component = Component.translatable(
|
||||
"[%s]%s%s%s› %s",
|
||||
Component
|
||||
.text(hostAndPort)
|
||||
.color(NamedTextColor.GRAY)
|
||||
.clickEvent(ClickEvent.copyToClipboard(hostAndPort))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.empty()
|
||||
.append(Component.text(hostAndPort).color(NamedTextColor.GRAY))
|
||||
.append(Component.newline())
|
||||
.append(Component.text("Click here to copy the server host and port to your clipboard").color(NamedTextColor.GREEN))
|
||||
)
|
||||
),
|
||||
Component.text(" "),
|
||||
context.sender().displayName().color(NamedTextColor.GRAY),
|
||||
Component.text(" "),
|
||||
Component.text(String.join(" ", args)).color(NamedTextColor.GRAY)
|
||||
).color(NamedTextColor.DARK_GRAY);
|
||||
|
||||
for (Bot eachBot : bots) {
|
||||
if (!eachBot.loggedIn()) continue;
|
||||
eachBot.chat().tellraw(component);
|
||||
}
|
||||
for (Bot eachBot : bots) {
|
||||
if (!eachBot.loggedIn()) continue;
|
||||
eachBot.chat().tellraw(component);
|
||||
}
|
||||
} catch (Exception ignored) {} // lazy fix for the bot spamming nullpointers in console (mabe)
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue