Home > ScriptingApi

ScriptingApi

ScriptingApi is a project mainly written in JAVASCRIPT and JAVA, it's free.

A plugin for hMod that allows you to write plugins in Javascript.

ScriptingApi : a plugin for hMod

ScriptingApi is a plugin that allows you to create plugins for hMod in pure Javascript (or Python). Every hook for hMod has been implemented so the results are limitless. Also, a few extra features were rolled in in order to make plugin development as painless as possible. All Javascript errors are stack traced in the console. If one plugin crashes, the others are unaffected.

Loading new Javascript plugins

  • Add a file to the js/ directory with the extension .js .
  • Use the /reloadscripts command.
  • Your plugin is loaded!

Loading new Python plugins

  • Put jython.jar in the plugins/ directory.
  • Add a file to the py/ directory with the extension .py .
  • Use the /reloadscripts command.
  • Your plugin is loaded!

Quick Examples

The best way to learn is to look at the files in the "src/js/" directory.

New API Info

All of these hooks are available to you: http://hmod.ricin.us/javadoc/index.html?PluginListener.html

If you wish to make an instance of a new hMod class, say Minecart you would do it like this:

var minecart = Api.create("Minecart", [
    /* x */ 0,
    /* y */ 50,
    /* z */ 10,
    /* http://hmod.ricin.us/javadoc/index.html?Minecart.Type.html */ Api.fetchEnum("Minecart.Type").Minecart
]);

Hook list

* `Api.onPlayerMove`
* `Api.onSignShow`
* `Api.onSignChange`
* `Api.onOpenInventory`
* `Api.onTeleport`
* `Api.onLoginChecks`
* `Api.onLogin`
* `Api.onDisconnect`
* `Api.onChat`
* `Api.onCommand`
* `Api.onConsoleCommand`
* `Api.onBan`
* `Api.onIpBan`
* `Api.onKick`
* `Api.onBlockCreate`
* `Api.onBlockDestroy`
* `Api.onArmSwing`
* `Api.onAttack`
* `Api.onBlockBreak`
* `Api.onBlockPlace`
* `Api.onBlockPhysics`
* `Api.onBlockRightClicked`
* `Api.onDamage`
* `Api.onExplode`
* `Api.onFlow`
* `Api.onHealthChange`
* `Api.onIgnite`
* `Api.onItemDrop`
* `Api.onItemPickUp`
* `Api.onItemUse`
* `Api.onLiquidDestroy`
* `Api.onMobSpawn`
* `Api.onRedstoneChange`
* `Api.onVehicleCollision`
* `Api.onVehicleDamage`
* `Api.onVehicleCreate`
* `Api.onVehicleDestroyed`
* `Api.onVehicleEnter`
* `Api.onVehiclePositionChange`
* `Api.onVehicleUpdate`

Info about the API

  • You can call all the native methods of Java objects. For example, when Player is an argument to a callback, you can use all the methods listed on this page.
  • The list of hooks and arguments is available here.
  • To get the instance of Server, either use "this" inside a callback or use Api.getServer();
  • To do an INFO level log, use Api.log.info("log message") to get an instance of the Logger class and call the info method.
  • To do an SEVERE level log, use Api.log.severe("log message") to get an instance of the Logger class and call the severe method.
  • To create an instance of HitBlox, use the Api.createHitBlox(player) method.
  • To send a message to all players use the Api.broadcast() method. broadcast takes three arguments, the first is the message to send, the second can be null or it can be a group to limit a message to, the third can be null or a boolean. If the third argument is true, broadcast will send a message to everyone NOT in the specified group.
  • All of the colors for chat are available with Colors.Blue, Colors.Red, etc...
  • A key:value object of all the item names and their id's is available as Items["Air"], Items["Stone"], etc... Blocks is aliased to Items.
  • A key:value object of all the ids and their respective names is available as ItemIds[0], ItemIds[1], etc...
  • You can access the etc class via Api.etc.
  • You can get the connection to MySQL server via Api.etc.getSQLConnection() (returned value is an instance of Connect).
  • You can access the current DataSource class (MySQLSource or FileFileSource) with Api.etc.getDataSource().
  • Create new instances of Item and Location with Api.createItem() and Api.createLocation().

Including external JARs

  • If you need to include classes from an external JAR you can use the new Api.loadJar methods. The only argument it accepts is the path to jar relative to the directory minecraft_server.jar is in.

The BlockBuilder class

The BlockBuilder class is meant to make building simple to complex objects really easy. It accounts for the users rotation and the axes.

Essentially you first create the blocks that you want, then you attach them to the world. All you have to do is construct the group of blocks in a "sandbox" where you start at x = 0, y = 0 and z = 0.

See the end of "src/js/Hitblox.js" for a simple example of how to use the BlockBuilder class.

Previous:Eiffelgrams