Skip to content

Commit

Permalink
Adding new config setting login-attack-delay. Set this in seconds for…
Browse files Browse the repository at this point in the history
… a delay before players can attack each other after logging on.

Use permission "essentials.pvpdelay.exempt" to bypass this restriction
  • Loading branch information
ementalo committed May 22, 2012
1 parent 3ef591d commit d5f52dd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.inventory.ItemStack;


Expand All @@ -32,10 +32,18 @@ public void onEntityDamage(final EntityDamageByEntityEvent event)
{
final User defender = ess.getUser(eDefend);
final User attacker = ess.getUser(eAttack);

if (!attacker.isAuthorized("essentials.pvpdelay.exempt") &&
System.currentTimeMillis() < (attacker.getLastLogin() + ess.getSettings().getLoginAttackDelay()))
{
event.setCancelled(true);
}

if (attacker.hasInvulnerabilityAfterTeleport() || defender.hasInvulnerabilityAfterTeleport())
{
event.setCancelled(true);
}

attacker.updateActivity(true);
final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
if (commandList != null && !commandList.isEmpty())
Expand Down
2 changes: 2 additions & 0 deletions Essentials/src/com/earth2me/essentials/ISettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,6 @@ public interface ISettings extends IConf
long getTeleportInvulnerability();

boolean isTeleportInvulnerability();

long getLoginAttackDelay();
}
14 changes: 13 additions & 1 deletion Essentials/src/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,22 @@ private boolean _isTeleportInvulnerability()
{
return (config.getLong("teleport-invulnerability", 0) > 0);
}

@Override
public boolean isTeleportInvulnerability()
{
return teleportInvulnerability;
}

private long _loginAttackDelay()
{
return config.getLong("login-attack-delay", 0) * 1000;
}

@Override
public long getLoginAttackDelay()
{
return _loginAttackDelay();
}

}
3 changes: 3 additions & 0 deletions Essentials/src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ repair-enchanted: true
#If you set this to true any plugin that uses teleport will have the previous location registered.
register-back-in-listener: false

#Delay to wait before people can cause attack damage after logging in
login-attack-delay: 0

############################################################
# +------------------------------------------------------+ #
# | EssentialsHome | #
Expand Down

0 comments on commit d5f52dd

Please sign in to comment.