2024-10-28 21:47:51 +00:00
|
|
|
package jesse.keeblarcraft.Commands;
|
|
|
|
|
2024-11-24 03:06:00 +00:00
|
|
|
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;
|
|
|
|
|
2024-10-28 21:47:51 +00:00
|
|
|
public class FactionCommands {
|
|
|
|
|
2024-12-06 07:04:09 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// @fn RegisterFactionCommands
|
|
|
|
///
|
|
|
|
/// @brief Registers all commands for factions
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2024-10-28 21:47:51 +00:00
|
|
|
public void RegisterFactionCommands() {
|
2024-11-24 03:06:00 +00:00
|
|
|
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);
|
2024-10-28 21:47:51 +00:00
|
|
|
|
2024-11-24 03:06:00 +00:00
|
|
|
// List command
|
|
|
|
factionNode.addChild(listAll);
|
|
|
|
factionNode.addChild(createFaction);
|
|
|
|
factionNode.addChild(disbandFaction);
|
|
|
|
factionNode.addChild(leaveFaction);
|
|
|
|
|
|
|
|
createFaction.addChild(createFactionName);
|
|
|
|
disbandFaction.addChild(disbandFactionName);
|
|
|
|
});
|
2024-10-28 21:47:51 +00:00
|
|
|
}
|
|
|
|
|
2024-12-06 07:04:09 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// @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
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2024-11-24 03:06:00 +00:00
|
|
|
private int CreateFaction(CommandContext<ServerCommandSource> 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!"));
|
|
|
|
}
|
2024-10-28 21:47:51 +00:00
|
|
|
|
|
|
|
return retValue;
|
|
|
|
}
|
|
|
|
|
2024-12-06 07:04:09 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// @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<ServerCommandSource> context, String factionName) {
|
2024-11-24 03:06:00 +00:00
|
|
|
int retValue = 0;
|
|
|
|
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
2024-12-06 07:04:09 +00:00
|
|
|
FactionManager.GetInstance().DeleteFaction(factionName, player);
|
2024-10-28 21:47:51 +00:00
|
|
|
|
|
|
|
return retValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int AddPlayerToFaction() {
|
|
|
|
int retValue = -1;
|
|
|
|
|
|
|
|
return retValue;
|
|
|
|
}
|
|
|
|
|
2024-12-06 07:04:09 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// @fn LeaveFaction
|
|
|
|
///
|
|
|
|
/// @param[in] context is the context of where this command runs from
|
|
|
|
///
|
|
|
|
/// @brief Command to leave a faction
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2024-11-24 03:06:00 +00:00
|
|
|
private int LeaveFaction(CommandContext<ServerCommandSource> context) {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
|
|
|
|
FactionManager.GetInstance().LeaveFaction(player);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-10-28 21:47:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-12-06 07:04:09 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// @fn ListAllFactions
|
|
|
|
///
|
|
|
|
/// @param[in] player is the command runner
|
|
|
|
///
|
|
|
|
/// @brief Command to see all factions on the server
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2024-11-24 03:06:00 +00:00
|
|
|
private int ListAllFactions(ServerPlayerEntity player) {
|
2024-10-28 21:47:51 +00:00
|
|
|
int retValue = -1;
|
|
|
|
|
2024-11-24 03:06:00 +00:00
|
|
|
System.out.println("Listing factions");
|
|
|
|
List<String> 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!"));
|
|
|
|
}
|
|
|
|
|
2024-10-28 21:47:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|