Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 5, 2024
1 parent c28e932 commit 219c07c
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 180 deletions.
137 changes: 56 additions & 81 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -186,13 +185,15 @@ public void setupPlayer(Player player) {

public Player getOpponent(UUID playerUUID) {
GameParticipant<MatchGamePlayer> playerParticipant = getParticipant(Bukkit.getPlayer(playerUUID));
if (playerParticipant != null) {
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
if (!gameParticipant.equals(playerParticipant)) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
if (!gamePlayer.isDisconnected()) {
return gamePlayer.getPlayer();
}
if (playerParticipant == null) {
return null;
}

for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
if (!gameParticipant.equals(playerParticipant)) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
if (!gamePlayer.isDisconnected()) {
return gamePlayer.getPlayer();
}
}
}
Expand Down Expand Up @@ -250,19 +251,19 @@ public void end() {
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
Player player = gamePlayer.getPlayer();
if (player != null) {
player.setFireTicks(0);
player.updateInventory();

Profile profile = Profile.getByUuid(player.getUniqueId());
profile.setState(ProfileState.LOBBY);
profile.setEnderpearlCooldown(new Cooldown(0));
PlayerUtil.allowMovement(gamePlayer.getPlayer());
VisibilityLogic.handle(player);
Practice.getInstance().getHotbar().giveHotbarItems(player);
PlayerUtil.teleportToSpawn(player);
PlayerUtil.allowMovement(gamePlayer.getPlayer());
}
if (player != null) {
player.setFireTicks(0);
player.updateInventory();

Profile profile = Profile.getByUuid(player.getUniqueId());
profile.setState(ProfileState.LOBBY);
profile.setEnderpearlCooldown(new Cooldown(0));
PlayerUtil.allowMovement(gamePlayer.getPlayer());
VisibilityLogic.handle(player);
Practice.getInstance().getHotbar().giveHotbarItems(player);
PlayerUtil.teleportToSpawn(player);
PlayerUtil.allowMovement(gamePlayer.getPlayer());
}
}
}

Expand All @@ -276,7 +277,6 @@ public void end() {

arena.setActive(false);
}

Practice.getInstance().getCache().getMatches().remove(this);
}

Expand Down Expand Up @@ -353,6 +353,14 @@ public void onRoundEnd() {

removeSpectator(player);
}
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
if (!gamePlayer.isDisconnected()) {
Profile profile = Profile.getByUuid(gamePlayer.getPlayer().getUniqueId());
profile.setMatch(null);
}
}
}
}

public void respawn(UUID playerUUID) {
Expand Down Expand Up @@ -478,7 +486,6 @@ public void onDeath(Player dead) {
if (!(state == MatchState.STARTING_ROUND || state == MatchState.PLAYING_ROUND)) {
return;
}
dead.getInventory().setContents(new ItemStack[36]);
PlayerUtil.animateDeath(dead);

MatchGamePlayer deadGamePlayer = getGamePlayer(dead);
Expand Down Expand Up @@ -520,6 +527,7 @@ public void onDeath(Player dead) {
Bukkit.getScheduler().runTaskLater(Practice.getInstance(), firework::detonate, 5L);
break;
}
PlayerUtil.setLastAttacker(killer, null);
killer.playSound(killer.getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
}

Expand All @@ -536,11 +544,11 @@ public void onDeath(Player dead) {
// Add snapshot to list
snapshots.add(snapshot);

// Reset inventory
PlayerUtil.reset(dead);

PlayerUtil.doVelocityChange(dead);

PlayerUtil.setLastAttacker(dead, null);

// Handle visibility for match players
// Send death message
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
Expand Down Expand Up @@ -584,12 +592,10 @@ public void onDeath(Player dead) {
logicTask.setNextAction(4);
}
} else {
dead.setAllowFlight(true);
dead.setFlying(true);

Practice.getInstance().getHotbar().giveHotbarItems(dead);
}

// Reset inventory
PlayerUtil.reset(dead);
}

public abstract boolean isOnSameTeam(Player first, Player second);
Expand Down Expand Up @@ -757,71 +763,40 @@ protected List<Player> getSpectatorsAsPlayers() {

public void sendDeathMessage(Player dead, Player killer, boolean finalKill) {
String deathMessage;
if (finalKill) {
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
Player player = gamePlayer.getPlayer();
if (killer == null) {
deathMessage = Locale.MATCH_PLAYER_DIED_FINAL.format(player,
getRelationColor(player, dead) + dead.getName()
);
} else {
deathMessage = Locale.MATCH_PLAYER_FINAL_KILL.format(player,
getRelationColor(player, dead) + dead.getName(),
getRelationColor(player, killer) + killer.getName()
);
}
player.sendMessage(deathMessage);
}
}
Locale deathLocale;

for (Player player : getSpectatorsAsPlayers()) {
if (killer == null) {
deathMessage = Locale.MATCH_PLAYER_DIED_FINAL.format(player,
getRelationColor(player, dead) + dead.getName()
);
} else {
deathMessage = Locale.MATCH_PLAYER_FINAL_KILL.format(player,
getRelationColor(player, dead) + dead.getName(),
getRelationColor(player, killer) + killer.getName()
);
}
player.sendMessage(deathMessage);
}
return;
if (finalKill) {
deathLocale = (killer == null) ? Locale.MATCH_PLAYER_DIED_FINAL : Locale.MATCH_PLAYER_FINAL_KILL;
} else {
deathLocale = (killer == null) ? Locale.MATCH_PLAYER_DIED : Locale.MATCH_PLAYER_KILLED;
}

for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
Player player = gamePlayer.getPlayer();
if (killer == null) {
deathMessage = Locale.MATCH_PLAYER_DIED.format(player,
getRelationColor(player, dead) + dead.getName()
);
} else {
deathMessage = Locale.MATCH_PLAYER_KILLED.format(player,
getRelationColor(player, dead) + dead.getName(),
getRelationColor(player, killer) + killer.getName()
);
}
deathMessage = formatDeathMessage(deathLocale, player, dead, killer);
player.sendMessage(deathMessage);
}
}

for (Player player : getSpectatorsAsPlayers()) {
if (killer == null) {
deathMessage = Locale.MATCH_PLAYER_DIED.format(player,
getRelationColor(player, dead) + dead.getName()
);
} else {
deathMessage = Locale.MATCH_PLAYER_KILLED.format(player,
getRelationColor(player, dead) + dead.getName(),
getRelationColor(player, killer) + killer.getName()
);
}
deathMessage = formatDeathMessage(deathLocale, player, dead, killer);
player.sendMessage(deathMessage);
}

}

private String formatDeathMessage(Locale deathLocale, Player player, Player dead, Player killer) {
String deathMessage;
if (killer == null) {
deathMessage = deathLocale.format(player,
getRelationColor(player, dead) + dead.getName()
);
} else {
deathMessage = deathLocale.format(player,
getRelationColor(player, dead) + dead.getName(),
getRelationColor(player, killer) + killer.getName()
);
}
return deathMessage;
}
}
9 changes: 6 additions & 3 deletions src/main/java/me/lrxh/practice/match/MatchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void onPlayerMoveEvent(PlayerMoveEvent event) {
if (!(player.getLocation().getY() >= match.getArena().getDeathZone()) && !match.getGamePlayer(player).isRespawned()) {
if (!bedGone) {

if(PlayerUtil.getLastAttacker(player) != null){
if (PlayerUtil.getLastAttacker(player) != null) {
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f);
}

Expand Down Expand Up @@ -335,6 +335,9 @@ public void onPlayerPickUpEvent(PlayerPickupItemEvent event) {
if (profile.getMatch() != null && profile.getMatch().getState().equals(MatchState.ENDING_MATCH)) {
event.setCancelled(true);
}
if (event.getPlayer().isOp() || event.getPlayer().getGameMode() == GameMode.CREATIVE) {
event.setCancelled(false);
}
}

@EventHandler
Expand All @@ -358,7 +361,7 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) {
event.getDrops().clear();
if (!bedGone) {

if(PlayerUtil.getLastAttacker(player) != null){
if (PlayerUtil.getLastAttacker(player) != null) {
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f);
}

Expand Down Expand Up @@ -739,7 +742,7 @@ public void onPlayerInteractEvent(PlayerInteractEvent event) {
}

if (kitLoadout != null) {
player.sendMessage(Locale.MATCH_GIVE_KIT.format(player, kitLoadout.getCustomName(), kitName));
player.sendMessage(Locale.MATCH_GIVE_KIT.format(player, kitLoadout.getCustomName(), match.getKit().getName()));
profile.getMatch().getGamePlayer(player).setKitLoadout(kitLoadout);
GameParticipant<MatchGamePlayer> participantA = match.getParticipantA();
player.getInventory().setArmorContents(InventoryUtil.color(kitLoadout.getArmor(), participantA.containsPlayer(player.getUniqueId()) ? Color.RED : Color.BLUE).toArray(new ItemStack[0]));
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/me/lrxh/practice/profile/ProfileListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.lrxh.practice.Locale;
import me.lrxh.practice.Practice;
import me.lrxh.practice.match.MatchState;
import me.lrxh.practice.profile.hotbar.HotbarItem;
import me.lrxh.practice.profile.meta.option.button.AllowSpectatorsOptionButton;
import me.lrxh.practice.profile.meta.option.button.DuelRequestsOptionButton;
Expand Down Expand Up @@ -190,10 +191,13 @@ public void onPlayerQuitEvent(PlayerQuitEvent event) {
}

if (profile.getMatch() != null) {
profile.getMatch().sendDeathMessage(event.getPlayer(), null, false);
profile.getMatch().end();
profile.setMatch(null);
if(profile.getMatch().getState().equals(MatchState.PLAYING_ROUND)
|| profile.getMatch().getState().equals(MatchState.ENDING_MATCH)
|| profile.getMatch().getState().equals(MatchState.STARTING_ROUND)){
profile.getMatch().sendDeathMessage(event.getPlayer(), null, false);
}

profile.getMatch().end();
}
if (profile.getState().equals(ProfileState.QUEUEING)) {
profile.getQueueProfile().getQueue().removeQueue();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/lrxh/practice/util/InventoryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public static void removeCrafting(Material material) {
public static List<ItemStack> color(ItemStack[] itemStackList, Color color) {
List<ItemStack> items = new ArrayList<>();
for (ItemStack itemStack : itemStackList) {
if(itemStack.getType()==null){
if (itemStack == null || itemStack.getType() == null) {
continue;
}
if (itemStack.getType() == Material.LEATHER_BOOTS || itemStack.getType() == Material.LEATHER_CHESTPLATE || itemStack.getType() == Material.LEATHER_HELMET
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/me/lrxh/practice/util/MathHelper.java

This file was deleted.

6 changes: 5 additions & 1 deletion src/main/java/me/lrxh/practice/util/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static List<String> format(List<String> lines, Player player) {
line = line.replaceAll("<party-size>", String.valueOf(profile.getParty().getListOfPlayers().size()));
}
Match match = profile.getMatch();
if(match != null) {
if (match != null) {
if (match.getOpponent(player.getUniqueId()) != null) {
line = line.replaceAll("<opponent>", match.getOpponent(player.getUniqueId()).getName());
line = line.replaceAll("<duration>", match.getDuration());
Expand All @@ -70,6 +70,10 @@ public static List<String> format(List<String> lines, Player player) {
if (match.getKit().getGameRules().isBedwars()) {
line = line.replaceAll("<bedA>", match.isBedABroken() ? CC.RED + CC.X : CC.GREEN + CC.CHECKMARK);
line = line.replaceAll("<bedB>", match.isBedBBroken() ? CC.RED + CC.X : CC.GREEN + CC.CHECKMARK);

boolean aTeam = match.getParticipantA().containsPlayer(player.getUniqueId());
line = line.replaceAll("<youA>", aTeam ? "" : "&7YOU");
line = line.replaceAll("<youB>", !aTeam ? "" : "&7YOU");
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/me/lrxh/practice/util/PlayerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public class PlayerUtil {
}

public void setLastAttacker(Player victim, Player attacker) {
victim.setMetadata("lastAttacker", new FixedMetadataValue(Practice.getInstance(), attacker.getUniqueId()));
if(attacker == null){
victim.setMetadata("lastAttacker", new FixedMetadataValue(Practice.getInstance(), null));
}else{
victim.setMetadata("lastAttacker", new FixedMetadataValue(Practice.getInstance(), attacker.getUniqueId()));
}
}

public static void setImmune(Player player, int ticks) {
Expand Down Expand Up @@ -111,7 +115,7 @@ public void applyFireballKnockback(Location location, List<Player> entities) {
}
}

public void doVelocityChange(Player player){
public void doVelocityChange(Player player) {
player.setVelocity(player.getVelocity().add(new Vector(0, 0.25, 0)));
player.setAllowFlight(true);
player.setFlying(true);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/me/lrxh/practice/util/TimeUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.lrxh.practice.util;

import lombok.experimental.UtilityClass;

import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
Expand All @@ -8,15 +10,12 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@UtilityClass
public final class TimeUtil {

private static final String HOUR_FORMAT = "%02d:%02d:%02d";
private static final String MINUTE_FORMAT = "%02d:%02d";

private TimeUtil() {
throw new RuntimeException("Cannot instantiate a utility class.");
}

public static String millisToTimer(long millis) {
long seconds = millis / 1000L;

Expand Down
Loading

0 comments on commit 219c07c

Please sign in to comment.