Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Thermo
- implements Listener
- {
- private static final List<BlockFace> FACES = Arrays.asList(new BlockFace[] {
- BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH,
- BlockFace.WEST });
- private static final List<Material> LAVA = Arrays.asList(new Material[] {
- Material.STATIONARY_LAVA, Material.LAVA });
- private static final List<Material> WATER = Arrays.asList(new Material[] {
- Material.STATIONARY_WATER, Material.WATER });
- HashMap<String, Long> cooldown = new HashMap();
- int time = 10;
- private static void collectFluid(Block anchor, Map<Block, Material> collected, List<Material> fluid)
- {
- if ((fluid.contains(anchor.getType())) &&
- (!collected.keySet().contains(anchor)))
- {
- collected.put(anchor, anchor.getType());
- for (BlockFace face : FACES) {
- collectFluid(anchor.getRelative(face), collected, fluid);
- }
- }
- }
- private static Material getOpposite(Material fluid)
- {
- switch (fluid)
- {
- case BED_BLOCK:
- return Material.WATER;
- case BIRCH_WOOD_STAIRS:
- return Material.STATIONARY_WATER;
- case BEDROCK:
- return Material.STATIONARY_LAVA;
- case BED:
- return Material.LAVA;
- }
- return Material.AIR;
- }
- @EventHandler
- public void onPlayerInteract(PlayerInteractEvent event)
- {
- if ((event.getAction() == Action.RIGHT_CLICK_BLOCK) &&
- (event.getMaterial() == Material.DAYLIGHT_DETECTOR))
- {
- Player player = event.getPlayer();
- Block anchor = event.getClickedBlock().getRelative(
- event.getBlockFace());
- if ((anchor.getType() == Material.STATIONARY_LAVA) || (
- (anchor.getType() == Material.STATIONARY_WATER) &&
- (Kit.getKit(player).equals("thermo"))))
- {
- if (this.cooldown.containsKey(player.getName()))
- {
- long timeleft = ((Long)this.cooldown.get(player.getName()))
- .longValue() /
- 1000L +
- this.time -
- System.currentTimeMillis() / 1000L;
- if (timeleft > 0L)
- {
- player.sendMessage("§cRecharging --- " + timeleft +
- "% left.");
- event.setCancelled(true);
- return;
- }
- }
- Map<Block, Material> fluidBlocks = new HashMap();
- collectFluid(anchor, fluidBlocks,
- anchor.getType() == Material.STATIONARY_LAVA ? LAVA :
- WATER);
- for (Block fluidBlock : fluidBlocks.keySet()) {
- fluidBlock.setType(Material.AIR);
- }
- ??? = fluidBlocks.entrySet().iterator();
- while (???.hasNext())
- {
- Map.Entry<Block, Material> fluidBlock = (Map.Entry)???.next();
- ((Block)fluidBlock.getKey()).setType(
- getOpposite((Material)fluidBlock.getValue()));
- }
- event.setCancelled(true);
- this.cooldown.put(player.getName(), Long.valueOf(System.currentTimeMillis()));
- }
- }
- }
- @EventHandler
- public void onPlace(BlockPlaceEvent event)
- {
- if ((event.getBlockPlaced().getType().equals(Material.DAYLIGHT_DETECTOR)) &&
- (Kit.getKit(event.getPlayer()).equals("thermo"))) {
- event.setCancelled(true);
- }
- }
- @EventHandler
- public void generateObsi(BlockPhysicsEvent e)
- {
- if (e.getChangedType() == Material.OBSIDIAN) {
- e.setCancelled(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement