Added buscript Javascript library.

This commit is contained in:
Jeremy Wood 2012-07-25 22:09:28 -04:00
parent 6133cf6bdf
commit 24e26bb7d7
6 changed files with 111 additions and 0 deletions

14
pom.xml
View File

@ -152,6 +152,7 @@
<include>me.main__.util:SerializationConfig</include> <include>me.main__.util:SerializationConfig</include>
<include>com.fernferret.allpay:AllPay</include> <include>com.fernferret.allpay:AllPay</include>
<include>com.pneumaticraft.commandhandler:CommandHandler</include> <include>com.pneumaticraft.commandhandler:CommandHandler</include>
<include>com.dumptruckman.minecraft:buscript</include>
</includes> </includes>
</artifactSet> </artifactSet>
<relocations> <relocations>
@ -167,6 +168,10 @@
<pattern>com.pneumaticraft.commandhandler</pattern> <pattern>com.pneumaticraft.commandhandler</pattern>
<shadedPattern>com.pneumaticraft.commandhandler.multiverse</shadedPattern> <shadedPattern>com.pneumaticraft.commandhandler.multiverse</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>buscript</pattern>
<shadedPattern>buscript.multiverse</shadedPattern>
</relocation>
</relocations> </relocations>
</configuration> </configuration>
</execution> </execution>
@ -221,6 +226,15 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- End of CommandHandler Dependency --> <!-- End of CommandHandler Dependency -->
<!-- Start of Buscript Dependency -->
<dependency>
<groupId>com.dumptruckman.minecraft</groupId>
<artifactId>buscript</artifactId>
<version>1.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- End of Buscript Dependency -->
<!-- Start of Test Dependencies --> <!-- Start of Test Dependencies -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>

View File

@ -7,6 +7,7 @@
package com.onarandombox.MultiverseCore; package com.onarandombox.MultiverseCore;
import buscript.Buscript;
import com.fernferret.allpay.AllPay; import com.fernferret.allpay.AllPay;
import com.fernferret.allpay.GenericBank; import com.fernferret.allpay.GenericBank;
import com.onarandombox.MultiverseCore.api.BlockSafety; import com.onarandombox.MultiverseCore.api.BlockSafety;
@ -42,6 +43,7 @@ import com.onarandombox.MultiverseCore.commands.PurgeCommand;
import com.onarandombox.MultiverseCore.commands.RegenCommand; import com.onarandombox.MultiverseCore.commands.RegenCommand;
import com.onarandombox.MultiverseCore.commands.ReloadCommand; import com.onarandombox.MultiverseCore.commands.ReloadCommand;
import com.onarandombox.MultiverseCore.commands.RemoveCommand; import com.onarandombox.MultiverseCore.commands.RemoveCommand;
import com.onarandombox.MultiverseCore.commands.ScriptCommand;
import com.onarandombox.MultiverseCore.commands.SetSpawnCommand; import com.onarandombox.MultiverseCore.commands.SetSpawnCommand;
import com.onarandombox.MultiverseCore.commands.SpawnCommand; import com.onarandombox.MultiverseCore.commands.SpawnCommand;
import com.onarandombox.MultiverseCore.commands.TeleportCommand; import com.onarandombox.MultiverseCore.commands.TeleportCommand;
@ -196,6 +198,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private HashMap<String, MVPlayerSession> playerSessions; private HashMap<String, MVPlayerSession> playerSessions;
private GenericBank bank = null; private GenericBank bank = null;
private AllPay banker; private AllPay banker;
private Buscript buscript;
private int pluginCount; private int pluginCount;
private DestinationFactory destFactory; private DestinationFactory destFactory;
//private SpoutInterface spoutInterface = null; //private SpoutInterface spoutInterface = null;
@ -303,6 +306,16 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.log(Level.INFO, "Spout integration enabled."); this.log(Level.INFO, "Spout integration enabled.");
} }
*/ */
initializeBuscript();
}
/**
* Initializes the buscript javascript library
*/
private void initializeBuscript() {
buscript = new Buscript(this);
// Add global variable "multiverse" to javascript environment
buscript.getGlobalScope().put("multiverse", buscript.getGlobalScope(), this);
} }
private void initializeDestinationFactory() { private void initializeDestinationFactory() {
@ -671,6 +684,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.commandHandler.registerCommand(new DebugCommand(this)); this.commandHandler.registerCommand(new DebugCommand(this));
this.commandHandler.registerCommand(new GeneratorCommand(this)); this.commandHandler.registerCommand(new GeneratorCommand(this));
this.commandHandler.registerCommand(new CheckCommand(this)); this.commandHandler.registerCommand(new CheckCommand(this));
this.commandHandler.registerCommand(new ScriptCommand(this));
} }
/** /**
@ -1122,4 +1136,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
public static MultiverseCoreConfiguration getStaticConfig() { public static MultiverseCoreConfiguration getStaticConfig() {
return MultiverseCoreConfiguration.getInstance(); return MultiverseCoreConfiguration.getInstance();
} }
@Override
public Buscript getScriptAPI() {
return buscript;
}
} }

View File

@ -7,6 +7,7 @@
package com.onarandombox.MultiverseCore.api; package com.onarandombox.MultiverseCore.api;
import buscript.Buscript;
import com.fernferret.allpay.AllPay; import com.fernferret.allpay.AllPay;
import com.fernferret.allpay.GenericBank; import com.fernferret.allpay.GenericBank;
import com.onarandombox.MultiverseCore.destination.DestinationFactory; import com.onarandombox.MultiverseCore.destination.DestinationFactory;
@ -222,4 +223,11 @@ public interface Core {
* @return The configuration. * @return The configuration.
*/ */
MultiverseCoreConfig getMVConfig(); MultiverseCoreConfig getMVConfig();
/**
* Gets the buscript object for Multiverse. This is what handles Javascript processing.
*
* @return The Multiverse buscript object.
*/
Buscript getScriptAPI();
} }

