Skip to content

Commit 4267784

Browse files
committed
Attempt to provide position for no permission command source fixes #13387
1 parent e5e2c50 commit 4267784

File tree

7 files changed

+79
-25
lines changed

7 files changed

+79
-25
lines changed

paper-server/patches/features/0001-Moonrise-optimisation-patches.patch

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23059,7 +23059,7 @@ index cda915fcb4822689f42b25280eb99aee082ddb74..094d2d528cb74b8f1d277cd780bba7f4
2305923059
thread1 -> {
2306023060
DedicatedServer dedicatedServer1 = new DedicatedServer(
2306123061
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
23062-
index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3cb4037ede 100644
23062+
index b6e4af0482b4d0c8d55a43c84d6d0f1741dc0000..9d8fef4e3ea8eabd63ce368475912c5fc69c493a 100644
2306323063
--- a/net/minecraft/server/MinecraftServer.java
2306423064
+++ b/net/minecraft/server/MinecraftServer.java
2306523065
@@ -185,7 +185,7 @@ import net.minecraft.world.scores.ScoreboardSaveData;
@@ -23071,7 +23071,7 @@ index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3c
2307123071
private static MinecraftServer SERVER; // Paper
2307223072
public static final Logger LOGGER = LogUtils.getLogger();
2307323073
public static final net.kyori.adventure.text.logger.slf4j.ComponentLogger COMPONENT_LOGGER = net.kyori.adventure.text.logger.slf4j.ComponentLogger.logger(LOGGER.getName()); // Paper
23074-
@@ -397,6 +397,93 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23074+
@@ -398,6 +398,93 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2307523075
return minecraftServer;
2307623076
}
2307723077

@@ -23165,7 +23165,7 @@ index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3c
2316523165
public MinecraftServer(
2316623166
// CraftBukkit start
2316723167
joptsimple.OptionSet options,
23168-
@@ -827,7 +914,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23168+
@@ -828,7 +915,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2316923169
serverLevel.setSpawnSettings(serverLevel.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && serverLevel.getGameRules().get(GameRules.SPAWN_MONSTERS)); // Paper - per level difficulty (from setDifficulty(ServerLevel, Difficulty, boolean))
2317023170
this.updateEffectiveRespawnData();
2317123171
this.forceTicks = false; // CraftBukkit
@@ -23174,7 +23174,7 @@ index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3c
2317423174
new org.bukkit.event.world.WorldLoadEvent(serverLevel.getWorld()).callEvent(); // Paper - call WorldLoadEvent
2317523175
}
2317623176

23177-
@@ -850,6 +937,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23177+
@@ -851,6 +938,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2317823178
public abstract boolean shouldRconBroadcast();
2317923179

2318023180
public boolean saveAllChunks(boolean suppressLogs, boolean flush, boolean force) {
@@ -23186,7 +23186,7 @@ index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3c
2318623186
this.scoreboard.storeToSaveDataIfDirty(this.overworld().getDataStorage().computeIfAbsent(ScoreboardSaveData.TYPE));
2318723187
boolean flag = false;
2318823188

23189-
@@ -858,7 +950,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23189+
@@ -859,7 +951,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2319023190
LOGGER.info("Saving chunks for level '{}'/{}", serverLevel, serverLevel.dimension().identifier());
2319123191
}
2319223192

@@ -23195,7 +23195,7 @@ index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3c
2319523195
flag = true;
2319623196
}
2319723197

23198-
@@ -948,7 +1040,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23198+
@@ -949,7 +1041,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2319923199
}
2320023200
}
2320123201

@@ -23204,7 +23204,7 @@ index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3c
2320423204
this.nextTickTimeNanos = Util.getNanos() + TimeUtil.NANOSECONDS_PER_MILLISECOND;
2320523205

2320623206
for (ServerLevel serverLevelx : this.getAllLevels()) {
23207-
@@ -958,18 +1050,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23207+
@@ -959,18 +1051,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2320823208

2320923209
this.waitUntilNextTick();
2321023210
}
@@ -23230,7 +23230,7 @@ index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3c
2323023230

