mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-21 03:10:54 -04:00
Simplify server command registration, fixing server commands being registered too late.
This commit is contained in:
parent
f362c86ed3
commit
53a97948b3
6 changed files with 6 additions and 76 deletions
build.gradle
fabric-command-api-v1
|
@ -12,7 +12,7 @@ plugins {
|
|||
def ENV = System.getenv()
|
||||
|
||||
class Globals {
|
||||
static def baseVersion = "0.12.4"
|
||||
static def baseVersion = "0.12.5"
|
||||
static def mcVersion = "1.16-rc1"
|
||||
static def yarnVersion = "+build.1"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
archivesBaseName = "fabric-command-api-v1"
|
||||
version = getSubprojectVersion(project, "1.0.7")
|
||||
version = getSubprojectVersion(project, "1.0.8")
|
||||
|
||||
dependencies {
|
||||
compile project(path: ':fabric-api-base', configuration: 'dev')
|
||||
|
|
|
@ -19,7 +19,6 @@ package net.fabricmc.fabric.mixin.command;
|
|||
import com.mojang.brigadier.AmbiguityConsumer;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
|
@ -30,31 +29,14 @@ import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
|||
|
||||
@Mixin(CommandManager.class)
|
||||
public abstract class MixinCommandManager {
|
||||
@Unique
|
||||
private static boolean fabric_isFirstRun = true;
|
||||
|
||||
/**
|
||||
* @reason Add commands before ambiguities are calculated.
|
||||
*/
|
||||
@Redirect(at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;findAmbiguities(Lcom/mojang/brigadier/AmbiguityConsumer;)V"), method = "<init>")
|
||||
private void fabric_addCommands(CommandDispatcher<ServerCommandSource> dispatcher, AmbiguityConsumer<ServerCommandSource> ambiguityConsumer, CommandManager.RegistrationEnvironment registrationEnvironment) {
|
||||
if (fabric_isFirstRun) {
|
||||
// Mods have not initialized yet on a dedicated server. These will be registered later though.
|
||||
if (registrationEnvironment != CommandManager.RegistrationEnvironment.DEDICATED) {
|
||||
CommandRegistrationCallback.EVENT.invoker().register(dispatcher, false);
|
||||
CommandRegistrationCallback.EVENT.invoker().register(dispatcher, registrationEnvironment == CommandManager.RegistrationEnvironment.DEDICATED);
|
||||
|
||||
// This should only be called on integrated server. On dedicated, we test this later due to mod init.
|
||||
dispatcher.findAmbiguities(ambiguityConsumer);
|
||||
}
|
||||
} else {
|
||||
// This will occur only if "/reload" is called or this is being registered on an integrated server.
|
||||
CommandRegistrationCallback.EVENT.invoker().register(dispatcher, registrationEnvironment == CommandManager.RegistrationEnvironment.DEDICATED);
|
||||
|
||||
// Mimic vanilla logic by calling findAmbiguities.
|
||||
dispatcher.findAmbiguities(ambiguityConsumer);
|
||||
}
|
||||
|
||||
fabric_isFirstRun = false;
|
||||
// Ambiguities will be called later if on a dedicated server and it is the first run
|
||||
dispatcher.findAmbiguities(ambiguityConsumer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.mixin.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
|
||||
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
|
||||
@Mixin(MinecraftDedicatedServer.class)
|
||||
public abstract class MixinMinecraftDedicatedServer {
|
||||
@Shadow
|
||||
@Final
|
||||
private static Logger LOGGER;
|
||||
|
||||
@Inject(method = "setupServer", at = @At("HEAD"))
|
||||
private void setupServer(CallbackInfoReturnable<Boolean> info) {
|
||||
MinecraftDedicatedServer server = ((MinecraftDedicatedServer) (Object) this);
|
||||
CommandDispatcher<ServerCommandSource> dispatcher = server.getCommandManager().getDispatcher();
|
||||
|
||||
CommandRegistrationCallback.EVENT.invoker().register(dispatcher, true);
|
||||
|
||||
// Now find ambiguities after commands have loaded.
|
||||
dispatcher.findAmbiguities((parent, child, sibling, collection) -> {
|
||||
LOGGER.warn("Ambiguity between arguments {} and {} with inputs: {}", dispatcher.getPath(child), dispatcher.getPath(sibling), collection);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -3,8 +3,7 @@
|
|||
"package": "net.fabricmc.fabric.mixin.command",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"MixinCommandManager",
|
||||
"MixinMinecraftDedicatedServer"
|
||||
"MixinCommandManager"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
"FabricMC"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.0",
|
||||
"fabricloader": ">=0.8.8",
|
||||
"fabric-api-base": "*"
|
||||
},
|
||||
"description": "Adds command-related hooks.",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue