kinda fix channel commands

This commit is contained in:
Draycia committed 2021-10-01 22:23:42 -07:00
1 parent d38b57f6a7
commit 3ba3dfc6e9
3 files changed
+21 -8

No files matched your search

@@ -117,7 +117,7 @@ public interface CarbonPlayer extends Audience, Identified {
* @param chatChannel the channel * @param chatChannel the channel
* @since 2.0.0 * @since 2.0.0
*/ */
void selectedChannel(final ChatChannel chatChannel); void selectedChannel(final @Nullable ChatChannel chatChannel);
/** /**
* Checks if the player has the specified permission. * Checks if the player has the specified permission.
@@ -168,9 +168,9 @@ public final class CarbonPlayerBukkit extends WrappedCarbonPlayer implements For
@Override @Override
public void sendMessageAsPlayer(final String message) { public void sendMessageAsPlayer(final String message) {
Bukkit.getScheduler().runTask(Bukkit.getPluginManager().getPlugin("CarbonChat"), () -> { // TODO: ensure method is not executed from main thread
Objects.requireNonNull(this.player()).chat(message); // bukkit doesn't like that
}); Objects.requireNonNull(this.player()).chat(message);
} }
@Override @Override
@@ -20,6 +20,7 @@ import net.draycia.carbon.common.config.ConfigLoader;
import net.draycia.carbon.common.config.PrimaryConfig; import net.draycia.carbon.common.config.PrimaryConfig;
import net.draycia.carbon.common.messages.CarbonMessageService; import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.registry.DefaultedRegistry; import net.kyori.registry.DefaultedRegistry;
import net.kyori.registry.RegistryImpl; import net.kyori.registry.RegistryImpl;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@@ -104,7 +105,7 @@ public class CarbonChannelRegistry extends RegistryImpl<Key, ChatChannel> implem
} }
try (final Stream<Path> paths = Files.walk(channelDirectory)) { try (final Stream<Path> paths = Files.walk(channelDirectory)) {
final CommandManager<Commander> commandManager = this.injector.getInstance(com.google.inject.Key.get(new TypeLiteral<CommandManager<Commander>>() {})); final CommandManager<Commander> commandManager = this.injector.getInstance(com.google.inject.Key.get(new TypeLiteral<>() {}));
paths.forEach(path -> { paths.forEach(path -> {
final String fileName = path.getFileName().toString(); final String fileName = path.getFileName().toString();
@@ -123,13 +124,25 @@ public class CarbonChannelRegistry extends RegistryImpl<Key, ChatChannel> implem
.permission("carbon.channel." + channelKey) .permission("carbon.channel." + channelKey)
.senderType(PlayerCommander.class) .senderType(PlayerCommander.class)
.handler(handler -> { .handler(handler -> {
var sender = ((PlayerCommander)handler.getSender()).carbonPlayer();
if (sender.muted(channel)) {
// TODO: "you are muted in this channel!!!!"
return;
}
if (handler.contains("message")) { if (handler.contains("message")) {
final String message = handler.get("message"); final String message = handler.get("message");
final var component = Component.text(message);
((PlayerCommander)handler.getSender()).carbonPlayer().sendMessageAsPlayer(message); // TODO: trigger platform events related to chat
// TODO: also make sure carbon events are also emitted properly?
for (final var recipient : channel.recipients(sender)) {
recipient.sendMessage(channel.render(sender, recipient, component, component));
}
} else { } else {
((PlayerCommander)handler.getSender()).carbonPlayer().selectedChannel(channel); sender.selectedChannel(channel);
this.messageService.changedChannels(handler.getSender(), channel.key().value()); this.messageService.changedChannels(sender, channel.key().value());
} }
}) })
.build(); // TODO: command aliases .build(); // TODO: command aliases