Skip to content

Commit df29afc

Browse files
committed
Add color to the display names of hunters
1 parent 4661903 commit df29afc

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

src/main/java/io/github/haykam821/totemhunt/game/phase/TotemHuntActivePhase.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import xyz.nucleoid.plasmid.game.GameCloseReason;
2929
import xyz.nucleoid.plasmid.game.GameSpace;
3030
import xyz.nucleoid.plasmid.game.common.GlobalWidgets;
31+
import xyz.nucleoid.plasmid.game.common.team.TeamManager;
3132
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
3233
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
3334
import xyz.nucleoid.plasmid.game.player.PlayerOffer;
@@ -45,15 +46,17 @@ public class TotemHuntActivePhase {
4546
private final TotemHuntConfig config;
4647
private final List<PlayerEntry> players = new ArrayList<>();
4748
private final TotemHuntBar timer;
49+
private final TeamManager teamManager;
4850
private int ticksElapsed = 0;
4951
private int ticksUntilClose = -1;
5052

51-
public TotemHuntActivePhase(GameSpace gameSpace, ServerWorld world, TotemHuntMap map, TotemHuntConfig config, GlobalWidgets widgets) {
53+
public TotemHuntActivePhase(GameSpace gameSpace, ServerWorld world, TotemHuntMap map, TotemHuntConfig config, GlobalWidgets widgets, TeamManager teamManager) {
5254
this.gameSpace = gameSpace;
5355
this.world = world;
5456
this.map = map;
5557
this.config = config;
5658
this.timer = new TotemHuntBar(this, widgets);
59+
this.teamManager = teamManager;
5760
}
5861

5962
public static void setRules(GameActivity activity) {
@@ -68,7 +71,13 @@ public static void setRules(GameActivity activity) {
6871
public static void open(GameSpace gameSpace, ServerWorld world, TotemHuntMap map, TotemHuntConfig config) {
6972
gameSpace.setActivity(activity -> {
7073
GlobalWidgets widgets = GlobalWidgets.addTo(activity);
71-
TotemHuntActivePhase phase = new TotemHuntActivePhase(gameSpace, world, map, config, widgets);
74+
TeamManager teamManager = TeamManager.addTo(activity);
75+
76+
for (Role role : Role.REGISTRY.values()) {
77+
role.registerTeam(teamManager);
78+
}
79+
80+
TotemHuntActivePhase phase = new TotemHuntActivePhase(gameSpace, world, map, config, widgets, teamManager);
7281

7382
TotemHuntActivePhase.setRules(activity);
7483

@@ -254,6 +263,10 @@ public TotemHuntConfig getConfig() {
254263
return this.config;
255264
}
256265

266+
public TeamManager getTeamManager() {
267+
return this.teamManager;
268+
}
269+
257270
public int getTicksElapsed() {
258271
return this.ticksElapsed;
259272
}

src/main/java/io/github/haykam821/totemhunt/game/role/HunterRole.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.minecraft.item.ItemStack;
1111
import net.minecraft.item.Items;
1212
import net.minecraft.text.Text;
13+
import net.minecraft.util.DyeColor;
1314
import net.minecraft.util.Formatting;
1415
import xyz.nucleoid.plasmid.util.ItemStackBuilder;
1516

@@ -27,6 +28,16 @@ public Text getName() {
2728
return NAME;
2829
}
2930

31+
@Override
32+
public boolean hasTeam() {
33+
return true;
34+
}
35+
36+
@Override
37+
public DyeColor getColor() {
38+
return DyeColor.RED;
39+
}
40+
3041
@Override
3142
public void onGiveTotem(TotemHuntActivePhase phase, PlayerEntry from, PlayerEntry to) {
3243
if (phase.isInvulnerabilityPeriod()) {

src/main/java/io/github/haykam821/totemhunt/game/role/Role.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,51 @@
88
import net.minecraft.item.ItemStack;
99
import net.minecraft.server.network.ServerPlayerEntity;
1010
import net.minecraft.text.Text;
11+
import net.minecraft.util.DyeColor;
12+
import net.minecraft.util.Identifier;
13+
import xyz.nucleoid.plasmid.game.common.team.GameTeamConfig;
14+
import xyz.nucleoid.plasmid.game.common.team.GameTeamKey;
15+
import xyz.nucleoid.plasmid.game.common.team.TeamManager;
1116
import xyz.nucleoid.plasmid.registry.TinyRegistry;
1217

1318
public abstract class Role {
1419
public static final TinyRegistry<Role> REGISTRY = TinyRegistry.create();
1520

21+
private GameTeamKey teamKey;
22+
private GameTeamConfig teamConfig;
23+
1624
public abstract Text getName();
1725

26+
public boolean hasTeam() {
27+
return false;
28+
}
29+
30+
public DyeColor getColor() {
31+
return null;
32+
}
33+
34+
private GameTeamKey getTeamKey() {
35+
if (this.teamKey == null) {
36+
Identifier id = REGISTRY.getIdentifier(this);
37+
this.teamKey = new GameTeamKey(id.toUnderscoreSeparatedString());
38+
}
39+
40+
return this.teamKey;
41+
}
42+
43+
public void registerTeam(TeamManager teamManager) {
44+
if (this.hasTeam()) {
45+
if (this.teamConfig == null) {
46+
this.teamConfig = GameTeamConfig.builder()
47+
.setName(this.getName())
48+
.setColors(GameTeamConfig.Colors.from(this.getColor()))
49+
.build();
50+
}
51+
52+
teamManager.addTeam(this.getTeamKey(), this.teamConfig);
53+
}
54+
}
55+
1856
public void onGiveTotem(TotemHuntActivePhase phase, PlayerEntry from, PlayerEntry to) {
1957
from.changeRole(Roles.PLAYER.getRole(), true);
2058
to.changeRole(Roles.HOLDER.getRole(), true);
@@ -26,6 +64,11 @@ public boolean canTransferTo(Role role) {
2664

2765
public void unapply(PlayerEntry entry) {
2866
entry.getPlayer().getInventory().clear();
67+
68+
// Update team
69+
if (this.hasTeam()) {
70+
entry.getPhase().getTeamManager().removePlayerFrom(entry.getPlayer(), this.getTeamKey());
71+
}
2972
}
3073

3174
public void apply(PlayerEntry entry) {
@@ -48,6 +91,11 @@ public void apply(PlayerEntry entry) {
4891
// Update inventory
4992
player.currentScreenHandler.sendContentUpdates();
5093
player.playerScreenHandler.onContentChanged(player.getInventory());
94+
95+
// Update team
96+
if (this.hasTeam()) {
97+
entry.getPhase().getTeamManager().addPlayerTo(entry.getPlayer(), this.getTeamKey());
98+
}
5199
}
52100

53101
public List<ItemStack> getHotbar() {

0 commit comments

Comments
 (0)