Powerblock

Software anyone can script for! Simply create scripts in Notepad! Follows JavaScript syntax. Interact with Java objects via the Rhino engine!


Project maintained by dreadiscool Hosted on GitHub Pages — Theme by mattgraham

Introducing PowerBlock

PowerBlock is a server written from scratch for Minecraft classic. What sets it apart from other software its huge versatility. Thanks to the Rhino scripting engine, anyone can create scripts, or plugins, for PowerBlock in Notepad! No complicated IDE setup required! Written in Java, PowerBlock can be run on ANY Operating System, unlike other software which requires Mono, and other heavy, sluggish frameworks.

Downloading PowerBlock

The latest compiled version of PowerBlock is available here. You must create a startup file for your server, depending on what Operating System you use.

Mac -> start.command
Windows -> start.bat
Linux -> start.sh

Inside your file, write the following lines to start up the server

java -jar PowerBlock.jar

Make sure that PowerBlock.jar and your start file are in the same folder! Finally, run your start file (not the Jar file!) and if all goes well, you should see a screen with text pop up. You should also see the following folders generate: world, and plugins

Congratulations! You have set up your first PowerBlock server!

Scripting in PowerBlock (Basic)

PowerBlock's most powerful feature is you! With its JavaScript engine, PowerBlock can understand instructions from the most important person - you. Developers who have an advanced knowledge of code will also be entertained: the engine allows the manipulation and creation of Java objects! Let's get started

All scripts have the .js file extension (for JavaScript). Create a new file, and end it with .js. In our example, we named it TestPlugin.js

Here is an example of an extremely basic script. Upon enabling, the line '[TestPlugin] Hello, world', will be printed to the console.

# name TestPlugin
# author dreadiscool
# version 1.0

function onEnable() {
    console.println('Hello, world!');
}

Printing messages is all well said and done, but for our script to be useful, we need to hook into some events.

# name TestPlugin
# author dreadiscool
# version 1.0

function onEnable() {
    console.println('Hello, world!');
}

// The e represents the Event object
function onPlayerJoin(e) {
    e.setJoinMessage('A player has joined!');
    console.println(e.getPlayer().getUsername() + ' has connected to the server!');
}

Now that we have a (somewhat) useful plugin, we want to let the entire server know about it! So let's tell them!

Previous startup code left out for brevity

function onPlayerCommand(player, command, args) {
    if (command == 'shout') {
        $.broadcastMessage('Hey everybody, ' + player.getUsername() + ' shouted!');
        return true;
    }
}

Scripting in PowerBlock (advanced)

There isn't much documentation on advanced scripting for PowerBlock. However, as time goes on, that will change. Here is an example script to add the 'reload' command in the console, and the '/plugins' command in-game.

# name Reloader
# author dreadiscool
# version 1.0

var BROADCAST_RELOAD = true;
var ALLOW_LIST_PLUGINS_IN_GAME = true;

function onEnable() {
    String.prototype.equals = function(s) {
        return this.toUpperCase() == s.toUpperCase();
    }
}

function onConsoleCommand(command, args) {
    if (command.equals('reload')) {
        console.println('Reloading...');
        if (BROADCAST_RELOAD) {
            $.broadcastMessage('&2The server is reloading, expect lag!');
        }
        var start = java.lang.System.currentTimeMillis();
        $.getPluginManager().unload();
        $.getPluginManager().load();
        var time = java.lang.System.currentTimeMillis() - start;
        console.println('Done reloading! [' + time + 'ms]');
        if (BROADCAST_RELOAD) {
            $.broadcastMessage('&2Finished reloading, moving on!');
        }
        return true;
    }
    else if (command.equals('plugins')) {
        var plugins = getPluginList();
        console.println(plugins);
        return true;
    }
    return false;
}

function onPlayerCommand(player, command, args) {
    if (command.equals('plugins')) {
        if (!ALLOW_LIST_PLUGINS_IN_GAME) {
            player.sendMessage('&cThe server administrator has blocked this command!');
            return true;
        }
        if (args.length == 0) {
            player.sendMessage(getPluginList());
        }
        else {
            player.sendMessage('&bUse the command like this: /plugins');
        }
        return true;
    }
    return false;
}

function getPluginList() {
    var plugins = $.getPluginManager().getAllPlugins();
    var sb = new java.lang.StringBuilder();
    sb.append('Running Scripts [' + plugins.length + '] ');
    for (var i = 0; i < plugins.length; i++) {
        sb.append(plugins[i].getPluginName() + ', ');
    }
    if (plugins.length == 0) {
        sb.append('This server is not running any plugins :-(  ');
    }
    sb.setLength(sb.length() - 2);
    return sb.toString();
}