2025-01-29 13:20:04 -05:00
|
|
|
package kamkeel.npcs.command;
|
2024-01-20 12:22:05 +03:00
|
|
|
|
|
|
|
|
import net.minecraft.command.CommandException;
|
|
|
|
|
import net.minecraft.command.ICommandSender;
|
|
|
|
|
import net.minecraft.util.ChunkCoordinates;
|
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
import noppes.npcs.EventHooks;
|
|
|
|
|
import noppes.npcs.api.IPos;
|
|
|
|
|
import noppes.npcs.api.IWorld;
|
|
|
|
|
import noppes.npcs.scripted.NpcAPI;
|
|
|
|
|
import noppes.npcs.scripted.event.CustomNPCsEvent;
|
|
|
|
|
|
2025-02-18 16:11:58 -05:00
|
|
|
import static kamkeel.npcs.util.ColorUtil.sendError;
|
|
|
|
|
import static kamkeel.npcs.util.ColorUtil.sendMessage;
|
|
|
|
|
|
2024-01-20 12:22:05 +03:00
|
|
|
public class CommandCommand extends CommandKamkeelBase {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getCommandName() {
|
|
|
|
|
return "command";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getDescription() {
|
2024-01-22 23:05:12 +03:00
|
|
|
return "command CommandName [arg1 arg2 ... argn]";
|
2024-01-20 12:22:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
|
|
|
|
if (args.length < 1) {
|
2024-01-22 23:05:12 +03:00
|
|
|
sendError(sender, "You must specify the command name");
|
2024-01-20 12:22:05 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-22 23:05:12 +03:00
|
|
|
String commandId = args[0];
|
2024-01-20 12:22:05 +03:00
|
|
|
String[] commandArgs = new String[args.length - 1];
|
|
|
|
|
System.arraycopy(args, 1, commandArgs, 0, args.length - 1);
|
|
|
|
|
|
|
|
|
|
IWorld senderWorld = NpcAPI.Instance().getIWorld(sender.getEntityWorld());
|
|
|
|
|
|
|
|
|
|
ChunkCoordinates senderCoords = sender.getPlayerCoordinates();
|
|
|
|
|
IPos senderPos = NpcAPI.Instance().getIPos(new BlockPos(senderCoords.posX, senderCoords.posY, senderCoords.posZ));
|
|
|
|
|
|
|
|
|
|
CustomNPCsEvent.ScriptedCommandEvent event = new CustomNPCsEvent.ScriptedCommandEvent(senderWorld, senderPos, sender.getCommandSenderName(), commandId, commandArgs);
|
|
|
|
|
EventHooks.onScriptedCommand(event);
|
|
|
|
|
|
|
|
|
|
if (!event.replyMessage.isEmpty()) {
|
|
|
|
|
sendMessage(sender, event.replyMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|