Add checkerframework compilation checking (#109)

* Reorder nullability annotations again

* Add checker validation to API module

* Add checker validation to Common module

* Begin checker validation for Bukkit module

* It compiles!
This commit is contained in:
Josh (Vicarious) authored and GitHub committed 2020-10-24 01:02:57 -07:00
1 parent 3314a51df8
commit d9ab711adc
83 files changed
+1127 -717

No files matched your search

@@ -1,7 +1,9 @@
package net.draycia.carbon.api.config;
import com.google.common.collect.ImmutableMap;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.Context;
import net.kyori.adventure.text.format.NamedTextColor;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
@@ -15,32 +17,31 @@ import java.util.List;
import java.util.Map;
@ConfigSerializable
@SuppressWarnings("initialization.fields.uninitialized")
public final class ChannelOptions {
@Setting
@Comment("What this channel is identified as. This will be what's typed ingame to use the channel.")
private String key = "channel";
private @NonNull String key = "channel";
@Setting
@Comment("This is what the <color> placeholder will typically be replaced with.\n" +
"Hex RGB (#B19CD9), named colors (light_purple), legacy (&d), and legacy RGB (&x&b&1&2&c&d&9) are all supported.\n" +
"If on a platform that supports PlaceholderAPI, this option will be ran through that as well.\n" +
"Note that the <color> placeholder is also used for personal and global user colors.")
private String color;
private @Nullable String color = NamedTextColor.WHITE.asHexString();
@Setting
@Comment("The contexts for this channel, which can modify the behaviour of channels and how/when players can use them.")
private Map<String, Context> contexts = new HashMap<>();
private @Nullable Map<@NonNull String, @NonNull Context> contexts = new HashMap<>();
@Setting
@Comment("The formats for this channel. The key is the name of the group as your permissions plugin reports it.")
private Map<String, String> formats = new HashMap<String, String>() {{
put("default", "<color><<displayname><reset><color>> <message>");
}};
private @Nullable Map<String, String> formats = ImmutableMap.of("default", "<color><<displayname><reset><color>> <message>");
@Setting
@Comment("The name of the format that the plugin will fall back to when it cannot find a matching format for the player's groups.")
private String defaultFormatName;
private @Nullable String defaultFormatName;
@Setting
@Comment("If this channel is the default channel players join in.\n" +
@@ -123,7 +124,7 @@ public final class ChannelOptions {
@Comment("The message that's sent when you attempt to ignore a channel but are unable to do so")
private String cannotIgnoreMessage;
private SharedChannelOptions defaultOptions() {
private @NonNull SharedChannelOptions defaultOptions() {
return CarbonChatProvider.carbonChat().channelSettings().defaultChannelOptions();
}
@@ -151,7 +152,7 @@ public final class ChannelOptions {
return this.color;
}
public @Nullable Context context(@NonNull final String key) {
public @Nullable Context context(final @NonNull String key) {
final Context localContext;
if (this.contexts != null) {
@@ -161,8 +162,10 @@ public final class ChannelOptions {
}
if (localContext == null) {
if (this.defaultOptions().contexts() != null) {
return this.defaultOptions().contexts().get(key);
final Map<String, Context> defaultContexts = this.defaultOptions().contexts();
if (defaultContexts != null) {
return defaultContexts.get(key);
} else {
return null;
}
@@ -184,28 +187,37 @@ public final class ChannelOptions {
return this.defaultOptions().contexts();
}
if (this.defaultOptions().contexts() == null) {
final Map<String, Context> defaultContexts = this.defaultOptions().contexts();
if (defaultContexts == null) {
return this.contexts;
}
final Map<String, Context> contexts = new HashMap<>(this.defaultOptions().contexts());
contexts.putAll(this.contexts);
final Map<String, Context> contexts = new HashMap<>(defaultContexts);
if (this.contexts != null) {
contexts.putAll(this.contexts);
}
return contexts;
}
public @Nullable String format(@NonNull final String key) {
public @Nullable String format(final @NonNull String key) {
final String localFormat;
if (this.formats() != null) {
localFormat = this.formats().get(key);
final Map<String, String> localFormats = this.formats();
if (localFormats != null) {
localFormat = localFormats.get(key);
} else {
localFormat = null;
}
if (localFormat == null) {
if (this.defaultOptions().formats() != null) {
return this.defaultOptions().formats().get(key);
final Map<String, String> defaultFormats = this.defaultOptions().formats();
if (defaultFormats != null) {
return defaultFormats.get(key);
} else {
return null;
}
@@ -214,7 +226,7 @@ public final class ChannelOptions {
return localFormat;
}
public @Nullable Map<String, String> formats() {
public @Nullable Map<@NonNull String, @NonNull String> formats() {
if (this.formats == null) {
return this.defaultOptions().formats();
}
@@ -222,17 +234,22 @@ public final class ChannelOptions {
return this.formats;
}
public @Nullable Map<String, String> formatsAndDefault() {
public @Nullable Map<@NonNull String, @NonNull String> formatsAndDefault() {
if (this.formats == null) {
return this.defaultOptions().formats();
}
if (this.defaultOptions().formats() == null) {
final Map<String, String> defaultFormats = this.defaultOptions().formats();
if (defaultFormats == null) {
return this.formats;
}
final Map<String, String> formats = new HashMap<>(this.defaultOptions().formats());
formats.putAll(this.formats);
final Map<String, String> formats = new HashMap<>(defaultFormats);
if (this.formats != null) {
formats.putAll(this.formats);
}
return formats;
}
@@ -301,7 +318,7 @@ public final class ChannelOptions {
return this.messagePrefix;
}
public @Nullable String switchMessage() {
public @NonNull String switchMessage() {
if (this.switchMessage == null) {
return this.defaultOptions().switchMessage();
}
@@ -309,7 +326,7 @@ public final class ChannelOptions {
return this.switchMessage;
}
public @Nullable String switchOtherMessage() {
public @NonNull String switchOtherMessage() {
if (this.switchOtherMessage == null) {
return this.defaultOptions().switchOtherMessage();
}
@@ -317,7 +334,7 @@ public final class ChannelOptions {
return this.switchOtherMessage;
}
public @Nullable String switchFailureMessage() {
public @NonNull String switchFailureMessage() {
if (this.switchFailureMessage == null) {
return this.defaultOptions().switchFailureMessage();
}
@@ -325,7 +342,7 @@ public final class ChannelOptions {
return this.switchFailureMessage;
}
public @Nullable String cannotIgnoreMessage() {
public @NonNull String cannotIgnoreMessage() {
if (this.cannotIgnoreMessage == null) {
return this.defaultOptions().cannotIgnoreMessage();
}
@@ -333,7 +350,7 @@ public final class ChannelOptions {
return this.cannotIgnoreMessage;
}
public @Nullable String toggleOffMessage() {
public @NonNull String toggleOffMessage() {
if (this.toggleOffMessage == null) {
return this.defaultOptions().toggleOffMessage();
}
@@ -341,7 +358,7 @@ public final class ChannelOptions {
return this.toggleOffMessage;
}
public @Nullable String toggleOnMessage() {
public @NonNull String toggleOnMessage() {
if (this.toggleOnMessage == null) {
return this.defaultOptions().toggleOnMessage();
}
@@ -349,7 +366,7 @@ public final class ChannelOptions {
return this.toggleOnMessage;
}
public @Nullable String toggleOtherOnMessage() {
public @NonNull String toggleOtherOnMessage() {
if (this.toggleOtherOnMessage == null) {
return this.defaultOptions().toggleOtherOnMessage();
}
@@ -357,7 +374,7 @@ public final class ChannelOptions {
return this.toggleOtherOnMessage;
}
public @Nullable String toggleOtherOffMessage() {
public @NonNull String toggleOtherOffMessage() {
if (this.toggleOtherOffMessage == null) {
return this.defaultOptions().toggleOtherOffMessage();
}
@@ -365,7 +382,7 @@ public final class ChannelOptions {
return this.toggleOtherOffMessage;
}
public @Nullable String cannotUseMessage() {
public @NonNull String cannotUseMessage() {
if (this.cannotUseMessage == null) {
return this.defaultOptions().cannotUseMessage();
}
@@ -1,5 +1,6 @@
package net.draycia.carbon.api.config;
import com.google.common.collect.ImmutableMap;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.CommentedConfigurationNode;
@@ -10,7 +11,6 @@ import org.spongepowered.configurate.objectmapping.meta.Setting;
import org.spongepowered.configurate.serialize.SerializationException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ConfigSerializable
@@ -40,18 +40,14 @@ public final class ChannelSettings {
private SharedChannelOptions sharedChannelOptions = new SharedChannelOptions();
@Setting
private Map<String, ChannelOptions> channelOptions =
private Map<@NonNull String, @NonNull ChannelOptions> channelOptions =
Collections.singletonMap("global", ChannelOptions.defaultChannel());
@Setting
@Comment("Used for message formats - custom tags that are replaced in descending order" +
"\nFor example, in the default config, <group> wil be replaced with <green>%vault_group%")
private @NonNull Map<@Nullable String, @NonNull String> customPlaceholders = new HashMap<String, String>() {
{
this.put("prefix", "<gray>[<group><gray>]");
this.put("group", "<green>%vault_group%");
}
};
private @NonNull Map<@NonNull String, @NonNull String> customPlaceholders =
ImmutableMap.of("prefix", "<gray>[<group><gray>]", "group", "<green>%vault_group%");
public SharedChannelOptions defaultChannelOptions() {
return this.sharedChannelOptions;
@@ -65,7 +61,7 @@ public final class ChannelSettings {
return this.customPlaceholders;
}
public ChannelOptions channelOptions(final String name) {
public @Nullable ChannelOptions channelOptions(final @NonNull String name) {
return this.channelOptions.get(name);
}
@@ -8,7 +8,6 @@ import org.spongepowered.configurate.objectmapping.meta.Setting;
import org.spongepowered.configurate.serialize.SerializationException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@@ -135,11 +134,8 @@ public final class ModerationSettings {
"The strings in the lists (\"lag\" etc) are what's replaced.\n" +
"Set to filters: {} if you want to disable the filter feature.\n" +
"Set the key to \"_\" for the replacement to be blank (remove the filtered pattern).")
private Map<String, List<Pattern>> replacements = new HashMap<String, List<Pattern>>() {
{
this.put("****", Collections.singletonList(Pattern.compile("la[g]+")));
}
};
private Map<String, List<Pattern>> replacements =
Collections.singletonMap("****", Collections.singletonList(Pattern.compile("la[g]+")));
@Setting
@Comment("Anything in blocked-words will prevent the message from being sent at all.\n" +
@@ -1,8 +1,8 @@
package net.draycia.carbon.api.config;
import com.google.common.collect.ImmutableMap;
import net.draycia.carbon.api.Context;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Setting;
@@ -14,43 +14,42 @@ import java.util.Map;
@ConfigSerializable
public final class SharedChannelOptions {
@Setting private String color = "#FFFFFF";
@Setting private Map<String, Context> contexts = new HashMap<>();
@Setting private Map<String, String> formats = new HashMap<String, String>() {{
put("default", "<color><<displayname><reset><color>> <message>");
put("staff", "<#00CED1>[Staff] <color><<displayname><reset><color>> <message>");
}};
@Setting private String defaultFormatName = "default";
@Setting private @NonNull String color = "#FFFFFF";
@Setting private @NonNull Map<String, Context> contexts = new HashMap<>();
@Setting private @NonNull Map<@NonNull String, @NonNull String> formats =
ImmutableMap.of("default", "<color><<displayname><reset><color>> <message>",
"staff", "<#00CED1>[Staff] <color><<displayname><reset><color>> <message>");
@Setting private @NonNull String defaultFormatName = "default";
@Setting private boolean ignorable = true;
@Setting private boolean crossServer = true;
@Setting private boolean honorsRecipientList = false;
@Setting private boolean permissionGroupMatching = false;
@Setting private List<String> groupOverrides = new ArrayList<>();
@Setting private @NonNull List<String> groupOverrides = new ArrayList<>();
@Setting private boolean shouldCancelChatEvent = false;
@Setting private boolean primaryGroupOnly = false;
@Setting private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
@Setting private String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
@Setting private String switchFailureMessage = "<red>You cannot use channel <channel>!";
@Setting private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
@Setting private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
@Setting private String toggleOtherOnMessage = "<gray><player> <reset><gray>can now see <color><channel> <gray>chat!";
@Setting private String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
@Setting private String cannotUseMessage = "You cannot use that channel!";
@Setting private String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
@Setting private @NonNull String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
@Setting private @NonNull String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
@Setting private @NonNull String switchFailureMessage = "<red>You cannot use channel <channel>!";
@Setting private @NonNull String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
@Setting private @NonNull String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
@Setting private @NonNull String toggleOtherOnMessage = "<gray><player> <reset><gray>can now see <color><channel> <gray>chat!";
@Setting private @NonNull String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
@Setting private @NonNull String cannotUseMessage = "You cannot use that channel!";
@Setting private @NonNull String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
public @Nullable String color() {
public @NonNull String color() {
return this.color;
}
public @Nullable Map<String, Context> contexts() {
public @NonNull Map<String, Context> contexts() {
return this.contexts;
}
public @Nullable Map<String, String> formats() {
public @NonNull Map<String, String> formats() {
return this.formats;
}
public @Nullable String defaultFormatName() {
public @NonNull String defaultFormatName() {
return this.defaultFormatName;
}
@@ -74,39 +73,39 @@ public final class SharedChannelOptions {
return this.groupOverrides;
}
public @Nullable String switchMessage() {
public @NonNull String switchMessage() {
return this.switchMessage;
}
public @Nullable String switchOtherMessage() {
public @NonNull String switchOtherMessage() {
return this.switchOtherMessage;
}
public @Nullable String switchFailureMessage() {
public @NonNull String switchFailureMessage() {
return this.switchFailureMessage;
}
public @Nullable String cannotIgnoreMessage() {
public @NonNull String cannotIgnoreMessage() {
return this.cannotIgnoreMessage;
}
public @Nullable String toggleOffMessage() {
public @NonNull String toggleOffMessage() {
return this.toggleOffMessage;
}
public @Nullable String toggleOnMessage() {
public @NonNull String toggleOnMessage() {
return this.toggleOnMessage;
}
public @Nullable String toggleOtherOnMessage() {
public @NonNull String toggleOtherOnMessage() {
return this.toggleOtherOnMessage;
}
public @Nullable String toggleOtherOffMessage() {
public @NonNull String toggleOtherOffMessage() {
return this.toggleOtherOffMessage;
}
public @Nullable String cannotUseMessage() {
public @NonNull String cannotUseMessage() {
return this.cannotUseMessage;
}
@@ -1,7 +1,6 @@
package net.draycia.carbon.api.config;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Comment;
import org.spongepowered.configurate.objectmapping.meta.Setting;
@@ -15,55 +14,55 @@ public final class WhisperOptions {
@Setting
@Comment("")
private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
private @NonNull String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
@Setting
@Comment("")
private String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
private @NonNull String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
@Setting
@Comment("")
private String switchFailureMessage = "<red>You cannot use channel <channel>!";
private @NonNull String switchFailureMessage = "<red>You cannot use channel <channel>!";
@Setting
@Comment("")
private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
private @NonNull String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
@Setting
@Comment("")
private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
private @NonNull String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
@Setting
@Comment("")
private String toggleOtherOnMessage = "<gray><player> <reset><gray>can now see <color><channel> <gray>chat!";
private @NonNull String toggleOtherOnMessage = "<gray><player> <reset><gray>can now see <color><channel> <gray>chat!";
@Setting
@Comment("")
private String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
private @NonNull String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
@Setting
@Comment("")
private String cannotUseMessage = "You cannot use that channel!";
private @NonNull String cannotUseMessage = "You cannot use that channel!";
@Setting
@Comment("")
private String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
private @NonNull String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
@Setting
@Comment("")
private String senderFormat = "<gold>[<white>Me <gray>-> <white><receiver><gold>] <message>";
private @NonNull String senderFormat = "<gold>[<white>Me <gray>-> <white><receiver><gold>] <message>";
@Setting
@Comment("")
private String receiverFormat = "<gold>[<white><sender> <gray>-> <white>Me<gold>] <message>";
private @NonNull String receiverFormat = "<gold>[<white><sender> <gray>-> <white>Me<gold>] <message>";
@Setting
@Comment("")
private String consoleFormat = "<gold>[<white><sender> <gray>-> <white><receiver><gold>] <message>";
private @NonNull String consoleFormat = "<gold>[<white><sender> <gray>-> <white><receiver><gold>] <message>";
@Setting
@Comment("")
private String nowWhisperingPlayer = "<white>You are now whispering <green><player><white>!";
private @NonNull String nowWhisperingPlayer = "<white>You are now whispering <green><player><white>!";
@Setting
@Comment("The message that's sent when attempting to message someone when you have whispers toggled off.")
@@ -85,55 +84,55 @@ public final class WhisperOptions {
return this.pings;
}
public @Nullable String consoleFormat() {
public @NonNull String consoleFormat() {
return this.consoleFormat;
}
public @Nullable String senderFormat() {
public @NonNull String senderFormat() {
return this.senderFormat;
}
public @Nullable String receiverFormat() {
public @NonNull String receiverFormat() {
return this.receiverFormat;
}
public @Nullable String switchMessage() {
public @NonNull String switchMessage() {
return this.switchMessage;
}
public @Nullable String switchOtherMessage() {
public @NonNull String switchOtherMessage() {
return this.switchOtherMessage;
}
public @Nullable String switchFailureMessage() {
public @NonNull String switchFailureMessage() {
return this.switchFailureMessage;
}
public @Nullable String cannotIgnoreMessage() {
public @NonNull String cannotIgnoreMessage() {
return this.cannotIgnoreMessage;
}
public @Nullable String toggleOffMessage() {
public @NonNull String toggleOffMessage() {
return this.toggleOffMessage;
}
public @Nullable String toggleOnMessage() {
public @NonNull String toggleOnMessage() {
return this.toggleOnMessage;
}
public @Nullable String toggleOtherOnMessage() {
public @NonNull String toggleOtherOnMessage() {
return this.toggleOtherOnMessage;
}
public @Nullable String toggleOtherOffMessage() {
public @NonNull String toggleOtherOffMessage() {
return this.toggleOtherOffMessage;
}
public @Nullable String cannotUseMessage() {
public @NonNull String cannotUseMessage() {
return this.cannotUseMessage;
}
public @Nullable String nowWhisperingPlayer() {
public @NonNull String nowWhisperingPlayer() {
return this.nowWhisperingPlayer;
}
@@ -141,7 +140,7 @@ public final class WhisperOptions {
return this.senderToggledOff;
}
public @Nullable String receiverToggledOff() {
public @NonNull String receiverToggledOff() {
return this.receiverToggledOff;
}