mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-11 21:06:55 +00:00
added teleport protection
This commit is contained in:
@@ -30,7 +30,7 @@ public class ConfigCache {
|
||||
addDefault("settings.lava_and_fire_stopper.enabled", "true");
|
||||
addDefault("settings.lava_and_fire_stopper.radius", "2.5");
|
||||
|
||||
addDefault("settings.channeling_enchant_disabled", "false", "Disables channeling (trident enchant) lightning strike. You may want to keep it disabled because players with pvp off can use it to attack players with pvp on");
|
||||
addDefault("settings.channeling_enchant_disabled", "false", "Disables channeling (trident enchant) lightning strike.\nYou may want to keep it disabled because players with pvp off can use it to attack players with pvp on");
|
||||
|
||||
addDefault("settings.only_owner_can_interact_with_pet", "false", "Makes it so only pet owner can interact with it. Useful if you don't want people renaming other people's pets.");
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ConfigCache {
|
||||
addDefault("settings.punish_for_combat_logout.announce", "true");
|
||||
addDefault("settings.punish_for_combat_logout.message", "&f%player% logged out while in combat. What a loser.");
|
||||
|
||||
addDefault("settings.cache_time", "30", "Time (in seconds) to keep player data in memory when players goes offline. This is used for checking if offline players pvp state. Adjust only if you know what you're doing. NEVER set to less than 6.");
|
||||
addDefault("settings.cache_time", "30", "Time (in seconds) to keep player data in memory when players goes offline.\nThis is used for checking if offline players pvp state.\nAdjust only if you know what you're doing. NEVER set to less than 6.");
|
||||
|
||||
addDefault("messages.pvp_enabled", "&cYou enabled PvP!");
|
||||
addDefault("messages.pvp_disabled", "&cYou disabled PvP!");
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package eu.endermite.togglepvp.listeners.player;
|
||||
|
||||
import eu.endermite.togglepvp.TogglePvp;
|
||||
import eu.endermite.togglepvp.players.PlayerData;
|
||||
import eu.endermite.togglepvp.players.SmartCache;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import java.time.Instant;
|
||||
|
||||
@eu.endermite.togglepvp.util.Listener
|
||||
public class PlayerTeleportListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerTeleport(org.bukkit.event.player.PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
SmartCache smartCache = TogglePvp.getPlugin().getSmartCache();
|
||||
PlayerData playerData = smartCache.getPlayerData(player.getUniqueId());
|
||||
playerData.setTeleportTimestamp(Instant.now().getEpochSecond());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,11 +10,13 @@ public class PlayerData {
|
||||
private boolean pvpEnabled;
|
||||
private boolean lastCombatCheck;
|
||||
private long loginTimestamp;
|
||||
private long teleportTimestamp;
|
||||
|
||||
public PlayerData(boolean pvpEnabled) {
|
||||
this.pvpEnabled = pvpEnabled;
|
||||
this.combattime = Instant.now().getEpochSecond()-1;
|
||||
this.loginTimestamp = Instant.now().getEpochSecond()-1;
|
||||
this.teleportTimestamp = Instant.now().getEpochSecond()-1;
|
||||
refreshCachetime();
|
||||
}
|
||||
|
||||
@@ -61,4 +63,12 @@ public class PlayerData {
|
||||
public long getLoginTimestamp() {
|
||||
return loginTimestamp;
|
||||
}
|
||||
|
||||
public void setTeleportTimestamp(long teleportTimestamp) {
|
||||
this.teleportTimestamp = teleportTimestamp + TogglePvp.getPlugin().getConfigCache().getTeleport_protection_time();
|
||||
}
|
||||
|
||||
public long getTeleportTimestamp() {
|
||||
return teleportTimestamp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,12 +85,15 @@ public class PlayerManager {
|
||||
|
||||
public boolean canDamage(UUID attacker, UUID victim, boolean sendDenyMessage, boolean checkVictimSpawnProtection) {
|
||||
|
||||
if (hasLoginProtection(attacker))
|
||||
if (hasLoginProtection(attacker) || hasTeleportProtection(attacker))
|
||||
return false;
|
||||
|
||||
if (checkVictimSpawnProtection && hasLoginProtection(victim))
|
||||
return false;
|
||||
|
||||
if (checkVictimSpawnProtection && hasTeleportProtection(victim))
|
||||
return false;
|
||||
|
||||
SmartCache smartCache = TogglePvp.getPlugin().getSmartCache();
|
||||
|
||||
if (!smartCache.getPlayerData(attacker).isPvpEnabled()) {
|
||||
@@ -123,4 +126,9 @@ public class PlayerManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasTeleportProtection(UUID uuid) {
|
||||
SmartCache smartCache = TogglePvp.getPlugin().getSmartCache();
|
||||
return Instant.now().getEpochSecond() < smartCache.getPlayerData(uuid).getTeleportTimestamp();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user