Skip to content
Spookit edited this page Dec 1, 2019 · 8 revisions

Creating Pandawa Package

Pandawa Package is a container for your script, its like plugin jar.
Pandawa Package can contains pandawa.yml to specify more information about the package.
Pandawa Package contains all scripts and resource files.
To create a pandawa package, all you need is to zip the entire script, and also put pandawa.yml in it
(optional). The zip can contains any files or any scripts.
Pandawa Package can be also a Directory/Folder that contains collections of script, pandawa.yml, and
resource files.

Package Installation

  • get the pandawa package file (.zip or zipped folder)
  • put it in ./plugins/PandawaJS/scripts/
  • restart the server or do /pdw reload

Pandawa Package Properties

Pandawa Package Properties contains useful data for PandawaJS and for your scripts,
PandawaJS will read pandawa.yml as your package properties and will use it
to load your script. This is optional, if you didn't include this file on your package,
PandawaJS will ignore it and will load all script at the same time, this is also happened
if you don't specify main field on pandawa.yml.

name: PandawaJS # the package name, avoid using name "default" as it will interrupt other packages
author: Septogeddon # the author
main: Main # the main script, in this example case "Main.js" (optional). If defined it will only run Main script, the other script can be called from Main Script
version: # the version string
dependencies: [] # list of dependencies (PandawaPackage dependencies, not Plugin dependencies)
libraries:
- exampleLib # assuming that you have 'exampleLib.jar' on your package

Put that file inside of your package zip or folder.
example file: https://pastebin.com/wM7QHMWR

Including Libraries On Your Package

To do this, you can put the jar on the package folder/zip.
And then put the file name of the library (without.jar, example Shop.jar -> Shop),
on pandawa.yml (if you don't have it then create one.)
See Pandawa Package Properties
See Java Libraries

Managing Java Objects

Using Java Object

All Common Java Objects mostly imported by default. Otherwise you have to import it.
Default classes list: https://pastebin.com/raw/phZrZBcH

Example Usage

Packages.java.io.File; // this is basically import the class
Packages.java.io.FileInputStream;
var fis = new FileInputStream(new File("C:/hello.txt"));

Reflections

All java objects imported to this plugin will actually imported as reflection
so, you can get any private fields or call any private methods without using Java Reflection.

Java Libraries

Java libraries allows you to do complex things using simple function.
This can be found in ./plugins/PandawaJS/libraries/.

By default, PandawaJS included these libraries

  • Apache Commons IO 2.5
  • Apache Commons Lang3 3.0
  • Gson 2.8.2
  • Jsoup 1.11.3
    You can add more libraries by placing the jar inside libraries folder.
    Bonus: You can add JavaCord to work with Discord bot management!

Default Implemented Functions

log(Object)

print something to console
similar to println writeln console.log

isPlayer(Object)

check if an object is a player
return true if object is player, false otherwise

toStringObject(Object)

deep to string object, could be an array

createConfig()

similar to "new Yaml()"
See Yaml

identify(Object)

print Object class name to console, used for debugging purpose

player(String)

get online player
See Players

color(String)

colorize the string using bukkit color

getServer()

return server instance
See org.bukkit.Server

$()

See getServer()

server()

See getServer()

registerCommand(function(sender,arguments))

Deprecated and should not be used.
Use Commands['commandName'] instead
See Command builder

async(function() return Object)

Run a task asynchronously (outside of Bukkit thread)
return a Future object that could get the result object of a task if the task returns something

Example Usage
var promise = async(function() {
	log('this is async function');
	return 'this is awesome');
});
var awesomeString = promise.get();
log(awesomeString); // prints 'this is awesome'

async(function(), number)

Run a task asynchronously with a delay
does not return a Future object

async(function(), number, number)

Run a task asynchronously with a delay and run delayed repeatedly
function() - the function
number - delay ticks
number - period ticks

sync(function() return Object)

Similar to async but runs synchronously (inside Bukkit thread)

sync(function(), number)

Similar to async but runs synchronously (inside Bukkit thread)

sync(function(), number, number)

Similar to async but runs synchronously (inside Bukkit thread)

seconds(number)

convert seconds to ticks

minutes(number)

convert minutes to ticks

hours(number)

convert hours to ticks

days(number)

convert days to ticks

Default Imported Class

GUI

This class allows you to create GUI

Initiate The Class

Example Usage

var gui = new GUI(title,size);
var gui = new GUI(title,InventoryType);

See org.bukkit.inventory.InventoryType

Put Items to GUI

Example Usage

var gui; // the gui
gui[0] = Items.APPLE; // put an Apple to slot 0
gui[1] = Items.GOLDEN_APPLE.executor(function(event) {
	log('Golden Apple is clicked');
}); // put a Golden Apple with executor in it to slot 1

Open the Inventory to a Player

Example Usage

var gui; // the gui
gui.open('Septogeddon');
//or
gui.open(Players.Septogeddon);
gui.open(Players['Septogeddon']);

Clearing the GUI

Example Usage

var gui; // the gui
gui.clear();

Close All GUI Viewer

Example Usage

var gui; // the gui
gui.closeAll(); // all players that viewing the GUI, will be closed.

Functions

GUIBuilder#open(Object) open the gui to a player
GUIBuilder#fillEmpty(Item) fill empty the gui
GUIBuilder#fill(Item) fill the gui
GUIBuilder#clear() clear the gui
GUIBuilder#closeAll() close all viewers

Yaml

This class allows you to load .yml files

Initiate The Class

Example Usage

var yaml = new Yaml();
var yaml = createConfig();
var yaml = Files['config.yml'].loadConfig();
var yaml = new Yaml(Files['config.yml']);

Get Object from Config

Example Usage

var yaml; // the instance
yaml.paths;
yaml['paths']['anotherpath'];
yaml.balance.Septogeddon;
yaml.balance['Septogeddon'];

Set Object to Config

Example Usage

var yaml; // the instance
yaml.paths = 'nothing';

Delete Object from Config

Example Usage

var yaml; // the instance
delete yaml.paths;
//or
yaml.paths = null;

Saving the Config

Example Usage

var yaml; // the instance
Files['config.yml'].write(yaml);

Hooks

This class allows you to listen to plugin events

Listen on Pandawa Plugin Disable

Example Usage

Hooks.onDisable(function() {
	// codes run when PandawaJS is disabling
});

NMS

This class allows you to get net.minecraft.server.$version classes

Getting NMS Classes

Example Usage

NMS.PacketPlayOutChat;
NMS['EntityPlayer'];

CraftBukkit

This class allows you to get org.bukkit.craftbukkit.$version classes

Getting CraftBukkit Classes

Example Usage

CraftBukkit.CraftServer;
CraftBukkit['CraftServer']

Craft

Similar to CraftBukkit
See CraftBukkit

InventoryType

An enum to inventory types
See org.bukkit.inventory.InventoryType

Command Builder

This allows you to register a command

Creating a Command Builder

Example Usage

var cmd = Commands['commandName']

Adding Command Aliases

Example Usage

var cmd;
cmd.also('aliasName');
cmd.alias('aliasName'); // alias = also
cmd.also('aliasName').also('aliasName2').alias('aliasName3');

Setting Permission

Example Usage

var cmd;
cmd.permission('permission.example');
cmd.permissionMessage('You dont have permission fool!');

Adding Executor

Example Usage

var cmd;
cmd.executor(function(sender,args)) {
	// sender is org.bukkit.command.CommandSender
	// args is String array (String[])
);

See org.bukkit.command.CommandSender

Adding Tab Completer

Example Usage

var cmd;
cmd.tabcompleter(function(sender,args)) {
	// sender is org.bukkit.command.CommandSender
	// args is String array (String[])
	// must return a String array
	return ['completer','here'];
};

See org.bukkit.command.CommandSender

Registering the Command

Example Usage

var cmd;
cmd.register();

Unregistering the Command

Example Usage

var cmd;
cmd.unregister();

Listener Builder

This allows you to listen Bukkit / Plugin events

Creating the Listener

Example Usage

var listener = Events['event name']
var listener = Events['com.example.plugin.events.ExamplePluginEvent']
var listener = Events['player.PlayerJoinEvent']

Listening the Event

Example Usage

var listener; // listener builder instance
listener.listen(function(event)) {
	//do something with the event
});
// #listen(PRIORITY, FUNCTION)
listener.listen('LOWEST',function(event)) {
	//do something with the event
});

Unlisten the Listener Builder

Example Usage

var listener; // listener builder instance
listener.unregister();

Entity Builder

This allows you to spawn an Entity

Creating the Builder

Example Usage

var entity = Entities.ENTITY_TYPE;
var entity = Entities.ARMOR_STAND;
var entity = Entities['ARMOR_STAND']

Spawning the Entity

Example Usage

var entity;
var playerExample;
entity.spawn(LOCATION);
entity.spawn(new Location(Worlds['world_nether'],10,10,10));
entity.spawn(playerExample.getLocation());

See org.bukkit.Location
See org.bukkit.entity.Player

Item Builder

This allows you to create an Item

Creating an Item

Example Usage

Items.APPLE;
Items['APPLE'];

Available Functions
ItemBuilder#executor(function(clickEvent)); Set the executor for GUI Click
ItemBuilder#name(String) set the display name
ItemBuilder#lore(String...) set the lore

Example Usage
var item;
item.lore('this','is','multiple','line','lore');

ItemBuilder#meta(function(meta)); consume the ItemMeta
See org.bukkit.inventory.meta.ItemMeta
ItemBuilder#flag(String...) set the flags
See org.bukkit.inventory.ItemFlag

Example Usage
var item;
item.flag('HIDE_ENCHANTS');
item.flag(); // will use all flags
item.flag('HIDE_ENCHANTS', 'HIDE_UNBREAKABLE');

ItemBuilder#unbreakable(boolean) set unbreakable
ItemBuilder#type(String) set the type
ItemBuilder#amount(number) set the amount
ItemBuilder#enchant(String,level) add the enchantment
See org.bukkit.enchantments.Enchantment
ItemBuilder#unenchant(String) remove the enchantment
and more from org.bukkit.inventory.ItemStack

File Streamer

This allows you to control file from your script package configuration folder ("./plugins/PandawaJS/configurations//")

Creating the Streamer

Example Usage

Files['config.yml']

Available Functions

FileStreamer#input() return InputStream
FileStreamer#output() return OutputStream
FileStreamer#reader() return Reader
FileStreamer#writer() return Writer
FileStreamer#write(Object) write Stringified Object
FileStreamer#readAll() read file and return String
FileStreamer#loadConfig() read file as Yaml config
FileStreamer#copy(InputStream) write from inputstream
and more from java.io.File

Potion Builder

This allows you to create PotionEffect object to apply on a LivingEntity (player, animals, monsters, creature)

Creating the Builder

Example Usage

Potions['SPEED'];
Potions.JUMP;

See org.bukkit.potion.PotionEffectType

Available Functions

PotionBuilder#apply(LivingEntity) could be applied to Player, ArmorStand, Wolf, Zombies, etc
See org.bukkit.entity.LivingEntity
PotionBuilder#type(String) set the Potion effect type
PotionBuilder#ambient() return boolean ambient state
PotionBuilder#ambient(boolean) set ambient state
PotionBuilder#particles() return boolean particles state
PotionBuilder#duration() return duration in tick (integer/number)
PotionBuilder#duration(number) set the duration (in ticks)
PotionBuilder#amplifier() return the amplifier level
PotionBuilder#amplifier(number) set the amplifier level

Pandawa Package

This class controls aspect of your script
Default package name is 'default' can be get by Packages.default or Packages['default']

Available Functions

Package#getName() return the package name
Package#getAuthor() return the author
Package#getVersion() return the package version
Package#getDependencies() return the dependencies list
Package#getMainScript() return main script name
Package#getScript() return a script
See Pandawa Script
Package#getAPI() return PandawaJS API
See PandawaAPI
Package#getPandawa() get the core, See Pandawa

Pandawa Script

This class is basically class to hold your script.
All functions and variables are shareable.

