-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #50 and adds various debug commands helpful for fixing issues As stated in the title, these commits fix issue #50 and add various debug commands (/taleofkingdoms [debug] [add,get,invoke,set] [{coins, worthiness},{coins, worthiness, hasRebuilt, hasAttacked},{saveVillagers, guildAttack},{coins, worthiness}]). See merge request SamB440/tale-of-kingdoms!31
- Loading branch information
Showing
12 changed files
with
503 additions
and
76 deletions.
There are no files selected for viewing
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
154 changes: 154 additions & 0 deletions
154
src/main/java/com/convallyria/taleofkingdoms/TaleOfKingdomsCommands.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,154 @@ | ||
package com.convallyria.taleofkingdoms; | ||
|
||
import com.convallyria.taleofkingdoms.client.commands.TaleOfKindomsCommand; | ||
import com.convallyria.taleofkingdoms.server.commands.debug.*; | ||
import com.mojang.brigadier.arguments.IntegerArgumentType; | ||
import com.mojang.brigadier.tree.ArgumentCommandNode; | ||
import com.mojang.brigadier.tree.LiteralCommandNode; | ||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; | ||
import net.minecraft.server.command.CommandManager; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
|
||
public class TaleOfKingdomsCommands { | ||
public TaleOfKingdomsCommands() { | ||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> { // Register commands | ||
// Base node /taleofkingdoms | ||
LiteralCommandNode<ServerCommandSource> baseNode = CommandManager | ||
.literal(TaleOfKingdoms.MODID) | ||
.executes(new TaleOfKindomsCommand()) | ||
.build(); | ||
|
||
// Debug node /taleofkingdoms debug | ||
|
||
LiteralCommandNode<ServerCommandSource> debugNode = CommandManager | ||
.literal("debug") | ||
.requires(p -> p.hasPermissionLevel(4)) | ||
.executes(new TaleOfKingdomsDebugCommand()) | ||
.build(); | ||
|
||
// Add node /taleofkingdoms debug add [coins|worthiness] [integer] | ||
|
||
LiteralCommandNode<ServerCommandSource> addNode = CommandManager | ||
.literal("add") | ||
.executes(new TaleOfKingdomsAddCommand()) | ||
.build(); | ||
|
||
LiteralCommandNode<ServerCommandSource> addCoinsNode = CommandManager | ||
.literal("coins") | ||
.build(); | ||
|
||
ArgumentCommandNode<ServerCommandSource, Integer> addCoinsArgumentNode = CommandManager | ||
.argument("coins", IntegerArgumentType.integer()) | ||
.executes(TaleOfKingdomsAddCommand::addCoins) | ||
.build(); | ||
|
||
LiteralCommandNode<ServerCommandSource> addWorthinessNode = CommandManager | ||
.literal("worthiness") | ||
.build(); | ||
|
||
ArgumentCommandNode<ServerCommandSource, Integer> addWorthinessArgumentNode = CommandManager | ||
.argument("worthiness", IntegerArgumentType.integer()) | ||
.executes(TaleOfKingdomsAddCommand::addWorthiness) | ||
.build(); | ||
|
||
// Get node /taleofkingdoms debug get [coins|worthiness] | ||
|
||
LiteralCommandNode<ServerCommandSource> getNode = CommandManager | ||
.literal("get") | ||
.executes(new TaleOfKingdomsGetCommand()) | ||
.build(); | ||
|
||
LiteralCommandNode<ServerCommandSource> getCoinsNode = CommandManager | ||
.literal("coins") | ||
.executes(TaleOfKingdomsGetCommand::getCoins) | ||
.build(); | ||
|
||
LiteralCommandNode<ServerCommandSource> getWorthinessNode = CommandManager | ||
.literal("worthiness") | ||
.executes(TaleOfKingdomsGetCommand::getWorthiness) | ||
.build(); | ||
|
||
LiteralCommandNode<ServerCommandSource> getHasRebuiltNode = CommandManager | ||
.literal("hasRebuilt") | ||
.executes(TaleOfKingdomsGetCommand::getHasRebuilt) | ||
.build(); | ||
|
||
LiteralCommandNode<ServerCommandSource> getHasAttackedNode = CommandManager | ||
.literal("hasAttacked") | ||
.executes(TaleOfKingdomsGetCommand::getHasAttacked) | ||
.build(); | ||
|
||
// Invoke node /taleofkingdoms debug invoke [saveVillagers|guildAttack] | ||
|
||
LiteralCommandNode<ServerCommandSource> invokeNode = CommandManager | ||
.literal("invoke") | ||
.executes(new TaleOfKingdomsInvokeCommand()) | ||
.build(); | ||
|
||
LiteralCommandNode<ServerCommandSource> invokeSaveVillagersNode = CommandManager | ||
.literal("saveVillagers") | ||
.executes(TaleOfKingdomsInvokeCommand::invokeSaveVillagers) | ||
.build(); | ||
|
||
LiteralCommandNode<ServerCommandSource> invokeGuildAttackNode = CommandManager | ||
.literal("guildAttack") | ||
.executes(TaleOfKingdomsInvokeCommand::invokeGuildAttack) | ||
.build(); | ||
|
||
// Set node /taleofkingdoms debug set [coins|worthiness] [integer] | ||
|
||
LiteralCommandNode<ServerCommandSource> setNode = CommandManager | ||
.literal("set") | ||
.executes(new TaleOfKingdomsSetCommand()) | ||
.build(); | ||
|
||
LiteralCommandNode<ServerCommandSource> setCoinsNode = CommandManager | ||
.literal("coins") | ||
.build(); | ||
|
||
ArgumentCommandNode<ServerCommandSource, Integer> setCoinsArgumentNode = CommandManager | ||
.argument("coins", IntegerArgumentType.integer()) | ||
.executes(TaleOfKingdomsSetCommand::setCoins) | ||
.build(); | ||
|
||
LiteralCommandNode<ServerCommandSource> setWorthinessNode = CommandManager | ||
.literal("worthiness") | ||
.build(); | ||
|
||
ArgumentCommandNode<ServerCommandSource, Integer> setWorthinessArgumentNode = CommandManager | ||
.argument("worthiness", IntegerArgumentType.integer()) | ||
.executes(TaleOfKingdomsSetCommand::setWorthiness) | ||
.build(); | ||
|
||
//Now stitch them together | ||
dispatcher.getRoot().addChild(baseNode); | ||
baseNode.addChild(debugNode); | ||
|
||
// Add node | ||
debugNode.addChild(addNode); | ||
addNode.addChild(addCoinsNode); | ||
addCoinsNode.addChild(addCoinsArgumentNode); | ||
addNode.addChild(addWorthinessNode); | ||
addWorthinessNode.addChild(addWorthinessArgumentNode); | ||
|
||
// Get node | ||
debugNode.addChild(getNode); | ||
getNode.addChild(getCoinsNode); | ||
getNode.addChild(getWorthinessNode); | ||
getNode.addChild(getHasRebuiltNode); | ||
getNode.addChild(getHasAttackedNode); | ||
|
||
// Invoke node | ||
debugNode.addChild(invokeNode); | ||
invokeNode.addChild(invokeSaveVillagersNode); | ||
invokeNode.addChild(invokeGuildAttackNode); | ||
|
||
// Set node | ||
debugNode.addChild(setNode); | ||
setNode.addChild(setCoinsNode); | ||
setCoinsNode.addChild(setCoinsArgumentNode); | ||
setNode.addChild(setWorthinessNode); | ||
setWorthinessNode.addChild(setWorthinessArgumentNode); | ||
}); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/convallyria/taleofkingdoms/client/commands/TaleOfKindomsCommand.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,24 @@ | ||
package com.convallyria.taleofkingdoms.client.commands; | ||
|
||
import com.convallyria.taleofkingdoms.TaleOfKingdoms; | ||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import net.minecraft.text.Texts; | ||
import net.minecraft.util.Util; | ||
|
||
public class TaleOfKindomsCommand implements Command<ServerCommandSource> { | ||
@Override | ||
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { | ||
Entity entity = context.getSource().getEntity(); | ||
if (entity != null) { | ||
String message = "[\"\",{\"text\":\"Tale of Kingdoms: A new Conquest\",\"bold\":true,\"underlined\":true,\"color\":\"blue\"},{\"text\":\"\\n\"},{\"text\":\"By Cotander/SamB440 & others. (hover)\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://gitlab.com/SamB440/tale-of-kingdoms/-/blob/master/src/main/resources/fabric.mod.json\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[{\"text\":\"Marackai, Aksel0206, PyroPyxel, Sheepguard, michaelb229, The_KingCobra200, Krol05, BeingAmazing(Ben)#6423. Click to view full list.\"}]}},{\"text\":\"\\n\"},{\"text\":\" Take a look at our website: \",\"color\":\"gold\"},{\"text\":\"https://www.convallyria.com\",\"underlined\":true,\"color\":\"gold\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.convallyria.com\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[{\"text\":\"Click to view our website.\"}]}},{\"text\":\"\\n\"},{\"text\":\" Join our Discord: \",\"color\":\"gold\"},{\"text\":\"https://discord.gg/fh62mxU\",\"underlined\":true,\"color\":\"gold\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://discord.gg/fh62mxU\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[{\"text\":\"Click to join our Discord.\"}]}},{\"text\":\"\\n\"},{\"text\":\"\\n\"},{\"text\":\"Copyright (C) Convallyria 2021\",\"color\":\"gray\"}]"; | ||
entity.sendSystemMessage(Texts.parse(context.getSource(), TaleOfKingdoms.parse(new StringReader(message)), entity, 0), Util.NIL_UUID); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.