Advertisement
Guest User

Untitled

a guest
May 12th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var blocks = {};
  2.  
  3. function onGameInitializationEvent(event){    
  4.     handleStart();
  5. }
  6.  
  7. function onStart(){    
  8.     handleStart();
  9. }
  10.  
  11. function onGameStoppingServerEvent(event){
  12.     handleStop();
  13. }
  14.  
  15. function onStop(){
  16.     handleStop();
  17. }
  18.  
  19. function handleStart(){
  20.     fileManager.create("blocks.json");
  21.     var fileJSON = JSON.parse(fileManager.read("blocks.json"));
  22.  
  23.     if(fileJSON != null)
  24.         blocks = fileJSON;
  25.  
  26.     console.log("First plugin loaded!");
  27.  
  28.     commandManager.register(createCommand());
  29.     eventManager.register(createEventListenerBlockBreak());
  30. }
  31.  
  32. function handleStop(){
  33.     fileManager.write("blocks.json", JSON.stringify(blocks));
  34. }
  35.  
  36.  
  37. function createEventListenerBlockBreak(){
  38.     var eventListener = {
  39.             listener: function(event, player) {
  40.                 //Name of the block break
  41.                 var name = event.transactions[0].original.state.type.name+"";
  42.  
  43.                 //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.
  44.                 if(player){
  45.                     player.sendMessage(Text.of("You broke a block ("+name+")"));
  46.                    
  47.                     if(blocks[name]){
  48.                         economyService.addMoney(player, parseFloat(blocks[name]));
  49.                         player.sendMessage(Text.of("You received ", TextColors.GREEN, blocks[name]+" "+economyService.currency.symbol.toPlain));
  50.                     }
  51.                 }
  52.             },
  53.             event: org.spongepowered.api.event.block.ChangeBlockEvent.Break.class
  54.         };
  55.  
  56.     return eventListener;
  57. }
  58.  
  59. function createCommand(){
  60.     var command = {
  61.             description: "Set the amount of money to receive when you break this block.",
  62.             permission: "job.set.amount",
  63.             executor: function(commandSource, commandContext) {
  64.                 //If the commandSource is a player, it set the price of the block and informs the player the price has been set.
  65.                 if(commandSource instanceof Player.class){                    
  66.                     blocks[commandContext.one("blockId").get+""] = Javascript.convertJSObjectToObject(commandContext.one("amount").get);
  67.                    
  68.                     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));                  
  69.                 }
  70.             },
  71.             commands: ["job", "jsJob"],
  72.             arguments: [
  73.                 {
  74.                     format: "onlyOne",
  75.                     name: "blockId"
  76.                 },
  77.                 {
  78.                     format: "onlyOne",
  79.                     type: "doubleNum",
  80.                     name: "amount"
  81.                 }
  82.             ]
  83.         };
  84.  
  85.     return command;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement