Solved Combat Tag plugin problem

Discussion in 'Plugin Development' started by Neymar11, Jul 24, 2014.

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

    Neymar11

    So I am working on a combattag plugin, but I have a problem.
    Most of the stuff works. I made a timer for when 1 player hits another, and It counts just fine. The problem is, when I hit a player, the counter starts, but if I hit the player again, it wount reset and start again, it just keeps counting.. So I want it like this: When I hit a player it should start counting, but If I hit a player again, I need it to repeat.

    Code:

    Code:java
    1. @EventHandler
    2. public void entityDamageByEntityEvent(EntityDamageByEntityEvent event){
    3.  
    4. final Player attacker = (Player) event.getDamager();
    5. final Player attacked = (Player) event.getEntity();
    6. if(event.getDamager() instanceof Player && event.getEntity() instanceof Player){
    7.  
    8. if(!(inCombat.contains(attacker))){
    9.  
    10. inCombat.add(attacker);
    11. inCombat.add(attacked);
    12.  
    13. attacker.sendMessage(ChatColor.GRAY + "[" + ChatColor.YELLOW + "TCCombatTag" +
    14. ChatColor.GRAY + "]" +ChatColor.RED + "You have tagged " + ChatColor.GOLD
    15. + attacked.getName() + ChatColor.RED + " for " + ChatColor.GOLD +
    16. plugin.getConfig().getLong("Time_In_Combat")
    17. + ChatColor.RED + " seconds!");
    18. attacked.sendMessage(ChatColor.GRAY + "[" + ChatColor.YELLOW + "TCCombatTag" +
    19. ChatColor.GRAY + "]" + ChatColor.RED + "You have been tagged by " + ChatColor.GOLD
    20. + attacker.getName() + ChatColor.RED + " for " + ChatColor.GOLD +
    21. plugin.getConfig().getLong("Time_In_Combat")
    22. + ChatColor.RED + " seconds!");
    23.  
    24.  
    25. plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
    26.  
    27. @Override
    28. public void run() {
    29. attacker.sendMessage(ChatColor.GREEN + "You are no longer in combat!");
    30. attacked.sendMessage(ChatColor.GREEN + "You are no longer in combat!");
    31.  
    32. inCombat.remove(attacker);
    33. inCombat.remove(attacked);
    34.  
    35. }
    36. }, plugin.getConfig().getLong("Time_In_Combat") * 20);
    37. }
    38. }
    39. }
     
  2. Offline

    TheWolfBadger

    Neymar11 Don't have it repeat. Have a HashMap that stores the UUIDs and their count. For instance when someone attacks another player.
    "myHashmap.put(player.getUniqueId(), plugin.getConfig().getLong("Time_In_Combat")*20)" You would also want to use a repeating task to degrade the Hashmap's values.
     
  3. Offline

    Neymar11

    TheWolfBadger
    Their count? You mean I should have a timer for each player?
     
  4. Offline

    TheWolfBadger

    Neymar11 Correct. Take a look at my LoggingPreventor on github. Here
     
  5. Offline

    ImDeJay

    When i made my combat tag plugin i did like said above.

    When a player hits another player, i added their name to a hashmap<string, integer>... String being the playername, Integer being the taskID of the timer.

    If they are hit the second time, i got the taskID from the hashmap and canceled the task, then started another task.

    So pretty much....

    Every time a person is attacked, check if they are in the hashmap, if they are, then cancel the old task and start a new task.

    Idk if that makes sense or not, but if you have more questions feel free to ask.
     
Thread Status:
Not open for further replies.

Share This Page