-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
752f1af
commit c97bbcd
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...c-api/1.6.4/src/testmod/java/net/legacyfabric/fabric/test/command/ModMetadataCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 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.legacyfabric.fabric.test.command; | ||
|
||
import java.util.Objects; | ||
|
||
import net.minecraft.text.ChatMessage; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.fabricmc.loader.api.ModContainer; | ||
import net.fabricmc.loader.api.metadata.ContactInformation; | ||
|
||
import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandException; | ||
import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandManager; | ||
import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandResult; | ||
import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; | ||
import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.GenericArguments; | ||
import net.legacyfabric.fabric.api.command.v2.lib.sponge.spec.CommandSpec; | ||
import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; | ||
|
||
public class ModMetadataCommand { | ||
public static void register(CommandManager manager) { | ||
manager.register( | ||
CommandSpec.builder() | ||
.arguments(GenericArguments.mod(ChatMessage.createTextMessage("modid"))) | ||
.executor(ModMetadataCommand::execute) | ||
.build(), | ||
"modmetadata" | ||
); | ||
} | ||
|
||
private static final boolean useStyle = !Objects.equals(FabricLoader.getInstance().getModContainer("minecraft").get().getMetadata().getVersion().getFriendlyString(), "1.8"); | ||
|
||
private static CommandResult execute(PermissibleCommandSource source, CommandContext ctx) throws CommandException { | ||
ModContainer container = ctx.<ModContainer>getOne("modid").orElseThrow(() -> new CommandException(ChatMessage.createTextMessage("mod not found"))); | ||
ChatMessage builder = ChatMessage.createTextMessage(""); | ||
builder.addText("Mod Name: ".concat(container.getMetadata().getName()).concat("\n")); | ||
builder.addText("Description: ".concat(container.getMetadata().getDescription()).concat("\n")); | ||
ContactInformation contact = container.getMetadata().getContact(); | ||
|
||
if (contact.get("issues").isPresent()) { | ||
ChatMessage issueText = ChatMessage.createTextMessage(""); | ||
issueText.addText("Issues: "); | ||
ChatMessage issueUrl = ChatMessage.createTextMessage(contact.get("issues").get()); | ||
issueText.addUsing(issueUrl); | ||
issueText.addText("\n"); | ||
builder.addUsing(issueText); | ||
} | ||
|
||
if (contact.get("sources").isPresent()) { | ||
ChatMessage sourcesText = ChatMessage.createTextMessage(""); | ||
sourcesText.addText("Sources: "); | ||
ChatMessage sourcesUrl = ChatMessage.createTextMessage(contact.get("sources").get()); | ||
sourcesText.addUsing(sourcesUrl); | ||
sourcesText.addText("\n"); | ||
builder.addUsing(sourcesText); | ||
} | ||
|
||
builder.addText("Metadata Type: ".concat(container.getMetadata().getType()).concat("\n")); | ||
source.method_5505(builder); | ||
return CommandResult.success(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ic-api/1.6.4/src/testmod/java/net/legacyfabric/fabric/test/command/SpongeCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 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.legacyfabric.fabric.test.command; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
|
||
import net.legacyfabric.fabric.api.command.v2.CommandRegistrar; | ||
|
||
public class SpongeCommandTest implements ModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
CommandRegistrar.EVENT.register((manager, dedicated) -> { | ||
ModMetadataCommand.register(manager); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters