Advertisement
demkom

Untitled

Mar 24th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.65 KB | None | 0 0
  1. package me.xdip.rp;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import org.bukkit.Chunk;
  6. import org.bukkit.Effect;
  7. import org.bukkit.Location;
  8. import org.bukkit.Material;
  9. import org.bukkit.Server;
  10. import org.bukkit.Sound;
  11. import org.bukkit.World;
  12. import org.bukkit.block.Block;
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.EventPriority;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.block.BlockPistonExtendEvent;
  17. import org.bukkit.event.block.BlockPistonRetractEvent;
  18. import org.bukkit.event.block.BlockRedstoneEvent;
  19. import org.bukkit.plugin.PluginManager;
  20. import org.bukkit.plugin.java.JavaPlugin;
  21. import org.bukkit.scheduler.BukkitScheduler;
  22.  
  23. public class Main extends JavaPlugin
  24.   implements Listener
  25. {
  26.   Map<Chunk, Integer> ratio = new HashMap();
  27.   Map<Chunk, Integer> ticks = new HashMap();
  28.   int[] ids = { 75, 76, 93, 94, 149 };
  29.  
  30.   public void onEnable() {
  31.     getServer().getPluginManager().registerEvents(this, this);
  32.   }
  33.  
  34.   @EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
  35.   public void onBlockRedstoneChange(BlockRedstoneEvent event) {
  36.     Block block = event.getBlock();
  37.     Chunk chunk = block.getChunk();
  38.     World world = block.getWorld();
  39.     int worldTime = (int)world.getTime();
  40.     if (!this.ticks.containsKey(chunk)) {
  41.       redstonePut(chunk, 1, worldTime);
  42.     } else {
  43.       int r = ((Integer)this.ratio.get(chunk)).intValue();
  44.       if ((((Integer)this.ticks.get(chunk)).intValue() < 12) && (((Integer)this.ticks.get(chunk)).intValue() - 10 > worldTime)) {
  45.         redstoneRemove(chunk);
  46.       } else if (((Integer)this.ticks.get(chunk)).intValue() + 5 > worldTime) {
  47.         int bid = block.getTypeId();
  48.         byte bdata = block.getData();
  49.         if (bid == 55) {
  50.           if (bdata <= 2)
  51.             r++;
  52.         }
  53.         else for (int id : this.ids)
  54.             if (bid == id)
  55.               r++;
  56.         Location loc = block.getLocation();
  57.         if (r > 2000) {
  58.           if (bid == 55) {
  59.             block.setType(Material.FIRE);
  60.             world.playEffect(loc, Effect.EXPLOSION_HUGE, 1);
  61.             world.playSound(loc, Sound.EXPLODE, 1.0F, 1.0F);
  62.           } else {
  63.             for (int id : this.ids)
  64.               if (bid == id) {
  65.                 getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(block, world, loc)
  66.                 {
  67.                   public void run() {
  68.                     this.val$block.setType(Material.FIRE);
  69.                     this.val$world.playEffect(this.val$loc, Effect.EXPLOSION_HUGE, 1);
  70.                     this.val$world.playSound(this.val$loc, Sound.EXPLODE, 1.0F, 1.0F);
  71.                   }
  72.                 });
  73.                 break;
  74.               }
  75.           }
  76.           r -= 400;
  77.         } else if (r > 1500) {
  78.           worldTime += 10;
  79.           if ((bid == 76) || (bid == 149))
  80.             world.playSound(loc, Sound.LAVA, 1.0F, 2.0F);
  81.           if ((bid == 93) || (bid == 76) || (bid == 149) || (
  82.             (bid == 55) && (bdata == 1)))
  83.             world.playEffect(loc, Effect.LAVA_POP, 1);
  84.         } else if (r > 1000) {
  85.           worldTime += 6;
  86.           if ((bid == 76) || (bid == 149)) {
  87.             world.playEffect(loc, Effect.LAVA_POP, 1);
  88.             world.playSound(loc, Sound.LAVA, 1.0F, 1.0F);
  89.           }
  90.         } else if ((r > 500) && (r <= 1000)) {
  91.           worldTime += 4;
  92.           if ((bid == 76) || (bid == 149))
  93.             world.playSound(loc, Sound.LAVA, 1.0F, 0.0F);
  94.         } else if (this.ticks.size() > 200) {
  95.           redstoneRemove(chunk);
  96.         }redstonePut(chunk, r, worldTime);
  97.       } else {
  98.         redstoneRemove(chunk);
  99.       }
  100.     }
  101.   }
  102.  
  103.   private void redstonePut(Chunk chunk, int r, int worldTime) {
  104.     this.ratio.put(chunk, Integer.valueOf(r));
  105.     this.ticks.put(chunk, Integer.valueOf(worldTime));
  106.   }
  107.  
  108.   private void redstoneRemove(Chunk chunk) {
  109.     this.ratio.remove(chunk);
  110.     this.ticks.remove(chunk);
  111.   }
  112.   @EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
  113.   public void onBlockPistonExtend(BlockPistonExtendEvent event) {
  114.     Chunk chunk = event.getBlock().getChunk();
  115.     if (this.ratio.containsKey(chunk)) {
  116.       int r = ((Integer)this.ratio.get(chunk)).intValue();
  117.       r += 50;
  118.       this.ratio.put(chunk, Integer.valueOf(r));
  119.     }
  120.   }
  121.  
  122.   @EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
  123.   public void onBlockPistonRetract(BlockPistonRetractEvent event)
  124.   {
  125.     Chunk chunk = event.getBlock().getChunk();
  126.     if (this.ratio.containsKey(chunk)) {
  127.       int r = ((Integer)this.ratio.get(chunk)).intValue();
  128.       r += 50;
  129.       this.ratio.put(chunk, Integer.valueOf(r));
  130.     }
  131.   }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement