From e7e2c1fbc36d71ab0317fa8dbd7c6b0b26c45129 Mon Sep 17 00:00:00 2001 From: devlrxxh Date: Fri, 5 Apr 2024 19:24:21 +0200 Subject: [PATCH] Quality of live improvements --- src/main/java/me/lrxh/practice/Practice.java | 2 +- .../commands/user/match/SpectateCommand.java | 2 +- src/main/java/me/lrxh/practice/kit/Kit.java | 2 +- .../lrxh/practice/kit/command/KitCommand.java | 22 +++++++++- .../lrxh/practice/kit/menu/KitEditorMenu.java | 12 ++--- .../practice/kit/menu/KitManagementMenu.java | 2 +- .../java/me/lrxh/practice/match/Match.java | 39 ++++++---------- .../me/lrxh/practice/match/MatchListener.java | 29 ++++++------ .../match/task/MatchPearlCooldownTask.java | 2 +- .../me/lrxh/practice/profile/KillEffects.java | 44 +++++++++++++++++-- .../profile/visibility/VisibilityLogic.java | 13 ++++++ .../scoreboard/ScoreboardAdapter.java | 2 +- 12 files changed, 115 insertions(+), 56 deletions(-) diff --git a/src/main/java/me/lrxh/practice/Practice.java b/src/main/java/me/lrxh/practice/Practice.java index 6be2cdc..58df9e5 100644 --- a/src/main/java/me/lrxh/practice/Practice.java +++ b/src/main/java/me/lrxh/practice/Practice.java @@ -166,7 +166,7 @@ public void onEnable() { Console.sendMessage(CC.translate(" ")); Console.sendMessage(CC.translate("&7| &cPractice Core")); Console.sendMessage(CC.translate(" ")); - Console.sendMessage(CC.translate("&7| &fAutor(s): &c" + getInstance().getDescription().getAuthors().toString().replace("[", "").replace("]", ""))); + Console.sendMessage(CC.translate("&7| &fAuthor(s): &c" + getInstance().getDescription().getAuthors().toString().replace("[", "").replace("]", ""))); Console.sendMessage(CC.translate("&7| &fVersion: &c" + getInstance().getDescription().getVersion())); Console.sendMessage(CC.translate("&7| &fSpigot: &c" + getInstance().getServer().getName())); Console.sendMessage(CC.translate(" ")); diff --git a/src/main/java/me/lrxh/practice/commands/user/match/SpectateCommand.java b/src/main/java/me/lrxh/practice/commands/user/match/SpectateCommand.java index 062ca38..9286da6 100644 --- a/src/main/java/me/lrxh/practice/commands/user/match/SpectateCommand.java +++ b/src/main/java/me/lrxh/practice/commands/user/match/SpectateCommand.java @@ -63,7 +63,7 @@ public void execute(Player player, String targetName) { public void leave(Player player) { Profile profile = Profile.getByUuid(player.getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING && profile.getMatch().getGamePlayer(player).isDead()) { + if (profile.getMatch() != null && profile.getMatch().getGamePlayer(player).isDead()) { profile.getMatch().getGamePlayer(player).setDisconnected(true); profile.setState(ProfileState.LOBBY); profile.setMatch(null); diff --git a/src/main/java/me/lrxh/practice/kit/Kit.java b/src/main/java/me/lrxh/practice/kit/Kit.java index d188f34..c2f608d 100644 --- a/src/main/java/me/lrxh/practice/kit/Kit.java +++ b/src/main/java/me/lrxh/practice/kit/Kit.java @@ -126,7 +126,7 @@ public void save() { configFile.getConfiguration().set(path + ".game-rules.sumo", gameRules.isSumo()); configFile.getConfiguration().set(path + ".game-rules.bedwars", gameRules.isBedwars()); configFile.getConfiguration().set(path + ".game-rules.health-regeneration", gameRules.isHealthRegeneration()); - configFile.getConfiguration().set(path + ".game-rules.hit-delay", gameRules.getHitDelay()); + configFile.getConfiguration().set(path + ".game-rules.show-health", gameRules.isShowHealth()); configFile.getConfiguration().set(path + ".game-rules.hit-delay", gameRules.getHitDelay()); configFile.getConfiguration().set(path + ".game-rules.boxing", gameRules.isBoxing()); diff --git a/src/main/java/me/lrxh/practice/kit/command/KitCommand.java b/src/main/java/me/lrxh/practice/kit/command/KitCommand.java index eb9ca5d..dc4eaf4 100644 --- a/src/main/java/me/lrxh/practice/kit/command/KitCommand.java +++ b/src/main/java/me/lrxh/practice/kit/command/KitCommand.java @@ -7,7 +7,6 @@ import me.lrxh.practice.match.participant.MatchGamePlayer; import me.lrxh.practice.participant.GameParticipant; import me.lrxh.practice.profile.Profile; -import me.lrxh.practice.profile.ProfileState; import me.lrxh.practice.util.CC; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -54,6 +53,7 @@ public void help2(Player player) { player.sendMessage(CC.translate("&7* &c/kit setdescription &7 &7 &7- &fSet kit description")); player.sendMessage(CC.translate("&7* &c/kit build &7 &7- &fAdd Build rule")); player.sendMessage(CC.translate("&7* &c/kit spleef &7 &7- &fAdd Spleef rule")); + player.sendMessage(CC.translate("&7* &c/kit showhp &7 &7- &fAdd Shop HP rule")); player.sendMessage(CC.translate("&7&m-----------------------------------------")); } @@ -340,6 +340,24 @@ public void hpregen(Player player, String kitName) { player.sendMessage(CC.GREEN + "You updated the kit's health regeneration status to " + (kit.getGameRules().isShowHealth() ? "Enabled" : ChatColor.RED + "Disabled" + ".")); } + @Subcommand("showhp") + @CommandCompletion("@kits") + @Syntax("") + public void showhp(Player player, String kitName) { + if (!Kit.getKits().contains(Kit.getByName(kitName))) { + player.sendMessage(CC.translate("&4ERROR - &cKit doesn't exists!")); + return; + } + Kit kit = Kit.getByName(kitName); + if (kit == null) return; + + kit.getGameRules().setShowHealth(!kit.getGameRules().isShowHealth()); + kit.save(); + + player.sendMessage(CC.GREEN + "You updated the kit's show health status to " + (kit.getGameRules().isShowHealth() ? "Enabled" : ChatColor.RED + "Disabled" + ".")); + } + + @Subcommand("hitdelay") @CommandCompletion("@kits") @Syntax("") @@ -353,7 +371,7 @@ public void showhp(Player player, String kitName, int delay) { kit.getGameRules().setHitDelay(delay); Profile profile = Profile.getByUuid(player.getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { Match match = profile.getMatch(); for (GameParticipant gameParticipant : match.getParticipants()) { for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) { diff --git a/src/main/java/me/lrxh/practice/kit/menu/KitEditorMenu.java b/src/main/java/me/lrxh/practice/kit/menu/KitEditorMenu.java index d27ca90..2eff611 100644 --- a/src/main/java/me/lrxh/practice/kit/menu/KitEditorMenu.java +++ b/src/main/java/me/lrxh/practice/kit/menu/KitEditorMenu.java @@ -152,8 +152,8 @@ private static class ClearInventoryButton extends Button { @Override public ItemStack getButtonItem(Player player) { - return new ItemBuilder(Material.STAINED_CLAY) - .durability(7) + return new ItemBuilder(Material.WOOL) + .durability(3) .name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.EDITOR.BUTTONS.CLEAR-BUTTON")) .clearFlags() .build(); @@ -178,8 +178,8 @@ private static class LoadDefaultKitButton extends Button { @Override public ItemStack getButtonItem(Player player) { - return new ItemBuilder(Material.STAINED_CLAY) - .durability(7) + return new ItemBuilder(Material.WOOL) + .durability(4) .name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.EDITOR.BUTTONS.LOAD-DEFAULT-BUTTON")) .clearFlags() .build(); @@ -208,7 +208,7 @@ private static class SaveButton extends Button { @Override public ItemStack getButtonItem(Player player) { - return new ItemBuilder(Material.STAINED_CLAY) + return new ItemBuilder(Material.WOOL) .durability(5) .name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.EDITOR.BUTTONS.SAVE-BUTTON")) .clearFlags() @@ -240,7 +240,7 @@ private static class CancelButton extends Button { @Override public ItemStack getButtonItem(Player player) { - return new ItemBuilder(Material.STAINED_CLAY) + return new ItemBuilder(Material.WOOL) .durability(14) .name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.EDITOR.BUTTONS.CANCEL-BUTTON")) .clearFlags() diff --git a/src/main/java/me/lrxh/practice/kit/menu/KitManagementMenu.java b/src/main/java/me/lrxh/practice/kit/menu/KitManagementMenu.java index b830ef7..c545782 100644 --- a/src/main/java/me/lrxh/practice/kit/menu/KitManagementMenu.java +++ b/src/main/java/me/lrxh/practice/kit/menu/KitManagementMenu.java @@ -77,7 +77,7 @@ private static class DeleteKitButton extends Button { @Override public ItemStack getButtonItem(Player player) { - return new ItemBuilder(Material.STAINED_CLAY) + return new ItemBuilder(Material.REDSTONE) .name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.MANAGEMENT.BUTTONS.DELETE-BUTTON")) .clearFlags() .build(); diff --git a/src/main/java/me/lrxh/practice/match/Match.java b/src/main/java/me/lrxh/practice/match/Match.java index c8e7d6d..1eb4393 100644 --- a/src/main/java/me/lrxh/practice/match/Match.java +++ b/src/main/java/me/lrxh/practice/match/Match.java @@ -22,14 +22,14 @@ import org.bukkit.*; import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; -import org.bukkit.entity.Firework; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; import java.util.ArrayList; import java.util.Collections; @@ -159,6 +159,11 @@ public void setupPlayer(Player player) { // Reset the player's inventory PlayerUtil.reset(player); + if (kit.getGameRules().isShowHealth()) { + + + } + // Set the player's max damage ticks player.setMaximumNoDamageTicks(getKit().getGameRules().getHitDelay()); @@ -263,6 +268,11 @@ public void end() { Practice.getInstance().getHotbar().giveHotbarItems(player); PlayerUtil.teleportToSpawn(player); PlayerUtil.allowMovement(gamePlayer.getPlayer()); + Objective objective = player.getScoreboard().getObjective(DisplaySlot.BELOW_NAME); + + if (objective != null) { + objective.unregister(); + } } } } @@ -501,31 +511,10 @@ public void onDeath(Player dead) { // Get killer if (killer != null) { + Profile killerProfile = Profile.getByUuid(killer.getUniqueId()); Location location = dead.getLocation(); - World world = location.getWorld(); - switch (killerProfile.getOptions().killEffect()) { - case LIGHTNING: - double x = location.getX(); - double y = location.getY() + 2.0; - double z = location.getZ(); - Location lightningLocation = new Location(world, x, y, z); - world.strikeLightning(lightningLocation); - break; - case FIREWORKS: - Firework firework = world.spawn(location, Firework.class); - FireworkMeta meta = firework.getFireworkMeta(); - FireworkEffect.Builder builder = FireworkEffect.builder() - .withColor(Color.RED) - .with(FireworkEffect.Type.BALL_LARGE) - .trail(true) - .flicker(false); - meta.addEffect(builder.build()); - meta.setPower(1); - firework.setFireworkMeta(meta); - Bukkit.getScheduler().runTaskLater(Practice.getInstance(), firework::detonate, 5L); - break; - } + killerProfile.getOptions().killEffect().execute(killer, location); PlayerUtil.setLastAttacker(killer, null); killer.playSound(killer.getLocation(), Sound.EXPLODE, 1.0f, 1.0f); } diff --git a/src/main/java/me/lrxh/practice/match/MatchListener.java b/src/main/java/me/lrxh/practice/match/MatchListener.java index beac58a..8efcbca 100644 --- a/src/main/java/me/lrxh/practice/match/MatchListener.java +++ b/src/main/java/me/lrxh/practice/match/MatchListener.java @@ -39,7 +39,8 @@ public class MatchListener implements Listener { public void onPlayerMoveEvent(PlayerMoveEvent event) { Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING) { + + if (profile.getMatch() != null) { if (profile.getMatch().getKit().getGameRules().isSumo() || profile.getMatch().getKit().getGameRules().isSpleef()) { Match match = profile.getMatch(); @@ -103,7 +104,7 @@ public void onPlayerMoveEvent(PlayerMoveEvent event) { public void onBlockPlaceEvent(BlockPlaceEvent event) { Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { Match match = profile.getMatch(); if (match.getKit().getGameRules().isBuild() && match.getState() == MatchState.PLAYING_ROUND) { @@ -165,7 +166,7 @@ public void onFallDamageEvent(EntityDamageEvent event) { public void onBlockBreakEvent(BlockBreakEvent event) { Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { Match match = profile.getMatch(); if (event.getBlock().getType() == Material.BED_BLOCK || event.getBlock().getType() == Material.BED) { Player player = event.getPlayer(); @@ -235,7 +236,7 @@ public void onBlockBreakEvent(BlockBreakEvent event) { public void onBucketEmptyEvent(PlayerBucketEmptyEvent event) { Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { Match match = profile.getMatch(); if (match.getKit().getGameRules().isBuild() && match.getState() == MatchState.PLAYING_ROUND) { @@ -271,7 +272,7 @@ public void onBucketEmptyEvent(PlayerBucketEmptyEvent event) { public void onPlayerPickupItemEvent(PlayerPickupItemEvent event) { Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { if (profile.getMatch().getGamePlayer(event.getPlayer()).isDead()) { event.setCancelled(true); return; @@ -312,7 +313,7 @@ public void onPlayerDropItemEvent(PlayerDropItemEvent event) { return; } - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { if (event.getItemDrop().getItemStack().getType() == Material.GLASS_BOTTLE) { event.getItemDrop().remove(); return; @@ -347,7 +348,7 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) { Profile profile = Profile.getByUuid(event.getEntity().getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { Match match = profile.getMatch(); event.getDrops().clear(); @@ -386,7 +387,7 @@ public void onProjectileLaunchEvent(ProjectileLaunchEvent event) { Player shooter = (Player) event.getEntity().getShooter(); Profile profile = Profile.getByUuid(shooter.getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { Match match = profile.getMatch(); if (match.getState() == MatchState.STARTING_ROUND) { @@ -443,7 +444,7 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) { if (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) { Profile profile = Profile.getByUuid(event.getEntity().getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING && !profile.getMatch().getKit().getGameRules().isHealthRegeneration()) { + if (profile.getMatch() != null && !profile.getMatch().getKit().getGameRules().isHealthRegeneration()) { event.setCancelled(true); } } @@ -456,7 +457,7 @@ public void onEntityDamage(EntityDamageEvent event) { Player player = (Player) event.getEntity(); Profile profile = Profile.getByUuid(player.getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { if (event.getCause() == EntityDamageEvent.DamageCause.VOID) { @@ -500,7 +501,7 @@ public void onEntityDamage(EntityDamageEvent event) { public void onHungerChange(FoodLevelChangeEvent event) { Player player = (Player) event.getEntity(); Profile profile = Profile.getByUuid(player.getUniqueId()); - if (!profile.getState().equals(ProfileState.FIGHTING)) return; + if (profile.getMatch() == null) return; if (profile.getMatch().getKit().getGameRules().isSumo() || profile.getMatch().getKit().getGameRules().isBedwars() || profile.getMatch().getKit().getGameRules().isSpleef() @@ -628,7 +629,7 @@ public void onFoodLevelChange(FoodLevelChangeEvent event) { Player player = (Player) event.getEntity(); Profile profile = Profile.getByUuid(player.getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING && + if (profile.getMatch() != null && profile.getMatch().getState() == MatchState.PLAYING_ROUND) { if (event.getFoodLevel() >= 20) { event.setFoodLevel(20); @@ -646,7 +647,7 @@ public void onFoodLevelChange(FoodLevelChangeEvent event) { // public void onPlayerQuitEvent(PlayerQuitEvent event) { // Profile profile = Profile.getProfiles().get(event.getPlayer().getUniqueId()); // -// if (profile.getState() == ProfileState.FIGHTING) { +// if (profile.getMatch() != null) { // Match match = profile.getMatch(); // // if (match != null && (match.getState() == MatchState.STARTING_ROUND || match.getState() == MatchState.PLAYING_ROUND)) { @@ -710,7 +711,7 @@ public void onPlayerInteractEvent(PlayerInteractEvent event) { event.getAction() == Action.RIGHT_CLICK_BLOCK)) { Profile profile = Profile.getByUuid(player.getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { Match match = profile.getMatch(); if (Practice.getInstance().getHotbar().fromItemStack(itemStack) == HotbarItem.SPECTATE_STOP) { diff --git a/src/main/java/me/lrxh/practice/match/task/MatchPearlCooldownTask.java b/src/main/java/me/lrxh/practice/match/task/MatchPearlCooldownTask.java index 8c351d7..de6a49c 100644 --- a/src/main/java/me/lrxh/practice/match/task/MatchPearlCooldownTask.java +++ b/src/main/java/me/lrxh/practice/match/task/MatchPearlCooldownTask.java @@ -14,7 +14,7 @@ public void run() { for (Player player : Practice.getInstance().getServer().getOnlinePlayers()) { Profile profile = Profile.getByUuid(player.getUniqueId()); - if (profile.getState() == ProfileState.FIGHTING || profile.getState() == ProfileState.EVENT) { + if (profile.getMatch() != null || profile.getState() == ProfileState.EVENT) { if (profile.getEnderpearlCooldown().hasExpired()) { if (!profile.getEnderpearlCooldown().isNotified()) { profile.getEnderpearlCooldown().setNotified(true); diff --git a/src/main/java/me/lrxh/practice/profile/KillEffects.java b/src/main/java/me/lrxh/practice/profile/KillEffects.java index 84154e9..134860a 100644 --- a/src/main/java/me/lrxh/practice/profile/KillEffects.java +++ b/src/main/java/me/lrxh/practice/profile/KillEffects.java @@ -1,16 +1,54 @@ package me.lrxh.practice.profile; import lombok.Getter; +import me.lrxh.practice.Practice; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.FireworkEffect; +import org.bukkit.Location; +import org.bukkit.entity.Firework; +import org.bukkit.entity.Player; +import org.bukkit.inventory.meta.FireworkMeta; @Getter public enum KillEffects { - NONE("None"), - LIGHTNING("Lightning"), - FIREWORKS("Fireworks"); + NONE("None") { + @Override + public void execute(Player player, Location location) { + } + }, + LIGHTNING("Lightning") { + @Override + public void execute(Player player, Location location) { + double x = location.getX(); + double y = location.getY() + 2.0; + double z = location.getZ(); + Location lightningLocation = new Location(location.getWorld(), x, y, z); + location.getWorld().strikeLightning(lightningLocation); + } + }, + FIREWORKS("Fireworks") { + @Override + public void execute(Player player, Location location) { + Firework firework = location.getWorld().spawn(location, Firework.class); + FireworkMeta meta = firework.getFireworkMeta(); + FireworkEffect.Builder builder = FireworkEffect.builder() + .withColor(Color.RED) + .with(FireworkEffect.Type.BALL_LARGE) + .trail(true) + .flicker(false); + meta.addEffect(builder.build()); + meta.setPower(1); + firework.setFireworkMeta(meta); + Bukkit.getScheduler().runTaskLater(Practice.getInstance(), firework::detonate, 5L); + } + }; private final String displayName; KillEffects(String displayName) { this.displayName = displayName; } + + public abstract void execute(Player player, Location location); } diff --git a/src/main/java/me/lrxh/practice/profile/visibility/VisibilityLogic.java b/src/main/java/me/lrxh/practice/profile/visibility/VisibilityLogic.java index d090ed0..df558dd 100644 --- a/src/main/java/me/lrxh/practice/profile/visibility/VisibilityLogic.java +++ b/src/main/java/me/lrxh/practice/profile/visibility/VisibilityLogic.java @@ -3,8 +3,12 @@ import me.lrxh.practice.match.participant.MatchGamePlayer; import me.lrxh.practice.profile.Profile; import me.lrxh.practice.profile.ProfileState; +import me.lrxh.practice.util.CC; +import org.apache.commons.lang.StringEscapeUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; public class VisibilityLogic { @@ -53,7 +57,16 @@ public static void handle(Player viewer, Player target) { } else { viewer.hidePlayer(target); } + if (viewerProfile.getMatch().getKit().getGameRules().isShowHealth()) { + Objective objective = viewer.getScoreboard().getObjective(DisplaySlot.BELOW_NAME); + if (objective == null) { + objective = viewer.getScoreboard().registerNewObjective("showhealth", "health"); + } + objective.setDisplaySlot(DisplaySlot.BELOW_NAME); + objective.setDisplayName(CC.RED + StringEscapeUtils.unescapeJava("❤")); + objective.getScore(target.getName()).setScore((int) Math.floor(target.getHealth() / 2)); + } } else if (viewerProfile.getState() == ProfileState.EVENT) { if (targetProfile.getState() == ProfileState.EVENT) { viewer.showPlayer(target); diff --git a/src/main/java/me/lrxh/practice/scoreboard/ScoreboardAdapter.java b/src/main/java/me/lrxh/practice/scoreboard/ScoreboardAdapter.java index 9343393..aa23272 100644 --- a/src/main/java/me/lrxh/practice/scoreboard/ScoreboardAdapter.java +++ b/src/main/java/me/lrxh/practice/scoreboard/ScoreboardAdapter.java @@ -47,7 +47,7 @@ public List getLines(Player player) { } - if (profile.getState() == ProfileState.FIGHTING) { + if (profile.getMatch() != null) { Match match = profile.getMatch(); if (match.getState().equals(MatchState.STARTING_ROUND)) { return PlaceholderUtil.format(new ArrayList<>(Practice.getInstance().getScoreboardConfig().getStringList("MATCH.STARTING")), player);