Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.Gust09.BreakBonus;
- import java.util.Arrays;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.Material;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- public class BreakBonus extends JavaPlugin implements Listener{
- Logger myLogger = Bukkit.getLogger();
- @Override
- public void onEnable(){
- myLogger.info("BreakBonus Enabled");
- loadConfiguration();
- Bukkit.getPluginManager().registerEvents(this, this);
- }
- @Override
- public void onDisable(){
- myLogger.info("BreakBonus Disabled");
- }
- public void loadConfiguration(){
- getConfig().options().copyDefaults(true);
- saveConfig();
- }
- @EventHandler
- public void onPlayerJoin(PlayerJoinEvent join){
- Player joiner = join.getPlayer();
- String path = "Data.";
- if(getConfig().getString("Data." + joiner.getName()) == null){
- myLogger.info("[BreakBonus] Player Data not found for " + joiner.getName() + ". Creating now!");
- getConfig().set(path + joiner.getName(), 0);
- saveConfig();
- }
- else{
- myLogger.info("[BreakBonus] Loaded Player Data for " + joiner.getName() + "!");
- }
- }
- @EventHandler
- public void onBlockBreak(BlockBreakEvent event){
- Player p = event.getPlayer();
- int blockId1 = getConfig().getInt("Config.BLOCK1");
- int blockId2 = getConfig().getInt("Config.BLOCK2");
- int blockId3 = getConfig().getInt("Config.BLOCK3");
- int blockId4 = getConfig().getInt("Config.BLOCK4");
- int blockId5 = getConfig().getInt("Config.BLOCK5");
- int blockId6 = getConfig().getInt("Config.BLOCK6");
- int blockId7 = getConfig().getInt("Config.BLOCK7");
- int blockId8 = getConfig().getInt("Config.BLOCK8");
- int blockId9 = getConfig().getInt("Config.BLOCK9");
- int blockId10 = getConfig().getInt("Config.BLOCK10");
- int blockId11 = getConfig().getInt("Config.BLOCK11");
- int blockId12 = getConfig().getInt("Config.BLOCK12");
- int blockId13 = getConfig().getInt("Config.BLOCK13");
- int blockId14 = getConfig().getInt("Config.BLOCK14");
- int blockId15 = getConfig().getInt("Config.BLOCK15");
- int blockId16 = getConfig().getInt("Config.BLOCK16");
- @SuppressWarnings("deprecation")
- int blockBroken = event.getBlock().getTypeId();
- if((blockBroken == (blockId1)) || (blockBroken == (blockId2)) || (blockBroken == (blockId3)) || (blockBroken == (blockId4))
- || (blockBroken == (blockId5)) || (blockBroken == (blockId6)) || (blockBroken == (blockId7)) || (blockBroken == (blockId8))
- || (blockBroken == (blockId9)) || (blockBroken == (blockId10)) || (blockBroken == (blockId11)) || (blockBroken == (blockId12))
- || (blockBroken == (blockId13)) || (blockBroken == (blockId14)) || (blockBroken == (blockId15)) || (blockBroken == (blockId16))){
- int brokenBlocks = getConfig().getInt("Data." + p.getName());
- int targetBlocks = getConfig().getInt("Config.OBJECTIVE");
- if(brokenBlocks > targetBlocks){
- myLogger.info("[BreakBonus] Player " + p.getName() + " has more broken blocks than the Objective. Reseting now!");
- getConfig().set("Data." + p.getName(), 0);
- saveConfig();
- }
- else{
- getConfig().set("Data." + p.getName(), (brokenBlocks + 1));
- saveConfig();
- }
- }
- if(getConfig().getInt("Data." + p.getName()) == getConfig().getInt("Config.OBJECTIVE")){
- p.sendMessage(getConfig().getString("Config.String_BonusFound"));
- ItemStack item = new ItemStack(Material.DIAMOND, 1);
- ItemMeta meta = item.getItemMeta();
- meta.setDisplayName("Diamond");
- meta.setLore(Arrays.asList("\2477Bonus"));
- item.setItemMeta(meta);
- p.getWorld().dropItem(p.getLocation(), item);
- getConfig().set("Data." + p.getName(), 0);
- saveConfig();
- }
- }
- public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args){
- if(commandLabel.equalsIgnoreCase("bbreload")){
- reloadConfig();
- theSender.sendMessage("\247aConfig Reloaded");
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement