Adds pvp protection after teleport

This commit is contained in:
snowleo 2012-03-27 21:14:38 +02:00
parent 97eed50ccc
commit b14e7c197f
7 changed files with 44 additions and 5 deletions

View File

@ -32,6 +32,9 @@ public class EssentialsEntityListener implements Listener
{
final User defender = ess.getUser(eDefend);
final User attacker = ess.getUser(eAttack);
if (attacker.hasInvulnerabilityAfterTeleport() || defender.hasInvulnerabilityAfterTeleport()) {
event.setCancelled(true);
}
attacker.updateActivity(true);
final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
if (commandList != null && !commandList.isEmpty())

View File

@ -229,14 +229,13 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent event)
{
final User user = ess.getUser(event.getPlayer());
//There is TeleportCause.COMMMAND but plugins have to actively pass the cause in on their teleports.
if ((event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND) && ess.getSettings().registerBackInListener())
{
final User user = ess.getUser(event.getPlayer());
user.setLastLocation();
}
user.enableInvulnerabilityAfterTeleport();
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)

View File

@ -48,6 +48,7 @@ public class EssentialsTimer implements Runnable
}
user.checkMuteTimeout(currentTime);
user.checkJailTimeout(currentTime);
user.resetInvulnerabilityAfterTeleport();
}
}
}

View File

@ -169,4 +169,6 @@ public interface ISettings extends IConf
boolean isMetricsEnabled();
void setMetricsEnabled(boolean metricsEnabled);
public long getTeleportInvulnerability();
}

View File

@ -609,7 +609,7 @@ public class Settings implements ISettings
{
return config.getBoolean("change-displayname", true);
}
@Override
public boolean changePlayerListName()
{
@ -745,4 +745,10 @@ public class Settings implements ISettings
{
this.metricsEnabled = metricsEnabled;
}
@Override
public long getTeleportInvulnerability()
{
return config.getLong("teleport-invulnerability", 0) * 1000;
}
}

View File

@ -603,8 +603,32 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return invSee;
}
public void setInvSee(boolean set)
public void setInvSee(final boolean set)
{
invSee = set;
}
private transient long teleportInvulnerabilityTimestamp = 0;
public void enableInvulnerabilityAfterTeleport()
{
final long time = ess.getSettings().getTeleportInvulnerability();
if (time > 0)
{
teleportInvulnerabilityTimestamp = System.currentTimeMillis() + time;
}
}
public void resetInvulnerabilityAfterTeleport()
{
if (teleportInvulnerabilityTimestamp != 0
&& teleportInvulnerabilityTimestamp < System.currentTimeMillis())
{
teleportInvulnerabilityTimestamp = 0;
}
}
public boolean hasInvulnerabilityAfterTeleport()
{
return teleportInvulnerabilityTimestamp != 0 && teleportInvulnerabilityTimestamp >= System.currentTimeMillis();
}
}

View File

@ -50,6 +50,10 @@ teleport-cooldown: 0
# The delay, in seconds, before a user actually teleports. If the user moves or gets attacked in this timeframe, the teleport never occurs.
teleport-delay: 0
# The delay, in seconds, a player can't be attacked by other players after he has been teleported by a command
# This will also prevent that the player can attack other players
teleport-invulnerability: 0
# The delay, in seconds, required between /heal attempts
heal-cooldown: 60