Skip to content

Commit

Permalink
Add color to the display names of hunters
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Jun 21, 2024
1 parent 4661903 commit df29afc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import xyz.nucleoid.plasmid.game.GameCloseReason;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.game.common.team.TeamManager;
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.player.PlayerOffer;
Expand All @@ -45,15 +46,17 @@ public class TotemHuntActivePhase {
private final TotemHuntConfig config;
private final List<PlayerEntry> players = new ArrayList<>();
private final TotemHuntBar timer;
private final TeamManager teamManager;
private int ticksElapsed = 0;
private int ticksUntilClose = -1;

public TotemHuntActivePhase(GameSpace gameSpace, ServerWorld world, TotemHuntMap map, TotemHuntConfig config, GlobalWidgets widgets) {
public TotemHuntActivePhase(GameSpace gameSpace, ServerWorld world, TotemHuntMap map, TotemHuntConfig config, GlobalWidgets widgets, TeamManager teamManager) {
this.gameSpace = gameSpace;
this.world = world;
this.map = map;
this.config = config;
this.timer = new TotemHuntBar(this, widgets);
this.teamManager = teamManager;
}

public static void setRules(GameActivity activity) {
Expand All @@ -68,7 +71,13 @@ public static void setRules(GameActivity activity) {
public static void open(GameSpace gameSpace, ServerWorld world, TotemHuntMap map, TotemHuntConfig config) {
gameSpace.setActivity(activity -> {
GlobalWidgets widgets = GlobalWidgets.addTo(activity);
TotemHuntActivePhase phase = new TotemHuntActivePhase(gameSpace, world, map, config, widgets);
TeamManager teamManager = TeamManager.addTo(activity);

for (Role role : Role.REGISTRY.values()) {
role.registerTeam(teamManager);
}

TotemHuntActivePhase phase = new TotemHuntActivePhase(gameSpace, world, map, config, widgets, teamManager);

TotemHuntActivePhase.setRules(activity);

Expand Down Expand Up @@ -254,6 +263,10 @@ public TotemHuntConfig getConfig() {
return this.config;
}

public TeamManager getTeamManager() {
return this.teamManager;
}

public int getTicksElapsed() {
return this.ticksElapsed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Formatting;
import xyz.nucleoid.plasmid.util.ItemStackBuilder;

Expand All @@ -27,6 +28,16 @@ public Text getName() {
return NAME;
}

@Override
public boolean hasTeam() {
return true;
}

@Override
public DyeColor getColor() {
return DyeColor.RED;
}

@Override
public void onGiveTotem(TotemHuntActivePhase phase, PlayerEntry from, PlayerEntry to) {
if (phase.isInvulnerabilityPeriod()) {
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/io/github/haykam821/totemhunt/game/role/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,51 @@
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;
import xyz.nucleoid.plasmid.game.common.team.GameTeamConfig;
import xyz.nucleoid.plasmid.game.common.team.GameTeamKey;
import xyz.nucleoid.plasmid.game.common.team.TeamManager;
import xyz.nucleoid.plasmid.registry.TinyRegistry;

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

private GameTeamKey teamKey;
private GameTeamConfig teamConfig;

public abstract Text getName();

public boolean hasTeam() {
return false;
}

public DyeColor getColor() {
return null;
}

private GameTeamKey getTeamKey() {
if (this.teamKey == null) {
Identifier id = REGISTRY.getIdentifier(this);
this.teamKey = new GameTeamKey(id.toUnderscoreSeparatedString());
}

return this.teamKey;
}

public void registerTeam(TeamManager teamManager) {
if (this.hasTeam()) {
if (this.teamConfig == null) {
this.teamConfig = GameTeamConfig.builder()
.setName(this.getName())
.setColors(GameTeamConfig.Colors.from(this.getColor()))
.build();
}

teamManager.addTeam(this.getTeamKey(), this.teamConfig);
}
}

public void onGiveTotem(TotemHuntActivePhase phase, PlayerEntry from, PlayerEntry to) {
from.changeRole(Roles.PLAYER.getRole(), true);
to.changeRole(Roles.HOLDER.getRole(), true);
Expand All @@ -26,6 +64,11 @@ public boolean canTransferTo(Role role) {

public void unapply(PlayerEntry entry) {
entry.getPlayer().getInventory().clear();

// Update team
if (this.hasTeam()) {
entry.getPhase().getTeamManager().removePlayerFrom(entry.getPlayer(), this.getTeamKey());
}
}

public void apply(PlayerEntry entry) {
Expand All @@ -48,6 +91,11 @@ public void apply(PlayerEntry entry) {
// Update inventory
player.currentScreenHandler.sendContentUpdates();
player.playerScreenHandler.onContentChanged(player.getInventory());

// Update team
if (this.hasTeam()) {
entry.getPhase().getTeamManager().addPlayerTo(entry.getPlayer(), this.getTeamKey());
}
}

public List<ItemStack> getHotbar() {
Expand Down

0 comments on commit df29afc

Please sign in to comment.