mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-07 08:58:20 +01:00
Revert argument changes to single file with adventure style result
This commit is contained in:
parent
8ee624f02d
commit
b4b2cf70c5
@ -107,34 +107,12 @@ public class ArgumentType {
|
|||||||
// Minecraft specific arguments
|
// Minecraft specific arguments
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link ArgumentTextColor} for colors, {@link ArgumentTextDecoration} for styles, {@link ArgumentColor} for raw colors,
|
* @see ArgumentColor
|
||||||
* {@link ArgumentDyeColor} for dye colors and {@link ArgumentTeamColor} for team formats
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public static ArgumentChatColor ChatColor(@NotNull String id) {
|
|
||||||
return new ArgumentChatColor(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArgumentTextColor TextColor(@NotNull String id) {
|
|
||||||
return new ArgumentTextColor(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArgumentTextDecoration TextDecoration(@NotNull String id) {
|
|
||||||
return new ArgumentTextDecoration(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArgumentColor Color(@NotNull String id) {
|
public static ArgumentColor Color(@NotNull String id) {
|
||||||
return new ArgumentColor(id);
|
return new ArgumentColor(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArgumentDyeColor DyeColor(@NotNull String id) {
|
|
||||||
return new ArgumentDyeColor(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArgumentTeamColor TeamColor(@NotNull String id) {
|
|
||||||
return new ArgumentTeamColor(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ArgumentTime
|
* @see ArgumentTime
|
||||||
*/
|
*/
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
package net.minestom.server.command.builder.arguments.minecraft;
|
|
||||||
|
|
||||||
import net.minestom.server.chat.ChatColor;
|
|
||||||
import net.minestom.server.command.builder.NodeMaker;
|
|
||||||
import net.minestom.server.command.builder.arguments.Argument;
|
|
||||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
|
||||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents an argument which will give you a {@link ChatColor}.
|
|
||||||
* <p>
|
|
||||||
* Example: red, white, reset
|
|
||||||
* @deprecated Use {@link ArgumentTextColor} for colors, {@link ArgumentTextDecoration} for styles, {@link ArgumentColor} for raw colors,
|
|
||||||
* {@link ArgumentDyeColor} for dye colors and {@link ArgumentTeamColor} for team formats
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class ArgumentChatColor extends Argument<ChatColor> {
|
|
||||||
|
|
||||||
public static final int UNDEFINED_COLOR = -2;
|
|
||||||
|
|
||||||
public ArgumentChatColor(String id) {
|
|
||||||
super(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public ChatColor parse(@NotNull String input) throws ArgumentSyntaxException {
|
|
||||||
final ChatColor color = ChatColor.fromName(input);
|
|
||||||
if (color == ChatColor.NO_COLOR)
|
|
||||||
throw new ArgumentSyntaxException("Undefined color", input, UNDEFINED_COLOR);
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
|
||||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
|
||||||
argumentNode.parser = "minecraft:chat_color";
|
|
||||||
|
|
||||||
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,8 @@
|
|||||||
package net.minestom.server.command.builder.arguments.minecraft;
|
package net.minestom.server.command.builder.arguments.minecraft;
|
||||||
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.minestom.server.color.Color;
|
import net.kyori.adventure.text.format.Style;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
import net.minestom.server.command.builder.NodeMaker;
|
import net.minestom.server.command.builder.NodeMaker;
|
||||||
import net.minestom.server.command.builder.arguments.Argument;
|
import net.minestom.server.command.builder.arguments.Argument;
|
||||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||||
@ -9,26 +10,36 @@ import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an argument that will give you a {@link Color}. Input is parsed
|
* Represents an argument which will give you a {@link Style} containing the colour or no
|
||||||
* first as a hex string ({@code #int}), then as a CSS hex string ({@code #rrggbb} or
|
* colour if the argument was {@code reset}.
|
||||||
* {@code #rgb}), then as an integer and finally as a named text colour. The values for
|
* <p>
|
||||||
* the named text colours can be found in {@link NamedTextColor}.
|
* Example: red, white, reset
|
||||||
* <br><br>
|
|
||||||
* This class is essentially a wrapper around {@link ArgumentTextColor}.
|
|
||||||
*/
|
*/
|
||||||
public class ArgumentColor extends Argument<Color> {
|
public class ArgumentColor extends Argument<Style> {
|
||||||
private final ArgumentTextColor argumentTextColor;
|
|
||||||
|
|
||||||
public static int UNDEFINED_COLOR = ArgumentTextColor.UNDEFINED_COLOR;
|
public static final int UNDEFINED_COLOR = -2;
|
||||||
|
|
||||||
public ArgumentColor(@NotNull String id) {
|
public ArgumentColor(String id) {
|
||||||
super(id);
|
super(id);
|
||||||
argumentTextColor = new ArgumentTextColor(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Color parse(@NotNull String input) throws ArgumentSyntaxException {
|
public Style parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||||
return new Color(this.argumentTextColor.parse(input));
|
String uppercaseInput = input.toUpperCase();
|
||||||
|
|
||||||
|
// check for colour
|
||||||
|
NamedTextColor color = NamedTextColor.NAMES.value(uppercaseInput);
|
||||||
|
if (color != null) {
|
||||||
|
return Style.style(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for reset
|
||||||
|
if (uppercaseInput.equals("RESET")) {
|
||||||
|
return Style.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ArgumentSyntaxException("Undefined color", input, UNDEFINED_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
package net.minestom.server.command.builder.arguments.minecraft;
|
|
||||||
|
|
||||||
import net.minestom.server.color.DyeColor;
|
|
||||||
import net.minestom.server.command.builder.NodeMaker;
|
|
||||||
import net.minestom.server.command.builder.arguments.Argument;
|
|
||||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An argument that returns a {@link DyeColor} from the name of the dye color.
|
|
||||||
*/
|
|
||||||
public class ArgumentDyeColor extends Argument<DyeColor> {
|
|
||||||
public static int UNDEFINED_DYE_COLOR = -2;
|
|
||||||
|
|
||||||
public ArgumentDyeColor(@NotNull String id) {
|
|
||||||
super(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull DyeColor parse(@NotNull String input) throws ArgumentSyntaxException {
|
|
||||||
try {
|
|
||||||
return DyeColor.valueOf(input.toUpperCase().replace(' ', '_').trim());
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
throw new ArgumentSyntaxException("Undefined dye color", input, UNDEFINED_DYE_COLOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
package net.minestom.server.command.builder.arguments.minecraft;
|
|
||||||
|
|
||||||
import net.minestom.server.color.TeamColor;
|
|
||||||
import net.minestom.server.command.builder.NodeMaker;
|
|
||||||
import net.minestom.server.command.builder.arguments.Argument;
|
|
||||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
|
||||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An argument that will give you a {@link TeamColor} from it's name or the int code.
|
|
||||||
*/
|
|
||||||
public class ArgumentTeamColor extends Argument<TeamColor> {
|
|
||||||
public static final int UNDEFINED_TEAM_FORMAT = -2;
|
|
||||||
|
|
||||||
public ArgumentTeamColor(@NotNull String id) {
|
|
||||||
super(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull TeamColor parse(@NotNull String input) throws ArgumentSyntaxException {
|
|
||||||
try {
|
|
||||||
return TeamColor.valueOf(input.toUpperCase().trim().replace(' ', '_'));
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
try {
|
|
||||||
return TeamColor.values()[Integer.parseInt(input)];
|
|
||||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException alsoIgnored) {
|
|
||||||
throw new ArgumentSyntaxException("Undefined team format!", input, UNDEFINED_TEAM_FORMAT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
|
||||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
|
||||||
argumentNode.parser = "minecraft:team_format";
|
|
||||||
|
|
||||||
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
package net.minestom.server.command.builder.arguments.minecraft;
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
|
||||||
import net.minestom.server.command.builder.NodeMaker;
|
|
||||||
import net.minestom.server.command.builder.arguments.Argument;
|
|
||||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
|
||||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
|
||||||
import net.minestom.server.utils.MathUtils;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents an argument that will give you a {@link TextColor}. Input is parsed
|
|
||||||
* first as a hex string ({@code #int}), then as a CSS hex string ({@code #rrggbb} or
|
|
||||||
* {@code #rgb}), then as an integer and finally as a named text colour. The values for
|
|
||||||
* the named text colours can be found in {@link NamedTextColor}.
|
|
||||||
*/
|
|
||||||
public class ArgumentTextColor extends Argument<TextColor> {
|
|
||||||
|
|
||||||
public static final int UNDEFINED_COLOR = -2;
|
|
||||||
|
|
||||||
public ArgumentTextColor(@NotNull String id) {
|
|
||||||
super(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull TextColor parse(@NotNull String input) throws ArgumentSyntaxException {
|
|
||||||
TextColor textColor;
|
|
||||||
|
|
||||||
// first try standard hex
|
|
||||||
textColor = TextColor.fromHexString(input);
|
|
||||||
if (textColor != null) {
|
|
||||||
return textColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now try CSS hex
|
|
||||||
textColor = TextColor.fromCSSHexString(input);
|
|
||||||
if (textColor != null) {
|
|
||||||
return textColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now try int
|
|
||||||
Integer number = MathUtils.tryParse(input);
|
|
||||||
if (number != null) {
|
|
||||||
return TextColor.color(number);
|
|
||||||
}
|
|
||||||
|
|
||||||
// fallback to legacy colour names
|
|
||||||
textColor = NamedTextColor.NAMES.value(input.toLowerCase());
|
|
||||||
if (textColor != null) {
|
|
||||||
return textColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// throw an error
|
|
||||||
throw new ArgumentSyntaxException("Undefined color", input, UNDEFINED_COLOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
|
||||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
|
||||||
argumentNode.parser = "minecraft:text_color";
|
|
||||||
|
|
||||||
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
package net.minestom.server.command.builder.arguments.minecraft;
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
|
||||||
import net.minestom.server.command.builder.NodeMaker;
|
|
||||||
import net.minestom.server.command.builder.arguments.Argument;
|
|
||||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
|
||||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents an argument that will give you a {@link TextDecoration}. Valid values can
|
|
||||||
* be found in the text decoration class. Values are case-insensitive.
|
|
||||||
*/
|
|
||||||
public class ArgumentTextDecoration extends Argument<TextDecoration> {
|
|
||||||
public static final int UNDEFINED_DECORATION = -2;
|
|
||||||
|
|
||||||
public ArgumentTextDecoration(@NotNull String id) {
|
|
||||||
super(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public TextDecoration parse(@NotNull String input) throws ArgumentSyntaxException {
|
|
||||||
TextDecoration decoration = TextDecoration.NAMES.value(input.toLowerCase());
|
|
||||||
|
|
||||||
if (decoration != null) {
|
|
||||||
return decoration;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new ArgumentSyntaxException("Undefined text decoration", input, UNDEFINED_DECORATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
|
||||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
|
||||||
argumentNode.parser = "minecraft:text_color";
|
|
||||||
|
|
||||||
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user