diff --git a/src/main/java/io/github/haykam821/totemhunt/game/PlayerEntry.java b/src/main/java/io/github/haykam821/totemhunt/game/PlayerEntry.java index a1432d6..20144e3 100644 --- a/src/main/java/io/github/haykam821/totemhunt/game/PlayerEntry.java +++ b/src/main/java/io/github/haykam821/totemhunt/game/PlayerEntry.java @@ -42,12 +42,15 @@ public void spawn(ServerWorld world, BlockBounds spawn) { this.player.sendMessage(Text.translatable("text.totemhunt.role_spawn", this.role.getName()), true); } - public void changeRole(Role role) { + public void changeRole(Role role, boolean notify) { this.role.unapply(this); role.apply(this); this.role = role; - this.player.sendMessage(Text.translatable("text.totemhunt.role_change", this.role.getName()), true); + + if (notify) { + this.player.sendMessage(Text.translatable("text.totemhunt.role_change", this.role.getName()), true); + } } @Override diff --git a/src/main/java/io/github/haykam821/totemhunt/game/phase/TotemHuntActivePhase.java b/src/main/java/io/github/haykam821/totemhunt/game/phase/TotemHuntActivePhase.java index 314f6cc..363c2bc 100644 --- a/src/main/java/io/github/haykam821/totemhunt/game/phase/TotemHuntActivePhase.java +++ b/src/main/java/io/github/haykam821/totemhunt/game/phase/TotemHuntActivePhase.java @@ -14,6 +14,7 @@ import io.github.haykam821.totemhunt.game.role.Roles; import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; +import net.minecraft.entity.EntityStatuses; import net.minecraft.entity.damage.DamageSource; import net.minecraft.screen.ScreenTexts; import net.minecraft.server.network.ServerPlayerEntity; @@ -152,8 +153,12 @@ private Text getWinMessage(ServerPlayerEntity hunter, ServerPlayerEntity holder) return Text.translatable("text.totemhunt.totem_found", hunterName, holderName, time).formatted(Formatting.RED); } - public void endGame(ServerPlayerEntity hunter, ServerPlayerEntity holder) { - this.gameSpace.getPlayers().sendMessage(this.getWinMessage(hunter, holder)); + public void endGame(PlayerEntry hunter, PlayerEntry holder) { + holder.changeRole(Roles.PLAYER.getRole(), false); + + this.gameSpace.getPlayers().sendMessage(this.getWinMessage(hunter.getPlayer(), holder.getPlayer())); + this.world.sendEntityStatus(holder.getPlayer(), EntityStatuses.USE_TOTEM_OF_UNDYING); + this.ticksUntilClose = this.config.getTicksUntilClose().get(this.world.getRandom()); } @@ -208,10 +213,10 @@ private void reassignRequiredRoles() { for (PlayerEntry entry : this.players) { if (needsHunter) { needsHunter = false; - entry.changeRole(Roles.HUNTER.getRole()); + entry.changeRole(Roles.HUNTER.getRole(), true); } else if (needsHolder) { needsHolder = false; - entry.changeRole(Roles.HUNTER.getRole()); + entry.changeRole(Roles.HUNTER.getRole(), true); } } } diff --git a/src/main/java/io/github/haykam821/totemhunt/game/role/HunterRole.java b/src/main/java/io/github/haykam821/totemhunt/game/role/HunterRole.java index 37ea9ad..cfa98aa 100644 --- a/src/main/java/io/github/haykam821/totemhunt/game/role/HunterRole.java +++ b/src/main/java/io/github/haykam821/totemhunt/game/role/HunterRole.java @@ -36,7 +36,7 @@ public void onGiveTotem(TotemHuntActivePhase phase, PlayerEntry from, PlayerEntr return; } - from.getPhase().endGame(from.getPlayer(), to.getPlayer()); + from.getPhase().endGame(from, to); } @Override diff --git a/src/main/java/io/github/haykam821/totemhunt/game/role/Role.java b/src/main/java/io/github/haykam821/totemhunt/game/role/Role.java index 54bf741..1776b38 100644 --- a/src/main/java/io/github/haykam821/totemhunt/game/role/Role.java +++ b/src/main/java/io/github/haykam821/totemhunt/game/role/Role.java @@ -16,8 +16,8 @@ public abstract class Role { public abstract Text getName(); public void onGiveTotem(TotemHuntActivePhase phase, PlayerEntry from, PlayerEntry to) { - from.changeRole(Roles.PLAYER.getRole()); - to.changeRole(Roles.HOLDER.getRole()); + from.changeRole(Roles.PLAYER.getRole(), true); + to.changeRole(Roles.HOLDER.getRole(), true); } public boolean canTransferTo(Role role) {