Quick Question?

Discussion in 'Plugin Development' started by Untamedbeast996, Mar 14, 2016.

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

    Untamedbeast996

    I have everything coded listener wise to listen for players and online player

    i just need to know this little bit,

    i want to be able to check if someone is being attacked by 2 or more players at the same time
     
  2. Offline

    Zombie_Striker

    @Untamedbeast996
    This would be achieved by creating your own object that stores all the damagers to a player.
    1. Create a new class (E.g. "Damagers") and create a collection/array that will store all the damagers (Use entities if you also want to take into account non-player entities).
    2. n the main class, add a Map that will store the player's uuid as the key, and a "Damagers" instance as the value.
    3. When a player damages another player, get the damagers instance and add the damager (if they are not currently in the collection/array).
    4. When you want to check the amount of damagers, get the "Damagers" instance and either use collection.size or loop through all the values in the array to get the amount of damagers.
     
  3. Offline

    DoggyCode™

    You would also probably want to remove some damages after a interval (I guess you're trying to see if players are teaming)
     
  4. Offline

    Zombie_Striker

    @Untamedbeast996
    In that case you should store the damagers in a Map. The damagers would be the key and the time the damage was taken would be a value in the form of a Long. When you want to get all the damagers, you would also have to then check if the current time minus the stored time is less than a threshold (e.g. 60 seconds, 5 minutes, ect.)
     
    DoggyCode™ likes this.
  5. Offline

    Untamedbeast996

    Yes i am.... im wanting to stop Teaming in Kitpvp when donors use their diamond armor
     
  6. Offline

    DoggyCode™

    Then above is your answer :p
     
  7. Offline

    Untamedbeast996

    Last edited: Mar 15, 2016
  8. Offline

    Zombie_Striker

    Code:
    7:24:11 AM Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    7:24:11 AM at com.odiegaming.Gary_S_Modd.AntiDiamondTeam.AntiDiamondTeamII.onCommand(AntiDiamondTeamII.java:589) ~[?:?]
    1. There is almost never a reason to have a class with more than one to two hundred lines. You may want to consider breaking your class down into other classes.
    2. Your problem is that you have an empty array. You have to make sure the the arraylist even contains any objects before trying to get an object from it. Use the following before you ever work with arraylists:
      Code:
      if(Array.length > index){
      This makes sure that the object you're trying to get does exists.
     
Thread Status:
Not open for further replies.

Share This Page