Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.V10lator.RenewBlocks;
- import org.bukkit.Chunk;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.event.Event;
- import org.bukkit.event.Event.Priority;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.block.BlockListener;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.util.config.Configuration;
- import couk.Adamki11s.Regios.Regions.GlobalRegionManager;
- import couk.Adamki11s.Regios.Regions.Region;
- public class RenewBlocks extends JavaPlugin
- {
- private boolean regios = false;
- private final RenewBlocks that = this;
- private Configuration config;
- private long delay;
- public void onEnable()
- {
- PluginManager pm = getServer().getPluginManager();
- if(pm.getPlugin("Regios") != null)
- regios = true;
- config = getConfiguration();
- config.load();
- delay = config.getInt("Delay", 0) + 1;
- pm.registerEvent(Event.Type.BLOCK_BREAK, new RBBL(), Priority.Normal, this);
- getServer().getLogger().info("["+getDescription().getName()+"] Enabled!");
- }
- public void onDisable()
- {
- config.setProperty("Delay", delay - 1);
- config.save();
- getServer().getLogger().info("["+getDescription().getName()+"] Disabled!");
- }
- private class RBBL extends BlockListener
- {
- public void onBlockBreak(BlockBreakEvent event)
- {
- if(event.isCancelled())
- return;
- Block block = event.getBlock();
- Chunk chunk = block.getChunk();
- int cx = chunk.getX();
- int cz = chunk.getZ();
- World world = block.getWorld();
- int old = block.getTypeId();
- byte data = block.getData();
- Location loc = block.getLocation();
- if(regios)
- {
- for(Region region: GlobalRegionManager.getRegions())
- {
- for(Chunk c: region.getChunkGrid().getChunks())
- {
- if(!c.getWorld().getName().equals(world) ||
- cx != c.getX() ||
- cz != c.getZ())
- {
- getServer().getScheduler().scheduleSyncDelayedTask(that, new task(old, data, loc), delay);
- }
- }
- }
- }
- else
- getServer().getScheduler().scheduleSyncDelayedTask(that, new task(old, data, loc), 1L);
- }
- }
- private class task implements Runnable
- {
- private final int old;
- private final byte data;
- private final Location loc;
- private task(int old, byte data, Location loc)
- {
- this.old = old;
- this.data = data;
- this.loc = loc;
- }
- public void run()
- {
- loc.getWorld().getBlockAt(loc).setTypeIdAndData(old, data, false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement