org.mozilla.javascript.annotations.JSStaticFunction Java Examples
The following examples show how to use
org.mozilla.javascript.annotations.JSStaticFunction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 6 votes |
@JSStaticFunction public static void setTarget(Object entity, Object target) { long entityId = getEntityId(entity); int typeId = nativeGetEntityTypeId(entityId); if (!(typeId > 0 && typeId < 64)) { throw new RuntimeException("setTarget only works on mob entities"); } long targetId = target == null? -1: getEntityId(target); if (targetId != -1) { int targetTypeId = nativeGetEntityTypeId(targetId); if (!(targetTypeId > 0 && targetTypeId < 64)) { throw new RuntimeException("setTarget only works on mob targets"); } } nativeEntitySetTarget(entityId, targetId); }
Example #2
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 6 votes |
@JSStaticFunction public static void setSignText(int x, int y, int z, int line, String newText) { if (line < 0 || line >= 4) throw new RuntimeException("Invalid line for sign: must be in the range of 0 to 3"); String text = nativeGetSignText(x, y, z); String newTextJoined = null; if (text == null) { StringBuilder out = new StringBuilder(); for (int i = 0; i < line; i++) { out.append("\n"); } newTextJoined = out.append(newText).toString(); } else { String[] outArr = text.split("\n"); if (line >= outArr.length) { String[] newArr = new String[line + 1]; for (int i = 0; i < outArr.length; i++) { newArr[i] = outArr[i]; } outArr = newArr; } outArr[line] = newText; newTextJoined = Utils.joinArray(outArr, "\n"); } nativeSetSignText(x, y, z, newTextJoined); }
Example #3
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static long spawnChicken(double x, double y, double z, String tex) { if (invalidTexName(tex)) { tex = null; } long entityId = spawnEntityImpl((float) x, (float) y, (float) z, 10, tex); return entityId; }
Example #4
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
private static void appendApiMethods(StringBuilder builder, Class<?> clazz, String namespace) { for (Method met : clazz.getMethods()) { if (met.getAnnotation(JSFunction.class) != null || met.getAnnotation(JSStaticFunction.class) != null) { appendApiMethodDescription(builder, met, namespace); } } builder.append("\n"); }
Example #5
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static void setFoodItem(int id, String iconName, int iconSubindex, int halfhearts, String name, int maxStackSize) { setItem(id, iconName, iconSubindex, name, maxStackSize); NativeItemApi.setProperties(id, "{\"use_animation\":\"eat\",\"use_duration\": 32," + "\"food\":{\"nutrition\":" + halfhearts + ",\"saturation_modifier\": \"normal\"," + "\"is_meat\": false}}"); }
Example #6
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static void setSpawnerEntityType(int x, int y, int z, int type) { if (getTile(x, y, z) != 52) { throw new RuntimeException("Block at " + x + ":" + y + ":" + z + " is not a mob spawner!"); } nativeSpawnerSetEntityType(x, y, z, type); }
Example #7
Source File: JSUtil.java From KakaoBot with GNU General Public License v3.0 | 5 votes |
@JSStaticFunction public static ScriptableObject readData(String key) { JSScriptEngine engine = KakaoTalkListener.getJsEngines()[0]; SharedPreferences preference = context.getSharedPreferences("script_data", Context.MODE_PRIVATE); return (ScriptableObject) engine.getContext().javaToJS(preference.getString(key, ""), engine.getScope()); }
Example #8
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static String getMinecraftVersion() { try { return androidContext.getPackageManager(). getPackageInfo("com.mojang.minecraftpe", 0). versionName; } catch (Exception e) { e.printStackTrace(); return "Unknown"; } }
Example #9
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static void saveData(String prefName, String prefValue) { SharedPreferences sPrefs = androidContext.getSharedPreferences( "BlockLauncherModPEScript" + currentScript, 0); SharedPreferences.Editor prefsEditor = sPrefs.edit(); prefsEditor.putString(prefName, prefValue); prefsEditor.commit(); }
Example #10
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static void defineThrowable(int id, String iconName, int iconSubindex, String name, int maxStackSize) { if (id <= 0 || id >= ITEM_ID_COUNT) { throw new IllegalArgumentException("Item IDs must be > 0 and < ITEM_ID_COUNT"); } if (itemsMeta != null && !itemsMeta.hasIcon(iconName, iconSubindex)) { throw new MissingTextureException("The item icon " + iconName + ":" + iconSubindex + " does not exist"); } nativeDefineSnowballItem(id, iconName, iconSubindex, name, maxStackSize); int renderer = RendererManager.nativeCreateItemSpriteRenderer(id); itemIdToRendererId.put(renderer, id); rendererToItemId.put(id, renderer); }
Example #11
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static String executeCommand(final String command, final boolean silent) { // fixme 1.2 runOnMainThread(new Runnable() { public void run() { nativeLevelExecuteCommand(command, silent); } }); /* String result = nativeLevelExecuteCommand(command, silent); if ("<no result>".equals(result)) return ""; return result; */ return ""; }
Example #12
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static int getItemEntityData(Object entity) { long entityId = getEntityId(entity); int typeId = nativeGetEntityTypeId(entityId); if (typeId != EntityType.ITEM) { throw new RuntimeException("getItemEntity only works on item entities"); } return nativeGetItemEntityItem(entityId, DAMAGE); }
Example #13
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static String getName(int id, int damage, boolean raw) { if (!nativeIsValidItem(id)) { throw new RuntimeException("getName called with invalid item ID: " + id); } if (id == 358) return "Map"; // Maps need an NBT, otherwise crash return nativeGetItemName(id, damage, raw); }
Example #14
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static void addCraftRecipe(int id, int count, int damage, Scriptable ingredientsScriptable) { int[] expanded = expandShapelessRecipe(ingredientsScriptable); if (!nativeIsValidItem(id)) { throw new RuntimeException("Invalid input in shapeless recipe: " + id + " is not a valid item. " + "You must create the item before you can add it to a recipe."); } for (int i = 0; i < expanded.length; i += 3) { if (!nativeIsValidItem(expanded[i])) { throw new RuntimeException("Invalid output in shapeless recipe: " + expanded[i] + " is not a valid item. You must create the item before you can add it to a" + " recipe."); } } for (Object[] r: activeShapelessRecipes) { if ( ((Integer) r[0]) == id && ((Integer) r[1]) == count && ((Integer) r[2]) == damage && Arrays.equals((int[]) r[3], expanded) ) { System.out.println("Recipe already exists."); return; } } activeShapelessRecipes.add(new Object[]{id, count, damage, expanded}); nativeAddShapelessRecipe(id, count, damage, expanded); }
Example #15
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static int[] getTextureCoords(int id, int damage, int side) { float[] retval = new float[6]; boolean success = nativeGetTextureCoordinatesForBlock(id, damage, side, retval); if (!success) throw new RuntimeException("Can't get texture for block " + id + ":" + damage); int[] newretval = new int[] {(int) (retval[0] * retval[4] + 0.5), (int) (retval[1] * retval[5] + 0.5), (int) (retval[2] * retval[4] + 0.5), (int) (retval[3] * retval[5] + 0.5), (int) (retval[4] + 0.5), (int) (retval[5] + 0.5)}; return newretval; }
Example #16
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static void setMaxHealth(Object ent, int halfhearts) { int entityType = getEntityTypeId(ent); if (!(entityType >= 10 && entityType < 64)) { throw new RuntimeException("setMaxHealth called on non-mob: entityType=" + entityType); } nativeSetMobMaxHealth(getEntityId(ent), halfhearts); }
Example #17
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static void removeData(String prefName) { SharedPreferences sPrefs = androidContext.getSharedPreferences( "BlockLauncherModPEScript" + currentScript, 0); SharedPreferences.Editor prefsEditor = sPrefs.edit(); prefsEditor.remove(prefName); prefsEditor.commit(); }
Example #18
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 5 votes |
@JSStaticFunction public static int getHealth(Object ent) { int entityType = getEntityTypeId(ent); if (!(entityType >= 10 && entityType < 64)) { return 0; // not a mob } return nativeGetMobHealth(getEntityId(ent)); }
Example #19
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static void setLightningLevel(double val) { nativeLevelSetLightningLevel((float) val); }
Example #20
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static void setEnchantType(int id, int flag, int value) { nativeSetAllowEnchantments(id, flag, value); }
Example #21
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static int getPointedBlockData() { return nativePlayerGetPointedBlock(0x10 + 1); }
Example #22
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static void rideAnimal(Object /* insert funny reference */rider, Object mount) { nativeRideAnimal(getEntityId(rider), getEntityId(mount)); }
Example #23
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static int getDifficulty() { return nativeLevelGetDifficulty(); }
Example #24
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static void setRainLevel(double val) { nativeLevelSetRainLevel((float) val); }
Example #25
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static void setBlockExtraData(int x, int y, int z, int data) { nativeLevelSetExtraData(x, y, z, data); }
Example #26
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static boolean isRemote() { return nativeLevelIsRemote(); }
Example #27
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static boolean isPlayer(Object ent) { return NativeEntityApi.getEntityTypeId(getEntityId(ent)) == EntityType.PLAYER; }
Example #28
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static String getI18n(String key) { return nativeGetI18NString(key); }
Example #29
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static boolean canSeeSky(int x, int y, int z) { return nativeLevelCanSeeSky(x, y, z); }
Example #30
Source File: ScriptManager.java From MCPELauncher with Apache License 2.0 | 4 votes |
@JSStaticFunction public static void setAllowOffhand(int id, boolean allowOffhand) { nativeItemSetAllowOffhand(id, allowOffhand); }