Human pass over storage

This commit is contained in:
Mariell Hoversholm committed 2020-09-09 22:16:57 +02:00
1 parent 14b2cbbd73
commit 8bb7446da8
8 files changed
+175 -96

No files matched your search

@@ -11,75 +11,101 @@ import java.util.UUID;
public interface ChatUser extends Audience { public interface ChatUser extends Audience {
@Nullable Player asPlayer(); @Nullable
@NonNull OfflinePlayer asOfflinePlayer(); Player asPlayer();
@NonNull
OfflinePlayer asOfflinePlayer();
@NonNull
UUID getUUID(); UUID getUUID();
boolean isOnline(); boolean isOnline();
@Nullable String getNickname(); @Nullable
void setNickname(String nickname, boolean fromRemote); String getNickname();
default void setNickname(String nickname) {
default void setNickname(@NonNull String nickname) {
this.setNickname(nickname, false); this.setNickname(nickname, false);
} }
void setNickname(@Nullable String nickname, boolean fromRemote);
@Nullable
ChatChannel getSelectedChannel(); ChatChannel getSelectedChannel();
void setSelectedChannel(ChatChannel channel, boolean fromRemote);
default void setSelectedChannel(ChatChannel channel) { default void setSelectedChannel(@NonNull ChatChannel channel) {
this.setSelectedChannel(channel, false); this.setSelectedChannel(channel, false);
} }
void setSelectedChannel(@NonNull ChatChannel channel, boolean fromRemote);
void clearSelectedChannel(); void clearSelectedChannel();
UserChannelSettings getChannelSettings(ChatChannel channel); @NonNull
UserChannelSettings getChannelSettings(@NonNull ChatChannel channel);
boolean isSpyingWhispers(); boolean isSpyingWhispers();
void setSpyingWhispers(boolean spyingWhispers, boolean fromRemote);
default void setSpyingWhispers(boolean spyingWhispers) { default void setSpyingWhispers(boolean spyingWhispers) {
this.setSpyingWhispers(spyingWhispers, false); this.setSpyingWhispers(spyingWhispers, false);
} }
void setSpyingWhispers(boolean spyingWhispers, boolean fromRemote);
boolean isMuted(); boolean isMuted();
void setMuted(boolean muted, boolean fromRemote);
default void setMuted(boolean muted) { default void setMuted(boolean muted) {
this.setMuted(muted, false); this.setMuted(muted, false);
} }
void setMuted(boolean muted, boolean fromRemote);
boolean isShadowMuted(); boolean isShadowMuted();
void setShadowMuted(boolean shadowMuted, boolean fromRemote);
default void setShadowMuted(boolean shadowMuted) { default void setShadowMuted(boolean shadowMuted) {
this.setShadowMuted(shadowMuted, false); this.setShadowMuted(shadowMuted, false);
} }
@Nullable @Nullable UUID getReplyTarget(); void setShadowMuted(boolean shadowMuted, boolean fromRemote);
void setReplyTarget(@Nullable UUID target, boolean fromRemote);
@Nullable
UUID getReplyTarget();
default void setReplyTarget(@Nullable UUID target) { default void setReplyTarget(@Nullable UUID target) {
this.setReplyTarget(target, false); this.setReplyTarget(target, false);
} }
default void setReplyTarget(@Nullable ChatUser user, boolean fromRemote) {
this.setReplyTarget(user.getUUID(), fromRemote);
}
default void setReplyTarget(@Nullable ChatUser user) { default void setReplyTarget(@Nullable ChatUser user) {
this.setReplyTarget(user.getUUID(), false); this.setReplyTarget(user.getUUID(), false);
} }
boolean isIgnoringUser(UUID uuid); void setReplyTarget(@Nullable UUID target, boolean fromRemote);
void setIgnoringUser(UUID uuid, boolean ignoring, boolean fromRemote);
default void setIgnoringUser(UUID uuid, boolean ignoring) { default void setReplyTarget(@Nullable ChatUser user, boolean fromRemote) {
this.setReplyTarget(user.getUUID(), fromRemote);
}
boolean isIgnoringUser(@NonNull UUID uuid);
void setIgnoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote);
default void setIgnoringUser(@NonNull UUID uuid, boolean ignoring) {
this.setIgnoringUser(uuid, ignoring, false); this.setIgnoringUser(uuid, ignoring, false);
} }
default boolean isIgnoringUser(@NonNull ChatUser user) { default boolean isIgnoringUser(@NonNull ChatUser user) {
return this.isIgnoringUser(user.getUUID()); return this.isIgnoringUser(user.getUUID());
} }
default void setIgnoringUser(@NonNull ChatUser user, boolean ignoring, boolean fromRemote) { default void setIgnoringUser(@NonNull ChatUser user, boolean ignoring, boolean fromRemote) {
this.setIgnoringUser(user.getUUID(), ignoring, fromRemote); this.setIgnoringUser(user.getUUID(), ignoring, fromRemote);
} }
default void setIgnoringUser(@NonNull ChatUser user, boolean ignoring) { default void setIgnoringUser(@NonNull ChatUser user, boolean ignoring) {
this.setIgnoringUser(user.getUUID(), ignoring, false); this.setIgnoringUser(user.getUUID(), ignoring, false);
} }
void sendMessage(ChatUser sender, String message); void sendMessage(@NonNull ChatUser sender, @NonNull String message);
} }
@@ -6,24 +6,30 @@ import java.util.List;
public class CommandSettings { public class CommandSettings {
private boolean enabled; private final boolean enabled;
private String name;
private List<String> aliases;
public CommandSettings(boolean enabled, String name, List<String> aliases) { @NonNull
private final String name;
@NonNull
private final List<@NonNull String> aliases;
public CommandSettings(boolean enabled, @NonNull String name, @NonNull List<@NonNull String> aliases) {
this.enabled = enabled; this.enabled = enabled;
this.name = name; this.name = name;
this.aliases = aliases; this.aliases = aliases;
} }
public String @NonNull [] getAliasesArray() { public @NonNull String @NonNull [] getAliasesArray() {
return aliases.toArray(new String[0]); return aliases.toArray(new String[0]);
} }
public List<String> getAliases() { @NonNull
public List<@NonNull String> getAliases() {
return aliases; return aliases;
} }
@NonNull
public String getName() { public String getName() {
return name; return name;
} }
@@ -6,21 +6,28 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public interface UserChannelSettings { public interface UserChannelSettings {
boolean isSpying(); boolean isSpying();
void setSpying(boolean spying, boolean fromRemote);
default void setSpying(boolean spying) { default void setSpying(boolean spying) {
this.setSpying(spying, false); this.setSpying(spying, false);
} }
void setSpying(boolean spying, boolean fromRemote);
boolean isIgnored(); boolean isIgnored();
void setIgnoring(boolean ignored, boolean fromRemote); void setIgnoring(boolean ignored, boolean fromRemote);
default void setIgnoring(boolean ignored) { default void setIgnoring(boolean ignored) {
this.setIgnoring(ignored, false); this.setIgnoring(ignored, false);
} }
@Nullable @Nullable TextColor getColor(); @Nullable
void setColor(@Nullable TextColor color, boolean fromRemote); TextColor getColor();
default void setColor(@Nullable TextColor color) { default void setColor(@Nullable TextColor color) {
this.setColor(color, false); this.setColor(color, false);
} }
void setColor(@Nullable TextColor color, boolean fromRemote);
} }
@@ -8,23 +8,30 @@ import java.util.UUID;
public interface UserService { public interface UserService {
@Nullable ChatUser wrap(String name); @Nullable
@Nullable ChatUser wrap(OfflinePlayer player); ChatUser wrap(String name);
@Nullable ChatUser wrap(UUID uuid);
@Nullable
ChatUser wrap(OfflinePlayer player);
@Nullable
ChatUser wrap(UUID uuid);
@Nullable @Nullable
default ChatUser wrapIfLoaded(@NonNull OfflinePlayer player) { default ChatUser wrapIfLoaded(@NonNull OfflinePlayer player) {
return wrapIfLoaded(player.getUniqueId()); return wrapIfLoaded(player.getUniqueId());
} }
@Nullable @Nullable @Nullable
ChatUser wrapIfLoaded(UUID uuid); ChatUser wrapIfLoaded(@NonNull UUID uuid);
@Nullable ChatUser refreshUser(UUID uuid); @Nullable
ChatUser refreshUser(@NonNull UUID uuid);
void onDisable(); void onDisable();
void invalidate(ChatUser user); void invalidate(@NonNull ChatUser user);
void validate(ChatUser user);
void validate(@NonNull ChatUser user);
} }
@@ -15,50 +15,58 @@ import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import javax.annotation.CheckForNull;
import java.util.*; import java.util.*;
public class CarbonChatUser implements ChatUser, ForwardingAudience { public class CarbonChatUser implements ChatUser, ForwardingAudience {
private final transient @Nullable @NonNull CarbonChat carbonChat; @NonNull
private final transient CarbonChat carbonChat;
@NonNull
private final Map<@NonNull String, @NonNull SimpleUserChannelSettings> channelSettings = new HashMap<>();
@NonNull
private final List<@NonNull UUID> ignoredUsers = new ArrayList<>();
@MonotonicNonNull // @NonNull but not initialised in all constructors.
private UUID uuid; private UUID uuid;
@Nullable
private @Nullable String selectedChannel = null; private String selectedChannel = null;
private final Map<String, SimpleUserChannelSettings> channelSettings = new HashMap<>();
private final List<UUID> ignoredUsers = new ArrayList<>();
private boolean muted = false; private boolean muted = false;
private boolean shadowMuted = false; private boolean shadowMuted = false;
private boolean spyingWhispers = false; private boolean spyingWhispers = false;
private @Nullable String nickname = null; @Nullable
private String nickname = null;
private transient @Nullable UUID replyTarget = null; @Nullable
private transient UUID replyTarget = null;
public CarbonChatUser() { public CarbonChatUser() {
this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat"); this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
} }
public CarbonChatUser(UUID uuid) { public CarbonChatUser(@NonNull UUID uuid) {
this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat"); this();
this.uuid = uuid; this.uuid = uuid;
} }
@Override @Override
public @NonNull Iterable<? extends Audience> audiences() { @NonNull
public Iterable<@NonNull ? extends Audience> audiences() {
return Collections.singleton(carbonChat.getAdventureManager().getAudiences().player(uuid)); return Collections.singleton(carbonChat.getAdventureManager().getAudiences().player(uuid));
} }
@Override @Override
public @Nullable Player asPlayer() { @Nullable
public Player asPlayer() {
return Bukkit.getPlayer(uuid); return Bukkit.getPlayer(uuid);
} }
@Override @Override
public @NonNull OfflinePlayer asOfflinePlayer() { @NonNull
public OfflinePlayer asOfflinePlayer() {
return Bukkit.getOfflinePlayer(uuid); return Bukkit.getOfflinePlayer(uuid);
} }
@@ -68,12 +76,14 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
} }
@Override @Override
@NonNull
public UUID getUUID() { public UUID getUUID() {
return uuid; return uuid;
} }
@Override @Override
public @Nullable String getNickname() { @Nullable
public String getNickname() {
return nickname; return nickname;
} }
@@ -106,6 +116,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
} }
@Override @Override
@Nullable
public ChatChannel getSelectedChannel() { public ChatChannel getSelectedChannel() {
return carbonChat.getChannelManager().getChannelOrDefault(selectedChannel); return carbonChat.getChannelManager().getChannelOrDefault(selectedChannel);
} }
@@ -140,7 +151,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
} }
@Override @Override
public boolean isIgnoringUser(UUID uuid) { public boolean isIgnoringUser(@NonNull UUID uuid) {
return ignoredUsers.contains(uuid); return ignoredUsers.contains(uuid);
} }
@@ -161,7 +172,8 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
} }
} }
public @NonNull List<UUID> getIgnoredUsers() { @NonNull
public List<@NonNull UUID> getIgnoredUsers() {
return ignoredUsers; return ignoredUsers;
} }
@@ -197,14 +209,14 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
return shadowMuted; return shadowMuted;
} }
@CheckForNull
@Override @Override
@Nullable
public UUID getReplyTarget() { public UUID getReplyTarget() {
return replyTarget; return replyTarget;
} }
@Override @Override
public void setReplyTarget(@NonNull UUID target, boolean fromRemote) { public void setReplyTarget(@Nullable UUID target, boolean fromRemote) {
this.replyTarget = target; this.replyTarget = target;
if (!fromRemote) { if (!fromRemote) {
@@ -216,13 +228,15 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
} }
@Override @Override
@NonNull
public UserChannelSettings getChannelSettings(@NonNull ChatChannel channel) { public UserChannelSettings getChannelSettings(@NonNull ChatChannel channel) {
return channelSettings.computeIfAbsent(channel.getKey(), (name) -> { return channelSettings.computeIfAbsent(channel.getKey(), (name) -> {
return new SimpleUserChannelSettings(uuid, channel.getKey()); return new SimpleUserChannelSettings(uuid, channel.getKey());
}); });
} }
public @NonNull Map<String, ? extends UserChannelSettings> getChannelSettings() { @NonNull
public Map<@NonNull String, @NonNull ? extends UserChannelSettings> getChannelSettings() {
return channelSettings; return channelSettings;
} }
@@ -242,7 +256,8 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
return spyingWhispers; return spyingWhispers;
} }
public void sendMessage(@NonNull ChatUser sender, String message) { @Override
public void sendMessage(@NonNull ChatUser sender, @NonNull String message) {
if (isIgnoringUser(sender) || sender.isIgnoringUser(this)) { if (isIgnoringUser(sender) || sender.isIgnoringUser(this)) {
return; return;
} }
@@ -1,6 +1,9 @@
package net.draycia.carbon.storage.impl; package net.draycia.carbon.storage.impl;
import com.google.common.cache.*; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalNotification;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
@@ -25,15 +28,17 @@ import java.util.concurrent.ExecutionException;
public class JSONUserService implements UserService { public class JSONUserService implements UserService {
private final @NonNull CarbonChat carbonChat; @NonNull
private final CarbonChat carbonChat;
private final LoadingCache<UUID, CarbonChatUser> userCache = CacheBuilder.newBuilder() @NonNull
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
@NonNull
private final Type userType = new TypeToken<CarbonChatUser>() {}.getType();
@NonNull
private final LoadingCache<@NonNull UUID, @NonNull CarbonChatUser> userCache = CacheBuilder.newBuilder()
.removalListener(this::saveUser) .removalListener(this::saveUser)
.build(CacheLoader.from(this::loadUser)); .build(CacheLoader.from(this::loadUser));
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private final Type userType = new TypeToken<CarbonChatUser>() {}.getType();
public JSONUserService(@NonNull CarbonChat carbonChat) { public JSONUserService(@NonNull CarbonChat carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
@@ -47,7 +52,8 @@ public class JSONUserService implements UserService {
} }
@Override @Override
public @Nullable ChatUser wrap(@NonNull String name) { @Nullable
public ChatUser wrap(@NonNull String name) {
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
if (player != null) { if (player != null) {
@@ -58,12 +64,14 @@ public class JSONUserService implements UserService {
} }
@Override @Override
public @Nullable ChatUser wrap(@NonNull OfflinePlayer player) { @Nullable
public ChatUser wrap(@NonNull OfflinePlayer player) {
return wrap(player.getUniqueId()); return wrap(player.getUniqueId());
} }
@Override @Override
public @Nullable ChatUser wrap(@NonNull UUID uuid) { @Nullable
public ChatUser wrap(@NonNull UUID uuid) {
try { try {
return userCache.get(uuid); return userCache.get(uuid);
} catch (ExecutionException e) { } catch (ExecutionException e) {
@@ -79,7 +87,8 @@ public class JSONUserService implements UserService {
} }
@Override @Override
public @Nullable ChatUser refreshUser(@NonNull UUID uuid) { @Nullable
public ChatUser refreshUser(@NonNull UUID uuid) {
userCache.invalidate(uuid); userCache.invalidate(uuid);
return this.wrap(uuid); return this.wrap(uuid);
@@ -92,9 +101,10 @@ public class JSONUserService implements UserService {
@Override @Override
public void validate(@NonNull ChatUser user) { public void validate(@NonNull ChatUser user) {
userCache.put(user.getUUID(), (CarbonChatUser)user); userCache.put(user.getUUID(), (CarbonChatUser) user);
} }
@NonNull
private CarbonChatUser loadUser(@NonNull UUID uuid) { private CarbonChatUser loadUser(@NonNull UUID uuid) {
File userFile = new File(carbonChat.getDataFolder(), "users/" + uuid.toString() + ".json"); File userFile = new File(carbonChat.getDataFolder(), "users/" + uuid.toString() + ".json");
ensureFileExists(userFile); ensureFileExists(userFile);
@@ -112,7 +122,7 @@ public class JSONUserService implements UserService {
return new CarbonChatUser(uuid); return new CarbonChatUser(uuid);
} }
private void saveUser(@NonNull RemovalNotification<UUID, CarbonChatUser> notification) { private void saveUser(@NonNull RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
File userFile = new File(carbonChat.getDataFolder(), "users/" + notification.getKey().toString() + ".json"); File userFile = new File(carbonChat.getDataFolder(), "users/" + notification.getKey().toString() + ".json");
ensureFileExists(userFile); ensureFileExists(userFile);
@@ -27,13 +27,15 @@ import java.util.concurrent.ExecutionException;
public class MySQLUserService implements UserService { public class MySQLUserService implements UserService {
private final LoadingCache<UUID, CarbonChatUser> userCache = CacheBuilder.newBuilder() @NonNull
private final CarbonChat carbonChat;
@NonNull
private final Database database;
@NonNull
private final LoadingCache<@NonNull UUID, @NonNull CarbonChatUser> userCache = CacheBuilder.newBuilder()
.removalListener(this::saveUser) .removalListener(this::saveUser)
.build(CacheLoader.from(this::loadUser)); .build(CacheLoader.from(this::loadUser));
private final @NonNull CarbonChat carbonChat;
private final @NonNull Database database;
public MySQLUserService(@NonNull CarbonChat carbonChat) { public MySQLUserService(@NonNull CarbonChat carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
@@ -61,7 +63,8 @@ public class MySQLUserService implements UserService {
try { try {
database.executeUpdate("ALTER TABLE sc_users ADD COLUMN spyingwhispers BOOLEAN DEFAULT false"); database.executeUpdate("ALTER TABLE sc_users ADD COLUMN spyingwhispers BOOLEAN DEFAULT false");
database.executeUpdate("ALTER TABLE sc_users ADD COLUMN nickname VARCHAR(512) DEFAULT false"); database.executeUpdate("ALTER TABLE sc_users ADD COLUMN nickname VARCHAR(512) DEFAULT false");
} catch (SQLSyntaxErrorException syntaxErrorException) {} } catch (SQLSyntaxErrorException ignored) {
}
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_channel_settings (uuid CHAR(36), channel CHAR(16), spying BOOLEAN, ignored BOOLEAN, color TINYTEXT, PRIMARY KEY (uuid, channel))"); database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_channel_settings (uuid CHAR(36), channel CHAR(16), spying BOOLEAN, ignored BOOLEAN, color TINYTEXT, PRIMARY KEY (uuid, channel))");
@@ -79,7 +82,8 @@ public class MySQLUserService implements UserService {
} }
@Override @Override
public @Nullable ChatUser wrap(@NonNull String name) { @Nullable
public ChatUser wrap(@NonNull String name) {
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
if (player != null) { if (player != null) {
@@ -90,12 +94,14 @@ public class MySQLUserService implements UserService {
} }
@Override @Override
public @Nullable ChatUser wrap(@NonNull OfflinePlayer player) { @Nullable
public ChatUser wrap(@NonNull OfflinePlayer player) {
return wrap(player.getUniqueId()); return wrap(player.getUniqueId());
} }
@Override @Override
public @Nullable ChatUser wrap(@NonNull UUID uuid) { @Nullable
public ChatUser wrap(@NonNull UUID uuid) {
try { try {
return userCache.get(uuid); return userCache.get(uuid);
} catch (ExecutionException e) { } catch (ExecutionException e) {
@@ -111,7 +117,8 @@ public class MySQLUserService implements UserService {
} }
@Override @Override
public @Nullable ChatUser refreshUser(@NonNull UUID uuid) { @Nullable
public ChatUser refreshUser(@NonNull UUID uuid) {
userCache.invalidate(uuid); userCache.invalidate(uuid);
return this.wrap(uuid); return this.wrap(uuid);
@@ -124,10 +131,11 @@ public class MySQLUserService implements UserService {
@Override @Override
public void validate(@NonNull ChatUser user) { public void validate(@NonNull ChatUser user) {
userCache.put(user.getUUID(), (CarbonChatUser)user); userCache.put(user.getUUID(), (CarbonChatUser) user);
} }
private @NonNull CarbonChatUser loadUser(@NonNull UUID uuid) { @NonNull
private CarbonChatUser loadUser(@NonNull UUID uuid) {
CarbonChatUser user = new CarbonChatUser(uuid); CarbonChatUser user = new CarbonChatUser(uuid);
try (DbStatement statement = database.query("SELECT * from sc_users WHERE uuid = ?;")) { try (DbStatement statement = database.query("SELECT * from sc_users WHERE uuid = ?;")) {
@@ -185,13 +193,9 @@ public class MySQLUserService implements UserService {
return user; return user;
} }
private void saveUser(@NonNull RemovalNotification<UUID, CarbonChatUser> notification) { private void saveUser(@NonNull RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
CarbonChatUser user = notification.getValue(); CarbonChatUser user = notification.getValue();
if (user == null) {
return;
}
database.createTransaction(stm -> { database.createTransaction(stm -> {
// Save user general data // Save user general data
String selectedName = null; String selectedName = null;
@@ -4,6 +4,7 @@ import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.storage.UserChannelSettings; import net.draycia.carbon.storage.UserChannelSettings;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@@ -11,28 +12,31 @@ import java.util.UUID;
public class SimpleUserChannelSettings implements UserChannelSettings { public class SimpleUserChannelSettings implements UserChannelSettings {
@NonNull
private final transient CarbonChat carbonChat;
private boolean spying; private boolean spying;
private boolean ignored; private boolean ignored;
private @Nullable String color; @Nullable
private String color;
@MonotonicNonNull // @NonNull but not initialised in all constructors.
private UUID uuid; private UUID uuid;
@MonotonicNonNull // @NonNull but not initialised in all constructors.
private String channel; private String channel;
private final transient @Nullable @NonNull CarbonChat carbonChat;
private SimpleUserChannelSettings() { private SimpleUserChannelSettings() {
carbonChat = (CarbonChat)Bukkit.getPluginManager().getPlugin("CarbonChat"); carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
} }
public SimpleUserChannelSettings(UUID uuid, String channel) { public SimpleUserChannelSettings(@NonNull UUID uuid, @NonNull String channel) {
this.uuid = uuid; this.uuid = uuid;
this.channel = channel; this.channel = channel;
carbonChat = (CarbonChat)Bukkit.getPluginManager().getPlugin("CarbonChat"); carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
} }
private @NonNull CarbonChatUser getUser() { @NonNull
return (CarbonChatUser)carbonChat.getUserService().wrap(uuid); private CarbonChatUser getUser() {
return (CarbonChatUser) carbonChat.getUserService().wrap(uuid);
} }
@Override @Override