Problem with timer

Discussion in 'Plugin Development' started by grzegorz2047, Jan 17, 2013.

Thread Status:
Not open for further replies.
  1. I'm creating simple parkour plugin and I am trying to implement timer . But i have huge problem. I was looking for answers on forum but I found nothing like that.
    Here is my code:
    Code:
        @EventHandler
        public void onClick(PlayerInteractEvent event) {
          if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
              Block i = event.getClickedBlock();
              //Sprawdza czy blok jest znakiem
              if(i.getState() instanceof Sign)
              {
                  BlockState stateBlock = i.getState();
                  Sign sign = (Sign) stateBlock;
                  Main plugin = this;
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                  String arena = sign.getLine(1).toString();
           
                  if(this.getConfig().contains("parkour." + arena.toString() +  ".W")){
                      String w = this.getConfig().getString("parkour." + arena +  ".W");
                      double q = this.getConfig().getDouble("parkour." + arena +  ".X");
                      double r = this.getConfig().getDouble("parkour." + arena +  ".Y");
                      double e = this.getConfig().getDouble("parkour." + arena +  ".Z");
                      float p = (float) this.getConfig().getDouble("parkour." + arena +  ".P");
                      float a = (float) this.getConfig().getDouble("parkour." + arena +  ".A");
                      Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                      event.getPlayer().teleport(tpto);//if teleported start counting
               
                      final int task =this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable(){
                        public void run() {
                     
                                            time++;//counts
                                        //here I cant put end counting cus onClick method doesn't work correctly when its here.
                                        }
                }, 0L, 20L);
                      taskid =task;//taskid is global otherwise it doesnt work at all
                  }
                }
         
         
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                    if(sign.getLine(2).equalsIgnoreCase("end")){
                        event.getPlayer().sendMessage("You have ended parkour with time " + time);//end counting
                        Bukkit.getScheduler().cancelTask(taskid);//To cancel I'm using this.
                 
                    }
                }
     
     
            }
          }
        }
    I just want to do something like this if player clicks at sign "xxx nameofarena" then teleports him and start counting if player clicks "xxx end" sign then it teleports him to spawn and stops counting
     
  2. Offline

    Craftiii4

    Record the time when the sign was clicked and when the end sign was clicked and work out the difference?
     
  3. It'll take a little time to find some information about date :D
     
  4. Offline

    CubixCoders

    When they click the sign do
    int clicktime = System.getCurrentTimeMillis();
    Then when they click the second sign do
    int newtime = System.getCurrentTimeMillis();
    Then just do
    player.sendMessage((newtime - clicktime) + " seconds.");
    I think that should work
     
  5. Now it show huge numbers :) like "19373847387 seconds"

    This is my code:
    Code:
        @EventHandler
        public void onClick(PlayerInteractEvent event) {
          if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
              Block i = event.getClickedBlock();
              //Sprawdza czy blok jest znakiem
              if(i.getState() instanceof Sign)
              {
                  BlockState stateBlock = i.getState();
                  Sign sign = (Sign) stateBlock;
                  Main plugin = this;
                  int clicktime=0;
                  int newtime=0;
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                  String arena = sign.getLine(1).toString();
               
                  if(this.getConfig().contains("parkour." + arena.toString() +  ".W")){
                      String w = this.getConfig().getString("parkour." + arena +  ".W");
                      double q = this.getConfig().getDouble("parkour." + arena +  ".X");
                      double r = this.getConfig().getDouble("parkour." + arena +  ".Y");
                      double e = this.getConfig().getDouble("parkour." + arena +  ".Z");
                      float p = (float) this.getConfig().getDouble("parkour." + arena +  ".P");
                      float a = (float) this.getConfig().getDouble("parkour." + arena +  ".A");
                      Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                      event.getPlayer().teleport(tpto);//if teleported start counting
                      clicktime = (int) System.currentTimeMillis();
                  }
                }
             
             
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                    if(sign.getLine(2).equalsIgnoreCase("end")){
                        newtime = (int) System.currentTimeMillis();
                        event.getPlayer().sendMessage((newtime - clicktime) + " seconds.");//end counting
                    }
                }
     
     
            }
          }
        }
    
    when I check (debug :) it like 101002032030 o I got it from code below.
    event.getPlayer().sendMessage("show times"+ newtime+ " " + clicktime +" ");
     
  6. Milli = x10^(-3).

    So to get the difference in seconds do;

    Code:java
    1.  
    2. long millisDifference = endtime - starttime;
    3. long secondsDifference = (millisDifference / 1000);
    4.  
     
    grzegorz2047 likes this.
  7. I see, but currentmillis doesnt work for me at all so I'm trying already with calendar.
     
  8. grzegorz2047
    How does it not work? What's wrong with it.
     
  9. Offline

    Craftiii4

    Adamki11s code should work fine. If its not working you are not using it correctly.
     
  10. The best option is to give all source of plugin :) You can try this plugin on this server: 5.9.180.101:3000

    Here is source code:
    Code:
    package me.grzegorz2047;
     
    import java.text.SimpleDateFormat;
    import java.util.Date;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    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.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.scheduler.BukkitTask;
     
    public class Main extends JavaPlugin implements Listener {
     
        String saved = "Pos saved";
        public String loaded = "Pos loaded";
        boolean notify =true;
        int czas=0;
        int taskid;
        protected int time;
     
     
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            String temp1 = (String) this.getConfig().get("saved",saved);
            String temp2 = (String) this.getConfig().get("loaded",loaded);
            boolean temp3 =  (Boolean) this.getConfig().get("notify",notify);
            this.saveConfig();//zapis
            saved=temp1;
            loaded=temp2;
            notify=temp3;
         
            System.out.println(this.getName()+" Dziala(Workin')");
        }
     
        public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, final String[] args) {
            if (!(sender instanceof Player)) { // If not player, return.
                return false;
            }
     
         
            //Logger log = getLogger();
            Player player = (Player) sender;
            Main plugin = this;
            if(commandLabel.equalsIgnoreCase("gpark")){
                if(args.length==1){
                    if(args[0].equalsIgnoreCase("setspawn") &&  player.hasPermission("gpark.setspawn") ){
                        plugin.getConfig().set("spawn." +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("spawn." +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("spawn." +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("spawn." +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("spawn." +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("spawn." +  ".A", player.getLocation().getYaw());
                        player.sendMessage("Spawn for parkours is set");
                        plugin.saveConfig();//zapis
                        return true;
                     
                    } 
                }
                if(args.length==2){
                    if(args[0].equalsIgnoreCase("setpark") &&  player.hasPermission("gpark.setpark") ){
                        plugin.getConfig().set("parkour." + args[1] +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("parkour." + args[1] +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("parkour." + args[1] +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("parkour." + args[1] +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("parkour." + args[1] +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("parkour." + args[1] +  ".A", player.getLocation().getYaw());
                        player.sendMessage(ChatColor.GREEN+ "parkour "+ ChatColor.RED +args[1] + ChatColor.GREEN+ " is set");
                        plugin.saveConfig();//zapis
                        return true;
                     
                    } 
                }
             
             
             
             
             
             
             
            return true;
            }
            return false;
         
        }
     
        @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent evt){
            if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_POWDER.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                //Logger log = getLogger();
                Player player = evt.getPlayer();
                Main plugin = this;
                plugin.getConfig().set("Players." + player.getName() + ".W", player.getWorld().getName());
                plugin.getConfig().set("Players." + player.getName() + ".X", player.getLocation().getX());
                plugin.getConfig().set("Players." + player.getName() + ".Y", player.getLocation().getY());
                plugin.getConfig().set("Players." + player.getName() + ".Z", player.getLocation().getZ());
                plugin.getConfig().set("Players." + player.getName() + ".P", player.getLocation().getPitch());
                plugin.getConfig().set("Players." + player.getName() + ".A", player.getLocation().getYaw());
     
                plugin.saveConfig();//zapis
                if(notify==true)
                evt.getPlayer().sendMessage(ChatColor.YELLOW +"@ " + saved);
         
                }
          if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_ROD.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                {
                    Player player = evt.getPlayer();
                    if(this.getConfig().contains("Players." + player.getName() + ".W")){
                 
                        String w = this.getConfig().getString("Players." + player.getName() + ".W");
                        double x = this.getConfig().getDouble("Players." + player.getName() + ".X");
                        double y = this.getConfig().getDouble("Players." + player.getName() + ".Y");
                        double z = this.getConfig().getDouble("Players." + player.getName() + ".Z");
                        float p = (float) this.getConfig().getDouble("Players." + player.getName() + ".P");
                        float a = (float) this.getConfig().getDouble("Players." + player.getName() + ".A");
                     
                        Location tpto = new Location(Bukkit.getWorld(w), x, y, z, p, a);
                        player.teleport(tpto);
                        if(notify==true){
                            evt.getPlayer().sendMessage(ChatColor.RED +"@ " +loaded);
                            }
                    }
                    else{
                        evt.getPlayer().sendMessage(ChatColor.RED +"@ " + "You didnt set checkpoint");
                    }
                 
                }
     
             
            }
        }
     
     
     
     
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
     
            if (event.isCancelled()) {
                return;
            }
     
            if (event.getFrom().getBlockX() == event.getTo().getBlockX()
                    && event.getFrom().getBlockY() == event.getTo().getBlockY()
                    && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
                return;
            }
     
            Player player = event.getPlayer();
            Location playerLoc = player.getLocation();
            World world = playerLoc.getWorld();
            //Main plugin = this;
         
            for(int x = (int)(playerLoc.getX()-1); x<=(int)(playerLoc.getX()+1); x++) {//Wykrywanie klockow
                for(int y=(int)(playerLoc.getY()-1); y<=(int)(playerLoc.getY()+1); y++) {
                    for(int z=(int)(playerLoc.getZ()-1); z<=(int)(playerLoc.getZ()+1); z++) {
                     
                        if(world.getBlockAt(x, y, z).getTypeId() == 10 || world.getBlockAt(x, y, z).getTypeId() == 11) {
                            if(this.getConfig().contains("spawn." +  ".W")){
                                String w = this.getConfig().getString("spawn." + ".W");
                                double q = this.getConfig().getDouble("spawn." + ".X");
                                double r = this.getConfig().getDouble("spawn." + ".Y");
                                double e = this.getConfig().getDouble("spawn." + ".Z");
                                float p = (float) this.getConfig().getDouble("spawn." + ".P");
                                float a = (float) this.getConfig().getDouble("spawn." + ".A");
                                Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                                player.setNoDamageTicks(20);
                             
                                player.teleport(tpto);
                                player.sendMessage(ChatColor.RED + "You failed parkour, back to respawn");
                             
                            }
                            else
                            {
                            player.sendMessage(ChatColor.RED + "Admin didnt set respawn, say it to him,you'll die :D");
                            }
                        }
                    }
                }
            }
        }
     
     
     
        @EventHandler
        public void onClick(PlayerInteractEvent event) {
          if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
              Block i = event.getClickedBlock();
              //Sprawdza czy blok jest znakiem
              if(i.getState() instanceof Sign)
              {
                  BlockState stateBlock = i.getState();
                  Sign sign = (Sign) stateBlock;
                  Main plugin = this;
                  long endtime = 0;
                  long starttime=0;
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                  String arena = sign.getLine(1).toString();
               
                  if(this.getConfig().contains("parkour." + arena.toString() +  ".W")){
                      String w = this.getConfig().getString("parkour." + arena +  ".W");
                      double q = this.getConfig().getDouble("parkour." + arena +  ".X");
                      double r = this.getConfig().getDouble("parkour." + arena +  ".Y");
                      double e = this.getConfig().getDouble("parkour." + arena +  ".Z");
                      float p = (float) this.getConfig().getDouble("parkour." + arena +  ".P");
                      float a = (float) this.getConfig().getDouble("parkour." + arena +  ".A");
                      Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                      event.getPlayer().teleport(tpto);//if teleported start counting
                      starttime = System.currentTimeMillis();
     
                   
                  }
                }
             
             
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                    if(sign.getLine(2).equalsIgnoreCase("end")){
                        endtime = System.currentTimeMillis();
                     
                        long millisDifference = endtime - starttime;
        long secondsDifference = (millisDifference / 1000);
                        event.getPlayer().sendMessage("You have ended parkour with time " + millisDifference);//end counting
                    }
                }
     
     
            }
          }
        }
     
     
     
        @EventHandler
        public void onSignChange(SignChangeEvent event) {
            if(event.getLine(0).equalsIgnoreCase("[gpark]") && event.getPlayer().hasPermission("tt.createsign")){
                if(!event.getLine(1).isEmpty() ){
                event.getPlayer().sendMessage(ChatColor.GREEN + "You created sign for parkour " + ChatColor.GOLD + event.getLine(1));
                }
                else if(event.getLine(2).equalsIgnoreCase("end"))
                {
                    event.getPlayer().sendMessage(ChatColor.GREEN + "You have created end of this parkour!");
                }
                else
                {
                    event.getPlayer().sendMessage(ChatColor.RED + "This sign is incorrect for parkour");
                }
            }
        }
     
     
     
     
     
     
     
     
     
    }
    I don't know why but one of variables gives 0 value. That's why it doesn't work for me . I cannot find the reason of 0 :/.
    Without currentMillis it shows correct values. If it gets currentmillis then sets to 0 dunno why.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  11. grzegorz2047
    Maybe you didn't assign the value to a variable? It shouldn't be zero.
     
  12. I tried even creating method to get current millis . Still just one variable works.
    I have checked using this: event.getPlayer().sendMessage(endtime+ " " + starttime);//end counting
    endtime works because it gets current millis correctly but starttime stays as default declared value. (200000)
    For me everything is correct.
    Here is updated code:
    Code:
    package me.grzegorz2047;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    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.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener {
     
        String saved = "Pos saved";
        public String loaded = "Pos loaded";
        boolean notify =true;
        int czas=0;
        int taskid;
        protected int time;
       
       
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            String temp1 = (String) this.getConfig().get("saved",saved);
            String temp2 = (String) this.getConfig().get("loaded",loaded);
            boolean temp3 =  (Boolean) this.getConfig().get("notify",notify);
            this.saveConfig();//zapis
            saved=temp1;
            loaded=temp2;
            notify=temp3;
           
            System.out.println(this.getName()+" Dziala(Workin')");
        }
       
        public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, final String[] args) {
            if (!(sender instanceof Player)) { // If not player, return.
                return false;
            }
     
           
            //Logger log = getLogger();
            Player player = (Player) sender;
            Main plugin = this;
            if(commandLabel.equalsIgnoreCase("gpark")){
                if(args.length==1){
                    if(args[0].equalsIgnoreCase("setspawn") &&  player.hasPermission("gpark.setspawn") ){
                        plugin.getConfig().set("spawn." +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("spawn." +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("spawn." +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("spawn." +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("spawn." +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("spawn." +  ".A", player.getLocation().getYaw());
                        player.sendMessage("Spawn for parkours is set");
                        plugin.saveConfig();//zapis
                        return true;
                       
                    }   
                }
                if(args.length==2){
                    if(args[0].equalsIgnoreCase("setpark") &&  player.hasPermission("gpark.setpark") ){
                        plugin.getConfig().set("parkour." + args[1] +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("parkour." + args[1] +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("parkour." + args[1] +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("parkour." + args[1] +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("parkour." + args[1] +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("parkour." + args[1] +  ".A", player.getLocation().getYaw());
                        player.sendMessage(ChatColor.GREEN+ "parkour "+ ChatColor.RED +args[1] + ChatColor.GREEN+ " is set");
                        plugin.saveConfig();//zapis
                        return true;
                       
                    }   
                }
               
               
               
               
               
               
               
            return true;
            }
            return false;
           
        }
     
        @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent evt){
            if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_POWDER.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                //Logger log = getLogger();
                Player player = evt.getPlayer();
                Main plugin = this;
                plugin.getConfig().set("Players." + player.getName() + ".W", player.getWorld().getName());
                plugin.getConfig().set("Players." + player.getName() + ".X", player.getLocation().getX());
                plugin.getConfig().set("Players." + player.getName() + ".Y", player.getLocation().getY());
                plugin.getConfig().set("Players." + player.getName() + ".Z", player.getLocation().getZ());
                plugin.getConfig().set("Players." + player.getName() + ".P", player.getLocation().getPitch());
                plugin.getConfig().set("Players." + player.getName() + ".A", player.getLocation().getYaw());
       
                plugin.saveConfig();//zapis
                if(notify==true)
                evt.getPlayer().sendMessage(ChatColor.YELLOW +"@ " + saved);
           
                }
          if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_ROD.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                {
                    Player player = evt.getPlayer();
                    if(this.getConfig().contains("Players." + player.getName() + ".W")){
                   
                        String w = this.getConfig().getString("Players." + player.getName() + ".W");
                        double x = this.getConfig().getDouble("Players." + player.getName() + ".X");
                        double y = this.getConfig().getDouble("Players." + player.getName() + ".Y");
                        double z = this.getConfig().getDouble("Players." + player.getName() + ".Z");
                        float p = (float) this.getConfig().getDouble("Players." + player.getName() + ".P");
                        float a = (float) this.getConfig().getDouble("Players." + player.getName() + ".A");
                       
                        Location tpto = new Location(Bukkit.getWorld(w), x, y, z, p, a);
                        player.teleport(tpto);
                        if(notify==true){
                            evt.getPlayer().sendMessage(ChatColor.RED +"@ " +loaded);
                            }
                    }
                    else{
                        evt.getPlayer().sendMessage(ChatColor.RED +"@ " + "You didnt set checkpoint");
                    }
                   
                }
     
               
            }
        }
       
       
       
       
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
     
            if (event.isCancelled()) {
                return;
            }
     
            if (event.getFrom().getBlockX() == event.getTo().getBlockX()
                    && event.getFrom().getBlockY() == event.getTo().getBlockY()
                    && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
                return;
            }
     
            Player player = event.getPlayer();
            Location playerLoc = player.getLocation();
            World world = playerLoc.getWorld();
            //Main plugin = this;
           
            for(int x = (int)(playerLoc.getX()-1); x<=(int)(playerLoc.getX()+1); x++) {//Wykrywanie klockow
                for(int y=(int)(playerLoc.getY()-1); y<=(int)(playerLoc.getY()+1); y++) {
                    for(int z=(int)(playerLoc.getZ()-1); z<=(int)(playerLoc.getZ()+1); z++) {
                       
                        if(world.getBlockAt(x, y, z).getTypeId() == 10 || world.getBlockAt(x, y, z).getTypeId() == 11) {
                            if(this.getConfig().contains("spawn." +  ".W")){
                                String w = this.getConfig().getString("spawn." + ".W");
                                double q = this.getConfig().getDouble("spawn." + ".X");
                                double r = this.getConfig().getDouble("spawn." + ".Y");
                                double e = this.getConfig().getDouble("spawn." + ".Z");
                                float p = (float) this.getConfig().getDouble("spawn." + ".P");
                                float a = (float) this.getConfig().getDouble("spawn." + ".A");
                                Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                                player.setNoDamageTicks(20);
                               
                                player.teleport(tpto);
                                player.sendMessage(ChatColor.RED + "You failed parkour, back to respawn");
                               
                            }
                            else
                            {
                            player.sendMessage(ChatColor.RED + "Admin didnt set respawn, say it to him,you'll die :D");
                            }
                        }
                    }
                }
            }
        }
       
       
       
        @EventHandler
        public void onClick(PlayerInteractEvent event) {
          if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
              Block i = event.getClickedBlock();
              //Sprawdza czy blok jest znakiem
              if(i.getState() instanceof Sign)
              {
                  BlockState stateBlock = i.getState();
                  Sign sign = (Sign) stateBlock;
                  //Main plugin = this;
                  long endtime = 400000;
                  long starttime=200000;
                 
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                  String arena = sign.getLine(1).toString();
                // starttime = System.currentTimeMillis();
                  if(this.getConfig().contains("parkour." + arena.toString() +  ".W")){
                      String w = this.getConfig().getString("parkour." + arena +  ".W");
                      double q = this.getConfig().getDouble("parkour." + arena +  ".X");
                      double r = this.getConfig().getDouble("parkour." + arena +  ".Y");
                      double e = this.getConfig().getDouble("parkour." + arena +  ".Z");
                      float p = (float) this.getConfig().getDouble("parkour." + arena +  ".P");
                      float a = (float) this.getConfig().getDouble("parkour." + arena +  ".A");
                      Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                      event.getPlayer().teleport(tpto);//if teleported start counting
                      starttime = GetMillis();
     
                     
                  }
                  else
                  {
                      event.getPlayer().sendMessage("Arena doesn't exists");
                  }
                }
               
               
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                    if(sign.getLine(2).equalsIgnoreCase("end")){
                        endtime = GetMillis();
                       
                        long millisDifference = endtime - starttime;
                        long secondsDifference = (millisDifference / 1000);
                        event.getPlayer().sendMessage(endtime+ " " + starttime);//end counting
                       
                    }
                }
     
     
            }
          }
        }
     
        public long GetMillis(){
            long millis = System.currentTimeMillis();
            return millis;
        }
       
        @EventHandler
        public void onSignChange(SignChangeEvent event) {
            if(event.getLine(0).equalsIgnoreCase("[gpark]") && event.getPlayer().hasPermission("tt.createsign")){
                if(!event.getLine(1).isEmpty() ){
                event.getPlayer().sendMessage(ChatColor.GREEN + "You created sign for parkour " + ChatColor.GOLD + event.getLine(1));
                }
                else if(event.getLine(2).equalsIgnoreCase("end"))
                {
                    event.getPlayer().sendMessage(ChatColor.GREEN + "You have created end of this parkour!");
                }
                else
                {
                    event.getPlayer().sendMessage(ChatColor.RED + "This sign is incorrect for parkour");
                }
            }
        }
       
       
       
       
       
       
       
       
       
    }
     
  13. Offline

    fireblast709

    grzegorz2047 maybe you should start by declaring starttime as an instance variable
     
    grzegorz2047 likes this.
  14. Thank you.Now it magically started working properly . It's very wierd. I hope it'll not conflict when more people will use parkour arena..
     
  15. Offline

    CubixCoders

    That's a good point, save it in a hashmap instead e.g.
    Code:
    [/S][/S][/S]
    [S][S][S]Map<String, Integer> times = new HashMap<String, Integer>();[/S][/S][/S]
    [S][S][S]//When they click the sign[/S][/S][/S]
    [S][S][S]times.put(p.getName(), System.currentTimeMillis());
    [/S][/S]
    Scratch that, use two hashmaps
    Code:
    Map<String, Integer> time1 = new HashMap<String, Integer>();
    Map<String, Integer> time2 = new HashMap<String, Integer>();
    
    Then when they first click the sign
    Code:
    time1.put(p.getName(), System.currentTimeMillis());
    
    And the second time
    Code:
    time2.put(p.getName(), System.currentTimeMillis());
    
    Then when getting the difference
    int millidif = time2.get(p.getName()) - time1.get(p.getName());
    int secdif = millidif / 1000;[/code][/code][/S][/code][/code][/S]

    Scratch that, use two hashmaps
    Code:
    Map<String, Integer> time1 = new HashMap<String, Integer>();
    Map<String, Integer> time2 = new HashMap<String, Integer>();
    
    Then when they first click the sign
    Code:
    time1.put(p.getName(), System.currentTimeMillis());
    
    And the second time
    Code:
    time2.put(p.getName(), System.currentTimeMillis());
    
    Then when getting the difference
    int millidif = time2.get(p.getName()) - time1.get(p.getName());
    int secdif = millidif / 1000;[/code][/code][/S][/code][/code][/S][/code]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  16. I have null point exception on this:
    Code:
    int millidif = time2.get(event.getPlayer().getName()) - time1.get(event.getPlayer().getName());

    Here is full code:
    Code:
    package me.grzegorz2047;
     
    import java.util.HashMap;
    import java.util.Map;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    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.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener {
     
        String saved = "Pos saved";
        public String loaded = "Pos loaded";
        boolean notify =true;
        int czas=0;
        int taskid;
        protected int time;
        public long starttime;
       
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            String temp1 = (String) this.getConfig().get("saved",saved);
            String temp2 = (String) this.getConfig().get("loaded",loaded);
            boolean temp3 =  (Boolean) this.getConfig().get("notify",notify);
            this.saveConfig();//zapis
            saved=temp1;
            loaded=temp2;
            notify=temp3;
           
            System.out.println(this.getName()+" Dziala(Workin')");
        }
       
        public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, final String[] args) {
            if (!(sender instanceof Player)) { // If not player, return.
                return false;
            }
     
           
            //Logger log = getLogger();
            Player player = (Player) sender;
            Main plugin = this;
            if(commandLabel.equalsIgnoreCase("gpark")){
                if(args.length==1){
                    if(args[0].equalsIgnoreCase("setspawn") &&  player.hasPermission("gpark.setspawn") ){
                        plugin.getConfig().set("spawn." +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("spawn." +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("spawn." +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("spawn." +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("spawn." +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("spawn." +  ".A", player.getLocation().getYaw());
                        player.sendMessage("Spawn for parkours is set");
                        plugin.saveConfig();//zapis
                        return true;
                       
                    }   
                }
                if(args.length==2){
                    if(args[0].equalsIgnoreCase("setpark") &&  player.hasPermission("gpark.setpark") ){
                        plugin.getConfig().set("parkour." + args[1] +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("parkour." + args[1] +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("parkour." + args[1] +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("parkour." + args[1] +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("parkour." + args[1] +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("parkour." + args[1] +  ".A", player.getLocation().getYaw());
                        player.sendMessage(ChatColor.GREEN+ "parkour "+ ChatColor.RED +args[1] + ChatColor.GREEN+ " is set");
                        plugin.saveConfig();//zapis
                        return true;
                       
                    }   
                }
               
               
               
               
               
               
               
            return true;
            }
            return false;
           
        }
     
        @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent evt){
            if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_POWDER.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                //Logger log = getLogger();
                Player player = evt.getPlayer();
                Main plugin = this;
                plugin.getConfig().set("Players." + player.getName() + ".W", player.getWorld().getName());
                plugin.getConfig().set("Players." + player.getName() + ".X", player.getLocation().getX());
                plugin.getConfig().set("Players." + player.getName() + ".Y", player.getLocation().getY());
                plugin.getConfig().set("Players." + player.getName() + ".Z", player.getLocation().getZ());
                plugin.getConfig().set("Players." + player.getName() + ".P", player.getLocation().getPitch());
                plugin.getConfig().set("Players." + player.getName() + ".A", player.getLocation().getYaw());
       
                plugin.saveConfig();//zapis
                if(notify==true)
                evt.getPlayer().sendMessage(ChatColor.YELLOW +"@ " + saved);
           
                }
          if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_ROD.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                {
                    Player player = evt.getPlayer();
                    if(this.getConfig().contains("Players." + player.getName() + ".W")){
                   
                        String w = this.getConfig().getString("Players." + player.getName() + ".W");
                        double x = this.getConfig().getDouble("Players." + player.getName() + ".X");
                        double y = this.getConfig().getDouble("Players." + player.getName() + ".Y");
                        double z = this.getConfig().getDouble("Players." + player.getName() + ".Z");
                        float p = (float) this.getConfig().getDouble("Players." + player.getName() + ".P");
                        float a = (float) this.getConfig().getDouble("Players." + player.getName() + ".A");
                       
                        Location tpto = new Location(Bukkit.getWorld(w), x, y, z, p, a);
                        player.teleport(tpto);
                        if(notify==true){
                            evt.getPlayer().sendMessage(ChatColor.RED +"@ " +loaded);
                            }
                    }
                    else{
                        evt.getPlayer().sendMessage(ChatColor.RED +"@ " + "You didnt set checkpoint");
                    }
                   
                }
     
               
            }
        }
       
       
       
       
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
     
            if (event.isCancelled()) {
                return;
            }
     
            if (event.getFrom().getBlockX() == event.getTo().getBlockX()
                    && event.getFrom().getBlockY() == event.getTo().getBlockY()
                    && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
                return;
            }
     
            Player player = event.getPlayer();
            Location playerLoc = player.getLocation();
            World world = playerLoc.getWorld();
            //Main plugin = this;
           
            for(int x = (int)(playerLoc.getX()-1); x<=(int)(playerLoc.getX()+1); x++) {//Wykrywanie klockow
                for(int y=(int)(playerLoc.getY()-1); y<=(int)(playerLoc.getY()+1); y++) {
                    for(int z=(int)(playerLoc.getZ()-1); z<=(int)(playerLoc.getZ()+1); z++) {
                       
                        if(world.getBlockAt(x, y, z).getTypeId() == 10 || world.getBlockAt(x, y, z).getTypeId() == 11) {
                            if(this.getConfig().contains("spawn." +  ".W")){
                                String w = this.getConfig().getString("spawn." + ".W");
                                double q = this.getConfig().getDouble("spawn." + ".X");
                                double r = this.getConfig().getDouble("spawn." + ".Y");
                                double e = this.getConfig().getDouble("spawn." + ".Z");
                                float p = (float) this.getConfig().getDouble("spawn." + ".P");
                                float a = (float) this.getConfig().getDouble("spawn." + ".A");
                                Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                                player.setNoDamageTicks(20);
                               
                                player.teleport(tpto);
                                player.sendMessage(ChatColor.RED + "You failed parkour, back to respawn");
                               
                            }
                            else
                            {
                            player.sendMessage(ChatColor.RED + "Admin didnt set respawn, say it to him,you'll die :D");
                            }
                        }
                    }
                }
            }
        }
       
       
       
        @EventHandler
        public void onClick(PlayerInteractEvent event) {
          if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
              Block i = event.getClickedBlock();
              //Sprawdza czy blok jest znakiem
              if(i.getState() instanceof Sign)
              {
                  BlockState stateBlock = i.getState();
                  Sign sign = (Sign) stateBlock;
                  //Main plugin = this;
                  long endtime = 400000;
                  Map<String, Integer> time1 = new HashMap<String, Integer>();
                  Map<String, Integer> time2 = new HashMap<String, Integer>();
                 
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                  String arena = sign.getLine(1).toString();
                  if(this.getConfig().contains("parkour." + arena.toString() +  ".W")){
                      String w = this.getConfig().getString("parkour." + arena +  ".W");
                      double q = this.getConfig().getDouble("parkour." + arena +  ".X");
                      double r = this.getConfig().getDouble("parkour." + arena +  ".Y");
                      double e = this.getConfig().getDouble("parkour." + arena +  ".Z");
                      float p = (float) this.getConfig().getDouble("parkour." + arena +  ".P");
                      float a = (float) this.getConfig().getDouble("parkour." + arena +  ".A");
                      Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                      event.getPlayer().teleport(tpto);//if teleported start counting
                      time1.put(event.getPlayer().getName(), (int) System.currentTimeMillis());;
     
                     
                  }
                }
               
               
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                    if(sign.getLine(2).equalsIgnoreCase("end")){
                        time2.put(event.getPlayer().getName(), (int) System.currentTimeMillis());
                       
                        int millidif = time2.get(event.getPlayer().getName()) - time1.get(event.getPlayer().getName());
                        int secdif = millidif / 1000;
                        event.getPlayer().sendMessage( "" +secdif);//end counting
                       
                    }
                }
     
     
            }
          }
        }
     
        public long GetMillis(){
            long millis = System.currentTimeMillis();
            return millis;
        }
       
        @EventHandler
        public void onSignChange(SignChangeEvent event) {
            if(event.getLine(0).equalsIgnoreCase("[gpark]") && event.getPlayer().hasPermission("tt.createsign")){
                if(!event.getLine(1).isEmpty() ){
                event.getPlayer().sendMessage(ChatColor.GREEN + "You created sign for parkour " + ChatColor.GOLD + event.getLine(1));
                }
                else if(event.getLine(2).equalsIgnoreCase("end"))
                {
                    event.getPlayer().sendMessage(ChatColor.GREEN + "You have created end of this parkour!");
                }
                else
                {
                    event.getPlayer().sendMessage(ChatColor.RED + "This sign is incorrect for parkour");
                }
            }
        }
       
       
       
       
       
       
       
       
       
    }
     
  17. Offline

    CubixCoders

    if(time1.get(p.getName() != null && time1.get(p.getName() != null)
     
  18. Offline

    fireblast709

    if(time1.containsKey(player.getName) && time2.containsKey(player.getName()))

    Besides, why do you need the second HashMap? You would say that you get, calculate and print the time when you get the second time
     
  19. Offline

    CubixCoders

    fireblast709
    Well because when you click the second sign, it would override the first time saved..
     
  20. It stopped working. Now it shows 0.

    Here is full code:
    Code:
    package me.grzegorz2047;
     
    import java.util.HashMap;
    import java.util.Map;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    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.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener {
     
        String saved = "Pos saved";
        public String loaded = "Pos loaded";
        boolean notify =true;
        int czas=0;
        int taskid;
        protected int time;
        public long starttime;
        public long millidif;
     
     
     
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            String temp1 = (String) this.getConfig().get("saved",saved);
            String temp2 = (String) this.getConfig().get("loaded",loaded);
            boolean temp3 =  (Boolean) this.getConfig().get("notify",notify);
            this.saveConfig();//zapis
            saved=temp1;
            loaded=temp2;
            notify=temp3;
     
            System.out.println(this.getName()+" Dziala(Workin')");
        }
     
        public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, final String[] args) {
            if (!(sender instanceof Player)) { // If not player, return.
                return false;
            }
     
     
            //Logger log = getLogger();
            Player player = (Player) sender;
            Main plugin = this;
            if(commandLabel.equalsIgnoreCase("gpark")){
                if(args.length==1){
                    if(args[0].equalsIgnoreCase("setspawn") &&  player.hasPermission("gpark.setspawn") ){
                        plugin.getConfig().set("spawn." +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("spawn." +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("spawn." +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("spawn." +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("spawn." +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("spawn." +  ".A", player.getLocation().getYaw());
                        player.sendMessage("Spawn for parkours is set");
                        plugin.saveConfig();//zapis
                        return true;
             
                    }
                }
                if(args.length==2){
                    if(args[0].equalsIgnoreCase("setpark") &&  player.hasPermission("gpark.setpark") ){
                        plugin.getConfig().set("parkour." + args[1] +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("parkour." + args[1] +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("parkour." + args[1] +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("parkour." + args[1] +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("parkour." + args[1] +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("parkour." + args[1] +  ".A", player.getLocation().getYaw());
                        player.sendMessage(ChatColor.GREEN+ "parkour "+ ChatColor.RED +args[1] + ChatColor.GREEN+ " is set");
                        plugin.saveConfig();//zapis
                        return true;
             
                    }
                }
     
     
     
     
     
     
     
            return true;
            }
            return false;
     
        }
     
        @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent evt){
            if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_POWDER.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                //Logger log = getLogger();
                Player player = evt.getPlayer();
                Main plugin = this;
                plugin.getConfig().set("Players." + player.getName() + ".W", player.getWorld().getName());
                plugin.getConfig().set("Players." + player.getName() + ".X", player.getLocation().getX());
                plugin.getConfig().set("Players." + player.getName() + ".Y", player.getLocation().getY());
                plugin.getConfig().set("Players." + player.getName() + ".Z", player.getLocation().getZ());
                plugin.getConfig().set("Players." + player.getName() + ".P", player.getLocation().getPitch());
                plugin.getConfig().set("Players." + player.getName() + ".A", player.getLocation().getYaw());
     
                plugin.saveConfig();//zapis
                if(notify==true)
                evt.getPlayer().sendMessage(ChatColor.YELLOW +"@ " + saved);
     
                }
          if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_ROD.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                {
                    Player player = evt.getPlayer();
                    if(this.getConfig().contains("Players." + player.getName() + ".W")){
         
                        String w = this.getConfig().getString("Players." + player.getName() + ".W");
                        double x = this.getConfig().getDouble("Players." + player.getName() + ".X");
                        double y = this.getConfig().getDouble("Players." + player.getName() + ".Y");
                        double z = this.getConfig().getDouble("Players." + player.getName() + ".Z");
                        float p = (float) this.getConfig().getDouble("Players." + player.getName() + ".P");
                        float a = (float) this.getConfig().getDouble("Players." + player.getName() + ".A");
             
                        Location tpto = new Location(Bukkit.getWorld(w), x, y, z, p, a);
                        player.teleport(tpto);
                        if(notify==true){
                            evt.getPlayer().sendMessage(ChatColor.RED +"@ " +loaded);
                            }
                    }
                    else{
                        evt.getPlayer().sendMessage(ChatColor.RED +"@ " + "You didnt set checkpoint");
                    }
         
                }
     
     
            }
        }
     
     
     
     
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
     
            if (event.isCancelled()) {
                return;
            }
     
            if (event.getFrom().getBlockX() == event.getTo().getBlockX()
                    && event.getFrom().getBlockY() == event.getTo().getBlockY()
                    && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
                return;
            }
     
            Player player = event.getPlayer();
            Location playerLoc = player.getLocation();
            World world = playerLoc.getWorld();
            //Main plugin = this;
     
            for(int x = (int)(playerLoc.getX()-1); x<=(int)(playerLoc.getX()+1); x++) {//Wykrywanie klockow
                for(int y=(int)(playerLoc.getY()-1); y<=(int)(playerLoc.getY()+1); y++) {
                    for(int z=(int)(playerLoc.getZ()-1); z<=(int)(playerLoc.getZ()+1); z++) {
             
                        if(world.getBlockAt(x, y, z).getTypeId() == 10 || world.getBlockAt(x, y, z).getTypeId() == 11) {
                            if(this.getConfig().contains("spawn." +  ".W")){
                                String w = this.getConfig().getString("spawn." + ".W");
                                double q = this.getConfig().getDouble("spawn." + ".X");
                                double r = this.getConfig().getDouble("spawn." + ".Y");
                                double e = this.getConfig().getDouble("spawn." + ".Z");
                                float p = (float) this.getConfig().getDouble("spawn." + ".P");
                                float a = (float) this.getConfig().getDouble("spawn." + ".A");
                                Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                                player.setNoDamageTicks(20);
                     
                                player.teleport(tpto);
                                player.sendMessage(ChatColor.RED + "You failed parkour, back to respawn");
                     
                            }
                            else
                            {
                            player.sendMessage(ChatColor.RED + "Admin didnt set respawn, say it to him,you'll die :D");
                            }
                        }
                    }
                }
            }
        }
     
     
     
        @EventHandler
        public void onClick(PlayerInteractEvent event) {
          if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
              Block i = event.getClickedBlock();
              //Sprawdza czy blok jest znakiem
              if(i.getState() instanceof Sign)
              {
                  BlockState stateBlock = i.getState();
                  Sign sign = (Sign) stateBlock;
                  //Main plugin = this;
                  long endtime = 400000;
                  Map<String, Long> time1 = new HashMap<String, Long>();
                  Map<String, Long> time2 = new HashMap<String, Long>();
       
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                  String arena = sign.getLine(1).toString();
                  if(this.getConfig().contains("parkour." + arena.toString() +  ".W")){
                      String w = this.getConfig().getString("parkour." + arena +  ".W");
                      double q = this.getConfig().getDouble("parkour." + arena +  ".X");
                      double r = this.getConfig().getDouble("parkour." + arena +  ".Y");
                      double e = this.getConfig().getDouble("parkour." + arena +  ".Z");
                      float p = (float) this.getConfig().getDouble("parkour." + arena +  ".P");
                      float a = (float) this.getConfig().getDouble("parkour." + arena +  ".A");
                      Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                      event.getPlayer().teleport(tpto);//if teleported start counting
                      //starttime = GetMillis();
                      time1.put(event.getPlayer().getName(), GetMillis());
     
           
                  }
                }
     
     
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                    if(sign.getLine(2).equalsIgnoreCase("end")){
                        time2.put(event.getPlayer().getName(), GetMillis());
             
                        if(time1.containsKey(event.getPlayer().getName()) && time2.containsKey(event.getPlayer().getName())) {
                 
                 
                              millidif = time2.get(event.getPlayer().getName()) - time1.get(event.getPlayer().getName());
                        }
             
                        long secdif = millidif / 1000;
                        event.getPlayer().sendMessage( "" +secdif);//end counting
             
                    }
                }
     
     
            }
          }
        }
     
        public long GetMillis(){
            long millis = System.currentTimeMillis();
            return millis;
        }
     
        @EventHandler
        public void onSignChange(SignChangeEvent event) {
            if(event.getLine(0).equalsIgnoreCase("[gpark]") && event.getPlayer().hasPermission("tt.createsign")){
                if(!event.getLine(1).isEmpty() ){
                event.getPlayer().sendMessage(ChatColor.GREEN + "You created sign for parkour " + ChatColor.GOLD + event.getLine(1));
                }
                else if(event.getLine(2).equalsIgnoreCase("end"))
                {
                    event.getPlayer().sendMessage(ChatColor.GREEN + "You have created end of this parkour!");
                }
                else
                {
                    event.getPlayer().sendMessage(ChatColor.RED + "This sign is incorrect for parkour");
                }
            }
        }
     
     
     
     
     
     
     
     
     
    }
    After while I checked again to debug using:
    Code:
    event.getPlayer().sendMessage(time2.get(event.getPlayer().getName()) + " " + time1.get(event.getPlayer().getName()));//end counting
    and I see that second variable has null value (time1.get()).
     
  21. Offline

    CubixCoders

    Lol okay, did you initialize it in your second click? when they end? use time2.put(p.getName(), GetMillis());
     
  22. Offline

    H2NCH2COOH

    Use long every time with time
     
  23. HashMap time1 for first click return null.
    HashMap time2 works perfect.
    starttime (for debug only as time1) works perfect.


    Line below showes me this:
    1192213131 123143414 null"
    first is time2, second is starttime, third is time1

    I'm very confused why it doesn't work how it should...
    I'm dissappointed because it doesn't look hard to do timer but it's wierd.

    Code:
                        event.getPlayer().sendMessage(time2.get(event.getPlayer().getName()) +  " " + starttime + time1.get(event.getPlayer().getName()));//end counting
    here is code:
    Code:
    package me.grzegorz2047;
     
    import java.util.HashMap;
    import java.util.Map;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    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.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener {
     
        String saved = "Pos saved";
        public String loaded = "Pos loaded";
        boolean notify =true;
        int czas=0;
        int taskid;
        protected int time;
        public long starttime;
        public long millidif;
     
     
     
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            String temp1 = (String) this.getConfig().get("saved",saved);
            String temp2 = (String) this.getConfig().get("loaded",loaded);
            boolean temp3 =  (Boolean) this.getConfig().get("notify",notify);
            this.saveConfig();//zapis
            saved=temp1;
            loaded=temp2;
            notify=temp3;
     
            System.out.println(this.getName()+" Dziala(Workin')");
        }
     
        public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, final String[] args) {
            if (!(sender instanceof Player)) { // If not player, return.
                return false;
            }
     
     
            //Logger log = getLogger();
            Player player = (Player) sender;
            Main plugin = this;
            if(commandLabel.equalsIgnoreCase("gpark")){
                if(args.length==1){
                    if(args[0].equalsIgnoreCase("setspawn") &&  player.hasPermission("gpark.setspawn") ){
                        plugin.getConfig().set("spawn." +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("spawn." +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("spawn." +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("spawn." +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("spawn." +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("spawn." +  ".A", player.getLocation().getYaw());
                        player.sendMessage("Spawn for parkours is set");
                        plugin.saveConfig();//zapis
                        return true;
               
                    }
                }
                if(args.length==2){
                    if(args[0].equalsIgnoreCase("setpark") &&  player.hasPermission("gpark.setpark") ){
                        plugin.getConfig().set("parkour." + args[1] +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("parkour." + args[1] +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("parkour." + args[1] +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("parkour." + args[1] +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("parkour." + args[1] +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("parkour." + args[1] +  ".A", player.getLocation().getYaw());
                        player.sendMessage(ChatColor.GREEN+ "parkour "+ ChatColor.RED +args[1] + ChatColor.GREEN+ " is set");
                        plugin.saveConfig();//zapis
                        return true;
               
                    }
                }
       
       
       
       
       
       
       
            return true;
            }
            return false;
     
        }
     
        @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent evt){
            if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_POWDER.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                //Logger log = getLogger();
                Player player = evt.getPlayer();
                Main plugin = this;
                plugin.getConfig().set("Players." + player.getName() + ".W", player.getWorld().getName());
                plugin.getConfig().set("Players." + player.getName() + ".X", player.getLocation().getX());
                plugin.getConfig().set("Players." + player.getName() + ".Y", player.getLocation().getY());
                plugin.getConfig().set("Players." + player.getName() + ".Z", player.getLocation().getZ());
                plugin.getConfig().set("Players." + player.getName() + ".P", player.getLocation().getPitch());
                plugin.getConfig().set("Players." + player.getName() + ".A", player.getLocation().getYaw());
     
                plugin.saveConfig();//zapis
                if(notify==true)
                evt.getPlayer().sendMessage(ChatColor.YELLOW +"@ " + saved);
     
                }
          if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_ROD.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                {
                    Player player = evt.getPlayer();
                    if(this.getConfig().contains("Players." + player.getName() + ".W")){
           
                        String w = this.getConfig().getString("Players." + player.getName() + ".W");
                        double x = this.getConfig().getDouble("Players." + player.getName() + ".X");
                        double y = this.getConfig().getDouble("Players." + player.getName() + ".Y");
                        double z = this.getConfig().getDouble("Players." + player.getName() + ".Z");
                        float p = (float) this.getConfig().getDouble("Players." + player.getName() + ".P");
                        float a = (float) this.getConfig().getDouble("Players." + player.getName() + ".A");
               
                        Location tpto = new Location(Bukkit.getWorld(w), x, y, z, p, a);
                        player.teleport(tpto);
                        if(notify==true){
                            evt.getPlayer().sendMessage(ChatColor.RED +"@ " +loaded);
                            }
                    }
                    else{
                        evt.getPlayer().sendMessage(ChatColor.RED +"@ " + "You didnt set checkpoint");
                    }
           
                }
     
       
            }
        }
     
     
     
     
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
     
            if (event.isCancelled()) {
                return;
            }
     
            if (event.getFrom().getBlockX() == event.getTo().getBlockX()
                    && event.getFrom().getBlockY() == event.getTo().getBlockY()
                    && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
                return;
            }
     
            Player player = event.getPlayer();
            Location playerLoc = player.getLocation();
            World world = playerLoc.getWorld();
            //Main plugin = this;
     
            for(int x = (int)(playerLoc.getX()-1); x<=(int)(playerLoc.getX()+1); x++) {//Wykrywanie klockow
                for(int y=(int)(playerLoc.getY()-1); y<=(int)(playerLoc.getY()+1); y++) {
                    for(int z=(int)(playerLoc.getZ()-1); z<=(int)(playerLoc.getZ()+1); z++) {
               
                        if(world.getBlockAt(x, y, z).getTypeId() == 10 || world.getBlockAt(x, y, z).getTypeId() == 11) {
                            if(this.getConfig().contains("spawn." +  ".W")){
                                String w = this.getConfig().getString("spawn." + ".W");
                                double q = this.getConfig().getDouble("spawn." + ".X");
                                double r = this.getConfig().getDouble("spawn." + ".Y");
                                double e = this.getConfig().getDouble("spawn." + ".Z");
                                float p = (float) this.getConfig().getDouble("spawn." + ".P");
                                float a = (float) this.getConfig().getDouble("spawn." + ".A");
                                Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                                player.setNoDamageTicks(20);
                       
                                player.teleport(tpto);
                                player.sendMessage(ChatColor.RED + "You failed parkour, back to respawn");
                       
                            }
                            else
                            {
                            player.sendMessage(ChatColor.RED + "Admin didnt set respawn, say it to him,you'll die :D");
                            }
                        }
                    }
                }
            }
        }
     
     
     
        @EventHandler
        public void onClick(PlayerInteractEvent event) {
          if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
              Block i = event.getClickedBlock();
              //Sprawdza czy blok jest znakiem
              if(i.getState() instanceof Sign)
              {
                  BlockState stateBlock = i.getState();
                  Sign sign = (Sign) stateBlock;
                  //Main plugin = this;
                  Map<String, Long> time1 = new HashMap<String, Long>();
                  Map<String, Long> time2 = new HashMap<String, Long>();
         
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
           
                  String arena = sign.getLine(1).toString();
                  if(this.getConfig().contains("parkour." + arena.toString() +  ".W")){
                      starttime = GetMillis();
                      String w = this.getConfig().getString("parkour." + arena +  ".W");
                      double q = this.getConfig().getDouble("parkour." + arena +  ".X");
                      double r = this.getConfig().getDouble("parkour." + arena +  ".Y");
                      double e = this.getConfig().getDouble("parkour." + arena +  ".Z");
                      float p = (float) this.getConfig().getDouble("parkour." + arena +  ".P");
                      float a = (float) this.getConfig().getDouble("parkour." + arena +  ".A");
                      Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                      event.getPlayer().teleport(tpto);//if teleported start counting
                      //
                      time1.put(event.getPlayer().getName(), GetMillis());
     
             
                  }
                }
       
       
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                    if(sign.getLine(2).equalsIgnoreCase("end")){
                        time2.put(event.getPlayer().getName(), GetMillis());
               
                        if(time1.containsKey(event.getPlayer().getName()) && time2.containsKey(event.getPlayer().getName())) {
                   
                   
                              millidif = time2.get(event.getPlayer().getName()) - time1.get(event.getPlayer().getName());
                        }
               
                        long secdif = millidif / 1000;
                        //event.getPlayer().sendMessage( "" +secdif);//end counting
                        event.getPlayer().sendMessage(time2.get(event.getPlayer().getName()) +  " " + starttime + time1.get(event.getPlayer().getName()));//end counting
                    }
                }
     
     
            }
          }
        }
     
        public long GetMillis(){
            long millis = System.currentTimeMillis();
            return millis;
        }
     
        @EventHandler
        public void onSignChange(SignChangeEvent event) {
            if(event.getLine(0).equalsIgnoreCase("[gpark]") && event.getPlayer().hasPermission("tt.createsign")){
                if(!event.getLine(1).isEmpty() ){
                event.getPlayer().sendMessage(ChatColor.GREEN + "You created sign for parkour " + ChatColor.GOLD + event.getLine(1));
                }
                else if(event.getLine(2).equalsIgnoreCase("end"))
                {
                    event.getPlayer().sendMessage(ChatColor.GREEN + "You have created end of this parkour!");
                }
                else
                {
                    event.getPlayer().sendMessage(ChatColor.RED + "This sign is incorrect for parkour");
                }
            }
        }
     
     
     
     
     
     
     
     
     
    }
     
  24. Offline

    CubixCoders

    Try sending the player the message after you do time1.put and see what comes up
     
    grzegorz2047 likes this.
  25. Now it shows correct:
    null , 21312323423, 234234234
    time2 is null but this is normal because is empty. This part is ok.
     
  26. Offline

    CubixCoders

    okay, instead of time2.get(player.getName()) use GetMillis();
     
  27. I think, I found problem. Java is stupid. I had to take HashMaps to the top of class(global) to make it work.
    Now code seems to work. Thank you for your patient and help :) But true is, that in this case, local variables sucks in java. I have never had issues when I'm programming in c++ with local variables.

    Here is code:
    Code:
    package me.grzegorz2047;
     
    import java.util.HashMap;
    import java.util.Map;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    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.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener {
     
        String saved = "Pos saved";
        public String loaded = "Pos loaded";
        boolean notify =true;
        int czas=0;
        int taskid;
        protected int time;
        public long starttime;
        public long millidif;
        Map<String, Long> time1 = new HashMap<String, Long>();
        Map<String, Long> time2 = new HashMap<String, Long>();
       
       
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            String temp1 = (String) this.getConfig().get("saved",saved);
            String temp2 = (String) this.getConfig().get("loaded",loaded);
            boolean temp3 =  (Boolean) this.getConfig().get("notify",notify);
            this.saveConfig();//zapis
            saved=temp1;
            loaded=temp2;
            notify=temp3;
           
            System.out.println(this.getName()+" Dziala(Workin')");
        }
       
        public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, final String[] args) {
            if (!(sender instanceof Player)) { // If not player, return.
                return false;
            }
     
           
            //Logger log = getLogger();
            Player player = (Player) sender;
            Main plugin = this;
            if(commandLabel.equalsIgnoreCase("gpark")){
                if(args.length==1){
                    if(args[0].equalsIgnoreCase("setspawn") &&  player.hasPermission("gpark.setspawn") ){
                        plugin.getConfig().set("spawn." +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("spawn." +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("spawn." +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("spawn." +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("spawn." +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("spawn." +  ".A", player.getLocation().getYaw());
                        player.sendMessage("Spawn for parkours is set");
                        plugin.saveConfig();//zapis
                        return true;
                       
                    }   
                }
                if(args.length==2){
                    if(args[0].equalsIgnoreCase("setpark") &&  player.hasPermission("gpark.setpark") ){
                        plugin.getConfig().set("parkour." + args[1] +  ".W", player.getWorld().getName());
                        plugin.getConfig().set("parkour." + args[1] +  ".X", player.getLocation().getX());
                        plugin.getConfig().set("parkour." + args[1] +  ".Y", player.getLocation().getY());
                        plugin.getConfig().set("parkour." + args[1] +  ".Z", player.getLocation().getZ());
                        plugin.getConfig().set("parkour." + args[1] +  ".P", player.getLocation().getPitch());
                        plugin.getConfig().set("parkour." + args[1] +  ".A", player.getLocation().getYaw());
                        player.sendMessage(ChatColor.GREEN+ "parkour "+ ChatColor.RED +args[1] + ChatColor.GREEN+ " is set");
                        plugin.saveConfig();//zapis
                        return true;
                       
                    }   
                }
               
               
               
               
               
               
               
            return true;
            }
            return false;
           
        }
     
        @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent evt){
            if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_POWDER.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                //Logger log = getLogger();
                Player player = evt.getPlayer();
                Main plugin = this;
                plugin.getConfig().set("Players." + player.getName() + ".W", player.getWorld().getName());
                plugin.getConfig().set("Players." + player.getName() + ".X", player.getLocation().getX());
                plugin.getConfig().set("Players." + player.getName() + ".Y", player.getLocation().getY());
                plugin.getConfig().set("Players." + player.getName() + ".Z", player.getLocation().getZ());
                plugin.getConfig().set("Players." + player.getName() + ".P", player.getLocation().getPitch());
                plugin.getConfig().set("Players." + player.getName() + ".A", player.getLocation().getYaw());
       
                plugin.saveConfig();//zapis
                if(notify==true)
                evt.getPlayer().sendMessage(ChatColor.YELLOW +"@ " + saved);
           
                }
          if(evt.getPlayer().getItemInHand().getTypeId() == Material.BLAZE_ROD.getId()&&  evt.getPlayer().hasPermission("tt.checkpoint")){
                {
                    Player player = evt.getPlayer();
                    if(this.getConfig().contains("Players." + player.getName() + ".W")){
                   
                        String w = this.getConfig().getString("Players." + player.getName() + ".W");
                        double x = this.getConfig().getDouble("Players." + player.getName() + ".X");
                        double y = this.getConfig().getDouble("Players." + player.getName() + ".Y");
                        double z = this.getConfig().getDouble("Players." + player.getName() + ".Z");
                        float p = (float) this.getConfig().getDouble("Players." + player.getName() + ".P");
                        float a = (float) this.getConfig().getDouble("Players." + player.getName() + ".A");
                       
                        Location tpto = new Location(Bukkit.getWorld(w), x, y, z, p, a);
                        player.teleport(tpto);
                        if(notify==true){
                            evt.getPlayer().sendMessage(ChatColor.RED +"@ " +loaded);
                            }
                    }
                    else{
                        evt.getPlayer().sendMessage(ChatColor.RED +"@ " + "You didnt set checkpoint");
                    }
                   
                }
     
               
            }
        }
       
       
       
       
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
     
            if (event.isCancelled()) {
                return;
            }
     
            if (event.getFrom().getBlockX() == event.getTo().getBlockX()
                    && event.getFrom().getBlockY() == event.getTo().getBlockY()
                    && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
                return;
            }
     
            Player player = event.getPlayer();
            Location playerLoc = player.getLocation();
            World world = playerLoc.getWorld();
            //Main plugin = this;
           
            for(int x = (int)(playerLoc.getX()-1); x<=(int)(playerLoc.getX()+1); x++) {//Wykrywanie klockow
                for(int y=(int)(playerLoc.getY()-1); y<=(int)(playerLoc.getY()+1); y++) {
                    for(int z=(int)(playerLoc.getZ()-1); z<=(int)(playerLoc.getZ()+1); z++) {
                       
                        if(world.getBlockAt(x, y, z).getTypeId() == 10 || world.getBlockAt(x, y, z).getTypeId() == 11) {
                            if(this.getConfig().contains("spawn." +  ".W")){
                                String w = this.getConfig().getString("spawn." + ".W");
                                double q = this.getConfig().getDouble("spawn." + ".X");
                                double r = this.getConfig().getDouble("spawn." + ".Y");
                                double e = this.getConfig().getDouble("spawn." + ".Z");
                                float p = (float) this.getConfig().getDouble("spawn." + ".P");
                                float a = (float) this.getConfig().getDouble("spawn." + ".A");
                                Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                                player.setNoDamageTicks(20);
                               
                                player.teleport(tpto);
                                player.sendMessage(ChatColor.RED + "You failed parkour, back to respawn");
                               
                            }
                            else
                            {
                            player.sendMessage(ChatColor.RED + "Admin didnt set respawn, say it to him,you'll die :D");
                            }
                        }
                    }
                }
            }
        }
       
       
       
        @EventHandler
        public void onClick(PlayerInteractEvent event) {
          if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
              Block i = event.getClickedBlock();
              //Sprawdza czy blok jest znakiem
              if(i.getState() instanceof Sign)
              {
                  BlockState stateBlock = i.getState();
                  Sign sign = (Sign) stateBlock;
                  //Main plugin = this;
     
                 
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                   
                  String arena = sign.getLine(1).toString();
                  if(this.getConfig().contains("parkour." + arena.toString() +  ".W")){
                      starttime = GetMillis();
                      String w = this.getConfig().getString("parkour." + arena +  ".W");
                      double q = this.getConfig().getDouble("parkour." + arena +  ".X");
                      double r = this.getConfig().getDouble("parkour." + arena +  ".Y");
                      double e = this.getConfig().getDouble("parkour." + arena +  ".Z");
                      float p = (float) this.getConfig().getDouble("parkour." + arena +  ".P");
                      float a = (float) this.getConfig().getDouble("parkour." + arena +  ".A");
                      Location tpto = new Location(Bukkit.getWorld(w), q, r, e, p, a);
                      event.getPlayer().teleport(tpto);//if teleported start counting
                      //
                      time1.put(event.getPlayer().getName(), GetMillis());
                     
                     
                  }
                }
               
               
                if(sign.getLine(0).equalsIgnoreCase("[gpark]")) {
                    if(sign.getLine(2).equalsIgnoreCase("end")){
                        time2.put(event.getPlayer().getName(), GetMillis());
                        event.getPlayer().sendMessage(time2.get(event.getPlayer().getName()) +  " " + starttime + time1.get(event.getPlayer().getName()));//end counting
                        if(time1.containsKey(event.getPlayer().getName()) && time2.containsKey(event.getPlayer().getName())) {
                           
                           
                              millidif = time2.get(event.getPlayer().getName()) - time1.get(event.getPlayer().getName());
                        }
                       
                        long secdif = millidif / 1000;
                        //event.getPlayer().sendMessage( "" +secdif);//end counting
                        event.getPlayer().sendMessage(time2.get(event.getPlayer().getName()) +  " " + starttime + time1.get(event.getPlayer().getName()));//end counting
                    }
                }
     
     
            }
          }
        }
     
        public long GetMillis(){
            long millis = System.currentTimeMillis();
            return millis;
        }
       
        @EventHandler
        public void onSignChange(SignChangeEvent event) {
            if(event.getLine(0).equalsIgnoreCase("[gpark]") && event.getPlayer().hasPermission("tt.createsign")){
                if(!event.getLine(1).isEmpty() ){
                event.getPlayer().sendMessage(ChatColor.GREEN + "You created sign for parkour " + ChatColor.GOLD + event.getLine(1));
                }
                else if(event.getLine(2).equalsIgnoreCase("end"))
                {
                    event.getPlayer().sendMessage(ChatColor.GREEN + "You have created end of this parkour!");
                }
                else
                {
                    event.getPlayer().sendMessage(ChatColor.RED + "This sign is incorrect for parkour");
                }
            }
        }
       
       
       
       
       
       
       
       
       
    }
     
  28. Offline

    CubixCoders

    Good to know you solved it :) Good luck!
     
  29. Offline

    fireblast709

    then don't override it. You wouldn't need one if you know how to use it properly :3
    afaik they work just the same :3
     
Thread Status:
Not open for further replies.

Share This Page