mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 15:08:29 +01:00
fix TeamColor allowing unsupported formats
This commit is contained in:
parent
aa7703c056
commit
d419bf9401
@ -6,9 +6,8 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.minestom.server.color.Color;
|
||||
import net.minestom.server.color.TeamFormat;
|
||||
import net.minestom.server.color.TeamColor;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -289,8 +288,17 @@ public final class ChatColor {
|
||||
return new Color(red, green, blue);
|
||||
}
|
||||
|
||||
public TeamFormat asTeamFormat() {
|
||||
return TeamFormat.values()[this.getId()];
|
||||
/**
|
||||
* Gets the TeamColor of this chat color.
|
||||
*
|
||||
* @return the team color, or null if there is no team color for this chat color
|
||||
*/
|
||||
public @Nullable TeamColor asTeamColor() {
|
||||
try {
|
||||
return TeamColor.values()[this.getId()];
|
||||
} catch (ArrayIndexOutOfBoundsException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
77
src/main/java/net/minestom/server/color/TeamColor.java
Normal file
77
src/main/java/net/minestom/server/color/TeamColor.java
Normal file
@ -0,0 +1,77 @@
|
||||
package net.minestom.server.color;
|
||||
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.util.RGBLike;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* The format used for teams. Note that this is often referred to as "team color". This
|
||||
* is misleading as teams can also use text decoration like bold, italics, etc.
|
||||
*/
|
||||
public enum TeamColor implements RGBLike {
|
||||
BLACK(NamedTextColor.BLACK),
|
||||
DARK_BLUE(NamedTextColor.DARK_BLUE),
|
||||
DARK_GREEN(NamedTextColor.DARK_GREEN),
|
||||
DARK_AQUA(NamedTextColor.DARK_AQUA),
|
||||
DARK_RED(NamedTextColor.DARK_RED),
|
||||
DARK_PURPLE(NamedTextColor.DARK_PURPLE),
|
||||
GOLD(NamedTextColor.GOLD),
|
||||
GRAY(NamedTextColor.GRAY),
|
||||
DARK_GRAY(NamedTextColor.DARK_GRAY),
|
||||
BLUE(NamedTextColor.BLUE),
|
||||
GREEN(NamedTextColor.GREEN),
|
||||
AQUA(NamedTextColor.AQUA),
|
||||
RED(NamedTextColor.RED),
|
||||
LIGHT_PURPLE(NamedTextColor.LIGHT_PURPLE),
|
||||
YELLOW(NamedTextColor.YELLOW),
|
||||
WHITE(NamedTextColor.WHITE);
|
||||
|
||||
private final TextColor color;
|
||||
|
||||
TeamColor(TextColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text color equivalent to this team color, if any.
|
||||
*
|
||||
* @return the text color
|
||||
*/
|
||||
public @Nullable TextColor getTextColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color equivalent to this team color, if any.
|
||||
*
|
||||
* @return the color
|
||||
*/
|
||||
public @Nullable Color getColor() {
|
||||
return this.color == null ? null : new Color(this.color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID number of this team color.
|
||||
*
|
||||
* @return the id number
|
||||
*/
|
||||
public int getId() {
|
||||
return this.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int red() {
|
||||
return this.color.red();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int green() {
|
||||
return this.color.green();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int blue() {
|
||||
return this.color.blue();
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
package net.minestom.server.color;
|
||||
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.util.RGBLike;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* The format used for teams. Note that this is often referred to as "team color". This
|
||||
* is misleading as teams can also use text decoration like bold, italics, etc.
|
||||
*/
|
||||
public enum TeamFormat implements RGBLike {
|
||||
BLACK(NamedTextColor.BLACK),
|
||||
DARK_BLUE(NamedTextColor.DARK_BLUE),
|
||||
DARK_GREEN(NamedTextColor.DARK_GREEN),
|
||||
DARK_AQUA(NamedTextColor.DARK_AQUA),
|
||||
DARK_RED(NamedTextColor.DARK_RED),
|
||||
DARK_PURPLE(NamedTextColor.DARK_PURPLE),
|
||||
GOLD(NamedTextColor.GOLD),
|
||||
GRAY(NamedTextColor.GRAY),
|
||||
DARK_GRAY(NamedTextColor.DARK_GRAY),
|
||||
BLUE(NamedTextColor.BLUE),
|
||||
GREEN(NamedTextColor.GREEN),
|
||||
AQUA(NamedTextColor.AQUA),
|
||||
RED(NamedTextColor.RED),
|
||||
LIGHT_PURPLE(NamedTextColor.LIGHT_PURPLE),
|
||||
YELLOW(NamedTextColor.YELLOW),
|
||||
WHITE(NamedTextColor.WHITE),
|
||||
OBFUSCATED(TextDecoration.OBFUSCATED),
|
||||
BOLD(TextDecoration.BOLD),
|
||||
STRIKETHROUGH(TextDecoration.STRIKETHROUGH),
|
||||
UNDERLINE(TextDecoration.UNDERLINED),
|
||||
ITALIC(TextDecoration.ITALIC),
|
||||
RESET(null, null);
|
||||
|
||||
private final TextDecoration decoration;
|
||||
private final TextColor color;
|
||||
|
||||
TeamFormat(TextDecoration decoration) {
|
||||
this(decoration, null);
|
||||
}
|
||||
|
||||
TeamFormat(TextColor color) {
|
||||
this(null, color);
|
||||
}
|
||||
|
||||
TeamFormat(TextDecoration decoration, TextColor color) {
|
||||
this.decoration = decoration;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this team color is a color.
|
||||
*
|
||||
* @return if it is a color
|
||||
*/
|
||||
public boolean isColor() {
|
||||
return this.color != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text color equivalent to this team color, if any.
|
||||
*
|
||||
* @return the text color
|
||||
*/
|
||||
public @Nullable TextColor getTextColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color equivalent to this team color, if any.
|
||||
*
|
||||
* @return the color
|
||||
*/
|
||||
public @Nullable Color getColor() {
|
||||
return this.color == null ? null : new Color(this.color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this team color is a text decoration.
|
||||
*
|
||||
* @return if it is a decoration
|
||||
*/
|
||||
public boolean isDecoration() {
|
||||
return this.decoration != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text decoration equivalent to this team color, if any.
|
||||
*
|
||||
* @return the decoration
|
||||
*/
|
||||
public @Nullable TextDecoration getDecoration() {
|
||||
return this.decoration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException if this team format is not a color
|
||||
*/
|
||||
@Override
|
||||
public int red() {
|
||||
if (!this.isColor()) {
|
||||
throw new IllegalStateException("This TeamFormat does not represent a color");
|
||||
}
|
||||
|
||||
return this.color.red();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException if this team format is not a color
|
||||
*/
|
||||
@Override
|
||||
public int green() {
|
||||
if (!this.isColor()) {
|
||||
throw new IllegalStateException("This TeamFormat does not represent a color");
|
||||
}
|
||||
|
||||
return this.color.green();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException if this team format is not a color
|
||||
*/
|
||||
@Override
|
||||
public int blue() {
|
||||
if (!this.isColor()) {
|
||||
throw new IllegalStateException("This TeamFormat does not represent a color");
|
||||
}
|
||||
|
||||
return this.color.blue();
|
||||
}
|
||||
}
|
@ -108,7 +108,7 @@ public class ArgumentType {
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link ArgumentTextColor} for colors, {@link ArgumentTextDecoration} for styles, {@link ArgumentColor} for raw colors,
|
||||
* {@link ArgumentDyeColor} for dye colors and {@link ArgumentTeamFormat} for team formats
|
||||
* {@link ArgumentDyeColor} for dye colors and {@link ArgumentTeamColor} for team formats
|
||||
*/
|
||||
@Deprecated
|
||||
public static ArgumentChatColor ChatColor(@NotNull String id) {
|
||||
@ -131,8 +131,8 @@ public class ArgumentType {
|
||||
return new ArgumentDyeColor(id);
|
||||
}
|
||||
|
||||
public static ArgumentTeamFormat TeamFormat(@NotNull String id) {
|
||||
return new ArgumentTeamFormat(id);
|
||||
public static ArgumentTeamColor TeamColor(@NotNull String id) {
|
||||
return new ArgumentTeamColor(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* <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 ArgumentTeamFormat} for team formats
|
||||
* {@link ArgumentDyeColor} for dye colors and {@link ArgumentTeamColor} for team formats
|
||||
*/
|
||||
@Deprecated
|
||||
public class ArgumentChatColor extends Argument<ChatColor> {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.color.TeamFormat;
|
||||
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;
|
||||
@ -8,22 +8,22 @@ import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An argument that will give you a {@link TeamFormat} from it's name or the int code.
|
||||
* An argument that will give you a {@link TeamColor} from it's name or the int code.
|
||||
*/
|
||||
public class ArgumentTeamFormat extends Argument<TeamFormat> {
|
||||
public class ArgumentTeamColor extends Argument<TeamColor> {
|
||||
public static final int UNDEFINED_TEAM_FORMAT = -2;
|
||||
|
||||
public ArgumentTeamFormat(@NotNull String id) {
|
||||
public ArgumentTeamColor(@NotNull String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TeamFormat parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||
public @NotNull TeamColor parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||
try {
|
||||
return TeamFormat.valueOf(input.toUpperCase().trim().replace(' ', '_'));
|
||||
return TeamColor.valueOf(input.toUpperCase().trim().replace(' ', '_'));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
try {
|
||||
return TeamFormat.values()[Integer.parseInt(input)];
|
||||
return TeamColor.values()[Integer.parseInt(input)];
|
||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException alsoIgnored) {
|
||||
throw new ArgumentSyntaxException("Undefined team format!", input, UNDEFINED_TEAM_FORMAT);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.color.TeamFormat;
|
||||
import net.minestom.server.color.TeamColor;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
@ -40,7 +40,7 @@ public class TeamsPacket implements ServerPacket {
|
||||
/**
|
||||
* The color of the team
|
||||
*/
|
||||
public TeamFormat teamFormat;
|
||||
public TeamColor teamColor;
|
||||
/**
|
||||
* The prefix of the team
|
||||
*/
|
||||
@ -56,9 +56,9 @@ public class TeamsPacket implements ServerPacket {
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #teamFormat}
|
||||
* @deprecated Use {@link #teamColor}
|
||||
*/
|
||||
@Deprecated public int teamColor = -1;
|
||||
@Deprecated public int teamColorOld = -1;
|
||||
/**
|
||||
* @deprecated Use {@link #teamDisplayName}
|
||||
*/
|
||||
@ -89,7 +89,7 @@ public class TeamsPacket implements ServerPacket {
|
||||
writer.writeByte(this.friendlyFlags);
|
||||
writer.writeSizedString(this.nameTagVisibility.getIdentifier());
|
||||
writer.writeSizedString(this.collisionRule.getIdentifier());
|
||||
writer.writeVarInt(this.teamColor != -1 ? this.teamColor : this.teamFormat.ordinal());
|
||||
writer.writeVarInt(this.teamColorOld != -1 ? this.teamColorOld : this.teamColor.getId());
|
||||
writer.writeSizedString(this.teamPrefixJson != null ? this.teamPrefixJson.toString() : this.teamPrefix);
|
||||
writer.writeSizedString(this.teamSuffixJson != null ? this.teamSuffixJson.toString() : this.teamSuffix);
|
||||
break;
|
||||
|
@ -4,7 +4,7 @@ import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.color.TeamFormat;
|
||||
import net.minestom.server.color.TeamColor;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.play.DisplayScoreboardPacket;
|
||||
import net.minestom.server.network.packet.server.play.ScoreboardObjectivePacket;
|
||||
@ -440,7 +440,7 @@ public class Sidebar implements Scoreboard {
|
||||
private final byte friendlyFlags = 0x00;
|
||||
private final TeamsPacket.NameTagVisibility nameTagVisibility = TeamsPacket.NameTagVisibility.NEVER;
|
||||
private final TeamsPacket.CollisionRule collisionRule = TeamsPacket.CollisionRule.NEVER;
|
||||
private final TeamFormat teamformat = TeamFormat.DARK_GREEN;
|
||||
private final TeamColor teamColor = TeamColor.DARK_GREEN;
|
||||
|
||||
|
||||
/**
|
||||
@ -471,7 +471,7 @@ public class Sidebar implements Scoreboard {
|
||||
teamsPacket.friendlyFlags = friendlyFlags;
|
||||
teamsPacket.nameTagVisibility = nameTagVisibility;
|
||||
teamsPacket.collisionRule = collisionRule;
|
||||
teamsPacket.teamFormat = teamformat;
|
||||
teamsPacket.teamColor = teamColor;
|
||||
teamsPacket.teamPrefix = MinecraftServer.getSerializationManager().serialize(prefix);
|
||||
teamsPacket.teamSuffix = MinecraftServer.getSerializationManager().serialize(suffix);
|
||||
teamsPacket.entities = new String[]{entityName};
|
||||
@ -504,7 +504,7 @@ public class Sidebar implements Scoreboard {
|
||||
teamsPacket.friendlyFlags = friendlyFlags;
|
||||
teamsPacket.nameTagVisibility = nameTagVisibility;
|
||||
teamsPacket.collisionRule = collisionRule;
|
||||
teamsPacket.teamFormat = teamformat;
|
||||
teamsPacket.teamColor = teamColor;
|
||||
teamsPacket.teamPrefix = MinecraftServer.getSerializationManager().serialize(prefix);
|
||||
teamsPacket.teamSuffix = MinecraftServer.getSerializationManager().serialize(suffix);
|
||||
return teamsPacket;
|
||||
|
@ -6,17 +6,16 @@ import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.color.TeamFormat;
|
||||
import net.minestom.server.color.TeamColor;
|
||||
import net.minestom.server.entity.LivingEntity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.instance.ChunkPopulator;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket.CollisionRule;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket.NameTagVisibility;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -57,10 +56,10 @@ public class Team implements ForwardingAudience {
|
||||
private CollisionRule collisionRule;
|
||||
|
||||
/**
|
||||
* Used to format the name of players on the team <br>
|
||||
* The format of a team defines how the names of the team members are visualized.
|
||||
* Used to color the name of players on the team <br>
|
||||
* The color of a team defines how the names of the team members are visualized.
|
||||
*/
|
||||
private TeamFormat teamFormat;
|
||||
private TeamColor teamColor;
|
||||
|
||||
/**
|
||||
* Shown before the names of the players who belong to this team.
|
||||
@ -87,7 +86,7 @@ public class Team implements ForwardingAudience {
|
||||
this.nameTagVisibility = NameTagVisibility.ALWAYS;
|
||||
this.collisionRule = CollisionRule.ALWAYS;
|
||||
|
||||
this.teamFormat = TeamFormat.WHITE;
|
||||
this.teamColor = TeamColor.WHITE;
|
||||
this.prefix = Component.empty();
|
||||
this.suffix = Component.empty();
|
||||
|
||||
@ -236,11 +235,13 @@ public class Team implements ForwardingAudience {
|
||||
*
|
||||
* @param color The new team color
|
||||
* @see #updateTeamColor(ChatColor)
|
||||
* @deprecated Use {@link #setTeamFormat(TeamFormat)}
|
||||
* @deprecated Use {@link #setTeamColor(TeamColor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setTeamColor(@NotNull ChatColor color) {
|
||||
this.setTeamFormat(color.asTeamFormat());
|
||||
TeamColor teamColor = color.asTeamColor();
|
||||
Validate.notNull(teamColor, "Cannot set team color to non-color.");
|
||||
this.setTeamColor(teamColor);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,31 +249,33 @@ public class Team implements ForwardingAudience {
|
||||
* <br><br>
|
||||
* <b>Warning:</b> This is only changed on the <b>server side</b>.
|
||||
*
|
||||
* @param format The new team color
|
||||
* @see #updateTeamFormat(TeamFormat)
|
||||
* @param color The new team color
|
||||
* @see #setTeamColor(TeamColor)
|
||||
*/
|
||||
public void setTeamFormat(@NotNull TeamFormat format) {
|
||||
this.teamFormat = format;
|
||||
public void setTeamColor(@NotNull TeamColor color) {
|
||||
this.teamColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the color of the team and sends an update packet.
|
||||
*
|
||||
* @param teamColor The new team color
|
||||
* @deprecated Use {@link #updateTeamFormat(TeamFormat)}
|
||||
* @param chatColor The new team color
|
||||
* @deprecated Use {@link #updateTeamColor(TeamColor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void updateTeamColor(@NotNull ChatColor teamColor) {
|
||||
this.updateTeamFormat(teamColor.asTeamFormat());
|
||||
public void updateTeamColor(@NotNull ChatColor chatColor) {
|
||||
TeamColor teamColor = chatColor.asTeamColor();
|
||||
Validate.notNull(teamColor, "Cannot set team color to non-color.");
|
||||
this.updateTeamColor(teamColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the color of the team and sends an update packet.
|
||||
*
|
||||
* @param format The new team color
|
||||
* @param color The new team color
|
||||
*/
|
||||
public void updateTeamFormat(@NotNull TeamFormat format) {
|
||||
this.setTeamFormat(format);
|
||||
public void updateTeamColor(@NotNull TeamColor color) {
|
||||
this.setTeamColor(color);
|
||||
sendUpdatePacket();
|
||||
}
|
||||
|
||||
@ -410,7 +413,7 @@ public class Team implements ForwardingAudience {
|
||||
teamsCreationPacket.friendlyFlags = this.friendlyFlags;
|
||||
teamsCreationPacket.nameTagVisibility = this.nameTagVisibility;
|
||||
teamsCreationPacket.collisionRule = this.collisionRule;
|
||||
teamsCreationPacket.teamFormat = this.teamFormat;
|
||||
teamsCreationPacket.teamColor = this.teamColor;
|
||||
teamsCreationPacket.teamPrefix = MinecraftServer.getSerializationManager().serialize(this.prefix);
|
||||
teamsCreationPacket.teamSuffix = MinecraftServer.getSerializationManager().serialize(this.suffix);
|
||||
teamsCreationPacket.entities = this.members.toArray(new String[0]);
|
||||
@ -494,12 +497,12 @@ public class Team implements ForwardingAudience {
|
||||
* Gets the color of the team.
|
||||
*
|
||||
* @return the team color
|
||||
* @deprecated Use {@link #getTeamFormat()}
|
||||
* @deprecated Use {@link #getTeamColor()}
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public ChatColor getTeamColor() {
|
||||
return ChatColor.fromName(teamFormat.name());
|
||||
public ChatColor getTeamColorOld() {
|
||||
return ChatColor.fromName(teamColor.name());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -508,8 +511,8 @@ public class Team implements ForwardingAudience {
|
||||
* @return the team color
|
||||
*/
|
||||
@NotNull
|
||||
public TeamFormat getTeamFormat() {
|
||||
return teamFormat;
|
||||
public TeamColor getTeamColor() {
|
||||
return teamColor;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -563,7 +566,7 @@ public class Team implements ForwardingAudience {
|
||||
updatePacket.friendlyFlags = this.friendlyFlags;
|
||||
updatePacket.nameTagVisibility = this.nameTagVisibility;
|
||||
updatePacket.collisionRule = this.collisionRule;
|
||||
updatePacket.teamFormat = this.teamFormat;
|
||||
updatePacket.teamColor = this.teamColor;
|
||||
updatePacket.teamPrefix = MinecraftServer.getSerializationManager().serialize(this.prefix);
|
||||
updatePacket.teamSuffix = MinecraftServer.getSerializationManager().serialize(this.suffix);
|
||||
|
||||
|
@ -3,7 +3,7 @@ package net.minestom.server.scoreboard;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.color.TeamFormat;
|
||||
import net.minestom.server.color.TeamColor;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket.CollisionRule;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket.NameTagVisibility;
|
||||
|
||||
@ -87,11 +87,11 @@ public class TeamBuilder {
|
||||
*
|
||||
* @param color The new color
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #updateTeamFormat(TeamFormat)}
|
||||
* @deprecated Use {@link #updateTeamColor(TeamColor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder updateTeamColor(ChatColor color) {
|
||||
return this.updateTeamFormat(color.asTeamFormat());
|
||||
return this.updateTeamColor(color.asTeamColor());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,8 +100,8 @@ public class TeamBuilder {
|
||||
* @param color The new color
|
||||
* @return this builder, for chaining
|
||||
*/
|
||||
public TeamBuilder updateTeamFormat(TeamFormat color) {
|
||||
this.team.updateTeamFormat(color);
|
||||
public TeamBuilder updateTeamColor(TeamColor color) {
|
||||
this.team.updateTeamColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -315,23 +315,23 @@ public class TeamBuilder {
|
||||
*
|
||||
* @param color The new team color
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #teamFormat(TeamFormat)}
|
||||
* @deprecated Use {@link #teamColor(TeamColor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder teamColor(ChatColor color) {
|
||||
return this.teamFormat(color.asTeamFormat());
|
||||
return this.teamColor(color.asTeamColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the format of the {@link Team} without an update packet.
|
||||
* Changes the color of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
* <b>Warning: </b> If you do not call {@link #updateTeamPacket()}, this is only changed of the <b>server side</b>.
|
||||
*
|
||||
* @param format The new team format
|
||||
* @param color The new team color
|
||||
* @return this builder, for chaining
|
||||
*/
|
||||
public TeamBuilder teamFormat(TeamFormat format) {
|
||||
this.team.setTeamFormat(format);
|
||||
public TeamBuilder teamColor(TeamColor color) {
|
||||
this.team.setTeamColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.color.TeamFormat;
|
||||
import net.minestom.server.color.TeamColor;
|
||||
import net.minestom.server.entity.LivingEntity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
@ -99,11 +99,11 @@ public final class TeamManager {
|
||||
* @param teamColor The team color
|
||||
* @param suffix The team suffix
|
||||
* @return the created {@link Team} with a prefix, teamColor and suffix
|
||||
* @deprecated Use {@link #createTeam(String, Component, TeamFormat, Component)}
|
||||
* @deprecated Use {@link #createTeam(String, Component, TeamColor, Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Team createTeam(String name, JsonMessage prefix, ChatColor teamColor, JsonMessage suffix) {
|
||||
return this.createTeam(name, prefix.asComponent(), teamColor.asTeamFormat(), suffix.asComponent());
|
||||
return this.createTeam(name, prefix.asComponent(), teamColor.asTeamColor(), suffix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,12 +111,12 @@ public final class TeamManager {
|
||||
*
|
||||
* @param name The registry name
|
||||
* @param prefix The team prefix
|
||||
* @param teamFormat The team format
|
||||
* @param teamColor The team format
|
||||
* @param suffix The team suffix
|
||||
* @return the created {@link Team} with a prefix, teamColor and suffix
|
||||
*/
|
||||
public Team createTeam(String name, Component prefix, TeamFormat teamFormat, Component suffix) {
|
||||
return this.createBuilder(name).prefix(prefix).teamFormat(teamFormat).suffix(suffix).updateTeamPacket().build();
|
||||
public Team createTeam(String name, Component prefix, TeamColor teamColor, Component suffix) {
|
||||
return this.createBuilder(name).prefix(prefix).teamColor(teamColor).suffix(suffix).updateTeamPacket().build();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,11 +128,11 @@ public final class TeamManager {
|
||||
* @param teamColor The team color
|
||||
* @param suffix The team suffix
|
||||
* @return the created {@link Team} with a prefix, teamColor, suffix and the display name
|
||||
* @deprecated Use {@link #createTeam(String, Component, Component, TeamFormat, Component)}
|
||||
* @deprecated Use {@link #createTeam(String, Component, Component, TeamColor, Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Team createTeam(String name, JsonMessage displayName, JsonMessage prefix, ChatColor teamColor, JsonMessage suffix) {
|
||||
return this.createTeam(name, displayName.asComponent(), prefix.asComponent(), teamColor.asTeamFormat(), suffix.asComponent());
|
||||
return this.createTeam(name, displayName.asComponent(), prefix.asComponent(), teamColor.asTeamColor(), suffix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,12 +141,12 @@ public final class TeamManager {
|
||||
* @param name The registry name
|
||||
* @param displayName The display name
|
||||
* @param prefix The team prefix
|
||||
* @param teamFormat The team color
|
||||
* @param teamColor The team color
|
||||
* @param suffix The team suffix
|
||||
* @return the created {@link Team} with a prefix, teamColor, suffix and the display name
|
||||
*/
|
||||
public Team createTeam(String name, Component displayName, Component prefix, TeamFormat teamFormat, Component suffix) {
|
||||
return this.createBuilder(name).teamDisplayName(displayName).prefix(prefix).teamFormat(teamFormat).suffix(suffix).updateTeamPacket().build();
|
||||
public Team createTeam(String name, Component displayName, Component prefix, TeamColor teamColor, Component suffix) {
|
||||
return this.createBuilder(name).teamDisplayName(displayName).prefix(prefix).teamColor(teamColor).suffix(suffix).updateTeamPacket().build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user