package jesse.keeblarcraft.Commands; import java.util.List; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.context.CommandContext; import jesse.keeblarcraft.FactionMgr.FactionManager; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; public class FactionCommands { ///////////////////////////////////////////////////////////////////////////// /// @fn RegisterFactionCommands /// /// @brief Registers all commands for factions ///////////////////////////////////////////////////////////////////////////// public void RegisterFactionCommands() { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { var factionNode = CommandManager.literal("faction").build(); var createFaction = CommandManager.literal("create").build(); var disbandFaction = CommandManager.literal("disband").build(); var promote = CommandManager.literal("promote").build(); var demote = CommandManager.literal("demote").build(); // The below nodes are duplicates but are necessary to make the execute path jump correctly var createFactionName = CommandManager.argument("faction_name", StringArgumentType.greedyString()) .executes(context -> CreateFaction ( context, StringArgumentType.getString(context, "faction_name") ) ).build(); var disbandFactionName = CommandManager.argument("faction_name", StringArgumentType.greedyString()) .executes(context -> DeleteFaction ( context, StringArgumentType.getString(context, "faction_name") ) ).build(); var leaveFaction = CommandManager.literal("leave").executes(context -> LeaveFaction(context) ).build(); var listAll = CommandManager.literal("list") .executes(context -> ListAllFactions(context.getSource().getPlayer())).build(); // Root node dispatcher.getRoot().addChild(factionNode); // List command factionNode.addChild(listAll); factionNode.addChild(createFaction); factionNode.addChild(disbandFaction); factionNode.addChild(leaveFaction); createFaction.addChild(createFactionName); disbandFaction.addChild(disbandFactionName); }); } ///////////////////////////////////////////////////////////////////////////// /// @fn CreateFaction /// /// @param[in] context is the context of where this command runs from /// /// @param[in] newFactionName is the faction name to be created /// /// @brief Command to create a faction ///////////////////////////////////////////////////////////////////////////// private int CreateFaction(CommandContext context, String newFactionName) { int retValue = 0; System.out.println("CreateFaction getting player obj"); ServerPlayerEntity player = context.getSource().getPlayer(); System.out.println("CreateFaction called"); if (newFactionName.length() >= 4) { FactionManager.GetInstance().CreateFaction(newFactionName, player); } else { player.sendMessage(Text.of("Your faction must be at least 4 letters long!")); } return retValue; } ///////////////////////////////////////////////////////////////////////////// /// @fn DeleteFaction /// /// @param[in] context is the context of where this command runs from /// /// @param[in] newFactionName is the faction name to be deleted /// /// @brief Command to create a faction ///////////////////////////////////////////////////////////////////////////// private int DeleteFaction(CommandContext context, String factionName) { int retValue = 0; ServerPlayerEntity player = context.getSource().getPlayer(); FactionManager.GetInstance().DeleteFaction(factionName, player); return retValue; } private int AddPlayerToFaction() { int retValue = -1; return retValue; } ///////////////////////////////////////////////////////////////////////////// /// @fn LeaveFaction /// /// @param[in] context is the context of where this command runs from /// /// @brief Command to leave a faction ///////////////////////////////////////////////////////////////////////////// private int LeaveFaction(CommandContext context) { ServerPlayerEntity player = context.getSource().getPlayer(); FactionManager.GetInstance().LeaveFaction(player); return 0; } private int KickPlayerFromFaction() { int retValue = -1; return retValue; } private int PromotePlayerInFaction() { int retValue = -1; return retValue; } private int DemotePlayerInFaction() { int retValue = -1; return retValue; } private int SetPlayerRoleInFaction() { int retValue = -1; return retValue; } private int DeclareFactionBase() { int retValue = -1; return retValue; } // admin only private int SetFactionPower() { int retValue = -1; return retValue; } private int DeclareFactionEvent() { int retValue = -1; return retValue; } private int DeclareEnemyFaction() { int retValue = -1; return retValue; } private int DeclareAlliedFaction() { int retValue = -1; return retValue; } private int DeclareNeutralFaction() { int retValue = -1; return retValue; } ///////////////////////////////////////////////////////////////////////////// /// @fn ListAllFactions /// /// @param[in] player is the command runner /// /// @brief Command to see all factions on the server ///////////////////////////////////////////////////////////////////////////// private int ListAllFactions(ServerPlayerEntity player) { int retValue = -1; System.out.println("Listing factions"); List facs = FactionManager.GetInstance().ListOfFactions(); if (facs != null) { player.sendMessage(Text.of("All factions on server: " + facs)); } else { player.sendMessage(Text.of("There are no factions on this server yet!")); } return retValue; } private int RegisterFactionChatChannel() { int retValue = -1; return retValue; } // admin only private int DeleteFactionChatChannel() { int retValue = -1; return retValue; } private int DepositToFactionBank() { int retValue = -1; return retValue; } private int WithdrawFromFactionBank() { int retValue = -1; return retValue; } private int FactionBankBalance() { int retValue = -1; return retValue; } private int ListFactionBankTransactions() { int retValue = -1; return retValue; } }