Example Usage

var script1 = Scripts['ScriptExample'];
script1.doTheThing(); // this will call function 'doTheThing' from script1 (ScriptExample)

PandawaAPI

Functions

PandawaAPI#registerImp(String,PandawaImpPackage)
PandawaAPI#unregisterImp(String)
PandawaAPI#getDefaultPackage()
PandawaAPI#getPackage(String)
PandawaAPI#getLoadedPackages()
PandawaAPI#readPandawa(File)
PandawaAPI#registerImplementation(Object)

Pandawa

Pandawa#getPackage() get the package
Pandawa#queueLoad() avoid using this
Pandawa#getResource() get the resource file inside pandawa (from .zip or directory) See PandawaResource
See Pandawa Resource

Pandawa Resource

PandawaResource#getName() get the resource/file name
PandawaResource#openStream() create new InputStream for this resource
PandawaResource#getPackage() get package owner
PandawaResource#saveResource() save the resource

Request Builder

This allows you to request event from Player

Creating the Builder

Example Usage

Requests.CHAT;
Requests.CLICK;
Requests['CHAT'];
Requests['CLICK'];

Requesting a Chat

Example Usage

var req = Requests.CHAT;
req.request(Players.Septogeddon, function(event) {
	Players.Septogeddon.sendMessage('You just chat: '+event.getMessage());
});

See org.bukkit.event.player.AsyncPlayerChatEvent

Requesting a Click

Example Usage

var req = Requests.CLICK;
req.request(Players.Septogeddon, function(event) {
	Players.Septogeddon.sendMessage('You just chat: '+event.getClickedBlock());
});

See org.bukkit.event.player.PlayerInteractEvent

Cancelling Request

Example Usage

var req; // request builder instance
req.cancel('PlayerName');
req.cancel(Players.Septogeddon);

Pandawa Objects

Commands

returns a Command builder.

Example Usage

Commands['commandName']
Commands.commandNameWithoutSpace

See Command Builder

Players

returns a Player (Online Player)

Example Usage

Players.Septogeddon
Players['Septogeddon']
for (var player in Players)

See org.bukkit.entity.Player

Worlds

returns a World

Example Usage

Worlds.world_nether
Worlds['world_the_end']
for (var world in Worlds)

See org.bukkit.entity.Worlds

Events

returns a Listener builder

Example Usage

Events[PlayerJoinEvent] // since 1.0.28
Events['player.PlayerJoinEvent']
Events['org.bukkit.event.player.PlayerJoinEvent']

See Listener builder

Entities

returns an Entity builder

Example Usage

Entities.ARMOR_STAND
Entities['ARMOR_STAND']

See Entity builder

Items

returns an Item builder

Example Usage

Items.GOLDEN_APPLE
Items['APPLE']

See Item builder
See org.bukkit.inventory.ItemStack

Files

returns a File streamer

Example Usage

Files['config.yml']

See File Streamer
See java.io.File

Potions

returns a Potion builder

Example Usage

Potions.CONFUSION
Potions['SPEED']

See Potion Builder
See org.bukkit.potion.PotionEffectType

PandawaPackages

returns a Pandawa Package

Example Usage

Packages['default']
Packages.SeptogeddonJSPacks

See Pandawa Package

Scripts

returns a Pandawa Script

Example Usage

Scripts['SimpleSystemInformation']
Scripts.SimpleGUI

See Pandawa Script

Plugins

returns a Main Plugin Instance

Example Usage

Plugins['WorldEdit']
Plugins.Essentials

See org.bukkit.plugin.Plugin
See org.bukkit.plugin.java.JavaPlugin

Test

Used to debug the plugin, should not be used.

Requests

returns Request Builder

Example Usage

Requests.CHAT;
Requests.CLICK;

See Request Builder

Resources

returns PandawaResource

Example Usage

Resources['pandawa.yml'];

See Pandawa Resource

JavaPackages

returns Java Package

Example Usage

JavaPackages['org.jsoup.Jsoup'];
JavaPackages.org.jsoup.Jsoup;

See Using Java Object

Clone this wiki locally