Use adventure textOfChildren method

This commit is contained in:
Jason Penilla committed 2024-01-13 21:03:33 -07:00
1 parent fd20b5e583
commit 4cbe7d4bf9
4 files changed
+5 -54

No files matched your search

@@ -29,7 +29,6 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import xyz.jpenilla.minimotd.common.util.Components;
import static net.kyori.adventure.text.Component.space;
import static net.kyori.adventure.text.Component.text;
@@ -77,7 +76,7 @@ public final class CommandHandler {
this.miniMOTD.reload();
} catch (final Exception ex) {
this.miniMOTD.logger().warn("Failed to reload MiniMOTD. Ensure there are no errors in your config files.", ex);
audience.sendMessage(Components.ofChildren(
audience.sendMessage(Component.textOfChildren(
Constants.COMMAND_PREFIX,
space(),
text("Failed to reload MiniMOTD. Ensure there are no errors in your config files. See console for more details.", RED)
@@ -85,7 +84,7 @@ public final class CommandHandler {
return;
}
audience.sendMessage(Components.ofChildren(
audience.sendMessage(Component.textOfChildren(
Constants.COMMAND_PREFIX,
space(),
text("Done reloading configuration.", GREEN)
@@ -35,7 +35,6 @@ import org.checkerframework.framework.qual.DefaultQualifier;
import org.slf4j.Logger;
import xyz.jpenilla.minimotd.common.config.ConfigManager;
import xyz.jpenilla.minimotd.common.config.MOTDConfig;
import xyz.jpenilla.minimotd.common.util.Components;
import static net.kyori.adventure.text.Component.newline;
@@ -91,7 +90,7 @@ public final class MiniMOTD<I> {
}
final int index = config.motds().size() == 1 ? 0 : ThreadLocalRandom.current().nextInt(config.motds().size());
final MOTDConfig.MOTD motdConfig = config.motds().get(index);
final Component motd = Components.ofChildren(
final Component motd = Component.textOfChildren(
parse(motdConfig.line1(), count),
newline(),
parse(motdConfig.line2(), count)
@@ -1,47 +0,0 @@
/*
* This file is part of MiniMOTD, licensed under the MIT License.
*
* Copyright (c) 2020-2024 Jason Penilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package xyz.jpenilla.minimotd.common.util;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.TextComponent;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import static net.kyori.adventure.text.Component.empty;
import static net.kyori.adventure.text.Component.text;
@DefaultQualifier(NonNull.class)
public final class Components {
private Components() {
throw new IllegalStateException();
}
public static TextComponent ofChildren(final ComponentLike... children) {
if (children.length == 0) {
return empty();
}
return text().append(children).build();
}
}
@@ -41,14 +41,14 @@ class ComponentColorDownsamplerTest {
@Test
void testColorDownsampling() {
final Component fullColor = Components.ofChildren(
final Component fullColor = Component.textOfChildren(
text("Green ", GREEN),
text("Orange Yellow ", ORANGE_YELLOW),
text("Pink ", PINK),
text("Blue ", BLUE),
text("Lime Green", LIME_GREEN)
);
final Component expectedDownsample = Components.ofChildren(
final Component expectedDownsample = Component.textOfChildren(
text("Green ", nearestTo(GREEN)),
text("Orange Yellow ", nearestTo(ORANGE_YELLOW)),
text("Pink ", nearestTo(PINK)),