Search in sources :

Example 6 with Callback

use of li.cil.oc.api.machine.Callback in project RFTools by McJty.

the class ScreenControllerTileEntity method getScreenCoordinate.

@Callback(doc = "Given a screen index return the coordinate (table indexed by 'x', 'y', and 'z') of that screen", getter = true)
@Optional.Method(modid = "opencomputers")
public Object[] getScreenCoordinate(Context context, Arguments args) throws Exception {
    int index = args.checkInteger(0);
    if (index < 0 || index >= connectedScreens.size()) {
        throw new IllegalArgumentException("Screen index out of range!");
    }
    BlockPos screen = connectedScreens.get(index);
    Map<String, Integer> coordinate = new HashMap<>();
    coordinate.put("x", screen.getX());
    coordinate.put("y", screen.getY());
    coordinate.put("z", screen.getZ());
    return new Object[] { coordinate };
}
Also used : HashMap(java.util.HashMap) BlockPos(net.minecraft.util.math.BlockPos) Callback(li.cil.oc.api.machine.Callback)

Example 7 with Callback

use of li.cil.oc.api.machine.Callback in project OpenModularTurrets by OpenModularTurretsTeam.

the class ManagedEnvironmentTurretBase method addTrustedPlayer.

@SuppressWarnings("unused")
@Callback(doc = "function(name:String, [canOpenGUI:boolean, canChangeTargeting:boolean, admin:boolean]):string;" + " adds Trusted player to Trustlist. Can return error.")
public Object[] addTrustedPlayer(Context context, Arguments args) {
    if (!base.isComputerAccessible()) {
        return new Object[] { "Computer access deactivated!" };
    }
    if (!base.addTrustedPlayer(args.checkString(0))) {
        return new Object[] { "Name not valid!" };
    }
    TrustedPlayer trustedPlayer = base.getTrustedPlayer(args.checkString(0));
    trustedPlayer.canOpenGUI = args.optBoolean(1, false);
    trustedPlayer.canChangeTargeting = args.optBoolean(1, false);
    trustedPlayer.admin = args.optBoolean(1, false);
    trustedPlayer.uuid = getPlayerUUID(args.checkString(0));
    return null;
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) Callback(li.cil.oc.api.machine.Callback)

Example 8 with Callback

use of li.cil.oc.api.machine.Callback in project LogisticsPipes by RS485.

the class BaseWrapperClass method helpCommand.

@Callback(direct = true)
public Object[] helpCommand(Context context, Arguments args) throws Exception {
    if (object == null) {
        throw new Exception("This LP object is not persistable");
    }
    if (args.count() != 1) {
        return new Object[] { "Wrong Argument Count" };
    }
    if (!args.isInteger(0)) {
        return new Object[] { "Wrong Argument Type" };
    }
    Integer number = args.checkInteger(0);
    if (!info.commands.containsKey(number)) {
        return new Object[] { "No command with that index" };
    }
    Method method = info.commands.get(number);
    StringBuilder help = new StringBuilder();
    help.append("---------------------------------\n");
    help.append("Command: ");
    help.append(method.getName());
    help.append("\n");
    help.append("Parameter: ");
    if (method.getParameterTypes().length > 0) {
        help.append("\n");
        boolean a = false;
        for (Class<?> clazz : method.getParameterTypes()) {
            if (a) {
                help.append(", ");
            }
            help.append(clazz.getSimpleName());
            a = true;
        }
        help.append("\n");
    } else {
        help.append("NONE\n");
    }
    help.append("Return Type: ");
    help.append(method.getReturnType().getName());
    help.append("\n");
    help.append("Description: \n");
    help.append(method.getAnnotation(CCCommand.class).description());
    return new Object[] { help.toString() };
}
Also used : Method(java.lang.reflect.Method) PermissionException(logisticspipes.security.PermissionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Callback(li.cil.oc.api.machine.Callback)

Example 9 with Callback

use of li.cil.oc.api.machine.Callback in project LogisticsPipes by RS485.

the class BaseWrapperClass method help.

@Callback(direct = true)
public Object[] help(Context context, Arguments args) throws Exception {
    if (object == null) {
        throw new Exception("This LP object is not persistable");
    }
    StringBuilder help = new StringBuilder();
    StringBuilder head = new StringBuilder();
    StringBuilder head2 = new StringBuilder();
    head.append("Type: ");
    head.append(info.type);
    head.append("\n");
    head2.append("Commands: \n");
    for (Integer num : info.commands.keySet()) {
        Method method = info.commands.get(num);
        StringBuilder command = new StringBuilder();
        if (help.length() != 0) {
            command.append("\n");
        }
        int number = num.intValue();
        if (number < 10) {
            command.append(" ");
        }
        command.append(number);
        command.append(" ");
        if (method.isAnnotationPresent(CCDirectCall.class)) {
            command.append("D");
        } else {
            command.append(" ");
        }
        if (method.isAnnotationPresent(CCQueued.class)) {
            command.append("Q");
        } else {
            command.append(" ");
        }
        command.append(": ");
        command.append(method.getName());
        StringBuilder param = new StringBuilder();
        param.append("(");
        boolean a = false;
        for (Class<?> clazz : method.getParameterTypes()) {
            if (a) {
                param.append(", ");
            }
            param.append(clazz.getSimpleName());
            a = true;
        }
        param.append(")");
        if (param.toString().length() + command.length() > 50) {
            command.append("\n      ---");
        }
        command.append(param.toString());
        help.append(command.toString());
    }
    String commands = help.toString();
    String[] lines = commands.split("\n");
    if (lines.length > 16) {
        int pageNumber = 1;
        if (args.count() > 0) {
            if (args.isDouble(0) || args.isInteger(0)) {
                pageNumber = args.checkInteger(0);
                if (pageNumber < 1) {
                    pageNumber = 1;
                }
            }
        }
        StringBuilder page = new StringBuilder();
        page.append(head.toString());
        page.append("Page ");
        page.append(pageNumber);
        page.append(" of ");
        page.append((int) (Math.floor(lines.length / 10) + (lines.length % 10 == 0 ? 0 : 1)));
        page.append("\n");
        page.append(head2.toString());
        pageNumber--;
        int from = pageNumber * 11;
        int to = pageNumber * 11 + 11;
        for (int i = from; i < to; i++) {
            if (i < lines.length) {
                page.append(lines[i]);
            }
            if (i < to - 1) {
                page.append("\n");
            }
        }
        return new Object[] { page.toString() };
    } else {
        for (int i = 0; i < 16 - lines.length; i++) {
            String buffer = head.toString();
            head = new StringBuilder();
            head.append("\n").append(buffer);
        }
    }
    return new Object[] { String.format("%s%s%s", head, head2, help) };
}
Also used : Method(java.lang.reflect.Method) PermissionException(logisticspipes.security.PermissionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Callback(li.cil.oc.api.machine.Callback)

Aggregations

Callback (li.cil.oc.api.machine.Callback)9 BlockPos (net.minecraft.util.math.BlockPos)4 HashMap (java.util.HashMap)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 PermissionException (logisticspipes.security.PermissionException)2 TrustedPlayer (omtteam.omlib.util.TrustedPlayer)2 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 IDataStorage (pl.asie.charset.api.tape.IDataStorage)1