Skip to content

Commit

Permalink
Implement dye color option for teams (#1066)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablete1234 <[email protected]>
  • Loading branch information
Pablete1234 authored Oct 7, 2022
1 parent ff638fe commit 99127f9
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 29 deletions.
8 changes: 8 additions & 0 deletions core/src/main/java/tc/oc/pgm/api/party/Party.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.kyori.adventure.text.Component;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import tc.oc.pgm.api.filter.query.PartyQuery;
import tc.oc.pgm.api.filter.query.PlayerQuery;
import tc.oc.pgm.api.match.Match;
Expand Down Expand Up @@ -100,6 +101,13 @@ public interface Party extends Audience, Named, Filterable<PartyQuery>, PartyQue
*/
Color getFullColor();

/**
* Gets the {@link DyeColor} of the party.
*
* @return a dye color
*/
DyeColor getDyeColor();

/**
* Gets a chat prefix for the party.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import tc.oc.pgm.regions.FiniteBlockRegion;
import tc.oc.pgm.regions.SectorRegion;
import tc.oc.pgm.renewable.BlockImage;
import tc.oc.pgm.util.bukkit.BukkitUtils;

/** Displays the status of a ControlPoint by coloring blocks in specified regions */
public class ControlPointBlockDisplay implements Listener {
Expand Down Expand Up @@ -87,7 +86,7 @@ public void setController(Competitor controllingTeam) {
this.controllerDisplayImage.restore(block);
}
} else {
byte blockData = BukkitUtils.chatColorToDyeColor(controllingTeam.getColor()).getWoolData();
byte blockData = controllingTeam.getDyeColor().getWoolData();
for (Block block : this.controllerDisplayRegion.getBlocks()) {
block.setData(blockData);
}
Expand All @@ -104,7 +103,7 @@ private void setBlock(Block block, Competitor team) {
.query(new BlockQuery(block))
.isAllowed()) {
if (team != null) {
block.setData(BukkitUtils.chatColorToDyeColor(team.getColor()).getWoolData());
block.setData(team.getDyeColor().getWoolData());
} else {
this.progressDisplayImage.restore(block);
}
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/tc/oc/pgm/ffa/Tribute.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tc.oc.pgm.ffa;

import static com.google.common.base.Preconditions.checkNotNull;
import static net.kyori.adventure.text.Component.empty;
import static net.kyori.adventure.text.Component.*;
import static tc.oc.pgm.util.text.PlayerComponent.player;

import java.util.Collection;
Expand All @@ -12,6 +12,7 @@
import net.kyori.adventure.text.Component;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.scoreboard.NameTagVisibility;
import org.jetbrains.annotations.NotNull;
import tc.oc.pgm.api.match.Match;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class Tribute implements Competitor {
private final String username;
private final ChatColor chatColor;
private final Color color;
private final DyeColor dyeColor;
private final PartyQuery query;

protected @Nullable MatchPlayer player;
Expand All @@ -58,6 +60,7 @@ public Tribute(final MatchPlayer player, final @Nullable ChatColor color) {
this.username = player.getBukkit().getName();
this.chatColor = color == null ? ChatColor.YELLOW : color;
this.color = BukkitUtils.colorOf(this.chatColor);
this.dyeColor = BukkitUtils.chatColorToDyeColor(this.chatColor);
this.query = new PartyQuery(null, this);
}

Expand Down Expand Up @@ -91,6 +94,11 @@ public Color getFullColor() {
return this.color;
}

@Override
public DyeColor getDyeColor() {
return dyeColor;
}

@Override
public Component getName(final NameStyle style) {
return player(player != null ? player.getBukkit() : null, style);
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/tc/oc/pgm/goals/OwnedGoal.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.teams.Team;
import tc.oc.pgm.teams.TeamMatchModule;
import tc.oc.pgm.util.bukkit.BukkitUtils;

/** A goal with an owning team. Match-time companion to {@link OwnedGoal} */
public abstract class OwnedGoal<T extends OwnedGoalDefinition> extends SimpleGoal<T> {
Expand All @@ -26,6 +25,6 @@ public OwnedGoal(T definition, Match match) {

@Override
public DyeColor getDyeColor() {
return owner != null ? BukkitUtils.chatColorToDyeColor(owner.getColor()) : DyeColor.WHITE;
return owner != null ? owner.getDyeColor() : DyeColor.WHITE;
}
}
9 changes: 4 additions & 5 deletions core/src/main/java/tc/oc/pgm/kits/tag/ItemModifier.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package tc.oc.pgm.kits.tag;

import com.google.common.collect.ImmutableSet;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import tc.oc.pgm.api.player.MatchPlayer;
import tc.oc.pgm.util.bukkit.BukkitUtils;
import tc.oc.pgm.util.inventory.tag.ItemTag;

public class ItemModifier {
Expand Down Expand Up @@ -36,12 +35,12 @@ public static void apply(ItemStack item, MatchPlayer player) {
leather.setColor(player.getParty().getFullColor());
item.setItemMeta(meta);
} else if (COLOR_AFFECTED.contains(item.getType())) {
item.setDurability(getWoolColor(player.getParty().getColor()));
item.setDurability(getWoolColor(player.getParty().getDyeColor()));
}
}

@SuppressWarnings("deprecation")
private static byte getWoolColor(ChatColor color) {
return BukkitUtils.chatColorToDyeColor(color).getWoolData();
private static byte getWoolColor(DyeColor color) {
return color.getWoolData();
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/match/ObserverParty.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class ObserverParty extends PartyImpl {

public ObserverParty(final Match match) {
super(match, "Observers", ChatColor.AQUA);
super(match, "Observers", ChatColor.AQUA, null);
}

@Override
Expand Down
14 changes: 13 additions & 1 deletion core/src/main/java/tc/oc/pgm/match/PartyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.party.Party;
import tc.oc.pgm.api.party.event.PartyRenameEvent;
Expand All @@ -33,12 +34,17 @@ public class PartyImpl implements Party, Audience {
private final String id;
private final ChatColor chatColor;
private final Color color;
private final DyeColor dyeColor;
private String legacyName;
private Component name;
private Component prefix;
private boolean plural;

public PartyImpl(final Match match, final String name, final ChatColor chatColor) {
public PartyImpl(
final Match match,
final String name,
final ChatColor chatColor,
final @Nullable DyeColor dyeColor) {
this.match = requireNonNull(match);
this.query = new PartyQuery(null, this);
this.memberMap = new HashMap<>();
Expand All @@ -47,6 +53,7 @@ public PartyImpl(final Match match, final String name, final ChatColor chatColor
this.id = requireNonNull(name);
this.chatColor = chatColor == null ? ChatColor.WHITE : chatColor;
this.color = BukkitUtils.colorOf(this.chatColor);
this.dyeColor = dyeColor == null ? BukkitUtils.chatColorToDyeColor(this.chatColor) : dyeColor;
this.setName(name);
}

Expand Down Expand Up @@ -145,6 +152,11 @@ public Color getFullColor() {
return this.color;
}

@Override
public DyeColor getDyeColor() {
return this.dyeColor;
}

@Override
public Component getChatPrefix() {
return this.prefix;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/match/QueuedParty.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public int compare(final MatchPlayer a, final MatchPlayer b) {
private List<MatchPlayer> memberOrder;

public QueuedParty(final Match match) {
super(match, "Participants", ChatColor.YELLOW);
super(match, "Participants", ChatColor.YELLOW, null);
}

@Override
Expand Down
5 changes: 1 addition & 4 deletions core/src/main/java/tc/oc/pgm/payload/Payload.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tc.oc.pgm.payload;

import java.time.Duration;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.Effect;
Expand All @@ -17,7 +16,6 @@
import tc.oc.pgm.api.region.Region;
import tc.oc.pgm.controlpoint.ControlPoint;
import tc.oc.pgm.payload.track.Track;
import tc.oc.pgm.util.bukkit.BukkitUtils;

public class Payload extends ControlPoint {

Expand Down Expand Up @@ -144,8 +142,7 @@ private void tickMinecart() {

private void updateWool() {
Competitor display = getDisplayTeam();
DyeColor color =
BukkitUtils.chatColorToDyeColor(display != null ? display.getColor() : ChatColor.WHITE);
DyeColor color = display != null ? display.getDyeColor() : DyeColor.WHITE;

Wool data = (Wool) minecart.getDisplayBlock();
data.setColor(color);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/teams/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Team extends PartyImpl implements Competitor, Feature<TeamFactory>
private JoinMatchModule jmm;

public Team(final TeamFactory info, final Match match) {
super(match, requireNonNull(info).getDefaultName(), info.getDefaultColor());
super(match, requireNonNull(info).getDefaultName(), info.getDefaultColor(), info.getDyeColor());
this.info = info;
this.min = info.getMinPlayers();
this.max = info.getMaxPlayers();
Expand Down
17 changes: 9 additions & 8 deletions core/src/main/java/tc/oc/pgm/teams/TeamFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.Nullable;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.scoreboard.NameTagVisibility;
import tc.oc.pgm.api.feature.FeatureInfo;
import tc.oc.pgm.api.match.Match;
Expand All @@ -13,7 +14,7 @@ public class TeamFactory extends SelfIdentifyingFeatureDefinition {
protected final String defaultName;
protected final boolean defaultNamePlural;
protected final ChatColor defaultColor;
@Nullable protected final ChatColor overheadColor;
protected final @Nullable DyeColor dyeColor;
protected final int minPlayers;
protected final int maxPlayers;
protected final int maxOverfill;
Expand All @@ -26,7 +27,7 @@ public class TeamFactory extends SelfIdentifyingFeatureDefinition {
* @param defaultName Default name for the team.
* @param defaultNamePlural Is the default name a plural word?
* @param defaultColor Default color for the team.
* @param overheadColor Color to be displayed above the team members' avatars.
* @param dyeColor Dye color to be used for blocks on kits or control points
* @param maxPlayers Maximum amount of players that may be on this team.
* @param nameTagVisibility Who can see the name tags of players on this team
*/
Expand All @@ -35,7 +36,7 @@ public TeamFactory(
String defaultName,
boolean defaultNamePlural,
ChatColor defaultColor,
@Nullable ChatColor overheadColor,
@Nullable DyeColor dyeColor,
int minPlayers,
int maxPlayers,
int maxOverfill,
Expand All @@ -44,7 +45,7 @@ public TeamFactory(
this.defaultName = defaultName;
this.defaultNamePlural = defaultNamePlural;
this.defaultColor = defaultColor;
this.overheadColor = overheadColor;
this.dyeColor = dyeColor;
this.minPlayers = minPlayers;
this.maxPlayers = maxPlayers;
this.maxOverfill = maxOverfill;
Expand Down Expand Up @@ -94,12 +95,12 @@ public String getDefaultColoredName() {
}

/**
* Gets the color to be displayed alongside the player's name above the player.
* Gets the dye color to use for blocks on kits or control points
*
* @return Overhead color.
* @return Dye color for the team
*/
public ChatColor getOverheadColor() {
return this.overheadColor != null ? this.overheadColor : this.defaultColor;
public @Nullable DyeColor getDyeColor() {
return this.dyeColor;
}

public int getMinPlayers() {
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/tc/oc/pgm/teams/TeamModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.scoreboard.NameTagVisibility;
import org.jdom2.Attribute;
import org.jdom2.Document;
Expand Down Expand Up @@ -120,7 +121,7 @@ private static TeamFactory parseTeamDefinition(Element el, MapFactory factory)
boolean plural = XMLUtils.parseBoolean(el.getAttribute("plural"), false);

ChatColor color = XMLUtils.parseChatColor(Node.fromAttr(el, "color"), ChatColor.WHITE);
ChatColor overheadColor = XMLUtils.parseChatColor(Node.fromAttr(el, "overhead-color"), null);
DyeColor dyeColor = XMLUtils.parseDyeColor(el.getAttribute("dye-color"), null);
NameTagVisibility nameTagVisibility =
XMLUtils.parseNameTagVisibility(
Node.fromAttr(el, "show-name-tags"), NameTagVisibility.ALWAYS);
Expand All @@ -141,7 +142,7 @@ private static TeamFactory parseTeamDefinition(Element el, MapFactory factory)
name,
plural,
color,
overheadColor,
dyeColor,
minPlayers,
maxPlayers,
maxOverfill,
Expand Down

0 comments on commit 99127f9

Please sign in to comment.