2323123231
this.isSaving = false;
2323223232
this.resources.close();
23233-
@@ -989,6 +1077,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23233+
@@ -990,6 +1078,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2323423234
this.services().nameToIdCache().save(false); // Paper - Perf: Async GameProfileCache saving
2323523235
}
2323623236
// Spigot end
@@ -23245,7 +23245,7 @@ index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3c
2324523245
// Paper start - Improved watchdog support - move final shutdown items here
2324623246
Util.shutdownExecutors();
2324723247
try {
23248-
@@ -1083,16 +1179,31 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23248+
@@ -1084,16 +1180,31 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2324923249
// execute small amounts of other tasks just in case the number of tasks we are
2325023250
// draining is large - chunk system and packet processing may be latency sensitive
2325123251

@@ -23280,15 +23280,15 @@ index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3c
2328023280
profiler.pop(); // moonrise:run_all_chunk
2328123281
profiler.pop(); // moonrise:run_all_tasks
2328223282

23283-
@@ -1393,6 +1504,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23283+
@@ -1394,6 +1505,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2328423284

2328523285
private boolean pollTaskInternal() {
2328623286
if (super.pollTask()) {
2328723287
+ this.moonrise$executeMidTickTasks(); // Paper - rewrite chunk system
2328823288
return true;
2328923289
} else {
2329023290
boolean ret = false; // Paper - force execution of all worlds, do not just bias the first
23291-
@@ -1534,6 +1646,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23291+
@@ -1535,6 +1647,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2329223292
// Paper - improve tick loop - moved into runAllTasksAtTickStart
2329323293
this.runAllTasksAtTickStart(); // Paper - improve tick loop
2329423294
this.tickServer(sprinting ? () -> false : this::haveTime);
@@ -23302,7 +23302,7 @@ index be6e4b5e485e10d37b5194c214f69b677622cc8a..bdaca3647425711ee8b10eb0593a9c3c
2330223302
this.tickFrame.end();
2330323303
this.recordEndOfTick(); // Paper - improve tick loop
2330423304
profilerFiller.pop();
23305-
@@ -2559,6 +2678,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23305+
@@ -2581,6 +2700,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2330623306
}
2330723307
}
2330823308

paper-server/patches/features/0002-Rewrite-dataconverter-system.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33353,10 +33353,10 @@ index c9bbf15b75ac4516c7d7fdfaf2390351702ca415..372030b78d25b4ff0b18575d151b0a63
3335333353
return structureTemplate.save(new CompoundTag());
3335433354
}
3335533355
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
33356-
index bdaca3647425711ee8b10eb0593a9c3cb4037ede..bd910d8263ba8c2bdbeadf33ef5244464a32f8eb 100644
33356+
index 9d8fef4e3ea8eabd63ce368475912c5fc69c493a..f1f57ddffa7fd08afb21ae7f0b4614baa5a922f8 100644
3335733357
--- a/net/minecraft/server/MinecraftServer.java
3335833358
+++ b/net/minecraft/server/MinecraftServer.java
33359-
@@ -383,6 +383,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
33359+
@@ -384,6 +384,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
3336033360
// Paper end - improve tick loop
3336133361

