Skip to content

Commit a7b7ff9

Browse files
committed
Add configurable toggle insomnia command, add command toggle insomnia per player, add command register
1 parent f1c9230 commit a7b7ff9

File tree

7 files changed

+162
-119
lines changed

7 files changed

+162
-119
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: MidnightTale <[email protected]>
3+
Date: Thu, 24 Jul 2025 07:30:57 +0700
4+
Subject: [PATCH] Add config for toggleinsomnia command
5+
6+
7+
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
8+
index 2842314c712449625e9275aff7707c916c3ea767..7ff3562f4095a1e79a1299b56a080ee5a15cfa0d 100644
9+
--- a/net/minecraft/world/entity/player/Player.java
10+
+++ b/net/minecraft/world/entity/player/Player.java
11+
@@ -831,6 +831,7 @@ public abstract class Player extends LivingEntity {
12+
this.currentImpulseImpactPos = input.read("current_explosion_impact_pos", Vec3.CODEC).orElse(null);
13+
this.ignoreFallDamageFromCurrentImpulse = input.getBooleanOr("ignore_fall_damage_from_current_explosion", false);
14+
this.currentImpulseContextResetGraceTime = input.getIntOr("current_impulse_context_reset_grace_time", 0);
15+
+ this.insomniaEnabled = input.getBooleanOr("atDeprecated.InsomniaEnabled", true); // atDeprecated - Load insomniaEnabled
16+
}
17+
18+
@Override
19+
@@ -860,6 +861,7 @@ public abstract class Player extends LivingEntity {
20+
output.storeNullable("current_explosion_impact_pos", Vec3.CODEC, this.currentImpulseImpactPos);
21+
output.putBoolean("ignore_fall_damage_from_current_explosion", this.ignoreFallDamageFromCurrentImpulse);
22+
output.putInt("current_impulse_context_reset_grace_time", this.currentImpulseContextResetGraceTime);
23+
+ output.putBoolean("atDeprecated.InsomniaEnabled", this.insomniaEnabled); // atDeprecated - Save insomniaEnabled
24+
}
25+
26+
@Override
27+
@@ -2373,4 +2375,16 @@ public abstract class Player extends LivingEntity {
28+
return this.message;
29+
}
30+
}
31+
+
32+
+ // atDeprecated start - Per-player insomnia toggle for phantom spawning
33+
+ private boolean insomniaEnabled = fun.mntale.atdeprecated.config.AtCoreConfig.PLAYER_CONFIG.defaultInsomniaState;
34+
+
35+
+ public boolean isInsomniaEnabled() {
36+
+ return insomniaEnabled;
37+
+ }
38+
+
39+
+ public void setInsomniaEnabled(boolean enabled) {
40+
+ this.insomniaEnabled = enabled;
41+
+ }
42+
+ // atDeprecated end
43+
}
44+
diff --git a/net/minecraft/world/level/levelgen/PhantomSpawner.java b/net/minecraft/world/level/levelgen/PhantomSpawner.java
45+
index 0cafe46e9a1b053c5e70f20a26b4402632d0f8bf..664ec25a89e3210ecd1d387472e92e5cb83e50a1 100644
46+
--- a/net/minecraft/world/level/levelgen/PhantomSpawner.java
47+
+++ b/net/minecraft/world/level/levelgen/PhantomSpawner.java
48+
@@ -41,6 +41,11 @@ public class PhantomSpawner implements CustomSpawner {
49+
// Paper end - Ability to control player's insomnia and phantoms
50+
if (level.getSkyDarken() >= 5 || !level.dimensionType().hasSkyLight()) {
51+
for (ServerPlayer serverPlayer : level.getLocalPlayers()) { // Folia - region threading
52+
+ // atDeprecated start - Skip players with insomnia disabled
53+
+ if (fun.mntale.atdeprecated.config.AtCoreConfig.PLAYER_CONFIG.perPlayerInsomnia && serverPlayer instanceof net.minecraft.world.entity.player.Player p && !p.isInsomniaEnabled()) {
54+
+ continue;
55+
+ }
56+
+ // atDeprecated end
57+
if (!serverPlayer.isSpectator() && (!level.paperConfig().entities.behavior.phantomsDoNotSpawnOnCreativePlayers || !serverPlayer.isCreative())) { // Paper - Add phantom creative and insomniac controls
58+
BlockPos blockPos = serverPlayer.blockPosition();
59+
if (!level.dimensionType().hasSkyLight() || blockPos.getY() >= level.getSeaLevel() && level.canSeeSky(blockPos)) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: MidnightTale <[email protected]>
3+
Date: Thu, 24 Jul 2025 08:24:07 +0700
4+
Subject: [PATCH] Setup commands
5+
6+
7+
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
8+
index f316bcd8dab860961a964c31512f9eb43f286ebd..aab00d6b754995c2ad962ed359ac729411af22e3 100644
9+
--- a/net/minecraft/server/dedicated/DedicatedServer.java
10+
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
11+
@@ -236,6 +236,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
12+
// CraftBukkit start
13+
this.server.loadPlugins();
14+
this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP);
15+
+ fun.mntale.atdeprecated.commands.CommandManager.init(); // atDeprecated - Register commands
16+
// CraftBukkit end
17+
18+
// Paper start - Add Velocity IP Forwarding Support

atdeprecated-server/minecraft-patches/removes/0005-Toggleinsomnia-phantom-spawn-per-player.patch

Lines changed: 0 additions & 119 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package fun.mntale.atdeprecated.commands;
2+
3+
import fun.mntale.atdeprecated.config.AtCoreConfig;
4+
import org.bukkit.Bukkit;
5+
6+
public class CommandManager {
7+
8+
public static void init() {
9+
if (AtCoreConfig.PLAYER_CONFIG.perPlayerInsomnia && AtCoreConfig.PLAYER_CONFIG.enableToggleInsomniaCommand) {
10+
Bukkit.getCommandMap().register("toggleinsomnia", "atdeprecated", new ToggleInsomniaCommand("toggleinsomnia"));
11+
}
12+
}
13+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package fun.mntale.atdeprecated.commands;
2+
3+
import net.kyori.adventure.text.Component;
4+
import net.kyori.adventure.text.format.NamedTextColor;
5+
import org.bukkit.command.Command;
6+
import org.bukkit.command.CommandSender;
7+
import org.bukkit.entity.Player;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
public class ToggleInsomniaCommand extends Command {
11+
12+
public ToggleInsomniaCommand(String name) {
13+
super(name);
14+
this.setDescription("Toggles phantom spawning for the player.");
15+
this.setUsage("/" + name);
16+
this.setPermission("atdeprecated.command.toggleinsomnia");
17+
}
18+
19+
@Override
20+
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
21+
if (!testPermission(sender)) {
22+
return true;
23+
}
24+
25+
if (!(sender instanceof Player player)) {
26+
sender.sendMessage(Component.text("Only players can use this command.").color(NamedTextColor.RED));
27+
return true;
28+
}
29+
30+
net.minecraft.world.entity.player.Player nmsPlayer = ((org.bukkit.craftbukkit.entity.CraftPlayer) player).getHandle();
31+
boolean current = nmsPlayer.isInsomniaEnabled();
32+
nmsPlayer.setInsomniaEnabled(!current);
33+
34+
player.sendActionBar(
35+
Component.text("Insomnia: ")
36+
.append(Component.text(!current ? "Enabled" : "Disabled")
37+
.color(!current ? NamedTextColor.GREEN : NamedTextColor.RED))
38+
);
39+
40+
return true;
41+
}
42+
}

atdeprecated-server/src/main/java/fun/mntale/atdeprecated/config/AtCoreConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import fun.mntale.atdeprecated.config.modules.features.BeaconConfig;
55
import fun.mntale.atdeprecated.config.modules.features.DispenserConfig;
66
import fun.mntale.atdeprecated.config.modules.features.ElytraConfig;
7+
import fun.mntale.atdeprecated.config.modules.features.PlayerConfig;
78
import fun.mntale.atdeprecated.config.modules.removed.RemovedConfig;
89
import java.io.File;
910

@@ -14,6 +15,7 @@ public class AtCoreConfig {
1415
public static final BeaconConfig BEACON_CONFIG = new BeaconConfig();
1516
public static final DispenserConfig DISPENSER_CONFIG = new DispenserConfig();
1617
public static final ElytraConfig ELYTRA_CONFIG = new ElytraConfig();
18+
public static final PlayerConfig PLAYER_CONFIG = new PlayerConfig();
1719
public static final RemovedConfig REMOVED_CONFIG = new RemovedConfig();
1820

1921
public static void init() {
@@ -30,6 +32,7 @@ private static void registerModules() {
3032
configManager.registerModule(BEACON_CONFIG);
3133
configManager.registerModule(DISPENSER_CONFIG);
3234
configManager.registerModule(ELYTRA_CONFIG);
35+
configManager.registerModule(PLAYER_CONFIG);
3336
configManager.registerModule(REMOVED_CONFIG);
3437
}
3538
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package fun.mntale.atdeprecated.config.modules.features;
2+
3+
import fun.mntale.atdeprecated.config.EnumConfigCategory;
4+
import fun.mntale.atdeprecated.config.IConfigModule;
5+
import fun.mntale.atdeprecated.config.annotations.ConfigInfo;
6+
7+
public class PlayerConfig implements IConfigModule {
8+
9+
@ConfigInfo(name = "per-player-insomnia", comments = "Enable per-player insomnia settings. If false, the server will use the global phantom spawning rules.")
10+
public boolean perPlayerInsomnia = true;
11+
12+
@ConfigInfo(name = "enable-toggle-insomnia-command", comments = "Enable the /toggleinsomnia command for players to control phantom spawning. Requires per-player-insomnia to be true.")
13+
public boolean enableToggleInsomniaCommand = true;
14+
15+
@ConfigInfo(name = "default-insomnia-state", comments = "The default state of insomnia for players when they first join. Requires per-player-insomnia to be true.")
16+
public boolean defaultInsomniaState = true;
17+
18+
@Override
19+
public EnumConfigCategory getCategory() {
20+
return EnumConfigCategory.FEATURES;
21+
}
22+
23+
@Override
24+
public String getBaseName() {
25+
return "player";
26+
}
27+
}

0 commit comments

Comments
 (0)