Advertisement
Guest User

Untitled

a guest
Sep 16th, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.23 KB | None | 0 0
  1. package net.livecraft.DrAgonmoray.DropBlocks;
  2.  
  3.  
  4. import java.util.HashMap;
  5.  
  6. import org.bukkit.event.Event;
  7. import org.bukkit.plugin.PluginManager;
  8. import org.bukkit.plugin.java.JavaPlugin;
  9.  
  10. public class DropBlocks extends JavaPlugin {
  11.     private final GRBlockListener blockListener = new GRBlockListener(this);
  12.     public Config config = new Config(this);
  13.     public int time = 30;
  14.     public HashMap<Integer, Integer> times = new HashMap<Integer, Integer>();
  15.     public void onDisable() {
  16.         System.out.println("DropBlocks disabled.");
  17.     }
  18.  
  19.     @Override
  20.     public void onEnable() {
  21.         PluginManager pm = getServer().getPluginManager();
  22.         config.configCheck();
  23.         pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Event.Priority.Monitor, this);
  24.         System.out.println("DropBlocks enabled.");
  25.     }
  26.  
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. package net.livecraft.DrAgonmoray.DropBlocks;
  43.  
  44. import org.bukkit.Location;
  45. import org.bukkit.block.Block;
  46. import org.bukkit.event.block.BlockBreakEvent;
  47. import org.bukkit.event.block.BlockListener;
  48.  
  49. public class GRBlockListener extends BlockListener {
  50.     public static DropBlocks plugin;
  51.     public GRBlockListener(DropBlocks instance) {
  52.         plugin = instance;
  53.     }
  54.    
  55.     public long getTime(int id) {
  56.         if (plugin.times.containsKey(id)) {
  57.             return (long)plugin.times.get(id);
  58.         } else {
  59.             return (long)plugin.time;
  60.         }
  61.     }
  62.     public void onBlockBreak(BlockBreakEvent event) {
  63.         Block block = event.getBlock();
  64.         if (event.isCancelled()) return;
  65.         plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new task(block.getTypeId(), block.getData(), block.getLocation()), getTime(block.getTypeId())*1200);
  66.     }
  67.    
  68.     private class task implements Runnable { //Thanks V10lator
  69.         private final int type;
  70.         private final byte data;
  71.         private final Location loc;
  72.        
  73.         private task(int type, byte data, Location loc) {
  74.             this.type = type;
  75.             this.data = data;
  76.             this.loc = loc;
  77.         }
  78.        
  79.         public void run() {
  80.             loc.getWorld().getBlockAt(loc).setTypeIdAndData(type, data, false);
  81.         }
  82.        
  83.     }
  84.  
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. package net.livecraft.DrAgonmoray.DropBlocks;
  101.  
  102. import java.io.File;
  103.  
  104. import org.bukkit.util.config.Configuration;
  105.  
  106. public class Config {
  107.     private static DropBlocks plugin;
  108.     public Config(DropBlocks instance) {
  109.         plugin = instance;
  110.     }
  111.    
  112.     public String directory = "plugins" + File.separator + "DropBlocks";
  113.     File file = new File(directory + File.separator + "config.yml");
  114.    
  115.     public Configuration config;
  116.  
  117.     public void configCheck() {
  118.         try {
  119.             new File(directory).mkdir();
  120.             if (!file.exists()) {
  121.                 file.createNewFile();
  122.             }
  123.             config = new Configuration(file);
  124.             loadconfig();
  125.         } catch (Exception e) {
  126.             e.printStackTrace();
  127.         }
  128.     }
  129.    
  130.     public int readInt(String node, int def) {
  131.         Object v = config.getProperty(node);
  132.         if (v != null) {
  133.             return config.getInt(node, 0);
  134.         } else {
  135.             config.setProperty(node, def);
  136.             config.save();
  137.             return def;
  138.         }
  139.     }
  140.  
  141.     public void loadconfig() {
  142.         config.load();
  143.         plugin.time = readInt("default", 30);
  144.         for (String key : config.getKeys()) {
  145.             if (!key.equals("default")) {
  146.                 for (int i : config.getIntList(key+".ids", null)) {
  147.                     plugin.times.put(i, config.getInt(key+".time", plugin.time));
  148.                 }
  149.             }
  150.         }
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement