Nullability annotations

This commit is contained in:
Mariell Hoversholm committed 2020-09-05 16:22:39 +02:00
1 parent c8990e9a13
commit 8040c5fb72
6 files changed
+31 -15

No files matched your search

@@ -47,7 +47,7 @@ public class ChannelRegistry implements Registry<ChatChannel> {
@Override @Override
@Nullable @Nullable
public ChatChannel get(String key) { public ChatChannel get(@NotNull String key) {
return registry.get(key); return registry.get(key);
} }
@@ -6,12 +6,14 @@ import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser; import net.draycia.carbon.storage.ChatUser;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CarbonPlaceholders extends PlaceholderExpansion { public class CarbonPlaceholders extends PlaceholderExpansion {
@NotNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public CarbonPlaceholders(CarbonChat carbonChat) { public CarbonPlaceholders(@NotNull CarbonChat carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
} }
@@ -38,7 +40,9 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
return true; return true;
} }
public String onPlaceholderRequest(final Player player, final String identifier) { @Override
@Nullable
public String onPlaceholderRequest(@NotNull final Player player, @NotNull final String identifier) {
String key = identifier.toLowerCase(); String key = identifier.toLowerCase();
if (key.startsWith("can_use_")) { if (key.startsWith("can_use_")) {
@@ -41,14 +41,18 @@ import org.apache.commons.lang.NotImplementedException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
public final class CarbonUtils { public final class CarbonUtils {
@NotNull
private static final String[] colors; private static final String[] colors;
public static Component createComponent(final Player player) { @NotNull
public static Component createComponent(@NotNull final Player player) {
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) { if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
return net.kyori.adventure.text.TextComponent.empty(); return net.kyori.adventure.text.TextComponent.empty();
} }
@@ -80,11 +84,13 @@ public final class CarbonUtils {
return BungeeCordComponentSerializer.get().deserialize(component.create()); return BungeeCordComponentSerializer.get().deserialize(component.create());
} }
public static TextColor parseColor(String input) { @Nullable
public static TextColor parseColor(@Nullable String input) {
return parseColor(null, input); return parseColor(null, input);
} }
public static TextColor parseColor(ChatUser user, String input) { @Nullable
public static TextColor parseColor(@Nullable ChatUser user, @Nullable String input) {
if (input == null) { if (input == null) {
input = "white"; input = "white";
} }
@@ -108,6 +114,7 @@ public final class CarbonUtils {
return TextColor.fromCSSHexString(input); return TextColor.fromCSSHexString(input);
} }
@NotNull
public static Argument onlineChatUserArgument() { public static Argument onlineChatUserArgument() {
return new CustomArgument<>((input) -> { return new CustomArgument<>((input) -> {
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat"); CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
@@ -130,6 +137,7 @@ public final class CarbonUtils {
}); });
} }
@NotNull
public static Argument chatUserArgument() { public static Argument chatUserArgument() {
return new CustomArgument<>((input) -> { return new CustomArgument<>((input) -> {
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat"); CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
@@ -146,6 +154,7 @@ public final class CarbonUtils {
}); });
} }
@NotNull
public static Argument textColorArgument() { public static Argument textColorArgument() {
return new CustomArgument<>((input) -> { return new CustomArgument<>((input) -> {
TextColor color = parseColor(input); TextColor color = parseColor(input);
@@ -158,6 +167,7 @@ public final class CarbonUtils {
}).overrideSuggestions(colors); }).overrideSuggestions(colors);
} }
@NotNull
public static Argument channelArgument() { public static Argument channelArgument() {
return new CustomArgument<>((input) -> { return new CustomArgument<>((input) -> {
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat"); CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
@@ -2,14 +2,14 @@ package net.draycia.carbon.util;
import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.NonNull; import org.jetbrains.annotations.NotNull;
@SuppressWarnings("ResultOfMethodCallIgnored") // This is a common pattern in this class. @SuppressWarnings("ResultOfMethodCallIgnored") // This is a common pattern in this class.
public final class FunctionalityConstants { public final class FunctionalityConstants {
public static final boolean HAS_HOVER_EVENT_METHOD = noThrow(() -> ItemFactory.class.getMethod("hoverContentOf", ItemStack.class)); public static final boolean HAS_HOVER_EVENT_METHOD = noThrow(() -> ItemFactory.class.getMethod("hoverContentOf", ItemStack.class));
private static boolean noThrow(@NonNull ThrowingRunnable runnable) { private static boolean noThrow(@NotNull ThrowingRunnable runnable) {
try { try {
runnable.run(); runnable.run();
return true; return true;
@@ -1,25 +1,27 @@
package net.draycia.carbon.util; package net.draycia.carbon.util;
import io.lettuce.core.pubsub.RedisPubSubListener; import io.lettuce.core.pubsub.RedisPubSubListener;
import org.jetbrains.annotations.NotNull;
@FunctionalInterface @FunctionalInterface
public interface RedisListener extends RedisPubSubListener<String, String> { public interface RedisListener extends RedisPubSubListener<String, String> {
void message(String channel, String message); @Override
void message(@NotNull String channel, @NotNull String message);
@Override @Override
default void message(String pattern, String channel, String message) { } default void message(@NotNull String pattern, @NotNull String channel, @NotNull String message) { }
@Override @Override
default void subscribed(String channel, long count) { } default void subscribed(@NotNull String channel, long count) { }
@Override @Override
default void psubscribed(String pattern, long count) { } default void psubscribed(@NotNull String pattern, long count) { }
@Override @Override
default void unsubscribed(String channel, long count) { } default void unsubscribed(@NotNull String channel, long count) { }
@Override @Override
default void punsubscribed(String pattern, long count) { } default void punsubscribed(@NotNull String pattern, long count) { }
} }
@@ -28,7 +28,7 @@ public interface Registry<T> {
* @return The entry associated with the key * @return The entry associated with the key
*/ */
@Nullable @Nullable
T get(String key); T get(@NotNull String key);
/** /**
* Clears all registered entries from the registry * Clears all registered entries from the registry