Skip to content

Commit 5ff4312

Browse files
committed
Fix double-jailing bug and add admin jail time checking
BUG FIXES: - Prevent jailing already-jailed players (was overwriting jail data) - Show clear error with remaining time: 'Player is already jailed! Remaining time: X. Use /jail release first.' NEW FEATURE: - Add /jail time <player> for admins to check any player's jail time - Regular players can only use /jail time (self-only) - Admins need oldschooljail.jail permission to check others - Clear error messages for permissions and non-jailed players DOCUMENTATION: - Updated README with new /jail time <player> command - Added permission explanation for admin jail time checking This prevents data corruption and gives admins better jail management tools.
1 parent adaaec0 commit 5ff4312

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ A classic jail mod for Minecraft Fabric servers (1.21.8+) - just like the good o
3535

3636
- `/jail release <player>` - Release a player from jail early and teleport them back to where they were
3737

38-
- `/jail time` - Check remaining jail time (available to jailed players)
38+
- `/jail time` - Check your own remaining jail time (available to jailed players)
39+
- `/jail time <player>` - Check any player's jail time (admin only - requires `oldschooljail.jail` permission)
3940

4041
### Admin Commands
4142
- `/jail set <jail_name>` - Set a jail at your current location
@@ -53,6 +54,7 @@ The mod uses the Fabric Permissions API and supports any permissions plugin that
5354
- `oldschooljail.delete` - Allows deleting jails
5455
- `oldschooljail.immune` - Makes a player immune to being jailed
5556
- `oldschooljail.time` - Allows using `/jail time` (granted to all by default)
57+
- `oldschooljail.jail` - Also allows using `/jail time <player>` to check other players' jail time
5658

5759
**Note**: If no permissions plugin is installed, the mod falls back to OP level 2 for admin commands.
5860

src/main/java/com/oldschooljail/command/JailCommand.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
7777

7878
// /jail time
7979
.then(CommandManager.literal("time")
80-
.executes(JailCommand::checkJailTime))
80+
.executes(JailCommand::checkJailTime)
81+
// /jail time <player>
82+
.then(CommandManager.argument("player", EntityArgumentType.player())
83+
.executes(JailCommand::checkPlayerJailTime)))
8184
);
8285
}
8386

@@ -136,6 +139,16 @@ private static int executeJail(ServerCommandSource source, ServerPlayerEntity ta
136139
return 0;
137140
}
138141

142+
// Check if target is already jailed
143+
JailedPlayersData jailedData = OldSchoolJailMod.getJailedPlayersData();
144+
if (jailedData.isJailed(target.getUuid())) {
145+
JailedPlayer existingJail = jailedData.getJailedPlayer(target.getUuid());
146+
long remaining = existingJail.getRemainingTimeSeconds();
147+
source.sendError(Text.literal("§c" + target.getName().getString() + " is already jailed! " +
148+
"Remaining time: " + formatTime(remaining) + ". Use /jail release first."));
149+
return 0;
150+
}
151+
139152
JailConfig config = OldSchoolJailMod.getConfig();
140153
long timeInSeconds = config.convertToSeconds(time);
141154

@@ -147,7 +160,6 @@ private static int executeJail(ServerCommandSource source, ServerPlayerEntity ta
147160
}
148161

149162
JailData jailData = OldSchoolJailMod.getJailData();
150-
JailedPlayersData jailedData = OldSchoolJailMod.getJailedPlayersData();
151163

152164
Jail jail = jailData.getJail(jailName);
153165
if (jail == null) {
@@ -333,6 +345,30 @@ private static int checkJailTime(CommandContext<ServerCommandSource> context) th
333345
return 1;
334346
}
335347

348+
private static int checkPlayerJailTime(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
349+
ServerCommandSource source = context.getSource();
350+
351+
// Check permission - only admins can check other players' jail time
352+
if (!PermissionUtil.hasPermission(source, PermissionUtil.JAIL_PLAYER)) {
353+
source.sendError(Text.literal("§cYou don't have permission to check other players' jail time!"));
354+
return 0;
355+
}
356+
357+
ServerPlayerEntity target = EntityArgumentType.getPlayer(context, "player");
358+
JailedPlayersData jailedData = OldSchoolJailMod.getJailedPlayersData();
359+
JailedPlayer jailed = jailedData.getJailedPlayer(target.getUuid());
360+
361+
if (jailed == null) {
362+
source.sendError(Text.literal("§c" + target.getName().getString() + " is not jailed!"));
363+
return 0;
364+
}
365+
366+
long remaining = jailed.getRemainingTimeSeconds();
367+
source.sendFeedback(() -> Text.literal("§e" + target.getName().getString() + " will be released in: " + formatTime(remaining)), false);
368+
369+
return 1;
370+
}
371+
336372
private static void teleportToJail(ServerPlayerEntity player, Jail jail) {
337373
// Get the world
338374
MinecraftServer server = player.getServer();

0 commit comments

Comments
 (0)