From 52f102d4ec0fe3e242017153101769011469aa85 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Tue, 30 Apr 2019 14:48:22 -0300 Subject: [PATCH] updated cotton client commands --- build.gradle.kts | 4 +- .../creeper123123321/viafabric/ViaFabric.java | 31 ++++------------ .../viafabric/commands/VRClientCommands.java | 37 +++++++++++++++++++ src/main/resources/fabric.mod.json | 5 ++- 4 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/github/creeper123123321/viafabric/commands/VRClientCommands.java diff --git a/build.gradle.kts b/build.gradle.kts index 3e8a99c..ff0a751 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -61,8 +61,8 @@ dependencies { modCompile("net.fabricmc:fabric:0.2.7+build.127") - modCompile("io.github.cottonmc:client-commands:0.2.1+1.14-pre5-SNAPSHOT") - include("io.github.cottonmc:client-commands:0.2.1+1.14-pre5-SNAPSHOT") + modCompile("io.github.cottonmc:cotton-client-commands:0.3.0+1.14-SNAPSHOT") + include("io.github.cottonmc:cotton-client-commands:0.3.0+1.14-SNAPSHOT") } minecraft { diff --git a/src/main/java/com/github/creeper123123321/viafabric/ViaFabric.java b/src/main/java/com/github/creeper123123321/viafabric/ViaFabric.java index 1262d1f..83738ca 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/ViaFabric.java +++ b/src/main/java/com/github/creeper123123321/viafabric/ViaFabric.java @@ -25,7 +25,10 @@ package com.github.creeper123123321.viafabric; import com.github.creeper123123321.viafabric.commands.VRCommandHandler; -import com.github.creeper123123321.viafabric.platform.*; +import com.github.creeper123123321.viafabric.platform.VRInjector; +import com.github.creeper123123321.viafabric.platform.VRLoader; +import com.github.creeper123123321.viafabric.platform.VRPlatform; +import com.github.creeper123123321.viafabric.platform.VRRewindPlatform; import com.github.creeper123123321.viafabric.protocol.protocol1_7_6_10to1_7_1_5.Protocol1_7_6_10To1_7_1_5; import com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.Protocol1_8To1_7_6_10; import com.github.creeper123123321.viafabric.util.JLoggerToLog4j; @@ -71,7 +74,7 @@ public class ViaFabric implements ModInitializer { .get().getMetadata().getVersion().getFriendlyString(); } - private static LiteralArgumentBuilder command(String commandName) { + public static LiteralArgumentBuilder command(String commandName) { return LiteralArgumentBuilder.literal(commandName) .then( RequiredArgumentBuilder @@ -95,26 +98,8 @@ public class ViaFabric implements ModInitializer { new VRRewindPlatform().init(); // new VRBackwardsPlatform().init(); todo reenable when viabackwards is updated - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { - try { - Class.forName("io.github.cottonmc.clientcommands.ClientCommands") - .getMethod("registerCommand", Consumer.class) - .invoke(null, - (Consumer>) c -> - c.register(command("viafabricclient")) - ); - } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - Via.getPlatform().getLogger().warning("ClientCommands isn't installed"); - } - } - - try { - Class.forName("net.fabricmc.fabric.api.registry.CommandRegistry"); - CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaversion"))); - CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaver"))); - CommandRegistry.INSTANCE.register(false, c -> c.register(command("vvfabric"))); - } catch (ClassNotFoundException e) { - Via.getPlatform().getLogger().warning("Fabric API isn't installed"); - } + CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaversion"))); + CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaver"))); + CommandRegistry.INSTANCE.register(false, c -> c.register(command("vvfabric"))); } } diff --git a/src/main/java/com/github/creeper123123321/viafabric/commands/VRClientCommands.java b/src/main/java/com/github/creeper123123321/viafabric/commands/VRClientCommands.java new file mode 100644 index 0000000..5cb80c7 --- /dev/null +++ b/src/main/java/com/github/creeper123123321/viafabric/commands/VRClientCommands.java @@ -0,0 +1,37 @@ +/* + * MIT License + * + * Copyright (c) 2018 creeper123123321 and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.creeper123123321.viafabric.commands; + +import com.github.creeper123123321.viafabric.ViaFabric; +import com.mojang.brigadier.CommandDispatcher; +import io.github.cottonmc.clientcommands.ClientCommandPlugin; +import net.minecraft.server.command.CommandSource; + +public class VRClientCommands implements ClientCommandPlugin { + @Override + public void registerCommands(CommandDispatcher commandDispatcher) { + commandDispatcher.register(ViaFabric.command("viafabricclient")); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 81266d7..6e08c46 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -18,6 +18,9 @@ "entrypoints": { "main": [ "com.github.creeper123123321.viafabric.ViaFabric" + ], + "cotton-client-commands": [ + "com.github.creeper123123321.viafabric.commands.VRClientCommands" ] }, "requires": { @@ -25,7 +28,7 @@ "fabric": "*" }, "recommended": { - "clientcommands": "*" + "cotton-client-commands": "*" }, "mixins": [ "mixins.viafabric.json"