Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.livecraft.DrAgonmoray.DropBlocks;
- import java.util.HashMap;
- import org.bukkit.event.Event;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- public class DropBlocks extends JavaPlugin {
- private final GRBlockListener blockListener = new GRBlockListener(this);
- public Config config = new Config(this);
- public int time = 30;
- public HashMap<Integer, Integer> times = new HashMap<Integer, Integer>();
- public void onDisable() {
- System.out.println("DropBlocks disabled.");
- }
- @Override
- public void onEnable() {
- PluginManager pm = getServer().getPluginManager();
- config.configCheck();
- pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Event.Priority.Monitor, this);
- System.out.println("DropBlocks enabled.");
- }
- }
- package net.livecraft.DrAgonmoray.DropBlocks;
- import org.bukkit.Location;
- import org.bukkit.block.Block;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.block.BlockListener;
- public class GRBlockListener extends BlockListener {
- public static DropBlocks plugin;
- public GRBlockListener(DropBlocks instance) {
- plugin = instance;
- }
- public long getTime(int id) {
- if (plugin.times.containsKey(id)) {
- return (long)plugin.times.get(id);
- } else {
- return (long)plugin.time;
- }
- }
- public void onBlockBreak(BlockBreakEvent event) {
- Block block = event.getBlock();
- if (event.isCancelled()) return;
- plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new task(block.getTypeId(), block.getData(), block.getLocation()), getTime(block.getTypeId())*1200);
- }
- private class task implements Runnable { //Thanks V10lator
- private final int type;
- private final byte data;
- private final Location loc;
- private task(int type, byte data, Location loc) {
- this.type = type;
- this.data = data;
- this.loc = loc;
- }
- public void run() {
- loc.getWorld().getBlockAt(loc).setTypeIdAndData(type, data, false);
- }
- }
- }
- package net.livecraft.DrAgonmoray.DropBlocks;
- import java.io.File;
- import org.bukkit.util.config.Configuration;
- public class Config {
- private static DropBlocks plugin;
- public Config(DropBlocks instance) {
- plugin = instance;
- }
- public String directory = "plugins" + File.separator + "DropBlocks";
- File file = new File(directory + File.separator + "config.yml");
- public Configuration config;
- public void configCheck() {
- try {
- new File(directory).mkdir();
- if (!file.exists()) {
- file.createNewFile();
- }
- config = new Configuration(file);
- loadconfig();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public int readInt(String node, int def) {
- Object v = config.getProperty(node);
- if (v != null) {
- return config.getInt(node, 0);
- } else {
- config.setProperty(node, def);
- config.save();
- return def;
- }
- }
- public void loadconfig() {
- config.load();
- plugin.time = readInt("default", 30);
- for (String key : config.getKeys()) {
- if (!key.equals("default")) {
- for (int i : config.getIntList(key+".ids", null)) {
- plugin.times.put(i, config.getInt(key+".time", plugin.time));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement