Timer - Creating

Discussion in 'Plugin Development' started by mateuszhp, Dec 14, 2012.

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

    mateuszhp

    Hi! I with the help of two people (Woobie & fireblast709) created, but they have created, the timer counting seconds and adds 1 second 1 lvl exp. Unfortunately, this timer is bugged, when you type / timer is added to the ArrayList but if another person enters / timer will be added, but the timer will not work, and others will be able to control (start / stop). Do you know the solution to this problem?
    Code:
    package MaTyyy.Perla;
     
    import java.util.ArrayList;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Perla extends JavaPlugin  implements Listener{
        public boolean addLevels = false;
        public ArrayList<String> xpToPlayers = new ArrayList<String>();
        public String x;
      public void onEnable()
      {
          getServer().getPluginManager().registerEvents(this, this);
          getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
          {
           
              @Override
              public void run()
              {
                        if(addLevels)
                  {
                          for(String player : xpToPlayers)
                          {
                              Player p = Bukkit.getPlayer(player);
                              if(p == null)
                              {
                                 
                                  continue;
                              }
                            p.setLevel(p.getLevel() + 1);
                            p.setExp(0);
                          }
                     
                  }
                 
              } 
          }, 0L, 20L);
          getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
          {
           
              @Override
              public void run()
              {
                        if(addLevels)
                  {
                          for(String player : xpToPlayers)
                          {
                              Player p = Bukkit.getPlayer(player);
                              if(p == null)
                              {
                                 
                                  continue;
                              }
                            p.setExp((float) (p.getExp() + 0.25));
                          }
                         
                  }
                 
              } 
          }, 0L, 10L);
          getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
          {
           
              @Override
              public void run()
              {
                        if(addLevels)
                  {
                          for(String player : xpToPlayers)
                          {
                              Player p = Bukkit.getPlayer(player);
                              if(p == null)
                              {
                       
                          continue;
                      }  p.setExp((float) (p.getExp() + 0.25));
                          }
                  }
                 
              } 
          }, 0L, 13L);
          getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
          {
           
              @Override
              public void run()
              {
                        if(addLevels)
                  {
                          for(String player : xpToPlayers)
                          {
                              Player p = Bukkit.getPlayer(player);
                              if(p == null)
                              {
                       
                          continue;
                      }  p.setExp((float) (p.getExp() + 0.15));
                          }
                  }
                 
              } 
          }, 0L, 15L);
         
          }
     
      public void onDisable() {
     
      }
     
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
          if(label.equals("timer"))
          {
              xpToPlayers.add(sender);
              addLevels = !addLevels;
              sender.sendMessage(ChatColor.DARK_BLUE + "Pomiar czasu " + ChatColor.RED +(addLevels ? "uruchomiony" : "zatrzymany."));
          }
          return false;
      }
      }
     
    
     
  2. Offline

    fireblast709

    The toggle of players:
    Code:java
    1. // If the player is in the list
    2. if(xpToPlayers.contains(player.getName()))
    3. {
    4. // Remove him/her
    5. xpToPlayers.remove(player.getName());
    6. }
    7. // Else
    8. else
    9. {
    10. // Add him/her
    11. xpToPlayers.add(player.getName());
    12. }
     
  3. Offline

    mateuszhp

    It does not work. If I typed, / timer to measure the time I will, if you'll write when I have uruchominony timer, the timer will stop me this, and you do not begin to measure time.
     
Thread Status:
Not open for further replies.

Share This Page