Need help with an anti-pvp log plugin.. Timer issue?

Discussion in 'Plugin Development' started by ZeusAllMighty11, Sep 8, 2012.

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

    ZeusAllMighty11

    Well I've been trying to prevent those pesky pvp loggers by creating an anti-pvp log plugin.. I have the base of it down. When a player and it's victim enter battle, they are logged in a list. I then need to start a timer, which I need help with... So the timer would reset every time the players hit eachother, until they stopped fighting, when the timer would actually do it's full countdown. When it reached 0 (or less than 1 we should say), we would remove them from a list (i've got that stuff down) and do whatever else.


    Though what happens if more than 2 players are fighting? How can I make timers for each battle 'group' ?

    So let's say bob and fred fight, and they do their stuff and they are logged.
    But during their fight, 2 other noobs from another part of the map named Jack and Jill start fighting. They can't reset bob and fred's timer, that would be pointless and easy to exploit. So instead, they'd need their own timer,... And possibly others if it was a big server.

    I need help figuring that part out ^
     
  2. Do you have this on github, than we can have a look at the code, that's easier helping:)
    I think i would know how to do this, just need some code to look at :p
     
  3. Offline

    ZeusAllMighty11

    Well there really is no code for you to look at... Except the simple listener for entity damage, cheks if hitter and damaged are instanceof player, and then add them to a list...
     
  4. Offline

    Prgr

    Hey Zeus you commented on my PVP Cheats post awhile back so I am returning the favor!
    Do timers reset when one player hits the other? what are you trying to accomplish? What I would do is record the time that joe hit someone in a hashmap for Key>string:playername, Value>customVictimClass(long time, string playername)
    Does that help at all?

    Example hashmap may look like this:
    Key>string:"Fred", Value>customVictimClass(long 15000, string "hannah")
    Key>string:"Fred", Value>customVictimClass(long 15020, string "hannah")
    Key>string:"hannah", Value>customVictimClass(long 15030, string "Fred")
    Key>string:"Joe", Value>customVictimClass(long 15035, string "Carl")
    Key>string:"Fred", Value>customVictimClass(long 15040, string "hannah")
    Key>string:"Carl", Value>customVictimClass(long 15035, string "Joe")
    Key>string:"Joe", Value>customVictimClass(long 15065, string "Carl")

    PS The hashmap can be cleaned out relatively easily
     
    ZeusAllMighty11 likes this.
  5. Yeah, this would be one of the first things i would do, create a hashmap:p
     
  6. Offline

    Prgr

    Hey what is a pvp log? is this about anti-"pvp log" or anti-"pvp" log?
     
  7. Offline

    Zidkon

    Bro I got a plugin done based on AntiPvpLogger plugin, I mean I practically edited the code of the guy who made that plugin and made it better and configurable.

    Basically it works with NPC's, so if players logs out on battle they got an NPC that they can kill and will drop items and all.

    Anyway the system is easier than what u are saying, basically you need to identify if a player is on battle or not by using Hashmap, setting a Map<Player, Boolean>, so you can identify if a player is or not on battle, not as you are saying setting out groups of combat, because wether a player hits you or not you should be in battle, anyway thats up to u to decide.

    So by using the onEntityDamage event you can identify both damager and damaged player, both u should add em sepparate on the hashmap, not together.

    What I did basically was of course check if the damager or damaged player was entities, if they are so I added them to a scheduleSyncDelayedTask, so when the task finishes they got a FALSE value on the hashmap, so they are out of battle.

    So basically every player that is involved into a battle will be registred on the Hashmap, and the scheduleSyncDelayedTask will decide when each one will finish their battle state.

    Don't know if you got the whole idea or if this was what u wanted.

    Anyway sorry for bad grammar :)
     
    ZeusAllMighty11 likes this.
  8. Offline

    TheSmallBones

    Hm... Incorporating my own anti pvp logger into my own plugin... What if 2 people get into combat at 12:00 midnight, then 3 seconds later 2 other people get into combat? Will the delayed task still be running for the first two people or will this interfere?
     
  9. Offline

    skore87

    Just have one scheduler repeating every second or so and check a HashMap<String,Long>. If the Long value is <= the current system time, remove them. To add to it, you would get the current system time and add the desired cooldown time that they would be locked in combat for in milliseconds.

    If you are worried about the scheduler eating up processing power, just have it cancel itself if there is no one in the hashmap. I would have a boolean value stating if the scheduler is on so that you can know to start up the scheduler on pvp contact again. Just remember to send the scheduler it's own task id so that it can cancel itself.
     
  10. Offline

    Zidkon

    No, every schedule is different, they are tasks appart from any other thing and they run sepparated, if someone starts and schedule at 12 m and 2 minutes later someone starts other schedule, each schedule is totally different and they do not interfeer.

    No, each player when they starts battle they starts their own scheduler and it doesnt need to repeat, is a 1 time scheduler that will run() when the time of the combat status goes away (no longer in battle), so it runs only once.

    Of course when the schedule task run it will change the value on the Hashmap of the player, in my case when the task runs it sets to false the Boolean for the player on the Hashmap.

    Yes. Thats true, you must get the ID of the scheduler so you can cancel it if you are going to start again a scheduler for the same player, and of course, I have some checks about the previous task ID.

    You don't need a long value, schedulers are by ticks so here you get the time needed.

    ZeusAllMighty11 if you need any help with this just post here, I have all the code and stuff and I can giv them to you if you like, then u can base ur code or smthing and probably make it better.
     
    TheSmallBones likes this.
  11. Offline

    skore87

    So.... You're saying you actually want the "combat" to be over even if they are still fighting each other? It would have to reset the time if you wanted them to stay in combat for the duration of actual combat...

    That's like saying I bang on you with a stick continually on the forehead for 10 minutes, but at the 1 minute marker I was no longer in in combat status.

    Now I can see if you want to specify exactly who, and if you did you would want to create custom classes and a completely different approach to this than my suggestion, they are in combat with, but what you described there has a huge hole in logic.
     
  12. Offline

    TheSmallBones

    Thank you SO much for explaining this right before I started to change my code :)
     
  13. Offline

    Zidkon

    I never said that, at the plugin I modified I made so if you get hit or u hit (every onEntityDamage event) then you will receive a restart of the schedule cancelling the previous task that played had, of course that depends on some checks I did since I had 2 different times for when a player hit or when a played get hit, so to avoid some errors I did some checks.

    So the combat scheduler timer will completly run if u did the last hit and the time passes and u don't receive or hit someone.

    ZeusAllMighty11 TheSmallBones I forgot to add some important details.

    You need of course to save the ID number of the task, so when someone hits or gets hit, you cancel the previous scheduler with the ID and then start a new one.

    To make it 100% compatible with some plugins that cancels the damage when is done, you will need to set the priority of the ENTITY_DAMAGE to high, so it will be the last plugin where the event will be modified, also you will need to check if the event was cancelled before, so if some plugin will block the attacks (such as a peacefull zone plugin), then your plugin will not set anyone on battle even if they didn't got damage.

    And of course also check if the damage was done by EntityDamageByEntityEvent, and then not mistake with any damage an entity takes xD. Anyway this last one u probably knew already ;)

    Good luck.
     
  14. Offline

    TheSmallBones

    I don't think I need to do the ID thing, when someone gets hit it adds both players to a list called TAGGED and starts a schedular, and it will only start another one if they are NOT on it. :)
     
  15. Offline

    Zidkon

    Then you will get that every 2 players get in 1 schedule making it to work, but by example the timer for the schedule is 10 seconds, at the second 8 I start running, then 2 seconds later we both are out of combat, that would be a way but is YOUR way :p, my way to see it is that your timer will start after the last hit is done, so both will be the time I said in combat, not less.

    Anyway that's up to u to do it that way, at some point you will see people hitting for 10 seconds and they will receive a message saying they are out of battle when they have been hitting themselves for 9 seconds already xD so will be a little strange i think.
     
Thread Status:
Not open for further replies.

Share This Page