Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var blocks = {};
- function onGameInitializationEvent(event){
- handleStart();
- }
- function onStart(){
- handleStart();
- }
- function onGameStoppingServerEvent(event){
- handleStop();
- }
- function onStop(){
- handleStop();
- }
- function handleStart(){
- fileManager.create("blocks.json");
- var fileJSON = JSON.parse(fileManager.read("blocks.json"));
- if(fileJSON != null)
- blocks = fileJSON;
- console.log("First plugin loaded!");
- commandManager.register(createCommand());
- eventManager.register(createEventListenerBlockBreak());
- }
- function handleStop(){
- fileManager.write("blocks.json", JSON.stringify(blocks));
- }
- function createEventListenerBlockBreak(){
- var eventListener = {
- listener: function(event, player) {
- //Name of the block break
- var name = event.transactions[0].original.state.type.name+"";
- //If the player is defined and the block is defined in the list of blocks, it send a message to the player that inform him how much money he received.
- if(player){
- player.sendMessage(Text.of("You broke a block ("+name+")"));
- if(blocks[name]){
- economyService.addMoney(player, parseFloat(blocks[name]));
- player.sendMessage(Text.of("You received ", TextColors.GREEN, blocks[name]+" "+economyService.currency.symbol.toPlain));
- }
- }
- },
- event: org.spongepowered.api.event.block.ChangeBlockEvent.Break.class
- };
- return eventListener;
- }
- function createCommand(){
- var command = {
- description: "Set the amount of money to receive when you break this block.",
- permission: "job.set.amount",
- executor: function(commandSource, commandContext) {
- //If the commandSource is a player, it set the price of the block and informs the player the price has been set.
- if(commandSource instanceof Player.class){
- blocks[commandContext.one("blockId").get+""] = Javascript.convertJSObjectToObject(commandContext.one("amount").get);
- commandSource.sendMessage(Text.of("You set the amount to receive for ", TextColors.GREEN, commandContext.one("blockId").get+"", TextColors.WHITE, " to ", TextColors.GREEN, commandContext.one("amount").get+""+economyService.currency.symbol.toPlain));
- }
- },
- commands: ["job", "jsJob"],
- arguments: [
- {
- format: "onlyOne",
- name: "blockId"
- },
- {
- format: "onlyOne",
- type: "doubleNum",
- name: "amount"
- }
- ]
- };
- return command;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement