mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 08:49:41 +00:00
Merge pull request #114 from Goodbird-git/scripted-commands
Implemented scripted commands
This commit is contained in:
4 files changed
+111
No files matched your search
@@ -0,0 +1,50 @@
|
||||
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 CommandName [arg1 arg2 ... argn]";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 1) {
|
||||
sendError(sender, "You must specify the command name");
|
||||
return;
|
||||
}
|
||||
|
||||
String commandId = args[0];
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ public class CommandKamkeel extends CommandBase{
|
||||
registerCommand(new ConfigCommand());
|
||||
registerCommand(new AnimationCommand());
|
||||
registerCommand(new OverlayCommand());
|
||||
registerCommand(new CommandCommand());
|
||||
}
|
||||
|
||||
public void registerCommand(CommandKamkeelBase command){
|
||||
|
||||
@@ -569,6 +569,13 @@ public class EventHooks {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void onScriptedCommand(CustomNPCsEvent.ScriptedCommandEvent event) {
|
||||
ForgeDataScript handler = ScriptController.Instance.forgeScripts;
|
||||
if (handler.isEnabled()) {
|
||||
handler.callScript(EnumScriptType.SCRIPT_COMMAND, event);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onCustomGuiButton(IPlayer player, ICustomGui gui, int buttonId) {
|
||||
CustomGuiEvent.ButtonEvent event = new CustomGuiEvent.ButtonEvent(player, gui, buttonId);
|
||||
CustomGuiController.onButton(event);
|
||||
|
||||
@@ -9,6 +9,7 @@ import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import noppes.npcs.api.AbstractNpcAPI;
|
||||
import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.event.ICustomNPCsEvent;
|
||||
import noppes.npcs.api.handler.data.INaturalSpawn;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
@@ -80,4 +81,56 @@ public class CustomNPCsEvent extends Event implements ICustomNPCsEvent {
|
||||
return this.airSpawnPassed;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ScriptedCommandEvent extends CustomNPCsEvent implements ICustomNPCsEvent.ScriptedCommandEvent {
|
||||
|
||||
public IWorld world;
|
||||
public IPos pos;
|
||||
public String senderName;
|
||||
public String id;
|
||||
public String[] args;
|
||||
public String replyMessage = "";
|
||||
|
||||
public ScriptedCommandEvent(IWorld world, IPos pos, String senderName, String id, String[] args){
|
||||
this.world = world;
|
||||
this.pos = pos;
|
||||
this.senderName = senderName;
|
||||
this.id = id;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public String getHookName() {
|
||||
return EnumScriptType.SCRIPT_COMMAND.function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWorld getSenderWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPos getSenderPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSenderName() {
|
||||
return senderName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReplyMessage(String message) {
|
||||
replyMessage = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user