2024-03-13 21:47:45 -04:00
|
|
|
package net.kelsoncraft.test;
|
|
|
|
|
|
|
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
2024-03-17 04:08:55 -04:00
|
|
|
import net.kelsoncraft.test.util.Messages;
|
2024-03-19 06:07:17 -04:00
|
|
|
import net.minecraft.block.PlayerSkullBlock;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerInventory;
|
|
|
|
import net.minecraft.inventory.CraftingInventory;
|
|
|
|
import net.minecraft.network.message.MessageType;
|
|
|
|
import net.minecraft.network.message.SentMessage;
|
2024-03-14 05:48:14 -04:00
|
|
|
import net.minecraft.server.command.CommandManager;
|
|
|
|
import net.minecraft.server.command.ServerCommandSource;
|
2024-03-19 06:07:17 -04:00
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
2024-03-13 21:47:45 -04:00
|
|
|
import net.minecraft.text.Text;
|
|
|
|
|
2024-03-14 05:48:14 -04:00
|
|
|
// https://www.reddit.com/r/fabricmc/comments/r3bd47/fabric_execute_commands/
|
|
|
|
|
2024-03-17 04:08:55 -04:00
|
|
|
public class TestCommands {
|
2024-03-14 05:48:14 -04:00
|
|
|
// This idea came from here:
|
|
|
|
// https://github.com/Draylar/get-off-my-lawn/blob/1.17/src/main/java/draylar/goml/command/ClaimCommand.java#L32-L98
|
|
|
|
|
2024-03-17 04:08:55 -04:00
|
|
|
public TestCommands() {
|
2024-03-14 05:48:14 -04:00
|
|
|
|
|
|
|
}
|
2024-03-19 06:07:17 -04:00
|
|
|
|
|
|
|
// I'm not sure how to use this.
|
|
|
|
// private String getPlayer() {
|
|
|
|
//
|
|
|
|
// PlayerEntity playerEntity = new PlayerEntity() {
|
|
|
|
// @Override
|
|
|
|
// public boolean isSpectator() {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public boolean isCreative() {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return "";
|
|
|
|
// }
|
|
|
|
|
|
|
|
// This may crash the server.
|
|
|
|
// PlayerEntity player;
|
|
|
|
// This might be fun.
|
|
|
|
// PlayerSkullBlock playerSkullBlock = new PlayerSkullBlock();
|
|
|
|
// PlayerInventory playerInventory = new PlayerInventory(player);
|
|
|
|
// CraftingInventory craftingInventory = new CraftingInventory();
|
|
|
|
|
2024-03-14 05:48:14 -04:00
|
|
|
// This works like this, now I know how to add commands to other classes, add them like this then initialize them in the main class.
|
|
|
|
public static void init() {
|
|
|
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(CommandManager.literal("teleport")
|
|
|
|
.executes(context -> {
|
|
|
|
context.getSource().sendFeedback(() -> Text.literal("Teleport to %s"), false);
|
|
|
|
return 1;
|
|
|
|
})));
|
2024-03-17 04:08:55 -04:00
|
|
|
|
|
|
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(CommandManager.literal("lightning")
|
|
|
|
.executes(context -> {
|
|
|
|
ServerCommandSource serverCommandSource = context.getSource();
|
|
|
|
// String playerName = serverCommandSource.getDisplayName().toString();
|
|
|
|
String playerName = serverCommandSource.getName();
|
|
|
|
String lightningMsg = String.format(Messages.Kbp_Fabric() + "Strike lightning at your location %s.", playerName);
|
|
|
|
|
|
|
|
context.getSource().sendFeedback(() -> Text.literal(lightningMsg), false);
|
|
|
|
return 1;
|
|
|
|
})));
|
2024-03-19 06:07:17 -04:00
|
|
|
|
|
|
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(CommandManager.literal("test1")
|
|
|
|
.executes(context -> {
|
|
|
|
// // I don't know how to send a chat message with the below code. I need a message params
|
|
|
|
// SentMessage sentMessage = new SentMessage() {
|
|
|
|
// @Override
|
|
|
|
// public Text getContent() {
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public void send(ServerPlayerEntity sender, boolean filterMaskEnabled, MessageType.Parameters params) {
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// context.getSource().sendChatMessage(sentMessage, false, );
|
|
|
|
|
|
|
|
|
|
|
|
context.getSource().sendFeedback(() -> Text.literal("You will be exterminated!"), false);
|
|
|
|
return 1;
|
|
|
|
})));
|
|
|
|
|
|
|
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(CommandManager.literal("craft")
|
|
|
|
.executes(context -> {
|
|
|
|
// // I don't know how to send a chat message with the below code. I need a message params
|
|
|
|
// SentMessage sentMessage = new SentMessage() {
|
|
|
|
// @Override
|
|
|
|
// public Text getContent() {
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public void send(ServerPlayerEntity sender, boolean filterMaskEnabled, MessageType.Parameters params) {
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// context.getSource().sendChatMessage(sentMessage, false, );
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
})));
|
|
|
|
|
|
|
|
|
2024-03-14 05:48:14 -04:00
|
|
|
}
|
2024-03-13 21:47:45 -04:00
|
|
|
}
|
2024-03-14 05:48:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|