1.14.4 Projectile and explosion making combat log buggy

Discussion in 'Spigot Plugin Development' started by kinukin, Jan 29, 2020.

  1. So I'm making a combat log but every time I get hit by a projectile or explosion then attack the entity that is producing the projectile or explosion the timer gets glitched and doesn't count down properly.

    Sometimes the numbers don't count down properly and sometimes the numbers count down too fast.

    The numbers should be counting from 10 to 0 but the order is bugged.

    Here is an image:


    Note: this only happens when you get attacked by a projectile or explosion then attack another entity while you are still in combat.

    Why is this happening?

    You can add me on my skype if you want to screen share: [email protected]

    Code (Text):
          public void onAntiLogDmg(EntityDamageByEntityEvent event)
            final Entity player = event.getEntity();
            final Entity target = event.getDamager();      
            if((target instanceof Player) || player instanceof Entity){
                if(!antilog.contains(player.getName()) || (!antilog.contains(target.getName())))
                player.sendMessage(ChatColor.GOLD + "You're now in Combat!");
                target.sendMessage(ChatColor.GOLD + "You're now in Combat!");        
                new BukkitRunnable() {
                    public void run() {
                         if ((antilog.contains(player.getName())) || (antilog.contains(target.getName())))
                             if(combattime == 0) {
                                   target.sendMessage(ChatColor.GREEN + "You can now log out safely.");
                                   player.sendMessage(ChatColor.GREEN + "You can now log out safely.");
                                   combattime = 10;
                             } else {
                }.runTaskTimer(Main.getInstance(), 0L, combattime);
              } else {
                    player.sendMessage("added 10 seconds to combat time");
                    target.sendMessage("added 10 seconds to combat time");
                    combattime = 10;
    #1 kinukin, Jan 29, 2020
    Last edited: Jan 29, 2020
  2. you should make one async runnable that runs every second, loops through the hashmap and decrements each player's combat level by one. then in the event just set the value to 10 inside the hashmap for a specific player.
    • Agree Agree x 1