mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-16 23:55:28 +01:00
Adds pvp protection after teleport
This commit is contained in:
parent
97eed50ccc
commit
b14e7c197f
@ -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())
|
||||
|
@ -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)
|
||||
|
@ -48,6 +48,7 @@ public class EssentialsTimer implements Runnable
|
||||
}
|
||||
user.checkMuteTimeout(currentTime);
|
||||
user.checkJailTimeout(currentTime);
|
||||
user.resetInvulnerabilityAfterTeleport();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,4 +169,6 @@ public interface ISettings extends IConf
|
||||
boolean isMetricsEnabled();
|
||||
|
||||
void setMetricsEnabled(boolean metricsEnabled);
|
||||
|
||||
public long getTeleportInvulnerability();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user