BEDFIGHTTTTTTTT

This commit is contained in:
nearfe 2024-06-17 21:18:58 -03:00
parent a8fdd72217
commit 710dc7f1d0

View File

@ -0,0 +1,106 @@
package land.battle.practice.match.custom;
import land.battle.practice.Practice;
import land.battle.practice.match.Match;
import land.battle.practice.match.team.impl.MatchTeam;
import land.battle.practice.player.PlayerData;
import land.battle.practice.player.PlayerState;
import land.battle.practice.util.CC;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import static com.cryptomorin.xseries.messages.Titles.sendTitle;
public class CustomMatchRespawnRunnable extends BukkitRunnable {
private final Practice plugin = Practice.getInstance();
private final Player player;
private final PlayerData practicePlayerData;
private final Match match;
private final MatchTeam playerTeam;
private final PotionEffect weakness = new PotionEffect(PotionEffectType.WEAKNESS,
Integer.MAX_VALUE, 0);
private final int startingTime;
private int respawnTime;
public CustomMatchRespawnRunnable(Player player, PlayerData practicePlayerData,
Match match, MatchTeam playerTeam, int startingTime, int respawnTime) {
this.player = player;
this.practicePlayerData = practicePlayerData;
this.match = match;
this.playerTeam = playerTeam;
this.startingTime = startingTime;
this.respawnTime = respawnTime;
}
@Override
public void run() {
final PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId());
if (playerData.getPlayerState() == PlayerState.FIGHTING) {
cancel();
return;
}
if (respawnTime <= 1) {
player.removePotionEffect(PotionEffectType.WEAKNESS);
player.teleport(
playerTeam.getTeamID() == 1 ? match.getStandaloneArena().getPositionOne().toBukkitLocation()
: match.getStandaloneArena().getPositionTwo().toBukkitLocation());
player.setFallDistance(50);
player.setAllowFlight(false);
player.setFlying(false);
sendTitle(player, "&aRespawning...", "");
player.sendMessage(CC.translate("&aYou have respawned!"));
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 1);
player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20, 0));
match.getTeams().forEach(
team -> team.getAlivePlayers().stream().filter(player1 -> !player.equals(player1)).forEach(
matchplayer -> player.sendMessage(CC.translate(playerTeam.getTeamID() == 1 ? "&9"
: "&c" + player.getName() + "&a has respawned!"))));
player.resetMaxHealth();
player.setHealth(player.getMaxHealth());
player.setFoodLevel(20);
match.getKit().applyToPlayer(player);
cancel();
return;
}
if (respawnTime == startingTime) {
player.addPotionEffect(weakness);
player.getInventory().clear();
player.updateInventory();
player.setHealth(player.getMaxHealth());
player.setFoodLevel(20);
player.setVelocity(player.getVelocity().add(new Vector(0, 0.25, 0)));
player.setAllowFlight(true);
player.setFlying(true);
player.setVelocity(player.getVelocity().add(new Vector(0, 0.15, 0)));
player.setAllowFlight(true);
player.setFlying(true);
}
respawnTime--;
sendTitle(player, "&a" + respawnTime, "");
player.playSound(player.getLocation(), Sound.NOTE_PLING, 0.7f, 1.0f);
}
}