ThitoYalasatria

PandawaJS RAW Documentation

Nov 29th, 2019
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.34 KB | None | 0 0
  1. Creating Pandawa Package
  2. Pandawa Package is a container for your script, its similar like plugin jar.
  3. Pandawa Package can contains pandawa.yml to specify more information about the package.
  4. Pandawa Package contains all scripts and resource files.
  5. To create a pandawa package, all you need is to zip the entire script, and also put pandawa.yml in it
  6. (optional). The zip can contains any files or any scripts.
  7. Pandawa Package can be also a Directory/Folder that contains collections of script, pandawa.yml, and
  8. resource files.
  9.  
  10. Installation:
  11. - get the pandawa package file (.zip or zipped folder)
  12. - put it in "./plugins/PandawaJS/scripts"
  13. - restart the server or do "/pdw reload"
  14.  
  15. Pandawa Package Properties (pandawa.yml)
  16. name: PandawaJS // the package name, avoid using name "default" as it will interrupt other packages
  17. author: Septogeddon // the author
  18. 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
  19. version: 1.0 // the version string
  20. dependencies: [] // list of dependencies (PandawaPackage dependencies, not Plugin dependencies)
  21.  
  22. Put that file inside of your package zip or folder.
  23. example file: https://pastebin.com/wM7QHMWR
  24.  
  25. Managing Java Objects
  26. 1.0 Using Java Object
  27. Example:
  28. Packages.java.io.File;
  29. Packages.java.io.FileInputStream;
  30.  
  31. var fis = new FileInputStream(new File("C:/hello.txt"));
  32. 1.1 Reflections
  33. All java objects imported to this plugin will actually imported as reflection
  34. so, you can get any private fields or call any private methods without using Java Reflection.
  35.  
  36. Default Implemented Functions
  37. log(Object)
  38. print something to console
  39. similar to println writeln console.log
  40. isPlayer(Object)
  41. check if an object is a player
  42. return true if object is player, false otherwise
  43. toStringObject(Object)
  44. deep to string object, could be an array
  45. createConfig()
  46. similar to "new Yaml()"
  47. See Yaml
  48. identify(Object)
  49. print Object class name to console, used for debugging purpose
  50. player(String)
  51. get online player
  52. similar to Players[String]
  53. color(String)
  54. colorize the string using bukkit color
  55. similar to ChatColor.translateAlternateColorCodes('&', String)
  56. getServer()
  57. return server instance
  58. See org.bukkit.Server
  59. $()
  60. similar to getServer()
  61. server()
  62. similar to getServer()
  63. registerCommand(function(sender,arguments))
  64. Deprecated and should not be used.
  65. Use Commands['commandName'] instead
  66. See Command builder
  67. async(function() return Object)
  68. Run a task asynchronously (outside of Bukkit thread)
  69. return a Future object that could get the result object of a task if the task returns something
  70. Example:
  71. var promise = async(function() {
  72. log('this is async function');
  73. return 'this is awesome');
  74. });
  75. var awesomeString = promise.get();
  76. log(awesomeString); // prints 'this is awesome'
  77. async(function(), number)
  78. Run a task asynchronously with a delay
  79. does not return a Future object
  80. async(function(), number, number)
  81. Run a task asynchronously with a delay and run delayed repeatedly
  82. function() - the function
  83. number - delay ticks
  84. number - period ticks
  85. sync(function() return Object)
  86. Similar to async but runs synchronously (inside Bukkit thread)
  87. sync(function(), number)
  88. Similar to async but runs synchronously (inside Bukkit thread)
  89. sync(function(), number, number)
  90. Similar to async but runs synchronously (inside Bukkit thread)
  91. seconds(number)
  92. convert seconds to ticks
  93. minutes(number)
  94. convert minutes to ticks
  95. hours(number)
  96. convert hours to ticks
  97. days(number)
  98. convert days to ticks
  99.  
  100. Default Imported Class
  101. GUI
  102. This class allows you to create GUI
  103. 1.0 Initiate The Class
  104. Example:
  105. var gui = new GUI(title,size);
  106. var gui = new GUI(title,InventoryType);
  107. See org.bukkit.inventory.InventoryType
  108. 1.1 Put Items to GUI
  109. Example:
  110. var gui; // the gui
  111. gui[0] = Items.APPLE; // put an Apple to slot 0
  112. gui[1] = Items.GOLDEN_APPLE.executor(function(event) {
  113. log('Golden Apple is clicked');
  114. }); // put a Golden Apple with executor in it to slot 1
  115. 1.2 Open the Inventory to a Player
  116. Example:
  117. var gui; // the gui
  118. gui.open('Septogeddon');
  119. //or
  120. gui.open(Players.Septogeddon);
  121. gui.open(Players['Septogeddon']);
  122. 1.3 Clearing the GUI
  123. Example:
  124. var gui; // the gui
  125. gui.clear();
  126. 1.4 Close All GUI Viewer
  127. Example:
  128. var gui; // the gui
  129. gui.closeAll(); // all players that viewing the GUI, will be closed.
  130. Yaml
  131. This class allows you to load .yml files
  132. 1.0 Initiate The Class
  133. Example:
  134. var yaml = new Yaml();
  135. var yaml = createConfig();
  136. var yaml = Files['config.yml'].loadConfig();
  137. var yaml = new Yaml(Files['config.yml']);
  138. 1.1 Get Object from Config
  139. Example:
  140. var yaml; // the instance
  141. yaml.paths;
  142. yaml['paths']['anotherpath'];
  143. yaml.balance.Septogeddon;
  144. yaml.balance['Septogeddon'];
  145. 1.2 Set Object to Config
  146. Example:
  147. var yaml; // the instance
  148. yaml.paths = 'nothing';
  149. 1.3 Delete Object from Config
  150. Example:
  151. var yaml; // the instance
  152. delete yaml.paths;
  153. //or
  154. yaml.paths = null;
  155. 1.4 Saving the Config
  156. Example:
  157. var yaml; // the instance
  158. Files['config.yml'].write(yaml);
  159. Hooks
  160. This class allows you to listen to plugin events
  161. 1.0 Listen on Pandawa Plugin Disable
  162. Example:
  163. Hooks.onDisable(function() {
  164. // codes run when PandawaJS is disabling
  165. });
  166. NMS
  167. This class allows you to get net.minecraft.server.$version classes
  168. 1.0 Getting NMS Classes
  169. Example:
  170. NMS.PacketPlayOutChat;
  171. NMS['EntityPlayer'];
  172. CraftBukkit
  173. This class allows you to get org.bukkit.craftbukkit.$version classes
  174. 1.0 Getting CraftBukkit Classes
  175. Example:
  176. CraftBukkit.CraftServer;
  177. CraftBukkit['CraftServer']
  178. Craft
  179. Similar to CraftBukkit
  180. See CraftBukkit
  181. InventoryType
  182. An enum to inventory types
  183. See org.bukkit.inventory.InventoryType
  184. Command Builder
  185. This allows you to register a command
  186. 1.0 Creating a Command Builder
  187. Example:
  188. var cmd = Commands['commandName']
  189. 1.1 Adding Command Aliases
  190. Example:
  191. var cmd;
  192. cmd.also('aliasName');
  193. cmd.alias('aliasName'); // alias = also
  194. cmd.also('aliasName').also('aliasName2').alias('aliasName3');
  195. 1.2 Setting Permission
  196. Example:
  197. var cmd;
  198. cmd.permission('permission.example');
  199. cmd.permissionMessage('You dont have permission fool!');
  200. 1.3 Adding Executor
  201. Example:
  202. var cmd;
  203. cmd.executor(function(sender,args)) {
  204. // sender is org.bukkit.command.CommandSender
  205. // args is String array (String[])
  206. );
  207. 1.4 Adding Tab Completer
  208. Example;
  209. var cmd;
  210. cmd.tabcompleter(function(sender,args)) {
  211. // sender is org.bukkit.command.CommandSender
  212. // args is String array (String[])
  213. // must return a String array
  214. return ['completer','here'];
  215. };
  216. 1.5 Registering the Command
  217. Example:
  218. var cmd;
  219. cmd.register();
  220. 1.6 Unregistering the Command
  221. Example:
  222. var cmd;
  223. cmd.unregister();
  224. Listener Builder
  225. This allows you to listen Bukkit / Plugin events
  226. 1.0 Creating the Listener
  227. Example:
  228. var listener = Events['event name']
  229. var listener = Events['com.example.plugin.events.ExamplePluginEvent']
  230. var listener = Events['player.PlayerJoinEvent']
  231. 1.1 Listening the Event
  232. Example:
  233. var listener; // listener builder instance
  234. listener.listen(function(event)) {
  235. //do something with the event
  236. });
  237. // #listen(PRIORITY, FUNCTION)
  238. listener.listen('LOWEST',function(event)) {
  239. //do something with the event
  240. });
  241. 1.2 Unlisten the Listener Builder
  242. Example:
  243. var listener; // listener builder instance
  244. listener.unregister();
  245. Entity Builder
  246. This allows you to spawn an Entity
  247. 1.0 Creating the Builder
  248. Example:
  249. var entity = Entities.ENTITY_TYPE;
  250. var entity = Entities.ARMOR_STAND;
  251. var entity = Entities['ARMOR_STAND']
  252. 1.1 Spawning the Entity
  253. Example:
  254. var entity;
  255. var playerExample; // see org.bukkit.entity.Player
  256. entity.spawn(LOCATION);
  257. entity.spawn(new Location(Worlds['world_nether'],10,10,10)); // see org.bukkit.Location
  258. entity.spawn(playerExample.getLocation()); // see org.bukkit.entity.Player
  259. Item Builder
  260. This allows you to create an Item
  261. 1.0 Creating an Item
  262. Example:
  263. Items.APPLE;
  264. Items['APPLE'];
  265. 1.1 Available Functions
  266. ItemBuilder#executor(function(clickEvent)); // Set the executor for GUI Click
  267. ItemBuilder#name(String) // set the display name
  268. ItemBuilder#lore(String...) // set the lore
  269. Example:
  270. var item;
  271. item.lore('this','is','multiple','line','lore');
  272. ItemBuilder#meta(function(meta)); // consume the ItemMeta (see org.bukkit.inventory.meta.ItemMeta)
  273. ItemBuilder#flag(String...) // set the flags (see org.bukkit.inventory.ItemFlag)
  274. Example:
  275. var item;
  276. item.flag('HIDE_ENCHANTS');
  277. item.flag(); // will use all flags
  278. item.flag('HIDE_ENCHANTS', 'HIDE_UNBREAKABLE');
  279. ItemBuilder#unbreakable(boolean) // set unbreakable
  280. ItemBuilder#type(String) // set the type
  281. ItemBuilder#amount(number) // set the amount
  282. ItemBuilder#enchant(String,level) // add the enchantment (see org.bukkit.enchantments.Enchantment)
  283. ItemBuilder#unenchant(String) // remove the enchantment
  284. and more from org.bukkit.inventory.ItemStack
  285. File Streamer
  286. This allows you to control file from your script package configuration folder ("./plugins/PandawaJS/configurations/<packageName>/")
  287. 1.0 Creating the Streamer
  288. Example:
  289. Files['config.yml']
  290. 1.1 Available Functions
  291. FileStreamer#input() // return InputStream
  292. FileStreamer#output() // return OutputStream
  293. FileStreamer#reader() // return Reader
  294. FileStreamer#writer() // return Writer
  295. FileStreamer#write(Object) // write Stringified Object
  296. FileStreamer#readAll() // read file and return String
  297. FileStreamer#loadConfig() // read file as Yaml config
  298. FileStreamer#copy(InputStream) // write from inputstream
  299. and other functions from java.io.File
  300. Potion Builder
  301. This allows you to create PotionEffect object to apply on a LivingEntity (player, animals, monsters, creature)
  302. 1.0 Creating the Builder
  303. Example:
  304. Potions['SPEED'];
  305. Potions.JUMP;
  306. See org.bukkit.potion.PotionEffectType
  307. 1.1 Available Functions
  308. PotionBuilder#apply(LivingEntity) // see org.bukkit.entity.LivingEntity (could be Player, ArmorStand, Wolf, Zombies, etc)
  309. PotionBuilder#type(String) // set the Potion effect type
  310. PotionBuilder#ambient() // return boolean ambient state
  311. PotionBuilder#ambient(boolean) // set ambient state
  312. PotionBuilder#particles() // return boolean particles state
  313. PotionBuilder#duration() // return duration in tick (integer/number)
  314. PotionBuilder#duration(number) // set the duration (in ticks)
  315. PotionBuilder#amplifier() // return the amplifier level
  316. PotionBuilder#amplifier(number) // set the amplifier level
  317. Pandawa Package
  318. This class controls aspect of your script
  319. Default package name is 'default' can be get by Packages.default or Packages['default']
  320. Available Functions:
  321. Package#getName() // return the package name
  322. Package#getAuthor() // return the author
  323. Package#getVersion() // return the package version
  324. Package#getDependencies() // return the dependencies list
  325. Package#getMainScript() // return main script name
  326. Package#getScript() // return a script, See Pandawa Script
  327. Package#getAPI() // return PandawaJS API, See PandawaAPI
  328. Package#getPandawa() // get the core, See Pandawa
  329. Pandawa Script
  330. This class is basically class to hold your script.
  331. All functions and variables are shareable.
  332. Example:
  333. var script1 = Scripts['ScriptExample'];
  334. script1.doTheThing(); // this will call function 'doTheThing' from script1 (ScriptExample)
  335. PandawaAPI
  336. Functions:
  337. PandawaAPI#registerImp(String,PandawaImpPackage)
  338. PandawaAPI#unregisterImp(String)
  339. PandawaAPI#getDefaultPackage()
  340. PandawaAPI#getPackage(String)
  341. PandawaAPI#getLoadedPackages()
  342. PandawaAPI#readPandawa(File)
  343. PandawaAPI#registerImplementation(Object)
  344. Pandawa
  345. Pandawa#getPackage() // get the package
  346. Pandawa#queueLoad() // avoid using this
  347. Pandawa#getResource() // get the resource file inside pandawa (from .zip or directory) See PandawaResource
  348. PandawaResource
  349. PandawaResource#getName() // get the resource/file name
  350. PandawaResource#openStream() // create new InputStream for this resource
  351. PandawaResource#getPackage() // get package owner
  352. PandawaResource#saveResource() // save the resource
  353. Request Builder
  354. This allows you to request event from Player
  355. 1.0 Creating the Builder
  356. Example:
  357. Requests.CHAT;
  358. Requests.CLICK;
  359. Requests['CHAT'];
  360. Requests['CLICK'];
  361. 1.1 Requesting a Chat
  362. Example:
  363. var req = Requests.CHAT;
  364. req.request(Players.Septogeddon, function(event) {
  365. Players.Septogeddon.sendMessage('You just chat: '+event.getMessage()); //see org.bukkit.event.player.AsyncPlayerChatEvent
  366. });
  367. 1.2 Requesting a Click
  368. Example:
  369. var req = Requests.CLICK;
  370. req.request(Players.Septogeddon, function(event) {
  371. Players.Septogeddon.sendMessage('You just chat: '+event.getClickedBlock()); //see org.bukkit.event.player.PlayerInteractEvent
  372. });
  373. 1.3 Cancelling Request
  374. Example:
  375. var req; // request builder instance
  376. req.cancel('PlayerName');
  377. req.cancel(Players.Septogeddon);
  378.  
  379. Commands
  380. It will return a Command builder.
  381. Usage:
  382. Commands['commandName']
  383. Commands.commandNameWithoutSpace
  384. See Command builder
  385. Players
  386. It will return a Player (Online Player)
  387. Usage:
  388. Players.Septogeddon
  389. Players['Septogeddon']
  390. for (var player in Players)
  391. See org.bukkit.entity.Player
  392. Worlds
  393. It will return a World
  394. Usage:
  395. Worlds.world_nether
  396. Worlds['world_the_end']
  397. for (var world in Worlds)
  398. See org.bukkit.entity.Worlds
  399. Events
  400. It will return a Listener builder
  401. Usage:
  402. Events['player.PlayerJoinEvent']
  403. Events['org.bukkit.event.player.PlayerJoinEvent']
  404. See Listener builder
  405. Entities
  406. It will return an Entity builder
  407. Usage:
  408. Entities.ARMOR_STAND
  409. Entities['ARMOR_STAND']
  410. See Entity builder
  411. Items
  412. It will return an Item builder
  413. Usage:
  414. Items.GOLDEN_APPLE
  415. Items['APPLE']
  416. See Item builder
  417. See org.bukkit.inventory.ItemStack
  418. Files
  419. It will return a File streamer
  420. Usage:
  421. Files['config.yml']
  422. See File Streamer
  423. See java.io.File
  424. Potions
  425. It will return a Potion builder
  426. Usage:
  427. Potions.CONFUSION
  428. Potions['SPEED']
  429. See Potion Builder
  430. See org.bukkit.potion.PotionEffectType
  431. PandawaPackages
  432. It will return a Pandawa Package
  433. Usage:
  434. Packages['default']
  435. Packages.SeptogeddonJSPacks
  436. See Pandawa Package
  437. Scripts
  438. It will return a Pandawa Script
  439. Usage:
  440. Scripts['SimpleSystemInformation']
  441. Scripts.SimpleGUI
  442. See Pandawa Script
  443. Plugins
  444. It will return a Main Plugin Instance
  445. Usage:
  446. Plugins['WorldEdit']
  447. Plugins.Essentials
  448. See org.bukkit.plugin.Plugin
  449. See org.bukkit.plugin.java.JavaPlugin
  450. Test
  451. Used to debug the plugin, should not be used.
  452. Requests
  453. It will return Request Builder
  454. Usage:
  455. Requests.CHAT;
  456. Requests.CLICK;
  457. See Request Builder
Advertisement
Add Comment
Please, Sign In to add comment