mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 21:20:04 +00:00
Implemented custom commands.
This commit is contained in:
1 parent
a47af08d0f
commit
3d498814f9
3 files changed
+91
-1
No files matched your search
@@ -0,0 +1,80 @@
|
||||
package foxz.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.api.ICommand;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptedCommand extends CommandBase implements ICommand {
|
||||
private String commandName;
|
||||
private int permissionLevel;
|
||||
private String commandUsage;
|
||||
private ArrayList<String> aliases;
|
||||
|
||||
public ScriptedCommand(String commandName, int permissionLevel) {
|
||||
this.commandName = commandName;
|
||||
this.permissionLevel = permissionLevel;
|
||||
this.commandUsage = "";
|
||||
this.aliases = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setCommandName(String commandName) {
|
||||
this.commandName = commandName;
|
||||
}
|
||||
|
||||
public void setCommandUsage(String commandUsage) {
|
||||
this.commandUsage = commandUsage;
|
||||
}
|
||||
|
||||
public void setPermissionLevel(int permissionLevel) {
|
||||
this.permissionLevel = permissionLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return this.commandName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender p_71518_1_) {
|
||||
return this.commandUsage;
|
||||
}
|
||||
|
||||
public String getCommandUsage() {
|
||||
return this.commandUsage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) {
|
||||
}
|
||||
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return this.permissionLevel;
|
||||
}
|
||||
|
||||
public int getPermissionLevel() { return this.getRequiredPermissionLevel(); }
|
||||
|
||||
public List<?> getCommandAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
public String[] getAliases() {
|
||||
return this.aliases.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public void addAliases(String... aliases) {
|
||||
this.aliases.addAll(Arrays.asList(aliases));
|
||||
}
|
||||
|
||||
public boolean hasAlias(String alias) {
|
||||
return this.aliases.contains(alias);
|
||||
}
|
||||
|
||||
public void removeAlias(String alias) {
|
||||
this.aliases.remove(alias);
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,10 @@
|
||||
package noppes.npcs.scripted;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
import foxz.command.ScriptedCommand;
|
||||
import jdk.nashorn.internal.ir.debug.ObjectSizeCalculator;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.command.CommandHandler;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -69,6 +71,14 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
worldCache.clear();
|
||||
}
|
||||
|
||||
public void registerICommand(ICommand command) {
|
||||
((CommandHandler)CustomNpcs.getServer().getCommandManager()).registerCommand((ScriptedCommand) command);
|
||||
}
|
||||
|
||||
public ICommand getICommand(String commandName, int priorityLevel) {
|
||||
return new ScriptedCommand(commandName,priorityLevel);
|
||||
}
|
||||
|
||||
public void addGlobalObject(String key, Object obj) {
|
||||
NpcAPI.engineObjects.put(key,obj);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user