3336233362
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {

paper-server/patches/features/0020-Incremental-chunk-and-player-saving.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Subject: [PATCH] Incremental chunk and player saving
55

66

77
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
8-
index bd910d8263ba8c2bdbeadf33ef5244464a32f8eb..47f34dfddfb1cce87e08c9eb93ad5b2b23c1075b 100644
8+
index f1f57ddffa7fd08afb21ae7f0b4614baa5a922f8..ac3e0c5bf876ad12bd41886dc1e90a5707084def 100644
99
--- a/net/minecraft/server/MinecraftServer.java
1010
+++ b/net/minecraft/server/MinecraftServer.java
11-
@@ -974,7 +974,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
11+
@@ -975,7 +975,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
1212
boolean var4;
1313
try {
1414
this.isSaving = true;
@@ -17,7 +17,7 @@ index bd910d8263ba8c2bdbeadf33ef5244464a32f8eb..47f34dfddfb1cce87e08c9eb93ad5b2b
1717
var4 = this.saveAllChunks(suppressLogs, flush, force);
1818
} finally {
1919
this.isSaving = false;
20-
@@ -1617,9 +1617,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
20+
@@ -1618,9 +1618,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2121
}
2222

2323
this.ticksUntilAutosave--;

paper-server/patches/features/0025-Optimise-EntityScheduler-ticking.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ index 2bc436cdf5180a7943c45fabb9fbbedae6f7db56..f312a7f5b1b2a777ab36b94ce7cbf387
2020

2121
@Override
2222
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
23-
index 47f34dfddfb1cce87e08c9eb93ad5b2b23c1075b..9934055a994c10d646d97a2d042d0e8b1e7e76c9 100644
23+
index ac3e0c5bf876ad12bd41886dc1e90a5707084def..9b3def0ab384ecbdf3901d88fc9c66afb08a86c8 100644
2424
--- a/net/minecraft/server/MinecraftServer.java
2525
+++ b/net/minecraft/server/MinecraftServer.java
26-
@@ -1750,33 +1750,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
26+
@@ -1751,33 +1751,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2727
}
2828
}
2929

paper-server/patches/features/0028-Optimize-Hoppers.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ index 0000000000000000000000000000000000000000..24a2090e068ad3c0d08705050944abdf
4848
+ }
4949
+}
5050
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
51-
index 9934055a994c10d646d97a2d042d0e8b1e7e76c9..e7d9306dfde918c1abb9e5320d7315810a66a4d7 100644
51+
index 9b3def0ab384ecbdf3901d88fc9c66afb08a86c8..d1b909ba4954de55c992c67b9e8770d4c758dfb2 100644
5252
--- a/net/minecraft/server/MinecraftServer.java
5353
+++ b/net/minecraft/server/MinecraftServer.java
54-
@@ -1805,6 +1805,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
54+
@@ -1806,6 +1806,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
5555
serverLevel.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
5656
serverLevel.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
5757
serverLevel.updateLagCompensationTick(); // Paper - lag compensation

paper-server/patches/sources/net/minecraft/commands/Commands.java.patch

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,30 @@
88
public static final String COMMAND_PREFIX = "/";
99
private static final ThreadLocal<@Nullable ExecutionContext<CommandSourceStack>> CURRENT_EXECUTION_CONTEXT = new ThreadLocal<>();
1010
private static final Logger LOGGER = LogUtils.getLogger();
11-
@@ -179,6 +_,7 @@
11+
@@ -164,7 +_,7 @@
12+
public static final PermissionCheck LEVEL_ADMINS = new PermissionCheck.Require(Permissions.COMMANDS_ADMIN);
13+
public static final PermissionCheck LEVEL_OWNERS = new PermissionCheck.Require(Permissions.COMMANDS_OWNER);
14+
private static final ClientboundCommandsPacket.NodeInspector<CommandSourceStack> COMMAND_NODE_INSPECTOR = new ClientboundCommandsPacket.NodeInspector<CommandSourceStack>() {
15+
- private final CommandSourceStack noPermissionSource = Commands.createCompilationContext(PermissionSet.NO_PERMISSIONS);
16+
+ private final CommandSourceStack noPermissionSource = Commands.createCompilationContext(PermissionSet.NO_PERMISSIONS); // Paper - diff on change - don't violate API contracts for location nullability
17+
18+
@Override
19+
public @Nullable Identifier suggestionId(ArgumentCommandNode<CommandSourceStack, ?> node) {
20+
@@ -179,13 +_,25 @@
1221

1322
@Override
1423
public boolean isRestricted(CommandNode<CommandSourceStack> node) {
1524
+ if (node.getRequirement() instanceof RestrictedMarker) return true; // Paper - restricted api
1625
Predicate<CommandSourceStack> requirement = node.getRequirement();
26+
+ // Paper start - don't violate API contracts for location nullability
27+
+ final var server = net.minecraft.server.MinecraftServer.getServer();
28+
+ if (server != null) {
29+
+ return !requirement.test(server.getOrCreateCommandSourceStack(PermissionSet.NO_PERMISSIONS));
30+
+ }
31+
+ // Paper end - don't violate API contracts for location nullability
1732
return !requirement.test(this.noPermissionSource);
1833
}
19-
@@ -186,6 +_,11 @@
34+
};
2035
private final CommandDispatcher<CommandSourceStack> dispatcher = new CommandDispatcher<>();
2136

2237
public Commands(Commands.CommandSelection selection, CommandBuildContext context) {

paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
private int playerIdleTimeout;
4141
private final long[] tickTimesNanos = new long[100];
4242
private long aggregatedTickTimesNanos = 0L;
43-
@@ -281,10 +_,109 @@
43+
@@ -281,10 +_,110 @@
4444
private final DiscontinuousFrame tickFrame;
4545
private final PacketProcessor packetProcessor;
4646

47+
+ private @Nullable CommandSourceStack noPermissionsCommandSourceStack = null; // Paper - don't violate API contracts for location nullability
4748
+ // CraftBukkit start
4849
+ public final WorldLoader.DataLoadContext worldLoaderContext;
4950
+ public org.bukkit.craftbukkit.CraftServer server;
@@ -1124,7 +1125,7 @@
11241125

11251126
profilerFiller.popPush("connection");
11261127
this.tickConnection();
1127-
@@ -1176,9 +_,12 @@
1128+
@@ -1176,10 +_,14 @@
11281129
this.serverActivityMonitor.tick();
11291130
}
11301131

@@ -1137,8 +1138,10 @@
11371138
+ respawnData = respawnData.withLevel(serverLevel.dimension());
11381139
+ // Paper end - per world respawn data - read "server global" respawn data from overworld dimension reference
11391140
this.effectiveRespawnData = serverLevel.getWorldBorderAdjustedRespawnData(respawnData);
1141+
+ this.noPermissionsCommandSourceStack = null; // Paper - don't violate API contracts for location nullability
11401142
}
11411143

