Fix commands on servers. ()

* Fix commands on servers.

Based off the same fix I made a year or two ago...

* Fix
This commit is contained in:
modmuss50 2020-05-02 21:19:24 +01:00
parent 304e48eb3a
commit 5644fa286e
5 changed files with 59 additions and 4 deletions

View file

@ -12,7 +12,7 @@ plugins {
def ENV = System.getenv()
class Globals {
static def baseVersion = "0.10.1"
static def baseVersion = "0.10.2"
static def mcVersion = "20w18a"
static def yarnVersion = "+build.1"
}

View file

@ -1,5 +1,5 @@
archivesBaseName = "fabric-command-api-v1"
version = getSubprojectVersion(project, "1.0.0")
version = getSubprojectVersion(project, "1.0.1")
dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev')

View file

@ -34,7 +34,10 @@ public abstract class MixinCommandManager {
*/
@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, boolean isDedicated) {
CommandRegistrationCallback.EVENT.invoker().register(dispatcher, isDedicated);
if (!isDedicated) {
CommandRegistrationCallback.EVENT.invoker().register(dispatcher, isDedicated);
}
// Now mimic vanilla logic by calling findAmbiguities.
dispatcher.findAmbiguities(ambiguityConsumer);
}

View file

@ -0,0 +1,51 @@
/*
* 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 java.io.File;
import java.net.Proxy;
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import com.mojang.datafixers.DataFixer;
import org.spongepowered.asm.mixin.Mixin;
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.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListenerFactory;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
import net.minecraft.util.UserCache;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
@Mixin(MinecraftDedicatedServer.class)
public abstract class MixinMinecraftDedicatedServer extends MinecraftServer {
public MixinMinecraftDedicatedServer(File gameDir, Proxy proxy, DataFixer dataFixer, CommandManager commandManager, YggdrasilAuthenticationService authService, MinecraftSessionService sessionService, GameProfileRepository gameProfileRepository, UserCache userCache, WorldGenerationProgressListenerFactory worldGenerationProgressListenerFactory, String levelName) {
super(gameDir, proxy, dataFixer, commandManager, authService, sessionService, gameProfileRepository, userCache, worldGenerationProgressListenerFactory, levelName);
}
@Inject(method = "setupServer", at = @At("HEAD"))
private void setupServer(CallbackInfoReturnable<Boolean> info) {
CommandRegistrationCallback.EVENT.invoker().register(getCommandManager().getDispatcher(), true);
//Possibly call findAmbiguities here
}
}

View file

@ -3,7 +3,8 @@
"package": "net.fabricmc.fabric.mixin.command",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinCommandManager"
"MixinCommandManager",
"MixinMinecraftDedicatedServer"
],
"client": [
],