Bump adventure and use DefaultedRegistry

This commit is contained in:
Draycia committed 2020-10-14 00:39:32 -07:00
1 parent b9296e351c
commit dc2e319511
5 files changed
+22 -12

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ description 'CarbonChat-API'
dependencies { dependencies {
compile 'org.checkerframework:checker-qual:3.6.1' compile 'org.checkerframework:checker-qual:3.6.1'
compile 'net.kyori:adventure-api:4.0.0-SNAPSHOT' compile 'net.kyori:adventure-api:4.0.0'
compile 'net.kyori:adventure-nbt:4.0.0-SNAPSHOT' compile 'net.kyori:adventure-nbt:4.0.0-SNAPSHOT'
compile 'net.kyori:adventure-platform-api:4.0.0-SNAPSHOT' compile 'net.kyori:adventure-platform-api:4.0.0-SNAPSHOT'
compile 'net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT' compile 'net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT'
@@ -1,5 +1,6 @@
package net.draycia.carbon.api.channels; package net.draycia.carbon.api.channels;
import net.kyori.registry.DefaultedRegistry;
import net.kyori.registry.Registry; import net.kyori.registry.Registry;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
@@ -10,7 +11,7 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
public class ChannelRegistry implements Registry<String, ChatChannel> { public class ChannelRegistry implements Registry<String, ChatChannel>, DefaultedRegistry<String, ChatChannel> {
private @NonNull final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>(); private @NonNull final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>();
@@ -34,10 +35,6 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
return this.registry.get(key); return this.registry.get(key);
} }
public @Nullable ChatChannel channelOrDefault(@NonNull final String key) {
return this.registry.getOrDefault(key, this.defaultChannel());
}
@Override @Override
public @Nullable String key(@NonNull final ChatChannel value) { public @Nullable String key(@NonNull final ChatChannel value) {
return null; return null;
@@ -57,4 +54,13 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
return this.defaultChannel; return this.defaultChannel;
} }
@Override
public @NonNull String defaultKey() {
return this.defaultChannel.key();
}
@Override
public @NonNull ChatChannel getOrDefault(@NonNull final String key) {
return this.registry.getOrDefault(key, this.defaultChannel());
}
} }
@@ -155,7 +155,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience {
return this.selectedChannel; return this.selectedChannel;
} }
return this.carbonChat.channelRegistry().channelOrDefault(this.selectedChannelKey); return this.carbonChat.channelRegistry().getOrDefault(this.selectedChannelKey);
} }
return null; return null;
@@ -14,6 +14,7 @@ import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.draycia.carbon.api.events.ReceiverContextEvent; import net.draycia.carbon.api.events.ReceiverContextEvent;
import net.draycia.carbon.api.users.CarbonUser; import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.Context; import net.draycia.carbon.api.Context;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
@@ -201,7 +202,8 @@ public class CarbonChatChannel implements TextChannel {
continue; continue;
} }
entry.getKey().sendMessage(entry.getValue()); // TODO: pass in Identity sender?
entry.getKey().sendMessage(Identity.nil(), entry.getValue());
} }
} }
@@ -212,10 +214,12 @@ public class CarbonChatChannel implements TextChannel {
continue; continue;
} }
entry.getKey().sendMessage(entry.getValue()); // TODO: pass in Identifiable sender?
entry.getKey().sendMessage(Identity.nil(), entry.getValue());
if (entry instanceof ConsoleUser) { if (entry instanceof ConsoleUser) {
this.carbonChat.messageProcessor().audiences().console().sendMessage(entry.getValue()); this.carbonChat.messageProcessor().audiences().console()
.sendMessage(Identity.nil(), entry.getValue());
} }
} }
} }
@@ -304,7 +308,7 @@ public class CarbonChatChannel implements TextChannel {
public void sendComponent(@NonNull final PlayerUser player, @NonNull final Component component) { public void sendComponent(@NonNull final PlayerUser player, @NonNull final Component component) {
for (final PlayerUser user : this.audiences()) { for (final PlayerUser user : this.audiences()) {
if (!user.ignoringUser(player)) { if (!user.ignoringUser(player)) {
user.sendMessage(component); user.sendMessage(Identity.identity(player.uuid()), component);
} }
} }
} }
@@ -158,7 +158,7 @@ public class MySQLUserService<T extends PlayerUser> implements UserService<T> {
final List<DbRow> channelSettings = this.database.getResults("SELECT * from sc_channel_settings WHERE uuid = ?;", uuid.toString()); final List<DbRow> channelSettings = this.database.getResults("SELECT * from sc_channel_settings WHERE uuid = ?;", uuid.toString());
final List<DbRow> ignoredUsers = this.database.getResults("SELECT * from sc_ignored_users WHERE uuid = ?;", uuid.toString()); final List<DbRow> ignoredUsers = this.database.getResults("SELECT * from sc_ignored_users WHERE uuid = ?;", uuid.toString());
final ChatChannel channel = this.carbonChat.channelRegistry().channelOrDefault(users.getString("channel")); final ChatChannel channel = this.carbonChat.channelRegistry().getOrDefault(users.getString("channel"));
if (channel != null) { if (channel != null) {
user.selectedChannel(channel, true); user.selectedChannel(channel, true);