Skip to content

Commit 45c0a04

Browse files
committed
Improve command registration for better compatibility
Enhanced `WorldCommand` registration by merging child commands and adjusting requirements for seamless integration with existing command structures.
1 parent fc15efc commit 45c0a04

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/main/java/net/thenextlvl/perworlds/PerWorldsPlugin.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,16 @@ private void persistGroups() {
112112
}
113113

114114
private void registerCommands() {
115-
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event ->
116-
event.registrar().register(WorldCommand.create(this)));
115+
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> {
116+
var command = WorldCommand.create(this);
117+
var world = event.registrar().getDispatcher().getRoot().getChild("world");
118+
if (world != null) {
119+
world.getChildren().forEach(command::addChild);
120+
var requirement = command.getRequirement();
121+
command.requirement = source -> requirement.test(source) || world.canUse(source);
122+
}
123+
event.registrar().register(command);
124+
});
117125
}
118126

119127
private final Set<String> knownWorldManagers = Set.of( // list ordered by likelihood of a plugin being used

0 commit comments

Comments
 (0)