mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
Nullability annotations
This commit is contained in:
6 files changed
+31
-15
No files matched your search
@@ -47,7 +47,7 @@ public class ChannelRegistry implements Registry<ChatChannel> {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatChannel get(String key) {
|
||||
public ChatChannel get(@NotNull String key) {
|
||||
return registry.get(key);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,14 @@ import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
@NotNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public CarbonPlaceholders(CarbonChat carbonChat) {
|
||||
public CarbonPlaceholders(@NotNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@@ -38,7 +40,9 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
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();
|
||||
|
||||
if (key.startsWith("can_use_")) {
|
||||
|
||||
@@ -41,14 +41,18 @@ import org.apache.commons.lang.NotImplementedException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public final class CarbonUtils {
|
||||
|
||||
@NotNull
|
||||
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) {
|
||||
return net.kyori.adventure.text.TextComponent.empty();
|
||||
}
|
||||
@@ -80,11 +84,13 @@ public final class CarbonUtils {
|
||||
return BungeeCordComponentSerializer.get().deserialize(component.create());
|
||||
}
|
||||
|
||||
public static TextColor parseColor(String input) {
|
||||
@Nullable
|
||||
public static TextColor parseColor(@Nullable String 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) {
|
||||
input = "white";
|
||||
}
|
||||
@@ -108,6 +114,7 @@ public final class CarbonUtils {
|
||||
return TextColor.fromCSSHexString(input);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Argument onlineChatUserArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
@@ -130,6 +137,7 @@ public final class CarbonUtils {
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Argument chatUserArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
@@ -146,6 +154,7 @@ public final class CarbonUtils {
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Argument textColorArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
TextColor color = parseColor(input);
|
||||
@@ -158,6 +167,7 @@ public final class CarbonUtils {
|
||||
}).overrideSuggestions(colors);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Argument channelArgument() {
|
||||
return new CustomArgument<>((input) -> {
|
||||
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.ItemStack;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored") // This is a common pattern in this class.
|
||||
public final class FunctionalityConstants {
|
||||
|
||||
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 {
|
||||
runnable.run();
|
||||
return true;
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package net.draycia.carbon.util;
|
||||
|
||||
import io.lettuce.core.pubsub.RedisPubSubListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RedisListener extends RedisPubSubListener<String, String> {
|
||||
|
||||
void message(String channel, String message);
|
||||
@Override
|
||||
void message(@NotNull String channel, @NotNull String message);
|
||||
|
||||
@Override
|
||||
default void message(String pattern, String channel, String message) { }
|
||||
default void message(@NotNull String pattern, @NotNull String channel, @NotNull String message) { }
|
||||
|
||||
@Override
|
||||
default void subscribed(String channel, long count) { }
|
||||
default void subscribed(@NotNull String channel, long count) { }
|
||||
|
||||
@Override
|
||||
default void psubscribed(String pattern, long count) { }
|
||||
default void psubscribed(@NotNull String pattern, long count) { }
|
||||
|
||||
@Override
|
||||
default void unsubscribed(String channel, long count) { }
|
||||
default void unsubscribed(@NotNull String channel, long count) { }
|
||||
|
||||
@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
|
||||
*/
|
||||
@Nullable
|
||||
T get(String key);
|
||||
T get(@NotNull String key);
|
||||
|
||||
/**
|
||||
* Clears all registered entries from the registry
|
||||
|
||||
Reference in new issue
Block a user