annotate utils

This commit is contained in:
xGinko 2024-03-20 10:16:33 +01:00
parent cb9e5e9553
commit 3d86639d4d
4 changed files with 15 additions and 13 deletions

View File

@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
@AutoService(ComponentLoggerProvider.class)
@SuppressWarnings("UnstableApiUsage")
public final class ComponentLoggerProviderImpl implements ComponentLoggerProvider {
private static final ANSIComponentSerializer SERIALIZER = ANSIComponentSerializer.builder()
private static final @NotNull ANSIComponentSerializer SERIALIZER = ANSIComponentSerializer.builder()
.flattener(TranslatableMapper.FLATTENER)
.build();

View File

@ -14,9 +14,9 @@ import java.time.Duration;
public class GenericUtil {
public static final TextColor COLOR = TextColor.color(102,255,230);
public static final Style STYLE = Style.style(COLOR, TextDecoration.BOLD);
public static final PlainTextComponentSerializer plainTextSerializer = PlainTextComponentSerializer.plainText();
public static final @NotNull TextColor COLOR = TextColor.color(102,255,230);
public static final @NotNull Style STYLE = Style.style(COLOR, TextDecoration.BOLD);
public static final @NotNull PlainTextComponentSerializer plainTextSerializer = PlainTextComponentSerializer.plainText();
public static @NotNull String formatDuration(Duration duration) {
if (duration.isNegative()) duration = duration.negated();
@ -34,7 +34,7 @@ public class GenericUtil {
}
}
public static String formatLocation(@NotNull Location location) {
public static @NotNull String formatLocation(@NotNull Location location) {
return "[" + location.getWorld().getName() + "] x=" + location.getBlockX() + ", y=" + location.getBlockY() + ", z=" + location.getBlockZ();
}
@ -51,7 +51,7 @@ public class GenericUtil {
}
}
public static Villager.Profession getWorkstationProfession(@NotNull Material workstation) {
public static @NotNull Villager.Profession getWorkstationProfession(@NotNull Material workstation) {
switch (workstation) {
case BARREL:
return Villager.Profession.FISHERMAN;

View File

@ -4,27 +4,28 @@ import me.xginko.villageroptimizer.VillagerOptimizer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
public class KyoriUtil {
public static void sendMessage(CommandSender sender, Component message) {
public static void sendMessage(@NotNull CommandSender sender, @NotNull Component message) {
VillagerOptimizer.getAudiences().sender(sender).sendMessage(message);
}
public static void sendActionBar(CommandSender sender, Component message) {
public static void sendActionBar(@NotNull CommandSender sender, @NotNull Component message) {
VillagerOptimizer.getAudiences().sender(sender).sendActionBar(message);
}
public static Component toUpperCase(Component input, Locale locale) {
public static @NotNull Component toUpperCase(@NotNull Component input, @NotNull Locale locale) {
return input.replaceText(TextReplacementConfig.builder()
.match("(?s).*")
.replacement((result, builder) -> builder.content(result.group(0).toUpperCase(locale)))
.build());
}
public static String translateChatColor(String string) {
public static @NotNull String translateChatColor(@NotNull String string) {
string = string.replace("&0", "<black>");
string = string.replace("&1", "<dark_blue>");
string = string.replace("&2", "<dark_green>");

View File

@ -6,6 +6,7 @@ import net.kyori.adventure.text.flattener.ComponentFlattener;
import net.kyori.adventure.translation.GlobalTranslator;
import net.kyori.adventure.translation.TranslationRegistry;
import net.kyori.adventure.translation.Translator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
@ -15,14 +16,14 @@ import java.util.function.Consumer;
public enum TranslatableMapper implements BiConsumer<TranslatableComponent, Consumer<Component>> {
INSTANCE;
public static final ComponentFlattener FLATTENER = ComponentFlattener.basic().toBuilder()
public static final @NotNull ComponentFlattener FLATTENER = ComponentFlattener.basic().toBuilder()
.complexMapper(TranslatableComponent.class, TranslatableMapper.INSTANCE)
.build();
@Override
public void accept(
final TranslatableComponent translatableComponent,
final Consumer<Component> componentConsumer
final @NotNull TranslatableComponent translatableComponent,
final @NotNull Consumer<Component> componentConsumer
) {
for (final Translator source : GlobalTranslator.translator().sources()) {
if (source instanceof TranslationRegistry && ((TranslationRegistry) source).contains(translatableComponent.key())) {