Skip to content

Commit

Permalink
Add title dead when reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
KinjerJS committed Apr 22, 2023
1 parent 8a8853c commit 271b4e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/main/java/fr/hyriode/lasergame/game/player/LGGamePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class LGGamePlayer extends HyriGamePlayer {

private int killStreak;

private final static int TIME_DEATH = 5;

public LGGamePlayer(Player player) {
super(player);
}
Expand All @@ -68,9 +70,15 @@ public void cleanPlayer(){

public void kill(LGGamePlayer killer){
if(player == null || !player.isOnline()) return;
int timeDeath = 5;
this.dead();
BroadcastUtil.broadcast(p -> HyriLanguageMessage.get("player.death.chat").getValue(p)
.replace("%victim%", this.getTeam().getColor().getChatColor() + this.player.getName())
.replace("%killer%", killer.getTeam().getColor().getChatColor() + killer.getPlayer().getName()));
}

public void dead() {
this.giveDeathArmor();
this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20 * timeDeath, 1, true, true), true);
this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20 * TIME_DEATH, 1, true, true), true);
this.player.playSound(this.player.getLocation(), Sound.VILLAGER_NO, 1f, 1f);
this.setDead(HyriGameDeathEvent.Reason.PLAYERS, new ArrayList<>());

Expand All @@ -79,7 +87,7 @@ public void kill(LGGamePlayer killer){
.addValue(HyriLanguage.FR, "MORT");

new BukkitRunnable(){
int i = timeDeath;
int i = TIME_DEATH;
@Override
public void run() {
if(plugin.getGame().getState() != HyriGameState.ENDED) {
Expand All @@ -95,17 +103,13 @@ public void run() {
}
}.runTaskTimer(this.plugin, 0L, 20L);

BroadcastUtil.broadcast(p -> HyriLanguageMessage.get("player.death.chat").getValue(p)
.replace("%victim%", this.getTeam().getColor().getChatColor() + this.player.getName())
.replace("%killer%", killer.getTeam().getColor().getChatColor() + killer.getPlayer().getName()));

Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, () -> {
if(this.plugin.getGame().getState() != HyriGameState.ENDED) {
this.setNotDead();
this.playReviveSound(player);
this.giveArmor();
}
}, 20L * timeDeath);
}, 20L * TIME_DEATH);
}

public void playReviveSound(final Player player) {
Expand All @@ -116,12 +120,6 @@ public void playReviveSound(final Player player) {
}
}

public void respawn() {
new ActionBar(HyriLanguageMessage.get("player.death.subtitle.good").getValue(player)).send(player);
this.giveArmor();
this.setNotDead();
}

public void giveArmor(){
giveArmor(this.getTeam().getColor().getDyeColor().getColor());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import fr.hyriode.api.HyriAPI;
import fr.hyriode.api.event.HyriEventHandler;
import fr.hyriode.api.language.HyriLanguageMessage;
import fr.hyriode.hyrame.actionbar.ActionBar;
import fr.hyriode.hyrame.game.HyriGamePlayer;
import fr.hyriode.hyrame.game.HyriGameSpectator;
import fr.hyriode.hyrame.game.event.player.HyriGameDeathEvent;
Expand Down Expand Up @@ -46,6 +48,7 @@ public void onReconnected(HyriGameReconnectedEvent event) {
} else {
player.getPlayer().teleport(((LGGameTeam) player.getTeam()).getConfig().getSpawnLocation());
}
player.dead();
player.spawn();
}

Expand Down

0 comments on commit 271b4e8

Please sign in to comment.