Advertisement
Guest User

BreakBonus

a guest
Aug 14th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.33 KB | None | 0 0
  1. package me.Gust09.BreakBonus;
  2.  
  3. import java.util.Arrays;
  4. import java.util.logging.Logger;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.Material;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.EventHandler;
  12. import org.bukkit.event.Listener;
  13. import org.bukkit.event.block.BlockBreakEvent;
  14. import org.bukkit.event.player.PlayerJoinEvent;
  15. import org.bukkit.inventory.ItemStack;
  16. import org.bukkit.inventory.meta.ItemMeta;
  17. import org.bukkit.plugin.java.JavaPlugin;
  18.  
  19. public class BreakBonus extends JavaPlugin implements Listener{
  20.  
  21.     Logger myLogger = Bukkit.getLogger();
  22.    
  23.     @Override
  24.     public void onEnable(){
  25.         myLogger.info("BreakBonus Enabled");
  26.         loadConfiguration();
  27.         Bukkit.getPluginManager().registerEvents(this, this);
  28.        
  29.         }
  30.  
  31.     @Override
  32.     public void onDisable(){
  33.         myLogger.info("BreakBonus Disabled");
  34.     }
  35.    
  36.     public void loadConfiguration(){
  37.          getConfig().options().copyDefaults(true);
  38.          saveConfig();
  39.          
  40.     }
  41.    
  42.     @EventHandler
  43.     public void onPlayerJoin(PlayerJoinEvent join){
  44.        
  45.         Player joiner = join.getPlayer();
  46.         String path = "Data.";
  47.        
  48.         if(getConfig().getString("Data." + joiner.getName()) == null){
  49.             myLogger.info("[BreakBonus] Player Data not found for " + joiner.getName() + ". Creating now!");
  50.             getConfig().set(path + joiner.getName(), 0);
  51.             saveConfig();
  52.         }
  53.         else{
  54.             myLogger.info("[BreakBonus] Loaded Player Data for " + joiner.getName() + "!");
  55.            
  56.         }
  57.     }
  58.    
  59.     @EventHandler
  60.     public void onBlockBreak(BlockBreakEvent event){
  61.        
  62.         Player p = event.getPlayer();
  63.        
  64.         int blockId1 = getConfig().getInt("Config.BLOCK1");
  65.         int blockId2 = getConfig().getInt("Config.BLOCK2");
  66.         int blockId3 = getConfig().getInt("Config.BLOCK3");
  67.         int blockId4 = getConfig().getInt("Config.BLOCK4");
  68.         int blockId5 = getConfig().getInt("Config.BLOCK5");
  69.         int blockId6 = getConfig().getInt("Config.BLOCK6");
  70.         int blockId7 = getConfig().getInt("Config.BLOCK7");
  71.         int blockId8 = getConfig().getInt("Config.BLOCK8");
  72.         int blockId9 = getConfig().getInt("Config.BLOCK9");
  73.         int blockId10 = getConfig().getInt("Config.BLOCK10");
  74.         int blockId11 = getConfig().getInt("Config.BLOCK11");
  75.         int blockId12 = getConfig().getInt("Config.BLOCK12");
  76.         int blockId13 = getConfig().getInt("Config.BLOCK13");
  77.         int blockId14 = getConfig().getInt("Config.BLOCK14");
  78.         int blockId15 = getConfig().getInt("Config.BLOCK15");
  79.         int blockId16 = getConfig().getInt("Config.BLOCK16");
  80.         @SuppressWarnings("deprecation")
  81.         int blockBroken = event.getBlock().getTypeId();
  82.                
  83.         if((blockBroken == (blockId1)) || (blockBroken == (blockId2)) || (blockBroken == (blockId3)) || (blockBroken == (blockId4))
  84.         || (blockBroken == (blockId5)) || (blockBroken == (blockId6)) || (blockBroken == (blockId7)) || (blockBroken == (blockId8))
  85.         || (blockBroken == (blockId9)) || (blockBroken == (blockId10)) || (blockBroken == (blockId11)) || (blockBroken == (blockId12))
  86.         || (blockBroken == (blockId13)) || (blockBroken == (blockId14)) || (blockBroken == (blockId15)) || (blockBroken == (blockId16))){
  87.            
  88.             int brokenBlocks = getConfig().getInt("Data." + p.getName());
  89.             int targetBlocks = getConfig().getInt("Config.OBJECTIVE");
  90.            
  91.             if(brokenBlocks > targetBlocks){
  92.                 myLogger.info("[BreakBonus] Player " + p.getName() + " has more broken blocks than the Objective. Reseting now!");
  93.                 getConfig().set("Data." + p.getName(), 0);
  94.                 saveConfig();
  95.             }
  96.             else{
  97.             getConfig().set("Data." + p.getName(), (brokenBlocks + 1));
  98.             saveConfig();
  99.             }
  100.         }
  101.        
  102.         if(getConfig().getInt("Data." + p.getName()) == getConfig().getInt("Config.OBJECTIVE")){
  103.             p.sendMessage(getConfig().getString("Config.String_BonusFound"));
  104.            
  105.             ItemStack item = new ItemStack(Material.DIAMOND, 1);
  106.             ItemMeta meta = item.getItemMeta();
  107.                    
  108.             meta.setDisplayName("Diamond");
  109.             meta.setLore(Arrays.asList("\2477Bonus"));
  110.             item.setItemMeta(meta);
  111.                        
  112.             p.getWorld().dropItem(p.getLocation(), item);
  113.            
  114.             getConfig().set("Data." + p.getName(), 0);
  115.             saveConfig();
  116.         }  
  117.        
  118.     }
  119.        
  120.         public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args){
  121.             if(commandLabel.equalsIgnoreCase("bbreload")){
  122.                 reloadConfig();
  123.                 theSender.sendMessage("\247aConfig Reloaded");
  124.             }
  125.            
  126.             return false;
  127.         }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement