[Lib] Regenerating Blocks

Discussion in 'Resources' started by TryB4, Dec 23, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    mrgreen33gamer

    TryB4 I am not getting no where with my code, I tried setting block state inside of a List and nothing happens when the block regens. Here is my code

    regen:

    Code:java
    1.  
    2. public void regener(final List<BlockState> blocks, final boolean effect, final int speed) {
    3.  
    4. new BukkitRunnable() {
    5. int i = -1;
    6. @SuppressWarnings("deprecation")
    7. @Override
    8. public void run() {
    9. if (i != blocks.size()-1) {
    10. i++;
    11. BlockState bs = blocks.get(i);
    12. bs.getBlock().setType(bs.getType());
    13. bs.getBlock().setData(bs.getBlock().getData());
    14. if (effect)
    15. bs.getBlock().getWorld().playEffect(bs.getLocation(), Effect.STEP_SOUND, bs.getBlock().getType());
    16. }else{
    17. for (BlockState bs : blocks) {
    18. bs.getBlock().setType(bs.getType());
    19. bs.getBlock().setData(bs.getBlock().getData());
    20. }
    21. blocks.clear();
    22. this.cancel();
    23. }
    24. }
    25. }.runTaskTimer(plugin, speed, speed);
    26. }
    27.  


    SRC code:

    Code:java
    1.  
    2. @EventHandler
    3. public void PyroEvent(PlayerInteractEvent event){
    4. Player player = event.getPlayer();
    5. int rt = 10 * 1000;
    6. WorldGuardPlugin wg = (WorldGuardPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
    7. ApplicableRegionSet set = wg.getRegionManager(player.getWorld()).getApplicableRegions(player.getLocation());
    8. final List<BlockState> regen = new ArrayList<BlockState>();
    9. if (event.getAction() == Action.RIGHT_CLICK_AIR) {
    10. if (event.getItem().getType() == Material.FIREBALL) {
    11. if (Main.pyro.contains(player.getName())) {
    12. if (System.currentTimeMillis()- ((Long) lasttime.get(event.getPlayer())).longValue() > rt) {
    13. if(set.getFlag(DefaultFlag.PVP).equals(State.DENY)){
    14.  
    15. }else{
    16. lasttime.put(event.getPlayer(), Long.valueOf(System.currentTimeMillis()));
    17. int radius = 10;
    18. int radiusSquared = radius * radius;
    19. List<Player> players = player.getWorld().getPlayers();
    20. event.setCancelled(true);
    21. if (!(lasttime.containsKey(event.getPlayer()))) {
    22. lasttime.put(event.getPlayer(), Long.valueOf(0L));
    23. }
    24. Location otherloc1 = player.getLocation();
    25. final Block lava1 = player.getWorld().getBlockAt(otherloc1.getBlockX(), (int) otherloc1.getY(), otherloc1.getBlockZ());
    26. regen.add(lava1.getState());
    27. lava1.setType(Material.LAVA);
    28. for (Player otherPlayer : players) {
    29. if (otherPlayer == player)
    30. continue;
    31. if (player.getLocation().distanceSquared(otherPlayer.getLocation()) < radiusSquared) {
    32.  
    33. otherPlayer.setFireTicks(5 * 20);
    34. Location otherloc = otherPlayer.getLocation();
    35.  
    36. final Block lava = otherPlayer.getWorld().getBlockAt(otherloc.getBlockX(), (int) otherloc.getY(), otherloc.getBlockZ());
    37. lava.setType(Material.LAVA);
    38. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
    39. @Override
    40. public void run() {
    41. regener(regen, false, 6);
    42. }
    43. }, 3 * 20);
    44. }
    45. }
    46. }
    47. } else {
    48. player.sendMessage("You cannot use this pyro effect until 10 seconds");
    49. }
    50.  
    51. }
    52. }
    53. }
    54. }
    55.  


    Please help :(
     
Thread Status:
Not open for further replies.

Share This Page