mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-06 12:33:03 +00:00
Adds pvp protection after teleport
This commit is contained in:
parent
97eed50ccc
commit
b14e7c197f
7 changed files with 44 additions and 5 deletions
|
@ -32,6 +32,9 @@ public class EssentialsEntityListener implements Listener
|
||||||
{
|
{
|
||||||
final User defender = ess.getUser(eDefend);
|
final User defender = ess.getUser(eDefend);
|
||||||
final User attacker = ess.getUser(eAttack);
|
final User attacker = ess.getUser(eAttack);
|
||||||
|
if (attacker.hasInvulnerabilityAfterTeleport() || defender.hasInvulnerabilityAfterTeleport()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
attacker.updateActivity(true);
|
attacker.updateActivity(true);
|
||||||
final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
|
final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
|
||||||
if (commandList != null && !commandList.isEmpty())
|
if (commandList != null && !commandList.isEmpty())
|
||||||
|
|
|
@ -229,14 +229,13 @@ public class EssentialsPlayerListener implements Listener
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onPlayerTeleport(final PlayerTeleportEvent event)
|
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.
|
//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())
|
if ((event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND) && ess.getSettings().registerBackInListener())
|
||||||
{
|
{
|
||||||
final User user = ess.getUser(event.getPlayer());
|
|
||||||
user.setLastLocation();
|
user.setLastLocation();
|
||||||
}
|
}
|
||||||
|
user.enableInvulnerabilityAfterTeleport();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class EssentialsTimer implements Runnable
|
||||||
}
|
}
|
||||||
user.checkMuteTimeout(currentTime);
|
user.checkMuteTimeout(currentTime);
|
||||||
user.checkJailTimeout(currentTime);
|
user.checkJailTimeout(currentTime);
|
||||||
|
user.resetInvulnerabilityAfterTeleport();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,4 +169,6 @@ public interface ISettings extends IConf
|
||||||
boolean isMetricsEnabled();
|
boolean isMetricsEnabled();
|
||||||
|
|
||||||
void setMetricsEnabled(boolean metricsEnabled);
|
void setMetricsEnabled(boolean metricsEnabled);
|
||||||
|
|
||||||
|
public long getTeleportInvulnerability();
|
||||||
}
|
}
|
||||||
|
|
|
@ -609,7 +609,7 @@ public class Settings implements ISettings
|
||||||
{
|
{
|
||||||
return config.getBoolean("change-displayname", true);
|
return config.getBoolean("change-displayname", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean changePlayerListName()
|
public boolean changePlayerListName()
|
||||||
{
|
{
|
||||||
|
@ -745,4 +745,10 @@ public class Settings implements ISettings
|
||||||
{
|
{
|
||||||
this.metricsEnabled = metricsEnabled;
|
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;
|
return invSee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInvSee(boolean set)
|
public void setInvSee(final boolean set)
|
||||||
{
|
{
|
||||||
invSee = 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.
|
# 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
|
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
|
# The delay, in seconds, required between /heal attempts
|
||||||
heal-cooldown: 60
|
heal-cooldown: 60
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue