Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // IN MAIN FILE
- const ScriptableObject_ = org.mozilla.javascript.ScriptableObject;
- var ScriptManager_ = com.mcbox.pesdk.mcpelauncher.ScriptManager;
- var ScriptManager__ = net.zhuoweizhang.mcpelauncher.ScriptManager;
- var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
- var addons = [];
- var Launcher = {
- isBlockLauncher: function() {
- return (ctx.getPackageName() == "net.zhuoweizhang.mcpelauncher" || ctx.getPackageName() == "net.zhuoweizhang.mcpelauncher.pro");
- },
- isToolbox: function() {
- return ctx.getPackageName() == "io.mrarm.mctoolbox";
- },
- isMcpeMaster: function() {
- return ctx.getPackageName() == "com.mcbox.pesdkb.mcpelauncher";
- }
- };
- var mainScriptName = "IceAttack"; //example
- (function loadAddons() {
- if(Launcher.isBlockLauncher() || Launcher.isToolbox()) {
- ScriptManager__.callScriptMethod("addonLoadHook", [mainScriptName]);
- }
- if(Launcher.isMcpeMaster()) {
- ScriptManager_.callScriptMethod("addonLoadHook", [mainScriptName]);
- }
- })();
- function registerAddon(name, desc, current_version, target_version, author) {
- var shouldMessage = true;
- try {
- let scripts;
- if(Launcher.isBlockLauncher() || Launcher.isToolbox()) {
- scripts = ScriptManager__.scripts;
- } else {
- scripts = ScriptManager_.scripts;
- }
- let scriptName;
- for(var i = 0; i < scripts.size(); i++) {
- var script = scripts.get(i);
- var scope = script.scope;
- if(ScriptableObject_.hasProperty(scope, "ADDON_NAME") && ScriptableObject_.hasProperty(scope, "ADDON_VERSION")) {
- if(ScriptableObject_.getProperty(scope, "ADDON_NAME") == name && ScriptableObject_.getProperty(scope, "ADDON_VERSION") == current_version) {
- scriptName = script.name;
- break;
- }
- }
- }
- addons.push({
- name: name,
- desc: desc,
- author: author==null?"Unknown":author,
- current_version: current_version,
- target_version: target_version,
- scriptName: scriptName
- });
- } catch(e) {
- shouldMessage = false;
- print("[" + mainScriptName + "] An error occurred while loading addons: " + e);
- }
- if(shouldMessage) {
- print("[" + mainScriptName + "] Successfully loaded the addon with name " + name + "!");
- }
- }
- /*
- Afterwards, the main script will have all the loaded addons stored in the addons array,
- which makes it possible to use a for loop on it. For example you can do addons[i].name
- which returns the name of the addon at index i in the addons array.
- */
- // IN ADDON FILE
- const ADDON_NAME = "BestAddon for IceAttack!";
- const ADDON_DESC = "It's just the best.";
- const ADDON_AUTHOR = "Smasher & peacestorm ;)."; //<< examples
- const ADDON_VERSION = "1.0"
- const TARGET_VERSION = "1.0"; //this means the addon is compatible with version 1.0 of the main script
- var ScriptManager_ = com.mcbox.pesdk.mcpelauncher.ScriptManager;
- var ScriptManager__ = net.zhuoweizhang.mcpelauncher.ScriptManager;
- var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
- var Launcher = {
- isBlockLauncher: function() {
- return (ctx.getPackageName() == "net.zhuoweizhang.mcpelauncher" || ctx.getPackageName() == "net.zhuoweizhang.mcpelauncher.pro");
- },
- isToolbox: function() {
- return ctx.getPackageName() == "io.mrarm.mctoolbox";
- },
- isMcpeMaster: function() {
- return ctx.getPackageName() == "com.mcbox.pesdkb.mcpelauncher";
- }
- };
- function addonLoadHook(mainScriptName) {
- if(mainScriptName == "IceAttack") { //insert main script name
- if(Launcher.isBlockLauncher() || Launcher.isToolbox()) {
- net.zhuoweizhang.mcpelauncher.ScriptManager.callScriptMethod("registerAddon", [ADDON_NAME, ADDON_DESC, ADDON_VERSION, TARGET_VERSION, ADDON_AUTHOR]);
- }
- if(Launcher.isMcpeMaster()) {
- com.mcbox.pesdk.mcpelauncher.ScriptManager.callScriptMethod("registerAddon", [ADDON_NAME, ADDON_DESC, ADDON_VERSION, TARGET_VERSION, ADDON_AUTHOR]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement