aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/world/anhgelus/molehunt/Game.java5
-rw-r--r--src/main/java/world/anhgelus/molehunt/Molehunt.java7
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);
+ });
}
}