From 3bff8bdb3c4a92e7bbac1f78946c38e99f1b25be Mon Sep 17 00:00:00 2001 From: devlrxxh Date: Wed, 26 Jun 2024 21:51:56 +0200 Subject: [PATCH] New Chunk restore system using NMS and renamed LOBBY -> IN_LOBBY --- pom.xml | 7 +-- .../neptune/arena/impl/StandAloneArena.java | 5 +- .../neptune/commands/KitEditorCommand.java | 2 +- .../neptune/configs/impl/HotbarLocale.java | 50 +++++++++---------- .../neptune/configs/impl/MenusLocale.java | 2 +- .../neptune/configs/impl/MessagesLocale.java | 2 +- .../configs/impl/ScoreboardLocale.java | 2 +- .../neptune/configs/impl/SettingsLocale.java | 5 +- .../lrxh/neptune/hotbar/impl/ItemAction.java | 2 +- .../java/dev/lrxh/neptune/match/Match.java | 2 +- .../neptune/match/listener/MatchListener.java | 2 +- .../neptune/match/tasks/MatchEndRunnable.java | 2 +- .../java/dev/lrxh/neptune/party/Party.java | 4 +- .../neptune/party/command/PartyCommand.java | 2 +- .../dev/lrxh/neptune/profile/Profile.java | 10 ++-- .../lrxh/neptune/profile/ProfileManager.java | 2 +- .../lrxh/neptune/profile/ProfileState.java | 2 +- .../lrxh/neptune/profile/VisibilityLogic.java | 2 +- .../profile/listener/ProfileListener.java | 7 +-- .../scoreboard/ScoreboardAdapter.java | 2 +- .../neptune/queue/tasks/QueueCheckTask.java | 8 +-- .../dev/lrxh/neptune/utils/PlayerUtil.java | 7 ++- .../dev/lrxh/neptune/utils/ServerUtils.java | 8 +-- .../dev/lrxh/neptune/utils/TtlHashMap.java | 30 ++++------- 24 files changed, 82 insertions(+), 85 deletions(-) diff --git a/pom.xml b/pom.xml index 578340b..af9ee42 100644 --- a/pom.xml +++ b/pom.xml @@ -73,15 +73,10 @@ system ${project.basedir}/libs/fawe.jar - - dev.lrxh - Build - 1.0 - dev.lrxh - Shared + Build 1.0 diff --git a/src/main/java/dev/lrxh/neptune/arena/impl/StandAloneArena.java b/src/main/java/dev/lrxh/neptune/arena/impl/StandAloneArena.java index 1d65160..bf129b3 100644 --- a/src/main/java/dev/lrxh/neptune/arena/impl/StandAloneArena.java +++ b/src/main/java/dev/lrxh/neptune/arena/impl/StandAloneArena.java @@ -7,18 +7,19 @@ import lombok.Setter; import lombok.experimental.SuperBuilder; import org.bukkit.Chunk; -import org.bukkit.ChunkSnapshot; import org.bukkit.Location; import java.util.ArrayList; import java.util.HashSet; import java.util.List; + + @Getter @Setter @SuperBuilder public class StandAloneArena extends Arena { - private transient ConcurrentLinkedHashMap chunkSnapshots; + private transient ConcurrentLinkedHashMap chunkSnapshots; private Location min; private Location max; private double deathY; diff --git a/src/main/java/dev/lrxh/neptune/commands/KitEditorCommand.java b/src/main/java/dev/lrxh/neptune/commands/KitEditorCommand.java index 8756fb1..e7c1f21 100644 --- a/src/main/java/dev/lrxh/neptune/commands/KitEditorCommand.java +++ b/src/main/java/dev/lrxh/neptune/commands/KitEditorCommand.java @@ -38,7 +38,7 @@ public void reset(Player player, String kitName) { (Arrays.asList(player.getInventory().getContents())); MessagesLocale.KIT_EDITOR_STOP.send(player.getUniqueId()); - profile.setState(ProfileState.LOBBY); + profile.setState(ProfileState.IN_LOBBY); } MessagesLocale.KIT_EDITOR_RESET.send(player.getUniqueId(), new Replacement("", kit.getDisplayName())); diff --git a/src/main/java/dev/lrxh/neptune/configs/impl/HotbarLocale.java b/src/main/java/dev/lrxh/neptune/configs/impl/HotbarLocale.java index 5d57709..7cd5d0a 100644 --- a/src/main/java/dev/lrxh/neptune/configs/impl/HotbarLocale.java +++ b/src/main/java/dev/lrxh/neptune/configs/impl/HotbarLocale.java @@ -3,37 +3,37 @@ import dev.lrxh.neptune.utils.ConfigFile; import lombok.Getter; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @Getter public enum HotbarLocale implements IDataAccessor { - LOBBY_UNRANKED_NAME("ITEMS.LOBBY.UNRANKED.NAME", null, DataType.STRING, "&aQueue Match &7(Right Click)"), - LOBBY_UNRANKED_MATERIAL("ITEMS.LOBBY.UNRANKED.MATERIAL", null, DataType.STRING, "IRON_SWORD"), - LOBBY_UNRANKED_SLOT("ITEMS.LOBBY.UNRANKED.SLOT", null, DataType.INT, "0"), - LOBBY_UNRANKED_ENABLED("ITEMS.LOBBY.UNRANKED.ENABLED", null, DataType.BOOLEAN, "true"), - LOBBY_SPECTATE_MENU_NAME("ITEMS.LOBBY.SPECTATE_MENU.NAME", null, DataType.STRING, "&6View Matches &7(Right Click)"), - LOBBY_SPECTATE_MENU_MATERIAL("ITEMS.LOBBY.SPECTATE_MENU.MATERIAL", null, DataType.STRING, "EMERALD"), - LOBBY_SPECTATE_MENU_SLOT("ITEMS.LOBBY.SPECTATE_MENU.SLOT", null, DataType.INT, "1"), - LOBBY_SPECTATE_MENU_ENABLED("ITEMS.LOBBY.SPECTATE_MENU.ENABLED", null, DataType.BOOLEAN, "true"), - LOBBY_PARTY_CREATE_NAME("ITEMS.LOBBY.PARTY_CREATE.NAME", null, DataType.STRING, "&9Create Party &7(Right Click)"), - LOBBY_PARTY_CREATE_MATERIAL("ITEMS.LOBBY.PARTY_CREATE.MATERIAL", null, DataType.STRING, "NAME_TAG"), - LOBBY_PARTY_CREATE_SLOT("ITEMS.LOBBY.PARTY_CREATE.SLOT", null, DataType.INT, "3"), - LOBBY_PARTY_CREATE_ENABLED("ITEMS.LOBBY.PARTY_CREATE.ENABLED", null, DataType.BOOLEAN, "true"), - LOBBY_LEADERBOARDS_NAME("ITEMS.LOBBY.LEADERBOARDS.NAME", null, DataType.STRING, "&cLeaderboards &7(Right Click)"), - LOBBY_LEADERBOARDS_MATERIAL("ITEMS.LOBBY.LEADERBOARDS.MATERIAL", null, DataType.STRING, "NETHER_STAR"), - LOBBY_LEADERBOARDS_SLOT("ITEMS.LOBBY.LEADERBOARDS.SLOT", null, DataType.INT, "5"), - LOBBY_LEADERBOARDS_ENABLED("ITEMS.LOBBY.LEADERBOARDS.ENABLED", null, DataType.BOOLEAN, "true"), - LOBBY_STATS_NAME("ITEMS.LOBBY.STATS.NAME", null, DataType.STRING, "&eStats &7(Right Click)"), - LOBBY_STATS_MATERIAL("ITEMS.LOBBY.STATS.MATERIAL", null, DataType.STRING, "COMPASS"), - LOBBY_STATS_SLOT("ITEMS.LOBBY.STATS.SLOT", null, DataType.INT, "7"), - LOBBY_STATS_ENABLED("ITEMS.LOBBY.STATS.ENABLED", null, DataType.BOOLEAN, "true"), - LOBBY_KIT_EDITOR_NAME("ITEMS.LOBBY.KIT_EDITOR.NAME", null, DataType.STRING, "&dKit Editor &7(Right Click)"), - LOBBY_KIT_EDITOR_MATERIAL("ITEMS.LOBBY.KIT_EDITOR.MATERIAL", null, DataType.STRING, "BOOK"), - LOBBY_KIT_EDITOR_SLOT("ITEMS.LOBBY.KIT_EDITOR.SLOT", null, DataType.INT, "8"), - LOBBY_KIT_EDITOR_ENABLED("ITEMS.LOBBY.KIT_EDITOR.ENABLED", null, DataType.BOOLEAN, "true"), + LOBBY_UNRANKED_NAME("ITEMS.IN_LOBBY.UNRANKED.NAME", null, DataType.STRING, "&aQueue Match &7(Right Click)"), + LOBBY_UNRANKED_MATERIAL("ITEMS.IN_LOBBY.UNRANKED.MATERIAL", null, DataType.STRING, "IRON_SWORD"), + LOBBY_UNRANKED_SLOT("ITEMS.IN_LOBBY.UNRANKED.SLOT", null, DataType.INT, "0"), + LOBBY_UNRANKED_ENABLED("ITEMS.IN_LOBBY.UNRANKED.ENABLED", null, DataType.BOOLEAN, "true"), + LOBBY_SPECTATE_MENU_NAME("ITEMS.IN_LOBBY.SPECTATE_MENU.NAME", null, DataType.STRING, "&6View Matches &7(Right Click)"), + LOBBY_SPECTATE_MENU_MATERIAL("ITEMS.IN_LOBBY.SPECTATE_MENU.MATERIAL", null, DataType.STRING, "EMERALD"), + LOBBY_SPECTATE_MENU_SLOT("ITEMS.IN_LOBBY.SPECTATE_MENU.SLOT", null, DataType.INT, "1"), + LOBBY_SPECTATE_MENU_ENABLED("ITEMS.IN_LOBBY.SPECTATE_MENU.ENABLED", null, DataType.BOOLEAN, "true"), + LOBBY_PARTY_CREATE_NAME("ITEMS.IN_LOBBY.PARTY_CREATE.NAME", null, DataType.STRING, "&9Create Party &7(Right Click)"), + LOBBY_PARTY_CREATE_MATERIAL("ITEMS.IN_LOBBY.PARTY_CREATE.MATERIAL", null, DataType.STRING, "NAME_TAG"), + LOBBY_PARTY_CREATE_SLOT("ITEMS.IN_LOBBY.PARTY_CREATE.SLOT", null, DataType.INT, "3"), + LOBBY_PARTY_CREATE_ENABLED("ITEMS.IN_LOBBY.PARTY_CREATE.ENABLED", null, DataType.BOOLEAN, "true"), + LOBBY_LEADERBOARDS_NAME("ITEMS.IN_LOBBY.LEADERBOARDS.NAME", null, DataType.STRING, "&cLeaderboards &7(Right Click)"), + LOBBY_LEADERBOARDS_MATERIAL("ITEMS.IN_LOBBY.LEADERBOARDS.MATERIAL", null, DataType.STRING, "NETHER_STAR"), + LOBBY_LEADERBOARDS_SLOT("ITEMS.IN_LOBBY.LEADERBOARDS.SLOT", null, DataType.INT, "5"), + LOBBY_LEADERBOARDS_ENABLED("ITEMS.IN_LOBBY.LEADERBOARDS.ENABLED", null, DataType.BOOLEAN, "true"), + LOBBY_STATS_NAME("ITEMS.IN_LOBBY.STATS.NAME", null, DataType.STRING, "&eStats &7(Right Click)"), + LOBBY_STATS_MATERIAL("ITEMS.IN_LOBBY.STATS.MATERIAL", null, DataType.STRING, "COMPASS"), + LOBBY_STATS_SLOT("ITEMS.IN_LOBBY.STATS.SLOT", null, DataType.INT, "7"), + LOBBY_STATS_ENABLED("ITEMS.IN_LOBBY.STATS.ENABLED", null, DataType.BOOLEAN, "true"), + LOBBY_KIT_EDITOR_NAME("ITEMS.IN_LOBBY.KIT_EDITOR.NAME", null, DataType.STRING, "&dKit Editor &7(Right Click)"), + LOBBY_KIT_EDITOR_MATERIAL("ITEMS.IN_LOBBY.KIT_EDITOR.MATERIAL", null, DataType.STRING, "BOOK"), + LOBBY_KIT_EDITOR_SLOT("ITEMS.IN_LOBBY.KIT_EDITOR.SLOT", null, DataType.INT, "8"), + LOBBY_KIT_EDITOR_ENABLED("ITEMS.IN_LOBBY.KIT_EDITOR.ENABLED", null, DataType.BOOLEAN, "true"), IN_QUEUE_QUEUE_LEAVE_NAME("ITEMS.IN_QUEUE.QUEUE_LEAVE.NAME", null, DataType.STRING, "&cLeave Queue &7(Right Click)"), IN_QUEUE_QUEUE_LEAVE_MATERIAL("ITEMS.IN_QUEUE.QUEUE_LEAVE.MATERIAL", null, DataType.STRING, "RED_DYE"), IN_QUEUE_QUEUE_LEAVE_SLOT("ITEMS.IN_QUEUE.QUEUE_LEAVE.SLOT", null, DataType.INT, "8"), diff --git a/src/main/java/dev/lrxh/neptune/configs/impl/MenusLocale.java b/src/main/java/dev/lrxh/neptune/configs/impl/MenusLocale.java index 0505420..4e770c3 100644 --- a/src/main/java/dev/lrxh/neptune/configs/impl/MenusLocale.java +++ b/src/main/java/dev/lrxh/neptune/configs/impl/MenusLocale.java @@ -3,7 +3,7 @@ import dev.lrxh.neptune.utils.ConfigFile; import lombok.Getter; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/dev/lrxh/neptune/configs/impl/MessagesLocale.java b/src/main/java/dev/lrxh/neptune/configs/impl/MessagesLocale.java index fef0bd5..839988e 100644 --- a/src/main/java/dev/lrxh/neptune/configs/impl/MessagesLocale.java +++ b/src/main/java/dev/lrxh/neptune/configs/impl/MessagesLocale.java @@ -5,8 +5,8 @@ import dev.lrxh.neptune.utils.ConfigFile; import dev.lrxh.neptune.utils.PlayerUtil; import lombok.Getter; +import org.jetbrains.annotations.Nullable; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/dev/lrxh/neptune/configs/impl/ScoreboardLocale.java b/src/main/java/dev/lrxh/neptune/configs/impl/ScoreboardLocale.java index 152b9b3..ee518e8 100644 --- a/src/main/java/dev/lrxh/neptune/configs/impl/ScoreboardLocale.java +++ b/src/main/java/dev/lrxh/neptune/configs/impl/ScoreboardLocale.java @@ -3,7 +3,7 @@ import dev.lrxh.neptune.utils.ConfigFile; import lombok.Getter; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/dev/lrxh/neptune/configs/impl/SettingsLocale.java b/src/main/java/dev/lrxh/neptune/configs/impl/SettingsLocale.java index 358ad10..20511d4 100644 --- a/src/main/java/dev/lrxh/neptune/configs/impl/SettingsLocale.java +++ b/src/main/java/dev/lrxh/neptune/configs/impl/SettingsLocale.java @@ -3,7 +3,7 @@ import dev.lrxh.neptune.utils.ConfigFile; import lombok.Getter; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -34,5 +34,4 @@ public enum SettingsLocale implements IDataAccessor { public ConfigFile getConfigFile() { return plugin.getConfigManager().getMainConfig(); } - -} +} \ No newline at end of file diff --git a/src/main/java/dev/lrxh/neptune/hotbar/impl/ItemAction.java b/src/main/java/dev/lrxh/neptune/hotbar/impl/ItemAction.java index 1a1f48b..1dc5fef 100644 --- a/src/main/java/dev/lrxh/neptune/hotbar/impl/ItemAction.java +++ b/src/main/java/dev/lrxh/neptune/hotbar/impl/ItemAction.java @@ -30,7 +30,7 @@ public void execute(Player player) { QUEUE_LEAVE() { @Override public void execute(Player player) { - Neptune.get().getProfileManager().getByUUID(player.getUniqueId()).setState(ProfileState.LOBBY); + Neptune.get().getProfileManager().getByUUID(player.getUniqueId()).setState(ProfileState.IN_LOBBY); Neptune.get().getQueueManager().remove(player.getUniqueId()); MessagesLocale.QUEUE_LEAVE.send(player.getUniqueId()); } diff --git a/src/main/java/dev/lrxh/neptune/match/Match.java b/src/main/java/dev/lrxh/neptune/match/Match.java index c51477d..0114515 100644 --- a/src/main/java/dev/lrxh/neptune/match/Match.java +++ b/src/main/java/dev/lrxh/neptune/match/Match.java @@ -168,7 +168,7 @@ public void removeSpectator(UUID playerUUID, boolean sendMessage) { if (profile.getMatch() == null) return; PlayerUtil.reset(playerUUID); PlayerUtil.teleportToSpawn(playerUUID); - profile.setState(ProfileState.LOBBY); + profile.setState(ProfileState.IN_LOBBY); profile.setMatch(null); spectators.remove(playerUUID); diff --git a/src/main/java/dev/lrxh/neptune/match/listener/MatchListener.java b/src/main/java/dev/lrxh/neptune/match/listener/MatchListener.java index de58313..39f851e 100644 --- a/src/main/java/dev/lrxh/neptune/match/listener/MatchListener.java +++ b/src/main/java/dev/lrxh/neptune/match/listener/MatchListener.java @@ -274,7 +274,7 @@ public void onBlockBreakEvent(BlockBreakEvent event) { if (player.getGameMode().equals(GameMode.CREATIVE)) return; Profile profile = plugin.getProfileManager().getByUUID(player.getUniqueId()); if (profile == null) return; - if (profile.getState().equals(ProfileState.LOBBY)) { + if (profile.getState().equals(ProfileState.IN_LOBBY)) { event.setCancelled(true); return; } diff --git a/src/main/java/dev/lrxh/neptune/match/tasks/MatchEndRunnable.java b/src/main/java/dev/lrxh/neptune/match/tasks/MatchEndRunnable.java index 5810918..83f8c66 100644 --- a/src/main/java/dev/lrxh/neptune/match/tasks/MatchEndRunnable.java +++ b/src/main/java/dev/lrxh/neptune/match/tasks/MatchEndRunnable.java @@ -37,7 +37,7 @@ public void run() { if (profile.getMatch() == null) continue; PlayerUtil.reset(participant.getPlayerUUID()); PlayerUtil.teleportToSpawn(participant.getPlayerUUID()); - profile.setState(profile.getGameData().getParty() == null ? ProfileState.LOBBY : ProfileState.IN_PARTY); + profile.setState(profile.getGameData().getParty() == null ? ProfileState.IN_LOBBY : ProfileState.IN_PARTY); profile.setMatch(null); } diff --git a/src/main/java/dev/lrxh/neptune/party/Party.java b/src/main/java/dev/lrxh/neptune/party/Party.java index a12f8a6..0f6db72 100644 --- a/src/main/java/dev/lrxh/neptune/party/Party.java +++ b/src/main/java/dev/lrxh/neptune/party/Party.java @@ -77,7 +77,7 @@ public void remove(UUID playerUUID) { Profile profile = Neptune.get().getProfileManager().getByUUID(playerUUID); users.remove(playerUUID); profile.getGameData().setParty(null); - profile.setState(ProfileState.LOBBY); + profile.setState(ProfileState.IN_LOBBY); } public void disband() { @@ -85,7 +85,7 @@ public void disband() { for (UUID user : users) { Profile profile = Neptune.get().getProfileManager().getByUUID(user); profile.getGameData().setParty(null); - profile.setState(ProfileState.LOBBY); + profile.setState(ProfileState.IN_LOBBY); } } diff --git a/src/main/java/dev/lrxh/neptune/party/command/PartyCommand.java b/src/main/java/dev/lrxh/neptune/party/command/PartyCommand.java index cdec841..eb56838 100644 --- a/src/main/java/dev/lrxh/neptune/party/command/PartyCommand.java +++ b/src/main/java/dev/lrxh/neptune/party/command/PartyCommand.java @@ -125,7 +125,7 @@ public void invite(Player player, String otherPlayer) { @Syntax("") public void accept(Player player, String otherString) { Profile profile = Neptune.get().getProfileManager().getByUUID(player.getUniqueId()); - if (!profile.getState().equals(ProfileState.LOBBY)) return; + if (!profile.getState().equals(ProfileState.IN_LOBBY)) return; try { if (profile.getGameData().getParty() != null) { MessagesLocale.PARTY_ALREADY_IN.send(player.getUniqueId()); diff --git a/src/main/java/dev/lrxh/neptune/profile/Profile.java b/src/main/java/dev/lrxh/neptune/profile/Profile.java index cf65d0c..ed6d7be 100644 --- a/src/main/java/dev/lrxh/neptune/profile/Profile.java +++ b/src/main/java/dev/lrxh/neptune/profile/Profile.java @@ -34,10 +34,14 @@ public class Profile { private GameData gameData; private MongoCollection collection = Neptune.get().getMongoManager().getCollection(); - public Profile(UUID playerUUID, ProfileState state) { + public Profile(UUID playerUUID) { this.playerUUID = playerUUID; - this.state = state; - this.username = Bukkit.getPlayer(playerUUID).getName(); + this.state = ProfileState.IN_LOBBY; + + Player player = Bukkit.getPlayer(playerUUID); + if(player == null) return; + + this.username = player.getName(); this.gameData = new GameData(); for (Kit kit : Neptune.get().getKitManager().kits) { diff --git a/src/main/java/dev/lrxh/neptune/profile/ProfileManager.java b/src/main/java/dev/lrxh/neptune/profile/ProfileManager.java index 92779f9..476de78 100644 --- a/src/main/java/dev/lrxh/neptune/profile/ProfileManager.java +++ b/src/main/java/dev/lrxh/neptune/profile/ProfileManager.java @@ -10,7 +10,7 @@ public class ProfileManager { private final Neptune plugin = Neptune.get(); public Profile createProfile(UUID playerUUID) { - Profile profile = new Profile(playerUUID, ProfileState.LOBBY); + Profile profile = new Profile(playerUUID); profiles.put(playerUUID, profile); return profile; } diff --git a/src/main/java/dev/lrxh/neptune/profile/ProfileState.java b/src/main/java/dev/lrxh/neptune/profile/ProfileState.java index ee70eb9..5567b84 100644 --- a/src/main/java/dev/lrxh/neptune/profile/ProfileState.java +++ b/src/main/java/dev/lrxh/neptune/profile/ProfileState.java @@ -1,7 +1,7 @@ package dev.lrxh.neptune.profile; public enum ProfileState { - LOBBY, + IN_LOBBY, IN_QUEUE, IN_GAME, IN_KIT_EDITOR, diff --git a/src/main/java/dev/lrxh/neptune/profile/VisibilityLogic.java b/src/main/java/dev/lrxh/neptune/profile/VisibilityLogic.java index 950f8fb..962c52c 100644 --- a/src/main/java/dev/lrxh/neptune/profile/VisibilityLogic.java +++ b/src/main/java/dev/lrxh/neptune/profile/VisibilityLogic.java @@ -37,7 +37,7 @@ public void handle(UUID playerUUID, UUID otherUUID) { return; } - if (has(playerUUID, otherUUID, ProfileState.LOBBY, ProfileState.IN_QUEUE, ProfileState.IN_PARTY)) { + if (has(playerUUID, otherUUID, ProfileState.IN_LOBBY, ProfileState.IN_QUEUE, ProfileState.IN_PARTY)) { viewerPlayer.showPlayer(plugin, otherPlayer); otherPlayer.showPlayer(plugin, viewerPlayer); return; diff --git a/src/main/java/dev/lrxh/neptune/profile/listener/ProfileListener.java b/src/main/java/dev/lrxh/neptune/profile/listener/ProfileListener.java index 9b4b5bb..3acaa57 100644 --- a/src/main/java/dev/lrxh/neptune/profile/listener/ProfileListener.java +++ b/src/main/java/dev/lrxh/neptune/profile/listener/ProfileListener.java @@ -7,6 +7,7 @@ import dev.lrxh.neptune.profile.Profile; import dev.lrxh.neptune.profile.ProfileState; import dev.lrxh.neptune.profile.VisibilityLogic; +import dev.lrxh.neptune.providers.clickable.Replacement; import dev.lrxh.neptune.utils.PlayerUtil; import dev.lrxh.neptune.utils.ServerUtils; import org.bukkit.entity.Player; @@ -28,7 +29,7 @@ public void onJoin(PlayerJoinEvent event) { event.setJoinMessage(null); if (!MessagesLocale.JOIN_MESSAGE.getString().equals("NONE")) { - ServerUtils.broadcast(MessagesLocale.JOIN_MESSAGE.getString().replace("", player.getName())); + ServerUtils.broadcast(MessagesLocale.JOIN_MESSAGE, new Replacement("", player.getName())); } VisibilityLogic.handle(player.getUniqueId()); PlayerUtil.reset(player.getUniqueId()); @@ -50,7 +51,7 @@ public void onQuit(PlayerQuitEvent event) { event.setQuitMessage(null); if (!MessagesLocale.LEAVE_MESSAGE.getString().equals("NONE")) { - ServerUtils.broadcast(MessagesLocale.LEAVE_MESSAGE.getString().replace("", player.getName())); + ServerUtils.broadcast(MessagesLocale.LEAVE_MESSAGE, new Replacement("", player.getName())); } plugin.getProfileManager().removeProfile(player.getUniqueId()); @@ -66,7 +67,7 @@ public void onInventoryClose(InventoryCloseEvent event) { (Arrays.asList(player.getInventory().getContents())); MessagesLocale.KIT_EDITOR_STOP.send(player.getUniqueId()); - profile.setState(ProfileState.LOBBY); + profile.setState(ProfileState.IN_LOBBY); } } } diff --git a/src/main/java/dev/lrxh/neptune/providers/scoreboard/ScoreboardAdapter.java b/src/main/java/dev/lrxh/neptune/providers/scoreboard/ScoreboardAdapter.java index df13cc9..e2a0d2a 100644 --- a/src/main/java/dev/lrxh/neptune/providers/scoreboard/ScoreboardAdapter.java +++ b/src/main/java/dev/lrxh/neptune/providers/scoreboard/ScoreboardAdapter.java @@ -25,7 +25,7 @@ public List getLines(Player player) { Profile profile = plugin.getProfileManager().getByUUID(player.getUniqueId()); if (profile == null) return new ArrayList<>(); ProfileState state = profile.getState(); - if (state.equals(ProfileState.LOBBY) || state.equals(ProfileState.IN_KIT_EDITOR)) { + if (state.equals(ProfileState.IN_LOBBY) || state.equals(ProfileState.IN_KIT_EDITOR)) { return PlaceholderUtil.format(new ArrayList<>(ScoreboardLocale.LOBBY.getStringList()), player); } if (state.equals(ProfileState.IN_PARTY)) { diff --git a/src/main/java/dev/lrxh/neptune/queue/tasks/QueueCheckTask.java b/src/main/java/dev/lrxh/neptune/queue/tasks/QueueCheckTask.java index 2d6834d..59824b8 100644 --- a/src/main/java/dev/lrxh/neptune/queue/tasks/QueueCheckTask.java +++ b/src/main/java/dev/lrxh/neptune/queue/tasks/QueueCheckTask.java @@ -50,10 +50,10 @@ public void run() { //If no arenas were found if (arena == null) { plugin.getQueueManager().remove(uuid1); - plugin.getProfileManager().getByUUID(uuid1).setState(ProfileState.LOBBY); + plugin.getProfileManager().getByUUID(uuid1).setState(ProfileState.IN_LOBBY); plugin.getQueueManager().remove(uuid2); - plugin.getProfileManager().getByUUID(uuid2).setState(ProfileState.LOBBY); + plugin.getProfileManager().getByUUID(uuid2).setState(ProfileState.IN_LOBBY); PlayerUtil.sendMessage(uuid1, CC.error("No arena was found!")); PlayerUtil.sendMessage(uuid2, CC.error("No arena was found!")); @@ -68,10 +68,10 @@ public void run() { ((StandAloneArena) arena).getMin() == null))) { plugin.getQueueManager().remove(uuid1); - plugin.getProfileManager().getByUUID(uuid1).setState(ProfileState.LOBBY); + plugin.getProfileManager().getByUUID(uuid1).setState(ProfileState.IN_LOBBY); plugin.getQueueManager().remove(uuid2); - plugin.getProfileManager().getByUUID(uuid2).setState(ProfileState.LOBBY); + plugin.getProfileManager().getByUUID(uuid2).setState(ProfileState.IN_LOBBY); PlayerUtil.sendMessage(uuid1, CC.error("Arena wasn't setup up properly! Please contact an admin if you see this.")); PlayerUtil.sendMessage(uuid2, CC.error("Arena wasn't setup up properly! Please contact an admin if you see this.")); diff --git a/src/main/java/dev/lrxh/neptune/utils/PlayerUtil.java b/src/main/java/dev/lrxh/neptune/utils/PlayerUtil.java index 892c82b..fdf1221 100644 --- a/src/main/java/dev/lrxh/neptune/utils/PlayerUtil.java +++ b/src/main/java/dev/lrxh/neptune/utils/PlayerUtil.java @@ -14,6 +14,7 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; +import java.util.List; import java.util.UUID; @UtilityClass @@ -82,7 +83,11 @@ public ItemStack getPlayerHead(UUID playerUUID) { return utils.getPlayerHead(playerUUID); } - public void sendMessage(UUID playerUUID, Object... content) { + public void sendMessage(UUID playerUUID, List content) { + utils.sendMessage(playerUUID, content); + } + + public void sendMessage(UUID playerUUID, Object content) { utils.sendMessage(playerUUID, content); } diff --git a/src/main/java/dev/lrxh/neptune/utils/ServerUtils.java b/src/main/java/dev/lrxh/neptune/utils/ServerUtils.java index b55125f..e902ba3 100644 --- a/src/main/java/dev/lrxh/neptune/utils/ServerUtils.java +++ b/src/main/java/dev/lrxh/neptune/utils/ServerUtils.java @@ -1,6 +1,8 @@ package dev.lrxh.neptune.utils; import dev.lrxh.neptune.Neptune; +import dev.lrxh.neptune.configs.impl.MessagesLocale; +import dev.lrxh.neptune.providers.clickable.Replacement; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -13,12 +15,12 @@ public void sendMessage(String message) { } public void error(String message) { - Bukkit.getServer().getConsoleSender().sendMessage(CC.error(message + "!")); + Bukkit.getServer().getConsoleSender().sendMessage(CC.error(message)); } - public void broadcast(String message) { + public void broadcast(MessagesLocale message, Replacement... replacements) { for (Player player : Neptune.get().getServer().getOnlinePlayers()) { - PlayerUtil.sendMessage(player.getUniqueId(), message); + message.send(player.getUniqueId(), replacements); } } } \ No newline at end of file diff --git a/src/main/java/dev/lrxh/neptune/utils/TtlHashMap.java b/src/main/java/dev/lrxh/neptune/utils/TtlHashMap.java index 655af8a..92bae4f 100644 --- a/src/main/java/dev/lrxh/neptune/utils/TtlHashMap.java +++ b/src/main/java/dev/lrxh/neptune/utils/TtlHashMap.java @@ -1,5 +1,7 @@ package dev.lrxh.neptune.utils; +import dev.lrxh.neptune.Neptune; +import dev.lrxh.neptune.providers.tasks.NeptuneRunnable; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -10,9 +12,7 @@ public class TtlHashMap { private final Map map = new ConcurrentHashMap<>(); - private final Map> futures = new ConcurrentHashMap<>(); private final Map actions = new ConcurrentHashMap<>(); - private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); private final long leaveTime; public TtlHashMap(long delay) { @@ -24,11 +24,6 @@ public int size() { } public void put(K key, V value) { - ScheduledFuture existingFuture = futures.remove(key); - if (existingFuture != null) { - existingFuture.cancel(false); - } - map.put(key, value); scheduleRemoval(key); } @@ -51,13 +46,7 @@ public void onExpire(K element) { } public void remove(K key) { - V value = map.remove(key); - if (value != null) { - ScheduledFuture future = futures.remove(key); - if (future != null) { - future.cancel(false); - } - } + map.remove(key); } public boolean contains(K key) { @@ -65,11 +54,12 @@ public boolean contains(K key) { } private void scheduleRemoval(K key) { - ScheduledFuture future = scheduler.schedule(() -> { - map.remove(key); - futures.remove(key); - onExpire(key); - }, leaveTime, TimeUnit.SECONDS); - futures.put(key, future); + Neptune.get().getTaskScheduler().startTaskLater(new NeptuneRunnable() { + @Override + public void run() { + map.remove(key); + onExpire(key); + } + }, leaveTime * 20L); } }