mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
partial channel switching support
This commit is contained in:
1 parent
f866157d97
commit
22f86a9268
4 files changed
+36
-5
No files matched your search
@@ -58,7 +58,7 @@ public final class CarbonPlayerBukkit extends CarbonPlayerCommon implements Forw
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void temporaryDisplayName(@Nullable Component displayName) {
|
public void temporaryDisplayName(final @Nullable Component displayName) {
|
||||||
this.carbonPlayer.temporaryDisplayName(displayName);
|
this.carbonPlayer.temporaryDisplayName(displayName);
|
||||||
|
|
||||||
final @Nullable Player player = this.player();
|
final @Nullable Player player = this.player();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.draycia.carbon.common.channels;
|
package net.draycia.carbon.common.channels;
|
||||||
|
|
||||||
|
import cloud.commandframework.CommandManager;
|
||||||
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@@ -11,8 +13,11 @@ import java.util.stream.Stream;
|
|||||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.common.ForCarbon;
|
import net.draycia.carbon.common.ForCarbon;
|
||||||
|
import net.draycia.carbon.common.command.Commander;
|
||||||
|
import net.draycia.carbon.common.command.PlayerCommander;
|
||||||
import net.draycia.carbon.common.config.ConfigLoader;
|
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.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.registry.DefaultedRegistry;
|
import net.kyori.registry.DefaultedRegistry;
|
||||||
import net.kyori.registry.RegistryImpl;
|
import net.kyori.registry.RegistryImpl;
|
||||||
@@ -47,6 +52,7 @@ public class CarbonChannelRegistry extends RegistryImpl<Key, ChatChannel> implem
|
|||||||
private final PrimaryConfig primaryConfig;
|
private final PrimaryConfig primaryConfig;
|
||||||
private @MonotonicNonNull Key defaultKey;
|
private @MonotonicNonNull Key defaultKey;
|
||||||
private @MonotonicNonNull ChatChannel basicChannel;
|
private @MonotonicNonNull ChatChannel basicChannel;
|
||||||
|
private final CarbonMessageService messageService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public CarbonChannelRegistry(
|
public CarbonChannelRegistry(
|
||||||
@@ -54,13 +60,15 @@ public class CarbonChannelRegistry extends RegistryImpl<Key, ChatChannel> implem
|
|||||||
@ForCarbon final Path dataDirectory,
|
@ForCarbon final Path dataDirectory,
|
||||||
final Injector injector,
|
final Injector injector,
|
||||||
final Logger logger,
|
final Logger logger,
|
||||||
final PrimaryConfig primaryConfig
|
final PrimaryConfig primaryConfig,
|
||||||
|
final CarbonMessageService messageService
|
||||||
) {
|
) {
|
||||||
this.configLoader = configLoader;
|
this.configLoader = configLoader;
|
||||||
this.dataDirectory = dataDirectory;
|
this.dataDirectory = dataDirectory;
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.primaryConfig = primaryConfig;
|
this.primaryConfig = primaryConfig;
|
||||||
|
this.messageService = messageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadChannels() {
|
public void loadChannels() {
|
||||||
@@ -95,6 +103,9 @@ 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 = (CommandManager<Commander>)
|
||||||
|
this.injector.getInstance(com.google.inject.Key.get(new TypeToken<CommandManager<Commander>>() {}.getType()));
|
||||||
|
|
||||||
paths.forEach(path -> {
|
paths.forEach(path -> {
|
||||||
final String fileName = path.getFileName().toString();
|
final String fileName = path.getFileName().toString();
|
||||||
|
|
||||||
@@ -102,8 +113,22 @@ public class CarbonChannelRegistry extends RegistryImpl<Key, ChatChannel> implem
|
|||||||
final @Nullable ChatChannel channel = this.loadChannel(path);
|
final @Nullable ChatChannel channel = this.loadChannel(path);
|
||||||
|
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
this.logger.info("Registering channel with key [" + channel.key() + "]");
|
final Key channelKey = channel.key();
|
||||||
register(channel.key(), channel);
|
|
||||||
|
this.logger.info("Registering channel with key [" + channelKey + "]");
|
||||||
|
register(channelKey, channel);
|
||||||
|
|
||||||
|
var command = commandManager.commandBuilder(channelKey.value())
|
||||||
|
//.literal(channelKey.toString(), channelKey.value())
|
||||||
|
.permission("carbon.channel." + channelKey)
|
||||||
|
.senderType(PlayerCommander.class)
|
||||||
|
.handler(handler -> {
|
||||||
|
((PlayerCommander)handler.getSender()).carbonPlayer().selectedChannel(channel);
|
||||||
|
this.messageService.changedChannels(handler.getSender(), channel.key().value());
|
||||||
|
})
|
||||||
|
.build(); // TODO: command aliases
|
||||||
|
|
||||||
|
commandManager.command(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -35,4 +35,10 @@ public interface CarbonMessageService {
|
|||||||
@Message("mute.spy.prefix")
|
@Message("mute.spy.prefix")
|
||||||
Component muteSpyPrefix(final Audience audience);
|
Component muteSpyPrefix(final Audience audience);
|
||||||
|
|
||||||
|
@Message("channel.change")
|
||||||
|
void changedChannels(
|
||||||
|
final Audience audience,
|
||||||
|
@Placeholder final String channel // TODO: allow MiniMessage based channel "names"
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,4 +3,4 @@ example.command.hello=<green>Hello from </green><plugin><green>!</green>
|
|||||||
mute.spy.prefix=<red><hover:show_text:<red>Muted</red>M</hover></red>
|
mute.spy.prefix=<red><hover:show_text:<red>Muted</red>M</hover></red>
|
||||||
test.phrase=English: Has anyone really been far even as decided to use even go want to do look more like?
|
test.phrase=English: Has anyone really been far even as decided to use even go want to do look more like?
|
||||||
unsupported.legacy=<red>Legacy color codes have been detected in a message. This is not supported behavior. Message: '<message>'
|
unsupported.legacy=<red>Legacy color codes have been detected in a message. This is not supported behavior. Message: '<message>'
|
||||||
|
channel.change=<green>You are now messaging </green><channel><green> chat!</green>
|
||||||
Reference in new issue
Block a user