mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Add ChannelRegistry#channelOrThrow, rename ChannelRegistry#keyOrDefault to channelOrDefault
This commit is contained in:
4 files changed
+38
-14
No files matched your search
@@ -26,6 +26,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.seiama.registry.Holder;
|
||||
import com.seiama.registry.Registry;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
@@ -33,6 +34,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -406,7 +408,8 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
|
||||
@Override
|
||||
public @Nullable ChatChannel channel(final Key key) {
|
||||
return this.channelRegistry.getOrCreateHolder(key).value();
|
||||
final @Nullable Holder<ChatChannel> holder = this.channelRegistry.getHolder(key);
|
||||
return holder == null ? null : holder.value();
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel channelByValue(final String value) {
|
||||
@@ -439,7 +442,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatChannel keyOrDefault(final Key key) {
|
||||
public ChatChannel channelOrDefault(final Key key) {
|
||||
final @Nullable ChatChannel channel = this.channel(key);
|
||||
|
||||
if (channel != null) {
|
||||
@@ -449,6 +452,15 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
return this.defaultChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatChannel channelOrThrow(final Key key) {
|
||||
final @Nullable ChatChannel channel = this.channel(key);
|
||||
if (channel != null) {
|
||||
return channel;
|
||||
}
|
||||
throw new NoSuchElementException("No channel registered with key '" + key.asString() + "'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void allKeys(final Consumer<Key> action) {
|
||||
for (final Key key : this.channelRegistry.keys()) {
|
||||
|
||||
@@ -44,7 +44,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Single {
|
||||
@@ -154,7 +153,7 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Audience audience() {
|
||||
public Audience audience() {
|
||||
return Audience.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.util.Tristate;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -256,11 +255,11 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
final String text = PlainTextComponentSerializer.plainText().serialize(message);
|
||||
Component formattedMessage = message;
|
||||
|
||||
ChatChannel channel = requireNonNullElse(this.selectedChannel(), this.carbonPlayerCommon().channelRegistry().defaultChannel());
|
||||
ChatChannel channel = requireNonNullElse(this.selectedChannel(), this.carbonPlayerCommon.channelRegistry().defaultChannel());
|
||||
|
||||
for (final Key channelKey : this.carbonPlayerCommon.channelRegistry().keys()) {
|
||||
final @MonotonicNonNull ChatChannel chatChannel = this.carbonPlayerCommon.channelRegistry().channel(channelKey);
|
||||
final @MonotonicNonNull String prefix = chatChannel.quickPrefix();
|
||||
final ChatChannel chatChannel = this.carbonPlayerCommon.channelRegistry().channelOrThrow(channelKey);
|
||||
final @Nullable String prefix = chatChannel.quickPrefix();
|
||||
|
||||
if (prefix == null) {
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user