Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.39 KB | None | 0 0
  1. public class Thermo
  2.   implements Listener
  3. {
  4.   private static final List<BlockFace> FACES = Arrays.asList(new BlockFace[] {
  5.     BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH,
  6.     BlockFace.WEST });
  7.   private static final List<Material> LAVA = Arrays.asList(new Material[] {
  8.     Material.STATIONARY_LAVA, Material.LAVA });
  9.   private static final List<Material> WATER = Arrays.asList(new Material[] {
  10.     Material.STATIONARY_WATER, Material.WATER });
  11.   HashMap<String, Long> cooldown = new HashMap();
  12.   int time = 10;
  13.  
  14.   private static void collectFluid(Block anchor, Map<Block, Material> collected, List<Material> fluid)
  15.   {
  16.     if ((fluid.contains(anchor.getType())) &&
  17.       (!collected.keySet().contains(anchor)))
  18.     {
  19.       collected.put(anchor, anchor.getType());
  20.       for (BlockFace face : FACES) {
  21.         collectFluid(anchor.getRelative(face), collected, fluid);
  22.       }
  23.     }
  24.   }
  25.  
  26.   private static Material getOpposite(Material fluid)
  27.   {
  28.     switch (fluid)
  29.     {
  30.     case BED_BLOCK:
  31.       return Material.WATER;
  32.     case BIRCH_WOOD_STAIRS:
  33.       return Material.STATIONARY_WATER;
  34.     case BEDROCK:
  35.       return Material.STATIONARY_LAVA;
  36.     case BED:
  37.       return Material.LAVA;
  38.     }
  39.     return Material.AIR;
  40.   }
  41.  
  42.   @EventHandler
  43.   public void onPlayerInteract(PlayerInteractEvent event)
  44.   {
  45.     if ((event.getAction() == Action.RIGHT_CLICK_BLOCK) &&
  46.       (event.getMaterial() == Material.DAYLIGHT_DETECTOR))
  47.     {
  48.       Player player = event.getPlayer();
  49.       Block anchor = event.getClickedBlock().getRelative(
  50.         event.getBlockFace());
  51.       if ((anchor.getType() == Material.STATIONARY_LAVA) || (
  52.         (anchor.getType() == Material.STATIONARY_WATER) &&
  53.         (Kit.getKit(player).equals("thermo"))))
  54.       {
  55.         if (this.cooldown.containsKey(player.getName()))
  56.         {
  57.           long timeleft = ((Long)this.cooldown.get(player.getName()))
  58.             .longValue() /
  59.             1000L +
  60.             this.time -
  61.             System.currentTimeMillis() / 1000L;
  62.           if (timeleft > 0L)
  63.           {
  64.             player.sendMessage("§cRecharging --- " + timeleft +
  65.               "% left.");
  66.             event.setCancelled(true);
  67.             return;
  68.           }
  69.         }
  70.         Map<Block, Material> fluidBlocks = new HashMap();
  71.         collectFluid(anchor, fluidBlocks,
  72.           anchor.getType() == Material.STATIONARY_LAVA ? LAVA :
  73.           WATER);
  74.         for (Block fluidBlock : fluidBlocks.keySet()) {
  75.           fluidBlock.setType(Material.AIR);
  76.         }
  77.         ??? = fluidBlocks.entrySet().iterator();
  78.         while (???.hasNext())
  79.         {
  80.           Map.Entry<Block, Material> fluidBlock = (Map.Entry)???.next();
  81.           ((Block)fluidBlock.getKey()).setType(
  82.             getOpposite((Material)fluidBlock.getValue()));
  83.         }
  84.         event.setCancelled(true);
  85.         this.cooldown.put(player.getName(), Long.valueOf(System.currentTimeMillis()));
  86.       }
  87.     }
  88.   }
  89.  
  90.   @EventHandler
  91.   public void onPlace(BlockPlaceEvent event)
  92.   {
  93.     if ((event.getBlockPlaced().getType().equals(Material.DAYLIGHT_DETECTOR)) &&
  94.       (Kit.getKit(event.getPlayer()).equals("thermo"))) {
  95.       event.setCancelled(true);
  96.     }
  97.   }
  98.  
  99.   @EventHandler
  100.   public void generateObsi(BlockPhysicsEvent e)
  101.   {
  102.     if (e.getChangedType() == Material.OBSIDIAN) {
  103.       e.setCancelled(true);
  104.     }
  105.   }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement