diff options
| author | anhgelus <anhgelus.morhtuuzh@proton.me> | 2024-08-22 13:39:00 +0000 |
|---|---|---|
| committer | anhgelus <anhgelus.morhtuuzh@proton.me> | 2024-08-22 13:39:00 +0000 |
| commit | ee4512e9fb41671b26940f2e994d6e49cdd304a9 (patch) | |
| tree | 1390fdd1f5cf2780533e3160af097422ce47bccb | |
| parent | a08b6601ebbe837e3a83e50a7a9cada23d5f385a (diff) | |
feat(game): update gamemode on start and on death
| -rw-r--r-- | src/main/java/world/anhgelus/molehunt/Game.java | 5 | ||||
| -rw-r--r-- | src/main/java/world/anhgelus/molehunt/Molehunt.java | 7 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/main/java/world/anhgelus/molehunt/Game.java b/src/main/java/world/anhgelus/molehunt/Game.java index f7c2715..fb39199 100644 --- a/src/main/java/world/anhgelus/molehunt/Game.java +++ b/src/main/java/world/anhgelus/molehunt/Game.java @@ -8,6 +8,7 @@ import net.minecraft.network.packet.s2c.play.TitleS2CPacket; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
+import net.minecraft.world.GameMode;
import net.minecraft.world.GameRules;
import world.anhgelus.molehunt.utils.TimeUtils;
@@ -54,7 +55,11 @@ public class Game { playerManager.getPlayerList().forEach(p -> {
p.networkHandler.sendPacket(timing);
p.networkHandler.sendPacket(title);
+ p.changeGameMode(GameMode.SURVIVAL);
});
+
+ server.setDefaultGameMode(GameMode.SPECTATOR);
+
timer.schedule(new TimerTask() {
@Override
public void run() {
diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index 9838281..83f5cbd 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -5,10 +5,12 @@ import com.mojang.brigadier.arguments.StringArgumentType; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; +import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents; import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; import net.minecraft.network.message.MessageType; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; +import net.minecraft.world.GameMode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +62,12 @@ public class Molehunt implements ModInitializer { ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource) -> { if (!(entity instanceof ServerPlayerEntity)) return; + if (game == null) return; if (game.gameFinished()) game.end(); }); + + ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> { + newPlayer.changeGameMode(GameMode.SPECTATOR); + }); } } |
