fabric: Begin work on commands manager for platform

This commit is contained in:
Zach Levis 2020-11-24 21:39:29 -08:00 committed by Jason
parent 0722bf6ead
commit eef98da9c9
16 changed files with 737 additions and 8 deletions

View file

@ -0,0 +1,68 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & 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 cloud.commandframework.fabric.testmod;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.standard.IntegerArgument;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.fabric.FabricCommandManager;
import net.fabricmc.api.ModInitializer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TextColor;
public final class FabricExample implements ModInitializer {
private static final CommandArgument<ServerCommandSource, String> NAME = StringArgument.of("name");
private static final CommandArgument<ServerCommandSource, Integer> HUGS = IntegerArgument.<ServerCommandSource>newBuilder("hugs")
.asOptionalWithDefault("1")
.build();
@Override
public void onInitialize() {
// Create a commands manager. We'll use native command source types for this.
final FabricCommandManager<ServerCommandSource> manager =
FabricCommandManager.createNative(CommandExecutionCoordinator.simpleCoordinator());
manager.command(manager.commandBuilder("cloudtest")
.argument(NAME)
.argument(HUGS)
.handler(ctx -> {
ctx.getSender().sendFeedback(new LiteralText("Hello, ")
.append(ctx.get(NAME))
.append(", hope you're doing well!")
.styled(style -> style.withColor(TextColor.fromRgb(0xAA22BB))), false);
ctx.getSender().sendFeedback(new LiteralText("Cloud would like to give you ")
.append(new LiteralText(String.valueOf(ctx.get(HUGS)))
.styled(style -> style.withColor(TextColor.fromRgb(0xFAB3DA))))
.append(" hug(s) <3")
.styled(style -> style.withBold(true)), false);
}));
}
}

View file

@ -0,0 +1,28 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg & 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.
//
/**
* A test mod for the fabric implementation of Cloud.
*/
package cloud.commandframework.fabric.testmod;

View file

@ -0,0 +1,28 @@
{
"schemaVersion": 1,
"id": "cloud-testmod",
"version": "${version}",
"name": "Cloud Test mod",
"description": "Command framework and dispatcher for the JVM",
"authors": [ "Alexander Söderberg" ],
"contact": {
"homepage": "https://commandframework.cloud/",
"sources": "https://github.com/Incendo/cloud"
},
"license": "MIT",
"icon": "assets/cloud/logo.png",
"entrypoints": {
"main": [
"cloud.commandframework.fabric.testmod.FabricExample"
]
},
"depends": {
"fabricloader": ">=0.7.4",
"fabric-command-api-v1": "*",
"minecraft": ">=1.14",
"cloud": "*"
}
}