annotate utils
This commit is contained in:
parent
cb9e5e9553
commit
3d86639d4d
@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
@AutoService(ComponentLoggerProvider.class)
|
@AutoService(ComponentLoggerProvider.class)
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
public final class ComponentLoggerProviderImpl implements ComponentLoggerProvider {
|
public final class ComponentLoggerProviderImpl implements ComponentLoggerProvider {
|
||||||
private static final ANSIComponentSerializer SERIALIZER = ANSIComponentSerializer.builder()
|
private static final @NotNull ANSIComponentSerializer SERIALIZER = ANSIComponentSerializer.builder()
|
||||||
.flattener(TranslatableMapper.FLATTENER)
|
.flattener(TranslatableMapper.FLATTENER)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -14,9 +14,9 @@ import java.time.Duration;
|
|||||||
|
|
||||||
public class GenericUtil {
|
public class GenericUtil {
|
||||||
|
|
||||||
public static final TextColor COLOR = TextColor.color(102,255,230);
|
public static final @NotNull TextColor COLOR = TextColor.color(102,255,230);
|
||||||
public static final Style STYLE = Style.style(COLOR, TextDecoration.BOLD);
|
public static final @NotNull Style STYLE = Style.style(COLOR, TextDecoration.BOLD);
|
||||||
public static final PlainTextComponentSerializer plainTextSerializer = PlainTextComponentSerializer.plainText();
|
public static final @NotNull PlainTextComponentSerializer plainTextSerializer = PlainTextComponentSerializer.plainText();
|
||||||
|
|
||||||
public static @NotNull String formatDuration(Duration duration) {
|
public static @NotNull String formatDuration(Duration duration) {
|
||||||
if (duration.isNegative()) duration = duration.negated();
|
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();
|
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) {
|
switch (workstation) {
|
||||||
case BARREL:
|
case BARREL:
|
||||||
return Villager.Profession.FISHERMAN;
|
return Villager.Profession.FISHERMAN;
|
||||||
|
@ -4,27 +4,28 @@ import me.xginko.villageroptimizer.VillagerOptimizer;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextReplacementConfig;
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class KyoriUtil {
|
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);
|
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);
|
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()
|
return input.replaceText(TextReplacementConfig.builder()
|
||||||
.match("(?s).*")
|
.match("(?s).*")
|
||||||
.replacement((result, builder) -> builder.content(result.group(0).toUpperCase(locale)))
|
.replacement((result, builder) -> builder.content(result.group(0).toUpperCase(locale)))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String translateChatColor(String string) {
|
public static @NotNull String translateChatColor(@NotNull String string) {
|
||||||
string = string.replace("&0", "<black>");
|
string = string.replace("&0", "<black>");
|
||||||
string = string.replace("&1", "<dark_blue>");
|
string = string.replace("&1", "<dark_blue>");
|
||||||
string = string.replace("&2", "<dark_green>");
|
string = string.replace("&2", "<dark_green>");
|
||||||
|
@ -6,6 +6,7 @@ import net.kyori.adventure.text.flattener.ComponentFlattener;
|
|||||||
import net.kyori.adventure.translation.GlobalTranslator;
|
import net.kyori.adventure.translation.GlobalTranslator;
|
||||||
import net.kyori.adventure.translation.TranslationRegistry;
|
import net.kyori.adventure.translation.TranslationRegistry;
|
||||||
import net.kyori.adventure.translation.Translator;
|
import net.kyori.adventure.translation.Translator;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -15,14 +16,14 @@ import java.util.function.Consumer;
|
|||||||
public enum TranslatableMapper implements BiConsumer<TranslatableComponent, Consumer<Component>> {
|
public enum TranslatableMapper implements BiConsumer<TranslatableComponent, Consumer<Component>> {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
public static final ComponentFlattener FLATTENER = ComponentFlattener.basic().toBuilder()
|
public static final @NotNull ComponentFlattener FLATTENER = ComponentFlattener.basic().toBuilder()
|
||||||
.complexMapper(TranslatableComponent.class, TranslatableMapper.INSTANCE)
|
.complexMapper(TranslatableComponent.class, TranslatableMapper.INSTANCE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(
|
public void accept(
|
||||||
final TranslatableComponent translatableComponent,
|
final @NotNull TranslatableComponent translatableComponent,
|
||||||
final Consumer<Component> componentConsumer
|
final @NotNull Consumer<Component> componentConsumer
|
||||||
) {
|
) {
|
||||||
for (final Translator source : GlobalTranslator.translator().sources()) {
|
for (final Translator source : GlobalTranslator.translator().sources()) {
|
||||||
if (source instanceof TranslationRegistry && ((TranslationRegistry) source).contains(translatableComponent.key())) {
|
if (source instanceof TranslationRegistry && ((TranslationRegistry) source).contains(translatableComponent.key())) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user