From 7182ab822f0cbd67793c596e67acc76a47158492 Mon Sep 17 00:00:00 2001 From: devlrxxh Date: Thu, 4 Apr 2024 23:33:09 +0200 Subject: [PATCH] Quality of live improvements to bedwars --- src/main/java/me/lrxh/practice/Locale.java | 1 + .../java/me/lrxh/practice/match/Match.java | 32 +++++------------- .../me/lrxh/practice/match/MatchListener.java | 22 +++++++++---- .../practice/profile/ProfileListener.java | 1 + .../me/lrxh/practice/util/InventoryUtil.java | 3 ++ .../lrxh/practice/util/PlaceholderUtil.java | 33 +++++++++---------- .../me/lrxh/practice/util/PlayerUtil.java | 10 +++++- .../util/assemble/AssembleThread.java | 6 ++-- src/main/resources/messages.yml | 1 + 9 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/main/java/me/lrxh/practice/Locale.java b/src/main/java/me/lrxh/practice/Locale.java index 0bbd8c2..5508349 100644 --- a/src/main/java/me/lrxh/practice/Locale.java +++ b/src/main/java/me/lrxh/practice/Locale.java @@ -63,6 +63,7 @@ public enum Locale { MATCH_PLAYER_KILLED("MATCH.PLAYER_KILLED"), MATCH_PLAYER_FINAL_KILL("MATCH.PLAYER_FINAL_KILL"), MATCH_PLAYER_DIED("MATCH.PLAYER_DIED"), + MATCH_PLAYER_DIED_FINAL("MATCH.PLAYER_DIED_FINAL"), REMATCH_SENT_REQUEST("REMATCH.SENT_REQUEST"), REMATCH_RECEIVED_REQUEST("REMATCH.RECEIVED_REQUEST"), REMATCH_RECEIVED_REQUEST_HOVER("REMATCH.RECEIVED_REQUEST_HOVER"), diff --git a/src/main/java/me/lrxh/practice/match/Match.java b/src/main/java/me/lrxh/practice/match/Match.java index b6f448e..ab874fe 100644 --- a/src/main/java/me/lrxh/practice/match/Match.java +++ b/src/main/java/me/lrxh/practice/match/Match.java @@ -250,23 +250,19 @@ public void end() { for (GameParticipant gameParticipant : getParticipants()) { for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) { Player player = gamePlayer.getPlayer(); - if (!gamePlayer.isDisconnected()) { if (player != null) { player.setFireTicks(0); player.updateInventory(); Profile profile = Profile.getByUuid(player.getUniqueId()); profile.setState(ProfileState.LOBBY); - profile.setMatch(null); profile.setEnderpearlCooldown(new Cooldown(0)); PlayerUtil.allowMovement(gamePlayer.getPlayer()); - player.sendMessage(CC.translate("&cEnemy &7committed suicide.")); VisibilityLogic.handle(player); Practice.getInstance().getHotbar().giveHotbarItems(player); PlayerUtil.teleportToSpawn(player); PlayerUtil.allowMovement(gamePlayer.getPlayer()); } - } } } @@ -373,6 +369,7 @@ public void respawn(UUID playerUUID) { gamePlayer.setRespawned(true); sendDeathMessage(player, PlayerUtil.getLastAttacker(player), false); + player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0f, 1); player.addPotionEffect( new PotionEffect(PotionEffectType.WEAKNESS, Integer.MAX_VALUE, 0)); @@ -382,12 +379,8 @@ public void respawn(UUID playerUUID) { 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); + PlayerUtil.doVelocityChange(player); + new BukkitRunnable() { int countdown = 3; @@ -395,7 +388,6 @@ public void respawn(UUID playerUUID) { public void run() { if (countdown > 0) { player.sendMessage(Locale.MATCH_RESPAWN_TIMER.format(player, countdown)); - player.playSound(player.getLocation(), Sound.NOTE_PLING, 10, 1); if (!gamePlayer.isRespawned()) { gamePlayer.setRespawned(false); this.cancel(); @@ -403,7 +395,7 @@ public void run() { countdown--; } else { player.sendMessage(Locale.MATCH_RESPAWNED.format(player)); - player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 1); + player.playSound(player.getLocation(), Sound.FALL_BIG, 1.0f, 1.0f); player.setAllowFlight(false); player.setFlying(false); boolean aTeam = getParticipantA().containsPlayer(player.getUniqueId()); @@ -464,7 +456,6 @@ public void showPlayer(UUID playerUUID) { public abstract boolean canEndRound(); public void onDisconnect(Player dead) { - // Don't continue if the match is already ending if (!(state == MatchState.STARTING_ROUND || state == MatchState.PLAYING_ROUND)) { return; } @@ -479,7 +470,6 @@ public void onDisconnect(Player dead) { } } end(); - sendDeathMessage(dead, null, false); } public void onDeath(Player dead) { @@ -530,14 +520,6 @@ public void onDeath(Player dead) { break; } } - dead.setHealth(dead.getMaxHealth()); - dead.setFoodLevel(20); - dead.setVelocity(dead.getVelocity().add(new Vector(0, 0.25, 0))); - dead.setAllowFlight(true); - dead.setFlying(true); - dead.setVelocity(dead.getVelocity().add(new Vector(0, 0.15, 0))); - dead.setAllowFlight(true); - dead.setFlying(true); // Store snapshot of player inventory and stats MatchSnapshot snapshot = new MatchSnapshot(dead, true); @@ -555,6 +537,8 @@ public void onDeath(Player dead) { // Reset inventory PlayerUtil.reset(dead); + PlayerUtil.doVelocityChange(dead); + // Handle visibility for match players // Send death message for (GameParticipant gameParticipant : getParticipants()) { @@ -776,7 +760,7 @@ public void sendDeathMessage(Player dead, Player killer, boolean finalKill) { for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) { Player player = gamePlayer.getPlayer(); if (killer == null) { - deathMessage = Locale.MATCH_PLAYER_FINAL_KILL.format(player, + deathMessage = Locale.MATCH_PLAYER_DIED_FINAL.format(player, getRelationColor(player, dead) + dead.getName() ); } else { @@ -791,7 +775,7 @@ public void sendDeathMessage(Player dead, Player killer, boolean finalKill) { for (Player player : getSpectatorsAsPlayers()) { if (killer == null) { - deathMessage = Locale.MATCH_PLAYER_FINAL_KILL.format(player, + deathMessage = Locale.MATCH_PLAYER_DIED_FINAL.format(player, getRelationColor(player, dead) + dead.getName() ); } else { diff --git a/src/main/java/me/lrxh/practice/match/MatchListener.java b/src/main/java/me/lrxh/practice/match/MatchListener.java index b6856ca..8eea5ca 100644 --- a/src/main/java/me/lrxh/practice/match/MatchListener.java +++ b/src/main/java/me/lrxh/practice/match/MatchListener.java @@ -12,10 +12,7 @@ import me.lrxh.practice.profile.hotbar.HotbarItem; import me.lrxh.practice.util.*; import org.apache.commons.lang.StringEscapeUtils; -import org.bukkit.Color; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; @@ -62,6 +59,11 @@ public void onPlayerMoveEvent(PlayerMoveEvent event) { if (profile.getMatch().kit.getGameRules().isBedwars()) { if (!(player.getLocation().getY() >= match.getArena().getDeathZone()) && !match.getGamePlayer(player).isRespawned()) { if (!bedGone) { + + if(PlayerUtil.getLastAttacker(player) != null){ + player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f); + } + match.respawn(player.getUniqueId()); } else { profile.getMatch().onDeath(player); @@ -191,8 +193,12 @@ public void onBlockBreakEvent(BlockBreakEvent event) { return; } + match.sendSound(Sound.ORB_PICKUP, 1.0F, 1.0F); + match.sendSound(Sound.WITHER_DEATH, 1.0F, 1.0F); + match.broadcast(" "); match.broadcast(Locale.MATCH_BED_BROKEN.format(player, aTeam ? CC.translate("&9Blue") : CC.translate("&cRed"), aTeam ? CC.translate("&c" + player.getName()) : CC.translate("&9" + player.getName()))); + match.broadcast(" "); } if (match.getKit().getGameRules().isBuild() && match.getState() == MatchState.PLAYING_ROUND) { @@ -276,7 +282,7 @@ public void onPlayerPickupItemEvent(PlayerPickupItemEvent event) { event.setCancelled(true); return; } - if (event.getItem().getItemStack().getType().equals(Material.ENDER_STONE) || (event.getItem().getItemStack().getType().equals(Material.WOOD))) { + if (event.getItem().getItemStack().getType().equals(Material.ENDER_STONE) || (event.getItem().getItemStack().getType().equals(Material.WOOD) || event.getItem().getItemStack().getType().equals(Material.WOOL))) { event.setCancelled(false); return; @@ -341,7 +347,6 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) { if (profile.getState() == ProfileState.FIGHTING) { - Match match = profile.getMatch(); event.getDrops().clear(); @@ -352,6 +357,11 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) { if (profile.getMatch().getKit().getGameRules().isBedwars()) { event.getDrops().clear(); if (!bedGone) { + + if(PlayerUtil.getLastAttacker(player) != null){ + player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f); + } + match.respawn(player.getUniqueId()); } else { profile.getMatch().onDeath(player); diff --git a/src/main/java/me/lrxh/practice/profile/ProfileListener.java b/src/main/java/me/lrxh/practice/profile/ProfileListener.java index 02f888f..6ca5e42 100644 --- a/src/main/java/me/lrxh/practice/profile/ProfileListener.java +++ b/src/main/java/me/lrxh/practice/profile/ProfileListener.java @@ -190,6 +190,7 @@ public void onPlayerQuitEvent(PlayerQuitEvent event) { } if (profile.getMatch() != null) { + profile.getMatch().sendDeathMessage(event.getPlayer(), null, false); profile.getMatch().end(); } diff --git a/src/main/java/me/lrxh/practice/util/InventoryUtil.java b/src/main/java/me/lrxh/practice/util/InventoryUtil.java index b37877a..5757d6c 100644 --- a/src/main/java/me/lrxh/practice/util/InventoryUtil.java +++ b/src/main/java/me/lrxh/practice/util/InventoryUtil.java @@ -251,6 +251,9 @@ public static void removeCrafting(Material material) { public static List color(ItemStack[] itemStackList, Color color) { List items = new ArrayList<>(); for (ItemStack itemStack : itemStackList) { + if(itemStack.getType()==null){ + continue; + } if (itemStack.getType() == Material.LEATHER_BOOTS || itemStack.getType() == Material.LEATHER_CHESTPLATE || itemStack.getType() == Material.LEATHER_HELMET || itemStack.getType() == Material.LEATHER_LEGGINGS) { LeatherArmorMeta meta = (LeatherArmorMeta) itemStack.getItemMeta(); diff --git a/src/main/java/me/lrxh/practice/util/PlaceholderUtil.java b/src/main/java/me/lrxh/practice/util/PlaceholderUtil.java index 8c3c800..91fe8ef 100644 --- a/src/main/java/me/lrxh/practice/util/PlaceholderUtil.java +++ b/src/main/java/me/lrxh/practice/util/PlaceholderUtil.java @@ -57,28 +57,27 @@ public static List format(List lines, Player player) { line = line.replaceAll("", profile.getParty().getLeader().getName()); line = line.replaceAll("", String.valueOf(profile.getParty().getListOfPlayers().size())); } + Match match = profile.getMatch(); + if(match != null) { + if (match.getOpponent(player.getUniqueId()) != null) { + line = line.replaceAll("", match.getOpponent(player.getUniqueId()).getName()); + line = line.replaceAll("", match.getDuration()); + line = line.replaceAll("", String.valueOf(BukkitReflection.getPing(match.getOpponent(player.getUniqueId())))); + line = line.replaceAll("", String.valueOf(match.getGamePlayer(player).getHits())); + line = line.replaceAll("", String.valueOf(match.getGamePlayer(match.getOpponent(player.getUniqueId())).getHits())); + line = line.replaceAll("", getDifference(player)); - if (profile.getMatch() != null) { - Match match = profile.getMatch(); - line = line.replaceAll("", match.getOpponent(player.getUniqueId()).getName()); - line = line.replaceAll("", match.getDuration()); - line = line.replaceAll("", String.valueOf(BukkitReflection.getPing(match.getOpponent(player.getUniqueId())))); - line = line.replaceAll("", String.valueOf(match.getGamePlayer(player).getHits())); - line = line.replaceAll("", String.valueOf(match.getGamePlayer(match.getOpponent(player.getUniqueId())).getHits())); - line = line.replaceAll("", getDifference(player)); - - if (match.getKit().getGameRules().isBedwars()) { - line = line.replaceAll("", match.isBedABroken() ? CC.RED + CC.X : CC.GREEN + CC.CHECKMARK); - line = line.replaceAll("", match.isBedBBroken() ? CC.RED + CC.X : CC.GREEN + CC.CHECKMARK); + if (match.getKit().getGameRules().isBedwars()) { + line = line.replaceAll("", match.isBedABroken() ? CC.RED + CC.X : CC.GREEN + CC.CHECKMARK); + line = line.replaceAll("", match.isBedBBroken() ? CC.RED + CC.X : CC.GREEN + CC.CHECKMARK); + } } - } - if (profile.getState() == ProfileState.SPECTATING) { - Match match = profile.getMatch(); - line = line.replaceAll("", match.getDuration()); + if (profile.getState() == ProfileState.SPECTATING) { + line = line.replaceAll("", match.getDuration()); + } } - if (Practice.getInstance().isPlaceholder()) { formattedLines.add(PlaceholderAPI.setPlaceholders(player, line)); } else { diff --git a/src/main/java/me/lrxh/practice/util/PlayerUtil.java b/src/main/java/me/lrxh/practice/util/PlayerUtil.java index 3f6ce06..d289fc4 100644 --- a/src/main/java/me/lrxh/practice/util/PlayerUtil.java +++ b/src/main/java/me/lrxh/practice/util/PlayerUtil.java @@ -91,7 +91,6 @@ public void reset(Player player) { player.getInventory().setContents(new ItemStack[36]); player.getActivePotionEffects().forEach(effect -> player.removePotionEffect(effect.getType())); player.getInventory().setHeldItemSlot(0); - player.updateInventory(); } @@ -112,6 +111,15 @@ public void applyFireballKnockback(Location location, List entities) { } } + public void doVelocityChange(Player player){ + 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); + } + public void denyMovement(Player player) { if (player == null) { return; diff --git a/src/main/java/me/lrxh/practice/util/assemble/AssembleThread.java b/src/main/java/me/lrxh/practice/util/assemble/AssembleThread.java index fa68524..c19b300 100644 --- a/src/main/java/me/lrxh/practice/util/assemble/AssembleThread.java +++ b/src/main/java/me/lrxh/practice/util/assemble/AssembleThread.java @@ -42,8 +42,7 @@ public void run() { private void tick() { for (Player player : this.assemble.getPlugin().getServer().getOnlinePlayers()) { Profile profile = Profile.getByUuid(player.getUniqueId()); - if (player != null) { - try { + try { if (!profile.getOptions().showScoreboard()) { return; } @@ -128,9 +127,8 @@ private void tick() { } catch (Exception e) { //Bukkit.getServer().getScheduler().runTask(assemble.getPlugin(), () -> player.kickPlayer(CC.translate("&cPlease rejoin."))); Bukkit.getLogger().warning("Error updating scoreboard for player " + player.getName() + ": " + e.getMessage()); - } + } } } - } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 6658b3a..ebe3005 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -127,6 +127,7 @@ MATCH: PLAYER_KILLED: '&a{1} &7killed &c{0}&7.' PLAYER_DIED: '{0} &7committed suicide.' PLAYER_FINAL_KILL: '&a{1} &7killed &c{0}&7. &b&lFINAL KILL' + PLAYER_DIED_FINAL: '{0} &7committed suicide. &b&lFINAL KILL' ROUNDS_TO_WIN: '' REMATCH: SENT_REQUEST: