Tested and working commands for mod. Setup future structure of mod
This commit is contained in:
parent
83d144c759
commit
b8bcee9d7b
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* CommandManager
|
||||||
|
*
|
||||||
|
* This class maintains all custom commands and executions throughout the mod
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package jesse.keeblarcraft.Commands;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
|
import net.minecraft.server.command.CommandManager;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import jesse.keeblarcraft.Commands.ShortcutCommands;
|
||||||
|
|
||||||
|
public class CustomCommandManager {
|
||||||
|
// Intentionally empty constructor since at object definition time it may not be possible to register commands
|
||||||
|
public CustomCommandManager() {}
|
||||||
|
|
||||||
|
// Registers all commands for the mod
|
||||||
|
public void RegisterCustomCommands() {
|
||||||
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||||
|
dispatcher.register(CommandManager.literal("amogus").executes(ctx -> {
|
||||||
|
ctx.getSource().sendFeedback(() -> Text.literal("AMOGOOOOOO"), false);
|
||||||
|
return 0;
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||||
|
dispatcher.register(CommandManager.literal("cbtest").executes(ctx -> {
|
||||||
|
ctx.getSource().sendFeedback(() -> TestCallback(ctx.getSource()), false);
|
||||||
|
return 0;
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
// CUSTOM COMMAND CLASS OBJECTS BELOW
|
||||||
|
ShortcutCommands shortcuts = new ShortcutCommands();
|
||||||
|
|
||||||
|
// REGISTER COMMANDS BELOW
|
||||||
|
System.out.println("REGISTERING CUSTOM COMMAND EXTENSIONS BELOW");
|
||||||
|
shortcuts.RegisterShortcutCommands();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Text TestCallback(ServerCommandSource ctx) {
|
||||||
|
String stuff = ctx.getName();
|
||||||
|
return Text.literal("Callback called from " + stuff);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* ShortcutCommands
|
||||||
|
*
|
||||||
|
* A class that simplifies some of the current vanilla commands with shortcut commands in the game
|
||||||
|
*/
|
||||||
|
|
||||||
|
package jesse.keeblarcraft.Commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
|
||||||
|
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 ShortcutCommands {
|
||||||
|
public void RegisterShortcutCommands()
|
||||||
|
{
|
||||||
|
// Abstract handling "value" to parse gamemodes 0-2 (survival; creative; spectator)
|
||||||
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||||
|
dispatcher.register(CommandManager.literal("gm")
|
||||||
|
.then(CommandManager.argument("value", IntegerArgumentType.integer())
|
||||||
|
.executes(context -> CreativeShortcut(IntegerArgumentType.getInteger(context, "value"), context))));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Command handlers below
|
||||||
|
|
||||||
|
private int CreativeShortcut(int value, CommandContext<ServerCommandSource> context)
|
||||||
|
{
|
||||||
|
int retValue = -1;
|
||||||
|
context.getSource().sendMessage(Text.literal("You sent value: " + value));
|
||||||
|
|
||||||
|
if (context.getSource().isExecutedByPlayer()) {
|
||||||
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||||
|
|
||||||
|
/// todo: change 4 to be OPERATOR level. 4 is DEFAULT operator level in Minecraft
|
||||||
|
if(player.hasPermissionLevel(4)) {
|
||||||
|
switch(value) {
|
||||||
|
case 0:
|
||||||
|
/// TODO: Add type checking & permission
|
||||||
|
player.changeGameMode(net.minecraft.world.GameMode.SURVIVAL);
|
||||||
|
player.sendMessage(Text.literal("Changing your game mode to SURVIVAL"));
|
||||||
|
retValue = 0;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
player.changeGameMode(net.minecraft.world.GameMode.CREATIVE);
|
||||||
|
player.sendMessage(Text.literal("Changing your game mode to CREATIVE"));
|
||||||
|
retValue = 0;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
player.changeGameMode(net.minecraft.world.GameMode.SPECTATOR);
|
||||||
|
player.sendMessage(Text.literal("Changing your game mode to SPECTATOR"));
|
||||||
|
retValue = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
player.sendMessage(Text.literal("Valid entries are 0=SURVIVAL, 1=CREATIVE, 2=SPECTATOR"));
|
||||||
|
retValue = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
player.sendMessage(Text.literal("You do not have permissions to run this command!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("This command cannot be executed by a non-player entity!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return retValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* ConfigManager
|
||||||
|
*
|
||||||
|
* This class is the central configuration file manager for all other classes and acts as a utility class for other classes to use.
|
||||||
|
* It is typical to define this class as a general object (not static instance) for each class in single-threaded actions. If you need
|
||||||
|
* a special function or action from this class; it is recommended to add it to this class and not make your own.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package jesse.keeblarcraft.ConfigMgr;
|
||||||
|
|
||||||
|
public class ConfigManager {
|
||||||
|
|
||||||
|
}
|
15
src/main/java/jesse/keeblarcraft/EventMgr/EventManager.java
Normal file
15
src/main/java/jesse/keeblarcraft/EventMgr/EventManager.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* EventManager
|
||||||
|
*
|
||||||
|
* This class is responsible for handling the setup and execution of events within the game for the mod. These events can be configured as plugins in this
|
||||||
|
* directory which are executed in an abstract fashion with handling. If you need a new event (for a story item, or handling a player event, etc) then it
|
||||||
|
* is preferred to add that as an extension class and called within this manager object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package jesse.keeblarcraft.EventMgr;
|
||||||
|
|
||||||
|
public class EventManager {
|
||||||
|
|
||||||
|
}
|
15
src/main/java/jesse/keeblarcraft/FactionMgr/TeamManager.java
Normal file
15
src/main/java/jesse/keeblarcraft/FactionMgr/TeamManager.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* TeamManager
|
||||||
|
*
|
||||||
|
* Class is responsible for keeping track of teams/factions chosen by the players in the game and saves to the configuration
|
||||||
|
* file for persistent data storage. Class handles checks as well for eligibility purposes (making sure players can join, etc)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package jesse.keeblarcraft.FactionMgr;
|
||||||
|
|
||||||
|
public class TeamManager {
|
||||||
|
// Class controls managing teams and pulling from configuration file and loading to configuration file
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,31 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Keeblarcraft
|
||||||
|
*
|
||||||
|
* This is the primary server side "main" object that is referenced by Fabric. This is where everything is setup for the mod
|
||||||
|
* and a very important class. Please becareful as you add to it
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package jesse.keeblarcraft;
|
package jesse.keeblarcraft;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
// import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jesse.keeblarcraft.Commands.CustomCommandManager;
|
||||||
|
|
||||||
|
// import com.mojang.brigadier.Command;
|
||||||
|
|
||||||
|
|
||||||
public class Keeblarcraft implements ModInitializer {
|
public class Keeblarcraft implements ModInitializer {
|
||||||
// This logger is used to write text to the console and the log file.
|
// This logger is used to write text to the console and the log file.
|
||||||
// It is considered best practice to use your mod id as the logger's name.
|
// It is considered best practice to use your mod id as the logger's name.
|
||||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger("keeblarcraft");
|
public static final Logger LOGGER = LoggerFactory.getLogger("keeblarcraft");
|
||||||
|
CustomCommandManager cmdMgr = new CustomCommandManager();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
@ -18,5 +34,12 @@ public class Keeblarcraft implements ModInitializer {
|
|||||||
// Proceed with mild caution.
|
// Proceed with mild caution.
|
||||||
|
|
||||||
LOGGER.info("Hello Fabric world!");
|
LOGGER.info("Hello Fabric world!");
|
||||||
|
cmdMgr.RegisterCustomCommands();
|
||||||
|
|
||||||
|
// I can't tell if this is required or not; and if it is I imagine it comes before I register the custom commands
|
||||||
|
// Command<ServerCommandSource> command = context -> {
|
||||||
|
// ServerCommandSource source = context.getSource();
|
||||||
|
// return 0;
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
}
|
}
|
17
src/main/java/jesse/keeblarcraft/StoryMgr/StoryMgr.java
Normal file
17
src/main/java/jesse/keeblarcraft/StoryMgr/StoryMgr.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Story Manager
|
||||||
|
*
|
||||||
|
* Class keeps track of the story/note-taking done by players and saves it automagically to the configuration file for note taking / story tracking for
|
||||||
|
* the server.
|
||||||
|
*
|
||||||
|
* In larger detail, this class will set a timeline for each player and where they are on the story. Depending on where they are in the story, certain
|
||||||
|
* milestones will be tagged to their account so they may access certain things that are unlockable achievements within this class
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package jesse.keeblarcraft.StoryMgr;
|
||||||
|
|
||||||
|
public class StoryMgr {
|
||||||
|
|
||||||
|
}
|
11
src/main/java/jesse/keeblarcraft/Utils/ChatUtil.java
Normal file
11
src/main/java/jesse/keeblarcraft/Utils/ChatUtil.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* ChatUtil
|
||||||
|
*
|
||||||
|
* Helpful utility for pretty printing in chat in the game with different supported functions and levels
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package jesse.keeblarcraft.Utils;
|
||||||
|
|
||||||
|
public class ChatUtil { }
|
Loading…
Reference in New Issue
Block a user