mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Cancel teleports for players who engaged in combat while teleporting
This commit is contained in:
1 parent
6c393661f5
commit
3911a848d4
2 files changed
+20
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 net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Statistic;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
@@ -29,6 +31,7 @@ public class TimedTeleport {
|
|||||||
private final Player player;
|
private final Player player;
|
||||||
private final Location initialLocation;
|
private final Location initialLocation;
|
||||||
private final double initialHealth;
|
private final double initialHealth;
|
||||||
|
private final int initialPlayerDamageDealt;
|
||||||
|
|
||||||
private final int warmupTime = HuskHomes.getSettings().getTeleportWarmupTime();
|
private final int warmupTime = HuskHomes.getSettings().getTeleportWarmupTime();
|
||||||
|
|
||||||
@@ -36,6 +39,7 @@ public class TimedTeleport {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
this.initialLocation = player.getLocation();
|
this.initialLocation = player.getLocation();
|
||||||
this.initialHealth = player.getHealth();
|
this.initialHealth = player.getHealth();
|
||||||
|
this.initialPlayerDamageDealt = player.getStatistic(Statistic.DAMAGE_DEALT, EntityType.PLAYER);
|
||||||
this.targetType = targetType;
|
this.targetType = targetType;
|
||||||
this.targetPoint = targetPoint;
|
this.targetPoint = targetPoint;
|
||||||
|
|
||||||
@@ -47,6 +51,7 @@ public class TimedTeleport {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
this.initialLocation = player.getLocation();
|
this.initialLocation = player.getLocation();
|
||||||
this.initialHealth = player.getHealth();
|
this.initialHealth = player.getHealth();
|
||||||
|
this.initialPlayerDamageDealt = player.getStatistic(Statistic.DAMAGE_DEALT, EntityType.PLAYER);
|
||||||
this.targetType = TargetType.RANDOM;
|
this.targetType = TargetType.RANDOM;
|
||||||
|
|
||||||
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
MessageManager.sendMessage(player, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||||
@@ -57,6 +62,7 @@ public class TimedTeleport {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
this.initialLocation = player.getLocation();
|
this.initialLocation = player.getLocation();
|
||||||
this.initialHealth = player.getHealth();
|
this.initialHealth = player.getHealth();
|
||||||
|
this.initialPlayerDamageDealt = player.getStatistic(Statistic.DAMAGE_DEALT, EntityType.PLAYER);
|
||||||
this.targetType = TargetType.PLAYER;
|
this.targetType = TargetType.PLAYER;
|
||||||
this.targetPlayerName = targetPlayerName;
|
this.targetPlayerName = targetPlayerName;
|
||||||
|
|
||||||
@@ -88,6 +94,13 @@ public class TimedTeleport {
|
|||||||
sendWarmupMessage(player, "teleporting_action_bar_cancelled");
|
sendWarmupMessage(player, "teleporting_action_bar_cancelled");
|
||||||
return;
|
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;
|
i[0] = i[0] - 1;
|
||||||
if (i[0] == 0) {
|
if (i[0] == 0) {
|
||||||
cancel();
|
cancel();
|
||||||
@@ -190,6 +203,12 @@ public class TimedTeleport {
|
|||||||
return totalDiff > movementThreshold;
|
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() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,3 +120,4 @@ error_invalid_player: '[Error:](#ff3300) [Please specify the name of a valid pla
|
|||||||
error_no_homes_set_other: '[Error:](#ff3300) [%1% hasn''t set any homes!](#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_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)'
|
||||||
Reference in new issue
Block a user