mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-07 11:20:32 +01:00
Added buscript Javascript library.
This commit is contained in:
parent
6133cf6bdf
commit
24e26bb7d7
14
pom.xml
14
pom.xml
@ -152,6 +152,7 @@
|
||||
<include>me.main__.util:SerializationConfig</include>
|
||||
<include>com.fernferret.allpay:AllPay</include>
|
||||
<include>com.pneumaticraft.commandhandler:CommandHandler</include>
|
||||
<include>com.dumptruckman.minecraft:buscript</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
@ -167,6 +168,10 @@
|
||||
<pattern>com.pneumaticraft.commandhandler</pattern>
|
||||
<shadedPattern>com.pneumaticraft.commandhandler.multiverse</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>buscript</pattern>
|
||||
<shadedPattern>buscript.multiverse</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
@ -221,6 +226,15 @@
|
||||
<scope>compile</scope>
|
||||
</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 -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import buscript.Buscript;
|
||||
import com.fernferret.allpay.AllPay;
|
||||
import com.fernferret.allpay.GenericBank;
|
||||
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.ReloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.RemoveCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ScriptCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.SetSpawnCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.SpawnCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
|
||||
@ -196,6 +198,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private HashMap<String, MVPlayerSession> playerSessions;
|
||||
private GenericBank bank = null;
|
||||
private AllPay banker;
|
||||
private Buscript buscript;
|
||||
private int pluginCount;
|
||||
private DestinationFactory destFactory;
|
||||
//private SpoutInterface spoutInterface = null;
|
||||
@ -303,6 +306,16 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
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() {
|
||||
@ -671,6 +684,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.commandHandler.registerCommand(new DebugCommand(this));
|
||||
this.commandHandler.registerCommand(new GeneratorCommand(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() {
|
||||
return MultiverseCoreConfiguration.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Buscript getScriptAPI() {
|
||||
return buscript;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import buscript.Buscript;
|
||||
import com.fernferret.allpay.AllPay;
|
||||
import com.fernferret.allpay.GenericBank;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
@ -222,4 +223,11 @@ public interface Core {
|
||||
* @return The configuration.
|
||||
*/
|
||||
MultiverseCoreConfig getMVConfig();
|
||||
|
||||
/**
|
||||
* Gets the buscript object for Multiverse. This is what handles Javascript processing.
|
||||
*
|
||||
* @return The Multiverse buscript object.
|
||||
*/
|
||||
Buscript getScriptAPI();
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
@ -202,3 +202,7 @@ commands:
|
||||
description: Regenerates a world Multiverse already knows about.
|
||||
usage: |
|
||||
/<command> {WORLD}
|
||||
mvscript:
|
||||
description: Runs a script from the Multiverse scripts directory.
|
||||
usage: |
|
||||
/<command> {script} [target]
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.test.utils;
|
||||
|
||||
import buscript.Buscript;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||
@ -80,6 +81,8 @@ public class TestInstanceCreator {
|
||||
when(mockPluginManager.getPlugins()).thenReturn(plugins);
|
||||
when(mockPluginManager.getPlugin("Multiverse-Core")).thenReturn(core);
|
||||
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
|
||||
File worldNormalFile = new File(core.getServerFolder(), "world");
|
||||
@ -178,6 +181,13 @@ public class TestInstanceCreator {
|
||||
serverfield.setAccessible(true);
|
||||
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
|
||||
WorldManager wm = PowerMockito.spy(new WorldManager(core));
|
||||
Field worldmanagerfield = MultiverseCore.class.getDeclaredField("worldManager");
|
||||
|
Loading…
Reference in New Issue
Block a user