1144+
public void tickConnection() {
11421145
@@ -1228,6 +_,22 @@
11431146
return this.levels.get(dimension);
11441147
}
@@ -1363,6 +1366,42 @@
13631366
}
13641367
}
13651368
}
1369+
@@ -1718,6 +_,26 @@
1370+
return this.resources.managers.getCommands();
1371+
}
1372+
1373+
+ // Paper start - don't violate API contracts for location nullability
1374+
+ public CommandSourceStack getOrCreateNoPermissionsCommandSourceStack() {
1375+
+ if (this.noPermissionsCommandSourceStack != null) {
1376+
+ return this.noPermissionsCommandSourceStack;
1377+
+ }
1378+
+ ServerLevel serverLevel = this.findRespawnDimension();
1379+
+ this.noPermissionsCommandSourceStack = new CommandSourceStack(
1380+
+ this,
1381+
+ Vec3.atLowerCornerOf(this.getRespawnData().pos()),
1382+
+ Vec2.ZERO,
1383+
+ serverLevel,
1384+
+ PermissionSet.NO_PERMISSIONS,
1385+
+ "",
1386+
+ net.minecraft.network.chat.CommonComponents.EMPTY,
1387+
+ this,
1388+
+ null
1389+
+ );
1390+
+ return this.noPermissionsCommandSourceStack;
1391+
+ }
1392+
+ // Paper end - don't violate API contracts for location nullability
1393+
public CommandSourceStack createCommandSourceStack() {
1394+
ServerLevel serverLevel = this.findRespawnDimension();
1395+
return new CommandSourceStack(
1396+
@@ -1725,7 +_,7 @@
1397+
Vec3.atLowerCornerOf(this.getRespawnData().pos()),
1398+
Vec2.ZERO,
1399+
serverLevel,
1400+
- LevelBasedPermissionSet.OWNER,
1401+
+ PermissionSet.NO_PERMISSIONS,
1402+
"Server",
1403+
Component.literal("Server"),
1404+
this,
13661405
@@ -1734,12 +_,12 @@
13671406
}
13681407

0 commit comments

Comments
 (0)