Yeah I don't even know if it's good but here, ha.
Updated the snippet to save by the Player's username, because it was saving the entire other player's character file to yours.
Code:
private Map<String, Long> attackedFirst;
Make sure to call this somewhere, somewhere where it is only going to be called once.
Code:
if(attackedFirst == null)
attackedFirst = new HashMap<String, Long>();
Code:
public boolean attackedFirst(Player player, Player victim) {
if(!victim.getAttackedFirst().containsKey(player.getUsername()))
player.getAttackedFirst().put(victim.getUsername(), System.currentTimeMillis());
refreshAttacked(player);
if(player.getAttackedFirst().containsKey(victim.getUsername()))
return true;
return false;
}
private void refreshAttacked(Player player) {
for(Map.Entry<String, Long> entry : player.getAttackedFirst().entrySet()) {
if(entry.getKey() != null) {
if(System.currentTimeMillis() - entry.getValue() > 600000)
player.getAttackedFirst().remove(entry.getKey());
}
}
}
public Map<String, Long> getAttackedFirst() {
return attackedFirst;
}
public void clearAttacked() {
attackedFirst.clear();
}
Call the clearAttacked method on death, and the attackedFirst(Player, Victim) boolean in your attack method, and if it returns true set skull. It should work, I think...
After 10 minutes when you go to attack someone, before the method attackedFirst(Player, Victim) is returned it checks for any players you attacked over 10 minutes ago, and removes them. Therefore if 10 minutes passes (Without you continuing to attack them) they can then skull on you.
Untested - It works.