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 {
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-platform-api: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;
import net.kyori.registry.DefaultedRegistry;
import net.kyori.registry.Registry;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -10,7 +11,7 @@ import java.util.Iterator;
import java.util.Map;
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<>();
@@ -34,10 +35,6 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
return this.registry.get(key);
}
public @Nullable ChatChannel channelOrDefault(@NonNull final String key) {
return this.registry.getOrDefault(key, this.defaultChannel());
}
@Override
public @Nullable String key(@NonNull final ChatChannel value) {
return null;
@@ -57,4 +54,13 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
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.carbonChat.channelRegistry().channelOrDefault(this.selectedChannelKey);
return this.carbonChat.channelRegistry().getOrDefault(this.selectedChannelKey);
}
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.users.CarbonUser;
import net.draycia.carbon.api.Context;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
@@ -201,7 +202,8 @@ public class CarbonChatChannel implements TextChannel {
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;
}
entry.getKey().sendMessage(entry.getValue());
// TODO: pass in Identifiable sender?
entry.getKey().sendMessage(Identity.nil(), entry.getValue());
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) {
for (final PlayerUser user : this.audiences()) {
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> 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) {
user.selectedChannel(channel, true);