scheduleSyncRepeatingTask problem

Discussion in 'Plugin Development' started by BenyTheBuff, Aug 25, 2014.

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

    BenyTheBuff

    I'm trying to setup a radiation system to when a player stands on a gold block they gain radiation and when they step off they lose it.

    this is my code anyone got any ideas on how I could achieve this?


    Code:
     @EventHandler
            public void onPlayerMoveEvent(PlayerMoveEvent event) {
                final Player player = (Player) event.getPlayer();
                final String playername = player.getName();
                if(event.getTo().getBlock().getRelative(BlockFace.DOWN).getType() == Material.GOLD_BLOCK && event.getFrom().getBlock().getRelative(BlockFace.DOWN).getType() != Material.GOLD_BLOCK) {
                        if(!(ongoldblock.contains(playername))){
                            ongoldblock.add(playername);
                            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                       
                            public void run() {
                             
                                    number += 1;
                                }
                       
                       
                            }, 0, 200);
                           
                    if(event.getFrom().getBlock().getRelative(BlockFace.DOWN).getType() == Material.GOLD_BLOCK && event.getTo().getBlock().getRelative(BlockFace.DOWN).getType() != Material.GOLD_BLOCK) { 
                        if(ongoldblock.contains(playername)){
                            ongoldblock.remove(playername);
                            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                            public void run() {
                               
                                number -= 1;
                           
                            }
                     
                   
                        }, 0, 200);
                       
                         
                        }
                    }
              }
          }
    }
     
  2. Offline

    mine-care

    Why casting player object to player object? Getplayer returns player object so the cast is useless.

    To achieve this have a int of 3000 (unique for each player) for instance and when they are on told, put them in a array list that contains only players, then have a sync repeating task (just one for the whole plugin) that each 5 ticks loops thru all the players in the array list and adds 1 to each ones Int. when they leave do the same but instead of adding a int, remove it :)
     
Thread Status:
Not open for further replies.

Share This Page