-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
5 changed files
with
106 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changelog | ||
|
||
## 0.1 | ||
- Added `/gm <gamemode>` for changing gamemode. | ||
- Added `/gm{0|s|survival}` for changing gamemode to Survival. | ||
- Added `/gm{1|c|creative}` for changing gamemode to Creative. | ||
- Added `/gm{2|a|adventure}` for changing gamemode to Adventure. | ||
- Added `/gm{3|sp|spectator}` for changing gamemode to Spectator. |
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
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
# More Commands Mod | ||
|
||
Adds various useful commands to the game. | ||
|
||
## Commands | ||
- `/gm <gamemode>`: Change gamemode. | ||
- `/gms` & `/gm0`: Change gamemode to Survival. | ||
- `/gmc` & `/gm1`: Change gamemode to Creative. | ||
- `/gma` & `/gm2`: Change gamemode to Adventure. | ||
- `/gmsp` & `/gm3`: Change gamemode to Spectator. |
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
package com.nixinova.morecmds; | ||
|
||
import com.nixinova.morecmds.commands.Gamemode; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
|
||
public class Main implements ModInitializer { | ||
|
||
@Override | ||
public void onInitialize() { | ||
System.out.println("Initialised"); | ||
new Gamemode().register(); | ||
} | ||
|
||
public static void debug(String msg) { | ||
System.out.println("MoreCMDs> " + msg); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/com/nixinova/morecmds/commands/Gamemode.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 @@ | ||
package com.nixinova.morecmds.commands; | ||
|
||
import static net.minecraft.server.command.CommandManager.argument; | ||
import static net.minecraft.server.command.CommandManager.literal; | ||
import static com.mojang.brigadier.arguments.StringArgumentType.string; | ||
|
||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import com.nixinova.morecmds.Main; | ||
|
||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import net.minecraft.world.GameMode; | ||
|
||
public class Gamemode { | ||
|
||
public void register() { | ||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> { | ||
// Generic | ||
dispatcher.register(literal("gm").then( | ||
argument("mode", string()).executes(this::generic) | ||
)); | ||
// Survival | ||
dispatcher.register(literal("gms").executes(this::survival)); | ||
dispatcher.register(literal("gm0").executes(this::survival)); | ||
// Creative | ||
dispatcher.register(literal("gmc").executes(this::creative)); | ||
dispatcher.register(literal("gm1").executes(this::creative)); | ||
// Adventure | ||
dispatcher.register(literal("gma").executes(this::adventure)); | ||
dispatcher.register(literal("gm2").executes(this::adventure)); | ||
// Spectator | ||
dispatcher.register(literal("gmsp").executes(this::spectator)); | ||
dispatcher.register(literal("gm3").executes(this::spectator)); | ||
}); | ||
} | ||
|
||
private int generic(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { | ||
Main.debug("Command 'gm' activated"); | ||
String input = StringArgumentType.getString(context, "mode"); | ||
GameMode mode = null; | ||
switch (input.toLowerCase()) { | ||
case "survival": case "s": case "0": mode = GameMode.SURVIVAL; break; | ||
case "creative": case "c": case "1": mode = GameMode.CREATIVE; break; | ||
case "adventure": case "a": case "2": mode = GameMode.ADVENTURE; break; | ||
case "spectator": case "sp": case "3": mode = GameMode.SPECTATOR; break; | ||
} | ||
if (mode == null) return -1; | ||
context.getSource().getPlayer().setGameMode(mode); | ||
return 1; | ||
} | ||
|
||
private int survival(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { | ||
Main.debug("Command 'gms' activated"); | ||
context.getSource().getPlayer().setGameMode(GameMode.SURVIVAL); | ||
return 1; | ||
} | ||
|
||
private int creative(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { | ||
Main.debug("Command 'gmc' activated"); | ||
context.getSource().getPlayer().setGameMode(GameMode.CREATIVE); | ||
return 1; | ||
} | ||
|
||
private int adventure(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { | ||
Main.debug("Command 'gma' activated"); | ||
context.getSource().getPlayer().setGameMode(GameMode.ADVENTURE); | ||
return 1; | ||
} | ||
|
||
private int spectator(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { | ||
Main.debug("Command 'gmsp' activated"); | ||
context.getSource().getPlayer().setGameMode(GameMode.SPECTATOR); | ||
return 1; | ||
} | ||
|
||
} |