View File

@ -0,0 +1,56 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;
import java.io.File;
import java.util.List;
/**
* States who is in what world.
*/
public class ScriptCommand extends MultiverseCommand {
public ScriptCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Runs a script.");
this.setCommandUsage("/mv script" + ChatColor.GOLD + " {script} [target]");
this.setArgRange(1, 2);
this.addKey("mv script");
this.addKey("mvscript");
this.addCommandExample(String.format("/mv script %sscript.txt", ChatColor.GOLD));
this.addCommandExample(String.format("/mv script %stest.txt %ssomeplayer", ChatColor.GOLD, ChatColor.GREEN));
this.setPermission("multiverse.core.script", "Runs a script.", PermissionDefault.OP);
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
File file = new File(plugin.getScriptAPI().getScriptFolder(), args.get(0));
if (!file.exists()) {
sender.sendMessage("That script file does not exist in the Multiverse-Core scripts directory!");
return;
}
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
String target = null;
if (args.size() == 2) {
target = args.get(1);
}
plugin.getScriptAPI().executeScript(file, target, player);
sender.sendMessage(String.format("Script '%s%s%s' finished!", ChatColor.GOLD, file.getName(), ChatColor.WHITE));
}
}

View File

@ -202,3 +202,7 @@ commands:
description: Regenerates a world Multiverse already knows about. description: Regenerates a world Multiverse already knows about.
usage: | usage: |
/<command> {WORLD} /<command> {WORLD}
mvscript:
description: Runs a script from the Multiverse scripts directory.
usage: |
/<command> {script} [target]

View File

@ -7,6 +7,7 @@
package com.onarandombox.MultiverseCore.test.utils; package com.onarandombox.MultiverseCore.test.utils;
import buscript.Buscript;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener; import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
@ -80,6 +81,8 @@ public class TestInstanceCreator {
when(mockPluginManager.getPlugins()).thenReturn(plugins); when(mockPluginManager.getPlugins()).thenReturn(plugins);
when(mockPluginManager.getPlugin("Multiverse-Core")).thenReturn(core); when(mockPluginManager.getPlugin("Multiverse-Core")).thenReturn(core);
when(mockPluginManager.getPermission(anyString())).thenReturn(null); when(mockPluginManager.getPermission(anyString())).thenReturn(null);
// Tell Buscript Vault is not available.
when(mockPluginManager.getPermission("Vault")).thenReturn(null);
// Make some fake folders to fool the fake MV into thinking these worlds exist // Make some fake folders to fool the fake MV into thinking these worlds exist
File worldNormalFile = new File(core.getServerFolder(), "world"); File worldNormalFile = new File(core.getServerFolder(), "world");
@ -178,6 +181,13 @@ public class TestInstanceCreator {
serverfield.setAccessible(true); serverfield.setAccessible(true);
serverfield.set(core, mockServer); serverfield.set(core, mockServer);
// Set buscript
Buscript buscript = PowerMockito.spy(new Buscript(core));
Field buscriptfield = MultiverseCore.class.getDeclaredField("buscript");
buscriptfield.setAccessible(true);
buscriptfield.set(core, buscript);
when(buscript.getPlugin()).thenReturn(core);
// Set worldManager // Set worldManager
WorldManager wm = PowerMockito.spy(new WorldManager(core)); WorldManager wm = PowerMockito.spy(new WorldManager(core));
Field worldmanagerfield = MultiverseCore.class.getDeclaredField("worldManager"); Field worldmanagerfield = MultiverseCore.class.getDeclaredField("worldManager");