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
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
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.
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
here is an example of complete code
there are several things to point out here
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.
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.
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
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
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.
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
here is an example of complete code
there are several things to point out here
- 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.
- 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();
- 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
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
Limit for
Code (Text):
var color = function(str){
return str.replaceAll("&", "§");
};
return str.replaceAll("&", "§");
};
Code (Text):
var color = function(str){
var cr = Java.type("org.bukkit.ChatColor");
return cr.translateAlternateColorCodes('&', 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);
}
};
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();
};
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();
};
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)));
};
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.
- Variables
- Bukkit
- provides static method access. For example, Bukkit.getOnlinePlayers() will return array of Player objects which are online.
- player (for sub classes of PlayerEvent)
- entity (for sub classes of EntityEvent)
- and more depends on the event classes
- (if you are experienced developer, you probably noticed that those variables are exactly same as the one in the actual event classes. And you are right! these variables are extracted using reflection)
- Bukkit
- Functions
- get(key)
- get global variable associated with the key
- returns object
- put(key, val)
- add new variable with given key and value pair. If the key already exists, it will be replaced with new value.
- didn't tested the key with other languages or special characters. You better not use them unless you are 100% confidence about them.
- the value accepts Java literals and any Bukkit objects that implement ConfigurationSerializable interface.
- has(key)
- check if a global variable associated with the key exist.
- returns boolean;
- get(key)
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.
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft versions listed: 1.10, 1.11
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
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.