mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 21:54:08 +00:00
Created a subcommand triggering scripted command event
This commit is contained in:
1 parent
1421f9e819
commit
e6c86a61db
2 files changed
+57
No files matched your search
@@ -0,0 +1,56 @@
|
||||
package kamkeel.command;
|
||||
|
||||
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;
|
||||
|
||||
public class CommandCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "command CommandID [arg1 arg2 ... argn]";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 1) {
|
||||
sendError(sender, "You must specify the command id");
|
||||
return;
|
||||
}
|
||||
|
||||
int commandId;
|
||||
try {
|
||||
commandId = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "CommandID must be an integer: " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user