Skip to content

Commit

Permalink
GH-407 Add platform receiver. Fix rcon bukkit adventure platform bug. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi authored Jul 15, 2024
1 parent 6d1c02e commit 1d95ea3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.rollczi.litecommands.adventure.AdventureAudienceProvider;
import dev.rollczi.litecommands.identifier.Identifier;
import dev.rollczi.litecommands.invocation.Invocation;
import dev.rollczi.litecommands.platform.PlatformReceiver;
import dev.rollczi.litecommands.platform.PlatformSender;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.AudienceProvider;
Expand Down Expand Up @@ -39,6 +40,10 @@ public Audience sender(Invocation<SENDER> invocation) {
return audienceProvider.player(uuidOptional.get());
}

if (invocation.platformSender() instanceof PlatformReceiver) {
return new RawTextAudience((PlatformReceiver) invocation.platformSender());
}

throw new IllegalArgumentException("Unsupported command sender type: " + sender.getClass().getName() + " or missing identifier");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.rollczi.litecommands.adventure.bukkit.platform;

import dev.rollczi.litecommands.platform.PlatformReceiver;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

@ApiStatus.Experimental
class RawTextAudience implements Audience {

private final PlatformReceiver platformReceiver;

public RawTextAudience(PlatformReceiver platformReceiver) {
this.platformReceiver = platformReceiver;
}

@Override
public void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) {
platformReceiver.sendMessage(message.toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import dev.rollczi.litecommands.identifier.Identifier;
import dev.rollczi.litecommands.platform.AbstractPlatformSender;
import dev.rollczi.litecommands.platform.PlatformReceiver;
import org.bukkit.command.CommandSender;
import org.bukkit.command.RemoteConsoleCommandSender;
import org.bukkit.entity.Player;

class BukkitPlatformSender extends AbstractPlatformSender {
class BukkitPlatformSender extends AbstractPlatformSender implements PlatformReceiver {

private final CommandSender handle;

Expand Down Expand Up @@ -38,7 +40,18 @@ public Identifier getIdentifier() {
return Identifier.of(((Player) this.handle).getUniqueId());
}

if (this.handle instanceof RemoteConsoleCommandSender) {
RemoteConsoleCommandSender commandSender = (RemoteConsoleCommandSender) this.handle;
return Identifier.of(RemoteConsoleCommandSender.class, commandSender.getName());
}

return Identifier.CONSOLE;
}

@Override
public Comparable<Void> sendMessage(String message) {
this.handle.sendMessage(message);
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.rollczi.litecommands.platform;

import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Experimental
public interface PlatformReceiver {

@ApiStatus.Experimental
Comparable<Void> sendMessage(String message);

}

0 comments on commit 1d95ea3

Please sign in to comment.