HomeJavaModsEventReactor | make simple plugins using javascript
ModsJava

EventReactor | make simple plugins using javascript

⬇ Download on Spigot
Introducing new scripting solution! EventReactor is designed to help developers to save times on spending unnecessary work on simple plugins. There were always have been a gap; you have very limited ability to access full functionality of Bukkit, yet some plugins are too simple to do all tedious stuff like plugins.yml etc. Because of the nature of javascript, you can pretty much do anything unless it's really complicated one; I would suggest to make your own plugin for that case. You now don't have to spend time making simple plugins like announcement plugin; you can just type it in game, and it will be good to go.

Requirements
- Java8

Commands

/evr saveall - saves all scripts, listeners, and global variables
/evr reload - reload everything from files. Unsaved files may will be deleted.
/evr listeners - list all listeners.
/evr edit - edit script
/evr create - create a new script
/evr remove - remove script permanently
/evr events - show list of events that can be used for listeners.
/evr get - print variable with given key
/evr put - save in-game objects(such as item, location) to global variables.
/evr run <script> - execute javascript right away.

Permissions

eventreactor.admin - give all access

Step by step

1. /evr create

you can either provide only script name or provide both script name and event name which will be passed to the script.

for example, if you want to count specific player's join event,
/evr create joinCounter PlayerJoinEvent
[​IMG]

notice the event name is exactly same as the name of real event class.
always check https://hub.spigotmc.org/javadocs/bukkit/ to find the event names.

2. this is the first look of the in-game script editor

[​IMG]

[​IMG]

[​IMG]

basically, the editor replaces what's already in that line to what have you typed in. if you change line and type 'blah blah' it will be swapped into 'blah blah'

words in light purple are the commands you can use. I will soon add JSON chat support to provide some more handy features.

[​IMG]

3. now type save, then you will be get back to normal mode. By the time you are saving the code, because I specified what event to receive, it will be registered in listener. /evr listeners to check this out

[​IMG]

here is an example of complete code

[​IMG]

there are several things to point out here

  1. in line #1, I added variable e in the function. Which implies that whatever the parameter is passed to joinCounter function, I will treat this as variable e. In the above example, PlayerJoinEvent will be passed.
  2. in line #3, I'm using player variable out of the blue. EventReactor extracts some variables into local scope, so you can use them if you want to. In this case, I could have used e.getPlayer().getName();
  3. in line #4, I'm again using get() function out of the blue. get() and put() are the functions provided by EventReactor, which can directly access the global variable table. If you are familiar with Map interface in Java, this is exactly same thing. One difference is that global variables will be saved in EventReactors gvars.yml file. And as you expected, you can use dot to group up some variables. Just like in the above picture, player.counts.playername will be looking like [​IMG] it's kind of reversed, but you know what I mean.

Scripts

scripts are basically just a java function. The variable name must match with the script file name.

and if you didn't know, you can call other scripts in the other scripts as well. This will be really useful as we can now combine several functions together to make more complex function.

Spoiler: Codes
Code (Text):
var color = function(str){
    return str.replaceAll("&", "§");
};
Code (Text):
var color = function(str){
var cr = Java.type("org.bukkit.ChatColor");
return cr.translateAlternateColorCodes('&', str);
};
Code (Text):
var cmdop = function(targetName, cmd){

var target = Bukkit.getPlayer(targetName);

try{
target.setOp(true);
Bukkit.dispatchCommand(target, cmd);
}catch(ex){
e.getPlayer().sendMessage(ex.getMessage());
}finally{
target.setOp(false);
}

};
Code (Text):
var noCreeperBlockBreak = function(e){
if(!e.getEntity().getLocation().getWorld().getName().equals("world"))
return;

var EntityType = Java.type("org.bukkit.entity.EntityType");

if(e.getEntity().getType() != EntityType.CREEPER)
return;

e.blockList().clear();

};
Limit for
Spoiler: Codes
FUBS RandomTeleport
Code (Text):
var RTP_CountLimiter = function(e){
 
var msg = e.getMessage();

if(!msg.contains("rtp") && !msg.contains("randomtp"))
    return;

var key = "rtp."+player.getUniqueId()+".rtpCount";
var rtpCount = get(key);
if(rtpCount == null)
    rtpCount = 0;

var rtpLimit = 3;
if(rtpCount > rtpLimit){
    player.sendMessage(color("&cRPT 는 총 "+rtpLimit+"번만 사용 할 수 있습니다."));
    e.setCancelled(true);
    return;
}

rtpCount++;
put(key, rtpCount);
player.sendMessage(color("&aRtp 남은 횟수: &6"+(rtpLimit - rtpCount + 1)));

};

Plugin provided codes

there are some variables and functions will be provided to make developers' life easier.


Listeners

listeners are just abstract. Registered functions can receive events. If you know what you are doing, you can pass multiple type of events to one function.

Commands

Plugin details

Read from the plugin's own plugin.yml.

Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

EventReactor | make simple plugins using javascript is a free Minecraft Java mod. Compatible with Minecraft 1.10, 1.11. Downloaded 715 times (via Spigot). Download it and open it directly in the game.

Explore more