Cancel teleports for players who engaged in combat while teleporting

This commit is contained in:
William committed 2022-01-13 15:33:29 +00:00
1 parent 6c393661f5
commit 3911a848d4
2 files changed
+21 -1

No files matched your search

@@ -10,6 +10,8 @@ import me.william278.huskhomes2.teleport.points.TeleportationPoint;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Statistic;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@@ -29,6 +31,7 @@ public class TimedTeleport {
private final Player player;
private final Location initialLocation;
private final double initialHealth;
private final int initialPlayerDamageDealt;
private final int warmupTime = HuskHomes.getSettings().getTeleportWarmupTime();
@@ -36,6 +39,7 @@ public class TimedTeleport {
this.player = player;
this.initialLocation = player.getLocation();
this.initialHealth = player.getHealth();
this.initialPlayerDamageDealt = player.getStatistic(Statistic.DAMAGE_DEALT, EntityType.PLAYER);
this.targetType = targetType;
this.targetPoint = targetPoint;
@@ -47,6 +51,7 @@ public class TimedTeleport {
this.player = player;
this.initialLocation = player.getLocation();
this.initialHealth = player.getHealth();
this.initialPlayerDamageDealt = player.getStatistic(Statistic.DAMAGE_DEALT, EntityType.PLAYER);
this.targetType = TargetType.RANDOM;
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
@@ -57,6 +62,7 @@ public class TimedTeleport {
this.player = player;
this.initialLocation = player.getLocation();
this.initialHealth = player.getHealth();
this.initialPlayerDamageDealt = player.getStatistic(Statistic.DAMAGE_DEALT, EntityType.PLAYER);
this.targetType = TargetType.PLAYER;
this.targetPlayerName = targetPlayerName;
@@ -88,6 +94,13 @@ public class TimedTeleport {
sendWarmupMessage(player, "teleporting_action_bar_cancelled");
return;
}
if (hasDamagedPlayers(executablePlayer)) {
cancel();
executablePlayer.playSound(executablePlayer.getLocation(), HuskHomes.getSettings().getTeleportCancelledSound(), 1, 1);
MessageManager.sendMessage(player, "teleporting_cancelled_pvp");
sendWarmupMessage(player, "teleporting_action_bar_cancelled");
return;
}
i[0] = i[0] - 1;
if (i[0] == 0) {
cancel();
@@ -190,6 +203,12 @@ public class TimedTeleport {
return totalDiff > movementThreshold;
}
// This returns if the player has damaged other players
public boolean hasDamagedPlayers(Player p) {
final int playerDamageDealt = p.getStatistic(Statistic.DAMAGE_DEALT, EntityType.PLAYER);
return playerDamageDealt > initialPlayerDamageDealt;
}
public Player getPlayer() {
return player;
}
+2 -1
View File
@@ -119,4 +119,5 @@ error_no_offline_position: '[Error:](#ff3300) [Could not find where %1% last log
error_invalid_player: '[Error:](#ff3300) [Please specify the name of a valid player!](#ff7e5e)'
error_no_homes_set_other: '[Error:](#ff3300) [%1% hasn''t set any homes!](#ff7e5e)'
error_home_invalid_other: '[Error:](#ff3300) [%1% doesn''t have a home set named "%2%"](#ff7e5e)'
error_edit_home_maximum_public_homes: '[Error:](#ff3300) [You can only make a maximum of %1% homes public.](#ff7e5e)'
error_edit_home_maximum_public_homes: '[Error:](#ff3300) [You can only make a maximum of %1% homes public.](#ff7e5e)'
teleporting_cancelled_pvp: '[Teleportation cancelled; you engaged in combat!](#ff7e5e)'