From b1b828257d6bd468ebcd480ccc1df168b91b4c53 Mon Sep 17 00:00:00 2001 From: Trixkz Date: Fri, 20 Sep 2024 02:14:31 -0400 Subject: [PATCH] Initial commit. --- pom.xml | 131 ++++ src/main/java/aether/Aether.java | 179 +++++ src/main/java/aether/AetherOptions.java | 18 + .../java/aether/event/BoardCreateEvent.java | 27 + src/main/java/aether/scoreboard/Board.java | 128 +++ .../java/aether/scoreboard/BoardAdapter.java | 17 + .../java/aether/scoreboard/BoardEntry.java | 90 +++ .../scoreboard/cooldown/BoardCooldown.java | 42 + .../scoreboard/cooldown/BoardFormat.java | 5 + .../trixkz/lifestealcore/LifeStealCore.java | 196 +++++ .../advancedmenusystem/Button.java | 52 ++ .../advancedmenusystem/Menu.java | 151 ++++ .../buttons/BackButton.java | 32 + .../buttons/DisplayButton.java | 31 + .../pagination/JumpToPageButton.java | 44 ++ .../pagination/PageButton.java | 54 ++ .../pagination/PaginatedMenu.java | 117 +++ .../pagination/ViewAllPagesMenu.java | 56 ++ .../advancedmenusystem/shop/GoBackButton.java | 25 + .../advancedmenusystem/shop/ShopButton.java | 74 ++ .../advancedmenusystem/shop/ShopBuyMenu.java | 55 ++ .../shop/ShopItemButton.java | 232 ++++++ .../advancedmenusystem/shop/ShopItemMenu.java | 39 + .../advancedmenusystem/shop/ShopItemSet.java | 19 + .../advancedmenusystem/shop/ShopItemType.java | 15 + .../advancedmenusystem/shop/ShopMenu.java | 39 + .../advancedmenusystem/shop/ShopSellMenu.java | 55 ++ .../advancedmenusystem/shop/ShopType.java | 144 ++++ .../shop/ShopTypeButton.java | 92 +++ .../shop/blocks/BlocksMenu.java | 105 +++ .../colorfulblocks/ColorfulBlocksMenu.java | 109 +++ .../shop/combat/CombatMenu.java | 81 ++ .../shop/customitems/CustomItemsMenu.java | 62 ++ .../shop/dyesandplants/DyesAndPlantsMenu.java | 93 +++ .../shop/farming/FarmingMenu.java | 84 ++ .../shop/food/FoodMenu.java | 78 ++ .../shop/mobdrops/MobDropsMenu.java | 81 ++ .../shop/ores/OresMenu.java | 76 ++ .../shop/potions/PotionsMenu.java | 62 ++ .../shop/redstone/RedstoneMenu.java | 80 ++ .../shop/spawners/SpawnersMenu.java | 75 ++ .../lifestealcore/chatcolor/ColorSet.java | 17 + .../chatcolor/GradientColor.java | 16 + .../lifestealcore/commands/BaseCommand.java | 53 ++ .../lifestealcore/commands/CommandInfo.java | 16 + .../lifestealcore/commands/EnvoyCommand.java | 44 ++ .../commands/LootboxCommand.java | 46 ++ .../commands/SetHeartsCommand.java | 41 + .../lifestealcore/commands/ShopCommand.java | 25 + .../lifestealcore/commands/SpawnCommand.java | 21 + .../commands/clan/ClanCommand.java | 141 ++++ .../commands/coins/CoinsCommand.java | 151 ++++ .../commands/koth/CreateCommand.java | 37 + .../commands/koth/DisableCommand.java | 48 ++ .../commands/koth/EnableCommand.java | 50 ++ .../commands/koth/KOTHCommand.java | 68 ++ .../commands/koth/PlayerCommand.java | 48 ++ .../commands/koth/RemoveCommand.java | 36 + .../commands/koth/SetDistanceCommand.java | 48 ++ .../commands/koth/SetLocationCommand.java | 43 ++ .../commands/koth/SetTimeCommand.java | 48 ++ .../commands/koth/TeleportCommand.java | 41 + .../commands/setspawn/MaxCommand.java | 36 + .../commands/setspawn/MinCommand.java | 36 + .../commands/setspawn/SetSpawnCommand.java | 84 ++ .../commands/setspawn/SpawnCommand.java | 36 + .../commands/tokens/TokensCommand.java | 155 ++++ .../events/KOTHCapLostEvent.java | 29 + .../events/KOTHCapTickEvent.java | 29 + .../lifestealcore/events/KOTHCappedEvent.java | 35 + .../events/KOTHDisabledEvent.java | 29 + .../events/KOTHEnabledEvent.java | 29 + .../listeners/BlockBreakListener.java | 25 + .../listeners/BlockExplodeListener.java | 23 + .../listeners/BlockPlaceListener.java | 25 + .../listeners/BlockSpreadListener.java | 27 + .../listeners/BucketListener.java | 39 + .../listeners/ButtonListener.java | 88 +++ .../listeners/ClanListeners.java | 116 +++ .../listeners/EntityChangeBlockListener.java | 25 + .../EntityDamageByEntityListener.java | 53 ++ .../listeners/EntityDeathListener.java | 27 + .../listeners/EventListeners.java | 162 ++++ .../lifestealcore/listeners/KOTHListener.java | 23 + .../lifestealcore/listeners/MenuListener.java | 26 + .../listeners/PlayerDataListener.java | 74 ++ .../listeners/PlayerDeathListener.java | 99 +++ .../listeners/RandomListeners.java | 97 +++ .../lifestealcore/managers/ChunkManager.java | 56 ++ .../lifestealcore/managers/CombatManager.java | 104 +++ .../managers/CommandManager.java | 31 + .../managers/CooldownManager.java | 74 ++ .../managers/LootboxManager.java | 93 +++ .../lifestealcore/managers/MongoManager.java | 84 ++ .../managers/PlayerDataManager.java | 100 +++ .../lifestealcore/managers/SpawnManager.java | 64 ++ .../managers/chatgames/ChatGame.java | 18 + .../managers/chatgames/ChatGameManager.java | 37 + .../managers/chatgames/chatmath/ChatMath.java | 4 + .../chatgames/chatquestion/ChatQuestion.java | 153 ++++ .../lifestealcore/managers/clans/Clan.java | 41 + .../managers/clans/ClanManager.java | 564 ++++++++++++++ .../lifestealcore/managers/envoys/Envoy.java | 15 + .../managers/envoys/EnvoyDrop.java | 72 ++ .../managers/envoys/EnvoyDropGlider.java | 71 ++ .../managers/envoys/EnvoyManager.java | 112 +++ .../managers/envoys/EnvoyReward.java | 30 + .../managers/event/EventScheduledTime.java | 95 +++ .../killstreaks/ChampionRankKillstreak.java | 22 + .../killstreaks/EmperorRankKillstreak.java | 22 + .../killstreaks/GodRankKillstreak.java | 22 + .../killstreaks/GoldenApplesKillstreak.java | 30 + .../GrandMasterRankKillstreak.java | 22 + .../managers/killstreaks/Killstreak.java | 20 + .../killstreaks/KillstreakManager.java | 37 + .../killstreaks/KillstreaksCallable.java | 9 + .../killstreaks/MasterRankKillstreak.java | 22 + .../killstreaks/RepairKillstreak.java | 29 + .../killstreaks/ResistanceKillstreak.java | 25 + .../lifestealcore/managers/koth/KOTH.java | 232 ++++++ .../managers/koth/KOTHManager.java | 250 ++++++ .../managers/leaderboards/Leaderboard.java | 130 ++++ .../leaderboards/LeaderboardManager.java | 23 + .../managers/pvpclass/ArcherClass.java | 222 ++++++ .../managers/pvpclass/BardClass.java | 318 ++++++++ .../managers/pvpclass/BardEffect.java | 26 + .../managers/pvpclass/PvPClass.java | 102 +++ .../managers/pvpclass/PvPClassManager.java | 183 +++++ .../managers/pvpclass/SavedPotionEffect.java | 18 + .../managers/pvpclass/TankClass.java | 146 ++++ .../normalmenusystem/ItemStackButton.java | 28 + .../lifestealcore/normalmenusystem/Menu.java | 63 ++ .../normalmenusystem/PaginatedMenu.java | 61 ++ .../normalmenusystem/PlayerMenuUtil.java | 20 + .../lifestealcore/playerdata/PlayerData.java | 46 ++ .../playerdata/PlayerSettings.java | 9 + .../lifestealcore/playerdata/PlayerState.java | 7 + .../currentgame/PlayerCurrentGameData.java | 10 + .../runnables/ClearLagRunnable.java | 51 ++ .../runnables/CombatTagRunnable.java | 63 ++ .../runnables/EnvoyRunnable.java | 55 ++ .../runnables/LootboxRunnable.java | 274 +++++++ .../runnables/SpawnRunnable.java | 88 +++ .../scoreboard/ScoreboardProvider.java | 101 +++ .../lifestealcore/utils/AsyncScheduler.java | 34 + .../me/trixkz/lifestealcore/utils/Cache.java | 29 + .../trixkz/lifestealcore/utils/Clickable.java | 51 ++ .../lifestealcore/utils/ColorUtils.java | 175 +++++ .../trixkz/lifestealcore/utils/Constants.java | 174 +++++ .../me/trixkz/lifestealcore/utils/Cuboid.java | 729 ++++++++++++++++++ .../lifestealcore/utils/CustomLocation.java | 124 +++ .../lifestealcore/utils/ItemBuilder.java | 185 +++++ .../me/trixkz/lifestealcore/utils/Pair.java | 17 + .../trixkz/lifestealcore/utils/TimeUtils.java | 128 +++ .../lifestealcore/utils/TimerRunnable.java | 35 + .../lifestealcore/utils/TtlHandler.java | 8 + .../lifestealcore/utils/TtlHashMap.java | 128 +++ .../me/trixkz/lifestealcore/utils/Utils.java | 216 ++++++ .../utils/config/ConfigCursor.java | 88 +++ .../utils/config/FileConfig.java | 50 ++ .../utils/config/file/Config.java | 39 + .../utils/config/file/ConfigFile.java | 103 +++ src/main/resources/config.yml | 97 +++ src/main/resources/envoys.yml | 14 + src/main/resources/koths.yml | 0 src/main/resources/lootbox.yml | 211 +++++ src/main/resources/messages.yml | 96 +++ src/main/resources/plugin.yml | 17 + 168 files changed, 12962 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/aether/Aether.java create mode 100644 src/main/java/aether/AetherOptions.java create mode 100644 src/main/java/aether/event/BoardCreateEvent.java create mode 100644 src/main/java/aether/scoreboard/Board.java create mode 100644 src/main/java/aether/scoreboard/BoardAdapter.java create mode 100644 src/main/java/aether/scoreboard/BoardEntry.java create mode 100644 src/main/java/aether/scoreboard/cooldown/BoardCooldown.java create mode 100644 src/main/java/aether/scoreboard/cooldown/BoardFormat.java create mode 100644 src/main/java/me/trixkz/lifestealcore/LifeStealCore.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/Button.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/Menu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/buttons/BackButton.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/buttons/DisplayButton.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/JumpToPageButton.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/PageButton.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/PaginatedMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/ViewAllPagesMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/GoBackButton.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopButton.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopBuyMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemButton.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemSet.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemType.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopSellMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopType.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopTypeButton.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/blocks/BlocksMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/colorfulblocks/ColorfulBlocksMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/combat/CombatMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/customitems/CustomItemsMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/dyesandplants/DyesAndPlantsMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/farming/FarmingMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/food/FoodMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/mobdrops/MobDropsMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ores/OresMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/potions/PotionsMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/redstone/RedstoneMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/spawners/SpawnersMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/chatcolor/ColorSet.java create mode 100644 src/main/java/me/trixkz/lifestealcore/chatcolor/GradientColor.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/BaseCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/CommandInfo.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/EnvoyCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/LootboxCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/SetHeartsCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/ShopCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/SpawnCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/clan/ClanCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/coins/CoinsCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/koth/CreateCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/koth/DisableCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/koth/EnableCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/koth/KOTHCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/koth/PlayerCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/koth/RemoveCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/koth/SetDistanceCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/koth/SetLocationCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/koth/SetTimeCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/koth/TeleportCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/setspawn/MaxCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/setspawn/MinCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/setspawn/SetSpawnCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/setspawn/SpawnCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/commands/tokens/TokensCommand.java create mode 100644 src/main/java/me/trixkz/lifestealcore/events/KOTHCapLostEvent.java create mode 100644 src/main/java/me/trixkz/lifestealcore/events/KOTHCapTickEvent.java create mode 100644 src/main/java/me/trixkz/lifestealcore/events/KOTHCappedEvent.java create mode 100644 src/main/java/me/trixkz/lifestealcore/events/KOTHDisabledEvent.java create mode 100644 src/main/java/me/trixkz/lifestealcore/events/KOTHEnabledEvent.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/BlockBreakListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/BlockExplodeListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/BlockPlaceListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/BlockSpreadListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/BucketListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/ButtonListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/ClanListeners.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/EntityChangeBlockListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/EntityDamageByEntityListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/EntityDeathListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/EventListeners.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/KOTHListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/MenuListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/PlayerDataListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/PlayerDeathListener.java create mode 100644 src/main/java/me/trixkz/lifestealcore/listeners/RandomListeners.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/ChunkManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/CombatManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/CommandManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/CooldownManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/LootboxManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/MongoManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/PlayerDataManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/SpawnManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/chatgames/ChatGame.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/chatgames/ChatGameManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/chatgames/chatmath/ChatMath.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/chatgames/chatquestion/ChatQuestion.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/clans/Clan.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/clans/ClanManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/envoys/Envoy.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyDrop.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyDropGlider.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyReward.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/event/EventScheduledTime.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/ChampionRankKillstreak.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/EmperorRankKillstreak.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GodRankKillstreak.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GoldenApplesKillstreak.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GrandMasterRankKillstreak.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/Killstreak.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/KillstreakManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/KillstreaksCallable.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/MasterRankKillstreak.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/RepairKillstreak.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/killstreaks/ResistanceKillstreak.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/koth/KOTH.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/koth/KOTHManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/leaderboards/Leaderboard.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/leaderboards/LeaderboardManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/pvpclass/ArcherClass.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/pvpclass/BardClass.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/pvpclass/BardEffect.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/pvpclass/PvPClass.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/pvpclass/PvPClassManager.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/pvpclass/SavedPotionEffect.java create mode 100644 src/main/java/me/trixkz/lifestealcore/managers/pvpclass/TankClass.java create mode 100644 src/main/java/me/trixkz/lifestealcore/normalmenusystem/ItemStackButton.java create mode 100644 src/main/java/me/trixkz/lifestealcore/normalmenusystem/Menu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/normalmenusystem/PaginatedMenu.java create mode 100644 src/main/java/me/trixkz/lifestealcore/normalmenusystem/PlayerMenuUtil.java create mode 100644 src/main/java/me/trixkz/lifestealcore/playerdata/PlayerData.java create mode 100644 src/main/java/me/trixkz/lifestealcore/playerdata/PlayerSettings.java create mode 100644 src/main/java/me/trixkz/lifestealcore/playerdata/PlayerState.java create mode 100644 src/main/java/me/trixkz/lifestealcore/playerdata/currentgame/PlayerCurrentGameData.java create mode 100644 src/main/java/me/trixkz/lifestealcore/runnables/ClearLagRunnable.java create mode 100644 src/main/java/me/trixkz/lifestealcore/runnables/CombatTagRunnable.java create mode 100644 src/main/java/me/trixkz/lifestealcore/runnables/EnvoyRunnable.java create mode 100644 src/main/java/me/trixkz/lifestealcore/runnables/LootboxRunnable.java create mode 100644 src/main/java/me/trixkz/lifestealcore/runnables/SpawnRunnable.java create mode 100644 src/main/java/me/trixkz/lifestealcore/scoreboard/ScoreboardProvider.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/AsyncScheduler.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/Cache.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/Clickable.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/ColorUtils.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/Constants.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/Cuboid.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/CustomLocation.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/ItemBuilder.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/Pair.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/TimeUtils.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/TimerRunnable.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/TtlHandler.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/TtlHashMap.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/Utils.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/config/ConfigCursor.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/config/FileConfig.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/config/file/Config.java create mode 100644 src/main/java/me/trixkz/lifestealcore/utils/config/file/ConfigFile.java create mode 100644 src/main/resources/config.yml create mode 100644 src/main/resources/envoys.yml create mode 100644 src/main/resources/koths.yml create mode 100644 src/main/resources/lootbox.yml create mode 100644 src/main/resources/messages.yml create mode 100644 src/main/resources/plugin.yml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9c16cd9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,131 @@ + + + 4.0.0 + + com.loganmagnan + LifeStealCore + 1.0 + + + 17 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + codemc-snapshots + https://repo.codemc.io/repository/maven-snapshots/ + + + CodeMC + https://repo.codemc.org/repository/maven-public/ + + + codemc-repo + https://repo.codemc.io/repository/maven-public/ + + + jitpack.io + https://jitpack.io + + + + + + io.papermc.paper + paper-api + 1.20-R0.1-SNAPSHOT + provided + + + org.projectlombok + lombok + 1.18.20 + provided + + + net.wesjd + anvilgui + 1.5.3-SNAPSHOT + + + io.github.bananapuncher714 + nbteditor + 7.18.1 + + + org.mongodb + mongo-java-driver + 3.12.10 + compile + + + org.apache.commons + commons-compress + 1.21 + + + org.apache.commons + commons-lang3 + 3.0 + + + net.luckperms + api + 5.3 + provided + + + com.github.decentsoftware-eu + decentholograms + 2.7.2 + provided + + + \ No newline at end of file diff --git a/src/main/java/aether/Aether.java b/src/main/java/aether/Aether.java new file mode 100644 index 0000000..2b1d28a --- /dev/null +++ b/src/main/java/aether/Aether.java @@ -0,0 +1,179 @@ +package aether; + +import aether.event.BoardCreateEvent; +import aether.scoreboard.Board; +import aether.scoreboard.BoardAdapter; +import aether.scoreboard.BoardEntry; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Score; +import org.bukkit.scoreboard.Scoreboard; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import static aether.AetherOptions.defaultOptions; + +public class Aether implements Listener { + + @Getter BoardAdapter adapter; + @Getter private JavaPlugin plugin; + @Getter private AetherOptions options; + + public Aether(JavaPlugin plugin, BoardAdapter adapter, AetherOptions options) { + this.options = options; + this.plugin = plugin; + + Bukkit.getPluginManager().registerEvents(this, plugin); + + setAdapter(adapter); + run(); + } + + public Aether(JavaPlugin plugin, BoardAdapter adapter) { + this(plugin, adapter, defaultOptions()); + } + + public Aether(JavaPlugin plugin) { + this(plugin, null, defaultOptions()); + } + + private void run() { + new BukkitRunnable() { + @Override + public void run() { + if (adapter == null) return; + for (Player player : Bukkit.getOnlinePlayers()) { + Board board = Board.getByPlayer(player); + if (board != null) { + List scores = adapter.getScoreboard(player, board, board.getCooldowns()); + List translatedScores = new ArrayList<>(); + if (scores == null) { + if (!board.getEntries().isEmpty()) { + for (BoardEntry boardEntry : board.getEntries()) { + boardEntry.remove(); + } + board.getEntries().clear(); + } + continue; + } + + for (String line : scores) { + translatedScores.add(ChatColor.translateAlternateColorCodes('&', line)); + } + + if (!options.scoreDirectionDown()) { + Collections.reverse(scores); + } + + Scoreboard scoreboard = board.getScoreboard(); + Objective objective = board.getObjective(); + + if (!(objective.getDisplayName().equals(adapter.getTitle(player)))) { + objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', adapter.getTitle(player))); + } + + outer: + for (int i = 0; i < scores.size(); i++) { + String text = scores.get(i); + int position; + if (options.scoreDirectionDown()) { + position = 15 - i; + } else { + position = i + 1; + } + + Iterator iterator = new ArrayList<>(board.getEntries()).iterator(); + while (iterator.hasNext()) { + BoardEntry boardEntry = iterator.next(); + Score score = objective.getScore(boardEntry.getKey()); + + if (score != null && boardEntry.getText().equals(ChatColor.translateAlternateColorCodes('&', text))) { + if (score.getScore() == position) { + continue outer; + } + } + } + + int positionToSearch = options.scoreDirectionDown() ? 15 - position : position - 1; + + iterator = board.getEntries().iterator(); + while (iterator.hasNext()) { + BoardEntry boardEntry = iterator.next(); + int entryPosition = scoreboard.getObjective(DisplaySlot.SIDEBAR).getScore(boardEntry.getKey()).getScore(); + + if (!options.scoreDirectionDown()) { + if (entryPosition > scores.size()) { + iterator.remove(); + boardEntry.remove(); + } + } + + } + + BoardEntry entry = board.getByPosition(positionToSearch); + + if (entry == null) { + new BoardEntry(board, text).send(position); + } else { + entry.setText(text).setup().send(position); + } + + if (board.getEntries().size() > scores.size()) { + iterator = board.getEntries().iterator(); + while (iterator.hasNext()) { + BoardEntry boardEntry = iterator.next(); + if ((!translatedScores.contains(boardEntry.getText())) || Collections.frequency(board.getBoardEntriesFormatted(), boardEntry.getText()) > 1) { + iterator.remove(); + boardEntry.remove(); + } + } + } + } + adapter.onScoreboardCreate(player, scoreboard); + player.setScoreboard(scoreboard); + } + } + } + }.runTaskTimerAsynchronously(plugin, 20L, 2L); + } + + public void setAdapter(BoardAdapter adapter) { + this.adapter = adapter; + for (Player player : Bukkit.getOnlinePlayers()) { + Board board = Board.getByPlayer(player); + if (board != null) { + Board.getBoards().remove(board); + } + Bukkit.getPluginManager().callEvent(new BoardCreateEvent(new Board(player, this, options), player)); + } + } + + @EventHandler + public void onPlayerJoinEvent(PlayerJoinEvent event) { + if (Board.getByPlayer(event.getPlayer()) == null) { + Bukkit.getPluginManager().callEvent(new BoardCreateEvent(new Board(event.getPlayer(), this, options), event.getPlayer())); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerQuitEvent(PlayerQuitEvent event) { + Board board = Board.getByPlayer(event.getPlayer()); + if (board != null) { + Board.getBoards().remove(board); + } + } +} diff --git a/src/main/java/aether/AetherOptions.java b/src/main/java/aether/AetherOptions.java new file mode 100644 index 0000000..526c513 --- /dev/null +++ b/src/main/java/aether/AetherOptions.java @@ -0,0 +1,18 @@ +package aether; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +@Getter +@Setter +@Accessors(chain = true, fluent = true) +public class AetherOptions { + + private boolean hook; + private boolean scoreDirectionDown; + + static AetherOptions defaultOptions() { + return new AetherOptions().hook(false).scoreDirectionDown(false); + } +} diff --git a/src/main/java/aether/event/BoardCreateEvent.java b/src/main/java/aether/event/BoardCreateEvent.java new file mode 100644 index 0000000..0cc018e --- /dev/null +++ b/src/main/java/aether/event/BoardCreateEvent.java @@ -0,0 +1,27 @@ +package aether.event; + +import aether.scoreboard.Board; +import lombok.Getter; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class BoardCreateEvent extends Event { + + private static final HandlerList HANDLERS = new HandlerList(); + @Getter private final Board board; + @Getter private final Player player; + + public BoardCreateEvent(Board board, Player player) { + this.board = board; + this.player = player; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } + + public HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/aether/scoreboard/Board.java b/src/main/java/aether/scoreboard/Board.java new file mode 100644 index 0000000..1a0130a --- /dev/null +++ b/src/main/java/aether/scoreboard/Board.java @@ -0,0 +1,128 @@ +package aether.scoreboard; + +import aether.Aether; +import aether.AetherOptions; +import aether.scoreboard.cooldown.BoardCooldown; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Board { + + @Getter private static Set boards = new HashSet<>(); + + private final Aether aether; + private final AetherOptions options; + + @Getter private Scoreboard scoreboard; + @Getter private Player player; + @Getter private Objective objective; + @Getter private Set keys; + @Getter private List entries; + + private Set cooldowns; + + public Board(Player player, Aether aether, AetherOptions options) { + this.player = player; + this.aether = aether; + this.options = options; + + this.keys = new HashSet<>(); + this.entries = new ArrayList<>(); + + this.cooldowns = new HashSet<>(); + + setup(); + } + + public static Board getByPlayer(Player player) { + for (Board board : boards) { + if (board.getPlayer().getName().equals(player.getName())) { + return board; + } + } + + return null; + } + + private void setup() { + if (options.hook() && !player.getScoreboard().equals(Bukkit.getScoreboardManager().getMainScoreboard())) { + scoreboard = player.getScoreboard(); + } else { + scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); + } + + objective = scoreboard.registerNewObjective("glaedr_is_shit", "dummy"); + objective.setDisplaySlot(DisplaySlot.SIDEBAR); + + if (aether.getAdapter() != null) { + objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', aether.getAdapter().getTitle(player))); + } else { + objective.setDisplayName("Default Title"); + } + + boards.add(this); + } + + public String getNewKey(BoardEntry entry) { + for (ChatColor color : ChatColor.values()) { + String colorText = color + "" + ChatColor.WHITE; + if (entry.getText().length() > 16) { + String sub = entry.getText().substring(0, 16); + colorText = colorText + ChatColor.getLastColors(sub); + } + + if (!keys.contains(colorText)) { + keys.add(colorText); + return colorText; + } + } + + throw new IndexOutOfBoundsException("No more keys available!"); + } + + public List getBoardEntriesFormatted() { + List toReturn = new ArrayList<>(); + for (BoardEntry entry : new ArrayList<>(entries)) { + toReturn.add(entry.getText()); + } + + return toReturn; + } + + public BoardEntry getByPosition(int position) { + int i = 0; + + for (BoardEntry board : entries) { + if (i == position) { + return board; + } + i++; + } + + return null; + } + + public BoardCooldown getCooldown(String id) { + for (BoardCooldown cooldown : getCooldowns()) { + if (cooldown.getId().equals(id)) { + return cooldown; + } + } + + return null; + } + + public Set getCooldowns() { + cooldowns.removeIf(cooldown -> System.currentTimeMillis() >= cooldown.getEnd()); + return cooldowns; + } +} diff --git a/src/main/java/aether/scoreboard/BoardAdapter.java b/src/main/java/aether/scoreboard/BoardAdapter.java new file mode 100644 index 0000000..2b1b1b8 --- /dev/null +++ b/src/main/java/aether/scoreboard/BoardAdapter.java @@ -0,0 +1,17 @@ +package aether.scoreboard; + +import aether.scoreboard.cooldown.BoardCooldown; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Scoreboard; + +import java.util.List; +import java.util.Set; + +public interface BoardAdapter { + + String getTitle(Player player); + + List getScoreboard(Player player, Board board, Set cooldowns); + + void onScoreboardCreate(Player player, Scoreboard board); +} diff --git a/src/main/java/aether/scoreboard/BoardEntry.java b/src/main/java/aether/scoreboard/BoardEntry.java new file mode 100644 index 0000000..903832e --- /dev/null +++ b/src/main/java/aether/scoreboard/BoardEntry.java @@ -0,0 +1,90 @@ +package aether.scoreboard; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import org.bukkit.ChatColor; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Score; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; + +@Accessors(chain = true) +public class BoardEntry { + + @Getter private Board board; + @Getter @Setter private String text; + @Getter private String originalText; + @Getter private String key; + @Getter private Team team; + + public BoardEntry(Board board, String text) { + this.board = board; + this.text = text; + this.originalText = text; + this.key = board.getNewKey(this); + + setup(); + } + + public BoardEntry setup() { + Scoreboard scoreboard = board.getScoreboard(); + + text = ChatColor.translateAlternateColorCodes('&', text); + + String teamName = key; + + if (teamName.length() > 16) { + teamName = teamName.substring(0, 16); + } + + if (scoreboard.getTeam(teamName) != null) { + team = scoreboard.getTeam(teamName); + } else { + team = scoreboard.registerNewTeam(teamName); + } + + if (!(team.getEntries().contains(key))) { + team.addEntry(key); + } + + if (!(board.getEntries().contains(this))) { + board.getEntries().add(this); + } + + return this; + } + + public BoardEntry send(int position) { + Objective objective = board.getObjective(); + + if (text.length() > 16) { + boolean fix = text.toCharArray()[15] == ChatColor.COLOR_CHAR; + + String prefix = fix ? text.substring(0, 15) : text.substring(0, 16); + String suffix = fix ? text.substring(15) : ChatColor.getLastColors(prefix) + text.substring(16); + + team.setPrefix(prefix); + + if (suffix.length() > 16) { + team.setSuffix(suffix.substring(0, 16)); + } else { + team.setSuffix(suffix); + } + } else { + team.setPrefix(text); + team.setSuffix(""); + } + + Score score = objective.getScore(key); + score.setScore(position); + + return this; + } + + public void remove() { + board.getKeys().remove(key); + board.getScoreboard().resetScores(key); + } + +} diff --git a/src/main/java/aether/scoreboard/cooldown/BoardCooldown.java b/src/main/java/aether/scoreboard/cooldown/BoardCooldown.java new file mode 100644 index 0000000..cfb9482 --- /dev/null +++ b/src/main/java/aether/scoreboard/cooldown/BoardCooldown.java @@ -0,0 +1,42 @@ +package aether.scoreboard.cooldown; + +import aether.scoreboard.Board; +import lombok.Getter; +import org.apache.commons.lang3.time.DurationFormatUtils; + +import java.text.DecimalFormat; + +public class BoardCooldown { + + private static final DecimalFormat SECONDS_FORMATTER = new DecimalFormat("#0.0"); + + @Getter private final Board board; + @Getter private final String id; + @Getter private final double duration; + @Getter private final long end; + + public BoardCooldown(Board board, String id, double duration) { + this.board = board; + this.id = id; + this.duration = duration; + this.end = (long) (System.currentTimeMillis() + (duration * 1000)); + + board.getCooldowns().add(this); + } + + public String getFormattedString(BoardFormat format) { + if (format == null) { + throw new NullPointerException(); + } + if (format == BoardFormat.SECONDS) { + return SECONDS_FORMATTER.format(((end - System.currentTimeMillis()) / 1000.0f)); + } else { + return DurationFormatUtils.formatDuration(end - System.currentTimeMillis(), "mm:ss"); + } + } + + public void cancel() { + board.getCooldowns().remove(this); + } + +} \ No newline at end of file diff --git a/src/main/java/aether/scoreboard/cooldown/BoardFormat.java b/src/main/java/aether/scoreboard/cooldown/BoardFormat.java new file mode 100644 index 0000000..24f34cf --- /dev/null +++ b/src/main/java/aether/scoreboard/cooldown/BoardFormat.java @@ -0,0 +1,5 @@ +package aether.scoreboard.cooldown; + +public enum BoardFormat { + SECONDS, MINUTES, HOURS +} diff --git a/src/main/java/me/trixkz/lifestealcore/LifeStealCore.java b/src/main/java/me/trixkz/lifestealcore/LifeStealCore.java new file mode 100644 index 0000000..5c642a4 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/LifeStealCore.java @@ -0,0 +1,196 @@ +package me.trixkz.lifestealcore; + +import aether.Aether; +import lombok.Getter; +import me.trixkz.lifestealcore.listeners.*; +import me.trixkz.lifestealcore.managers.*; +import me.trixkz.lifestealcore.managers.chatgames.ChatGameManager; +import me.trixkz.lifestealcore.managers.clans.ClanManager; +import me.trixkz.lifestealcore.managers.envoys.EnvoyManager; +import me.trixkz.lifestealcore.managers.killstreaks.KillstreakManager; +import me.trixkz.lifestealcore.managers.koth.KOTHManager; +import me.trixkz.lifestealcore.managers.leaderboards.LeaderboardManager; +import me.trixkz.lifestealcore.managers.pvpclass.PvPClassManager; +import me.trixkz.lifestealcore.normalmenusystem.PlayerMenuUtil; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.runnables.*; +import me.trixkz.lifestealcore.scoreboard.ScoreboardProvider; +import me.trixkz.lifestealcore.utils.ColorUtils; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import me.trixkz.lifestealcore.utils.config.FileConfig; +import me.trixkz.lifestealcore.utils.config.file.Config; +import net.luckperms.api.LuckPerms; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.*; + +@Getter +public class LifeStealCore extends JavaPlugin { + + @Getter public static LifeStealCore instance; + + private Config settingsConfig; + private FileConfig messagesConfig; + private FileConfig kothsConfig; + private FileConfig lootboxConfig; + private FileConfig envoysConfig; + + private CommandManager commandManager; + private ClanManager clanManager; + private ChunkManager chunkManager; + private PvPClassManager pvpClassManager; + private KOTHManager kothManager; + private SpawnManager spawnManager; + private MongoManager mongoManager; + private PlayerDataManager playerDataManager; + private LootboxManager lootboxManager; + private LeaderboardManager leaderboardManager; + private ChatGameManager chatGameManager; + private CombatManager combatManager; + private CooldownManager cooldownManager; + private KillstreakManager killstreakManager; + private EnvoyManager envoyManager; + + private LuckPerms luckPerms; + + private HashMap playerMenuUtilMap = new HashMap(); + + private List players = new ArrayList(); + + public void onEnable() { + instance = this; + + this.saveDefaultConfig(); + this.settingsConfig = new Config("config", this); + this.messagesConfig = new FileConfig(this, "messages.yml"); + this.kothsConfig = new FileConfig(this, "koths.yml"); + this.lootboxConfig = new FileConfig(this, "lootbox.yml"); + this.envoysConfig = new FileConfig(this, "envoys.yml"); + + Bukkit.getConsoleSender().sendMessage("------------------------------------------------"); + Bukkit.getConsoleSender().sendMessage(Utils.translate("&dLifestealCore &8- &av" + this.getDescription().getVersion())); + Bukkit.getConsoleSender().sendMessage(Utils.translate("&7Made by &eLoganM Development")); + Bukkit.getConsoleSender().sendMessage("------------------------------------------------"); + + new Constants(); + new ColorUtils(); + + this.loadManagers(); + this.loadListeners(); + this.loadRunnables(); + + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity.getType() != EntityType.PLAYER && entity.getType() != EntityType.ITEM_FRAME) { + entity.remove(); + } + } + + world.setGameRuleValue("doDaylightCycle", "false"); + world.setTime(0L); + world.setStorm(false); + } + + RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class); + + if (provider != null) { + luckPerms = provider.getProvider(); + } + } + + public void onDisable() { + for (Player player : this.getServer().getOnlinePlayers()) { + PlayerData playerData = this.playerDataManager.getPlayerData(player.getUniqueId()); + + this.playerDataManager.savePlayerData(playerData); + } + + this.getServer().getScheduler().cancelTask(this.leaderboardManager.getLeaderboard().getHologramTaskId()); + this.envoyManager.saveEnvoyLocations(); + this.mongoManager.disconnect(); + + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity.getType() == EntityType.DROPPED_ITEM) { + entity.remove(); + } + } + + for (Chunk chunk : world.getLoadedChunks()) { + chunk.unload(true); + } + } + + instance = null; + } + + private void loadManagers() { + this.commandManager = new CommandManager(); + this.clanManager = new ClanManager(); + this.chunkManager = new ChunkManager(); + this.pvpClassManager = new PvPClassManager(); + this.kothManager = new KOTHManager(); + this.spawnManager = new SpawnManager(); + this.mongoManager = new MongoManager(); + this.playerDataManager = new PlayerDataManager(); + this.lootboxManager = new LootboxManager(); + this.leaderboardManager = new LeaderboardManager(); + this.chatGameManager = new ChatGameManager(); + this.combatManager = new CombatManager(); + this.cooldownManager = new CooldownManager(); + this.killstreakManager = new KillstreakManager(); + this.envoyManager = new EnvoyManager(); + } + + private void loadListeners() { + Arrays.asList( + new MenuListener(), + new ButtonListener(), + new ClanListeners(), + this.pvpClassManager, + new EventListeners(), + new KOTHListener(), + new RandomListeners(), + new PlayerDataListener(), + new BlockBreakListener(), + new BlockExplodeListener(), + new BlockPlaceListener(), + new BlockSpreadListener(), + new BucketListener(), + new EntityChangeBlockListener(), + new PlayerDeathListener(), + new EntityDamageByEntityListener(), + new EntityDeathListener() + ).forEach(listener -> this.getServer().getPluginManager().registerEvents(listener, this)); + } + + private void loadRunnables() { + new Aether(this, new ScoreboardProvider()); + + new SpawnRunnable(); + new ClearLagRunnable(); + new CombatTagRunnable(); + new EnvoyRunnable(); + } + + public PlayerMenuUtil getPlayerMenuUtil(Player player) { + PlayerMenuUtil playerMenuUtil; + + if (playerMenuUtilMap.containsKey(player)) { + return playerMenuUtilMap.get(player); + } else { + playerMenuUtil = new PlayerMenuUtil(player); + + playerMenuUtilMap.put(player, playerMenuUtil); + + return playerMenuUtil; + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/Button.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/Button.java new file mode 100644 index 0000000..7926f1a --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/Button.java @@ -0,0 +1,52 @@ +package me.trixkz.lifestealcore.advancedmenusystem; + +import org.apache.commons.lang3.StringUtils; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public abstract class Button { + + public static Button placeholder(final Material material, final byte data, String... title) { + return (new Button() { + public ItemStack getButtonItem(Player player) { + ItemStack it = new ItemStack(material, 1, data); + ItemMeta meta = it.getItemMeta(); + + meta.setDisplayName(StringUtils.join(title)); + it.setItemMeta(meta); + + return it; + } + }); + } + + public static void playFail(Player player) { + player.playSound(player.getLocation(), Sound.BLOCK_GRASS_BREAK, 20F, 0.1F); + } + + public static void playSuccess(Player player) { + player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BELL, 20F, 15F); + } + + public static void playNeutral(Player player) { + player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 20F, 1F); + } + + public abstract ItemStack getButtonItem(Player player); + + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + + } + + public boolean shouldCancel(Player player, int slot, ClickType clickType) { + return (true); + } + + public boolean shouldUpdate(Player player, int slot, ClickType clickType) { + return (false); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/Menu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/Menu.java new file mode 100644 index 0000000..b8a9e7a --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/Menu.java @@ -0,0 +1,151 @@ +package me.trixkz.lifestealcore.advancedmenusystem; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.scheduler.BukkitTask; +import java.util.HashMap; +import java.util.Map; + +@Getter @Setter +public abstract class Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public static Map currentlyOpenedMenus = new HashMap<>(); + @Getter private Map buttons = new HashMap<>(); + + private boolean autoUpdate = false; + private boolean updateAfterClick = true; + private boolean closedByMenu = false; + private boolean placeholder = false; + + private Button placeholderButton = Button.placeholder(Material.LIGHT_GRAY_STAINED_GLASS_PANE, (byte) 0, " "); + private BukkitTask task; + + private ItemStack createItemStack(Player player, Button button) { + ItemStack item = button.getButtonItem(player); + if (item.getType() != Material.PLAYER_HEAD) { + ItemMeta meta = item.getItemMeta(); + if (meta != null && meta.hasDisplayName()) { + meta.setDisplayName(meta.getDisplayName() + "§b§c§d§e"); + } + item.setItemMeta(meta); + } + + return item; + } + + public void openMenu(final Player player) { + this.buttons = this.getButtons(player); + + Menu previousMenu = Menu.currentlyOpenedMenus.get(player.getName()); + Inventory inventory = null; + int size = this.getSize() == -1 ? this.size(this.buttons) : this.getSize(); + boolean update = false; + String title = this.getTitle(player); + + if (title.length() > 32) { + title = title.substring(0, 32); + } + + if (player.getOpenInventory() != null) { + if (previousMenu == null) { + player.closeInventory(); + } else { + int previousSize = player.getOpenInventory().getTopInventory().getSize(); + + if (previousSize == size && player.getOpenInventory().getTopInventory().toString().equals(title)) { + inventory = player.getOpenInventory().getTopInventory(); + update = true; + } else { + previousMenu.setClosedByMenu(true); + player.closeInventory(); + } + } + } + + if (inventory == null) { + inventory = Bukkit.createInventory(player, size, title); + } + + inventory.setContents(new ItemStack[inventory.getSize()]); + + currentlyOpenedMenus.put(player.getName(), this); + + for (Map.Entry buttonEntry : this.buttons.entrySet()) { + inventory.setItem(buttonEntry.getKey(), createItemStack(player, buttonEntry.getValue())); + } + + if (this.isPlaceholder()) { + for (int index = 0; index < size; index++) { + if (this.buttons.get(index) == null) { + this.buttons.put(index, this.placeholderButton); + inventory.setItem(index, this.placeholderButton.getButtonItem(player)); + } + } + } + + if (update) { + player.updateInventory(); + } else { + player.openInventory(inventory); + } + + this.setClosedByMenu(false); + if (autoUpdate && task == null) { + task = this.main.getServer().getScheduler().runTaskTimer(this.main, () -> this.openMenu(player), 0, 20L); + } + } + + public int size(Map buttons) { + int highest = 0; + + for (int buttonValue : buttons.keySet()) { + if (buttonValue > highest) { + highest = buttonValue; + } + } + + return (int) (Math.ceil((highest + 1) / 9D) * 9D); + } + + public int getSlot(int x, int y) { + return ((9 * y) + x); + } + + public int getSize() { + return -1; + } + + public abstract String getTitle(Player player); + + public abstract Map getButtons(Player player); + + public void onClose(Player player) { + if (task != null) { + task.cancel(); + } + } + + public void fillEmptySlots(Map buttons, ItemStack itemStack) { + int bound = getSize(); + + for (int slot = 0; slot < bound; slot++) { + if (buttons.get(slot) == null) { + buttons.put(slot, new Button() { + @Override + public ItemStack getButtonItem(Player player) { + return itemStack; + } + }); + } + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/buttons/BackButton.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/buttons/BackButton.java new file mode 100644 index 0000000..d1439a3 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/buttons/BackButton.java @@ -0,0 +1,32 @@ +package me.trixkz.lifestealcore.advancedmenusystem.buttons; + +import lombok.AllArgsConstructor; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import java.util.Arrays; + +@AllArgsConstructor +public class BackButton extends Button { + + private Menu back; + + @Override + public ItemStack getButtonItem(Player player) { + return new ItemBuilder(Material.RED_BED) + .name("&cGo Back") + .lore(Arrays.asList(" ", "&9Click to go back.")) + .hideFlags() + .build(); + } + + @Override + public void clicked(Player player, int i, ClickType clickType, int hb) { + this.back.openMenu(player); + playNeutral(player); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/buttons/DisplayButton.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/buttons/DisplayButton.java new file mode 100644 index 0000000..72a98bf --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/buttons/DisplayButton.java @@ -0,0 +1,31 @@ +package me.trixkz.lifestealcore.advancedmenusystem.buttons; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +@AllArgsConstructor @Getter @Setter +public class DisplayButton extends Button { + + private ItemStack itemStack; + private boolean cancel; + + @Override + public ItemStack getButtonItem(Player player) { + if (this.itemStack == null) { + return new ItemStack(Material.AIR); + } else { + return this.itemStack; + } + } + + @Override + public boolean shouldCancel(Player player, int slot, ClickType clickType) { + return this.cancel; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/JumpToPageButton.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/JumpToPageButton.java new file mode 100644 index 0000000..2da0f99 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/JumpToPageButton.java @@ -0,0 +1,44 @@ +package me.trixkz.lifestealcore.advancedmenusystem.pagination; + +import lombok.AllArgsConstructor; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.List; + +@AllArgsConstructor +public class JumpToPageButton extends Button { + + private int page; + private PaginatedMenu menu; + private boolean current; + + @Override + public ItemStack getButtonItem(Player player) { + List lore = new ArrayList<>(); + + lore.add(" "); + if (this.current) { + lore.add("&9Current page"); + } else { + lore.add("&9Other page"); + } + lore.add(" "); + + return new ItemBuilder(this.current ? Material.LIME_DYE : Material.GRAY_DYE) + .name("&d&lPage: &e" + this.page) + .lore(lore) + .hideFlags() + .build(); + } + + @Override + public void clicked(Player player, int i, ClickType clickType, int hb) { + this.menu.modPage(player, this.page - this.menu.getPage()); + playNeutral(player); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/PageButton.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/PageButton.java new file mode 100644 index 0000000..60105c3 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/PageButton.java @@ -0,0 +1,54 @@ +package me.trixkz.lifestealcore.advancedmenusystem.pagination; + +import lombok.AllArgsConstructor; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.List; + +@AllArgsConstructor +public class PageButton extends Button { + + private int mod; + private PaginatedMenu menu; + + @Override + public ItemStack getButtonItem(Player player) { + List lore = new ArrayList<>(); + + lore.add(" "); + lore.add("&9Right Click to"); + lore.add("&9switch to a page."); + lore.add(" "); + + return new ItemBuilder(this.hasNext(player) ? (this.mod > 0 ? Material.PURPLE_CARPET : Material.ORANGE_CARPET) : Material.GRAY_CARPET) + .name(this.hasNext(player) ? (this.mod > 0 ? "&aNext Page" : "&cPrevious Page") : (this.mod > 0 ? "&7Last Page" : "&7First Page")) + .lore(lore) + .hideFlags() + .build(); + } + + @Override + public void clicked(Player player, int i, ClickType clickType, int hb) { + if (clickType == ClickType.RIGHT) { + new ViewAllPagesMenu(this.menu).openMenu(player); + playNeutral(player); + } else { + if (hasNext(player)) { + this.menu.modPage(player, this.mod); + playNeutral(player); + } else { + playFail(player); + } + } + } + + private boolean hasNext(Player player) { + int pg = this.menu.getPage() + this.mod; + return pg > 0 && this.menu.getPages(player) >= pg; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/PaginatedMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/PaginatedMenu.java new file mode 100644 index 0000000..d763d25 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/PaginatedMenu.java @@ -0,0 +1,117 @@ +package me.trixkz.lifestealcore.advancedmenusystem.pagination; + +import lombok.Getter; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.IntStream; + +public abstract class PaginatedMenu extends Menu { + + @Getter private int page = 1; + + { + setUpdateAfterClick(false); + } + + @Override + public String getTitle(Player player) { + return getPrePaginatedTitle(player) + " - " + page + "/" + getPages(player); + } + + /** + * Changes the page number + * + * @param player player viewing the inventory + * @param mod delta to modify the page number by + */ + public final void modPage(Player player, int mod) { + page += mod; + getButtons().clear(); + openMenu(player); + } + + /** + * @param player player viewing the inventory + */ + public final int getPages(Player player) { + int buttonAmount = getAllPagesButtons(player).size(); + + if (buttonAmount == 0) { + return 1; + } + + return (int) Math.ceil(buttonAmount / (double) getMaxItemsPerPage(player)); + } + + @Override + public final Map getButtons(Player player) { + int minIndex = (int) ((double) (page - 1) * getMaxItemsPerPage(player)); + int maxIndex = (int) ((double) (page) * getMaxItemsPerPage(player)); + + HashMap buttons = new HashMap<>(); + + buttons.put(0, new PageButton(-1, this)); + buttons.put(8, new PageButton(1, this)); + + for (Map.Entry entry : getAllPagesButtons(player).entrySet()) { + int ind = entry.getKey(); + if (ind >= minIndex && ind < maxIndex) { + ind -= (int) ((double) (getMaxItemsPerPage(player)) * (page - 1)) - 9; + buttons.put(ind, entry.getValue()); + } + } + + Map global = getGlobalButtons(player); + if (global != null) { + for (Map.Entry gent : global.entrySet()) { + buttons.put(gent.getKey(), gent.getValue()); + } + } + + return buttons; + } + + public int getMaxItemsPerPage(Player player) { + return 18; + } + + /** + * @param player player viewing the inventory + * + * @return a Map of buttons that returns items which will be present on all pages + */ + public Map getGlobalButtons(Player player) { + return null; + } + + protected void bottomTopButtons(boolean full, Map buttons, ItemStack itemStack) { + IntStream.range(0, getSize()).filter(slot -> buttons.get(slot) == null).forEach(slot -> { + if (slot < 9 || slot > getSize() - 10 || full && (slot % 9 == 0 || (slot + 1) % 9 == 0)) { + buttons.put(slot, new Button() { + @Override + public ItemStack getButtonItem(Player player) { + return itemStack; + } + }); + } + }); + } + + /** + * @param player player viewing the inventory + * + * @return title of the inventory before the page number is added + */ + public abstract String getPrePaginatedTitle(Player player); + + /** + * @param player player viewing the inventory + * + * @return a map of buttons that will be paginated and spread across pages + */ + public abstract Map getAllPagesButtons(Player player); +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/ViewAllPagesMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/ViewAllPagesMenu.java new file mode 100644 index 0000000..7600c0d --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/pagination/ViewAllPagesMenu.java @@ -0,0 +1,56 @@ +package me.trixkz.lifestealcore.advancedmenusystem.pagination; + +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.buttons.BackButton; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import java.util.HashMap; +import java.util.Map; + +@RequiredArgsConstructor +public class ViewAllPagesMenu extends Menu { + + @NonNull @Getter + PaginatedMenu menu; + + @Override + public String getTitle(Player player) { + return Utils.translate("&eSwitch to page..."); + } + + @Override + public Map getButtons(Player player) { + HashMap buttons = new HashMap<>(); + + buttons.put(0, new BackButton(menu)); + + int index = 10; + for (int i = 1; i <= menu.getPages(player); i++) { + buttons.put(index++, new JumpToPageButton(i, menu, menu.getPage() == i)); + + if ((index - 8) % 9 == 0) { + index += 2; + } + } + + fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).durability(0).name(" ").build()); + + return buttons; + } + + @Override + public boolean isAutoUpdate() { + return true; + } + + @Override + public int getSize() { + return 3 * 9; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/GoBackButton.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/GoBackButton.java new file mode 100644 index 0000000..5095c64 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/GoBackButton.java @@ -0,0 +1,25 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +public class GoBackButton extends Button { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public ItemStack getButtonItem(Player player) { + return new ItemBuilder(Material.BARRIER).name(Utils.translate("&4Go back")).amount(1).build(); + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + new ShopMenu().openMenu(player); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopButton.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopButton.java new file mode 100644 index 0000000..e7a964c --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopButton.java @@ -0,0 +1,74 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class ShopButton extends Button { + + private ItemStack itemStack; + private int data; + private int buyPrice; + private int sellPrice; + private boolean sellable; + + @Override + public ItemStack getButtonItem(Player player) { + PlayerData playerData = LifeStealCore.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()); + + this.itemStack.setDurability((short) (this.data)); + + ItemMeta itemMeta = this.itemStack.getItemMeta(); + itemMeta.setDisplayName(Utils.translate("&d" + this.itemStack.getType().name())); + + List lore = new ArrayList(); + lore.add("&9Buy price: &d" + this.buyPrice + " &7&o(Left click)"); + + if (this.sellable) { + lore.add("&9Sell price: &d" + this.sellPrice + " &7&o(Right click)"); + } else { + lore.add("&9Not sellable"); + } + + itemMeta.setLore(Utils.translate(lore)); + + this.itemStack.setItemMeta(itemMeta); + + return this.itemStack; + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + PlayerData playerData = LifeStealCore.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()); + + this.itemStack.setDurability((short) (this.data)); + + switch (clickType) { + case LEFT: + new ShopBuyMenu(this.itemStack, this.buyPrice).openMenu(player); + + break; + case RIGHT: + if (this.sellable) { + new ShopSellMenu(this.itemStack, this.sellPrice).openMenu(player); + } + + break; + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopBuyMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopBuyMenu.java new file mode 100644 index 0000000..27918f0 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopBuyMenu.java @@ -0,0 +1,55 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.HashMap; +import java.util.Map; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class ShopBuyMenu extends Menu { + + private ItemStack itemStack; + private int buyPrice; + + @Override + public String getTitle(Player player) { + return Utils.translate("&eBuying " + this.itemStack.getItemMeta().getDisplayName() + "..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + buttons.put(22, new ShopItemButton(this.itemStack, this.buyPrice, 0, true, ShopItemType.ITEM)); + buttons.put(18, new ShopItemButton(this.itemStack, this.buyPrice, 0, true, ShopItemType.SET_TO_ONE)); + buttons.put(19, new ShopItemButton(this.itemStack, this.buyPrice, 0, true, ShopItemType.REMOVE_TEN)); + buttons.put(20, new ShopItemButton(this.itemStack, this.buyPrice, 0, true, ShopItemType.REMOVE_ONE)); + buttons.put(24, new ShopItemButton(this.itemStack, this.buyPrice, 0, true, ShopItemType.ADD_ONE)); + buttons.put(25, new ShopItemButton(this.itemStack, this.buyPrice, 0, true, ShopItemType.ADD_TEN)); + buttons.put(26, new ShopItemButton(this.itemStack, this.buyPrice, 0, true, ShopItemType.SET_TO_SIXTY_FOUR)); + buttons.put(39, new ShopItemButton(this.itemStack, this.buyPrice, 0, true, ShopItemType.CONFIRM)); + buttons.put(41, new ShopItemButton(this.itemStack, this.buyPrice, 0, true, ShopItemType.CANCEL)); + // buttons.put(49, new ShopItemButton(this.itemStack, this.buyPrice, 0, true, ShopItemType.MORE)); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemButton.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemButton.java new file mode 100644 index 0000000..da9e5db --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemButton.java @@ -0,0 +1,232 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class ShopItemButton extends Button { + + private ItemStack itemStack; + private int buyPrice; + private int sellPrice; + private boolean buy; + private ShopItemType shopItemType; + + @Override + public ItemStack getButtonItem(Player player) { + PlayerData playerData = LifeStealCore.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (this.buy) { + this.buyPrice *= this.itemStack.getAmount(); + } else { + this.sellPrice *= this.itemStack.getAmount(); + } + + ItemStack itemStackCopy = new ItemStack(this.itemStack.getType()); + + ItemMeta itemMeta = itemStackCopy.getItemMeta(); + + List lore = new ArrayList(); + + switch (this.shopItemType) { + case ITEM: + ItemMeta itemMetaCopy = itemStackCopy.getItemMeta(); + itemMetaCopy.setDisplayName(Utils.translate("&d" + this.itemStack.getType().name())); + + if (this.buy) { + lore.add("&9Buy price: &d" + this.buyPrice); + } else { + lore.add("&9Sell price: &d" + this.sellPrice); + } + + itemMetaCopy.setLore(Utils.translate(lore)); + + this.itemStack.setItemMeta(itemMetaCopy); + + break; + case CONFIRM: + if (this.buy) { + lore.add(playerData.getCoins() >= this.buyPrice ? "&aClick to buy" : "&cNot enough coins"); + } else { + int itemStacks = 0; + + for (ItemStack itemStack : player.getInventory().getContents()) { + if (itemStack == null) { + continue; + } + + if (this.itemStack.getType() == itemStack.getType()) { + itemStacks += itemStack.getAmount(); + } + } + + lore.add(itemStacks >= this.itemStack.getAmount() ? "&aClick to sell" : "&cNot enough items"); + } + + itemStackCopy.setType(Material.GREEN_STAINED_GLASS); + + itemMeta.setDisplayName(Utils.translate("&aConfirm")); + itemMeta.setLore(Utils.translate(lore)); + + break; + case CANCEL: + itemStackCopy.setType(Material.RED_STAINED_GLASS); + + itemMeta.setDisplayName(Utils.translate("&cCancel")); + + break; + case ADD_ONE: + itemStackCopy.setAmount(1); + itemStackCopy.setType(Material.GREEN_STAINED_GLASS_PANE); + + itemMeta.setDisplayName(Utils.translate("&aAdd 1")); + + break; + case ADD_TEN: + itemStackCopy.setAmount(10); + itemStackCopy.setType(Material.GREEN_STAINED_GLASS_PANE); + + itemMeta.setDisplayName(Utils.translate("&aAdd 10")); + + break; + case SET_TO_SIXTY_FOUR: + itemStackCopy.setAmount(64); + itemStackCopy.setType(Material.GREEN_STAINED_GLASS_PANE); + + itemMeta.setDisplayName(Utils.translate("&aSet to 64")); + + break; + case REMOVE_ONE: + itemStackCopy.setAmount(1); + itemStackCopy.setType(Material.RED_STAINED_GLASS_PANE); + + itemMeta.setDisplayName(Utils.translate("&cRemove 1")); + + break; + case REMOVE_TEN: + itemStackCopy.setAmount(10); + itemStackCopy.setType(Material.RED_STAINED_GLASS_PANE); + + itemMeta.setDisplayName(Utils.translate("&cRemove 10")); + + break; + case SET_TO_ONE: + itemStackCopy.setAmount(1); + itemStackCopy.setType(Material.RED_STAINED_GLASS_PANE); + + itemMeta.setDisplayName(Utils.translate("&cSet to 1")); + + break; + case MORE: + itemStackCopy.setAmount(this.itemStack.getAmount() + 64); + + if (this.buy) { + itemStackCopy.setType(Material.GREEN_STAINED_GLASS_PANE); + } else { + itemStackCopy.setType(Material.RED_STAINED_GLASS_PANE); + } + + itemMeta.setDisplayName(Utils.translate(this.buy ? "&aBuy more" : "&cSell more")); + + break; + } + + itemStackCopy.setItemMeta(itemMeta); + + return this.shopItemType == ShopItemType.ITEM ? this.itemStack : itemStackCopy; + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + PlayerData playerData = LifeStealCore.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()); + + switch (this.shopItemType) { + case ITEM: + break; + case CONFIRM: + if (this.buy) { + if (playerData.getCoins() >= this.buyPrice) { + player.getInventory().addItem(new ItemStack(this.itemStack.getType(), this.itemStack.getAmount())); + + playerData.setCoins(playerData.getCoins() - this.buyPrice); + } + } else { + int itemStacks = 0; + + for (ItemStack itemStack : player.getInventory().getContents()) { + if (itemStack == null) { + continue; + } + + if (this.itemStack.getType() == itemStack.getType()) { + itemStacks += itemStack.getAmount(); + } + } + + if (itemStacks >= this.itemStack.getAmount()) { + player.getInventory().removeItem(new ItemStack(this.itemStack.getType(), this.itemStack.getAmount())); + + playerData.setCoins(playerData.getCoins() + this.itemStack.getAmount()); + } + } + + break; + case CANCEL: + player.closeInventory(); + + break; + case ADD_ONE: + this.itemStack.setAmount(this.itemStack.getAmount() + 1); + + break; + case ADD_TEN: + this.itemStack.setAmount(this.itemStack.getAmount() + 10); + + break; + case SET_TO_SIXTY_FOUR: + this.itemStack.setAmount(64); + + break; + case REMOVE_ONE: + this.itemStack.setAmount(this.itemStack.getAmount() - 1); + + if (this.itemStack.getAmount() < 1) { + this.itemStack.setAmount(1); + } + + break; + case REMOVE_TEN: + this.itemStack.setAmount(this.itemStack.getAmount() - 10); + + if (this.itemStack.getAmount() < 1) { + this.itemStack.setAmount(1); + } + + break; + case SET_TO_ONE: + this.itemStack.setAmount(1); + + break; + case MORE: + break; + } + + player.updateInventory(); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemMenu.java new file mode 100644 index 0000000..3ad9cd2 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemMenu.java @@ -0,0 +1,39 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import java.util.HashMap; +import java.util.Map; + +public class ShopItemMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public String getTitle(Player player) { + return Utils.translate("&eShop menu"); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + for (ShopType shopType : ShopType.values()) { + buttons.put(shopType.getSlot(), new ShopTypeButton(shopType)); + } + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemSet.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemSet.java new file mode 100644 index 0000000..1012402 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemSet.java @@ -0,0 +1,19 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class ShopItemSet { + + private Material material = null; + private Data data = null; + private BuyPrice buyPrice = null; + private SellPrice sellPrice = null; + private Sellable sellable = null; +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemType.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemType.java new file mode 100644 index 0000000..276fa6a --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopItemType.java @@ -0,0 +1,15 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +public enum ShopItemType { + + ITEM, + CONFIRM, + CANCEL, + ADD_ONE, + ADD_TEN, + SET_TO_SIXTY_FOUR, + REMOVE_ONE, + REMOVE_TEN, + SET_TO_ONE, + MORE; +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopMenu.java new file mode 100644 index 0000000..574ea0a --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopMenu.java @@ -0,0 +1,39 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import java.util.HashMap; +import java.util.Map; + +public class ShopMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public String getTitle(Player player) { + return Utils.translate("&eShop menu"); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + for (ShopType shopType : ShopType.values()) { + buttons.put(shopType.getSlot(), new ShopTypeButton(shopType)); + } + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopSellMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopSellMenu.java new file mode 100644 index 0000000..e65404a --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopSellMenu.java @@ -0,0 +1,55 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.HashMap; +import java.util.Map; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class ShopSellMenu extends Menu { + + private ItemStack itemStack; + private int sellPrice; + + @Override + public String getTitle(Player player) { + return Utils.translate("&eSelling " + this.itemStack.getItemMeta().getDisplayName() + "..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + buttons.put(22, new ShopItemButton(this.itemStack, 0, this.sellPrice, false, ShopItemType.ITEM)); + buttons.put(18, new ShopItemButton(this.itemStack, 0, this.sellPrice, false, ShopItemType.SET_TO_ONE)); + buttons.put(19, new ShopItemButton(this.itemStack, 0, this.sellPrice, false, ShopItemType.REMOVE_TEN)); + buttons.put(20, new ShopItemButton(this.itemStack, 0, this.sellPrice, false, ShopItemType.REMOVE_ONE)); + buttons.put(24, new ShopItemButton(this.itemStack, 0, this.sellPrice, false, ShopItemType.ADD_ONE)); + buttons.put(25, new ShopItemButton(this.itemStack, 0, this.sellPrice, false, ShopItemType.ADD_TEN)); + buttons.put(26, new ShopItemButton(this.itemStack, 0, this.sellPrice, false, ShopItemType.SET_TO_SIXTY_FOUR)); + buttons.put(39, new ShopItemButton(this.itemStack, 0, this.sellPrice, false, ShopItemType.CONFIRM)); + buttons.put(41, new ShopItemButton(this.itemStack, 0, this.sellPrice, false, ShopItemType.CANCEL)); + // buttons.put(49, new ShopItemButton(this.itemStack, 0, this.sellPrice, true, ShopItemType.MORE)); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopType.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopType.java new file mode 100644 index 0000000..abaacef --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopType.java @@ -0,0 +1,144 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.bukkit.Material; +import java.util.Arrays; +import java.util.List; + +@Getter +@AllArgsConstructor +@RequiredArgsConstructor +public enum ShopType { + + BLOCKS( + "&dBlocks", + Arrays.asList( + "&9Click to open the &dBlocks &9section" + ), + Material.GRASS, + 0, + 11 + ), + + FOOD( + "&dFood", + Arrays.asList( + "&9Click to open the &dFood &9section" + ), + Material.COOKED_BEEF, + 0, + 12 + ), + + COLORFUL_BLOCKS( + "&dColorful blocks", + Arrays.asList( + "&9Click to open the &dColorful blocks &9section" + ), + Material.STONE, + 0, + 13 + ), + + ORES( + "&dOres", + Arrays.asList( + "&9Click to open the &dOres &9section" + ), + Material.DIAMOND, + 0, + 14 + ), + + COMBAT( + "&dCombat", + Arrays.asList( + "&9Click to open the &dCombat &9section" + ), + Material.DIAMOND_SWORD, + 0, + 15 + ), + + FARMING( + "&dFarming", + Arrays.asList( + "&9Click to open the &dFarming &9section" + ), + Material.WHEAT, + 0, + 20 + ), + + MOB_DROPS( + "&dMob drops", + Arrays.asList( + "&9Click to open the &dMob drops &9section" + ), + Material.ROTTEN_FLESH, + 0, + 21 + ), + + DYES_AND_PLANTS( + "&dDyes and plants", + Arrays.asList( + "&9Click to open the &dDyes and plants &9section" + ), + Material.INK_SAC, + 14, + 22 + ), + + POTIONS( + "&dPotions", + Arrays.asList( + "&9Click to open the &dPotions &9section" + ), + Material.POTION, + 8229, + 23 + ), + + REDSTONE( + "&dRedstone", + Arrays.asList( + "&9Click to open the &dRedstone &9section" + ), + Material.REDSTONE, + 0, + 24 + ), + + CUSTOM_ITEMS( + "&dCustom items", + Arrays.asList( + "&9Click to open the &dCustom items &9section" + ), + Material.NETHER_STAR, + 0, + 30 + ), + + SPAWNERS( + "&dSpawners", + Arrays.asList( + "&9Click to open the &dSpawners &9section" + ), + Material.SPAWNER, + 0, + 32 + ); + + private String name; + private List lore; + private Material material; + private int data; + private int slot; + + public static ShopType getShopByName(String name) { + return Arrays.stream(values()).filter(shopType -> shopType.getName().equalsIgnoreCase(name)).findFirst().orElse(null); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopTypeButton.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopTypeButton.java new file mode 100644 index 0000000..89fa81d --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ShopTypeButton.java @@ -0,0 +1,92 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.shop.blocks.BlocksMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.colorfulblocks.ColorfulBlocksMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.combat.CombatMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.customitems.CustomItemsMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.dyesandplants.DyesAndPlantsMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.farming.FarmingMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.food.FoodMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.mobdrops.MobDropsMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ores.OresMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.potions.PotionsMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.redstone.RedstoneMenu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.spawners.SpawnersMenu; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class ShopTypeButton extends Button { + + private ShopType shopType; + + @Override + public ItemStack getButtonItem(Player player) { + return new ItemBuilder(this.shopType.getMaterial()).name(Utils.translate(this.shopType.getName())).lore(Utils.translate(this.shopType.getLore())).durability(this.shopType.getData()).build(); + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + switch (this.shopType) { + case BLOCKS: + new BlocksMenu().openMenu(player); + + break; + case FOOD: + new FoodMenu().openMenu(player); + + break; + case COLORFUL_BLOCKS: + new ColorfulBlocksMenu().openMenu(player); + + break; + case ORES: + new OresMenu().openMenu(player); + + break; + case COMBAT: + new CombatMenu().openMenu(player); + + break; + case FARMING: + new FarmingMenu().openMenu(player); + + break; + case MOB_DROPS: + new MobDropsMenu().openMenu(player); + + break; + case DYES_AND_PLANTS: + new DyesAndPlantsMenu().openMenu(player); + + break; + case POTIONS: + new PotionsMenu().openMenu(player); + + break; + case REDSTONE: + new RedstoneMenu().openMenu(player); + + break; + case CUSTOM_ITEMS: + new CustomItemsMenu().openMenu(player); + + break; + case SPAWNERS: + new SpawnersMenu().openMenu(player); + + break; + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/blocks/BlocksMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/blocks/BlocksMenu.java new file mode 100644 index 0000000..d222aa7 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/blocks/BlocksMenu.java @@ -0,0 +1,105 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.blocks; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class BlocksMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public BlocksMenu() { + this.shopItemSets.add(new ShopItemSet<>(Material.STONE, 0, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.STONE, 1, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.STONE, 2, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.STONE, 3, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.STONE, 4, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.STONE, 5, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.STONE, 6, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.OBSIDIAN, 0, 3500, 450, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.GRASS, 0, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIRT, 0, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIRT, 1, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIRT, 2, 8, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.COBBLESTONE, 0, 8, 2, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.LOG, 0, 3000, 2500, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.LOG, 1, 3000, 2500, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.LOG, 2, 3000, 2500, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.LOG, 3, 3000, 2500, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOD, 0, 30, 5, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOD, 1, 30, 5, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOD, 2, 30, 5, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOD, 3, 30, 5, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOD, 4, 30, 5, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOD, 5, 30, 5, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.LEAVES, 0, 60, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.LEAVES, 1, 60, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.LEAVES, 2, 60, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.LEAVES, 3, 60, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.SAND, 0, 4, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.SAND, 1, 4, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.SANDSTONE, 0, 4, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.SANDSTONE, 1, 4, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.SANDSTONE, 2, 4, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.RED_SANDSTONE, 0, 4, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.RED_SANDSTONE, 1, 4, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.RED_SANDSTONE, 2, 4, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.GLASS, 0, 4, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.SNOW_BLOCK, 0, 25, 4, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.ICE, 0, 25, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.PACKED_ICE, 0, 40, 4, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.NETHERRACK, 0, 15, 4, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.SOUL_SAND, 0, 80, 15, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.GLOWSTONE, 0, 20, 4, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.QUARTZ_BLOCK, 0, 15, 10, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.QUARTZ_BLOCK, 1, 15, 5, true)); + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/colorfulblocks/ColorfulBlocksMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/colorfulblocks/ColorfulBlocksMenu.java new file mode 100644 index 0000000..a559f0a --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/colorfulblocks/ColorfulBlocksMenu.java @@ -0,0 +1,109 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.colorfulblocks; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class ColorfulBlocksMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public ColorfulBlocksMenu() { +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 0, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 1, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 2, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 3, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 4, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 5, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 6, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 7, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 8, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 9, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 10, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 11, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 12, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 13, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 14, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_CLAY, 15, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 0, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 1, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 2, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 3, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 4, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 5, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 6, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 7, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 8, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 9, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 10, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 11, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 12, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 13, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 14, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STAINED_GLASS, 15, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 0, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 1, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 2, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 3, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 4, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 5, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 6, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 7, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 8, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 9, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 10, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 11, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 12, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 13, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 14, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOL, 15, 75, 0, false)); + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/combat/CombatMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/combat/CombatMenu.java new file mode 100644 index 0000000..25c8252 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/combat/CombatMenu.java @@ -0,0 +1,81 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.combat; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class CombatMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public CombatMenu() { + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND_SWORD, 0, 8000, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_SWORD, 0, 200, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.BOW, 0, 150, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.FISHING_ROD, 0, 150, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND_PICKAXE, 0, 12000, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND_AXE, 0, 12000, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND_SHOVEL, 0, 4000, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND_HOE, 0, 8000, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_PICKAXE, 0, 325, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_AXE, 0, 300, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_SHOVEL, 0, 100, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_HOE, 0, 200, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND_HELMET, 0, 20000, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND_CHESTPLATE, 0, 32000, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND_LEGGINGS, 0, 28000, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND_BOOTS, 0, 16000, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_HELMET, 0, 500, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_CHESTPLATE, 0, 800, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_LEGGINGS, 0, 700, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_BOOTS, 0, 400, 0, false)); + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/customitems/CustomItemsMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/customitems/CustomItemsMenu.java new file mode 100644 index 0000000..c1651f0 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/customitems/CustomItemsMenu.java @@ -0,0 +1,62 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.customitems; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class CustomItemsMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public CustomItemsMenu() { + + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/dyesandplants/DyesAndPlantsMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/dyesandplants/DyesAndPlantsMenu.java new file mode 100644 index 0000000..7fbc927 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/dyesandplants/DyesAndPlantsMenu.java @@ -0,0 +1,93 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.dyesandplants; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class DyesAndPlantsMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public DyesAndPlantsMenu() { +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 0, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 1, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 2, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 3, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 4, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 5, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 6, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 7, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 8, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 9, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 10, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 11, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 12, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 13, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 14, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.INK_SACK, 15, 50, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RED_ROSE, 0, 15, 2, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RED_ROSE, 1, 15, 2, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RED_ROSE, 2, 15, 2, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RED_ROSE, 3, 20, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RED_ROSE, 4, 20, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RED_ROSE, 5, 20, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RED_ROSE, 6, 20, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RED_ROSE, 7, 15, 2, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RED_ROSE, 8, 15, 2, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.YELLOW_FLOWER, 0, 15, 2, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.DOUBLE_PLANT, 0, 15, 2, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.DOUBLE_PLANT, 1, 15, 2, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.DOUBLE_PLANT, 2, 20, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.DOUBLE_PLANT, 3, 20, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.DOUBLE_PLANT, 4, 20, 1, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.DOUBLE_PLANT, 5, 20, 1, true)); + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/farming/FarmingMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/farming/FarmingMenu.java new file mode 100644 index 0000000..e078c53 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/farming/FarmingMenu.java @@ -0,0 +1,84 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.farming; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class FarmingMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public FarmingMenu() { +// this.shopItemSets.add(new ShopItemSet<>(Material.SAPLING, 0, 2000, 200, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.SAPLING, 1, 2000, 200, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.SAPLING, 2, 2000, 200, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.SAPLING, 3, 2000, 200, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.SAPLING, 4, 2000, 200, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.SAPLING, 5, 2000, 200, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.SEEDS, 0, 150, 1, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.MELON_SEEDS, 0, 100, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.PUMPKIN_SEEDS, 0, 100, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.NETHER_WARTS, 0, 150, 70, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.INK_SAC, 3, 20, 1, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.BROWN_MUSHROOM, 0, 25, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.RED_MUSHROOM, 0, 25, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.SUGAR_CANE, 0, 2700, 2000, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.BOOK, 0, 30, 15, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.PAPER, 0, 20, 10, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.WHEAT, 0, 150, 50, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.VINE, 0, 10, 1, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.CACTUS, 0, 50, 10, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.MELON_BLOCK, 0, 1000, 100, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.PUMPKIN, 0, 500, 150, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.WATER_BUCKET, 0, 75, 150, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.LAVA_BUCKET, 0, 8000, 400, true)); + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/food/FoodMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/food/FoodMenu.java new file mode 100644 index 0000000..3b7ae5a --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/food/FoodMenu.java @@ -0,0 +1,78 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.food; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class FoodMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public FoodMenu() { + this.shopItemSets.add(new ShopItemSet<>(Material.COOKED_CHICKEN, 0, 25, 4, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.COOKED_BEEF, 0, 25, 5, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.GRILLED_PORK, 0, 25, 4, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.COOKED_FISH, 0, 40, 6, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.COOKED_RABBIT, 0, 30, 4, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.COOKED_MUTTON, 0, 25, 3, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.ROTTEN_FLESH, 0, 25, 6, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.BAKED_POTATO, 0, 25, 9, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.POTATO, 0, 25, 9, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.BREAD, 0, 40, 13, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.CARROT, 0, 150, 50, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.MELON, 0, 200, 10, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.MUSHROOM_SOUP, 0, 40, 4, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.RABBIT_STEW, 0, 100, 18, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.GOLDEN_APPLE, 0, 4250, 500, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.GOLDEN_APPLE, 1, 36000, 2750, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.APPLE, 0, 250, 5, true)); + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a food to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/mobdrops/MobDropsMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/mobdrops/MobDropsMenu.java new file mode 100644 index 0000000..6c2dda6 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/mobdrops/MobDropsMenu.java @@ -0,0 +1,81 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.mobdrops; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class MobDropsMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public MobDropsMenu() { + this.shopItemSets.add(new ShopItemSet<>(Material.GHAST_TEAR, 0, 5000, 50, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.GOLD_NUGGET, 0, 1000, 10, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.FEATHER, 0, 15, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.LEATHER, 0, 25, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.EGG, 0, 50, 35, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RED_ROSE, 0, 15, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.BONE, 0, 25, 5, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.ROTTEN_FLESH, 0, 25, 5, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.ARROW, 0, 15, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.SPIDER_EYE, 0, 20, 5, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.STRING, 0, 15, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.RABBIT_HIDE, 0, 25, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.ENDER_PEARL, 0, 100, 10, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.EYE_OF_ENDER, 0, 50, 5, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.BLAZE_ROD, 0, 50, 5, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RAW_BEEF, 0, 20, 5, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.PORK, 0, 20, 5, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.RAW_CHICKEN, 0, 20, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.MUTTON, 0, 20, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.NETHER_STAR, 0, 10000, 3000, true)); + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ores/OresMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ores/OresMenu.java new file mode 100644 index 0000000..f7c5b94 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/ores/OresMenu.java @@ -0,0 +1,76 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.ores; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class OresMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public OresMenu() { + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_INGOT, 0, 200, 5, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.GOLD_INGOT, 0, 800, 40, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.EMERALD, 0, 3000, 100, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND, 0, 4000, 70, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.COAL, 0, 25, 2, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.REDSTONE, 0, 55, 10, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.INK_SAC, 4, 50, 1, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.IRON_BLOCK, 0, 6000, 45, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.GOLD_BLOCK, 0, 8000, 440, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.EMERALD_BLOCK, 0, 20000, 900, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.DIAMOND_BLOCK, 0, 40000, 770, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.COAL_BLOCK, 0, 675, 22, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.REDSTONE_BLOCK, 0, 3000, 80, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.LAPIS_BLOCK, 0, 1350, 10, true)); + this.shopItemSets.add(new ShopItemSet<>(Material.QUARTZ, 0, 500, 6, true)); + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/potions/PotionsMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/potions/PotionsMenu.java new file mode 100644 index 0000000..4753cb9 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/potions/PotionsMenu.java @@ -0,0 +1,62 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.potions; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class PotionsMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public PotionsMenu() { + + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/redstone/RedstoneMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/redstone/RedstoneMenu.java new file mode 100644 index 0000000..77c7dc0 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/redstone/RedstoneMenu.java @@ -0,0 +1,80 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.redstone; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class RedstoneMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public RedstoneMenu() { + this.shopItemSets.add(new ShopItemSet<>(Material.REDSTONE, 0, 50, 10, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.REDSTONE_TORCH_ON, 0, 50, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.REDSTONE_COMPARATOR, 0, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.PISTON_BASE, 0, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.PISTON_STICKY_BASE, 0, 75, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.HOPPER, 0, 12500, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.DISPENSER, 0, 75, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.DROPPER, 0, 75, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.LEVER, 0, 25, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.STONE_BUTTON, 0, 25, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOD_BUTTON, 0, 25, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.STONE_PLATE, 0, 50, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.WOOD_PLATE, 0, 50, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.CARPET, 0, 150, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.TRIPWIRE_HOOK, 0, 75, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.REDSTONE_BLOCK, 0, 3000, 75, true)); +// this.shopItemSets.add(new ShopItemSet<>(Material.REDSTONE_LAMP_ON, 0, 75, 0, false)); + this.shopItemSets.add(new ShopItemSet<>(Material.FURNACE, 0, 75, 0, false)); +// this.shopItemSets.add(new ShopItemSet<>(Material.TRAP_DOOR, 0, 50, 0, false)); + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/spawners/SpawnersMenu.java b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/spawners/SpawnersMenu.java new file mode 100644 index 0000000..fdd6342 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/advancedmenusystem/shop/spawners/SpawnersMenu.java @@ -0,0 +1,75 @@ +package me.trixkz.lifestealcore.advancedmenusystem.shop.spawners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import me.trixkz.lifestealcore.advancedmenusystem.shop.GoBackButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopButton; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopItemSet; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class SpawnersMenu extends Menu { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List> shopItemSets = new ArrayList>(); + + public SpawnersMenu() { + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 1460000, 0, false)); // pig + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 1300000, 0, false)); // chicken + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 920000, 0, false)); // sheep + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 2000000, 0, false)); // cow + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 2750000, 0, false)); // zombie + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 4000000, 0, false)); // rabbit + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 8500000, 0, false)); // skeleton + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 6000000, 0, false)); // spider + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 12000000, 0, false)); // zombie pigman + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 18000000, 0, false)); // blaze + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 15000000, 0, false)); // creeper + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 10000000, 0, false)); // enderman + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 28000000, 0, false)); // iron golem + this.shopItemSets.add(new ShopItemSet<>(Material.SPAWNER, 0, 36000000, 0, false)); // guardian + } + + @Override + public String getTitle(Player player) { + return Utils.translate("&eClick a block to buy or sell..."); + } + + @Override + public int getSize() { + return 54; + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap(); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + this.shopItemSets.forEach((shopItemSet) -> { + if (atomicInteger.get() == 49) { + atomicInteger.addAndGet(1); + } + + buttons.put(atomicInteger.get(), new ShopButton(new ItemStack(shopItemSet.getMaterial(), 1), shopItemSet.getData(), shopItemSet.getBuyPrice(), shopItemSet.getSellPrice(), shopItemSet.getSellable())); + + atomicInteger.addAndGet(1); + }); + + buttons.put(49, new GoBackButton()); + + this.fillEmptySlots(buttons, new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(Utils.translate("")).durability(0).build()); + + return buttons; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/chatcolor/ColorSet.java b/src/main/java/me/trixkz/lifestealcore/chatcolor/ColorSet.java new file mode 100644 index 0000000..215d236 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/chatcolor/ColorSet.java @@ -0,0 +1,17 @@ +package me.trixkz.lifestealcore.chatcolor; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class ColorSet { + + private R red = null; + private G green = null; + private B blue = null; +} diff --git a/src/main/java/me/trixkz/lifestealcore/chatcolor/GradientColor.java b/src/main/java/me/trixkz/lifestealcore/chatcolor/GradientColor.java new file mode 100644 index 0000000..bb62dda --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/chatcolor/GradientColor.java @@ -0,0 +1,16 @@ +package me.trixkz.lifestealcore.chatcolor; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class GradientColor { + + private ColorSet colorCodeOne; + private ColorSet colorCodeTwo; +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/BaseCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/BaseCommand.java new file mode 100644 index 0000000..bbaaf64 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/BaseCommand.java @@ -0,0 +1,53 @@ +package me.trixkz.lifestealcore.commands; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public abstract class BaseCommand implements CommandExecutor { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private CommandInfo commandInfo; + + public BaseCommand() { + this.commandInfo = this.getClass().getDeclaredAnnotation(CommandInfo.class); + } + + public abstract void executeAs(Player player, String[] args); + + public abstract void executeAs(CommandSender sender, String[] args); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (!this.commandInfo.permission().equals("")) { + if (!sender.hasPermission(this.commandInfo.permission())) { + sender.sendMessage(Utils.translate(Constants.PREFIX + "No permission")); + + return true; + } + } + + if (this.commandInfo.player()) { + if (!(sender instanceof Player)) { + sender.sendMessage(Utils.translate(Constants.PREFIX + "You have to be a player to do this")); + + return true; + } + + Player player = (Player) sender; + + this.executeAs(player, args); + + return true; + } + + this.executeAs(sender, args); + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/me/trixkz/lifestealcore/commands/CommandInfo.java b/src/main/java/me/trixkz/lifestealcore/commands/CommandInfo.java new file mode 100644 index 0000000..f6d839c --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/CommandInfo.java @@ -0,0 +1,16 @@ +package me.trixkz.lifestealcore.commands; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface CommandInfo { + + String name(); + String permission(); + + boolean player(); +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/EnvoyCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/EnvoyCommand.java new file mode 100644 index 0000000..625ccae --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/EnvoyCommand.java @@ -0,0 +1,44 @@ +package me.trixkz.lifestealcore.commands; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.CustomLocation; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +@CommandInfo(name = "envoy", permission = "skyblock.admin", player = true) +public class EnvoyCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + FileConfiguration config = this.main.getEnvoysConfig().getConfig(); + + if (args.length == 0) { + player.sendMessage(Utils.translate("&cUsage:")); + player.sendMessage(Utils.translate(" &c/envoy start")); + player.sendMessage(Utils.translate(" &c/envoy addlocation")); + } else { + switch (args[0].toLowerCase()) { + case "start": + this.main.getEnvoyManager().startEnvoyEvent(); + + break; + case "addlocation": + this.main.getEnvoyManager().getEnvoyLocations().add(CustomLocation.fromBukkitLocation(player.getLocation())); + + player.sendMessage(ChatColor.GREEN + "Successfully added another location"); + + break; + } + } + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/LootboxCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/LootboxCommand.java new file mode 100644 index 0000000..706ccee --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/LootboxCommand.java @@ -0,0 +1,46 @@ +package me.trixkz.lifestealcore.commands; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "lootbox", permission = "lifestealcore.admin", player = true) +public class LootboxCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + if (args.length == 0) { + player.sendMessage(Utils.translate("&cUsage:")); + player.sendMessage(Utils.translate(" &c/lootbox give ")); + } else { + switch (args[0].toLowerCase()) { + case "give": + Player target = this.main.getServer().getPlayer(args[1]); + + if (target == null) { + return; + } + + if (!Utils.isNumeric(args[2])) { + return; + } + + int amount = Integer.parseInt(args[2]); + + target.getInventory().addItem(this.main.getLootboxManager().getLootboxItemStack(player, amount)); + player.sendMessage(Utils.translate(Constants.PREFIX + "You have given " + target.getName() + " " + amount + " lootbox" + (amount == 1 ? "" : "es"))); + + break; + } + } + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/SetHeartsCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/SetHeartsCommand.java new file mode 100644 index 0000000..560cf5d --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/SetHeartsCommand.java @@ -0,0 +1,41 @@ +package me.trixkz.lifestealcore.commands; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.UUID; + +@CommandInfo(name = "sethearts", permission = "lifestealcore.admin", player = false) +public class SetHeartsCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + Player target = this.main.getServer().getPlayer(args[0]); + + if (target == null) { + return; + } + + UUID targetUUID = target.getUniqueId(); + + PlayerData targetData = this.main.getPlayerDataManager().getPlayerData(targetUUID); + + double amount = Double.parseDouble(args[1]); + + target.setMaxHealth(amount); + + targetData.setHearts(target.getMaxHealth()); + + sender.sendMessage(Utils.translate("&eYou have set &d" + target.getName() + " &ehearts to &d" + target.getMaxHealth())); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/ShopCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/ShopCommand.java new file mode 100644 index 0000000..a44db97 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/ShopCommand.java @@ -0,0 +1,25 @@ +package me.trixkz.lifestealcore.commands; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.shop.ShopMenu; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "shop", permission = "", player = true) +public class ShopCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + new ShopMenu().openMenu(player); + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/SpawnCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/SpawnCommand.java new file mode 100644 index 0000000..81daaf7 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/SpawnCommand.java @@ -0,0 +1,21 @@ +package me.trixkz.lifestealcore.commands; + +import me.trixkz.lifestealcore.LifeStealCore; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "spawn", permission = "", player = true) +public class SpawnCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + this.main.getSpawnManager().getPlayers().put(player.getUniqueId(), 5); + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} \ No newline at end of file diff --git a/src/main/java/me/trixkz/lifestealcore/commands/clan/ClanCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/clan/ClanCommand.java new file mode 100644 index 0000000..f45ed83 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/clan/ClanCommand.java @@ -0,0 +1,141 @@ +package me.trixkz.lifestealcore.commands.clan; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.managers.clans.Clan; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.UUID; + +@CommandInfo(name = "clan", permission = "", player = true) +public class ClanCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private ArrayList message = new ArrayList(); + + @Override + public void executeAs(Player player, String[] args) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (args.length == 0) { + if (!this.main.getClanManager().isAClanMember(player)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.NO_CLAN_MESSAGE)); + + return; + } + + // to do + + // new IslandManageMenu(this.main.getPlayerMenuUtil(player)).open(player); + } else { + switch (args[0].toLowerCase()) { + case "help": + this.message.add(Utils.chatBar); + this.message.add("&dClan Commands &7(&fPlayer&7)"); + this.message.add(Utils.chatBar); + + // to do + + //this.message.add("&7⚫ &9/clan &7- &eOpen the clan manage menu"); + + this.message.add("&7⚫ &9/clan create &7- &eCreate your clan"); + this.message.add("&7⚫ &9/clan delete &7- &eDelete your clan"); + this.message.add("&7⚫ &9/clan join &7- &eJoin a player's clan that you have been invited to"); + this.message.add("&7⚫ &9/clan leave &7- &eLeave your clan"); + this.message.add("&7⚫ &9/clan invite &7- &eGive a player access to your clan"); + this.message.add("&7⚫ &9/clan uninvite &7- &eRemove a player's access to your clan"); + this.message.add("&7⚫ &9/clan top &7- &eOpen the top clans menu"); + this.message.add("&7⚫ &9/clan kick &7- &eKick a player from your clan"); + this.message.add("&7⚫ &9/clan level &7- &eLook at your clan's level"); + this.message.add("&7⚫ &9/clan setname &7- &eSet a name for your clan"); + this.message.add(Utils.chatBar); + + for (String string : this.message) { + player.sendMessage(Utils.translate(string)); + } + + this.message.clear(); + + break; + case "create": + this.main.getClanManager().makeClan(player); + + break; + case "delete": + this.main.getClanManager().deleteIsland(player); + + break; + case "join": + UUID joinTarget = this.main.getServer().getPlayer(args[1]).getUniqueId(); + + PlayerData joinTargetPlayerData = this.main.getPlayerDataManager().getPlayerData(joinTarget); + + this.main.getClanManager().joinClan(joinTargetPlayerData.getClanOwner(), player); + + break; + case "leave": + this.main.getClanManager().leaveClan(playerData.getClanOwner(), player); + + break; + case "invite": + Player inviteTarget = this.main.getServer().getPlayer(args[1]); + + this.main.getClanManager().createClanInvite(player, inviteTarget); + + break; + case "uninvite": + Utils.getOfflinePlayer(args[1], (offlinePlayer) -> { + this.main.getClanManager().removeClanInvite(player, offlinePlayer); + }); + + break; + case "top": + // new ClanTopMenu(this.main.getPlayerMenuUtil(player)).open(player); + + break; + case "kick": + Utils.getOfflinePlayer(args[1], (offlinePlayer) -> { + this.main.getClanManager().kickPlayerFromClan(player, offlinePlayer); + }); + + break; + case "level": + this.main.getClanManager().lookAtClanLevel(player); + + break; + case "setname": + if (!this.main.getClanManager().isOwner(player)) { + player.sendMessage(Utils.translate(Constants.PREFIX + "No permission, you have to be the owner of the island")); + + return; + } + + Clan clan = this.main.getClanManager().getClan(playerData.getClanOwner()); + + String name = args[1]; + + if (name == null) { + return; + } + + clan.setName(name); + clan.sendMessageToAllClanMembers(Utils.translate(Constants.CLAN_PREFIX + "The island's name is &9" + name)); + + break; + } + } + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/coins/CoinsCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/coins/CoinsCommand.java new file mode 100644 index 0000000..24c00fe --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/coins/CoinsCommand.java @@ -0,0 +1,151 @@ +package me.trixkz.lifestealcore.commands.coins; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import java.text.DecimalFormat; +import java.util.ArrayList; + +@CommandInfo(name = "coins", permission = "", player = true) +public class CoinsCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private ArrayList message = new ArrayList(); + + @Override + public void executeAs(Player player, String[] args) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + DecimalFormat decimalFormat = new DecimalFormat("##.##"); + + if (args.length == 0) { + player.sendMessage(Utils.translate(Constants.PREFIX + this.main.getMessagesConfig().getConfig().getString("COINS.BALANCE").replace("%coins%", decimalFormat.format(playerData.getCoins())))); + + return; + } else { + switch (args[0].toLowerCase()) { + case "help": + for (String string : this.main.getMessagesConfig().getConfig().getStringList("COINS.HELP_MESSAGE.PLAYER")) { + this.message.add(string.replace("%line%", Utils.chatBar)); + } + + if (player.hasPermission("skyblock.admin")) { + for (String string : this.main.getMessagesConfig().getConfig().getStringList("COINS.HELP_MESSAGE.ADMIN")) { + this.message.add(string.replace("%line%", Utils.chatBar)); + } + } + + for (String string : this.message) { + player.sendMessage(Utils.translate(string)); + } + + this.message.clear(); + + return; + case "pay": + Player payTarget = this.main.getServer().getPlayer(args[1]); + + if (payTarget == null) { + return; + } + + PlayerData payTargetPlayerData = this.main.getPlayerDataManager().getPlayerData(payTarget.getUniqueId()); + + if (!Utils.isNumeric(args[2])) { + return; + } + + double payAmount = Double.parseDouble(args[2]); + + if (playerData.getCoins() >= payAmount) { + playerData.setCoins(playerData.getCoins() - payAmount); + payTargetPlayerData.setCoins(payTargetPlayerData.getCoins() + payAmount); + } + + player.sendMessage(Utils.translate("&aPaid &a&l" + payTarget.getName() + "&a's &a&l" + decimalFormat.format(payAmount) + " &acoins")); + payTarget.sendMessage(Utils.translate("&a&l" + player.getName() + " &ahas paid you &a&l" + decimalFormat.format(payAmount) + " &acoins")); + + return; + case "set": + case "add": + case "remove": + if (!player.hasPermission("skyblock.admin")) { + player.sendMessage(Utils.translate("&cNo permission")); + + return; + } + + Player target = this.main.getServer().getPlayer(args[1]); + + if (target == null) { + return; + } + + PlayerData targetPlayerData = this.main.getPlayerDataManager().getPlayerData(target.getUniqueId()); + + if (!Utils.isNumeric(args[2])) { + return; + } + + double amount = Double.parseDouble(args[2]); + + switch (args[0].toLowerCase()) { + case "set": + targetPlayerData.setCoins(amount); + + player.sendMessage(Utils.translate("&aSet &a&l" + target.getName() + " &acoins balance to &a&l" + decimalFormat.format(amount))); + target.sendMessage(Utils.translate("&aCoins balance updated, you now have &a&l" + decimalFormat.format(targetPlayerData.getCoins()) + " &acoins")); + + break; + case "add": + targetPlayerData.setCoins(targetPlayerData.getCoins() + amount); + + player.sendMessage(Utils.translate("&aAdded &a&l" + decimalFormat.format(amount) + " &acoins to &a&l" + target.getName() + "&a's coins balance")); + target.sendMessage(Utils.translate("&aCoins balance updated, you now have &a&l" + decimalFormat.format(targetPlayerData.getCoins()) + " &acoins")); + + break; + case "remove": + if (targetPlayerData.getCoins() >= amount) { + targetPlayerData.setCoins(targetPlayerData.getCoins() - amount); + } + + player.sendMessage(Utils.translate("&aRemoved &a&l" + decimalFormat.format(amount) + " &acoins to &a&l" + target.getName() + "&a's coins balance")); + target.sendMessage(Utils.translate("&aCoins balance updated, you now have &a&l" + decimalFormat.format(targetPlayerData.getCoins()) + " &acoins")); + + break; + } + + break; + } + + if (!player.hasPermission("skyblock.admin")) { + player.sendMessage(Utils.translate("&cNo permission")); + + return; + } + + Player target = this.main.getServer().getPlayer(args[0]); + + if (target == null) { + return; + } + + PlayerData targetPlayerData = this.main.getPlayerDataManager().getPlayerData(target.getUniqueId()); + + player.sendMessage(Utils.translate("&a&l" + target.getName() + " &ahas &a&l" + decimalFormat.format(targetPlayerData.getCoins()) + " &acoins")); + } + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/koth/CreateCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/koth/CreateCommand.java new file mode 100644 index 0000000..f50f88c --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/koth/CreateCommand.java @@ -0,0 +1,37 @@ +package me.trixkz.lifestealcore.commands.koth; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.CustomLocation; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "koth", permission = "lifestealcore.admin", player = true) +public class CreateCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + String name = args[1]; + + if (name == null) { + return; + } + + KOTH koth = new KOTH(name, CustomLocation.fromBukkitLocation(player.getLocation())); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You have made a KOTH called &d" + name)); + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/koth/DisableCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/koth/DisableCommand.java new file mode 100644 index 0000000..bc10607 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/koth/DisableCommand.java @@ -0,0 +1,48 @@ +package me.trixkz.lifestealcore.commands.koth; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.managers.event.EventScheduledTime; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import java.util.Date; + +@CommandInfo(name = "koth", permission = "lifestealcore.admin", player = true) +public class DisableCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + String name = args[1]; + + if (name == null) { + return; + } + + KOTH koth = this.main.getKothManager().getKOTH(name); + + if (koth == null) { + return; + } + + koth.disable(); + + EventScheduledTime eventScheduledTime = EventScheduledTime.parse(new Date()); + + this.main.getKothManager().getKothSchedule().remove(eventScheduledTime); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You have disabled the KOTH called &d" + name)); + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/koth/EnableCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/koth/EnableCommand.java new file mode 100644 index 0000000..0b0e01f --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/koth/EnableCommand.java @@ -0,0 +1,50 @@ +package me.trixkz.lifestealcore.commands.koth; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "koth", permission = "lifestealcore.admin", player = true) +public class EnableCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + String name = args[1]; + + if (name == null) { + return; + } + + KOTH kothOne = this.main.getKothManager().getKOTH(name); + + if (kothOne == null) { + return; + } + + for (KOTH kothTwo : this.main.getKothManager().getKoths().values()) { + if (kothTwo.isActive()) { + player.sendMessage(Utils.translate(Constants.PREFIX + "&d" + kothTwo.getName() + " &eis active")); + + return; + } + } + + kothOne.enable(); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You have enabled the KOTH called &d" + name)); + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/koth/KOTHCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/koth/KOTHCommand.java new file mode 100644 index 0000000..7d875d0 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/koth/KOTHCommand.java @@ -0,0 +1,68 @@ +package me.trixkz.lifestealcore.commands.koth; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "koth", permission = "lifestealcore.admin", player = true) +public class KOTHCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + if (args.length == 0) { + + } else { + switch (args[0].toLowerCase()) { + case "create": + new CreateCommand().executeAs(player, args); + + break; + case "remove": + new RemoveCommand().executeAs(player, args); + + break; + case "enable": + new EnableCommand().executeAs(player, args); + + break; + case "disable": + new DisableCommand().executeAs(player, args); + + break; + case "setlocation": + new SetLocationCommand().executeAs(player, args); + + break; + case "settime": + new SetTimeCommand().executeAs(player, args); + + break; + case "setdistance": + new SetDistanceCommand().executeAs(player, args); + + break; + case "list": + break; + case "teleport": + new TeleportCommand().executeAs(player, args); + + break; + case "player": + new PlayerCommand().executeAs(player, args); + + break; + } + } + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/koth/PlayerCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/koth/PlayerCommand.java new file mode 100644 index 0000000..9396bc6 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/koth/PlayerCommand.java @@ -0,0 +1,48 @@ +package me.trixkz.lifestealcore.commands.koth; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "koth", permission = "lifestealcore.admin", player = true) +public class PlayerCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + String name = args[1]; + + if (name == null) { + return; + } + + KOTH koth = this.main.getKothManager().getKOTH(name); + + if (koth == null) { + return; + } + + if (koth.isActive()) { + if (koth.getPlayer() == null) { + player.sendMessage(Utils.translate(Constants.PREFIX + "There is no player capping the KOTH called &d" + koth.getName())); + } else { + player.sendMessage(Utils.translate(Constants.PREFIX + "&d" + this.main.getServer().getPlayer(koth.getPlayer()) + " &eis capping the KOTH called &d" + koth.getName())); + } + } else { + player.sendMessage(Utils.translate(Constants.PREFIX + "There is no KOTH active")); + } + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/koth/RemoveCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/koth/RemoveCommand.java new file mode 100644 index 0000000..ab59663 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/koth/RemoveCommand.java @@ -0,0 +1,36 @@ +package me.trixkz.lifestealcore.commands.koth; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "koth", permission = "lifestealcore.admin", player = true) +public class RemoveCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + String name = args[1]; + + if (name == null) { + return; + } + + this.main.getKothManager().removeKOTH(name); + this.main.getKothManager().saveKOTHs(); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You have removed the KOTH called &d" + name)); + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/koth/SetDistanceCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/koth/SetDistanceCommand.java new file mode 100644 index 0000000..425e3e4 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/koth/SetDistanceCommand.java @@ -0,0 +1,48 @@ +package me.trixkz.lifestealcore.commands.koth; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "koth", permission = "lifestealcore.admin", player = true) +public class SetDistanceCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + String name = args[1]; + + if (name == null) { + return; + } + + KOTH koth = this.main.getKothManager().getKOTH(name); + + if (koth == null) { + return; + } + + if (!Utils.isNumeric(args[2])) { + return; + } + + int distance = Integer.parseInt(args[2]); + + koth.setDistance(distance); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You have set the distance to &d" + distance + " &e for the KOTH called &d" + name)); + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/koth/SetLocationCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/koth/SetLocationCommand.java new file mode 100644 index 0000000..d29b4ec --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/koth/SetLocationCommand.java @@ -0,0 +1,43 @@ +package me.trixkz.lifestealcore.commands.koth; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.CustomLocation; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "koth", permission = "lifestealcore.admin", player = true) +public class SetLocationCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + String name = args[1]; + + if (name == null) { + return; + } + + KOTH koth = this.main.getKothManager().getKOTH(name); + + if (koth == null) { + return; + } + + koth.setLocation(CustomLocation.fromBukkitLocation(player.getLocation())); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You have set the location for the KOTH called &d" + name)); + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/koth/SetTimeCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/koth/SetTimeCommand.java new file mode 100644 index 0000000..a01afa2 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/koth/SetTimeCommand.java @@ -0,0 +1,48 @@ +package me.trixkz.lifestealcore.commands.koth; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "koth", permission = "lifestealcore.admin", player = true) +public class SetTimeCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + String name = args[1]; + + if (name == null) { + return; + } + + KOTH koth = this.main.getKothManager().getKOTH(name); + + if (koth == null) { + return; + } + + if (!Utils.isNumeric(args[2])) { + return; + } + + int time = Integer.parseInt(args[2]); + + koth.setTime(time); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You have set the time to &d" + time + " &e for the KOTH called &d" + name)); + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/koth/TeleportCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/koth/TeleportCommand.java new file mode 100644 index 0000000..3a941b1 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/koth/TeleportCommand.java @@ -0,0 +1,41 @@ +package me.trixkz.lifestealcore.commands.koth; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo(name = "koth", permission = "lifestealcore.admin", player = true) +public class TeleportCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + String name = args[1]; + + if (name == null) { + return; + } + + KOTH koth = this.main.getKothManager().getKOTH(name); + + if (koth == null) { + return; + } + + player.teleport(koth.getCustomLocation().toBukkitLocation()); + player.sendMessage(Utils.translate(Constants.PREFIX + "You have teleported to the KOTH called &d" + name)); + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/setspawn/MaxCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/setspawn/MaxCommand.java new file mode 100644 index 0000000..f049578 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/setspawn/MaxCommand.java @@ -0,0 +1,36 @@ +package me.trixkz.lifestealcore.commands.setspawn; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.utils.CustomLocation; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +@CommandInfo(name = "setspawn", permission = "lifestealcore.admin", player = true) +public class MaxCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + this.main.getSpawnManager().setSpawnLocation(CustomLocation.fromBukkitLocation(player.getLocation())); + this.saveLocation(player, "spawn.max"); + + player.sendMessage(ChatColor.GREEN + "Successfully set the max location."); + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } + + private void saveLocation(Player player, String location) { + FileConfiguration config = this.main.getSettingsConfig().getConfig(); + config.set(location, CustomLocation.locationToString(CustomLocation.fromBukkitLocation(player.getLocation()))); + + this.main.getSettingsConfig().save(); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/setspawn/MinCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/setspawn/MinCommand.java new file mode 100644 index 0000000..a22ba3c --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/setspawn/MinCommand.java @@ -0,0 +1,36 @@ +package me.trixkz.lifestealcore.commands.setspawn; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.utils.CustomLocation; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +@CommandInfo(name = "setspawn", permission = "lifestealcore.admin", player = true) +public class MinCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + this.main.getSpawnManager().setSpawnLocation(CustomLocation.fromBukkitLocation(player.getLocation())); + this.saveLocation(player, "spawn.min"); + + player.sendMessage(ChatColor.GREEN + "Successfully set the min location."); + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } + + private void saveLocation(Player player, String location) { + FileConfiguration config = this.main.getSettingsConfig().getConfig(); + config.set(location, CustomLocation.locationToString(CustomLocation.fromBukkitLocation(player.getLocation()))); + + this.main.getSettingsConfig().save(); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/setspawn/SetSpawnCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/setspawn/SetSpawnCommand.java new file mode 100644 index 0000000..acdffa1 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/setspawn/SetSpawnCommand.java @@ -0,0 +1,84 @@ +package me.trixkz.lifestealcore.commands.setspawn; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.utils.CustomLocation; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +@CommandInfo(name = "setspawn", permission = "lifestealcore.admin", player = true) +public class SetSpawnCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + FileConfiguration config = this.main.getSettingsConfig().getConfig(); + + if (args.length == 0) { + player.sendMessage(Utils.translate("&cUsage:")); + player.sendMessage(Utils.translate(" &c/setspawn spawn")); + player.sendMessage(Utils.translate(" &c/setspawn min")); + player.sendMessage(Utils.translate(" &c/setspawn max")); + player.sendMessage(Utils.translate(" &c/setspawn holograms")); + + return; + } + + switch (args[0].toLowerCase()) { + case "spawn": + new SpawnCommand().executeAs(player, args); + + break; + case "min": + new MinCommand().executeAs(player, args); + + break; + case "max": + new MaxCommand().executeAs(player, args); + + break; + case "cornermin": + this.main.getSpawnManager().setSpawnLocation(CustomLocation.fromBukkitLocation(player.getLocation())); + + config.set("corner.min", CustomLocation.locationToString(CustomLocation.fromBukkitLocation(player.getLocation()))); + + this.main.getSettingsConfig().save(); + + player.sendMessage(ChatColor.GREEN + "Successfully set the corner min location."); + + break; + case "cornermax": + this.main.getSpawnManager().setSpawnLocation(CustomLocation.fromBukkitLocation(player.getLocation())); + + config.set("corner.max", CustomLocation.locationToString(CustomLocation.fromBukkitLocation(player.getLocation()))); + + this.main.getSettingsConfig().save(); + + player.sendMessage(ChatColor.GREEN + "Successfully set the corner max location."); + + break; + case "holograms": + this.main.getSpawnManager().setSpawnLocation(CustomLocation.fromBukkitLocation(player.getLocation())); + + config.set("holograms.location", CustomLocation.locationToString(CustomLocation.fromBukkitLocation(player.getLocation()))); + + this.main.getSettingsConfig().save(); + + player.sendMessage(ChatColor.GREEN + "Successfully set the holograms location"); + + break; + } + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/setspawn/SpawnCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/setspawn/SpawnCommand.java new file mode 100644 index 0000000..193084e --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/setspawn/SpawnCommand.java @@ -0,0 +1,36 @@ +package me.trixkz.lifestealcore.commands.setspawn; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.utils.CustomLocation; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +@CommandInfo(name = "setspawn", permission = "lifestealcore.admin", player = true) +public class SpawnCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public void executeAs(Player player, String[] args) { + this.main.getSpawnManager().setSpawnLocation(CustomLocation.fromBukkitLocation(player.getLocation())); + this.saveLocation(player, "spawn.location"); + + player.sendMessage(ChatColor.GREEN + "Successfully set the spawn location."); + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } + + private void saveLocation(Player player, String location) { + FileConfiguration config = this.main.getSettingsConfig().getConfig(); + config.set(location, CustomLocation.locationToString(CustomLocation.fromBukkitLocation(player.getLocation()))); + + this.main.getSettingsConfig().save(); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/commands/tokens/TokensCommand.java b/src/main/java/me/trixkz/lifestealcore/commands/tokens/TokensCommand.java new file mode 100644 index 0000000..4a60de4 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/commands/tokens/TokensCommand.java @@ -0,0 +1,155 @@ +package me.trixkz.lifestealcore.commands.tokens; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.BaseCommand; +import me.trixkz.lifestealcore.commands.CommandInfo; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import java.util.ArrayList; + +@CommandInfo(name = "tokens", permission = "", player = true) +public class TokensCommand extends BaseCommand { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private ArrayList message = new ArrayList(); + + @Override + public void executeAs(Player player, String[] args) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (args.length == 0) { + player.sendMessage(Utils.translate("&dTokens: &f" + playerData.getTokens())); + + return; + } else { + switch (args[0].toLowerCase()) { + case "help": + this.message.add(Utils.chatBar); + this.message.add("&dTokens Commands &7(&fPlayer&7)"); + this.message.add(Utils.chatBar); + this.message.add("&7⚫ &9/tokens &7- &eLook at your tokens balance"); + this.message.add("&7⚫ &9/tokens pay &7- &eSend the specified amount of tokens to the specified player"); + + if (player.hasPermission("skyblock.admin")) { + this.message.add(Utils.chatBar); + this.message.add("&dTokens Commands &7(&fAdmin&7)"); + this.message.add(Utils.chatBar); + this.message.add("&7⚫ &9/tokens &7- &eLook at the specified player's tokens balance"); + this.message.add("&7⚫ &9/tokens set &7- &eSet the specified amount of tokens to the specified player"); + this.message.add("&7⚫ &9/tokens add &7- &eAdd the specified amount of tokens to the specified player"); + this.message.add("&7⚫ &9/tokens remove &7- &eRemove the specified amount of tokens to the specified player"); + } + + this.message.add(Utils.chatBar); + + for (String string : this.message) { + player.sendMessage(Utils.translate(string)); + } + + this.message.clear(); + + return; + case "pay": + Player payTarget = this.main.getServer().getPlayer(args[1]); + + if (payTarget == null) { + return; + } + + PlayerData payTargetPlayerData = this.main.getPlayerDataManager().getPlayerData(payTarget.getUniqueId()); + + if (!Utils.isNumeric(args[2])) { + return; + } + + int payAmount = Integer.parseInt(args[2]); + + if (playerData.getTokens() >= payAmount) { + playerData.setTokens(playerData.getTokens() - payAmount); + payTargetPlayerData.setTokens(payTargetPlayerData.getTokens() + payAmount); + } + + player.sendMessage(Utils.translate("&aPaid &a&l" + payTarget.getName() + "&a's &a&l" + payAmount + " &atokens")); + payTarget.sendMessage(Utils.translate("&a&l" + player.getName() + " &ahas paid you &a&l" + payAmount + " &atokens")); + + return; + case "set": + case "add": + case "remove": + if (!player.hasPermission("skyblock.admin")) { + player.sendMessage(Utils.translate("&cNo permission")); + + return; + } + + Player target = this.main.getServer().getPlayer(args[1]); + + if (target == null) { + return; + } + + PlayerData targetPlayerData = this.main.getPlayerDataManager().getPlayerData(target.getUniqueId()); + + if (!Utils.isNumeric(args[2])) { + return; + } + + int amount = Integer.parseInt(args[2]); + + switch (args[0].toLowerCase()) { + case "set": + targetPlayerData.setTokens(amount); + + player.sendMessage(Utils.translate("&aSet &a&l" + target.getName() + " &atokens balance to &a&l" + amount)); + target.sendMessage(Utils.translate("&aTokens balance updated, you now have &a&l" + targetPlayerData.getTokens() + " &atokens")); + + break; + case "add": + targetPlayerData.setTokens(targetPlayerData.getTokens() + amount); + + player.sendMessage(Utils.translate("&aAdded &a&l" + amount + " &atokens to &a&l" + target.getName() + "&a's tokens balance")); + target.sendMessage(Utils.translate("&aTokens balance updated, you now have &a&l" + targetPlayerData.getTokens() + " &atokens")); + + break; + case "remove": + if (targetPlayerData.getTokens() >= amount) { + targetPlayerData.setTokens(targetPlayerData.getTokens() - amount); + } + + player.sendMessage(Utils.translate("&aRemoved &a&l" + amount + " &atokens to &a&l" + target.getName() + "&a's tokens balance")); + target.sendMessage(Utils.translate("&aTokens balance updated, you now have &a&l" + targetPlayerData.getTokens() + " &atokens")); + + break; + } + + break; + } + + if (!player.hasPermission("skyblock.admin")) { + player.sendMessage(Utils.translate("&cNo permission")); + + return; + } + + Player target = this.main.getServer().getPlayer(args[0]); + + if (target == null) { + return; + } + + PlayerData targetPlayerData = this.main.getPlayerDataManager().getPlayerData(target.getUniqueId()); + + player.sendMessage(Utils.translate("&a&l" + target.getName() + " &ahas &a&l" + targetPlayerData.getTokens() + " &atokens")); + } + + return; + } + + @Override + public void executeAs(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/events/KOTHCapLostEvent.java b/src/main/java/me/trixkz/lifestealcore/events/KOTHCapLostEvent.java new file mode 100644 index 0000000..174d632 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/events/KOTHCapLostEvent.java @@ -0,0 +1,29 @@ +package me.trixkz.lifestealcore.events; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class KOTHCapLostEvent extends Event { + + private static HandlerList handlersList = new HandlerList(); + + private KOTH koth; + + @Override + public HandlerList getHandlers() { + return handlersList; + } + + public static HandlerList getHandlerList() { + return handlersList; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/events/KOTHCapTickEvent.java b/src/main/java/me/trixkz/lifestealcore/events/KOTHCapTickEvent.java new file mode 100644 index 0000000..00e8856 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/events/KOTHCapTickEvent.java @@ -0,0 +1,29 @@ +package me.trixkz.lifestealcore.events; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class KOTHCapTickEvent extends Event { + + private static HandlerList handlersList = new HandlerList(); + + private KOTH koth; + + @Override + public HandlerList getHandlers() { + return handlersList; + } + + public static HandlerList getHandlerList() { + return handlersList; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/events/KOTHCappedEvent.java b/src/main/java/me/trixkz/lifestealcore/events/KOTHCappedEvent.java new file mode 100644 index 0000000..6b1fbe0 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/events/KOTHCappedEvent.java @@ -0,0 +1,35 @@ +package me.trixkz.lifestealcore.events; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +@Getter +@Setter +public class KOTHCappedEvent extends PlayerEvent implements Cancellable { + + private static HandlerList handlersList = new HandlerList(); + + private KOTH koth; + + private boolean cancelled; + + public KOTHCappedEvent(Player player, KOTH koth) { + super(player); + + this.koth = koth; + } + + @Override + public HandlerList getHandlers() { + return handlersList; + } + + public static HandlerList getHandlerList() { + return handlersList; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/events/KOTHDisabledEvent.java b/src/main/java/me/trixkz/lifestealcore/events/KOTHDisabledEvent.java new file mode 100644 index 0000000..c7b81c2 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/events/KOTHDisabledEvent.java @@ -0,0 +1,29 @@ +package me.trixkz.lifestealcore.events; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class KOTHDisabledEvent extends Event { + + private static HandlerList handlersList = new HandlerList(); + + private KOTH koth; + + @Override + public HandlerList getHandlers() { + return handlersList; + } + + public static HandlerList getHandlerList() { + return handlersList; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/events/KOTHEnabledEvent.java b/src/main/java/me/trixkz/lifestealcore/events/KOTHEnabledEvent.java new file mode 100644 index 0000000..62e4f9d --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/events/KOTHEnabledEvent.java @@ -0,0 +1,29 @@ +package me.trixkz.lifestealcore.events; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class KOTHEnabledEvent extends Event { + + private static HandlerList handlersList = new HandlerList(); + + private KOTH koth; + + @Override + public HandlerList getHandlers() { + return handlersList; + } + + public static HandlerList getHandlerList() { + return handlersList; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/BlockBreakListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/BlockBreakListener.java new file mode 100644 index 0000000..6d0c411 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/BlockBreakListener.java @@ -0,0 +1,25 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.playerdata.PlayerState; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; + +public class BlockBreakListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler(ignoreCancelled = true) + public void onBlockBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData.getPlayerState() == PlayerState.SPAWN) { + // event.setCancelled(true); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/BlockExplodeListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/BlockExplodeListener.java new file mode 100644 index 0000000..1f55450 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/BlockExplodeListener.java @@ -0,0 +1,23 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockExplodeEvent; + +public class BlockExplodeListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler(ignoreCancelled = true) + public void onBlockExplode(BlockExplodeEvent event) { + Block blockOne = event.getBlock(); + + // change to work in the spawn of the server + +// this.main.getIslandManager().getIslandByLocation(blockOne.getLocation()).ifPresent((island) -> { +// event.blockList().removeIf(blockTwo -> !island.isLocationInIsland(blockTwo.getLocation())); +// }); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/BlockPlaceListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/BlockPlaceListener.java new file mode 100644 index 0000000..bac18c1 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/BlockPlaceListener.java @@ -0,0 +1,25 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.playerdata.PlayerState; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; + +public class BlockPlaceListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler(ignoreCancelled = true) + public void onBlockPlace(BlockPlaceEvent event) { + Player player = event.getPlayer(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData.getPlayerState() == PlayerState.SPAWN) { + // event.setCancelled(true); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/BlockSpreadListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/BlockSpreadListener.java new file mode 100644 index 0000000..1919e3b --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/BlockSpreadListener.java @@ -0,0 +1,27 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockSpreadEvent; + +public class BlockSpreadListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler(ignoreCancelled = true) + public void onBlockSpread(BlockSpreadEvent event) { + Block block = event.getBlock(); + + // change to work in the spawn of the server + +// this.main.getIslandManager().getIslandByLocation(block.getLocation()).ifPresent((island) -> { +// if (event.getSource().getType() != Material.FIRE) { +// return; +// } +// +// event.setCancelled(true); +// }); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/BucketListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/BucketListener.java new file mode 100644 index 0000000..6ad53b4 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/BucketListener.java @@ -0,0 +1,39 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.playerdata.PlayerState; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; + +public class BucketListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler(ignoreCancelled = true) + public void onBucketFill(PlayerBucketFillEvent event) { + this.getBucketEvent(event); + } + + @EventHandler(ignoreCancelled = true) + public void onBucketEmpty(PlayerBucketEmptyEvent event) { + this.getBucketEvent(event); + } + + public void getBucketEvent(PlayerBucketEvent event) { + Player player = event.getPlayer(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + Block block = event.getBlockClicked(); + + if (playerData.getPlayerState() == PlayerState.SPAWN) { + event.setCancelled(true); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/ButtonListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/ButtonListener.java new file mode 100644 index 0000000..1fe8d72 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/ButtonListener.java @@ -0,0 +1,88 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.advancedmenusystem.Button; +import me.trixkz.lifestealcore.advancedmenusystem.Menu; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; + +public class ButtonListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler(priority = EventPriority.HIGHEST) + public void onButtonPress(InventoryClickEvent event) { + Player player = (Player) event.getWhoClicked(); + + Menu menu = Menu.currentlyOpenedMenus.get(player.getName()); + + if (menu != null) { + if (event.getSlot() != event.getRawSlot()) { + if ((event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT)) { + event.setCancelled(true); + } + + return; + } + + if (menu.getButtons().containsKey(event.getSlot())) { + Button button = menu.getButtons().get(event.getSlot()); + + boolean cancel = button.shouldCancel(player, event.getSlot(), event.getClick()); + + if (!cancel && (event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT)) { + event.setCancelled(true); + + if (event.getCurrentItem() != null) { + player.getInventory().addItem(event.getCurrentItem()); + } + } else { + event.setCancelled(cancel); + } + + button.clicked(player, event.getSlot(), event.getClick(), event.getHotbarButton()); + + if (Menu.currentlyOpenedMenus.containsKey(player.getName())) { + Menu newMenu = Menu.currentlyOpenedMenus.get(player.getName()); + + if (newMenu == menu && menu.isUpdateAfterClick()) { + menu.setClosedByMenu(true); + + newMenu.openMenu(player); + } + } else if (button.shouldUpdate(player, event.getSlot(), event.getClick())) { + menu.setClosedByMenu(true); + menu.openMenu(player); + } + + if (event.isCancelled()) { + Bukkit.getScheduler().runTaskLater(this.main, player::updateInventory, 1L); + } + } else { + if ((event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT || event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) || event.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD) || event.getAction().equals(InventoryAction.HOTBAR_SWAP))) { + event.setCancelled(true); + } + } + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void onInventoryClose(InventoryCloseEvent event) { + Player player = (Player) event.getPlayer(); + + Menu menu = Menu.currentlyOpenedMenus.get(player.getName()); + + if (menu != null) { + menu.onClose(player); + + Menu.currentlyOpenedMenus.remove(player.getName()); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/ClanListeners.java b/src/main/java/me/trixkz/lifestealcore/listeners/ClanListeners.java new file mode 100644 index 0000000..1dd70de --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/ClanListeners.java @@ -0,0 +1,116 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.managers.clans.Clan; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import java.util.UUID; + +public class ClanListeners implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + event.setJoinMessage(null); + + Player player = event.getPlayer(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + player.setMaxHealth(playerData.getHearts()); + + if (playerData.getClanOwner() == null) { + return; + } + + Clan clan = this.main.getClanManager().getClan(playerData.getClanOwner()); + + if (clan == null) { + this.main.getClanManager().loadClan(player); + + return; + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + event.setQuitMessage(null); + + Player player = event.getPlayer(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData.getClanOwner() == null) { + return; + } + + Clan clan = this.main.getClanManager().getClan(playerData.getClanOwner()); + + if (clan == null) { + return; + } + + int playersOnline = 0; + + Player owner = this.main.getServer().getPlayer(clan.getOwner()); + + if (owner != null) { + playersOnline++; + } + + for (UUID uuid : this.main.getClanManager().getClan(playerData.getClanOwner()).getPlayersAdded()) { + Player playerAdded = this.main.getServer().getPlayer(uuid); + + if (playerAdded != null) { + playersOnline++; + } + } + + if (playersOnline == 1) { + this.main.getClanManager().saveClan(player); + } + } + + @EventHandler + public void onPlayerKick(PlayerKickEvent event) { + Player player = event.getPlayer(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData.getClanOwner() == null) { + return; + } + + Clan clan = this.main.getClanManager().getClan(playerData.getClanOwner()); + + if (clan == null) { + return; + } + + int playersOnline = 0; + + Player owner = this.main.getServer().getPlayer(clan.getOwner()); + + if (owner != null) { + playersOnline++; + } + + for (UUID uuid : this.main.getClanManager().getClan(playerData.getClanOwner()).getPlayersAdded()) { + Player playerAdded = this.main.getServer().getPlayer(uuid); + + if (playerAdded != null) { + playersOnline++; + } + } + + if (playersOnline == 1) { + this.main.getClanManager().saveClan(player); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/EntityChangeBlockListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/EntityChangeBlockListener.java new file mode 100644 index 0000000..b35d076 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/EntityChangeBlockListener.java @@ -0,0 +1,25 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityChangeBlockEvent; + +public class EntityChangeBlockListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler(ignoreCancelled = true) + public void onEntityChangeBlock(EntityChangeBlockEvent event) { + Block block = event.getBlock(); + + // change to work in the spawn of the server + +// this.main.getIslandManager().getIslandByLocation(block.getLocation()).ifPresent((island) -> { +// if (event.getEntityType() == EntityType.ENDERMAN) { +// event.setCancelled(true); +// } +// }); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/EntityDamageByEntityListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/EntityDamageByEntityListener.java new file mode 100644 index 0000000..8028000 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/EntityDamageByEntityListener.java @@ -0,0 +1,53 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.managers.clans.Clan; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +public class EntityDamageByEntityListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity damager = event.getDamager(); + Entity entity = event.getEntity(); + + if (!(damager instanceof Player)) { + return; + } + + if (!(entity instanceof Player)) { + return; + } + + Player player = (Player) damager; + Player target = (Player) entity; + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + PlayerData targetData = this.main.getPlayerDataManager().getPlayerData(target.getUniqueId()); + + if (playerData.getClanOwner() == null) { + return; + } + + if (targetData.getClanOwner() == null) { + return; + } + + Clan clan = this.main.getClanManager().getClan(playerData.getClanOwner()); + + if (clan.getOwner().equals(target.getUniqueId()) || clan.getPlayersAdded().contains(target.getUniqueId())) { + event.setCancelled(true); + + player.sendMessage(Utils.translate(Constants.PREFIX + "&9" + target.getName() + " &eis apart of your clan")); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/EntityDeathListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/EntityDeathListener.java new file mode 100644 index 0000000..2619c47 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/EntityDeathListener.java @@ -0,0 +1,27 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDeathEvent; + +public class EntityDeathListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler(ignoreCancelled = true) + public void onEntityDeath(EntityDeathEvent event) { + Entity entity = event.getEntity(); + + Player player = event.getEntity().getKiller(); + + if (player == null) { + return; + } + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/EventListeners.java b/src/main/java/me/trixkz/lifestealcore/listeners/EventListeners.java new file mode 100644 index 0000000..ef8addd --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/EventListeners.java @@ -0,0 +1,162 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.events.KOTHCapLostEvent; +import me.trixkz.lifestealcore.events.KOTHCappedEvent; +import me.trixkz.lifestealcore.events.KOTHDisabledEvent; +import me.trixkz.lifestealcore.events.KOTHEnabledEvent; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.scheduler.BukkitRunnable; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class EventListeners implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler + public void onEventEnabled(KOTHEnabledEvent event) { + if (event.getKoth().isHidden()) { + return; + } + + KOTH koth = event.getKoth(); + + String[] messageOne = null; + + switch (event.getKoth().getName()) { + default: + String location = ""; + String world = ""; + String eventType = ""; + + location = Utils.translate("&8(" + koth.getCustomLocation().toBukkitLocation().getBlockX() + "&8, " + koth.getCustomLocation().toBukkitLocation().getBlockZ() + "&8)"); + world = this.getWorldName(koth.getWorld()); + eventType = "KOTH"; + + messageOne = new String[]{ + Utils.translate("&8███████"), + Utils.translate("&8█&e█&8███&e█&8█"), + Utils.translate("&8█&e█&8██&e█&8██"), + Utils.translate("&8█&e███&8███ &d" + event.getKoth().getName() + " " + eventType), + Utils.translate("&8█&e█&8██&e█&8██"), + Utils.translate("&8█&e█&8███&e█&8█"), + Utils.translate("&8█&e█&8███&e█&8█"), + Utils.translate("&8███████") + }; + + break; + } + + String[] messageTwo = messageOne; + + this.main.getServer().getScheduler().runTaskAsynchronously(this.main, new BukkitRunnable() { + @Override + public void run() { + for (Player player : main.getServer().getOnlinePlayers()) { + player.sendMessage(messageTwo); + } + } + }); + } + + @EventHandler + public void onEventDisabled(KOTHDisabledEvent event) { + + } + + @EventHandler + public void onEventCapped(KOTHCappedEvent event) { + Player player = event.getPlayer(); + + if (event.getKoth().isHidden()) { + return; + } + + KOTH koth = event.getKoth(); + + String[] messageOne = null; + String[] fillerMessage = {"", "", "", "", "", "", "", "", "", ""}; + + messageOne = new String[]{ + Utils.translate("&8[&9KOTH&8] &d" + koth.getName() + " &ehas been capped by &d" + player.getName()), + Utils.translate("&8[&9KOTH&8] &eAwarded a &dKOTH crate key &eto" + player.getName()) + }; + + this.main.getServer().dispatchCommand(this.main.getServer().getConsoleSender(), "crate givekey " + player.getName() + " koth 1"); + + ItemStack itemStack = this.getKOTHCappedSign(player, koth); + + player.getInventory().addItem(itemStack); + + if (!player.getInventory().contains(itemStack)) { + player.getWorld().dropItemNaturally(player.getLocation(), itemStack); + } + + String[] messageTwo = messageOne; + + this.main.getServer().getScheduler().runTaskAsynchronously(this.main, new BukkitRunnable() { + @Override + public void run() { + for (Player player : main.getServer().getOnlinePlayers()) { + player.sendMessage(fillerMessage); + player.sendMessage(messageTwo); + } + } + }); + } + + @EventHandler + public void onKOTHCapLost(KOTHCapLostEvent event) { + KOTH koth = event.getKoth(); + + if (koth.getRemainingTime() <= (koth.getTime() - 30)) { + this.main.getServer().broadcastMessage(Utils.translate("&8[&9KOTH&8] &eCap of &d" + koth.getName() + " &ehas been lost")); + } + } + + public String getWorldName(String world) { + switch (world) { + case "world": + return "Overworld"; + case "world_the_end": + return "The end"; + case "world_nether": + return "The nether"; + } + + return world; + } + + public ItemStack getKOTHCappedSign(Player player, KOTH koth) { + ItemStack itemStack = new ItemStack(Material.OAK_SIGN); + + ItemMeta itemMeta = itemStack.getItemMeta(); + itemMeta.setDisplayName(Utils.translate("&eKOTH Capped sign")); + + List lore = new ArrayList(); + + DateFormat dateFormat = new SimpleDateFormat("M/d HH:mm:ss"); + + lore.add(Utils.translate("&d" + koth.getName())); + lore.add(Utils.translate("&eCapped by")); + lore.add(Utils.translate("&d" + player.getName())); + lore.add(Utils.translate(dateFormat.format(new Date()).replace(" AM", "").replace(" PM", ""))); + + itemMeta.setLore(lore); + + itemStack.setItemMeta(itemMeta); + + return itemStack; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/KOTHListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/KOTHListener.java new file mode 100644 index 0000000..0dd6493 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/KOTHListener.java @@ -0,0 +1,23 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.events.KOTHCapTickEvent; +import me.trixkz.lifestealcore.managers.koth.KOTH; +import me.trixkz.lifestealcore.utils.TimeUtils; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class KOTHListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler + public void onEventCapTick(KOTHCapTickEvent event) { + KOTH koth = event.getKoth(); + + if (koth.getRemainingTime() % 180 == 0 && koth.getRemainingTime() <= (koth.getTime() - 30)) { + this.main.getServer().broadcastMessage(Utils.translate("&8[&9KOTH&8] &eSomeone is trying to cap &d" + koth.getName() + " &8(&d" + TimeUtils.formatIntoMMSS(koth.getRemainingTime()) + "&8)")); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/MenuListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/MenuListener.java new file mode 100644 index 0000000..6bb867e --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/MenuListener.java @@ -0,0 +1,26 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.normalmenusystem.Menu; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.InventoryHolder; + +public class MenuListener implements Listener { + + @EventHandler + public void onMenuClick(InventoryClickEvent event) { + InventoryHolder holder = event.getInventory().getHolder(); + + if (holder instanceof Menu) { + event.setCancelled(true); + + if (event.getCurrentItem() == null) { + return; + } + + Menu menu = (Menu) holder; + menu.handleMenu(event); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/PlayerDataListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/PlayerDataListener.java new file mode 100644 index 0000000..d2b93b8 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/PlayerDataListener.java @@ -0,0 +1,74 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerLoginEvent; + +public class PlayerDataListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(event.getUniqueId()); + + if (playerData.getDeathBanTime() == 0) { + return; + } + + if (((playerData.getDeathBanTime() + playerData.getDeathBanTimeAddedAt()) - System.currentTimeMillis()) <= 0) { + playerData.setDeathBanTime(0); + + return; + } + + event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); + event.setKickMessage(Utils.translate("&cYou have been death banned for &c&l" + Utils.makeTimeReadable(((playerData.getDeathBanTime() + playerData.getDeathBanTimeAddedAt()) - System.currentTimeMillis())))); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerLogin(PlayerLoginEvent event) { + PlayerData playerData = this.main.getPlayerDataManager().getOrCreate(event.getPlayer().getUniqueId()); + + if (playerData == null) { + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + event.setKickMessage("§cAn error has occurred while loading your profile. Please reconnect."); + + return; + } + + if (!playerData.isLoaded()) { + this.main.getPlayerDataManager().savePlayerData(playerData); + + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + event.setKickMessage("§cAn error has occurred while loading your profile. Please reconnect."); + } + } + + @EventHandler + public void onPlayerKick(PlayerKickEvent event) { + Player player = event.getPlayer(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + this.handleLeave(player); + this.handleDataSave(playerData); + } + + private void handleLeave(Player player) { + + } + + private void handleDataSave(PlayerData playerData) { + if (playerData != null) { + this.main.getPlayerDataManager().deletePlayer(playerData.getUniqueId()); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/PlayerDeathListener.java b/src/main/java/me/trixkz/lifestealcore/listeners/PlayerDeathListener.java new file mode 100644 index 0000000..c69a550 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/PlayerDeathListener.java @@ -0,0 +1,99 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.managers.killstreaks.Killstreak; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.playerdata.PlayerState; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; + +public class PlayerDeathListener implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent event) { + Player player = event.getPlayer(); + Player killer = event.getEntity().getKiller(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData == null) { + this.main.getLogger().warning(player.getName() + "'s player data is null"); + + return; + } + + if (killer != null) { + PlayerData killerData = this.main.getPlayerDataManager().getPlayerData(killer.getUniqueId()); + + this.main.getServer().broadcastMessage(Utils.translate("&9" + player.getName() + " &ewas killed by &9" + killer.getName())); + + playerData.setPlayerState(PlayerState.SPAWN); + playerData.setDeaths(playerData.getDeaths() + 1); + killerData.setKills(killerData.getKills() + 1); + killerData.setCoins(killerData.getCoins() + this.main.getSettingsConfig().getConfig().getInt("COINS-GIVEN-PER-KILL")); + + if (player.getMaxHealth() <= 2) { + player.setMaxHealth(20); + + long deathBanTime = Utils.parseTime("2d"); + +// for (String string : this.main.getSettingsConfig().getConfig().getConfigurationSection("DEATH-BAN-TIMES")) { +// +// } +// +// for (int i = 0; i < this.main.getSettingsConfig().getConfig().getConfigurationSection("DEATH-BAN-TIMES").getKeys(false).size(); i++) { +// +// } + + playerData.setHearts(player.getMaxHealth()); + playerData.setCurrentKillstreak(0); + playerData.setDeathBanTime(deathBanTime); + playerData.setDeathBanTimeAddedAt(System.currentTimeMillis()); + player.kickPlayer(Utils.translate("&cYou have been death banned for &c&l" + Utils.makeTimeReadable(((playerData.getDeathBanTime() + playerData.getDeathBanTimeAddedAt()) - System.currentTimeMillis())))); + } else { + player.setMaxHealth(player.getMaxHealth() - 2); + } + + killer.setMaxHealth(killer.getMaxHealth() + 2); + + playerData.setHearts(player.getMaxHealth()); + killerData.setHearts(killer.getMaxHealth()); + + playerData.setCurrentKillstreak(0); + killerData.setCurrentKillstreak(killerData.getCurrentKillstreak() + 1); + + if (playerData.getBounty() > 0) { + killerData.setCoins(killerData.getCoins() + playerData.getBounty()); + + this.main.getServer().broadcastMessage(Utils.translate("&8[&6&lBounty&8] &d" + killer.getName() + " &ehas taken &d" + player.getName() + "&e's bounty for &d" + playerData.getBounty() + " &ecoins")); + + playerData.setBounty(0); + } + + for (Killstreak killstreak : this.main.getKillstreakManager().getKillstreaks()) { + if (killstreak.getKillstreak() == killerData.getCurrentKillstreak()) { + killstreak.getKillstreaksCallable().executeAs(killer, killerData); + } + } + + if (killerData.getCurrentKillstreak() > killerData.getHighestKillstreak()) { + killerData.setHighestKillstreak(killerData.getCurrentKillstreak()); + } + } else { + this.main.getServer().broadcastMessage(Utils.translate("&9" + player.getName() + " &edied")); + + playerData.setPlayerState(PlayerState.SPAWN); + playerData.setDeaths(playerData.getDeaths() + 1); + playerData.setCurrentKillstreak(0); + + if (playerData.getBounty() > 0) { + playerData.setBounty(0); + } + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/listeners/RandomListeners.java b/src/main/java/me/trixkz/lifestealcore/listeners/RandomListeners.java new file mode 100644 index 0000000..708d7bc --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/listeners/RandomListeners.java @@ -0,0 +1,97 @@ +package me.trixkz.lifestealcore.listeners; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.playerdata.PlayerState; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.*; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerToggleFlightEvent; +import org.bukkit.event.weather.WeatherChangeEvent; + +public class RandomListeners implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + + if (player.getGameMode() == GameMode.CREATIVE) { + return; + } + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData == null) { + this.main.getLogger().warning(player.getName() + "'s player data is null"); + + return; + } + + if (playerData.getPlayerState() != PlayerState.SPAWN) { + return; + } + + if (!Utils.getPlayer(player, this.main.getSpawnManager().getSpawnMin(), this.main.getSpawnManager().getSpawnMax())) { + return; + } + + playerData.setPlayerState(PlayerState.WARZONE); + } + + @EventHandler + public void onWeatherChange(WeatherChangeEvent event) { + if (event.toWeatherState()) { + event.setCancelled(true); + } + } + + @EventHandler + public void onBlockFade(BlockFadeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBlockForm(BlockFormEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onHangingBreak(HangingBreakEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBlockBurn(BlockBurnEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBlockSpread(BlockSpreadEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBlockIgnite(BlockIgniteEvent event) { + if (event.getCause() == BlockIgniteEvent.IgniteCause.LIGHTNING) { + event.setCancelled(true); + } + } + + @EventHandler + public void onPlayerToggleFlight(PlayerToggleFlightEvent event) { + + } + + @EventHandler + public void onCreatureSpawn(CreatureSpawnEvent event) { + + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/ChunkManager.java b/src/main/java/me/trixkz/lifestealcore/managers/ChunkManager.java new file mode 100644 index 0000000..41a5660 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/ChunkManager.java @@ -0,0 +1,56 @@ +package me.trixkz.lifestealcore.managers; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.CustomLocation; +import org.bukkit.Chunk; +import org.bukkit.scheduler.BukkitRunnable; + +public class ChunkManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public ChunkManager() { + new BukkitRunnable() { + @Override + public void run() { + loadChunks(); + } + }.runTaskLater(this.main, 1); + } + + private void loadChunks() { + CustomLocation spawnMin = this.main.getSpawnManager().getSpawnMin(); + CustomLocation spawnMax = this.main.getSpawnManager().getSpawnMax(); + + if (spawnMin != null && spawnMax != null) { + int spawnMinX = spawnMin.toBukkitLocation().getBlockX() >> 4; + int spawnMinZ = spawnMin.toBukkitLocation().getBlockZ() >> 4; + int spawnMaxX = spawnMax.toBukkitLocation().getBlockX() >> 4; + int spawnMaxZ = spawnMax.toBukkitLocation().getBlockZ() >> 4; + + if (spawnMinX > spawnMaxX) { + int lastSpawnMinX = spawnMinX; + + spawnMinX = spawnMaxX; + spawnMaxX = lastSpawnMinX; + } + + if (spawnMinZ > spawnMaxZ) { + int lastSpawnMinZ = spawnMinZ; + + spawnMinZ = spawnMaxZ; + spawnMaxZ = lastSpawnMinZ; + } + + for (int x = spawnMinX; x <= spawnMaxX; x++) { + for (int z = spawnMinZ; z <= spawnMaxZ; z++) { + Chunk chunk = spawnMin.toBukkitWorld().getChunkAt(x, z); + + if (!chunk.isLoaded()) { + chunk.load(); + } + } + } + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/CombatManager.java b/src/main/java/me/trixkz/lifestealcore/managers/CombatManager.java new file mode 100644 index 0000000..c006fe7 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/CombatManager.java @@ -0,0 +1,104 @@ +package me.trixkz.lifestealcore.managers; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import org.apache.commons.lang3.tuple.Pair; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; +import java.util.*; + +@Getter +@Setter +public class CombatManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private Set combatSet = new HashSet(); + + private Map timeMap = new HashMap(); + private Map> assists = new HashMap>(); + private Map> fallDamageModifiers = new HashMap>(); + private Map fallDamageTasks = new HashMap(); + + private int count = 0; + +// public CombatManager() { +// this.main.getServer().getScheduler().runTaskTimer(this.main, () -> this.combatSet.forEach((key) -> { +// this.count++; +// +// for (Player player : this.main.getServer().getOnlinePlayers()) { +// if (this.isInCombat(player)) { +// int count = this.getCombatTime(player); +// +// Bukkit.broadcastMessage("Count - " + count); +// +// count--; +// +// this.setCombatTime(player, count); +// +// if (count == 0) { +// this.combatSet.remove(player); +// this.timeMap.remove(player); +// } +// } +// +// if (this.count == 160) { +// this.count = 0; +// } +// } +// }), 20, 20); +// } + + public void setCombatSet(UUID player, boolean inSpawn) { + if (inSpawn) { + this.combatSet.add(player); + this.timeMap.put(player, 16); + } else { + this.combatSet.remove(player); + this.timeMap.remove(player); + } + } + + public void setCombatTime(UUID player, int time) { + this.timeMap.remove(player); + this.timeMap.put(player, time); + } + + public boolean isInCombat(UUID player) { + return this.combatSet.contains(player); + } + + public int getCombatTime(UUID player) { + return this.timeMap.get(player); + } + + public void cancelNextFallDamage(Player player, int ticks) { + setNextFallDamage(player, damage -> 0.0D, ticks); + } + + public void setNextFallDamage(Player player, DamageModifier modifier, int ticks) { + setNextFallDamage(player, modifier, ticks, true); + } + + public void setNextFallDamage(Player player, DamageModifier modifier, int ticks, boolean reset) { + removeFallProtection(player); + this.fallDamageModifiers.put(player, Pair.of(reset, modifier)); + if (ticks > 0) + this.fallDamageTasks.put(player, Bukkit.getScheduler().runTaskLaterAsynchronously(this.main, () -> { + this.fallDamageTasks.remove(player); + this.fallDamageModifiers.remove(player); + }, ticks)); + } + + public void removeFallProtection(Player player) { + this.fallDamageModifiers.remove(player); + if (this.fallDamageTasks.containsKey(player)) + ((BukkitTask)this.fallDamageTasks.remove(player)).cancel(); + } + + public static interface DamageModifier { + double modify(double param1Double); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/CommandManager.java b/src/main/java/me/trixkz/lifestealcore/managers/CommandManager.java new file mode 100644 index 0000000..8e2a6ea --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/CommandManager.java @@ -0,0 +1,31 @@ +package me.trixkz.lifestealcore.managers; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.commands.*; +import me.trixkz.lifestealcore.commands.clan.ClanCommand; +import me.trixkz.lifestealcore.commands.coins.CoinsCommand; +import me.trixkz.lifestealcore.commands.koth.KOTHCommand; +import me.trixkz.lifestealcore.commands.setspawn.SetSpawnCommand; +import me.trixkz.lifestealcore.commands.tokens.TokensCommand; + +public class CommandManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public CommandManager() { + this.registerCommands(); + } + + private void registerCommands() { + this.main.getCommand("lootbox").setExecutor(new LootboxCommand()); + this.main.getCommand("clan").setExecutor(new ClanCommand()); + this.main.getCommand("koth").setExecutor(new KOTHCommand()); + this.main.getCommand("spawn").setExecutor(new SpawnCommand()); + this.main.getCommand("setspawn").setExecutor(new SetSpawnCommand()); + this.main.getCommand("coins").setExecutor(new CoinsCommand()); + this.main.getCommand("tokens").setExecutor(new TokensCommand()); + this.main.getCommand("shop").setExecutor(new ShopCommand()); + this.main.getCommand("envoy").setExecutor(new EnvoyCommand()); + this.main.getCommand("sethearts").setExecutor(new SetHeartsCommand()); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/CooldownManager.java b/src/main/java/me/trixkz/lifestealcore/managers/CooldownManager.java new file mode 100644 index 0000000..671b70d --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/CooldownManager.java @@ -0,0 +1,74 @@ +package me.trixkz.lifestealcore.managers; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import org.bukkit.entity.Player; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@Getter +@Setter +public class CooldownManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private Set cooldownSet = new HashSet(); + + private Map cooldownTimeMap = new HashMap(); + + private Set refillSet = new HashSet(); + + private Map refillTimeMap = new HashMap(); + + private int cooldownCount = 0; + private int refillCount = 0; + + public void setCooldownSet(Player player, boolean inSpawn, int number) { + if (inSpawn) { + this.cooldownSet.add(player); + this.cooldownTimeMap.put(player, number); + } else { + this.cooldownSet.remove(player); + this.cooldownTimeMap.remove(player); + } + } + + public int getCooldownTime(Player player) { + return this.cooldownTimeMap.get(player); + } + + public void setCooldownTime(Player player, int time) { + this.cooldownTimeMap.remove(player); + this.cooldownTimeMap.put(player, time); + } + + public boolean isOnCooldown(Player player) { + return this.cooldownSet.contains(player); + } + + public void setRefillSet(Player player, boolean inSpawn) { + if (inSpawn) { + this.refillSet.add(player); + this.refillTimeMap.put(player, 60); + } else { + this.refillSet.remove(player); + this.refillTimeMap.remove(player); + } + } + + public int getRefillTime(Player player) { + return this.refillTimeMap.get(player); + } + + public void setRefillTime(Player player, int time) { + this.refillTimeMap.remove(player); + this.refillTimeMap.put(player, time); + } + + public boolean isOnRefillCooldown(Player player) { + return this.refillSet.contains(player); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/LootboxManager.java b/src/main/java/me/trixkz/lifestealcore/managers/LootboxManager.java new file mode 100644 index 0000000..ddb17e7 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/LootboxManager.java @@ -0,0 +1,93 @@ +package me.trixkz.lifestealcore.managers; + +import io.github.bananapuncher714.nbteditor.NBTEditor; +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.normalmenusystem.ItemStackButton; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import java.util.*; + +@Getter +@Setter +public class LootboxManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List itemStacks = new ArrayList(); + + public LootboxManager() { + FileConfiguration fileConfiguration = this.main.getLootboxConfig().getConfig(); + + ConfigurationSection configurationSection = fileConfiguration.getConfigurationSection("lootbox"); + + if (configurationSection == null) { + return; + } + + configurationSection.getKeys(false).forEach((number) -> { + String name = configurationSection.getString(number + ".name"); + + List loreArrayList = configurationSection.getStringList(number + ".lore"); + + String[] lore = new String[loreArrayList.size()]; + + for (int i = 0; i < loreArrayList.size(); i++) { + lore[i] = loreArrayList.get(i); + } + + Material material = Material.getMaterial(configurationSection.getString(number + ".material")); + + int data = configurationSection.getInt(number + ".data"); + int amount = configurationSection.getInt(number + ".amount"); + + Map enchantments = new HashMap(); + + if (configurationSection.getStringList(number + ".enchantments") != null) { + configurationSection.getStringList(number + ".enchantments").forEach((string) -> { + String[] stringArray = string.split(":"); + + enchantments.put(Enchantment.getByName(stringArray[0]), Integer.parseInt(stringArray[1])); + }); + } + + ItemStackButton itemStackButton = new ItemStackButton(name, lore, material, data, amount); + + ItemStack itemStack = itemStackButton.makeItemStack(); + + if (enchantments.size() >= 1) { + itemStack.addEnchantments(enchantments); + } + + this.itemStacks.add(itemStack); + }); + } + + public ItemStack getLootboxItemStack(Player player, int amount) { + ItemStack itemStack = new ItemStack(Material.ENDER_CHEST, amount); + + ItemMeta itemMeta = itemStack.getItemMeta(); + itemMeta.setDisplayName(Utils.translate("&dLootbox")); + itemMeta.setLore(Utils.translate(Arrays.asList("&9Right click to use"))); + + itemStack.setItemMeta(itemMeta); + itemStack = NBTEditor.set(itemStack, "Lootbox", player.getUniqueId().toString() + "Lootbox"); + + return itemStack; + } + + public boolean isLootboxItemStack(Player player, ItemStack itemStack) { + if (itemStack.getItemMeta() == null) { + return false; + } + + return NBTEditor.contains(itemStack, player.getUniqueId().toString() + "Lootbox"); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/MongoManager.java b/src/main/java/me/trixkz/lifestealcore/managers/MongoManager.java new file mode 100644 index 0000000..3746c22 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/MongoManager.java @@ -0,0 +1,84 @@ +package me.trixkz.lifestealcore.managers; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.mongodb.MongoClient; +import com.mongodb.MongoCredential; +import com.mongodb.ServerAddress; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import lombok.Getter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.Utils; +import me.trixkz.lifestealcore.utils.config.file.Config; +import org.bson.Document; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.List; + +@Getter +public class MongoManager { + + private final MongoManager instance; + private final LifeStealCore main = LifeStealCore.getInstance(); + + private final Config configFile = this.main.getSettingsConfig(); + private final FileConfiguration fileConfig = configFile.getConfig(); + private final ConfigurationSection config = fileConfig.getConfigurationSection("mongo"); + + private MongoClient mongoClient; + private MongoDatabase mongoDatabase; + + private final String host = config.getString("host"); + private final int port = config.getInt("port"); + private final String database = config.getString("database"); + private final boolean auth = config.getBoolean("auth.enabled"); + private final String user = config.getString("auth.username"); + private final String password = config.getString("auth.password"); + private final String authDatabase = config.getString("auth.auth-database"); + + private boolean connected; + + private MongoCollection players; + private MongoCollection clans; + + private Gson gson = new Gson(); + + private Type type = (new TypeToken>() { + + }).getType(); + + public MongoManager() { + instance = this; + try { + if (auth) { + final MongoCredential credential = MongoCredential.createCredential(user, authDatabase, password.toCharArray()); + mongoClient = new MongoClient(new ServerAddress(host, port), Collections.singletonList(credential)); + } else { + mongoClient = new MongoClient(host, port); + } + connected = true; + mongoDatabase = mongoClient.getDatabase(database); + Bukkit.getConsoleSender().sendMessage(Utils.translate("&d[LifestealCore] &aSuccessfully connected to the database!")); + this.players = this.mongoDatabase.getCollection("players"); + this.clans = this.mongoDatabase.getCollection("clans"); + } catch (Exception exception) { + connected = false; + Bukkit.getConsoleSender().sendMessage(Utils.translate("&d[LifestealCore] &cFailed to connect to the database!")); + exception.printStackTrace(); + Bukkit.getPluginManager().disablePlugin(this.main); + Bukkit.getConsoleSender().sendMessage(Utils.translate("&b[LifestealCore] &cDisabling LifestealCore...")); + } + } + + public void disconnect() { + if (this.mongoClient != null) { + this.mongoClient.close(); + this.connected = false; + Bukkit.getConsoleSender().sendMessage(Utils.translate("&d[LifestealCore] &aSuccessfully disconnected from the database!")); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/PlayerDataManager.java b/src/main/java/me/trixkz/lifestealcore/managers/PlayerDataManager.java new file mode 100644 index 0000000..abe72f6 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/PlayerDataManager.java @@ -0,0 +1,100 @@ +package me.trixkz.lifestealcore.managers; + +import com.mongodb.client.MongoCursor; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.UpdateOptions; +import lombok.Getter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.playerdata.PlayerState; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.CustomLocation; +import org.bson.Document; +import org.bukkit.entity.Player; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class PlayerDataManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Getter private Map players = new HashMap<>(); + + public PlayerData getOrCreate(UUID uniqueId) { + return this.players.computeIfAbsent(uniqueId, PlayerData::new); + } + + public PlayerData getPlayerData(UUID uniqueId) { + return this.players.getOrDefault(uniqueId, new PlayerData(uniqueId)); + } + + public Collection getAllPlayers() { + return this.players.values(); + } + + public void loadPlayerData(PlayerData playerData) { + Document document = this.main.getMongoManager().getPlayers().find(Filters.eq(Constants.PLAYER_DATA_UNIQUE_ID, playerData.getUniqueId().toString())).first(); + + if (document != null) { + playerData.setCoins(document.getDouble(Constants.PLAYER_DATA_COINS)); + playerData.setTokens(document.getInteger(Constants.PLAYER_DATA_TOKENS)); + playerData.setClanOwner((document.getString(Constants.PLAYER_DATA_CLAN_OWNER) == null ? null : UUID.fromString(document.getString(Constants.PLAYER_DATA_CLAN_OWNER)))); + playerData.setKills(document.getInteger(Constants.PLAYER_DATA_KILLS)); + playerData.setDeaths(document.getInteger(Constants.PLAYER_DATA_DEATHS)); + playerData.setHearts(document.getDouble(Constants.PLAYER_DATA_HEARTS)); + playerData.setBounty(document.getInteger(Constants.PLAYER_DATA_BOUNTY)); + playerData.setCurrentKillstreak(document.getInteger(Constants.PLAYER_DATA_CURRENT_KILLSTREAK)); + playerData.setHighestKillstreak(document.getInteger(Constants.PLAYER_DATA_HIGHEST_KILLSTREAK)); + playerData.setDeathBanTime(document.getLong(Constants.PLAYER_DATA_DEATH_BAN_TIME)); + playerData.setDeathBanTimeAddedAt(document.getLong(Constants.PLAYER_DATA_DEATH_BAN_TIME_ADDED_AT)); + } + + playerData.setLoaded(true); + } + + public void savePlayerData(PlayerData playerData) { + Document document = new Document(); + + document.put(Constants.PLAYER_DATA_UNIQUE_ID, playerData.getUniqueId().toString()); + document.put(Constants.PLAYER_DATA_COINS, playerData.getCoins()); + document.put(Constants.PLAYER_DATA_TOKENS, playerData.getTokens()); + document.put(Constants.PLAYER_DATA_CLAN_OWNER, (playerData.getClanOwner() == null ? null : playerData.getClanOwner().toString())); + document.put(Constants.PLAYER_DATA_KILLS, playerData.getKills()); + document.put(Constants.PLAYER_DATA_DEATHS, playerData.getDeaths()); + document.put(Constants.PLAYER_DATA_HEARTS, playerData.getHearts()); + document.put(Constants.PLAYER_DATA_BOUNTY, playerData.getBounty()); + document.put(Constants.PLAYER_DATA_CURRENT_KILLSTREAK, playerData.getCurrentKillstreak()); + document.put(Constants.PLAYER_DATA_HIGHEST_KILLSTREAK, playerData.getHighestKillstreak()); + document.put(Constants.PLAYER_DATA_DEATH_BAN_TIME, playerData.getDeathBanTime()); + document.put(Constants.PLAYER_DATA_DEATH_BAN_TIME_ADDED_AT, playerData.getDeathBanTimeAddedAt()); + + this.main.getMongoManager().getPlayers().replaceOne(Filters.eq(Constants.PLAYER_DATA_UNIQUE_ID, playerData.getUniqueId().toString()), document, new UpdateOptions().upsert(true)); + } + + public void deletePlayer(UUID uniqueId) { + this.savePlayerData(getPlayerData(uniqueId)); + this.getPlayers().remove(uniqueId); + } + + public void sendToSpawnAndResetPlayer(Player player) { + if (!player.isOnline()) { + return; + } + + PlayerData playerData = this.getPlayerData(player.getUniqueId()); + + player.teleport(CustomLocation.stringToLocation(this.main.getSettingsConfig().getConfig().getString("spawn.location")).toBukkitLocation()); + + playerData.setPlayerState(PlayerState.SPAWN); + } + + public MongoCursor getPlayersSorted(String stat) { + Document sort = new Document(); + sort.put(stat, -1); + + return this.main.getMongoManager().getPlayers().find().sort(sort).limit(10).iterator(); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/SpawnManager.java b/src/main/java/me/trixkz/lifestealcore/managers/SpawnManager.java new file mode 100644 index 0000000..dbf626a --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/SpawnManager.java @@ -0,0 +1,64 @@ +package me.trixkz.lifestealcore.managers; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.CustomLocation; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@Getter +@Setter +public class SpawnManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private FileConfiguration config = this.main.getSettingsConfig().getConfig(); + + private CustomLocation spawnLocation; + private CustomLocation spawnMin; + private CustomLocation spawnMax; + private CustomLocation cornerMin; + private CustomLocation cornerMax; + private CustomLocation hologramsLocation; + + private Map players = new HashMap(); + + public SpawnManager() { + this.loadConfig(); + } + + private void loadConfig() { + if (this.config.contains("spawn.location")) { + try { + this.spawnLocation = CustomLocation.stringToLocation(this.config.getString("spawn.location")); + this.spawnMin = CustomLocation.stringToLocation(this.config.getString("spawn.min")); + this.spawnMax = CustomLocation.stringToLocation(this.config.getString("spawn.max")); + this.cornerMin = CustomLocation.stringToLocation(this.config.getString("corner.min")); + this.cornerMax = CustomLocation.stringToLocation(this.config.getString("corner.max")); + } catch (NullPointerException exception) { + Bukkit.getConsoleSender().sendMessage(Utils.translate("&cSpawn min & max locations not found!")); + } + } + + if (this.config.contains("holograms.location")) { + // this.hologramsLocation = CustomLocation.stringToLocation(this.config.getString("holograms.location")); + } + } + + public void saveConfig() { + this.config.set("spawn.location", CustomLocation.locationToString(this.spawnLocation)); + this.config.set("spawn.min", CustomLocation.locationToString(this.spawnMin)); + this.config.set("spawn.max", CustomLocation.locationToString(this.spawnMax)); + this.config.set("corner.min", CustomLocation.locationToString(this.cornerMin)); + this.config.set("corner.max", CustomLocation.locationToString(this.cornerMax)); + // this.config.set("holograms.location", CustomLocation.locationToString(this.hologramsLocation)); + + this.main.getSettingsConfig().save(); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/chatgames/ChatGame.java b/src/main/java/me/trixkz/lifestealcore/managers/chatgames/ChatGame.java new file mode 100644 index 0000000..c101bc4 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/chatgames/ChatGame.java @@ -0,0 +1,18 @@ +package me.trixkz.lifestealcore.managers.chatgames; + +import lombok.Getter; +import lombok.Setter; +import org.bukkit.event.Listener; + +@Getter +@Setter +public abstract class ChatGame implements Listener { + + private boolean started = false; + + public abstract String getName(); + + public abstract void startGame(); + + public abstract void stopGame(); +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/chatgames/ChatGameManager.java b/src/main/java/me/trixkz/lifestealcore/managers/chatgames/ChatGameManager.java new file mode 100644 index 0000000..005fe17 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/chatgames/ChatGameManager.java @@ -0,0 +1,37 @@ +package me.trixkz.lifestealcore.managers.chatgames; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.managers.chatgames.chatquestion.ChatQuestion; +import org.bukkit.scheduler.BukkitRunnable; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +@Getter +@Setter +public class ChatGameManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List chatGames = new ArrayList(); + + public ChatGameManager() { + this.chatGames.add(new ChatQuestion()); + // this.chatGames.add(new ChatMath()); + this.chatGames.forEach((chatGame) -> { + this.main.getServer().getPluginManager().registerEvents(chatGame, this.main); + }); + + new BukkitRunnable() { + @Override + public void run() { + int random = ThreadLocalRandom.current().nextInt(chatGames.size()); + + ChatGame chatGame = chatGames.get(random); + chatGame.startGame(); + } + }.runTaskTimerAsynchronously(this.main, 6000L, 6000L); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/chatgames/chatmath/ChatMath.java b/src/main/java/me/trixkz/lifestealcore/managers/chatgames/chatmath/ChatMath.java new file mode 100644 index 0000000..204feba --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/chatgames/chatmath/ChatMath.java @@ -0,0 +1,4 @@ +package me.trixkz.lifestealcore.managers.chatgames.chatmath; + +public class ChatMath { +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/chatgames/chatquestion/ChatQuestion.java b/src/main/java/me/trixkz/lifestealcore/managers/chatgames/chatquestion/ChatQuestion.java new file mode 100644 index 0000000..d44add0 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/chatgames/chatquestion/ChatQuestion.java @@ -0,0 +1,153 @@ +package me.trixkz.lifestealcore.managers.chatgames.chatquestion; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.managers.chatgames.ChatGame; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.scheduler.BukkitRunnable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +public class ChatQuestion extends ChatGame { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List questions = new ArrayList(); + + private Question question = null; + + private double time = 0; + + public ChatQuestion() { + for (int i = 0; i < this.main.getSettingsConfig().getConfig().getConfigurationSection("CHAT-GAMES.QUESTIONS").getKeys(false).size(); i++) { + this.questions.add(new Question(this.main.getSettingsConfig().getConfig().getString("CHAT-GAMES.QUESTIONS." + i + ".QUESTION"), this.main.getSettingsConfig().getConfig().getStringList("CHAT-GAMES.QUESTIONS." + i + ".ANSWERS"))); + } + } + + @Override + public String getName() { + return Utils.translate("&d&lChat question"); + } + + @Override + public void startGame() { + this.setStarted(true); + + new BukkitRunnable() { + @Override + public void run() { + if (!isStarted()) { + cancel(); + + return; + } + + time += 0.10; + } + }.runTaskTimer(this.main, 5L, 5L); + + int random = ThreadLocalRandom.current().nextInt(this.questions.size()); + + Question question = this.questions.get(random); + + this.question = question; + + List message = new ArrayList( + Arrays.asList( + "", + this.getName(), + "", + "&7┃ &9Question: &d" + this.question.getQuestion(), + "&7┃ &9Respond with the right answer", + "&7┃ &9to get 10 thousand coins", + "" + ) + ); + + message.forEach((string) -> { + this.main.getServer().broadcastMessage(Utils.translate(string)); + }); + + new BukkitRunnable() { + @Override + public void run() { + if (!isStarted()) { + cancel(); + + return; + } + + stopGame(); + } + }.runTaskLater(this.main, 300L); + } + + @Override + public void stopGame() { + this.setStarted(false); + this.main.getServer().broadcastMessage(Utils.translate(Constants.PREFIX + "&eNo one answered the question in time")); + } + + @Getter + @Setter + @AllArgsConstructor + @RequiredArgsConstructor + public class Question { + + private String question; + private List answers; + } + + @EventHandler + public void onAsyncPlayerChat(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (!this.isStarted()) { + return; + } + + if (this.question == null) { + return; + } + + String answer = event.getMessage(); + + if (!this.question.getAnswers().contains(answer)) { + return; + } + + this.setStarted(false); + + event.setCancelled(true); + + List message = new ArrayList( + Arrays.asList( + "", + this.getName(), + "", + "&7┃ &9Answer: &d" + answer, + "&7┃ &9Winner: &d" + player.getName(), + "&7┃ &9Time: &d" + this.time, + "" + ) + ); + + message.forEach((string) -> { + this.main.getServer().broadcastMessage(Utils.translate(string)); + }); + + playerData.setCoins(playerData.getCoins() + 10000); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/clans/Clan.java b/src/main/java/me/trixkz/lifestealcore/managers/clans/Clan.java new file mode 100644 index 0000000..c7797f1 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/clans/Clan.java @@ -0,0 +1,41 @@ +package me.trixkz.lifestealcore.managers.clans; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.Utils; + +import java.util.List; +import java.util.UUID; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class Clan { + + private String name; + private int level; + private UUID owner; + private List playersAdded; + private boolean locked; + private int maxClanMembers; + + public void sendMessageToAllClanMembers(String message) { + Utils.getOfflinePlayer(LifeStealCore.getInstance().getServer().getOfflinePlayer(this.owner).getName(), (offlinePlayer) -> { + if (offlinePlayer.getPlayer() != null) { + offlinePlayer.getPlayer().sendMessage(message); + } + }); + + for (UUID uuid : LifeStealCore.getInstance().getClanManager().getClan(this.owner).getPlayersAdded()) { + Utils.getOfflinePlayer(LifeStealCore.getInstance().getServer().getOfflinePlayer(uuid).getName(), (offlinePlayer) -> { + if (offlinePlayer.getPlayer() != null) { + offlinePlayer.getPlayer().sendMessage(message); + } + }); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/clans/ClanManager.java b/src/main/java/me/trixkz/lifestealcore/managers/clans/ClanManager.java new file mode 100644 index 0000000..991c638 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/clans/ClanManager.java @@ -0,0 +1,564 @@ +package me.trixkz.lifestealcore.managers.clans; + +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.UpdateOptions; +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.*; +import org.bson.Document; +import org.bukkit.*; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +@Getter +@Setter +public class ClanManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private HashMap clans = new HashMap(); + + private Map> clanInvites = new TtlHashMap<>(TimeUnit.SECONDS, 15); + + private Cache> clanLevelsSortCache = new Cache<>(5000); + + public ClanManager() { + + } + + /** + * Adds an clan to the server for the player + * + * @param player - The player + * @param clan - The clan + */ + public void createClan(Player player, Clan clan) { + this.clans.put(player.getUniqueId(), clan); + } + + /** + * Removes an clan from the server for the player + * + * @param player - The player + */ + public void removeClan(Player player) { + this.clans.remove(player.getUniqueId()); + } + + /** + * Gets the player's clan + * + * @param player - The player + * @return The player's clan + */ + public Clan getClan(UUID player) { + return this.clans.get(player); + } + + /** + * Checks whether the player is an owner of their clan + * + * @param player - The player + * @return True or false + */ + public boolean isOwner(OfflinePlayer player) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + return player.getUniqueId().equals(playerData.getClanOwner()); + } + + /** + * Checks whether the player is in an clan + * + * @param player - The player + * @return True or false + */ + public boolean isInAClan(OfflinePlayer player) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + return this.clans.containsKey(playerData.getClanOwner()) || (playerData.getClanOwner() != null && this.getClan(playerData.getClanOwner()).getPlayersAdded().contains(player.getUniqueId())); + } + + /** + * Checks whether the player is an clan member + * + * @param player - The player + * @return True or false + */ + public boolean isAClanMember(OfflinePlayer player) { + return this.main.getClanManager().isOwner(player) || this.main.getClanManager().isInAClan(player); + } + + /** + * Checks whether the player's clan has the maximum amount of clan members in it + * + * @param player - The player + * @return True or false + */ + public boolean hasMaxClanMembers(UUID player) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player); + + return (this.main.getClanManager().getClan(playerData.getClanOwner()).getPlayersAdded().size() + 1) >= this.main.getClanManager().getClan(player).getMaxClanMembers(); + } + + /** + * Load the player's clan + * + * @param player - The player + */ + public void loadClan(Player player) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + Document document = this.main.getMongoManager().getClans().find(Filters.eq(Constants.CLAN_OWNER, playerData.getClanOwner().toString())).first(); + + if (document == null) { + return; + } + + String name = document.getString(Constants.CLAN_NAME); + + int level = document.getInteger(Constants.CLAN_LEVEL); + + String ownerString = document.getString(Constants.CLAN_OWNER); + + List playersAddedString = new ArrayList(); + + ((List) this.main.getMongoManager().getGson().fromJson(document.getString(Constants.CLAN_PLAYERS_ADDED), this.main.getMongoManager().getType())).forEach(playerAdded -> playersAddedString.add(String.valueOf(playerAdded))); + + boolean locked = document.getBoolean(Constants.CLAN_LOCKED); + + int maxIslandMembers = document.getInteger(Constants.CLAN_MAX_CLAN_MEMBERS); + + UUID owner = UUID.fromString(ownerString); + + List playersAdded = new ArrayList(); + + for (String string : playersAddedString) { + playersAdded.add(UUID.fromString(string)); + } + + Clan clan = new Clan( + name, + level, + owner, + playersAdded, + locked, + maxIslandMembers + ); + + this.clans.put(owner, clan); + + clan.setLocked(false); + } + + /** + * Save the player's clan + * + * @param player - The player + */ + public void saveClan(Player player) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData.getClanOwner() == null) { + return; + } + + Document document = this.main.getMongoManager().getClans().find(Filters.eq(Constants.CLAN_OWNER, playerData.getClanOwner().toString())).first(); + + if (document == null) { + return; + } + + Clan clan = this.getClan(playerData.getClanOwner()); + + String name = clan.getName(); + + int level = clan.getLevel(); + + String ownerString = clan.getOwner().toString(); + + List playersAdded = clan.getPlayersAdded(); + + boolean locked = clan.isLocked(); + + int maxClanMembers = clan.getMaxClanMembers(); + + List playersAddedString = new ArrayList(); + + for (UUID uuid : playersAdded) { + playersAddedString.add(uuid.toString()); + } + + document.put(Constants.CLAN_NAME, name); + document.put(Constants.CLAN_LEVEL, level); + document.put(Constants.CLAN_OWNER, ownerString); + document.put(Constants.CLAN_PLAYERS_ADDED, this.main.getMongoManager().getGson().toJson(playersAddedString)); + document.put(Constants.CLAN_LOCKED, locked); + document.put(Constants.CLAN_MAX_CLAN_MEMBERS, maxClanMembers); + + Player owner = this.main.getServer().getPlayer(clan.getOwner()); + + if (owner != null) { + owner.chat("/spawn"); + } + + for (UUID uuid : this.main.getClanManager().getClan(playerData.getClanOwner()).getPlayersAdded()) { + Player playerAdded = this.main.getServer().getPlayer(uuid); + + if (playerAdded != null) { + playerAdded.chat("/spawn"); + } + } + + this.clans.remove(playerData.getClanOwner()); + this.main.getMongoManager().getClans().replaceOne(Filters.eq(Constants.CLAN_OWNER, playerData.getClanOwner().toString()), document, new UpdateOptions().upsert(true)); + + clan.setLocked(true); + } + + /** + * Make the player's clan + * + * @param player - The player + */ + public void makeClan(Player player) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + Document document = new Document(); + + if (this.isAClanMember(player)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.CLAN_ALREADY_MADE_MESSAGE)); + + return; + } + + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.MAKING_CLAN_MESSAGE)); + + String name = player.getName() + "'s island"; + + int level = 0; + + List playersAdded = new ArrayList(); + + boolean locked = false; + + int maxClanMembers = 10; + + String worldName = player.getName() + "Clan"; + + Clan clan = new Clan( + name, + level, + player.getUniqueId(), + playersAdded, + locked, + maxClanMembers + ); + + document.put(Constants.CLAN_OWNER, player.getUniqueId().toString()); + + this.createClan(player, clan); + this.main.getMongoManager().getClans().insertOne(document); + + playerData.setClanOwner(player.getUniqueId()); + + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.CLAN_MADE_MESSAGE)); + } + + /** + * Delete the player's clan + * + * @param player - The player + */ + public void deleteIsland(Player player) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + Document document = this.main.getMongoManager().getClans().find(Filters.eq(Constants.CLAN_OWNER, playerData.getClanOwner().toString())).first(); + + if (document == null) { + return; + } + + if (!this.isOwner(player)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.NOT_CLAN_OWNER_MESSAGE)); + + return; + } + + Clan clan = this.getClan(player.getUniqueId()); + + playerData.setClanOwner(null); + + for (UUID uuid : clan.getPlayersAdded()) { + PlayerData playerAddedPlayerData = this.main.getPlayerDataManager().getOrCreate(uuid); + playerAddedPlayerData.setClanOwner(null); + + if (this.main.getServer().getPlayer(uuid) == null) { + this.main.getPlayerDataManager().savePlayerData(playerAddedPlayerData); + this.main.getPlayerDataManager().getPlayers().remove(uuid); + } + } + + clan.sendMessageToAllClanMembers(Utils.translate(Constants.CLAN_PREFIX + Constants.CLAN_DELETED_MESSAGE.replace("%player%", player.getName()))); + + this.removeClan(player); + this.main.getMongoManager().getClans().deleteOne(document); + } + + /** + * Transfer the player's clan ownership to the target + * + * @param player - The player + * @param target - The target + */ + public void transferClanOwnership(Player player, OfflinePlayer target) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (!this.isOwner(player)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.NOT_CLAN_OWNER_MESSAGE)); + + return; + } + + if (!this.isAClanMember(target)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.NOT_IN_CLAN_MESSAGE.replace("%player%", target.getName()))); + + return; + } + + Clan clan = this.getClan(player.getUniqueId()); + clan.setOwner(target.getUniqueId()); + + playerData.setClanOwner(target.getUniqueId()); + + for (UUID uuid : clan.getPlayersAdded()) { + PlayerData playerAddedPlayerData = this.main.getPlayerDataManager().getPlayerData(uuid); + playerAddedPlayerData.setClanOwner(target.getUniqueId()); + + if (this.main.getServer().getPlayer(uuid) == null) { + this.main.getPlayerDataManager().savePlayerData(playerAddedPlayerData); + this.main.getPlayerDataManager().getPlayers().remove(uuid); + } + } + + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.CLAN_OWNERSHIP_TRANSFERRED_MESSAGE.replace("%player%", target.getName()))); + } + + /** + * Look at the player's clan level + * + * @param player - The player + */ + public void lookAtClanLevel(Player player) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (!this.isAClanMember(player)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.NO_CLAN_MESSAGE)); + + return; + } + + Clan clan = this.getClan(playerData.getClanOwner()); + + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.CLAN_LEVEL_MESSAGE.replace("%level%", String.valueOf(clan.getLevel())))); + } + + /** + * Get the clan top + * + * @return The list of the clans + */ + public List getClanTop() { + return this.clanLevelsSortCache.getCache(() -> this.clans.values().stream().sorted(Comparator.comparing(Clan :: getLevel).reversed()).collect(Collectors.toList())); + } + + public void createClanInvite(Player player, Player target) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (!this.isOwner(player)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.NOT_CLAN_OWNER_MESSAGE)); + + return; + } + + if (this.hasClanInvite(player.getUniqueId(), target.getUniqueId())) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.ALREADY_INVITED_TO_CLAN_MESSAGE.replace("%player%", target.getName()))); + + return; + } + + if (this.hasMaxClanMembers(player.getUniqueId())) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.MAXIMUM_AMOUNT_OF_CLAN_MEMBERS_MESSAGE)); + + return; + } + + if (target == null) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.NOT_ONLINE_MESSAGE.replace("%player%", target.getName()))); + + return; + } + + if (this.isAClanMember(target)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.ALREADY_IN_CLAN_MESSAGE.replace("%player%", target.getName()))); + + return; + } + + if (this.getClan(playerData.getClanOwner()).getPlayersAdded().contains(target.getUniqueId())) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.ALREADY_IN_YOUR_CLAN_MESSAGE.replace("%player%", target.getName()))); + + return; + } + + this.clanInvites.computeIfAbsent(target.getUniqueId(), playerTarget -> new ArrayList<>()).add(player.getUniqueId()); + + Clickable clickable = new Clickable(Utils.translate(Constants.PREFIX + Constants.INVITED_TO_CLAN_INVITATION_MESSAGE.replace("%player%", player.getName())), Utils.translate(Constants.CLICK_TO_JOIN_CLAN_MESSAGE), "/clan join " + player.getName()); + clickable.sendToPlayer(target); + + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.INVITED_TO_CLAN_MESSAGE.replace("%player%", target.getName()))); + } + + public void removeClanInvite(Player player, OfflinePlayer target) { + if (!this.isOwner(player)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.NOT_CLAN_OWNER_MESSAGE)); + + return; + } + + if (!this.hasClanInvite(player.getUniqueId(), target.getUniqueId())) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.NOT_INVITED_TO_CLAN_MESSAGE.replace("%player%", target.getName()))); + + return; + } + + this.clanInvites.remove(target.getUniqueId()); + + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.UNINVITED_TO_CLAN_MESSAGE.replace("%player%", target.getName()))); + } + + public boolean hasClanInvite(UUID player, UUID target) { + return this.clanInvites.get(target) != null && this.clanInvites.get(target).contains(player); + } + + public void joinClan(UUID player, Player target) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player); + + Clan clan = this.getClan(playerData.getClanOwner()); + + PlayerData targetPlayerData = this.main.getPlayerDataManager().getPlayerData(target.getUniqueId()); + + if (clan == null) { + target.sendMessage(Utils.translate(Constants.PREFIX + Constants.INVALID_CLAN_MESSAGE)); + + return; + } + + if (this.isAClanMember(target)) { + target.sendMessage(Utils.translate(Constants.PREFIX + Constants.CLAN_ALREADY_MADE_MESSAGE)); + + return; + } + + if (!this.hasClanInvite(player, target.getUniqueId())) { + target.sendMessage(Utils.translate(Constants.PREFIX + Constants.NO_INVITE_TO_CLAN_MESSAGE)); + + return; + } + + if (this.hasMaxClanMembers(player)) { + target.sendMessage(Utils.translate(Constants.PREFIX + Constants.MAXIMUM_AMOUNT_OF_CLAN_MEMBERS_MESSAGE)); + + return; + } + + this.clanInvites.remove(target.getUniqueId()); + + clan.getPlayersAdded().add(target.getUniqueId()); + + targetPlayerData.setClanOwner(player); + + clan.sendMessageToAllClanMembers(Utils.translate(Constants.CLAN_PREFIX + Constants.JOINED_CLAN_MESSAGE.replace("%player%", target.getName()))); + + if (this.main.getServer().getPlayer(player) == null) { + this.main.getPlayerDataManager().savePlayerData(playerData); + this.main.getPlayerDataManager().getPlayers().remove(player); + } + } + + public void leaveClan(UUID player, Player target) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player); + + if (playerData.getClanOwner() == null) { + return; + } + + Clan clan = this.getClan(playerData.getClanOwner()); + + if (clan == null) { + return; + } + + PlayerData targetPlayerData = this.main.getPlayerDataManager().getPlayerData(target.getUniqueId()); + + if (!this.isAClanMember(target)) { + target.sendMessage(Utils.translate(Constants.PREFIX + Constants.NO_CLAN_MESSAGE)); + + return; + } + + if (this.isOwner(target)) { + target.sendMessage(Utils.translate(Constants.PREFIX + Constants.INVALID_ACTION_MESSAGE)); + + return; + } + + clan.getPlayersAdded().remove(target.getUniqueId()); + + targetPlayerData.setClanOwner(null); + + clan.sendMessageToAllClanMembers(Utils.translate(Constants.CLAN_PREFIX + Constants.LEFT_CLAN_MESSAGE.replace("%player%", target.getName()))); + + if (this.main.getServer().getPlayer(player) == null) { + this.main.getPlayerDataManager().savePlayerData(playerData); + this.main.getPlayerDataManager().getPlayers().remove(player); + } + } + + public void kickPlayerFromClan(Player player, OfflinePlayer target) { + if (!this.isOwner(player)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.NOT_CLAN_OWNER_MESSAGE)); + + return; + } + + if (this.main.getClanManager().isOwner(target)) { + player.sendMessage(Utils.translate(Constants.PREFIX + Constants.INVALID_ACTION_MESSAGE)); + + return; + } + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + Clan clan = this.getClan(playerData.getClanOwner()); + + if (this.isAClanMember(target)) { + PlayerData targetPlayerData = this.main.getPlayerDataManager().getPlayerData(target.getUniqueId()); + + clan.getPlayersAdded().remove(target.getUniqueId()); + + targetPlayerData.setClanOwner(null); + + clan.sendMessageToAllClanMembers(Utils.translate(Constants.CLAN_PREFIX + Constants.PLAYER_KICKED_FROM_CLAN.replace("%player%", target.getName()))); + + return; + } + + clan.sendMessageToAllClanMembers(Utils.translate(Constants.CLAN_PREFIX + Constants.PLAYER_KICKED_FROM_CLAN.replace("%player%", target.getName()))); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/envoys/Envoy.java b/src/main/java/me/trixkz/lifestealcore/managers/envoys/Envoy.java new file mode 100644 index 0000000..89d49cd --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/envoys/Envoy.java @@ -0,0 +1,15 @@ +package me.trixkz.lifestealcore.managers.envoys; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class Envoy { + + private EnvoyReward envoyReward; +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyDrop.java b/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyDrop.java new file mode 100644 index 0000000..c2dd5e0 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyDrop.java @@ -0,0 +1,72 @@ +package me.trixkz.lifestealcore.managers.envoys; + +import me.trixkz.lifestealcore.LifeStealCore; +import org.bukkit.*; +import org.bukkit.block.Chest; +import org.bukkit.entity.Firework; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.FireworkMeta; +import org.bukkit.scheduler.BukkitRunnable; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +public class EnvoyDrop { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public EnvoyDrop(World world, double x, double y, double z, double height) { + new BukkitRunnable() { + double heightCurrent = height; + + @Override + public void run() { + Location location = new Location(world, x, heightCurrent, z); + Location locationPrevious = new Location(world, x, heightCurrent + 1, z); + + if (heightCurrent > y) { + location.getBlock().setType(Material.CHEST); + locationPrevious.getBlock().setType(Material.AIR); + + heightCurrent--; + } else { + location.getBlock().setType(Material.CHEST); + locationPrevious.getBlock().setType(Material.AIR); + + Chest chest = (Chest) location.getBlock().getState(); + + Inventory inventory = chest.getInventory(); + + List itemStacks = new ArrayList(); + + double random = ThreadLocalRandom.current().nextDouble(1.01); + + for (Envoy envoy : main.getEnvoyManager().getEnvoys()) { + if (envoy.getEnvoyReward().getChance() <= random) { + continue; + } + + itemStacks.addAll(envoy.getEnvoyReward().getItemStacks()); + + break; + } + + for (ItemStack itemStack : itemStacks) { + inventory.addItem(itemStack); + } + + Firework firework = location.getWorld().spawn(new Location(world, x + 0.5, y, z + 0.5), Firework.class); + + FireworkMeta fireworkMeta = firework.getFireworkMeta(); + fireworkMeta.addEffect(FireworkEffect.builder().flicker(false).trail(true).with(FireworkEffect.Type.BURST).withColor(Color.RED).withColor(Color.WHITE).withFade(Color.GRAY).build()); + + firework.setFireworkMeta(fireworkMeta); + firework.eject(); + + this.cancel(); + } + } + }.runTaskTimer(this.main, 0L, 2L); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyDropGlider.java b/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyDropGlider.java new file mode 100644 index 0000000..615dff7 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyDropGlider.java @@ -0,0 +1,71 @@ +package me.trixkz.lifestealcore.managers.envoys; + +import me.trixkz.lifestealcore.LifeStealCore; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.ArmorStand; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.EulerAngle; +import java.util.HashMap; + +public class EnvoyDropGlider { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private HashMap parts = new HashMap<>(); + + public EnvoyDropGlider(World world, double x, double y, double z) { + Location loc = new Location(world, x + 0.5D, y, z + 0.5D); + ArmorStand leftSide = makeNewArmorStand(loc.getWorld(), loc.getX() - 0.32D, loc.getY() + 0.93D, loc.getZ()); + leftSide.setHeadPose(new EulerAngle(0.0D, Math.toRadians(270.0D), Math.toRadians(251.0D))); + leftSide.setHelmet(new ItemStack(Material.RED_BANNER)); + ArmorStand middle = makeNewArmorStand(loc.getWorld(), loc.getX() + 1.345D, loc.getY() + 0.76D, loc.getZ()); + middle.setHeadPose(new EulerAngle(0.0D, Math.toRadians(270.0D), Math.toRadians(270.0D))); + middle.setHelmet(new ItemStack(Material.RED_BANNER)); + ArmorStand rightSide = makeNewArmorStand(loc.getWorld(), loc.getX() + 0.32D, loc.getY() + 0.93D, loc.getZ()); + rightSide.setHeadPose(new EulerAngle(0.0D, Math.toRadians(90.0D), Math.toRadians(109.0D))); + rightSide.setHelmet(new ItemStack(Material.RED_BANNER)); + ArmorStand leftStick = makeNewArmorStand(loc.getWorld(), loc.getX() + 0.62D, loc.getY() - 0.55D, + loc.getZ() + 0.28D); + leftStick.setHelmet(new ItemStack(Material.STICK)); + ArmorStand rightStick = makeNewArmorStand(loc.getWorld(), loc.getX() - 0.62D, loc.getY() + 0.92D, + loc.getZ() - 0.28D); + rightStick.setHeadPose(new EulerAngle(0.0D, Math.toRadians(180.0D), Math.toRadians(180.0D))); + rightStick.setHelmet(new ItemStack(Material.STICK)); + this.parts.put("leftSide", leftSide); + this.parts.put("middle", middle); + this.parts.put("rightSide", rightSide); + this.parts.put("leftStick", leftStick); + this.parts.put("rightStick", rightStick); + } + + public void drop(final double finalY) { + (new BukkitRunnable() { + public void run() { + if (((ArmorStand)parts.get("middle")).getLocation().getY() > finalY + 1.0D) { + for (String part : parts.keySet()) + ((ArmorStand)parts.get(part)).teleport(((ArmorStand)parts.get(part)).getLocation().subtract(0.0D, 1.0D, 0.0D)); + } else { + for (String part : parts.keySet()) + ((ArmorStand)parts.get(part)).remove(); + cancel(); + } + } + }).runTaskTimer(this.main, 0L, 2L); + } + + private static ArmorStand makeNewArmorStand(World world, double x, double y, double z) { + Location asLoc = new Location(world, x, y, z); + ArmorStand as = (ArmorStand)asLoc.getWorld().spawn(asLoc, ArmorStand.class); + as.setBasePlate(false); + as.setArms(false); + as.setVisible(false); + as.setOp(true); + as.setCanPickupItems(false); + as.setGravity(false); + as.setSmall(false); + return as; + } +} \ No newline at end of file diff --git a/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyManager.java b/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyManager.java new file mode 100644 index 0000000..1d79d64 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyManager.java @@ -0,0 +1,112 @@ +package me.trixkz.lifestealcore.managers.envoys; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.normalmenusystem.ItemStackButton; +import me.trixkz.lifestealcore.utils.CustomLocation; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +@Getter +@Setter +public class EnvoyManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List envoys = new ArrayList(); + private List envoyLocations = new ArrayList(); + + private boolean started = false; + + public EnvoyManager() { + FileConfiguration fileConfiguration = this.main.getEnvoysConfig().getConfig(); + + ConfigurationSection configurationSection = fileConfiguration.getConfigurationSection("envoys"); + + AtomicInteger atomicInteger = new AtomicInteger(0); + + if (configurationSection == null) { + return; + } + + configurationSection.getKeys(false).forEach((number) -> { + List itemStacks = new ArrayList(); + List commands = new ArrayList(); + + double chance = 0; + + String name = configurationSection.getString(number + ".item-stacks." + atomicInteger + ".name"); + + List loreArrayList = configurationSection.getStringList(number + ".item-stacks." + atomicInteger + ".lore"); + + String[] lore = new String[loreArrayList.size()]; + + for (int i = 0; i < loreArrayList.size(); i++) { + lore[i] = loreArrayList.get(i); + } + + Material material = Material.getMaterial(configurationSection.getString(number + ".item-stacks." + atomicInteger + ".material")); + + int data = configurationSection.getInt(number + ".item-stacks." + atomicInteger + ".data"); + int amount = configurationSection.getInt(number + ".item-stacks." + atomicInteger + ".amount"); + + Map enchantments = new HashMap(); + + if (configurationSection.getStringList(number + ".item-stacks." + atomicInteger + ".enchantments") != null) { + configurationSection.getStringList(number + ".item-stacks." + atomicInteger + ".enchantments").forEach((string) -> { + String[] stringArray = string.split(":"); + + enchantments.put(Enchantment.getByName(stringArray[0]), Integer.parseInt(stringArray[1])); + }); + } + + ItemStackButton itemStackButton = new ItemStackButton(name, lore, material, data, amount); + + ItemStack itemStack = itemStackButton.makeItemStack(); + + if (enchantments.size() >= 1) { + itemStack.addEnchantments(enchantments); + } + + itemStacks.add(itemStack); + + chance = configurationSection.getDouble(number + ".chance"); + + this.envoys.add(new Envoy(new EnvoyReward(itemStacks, chance))); + + atomicInteger.addAndGet(1); + }); + + this.loadEnvoyLocations(); + } + + public void loadEnvoyLocations() { + this.main.getEnvoysConfig().getConfig().getStringList("envoy-locations").forEach((envoyLocation) -> { + this.envoyLocations.add(CustomLocation.stringToLocation(envoyLocation)); + }); + } + + public void saveEnvoyLocations() { + List envoyLocations = new ArrayList(); + + this.envoyLocations.forEach((envoyLocation) -> { + envoyLocations.add(CustomLocation.locationToString(envoyLocation)); + }); + + this.main.getEnvoysConfig().getConfig().set("envoy-locations", envoyLocations); + this.main.getEnvoysConfig().save(); + } + + public void startEnvoyEvent() { + this.started = true; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyReward.java b/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyReward.java new file mode 100644 index 0000000..2a326ba --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/envoys/EnvoyReward.java @@ -0,0 +1,30 @@ +package me.trixkz.lifestealcore.managers.envoys; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class EnvoyReward { + + private List itemStacks; + private double chance; + + public void givePlayerItemStacks(Player player) { + for (ItemStack itemStack : this.itemStacks) { + if (player.getInventory().firstEmpty() == -1) { + player.getWorld().dropItem(player.getEyeLocation(), itemStack); + } else { + player.getInventory().addItem(itemStack); + } + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/event/EventScheduledTime.java b/src/main/java/me/trixkz/lifestealcore/managers/event/EventScheduledTime.java new file mode 100644 index 0000000..316e048 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/event/EventScheduledTime.java @@ -0,0 +1,95 @@ +package me.trixkz.lifestealcore.managers.event; + +import com.google.common.primitives.Ints; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +import java.util.Calendar; +import java.util.Date; +import java.util.Objects; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class EventScheduledTime { + + private int day; + private int hour; + private int minutes; + + public static EventScheduledTime parse(String input) { + String[] inputSplit = input.split(" "); + + int days = Integer.parseInt(inputSplit[0]); + + String[] timeSplit = inputSplit[1].split(":"); + int hour = Integer.parseInt(timeSplit[0]); + int minutes = timeSplit.length > 1 ? Integer.parseInt(timeSplit[1]) : 0; + + return (new EventScheduledTime(days, hour, minutes)); + } + + public static EventScheduledTime parse(Date input) { + Calendar calendar = Calendar.getInstance(); + + calendar.setTime(input); + + int days = calendar.get(Calendar.DAY_OF_YEAR); + int hour = calendar.get(Calendar.HOUR_OF_DAY); + int minutes = calendar.get(Calendar.MINUTE); + + return (new EventScheduledTime(days, hour, minutes)); + } + + public Date toDate() { + Calendar activationTime = Calendar.getInstance(); + + activationTime.set(Calendar.DAY_OF_YEAR, day); + activationTime.set(Calendar.HOUR_OF_DAY, hour); + activationTime.set(Calendar.MINUTE, minutes); + activationTime.set(Calendar.SECOND, 0); + activationTime.set(Calendar.MILLISECOND, 0); + + return (activationTime.getTime()); + } + + + @Override + public boolean equals(Object object) { + if (object instanceof EventScheduledTime) { + EventScheduledTime other = (EventScheduledTime) object; + + return (other.day == this.day && other.hour == this.hour && other.minutes == this.minutes); + } + + return (false); + } + + + @Override + public int hashCode() { + return Objects.hash(day, hour, minutes); + } + + public int compare(EventScheduledTime other) { + int result = Ints.compare(day, other.day); + + if (result == 0) { + result = Ints.compare(hour, other.hour); + } + + if (result == 0) { + result = Ints.compare(minutes, other.minutes); + } + + return (result); + } + + @Override + public String toString() { + return (day + " " + hour + ":" + minutes); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/ChampionRankKillstreak.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/ChampionRankKillstreak.java new file mode 100644 index 0000000..6dc64e6 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/ChampionRankKillstreak.java @@ -0,0 +1,22 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; + +public class ChampionRankKillstreak extends Killstreak { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public ChampionRankKillstreak() { + super("Champion rank", LifeStealCore.getInstance().getSettingsConfig().getConfig().getInt("KILLSTREAKS.CHAMPION-RANK.KILLS-NEEDED"), new ItemBuilder(Material.NETHER_STAR).name(LifeStealCore.getInstance().getSettingsConfig().getConfig().getString("KILLSTREAKS.CHAMPION-RANK.ITEM.NAME")).lore(LifeStealCore.getInstance().getSettingsConfig().getConfig().getStringList("KILLSTREAKS.CHAMPION-RANK.ITEM.LORE")).build()); + } + + public KillstreaksCallable getKillstreaksCallable() { + return (player, playerData) -> { + this.main.getServer().broadcastMessage(Utils.translate(this.main.getSettingsConfig().getConfig().getString("KILLSTREAKS.MESSAGE").replace("%player%", player.getName()).replace("%killstreak%", String.valueOf(this.getKillstreak())))); + this.main.getServer().dispatchCommand(this.main.getServer().getConsoleSender(), "lp user " + player.getName() + " parent add Champion"); + }; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/EmperorRankKillstreak.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/EmperorRankKillstreak.java new file mode 100644 index 0000000..2450886 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/EmperorRankKillstreak.java @@ -0,0 +1,22 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; + +public class EmperorRankKillstreak extends Killstreak { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public EmperorRankKillstreak() { + super("Emperor rank", LifeStealCore.getInstance().getSettingsConfig().getConfig().getInt("KILLSTREAKS.EMPEROR-RANK.KILLS-NEEDED"), new ItemBuilder(Material.NETHER_STAR).name(LifeStealCore.getInstance().getSettingsConfig().getConfig().getString("KILLSTREAKS.EMPEROR-RANK.ITEM.NAME")).lore(LifeStealCore.getInstance().getSettingsConfig().getConfig().getStringList("KILLSTREAKS.EMPEROR-RANK.ITEM.LORE")).build()); + } + + public KillstreaksCallable getKillstreaksCallable() { + return (player, playerData) -> { + this.main.getServer().broadcastMessage(Utils.translate(this.main.getSettingsConfig().getConfig().getString("KILLSTREAKS.MESSAGE").replace("%player%", player.getName()).replace("%killstreak%", String.valueOf(this.getKillstreak())))); + this.main.getServer().dispatchCommand(this.main.getServer().getConsoleSender(), "lp user " + player.getName() + " parent add Emperor"); + }; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GodRankKillstreak.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GodRankKillstreak.java new file mode 100644 index 0000000..8cd2d82 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GodRankKillstreak.java @@ -0,0 +1,22 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; + +public class GodRankKillstreak extends Killstreak { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public GodRankKillstreak() { + super("God rank", LifeStealCore.getInstance().getSettingsConfig().getConfig().getInt("KILLSTREAKS.GOD-RANK.KILLS-NEEDED"), new ItemBuilder(Material.NETHER_STAR).name(LifeStealCore.getInstance().getSettingsConfig().getConfig().getString("KILLSTREAKS.GOD-RANK.ITEM.NAME")).lore(LifeStealCore.getInstance().getSettingsConfig().getConfig().getStringList("KILLSTREAKS.GOD-RANK.ITEM.LORE")).build()); + } + + public KillstreaksCallable getKillstreaksCallable() { + return (player, playerData) -> { + this.main.getServer().broadcastMessage(Utils.translate(this.main.getSettingsConfig().getConfig().getString("KILLSTREAKS.MESSAGE").replace("%player%", player.getName()).replace("%killstreak%", String.valueOf(this.getKillstreak())))); + this.main.getServer().dispatchCommand(this.main.getServer().getConsoleSender(), "lp user " + player.getName() + " parent add God"); + }; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GoldenApplesKillstreak.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GoldenApplesKillstreak.java new file mode 100644 index 0000000..9ec2e64 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GoldenApplesKillstreak.java @@ -0,0 +1,30 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public class GoldenApplesKillstreak extends Killstreak { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public GoldenApplesKillstreak() { + super("Golden apples", LifeStealCore.getInstance().getSettingsConfig().getConfig().getInt("KILLSTREAKS.GOLDEN-APPLES.KILLS-NEEDED"), new ItemBuilder(Material.NETHER_STAR).name(LifeStealCore.getInstance().getSettingsConfig().getConfig().getString("KILLSTREAKS.GOLDEN-APPLES.ITEM.NAME")).lore(LifeStealCore.getInstance().getSettingsConfig().getConfig().getStringList("KILLSTREAKS.GOLDEN-APPLES.ITEM.LORE")).build()); + } + + public KillstreaksCallable getKillstreaksCallable() { + return (player, playerData) -> { + this.main.getServer().broadcastMessage(Utils.translate(this.main.getSettingsConfig().getConfig().getString("KILLSTREAKS.MESSAGE").replace("%player%", player.getName()).replace("%killstreak%", String.valueOf(this.getKillstreak())))); + + if (player.getInventory().firstEmpty() == -1) { + player.sendMessage(Utils.translate("&cYour inventory is full")); + + return; + } + + player.getInventory().addItem(new ItemStack(Material.GOLDEN_APPLE, 8)); + }; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GrandMasterRankKillstreak.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GrandMasterRankKillstreak.java new file mode 100644 index 0000000..12db865 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/GrandMasterRankKillstreak.java @@ -0,0 +1,22 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; + +public class GrandMasterRankKillstreak extends Killstreak { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public GrandMasterRankKillstreak() { + super("Grand master rank", LifeStealCore.getInstance().getSettingsConfig().getConfig().getInt("KILLSTREAKS.GRAND-MASTER-RANK.KILLS-NEEDED"), new ItemBuilder(Material.NETHER_STAR).name(LifeStealCore.getInstance().getSettingsConfig().getConfig().getString("KILLSTREAKS.GRAND-MASTER-RANK.ITEM.NAME")).lore(LifeStealCore.getInstance().getSettingsConfig().getConfig().getStringList("KILLSTREAKS.GRAND-MASTER-RANK.ITEM.LORE")).build()); + } + + public KillstreaksCallable getKillstreaksCallable() { + return (player, playerData) -> { + this.main.getServer().broadcastMessage(Utils.translate(this.main.getSettingsConfig().getConfig().getString("KILLSTREAKS.MESSAGE").replace("%player%", player.getName()).replace("%killstreak%", String.valueOf(this.getKillstreak())))); + this.main.getServer().dispatchCommand(this.main.getServer().getConsoleSender(), "lp user " + player.getName() + " parent add GrandMaster"); + }; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/Killstreak.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/Killstreak.java new file mode 100644 index 0000000..8f80426 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/Killstreak.java @@ -0,0 +1,20 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import org.bukkit.inventory.ItemStack; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public abstract class Killstreak { + + private String name; + private int killstreak; + private ItemStack material; + + public abstract KillstreaksCallable getKillstreaksCallable(); +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/KillstreakManager.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/KillstreakManager.java new file mode 100644 index 0000000..21e69b0 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/KillstreakManager.java @@ -0,0 +1,37 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +public class KillstreakManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List killstreaks = new ArrayList(); + + public KillstreakManager() { + this.killstreaks.add(new RepairKillstreak()); + this.killstreaks.add(new ChampionRankKillstreak()); + this.killstreaks.add(new GoldenApplesKillstreak()); + this.killstreaks.add(new ResistanceKillstreak()); + this.killstreaks.add(new MasterRankKillstreak()); + this.killstreaks.add(new GrandMasterRankKillstreak()); + this.killstreaks.add(new EmperorRankKillstreak()); + this.killstreaks.add(new GodRankKillstreak()); + } + + public Killstreak getKillstreakByName(String string) { + for (Killstreak killstreak : this.killstreaks) { + if (killstreak.getName().equalsIgnoreCase(string)) { + return killstreak; + } + } + + return null; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/KillstreaksCallable.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/KillstreaksCallable.java new file mode 100644 index 0000000..a89685d --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/KillstreaksCallable.java @@ -0,0 +1,9 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import me.trixkz.lifestealcore.playerdata.PlayerData; +import org.bukkit.entity.Player; + +public interface KillstreaksCallable { + + void executeAs(Player player, PlayerData playerData); +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/MasterRankKillstreak.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/MasterRankKillstreak.java new file mode 100644 index 0000000..907a1d5 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/MasterRankKillstreak.java @@ -0,0 +1,22 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; + +public class MasterRankKillstreak extends Killstreak { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public MasterRankKillstreak() { + super("Master rank", LifeStealCore.getInstance().getSettingsConfig().getConfig().getInt("KILLSTREAKS.MASTER-RANK.KILLS-NEEDED"), new ItemBuilder(Material.NETHER_STAR).name(LifeStealCore.getInstance().getSettingsConfig().getConfig().getString("KILLSTREAKS.MASTER-RANK.ITEM.NAME")).lore(LifeStealCore.getInstance().getSettingsConfig().getConfig().getStringList("KILLSTREAKS.MASTER-RANK.ITEM.LORE")).build()); + } + + public KillstreaksCallable getKillstreaksCallable() { + return (player, playerData) -> { + this.main.getServer().broadcastMessage(Utils.translate(this.main.getSettingsConfig().getConfig().getString("KILLSTREAKS.MESSAGE").replace("%player%", player.getName()).replace("%killstreak%", String.valueOf(this.getKillstreak())))); + this.main.getServer().dispatchCommand(this.main.getServer().getConsoleSender(), "lp user " + player.getName() + " parent add Master"); + }; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/RepairKillstreak.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/RepairKillstreak.java new file mode 100644 index 0000000..9cd5847 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/RepairKillstreak.java @@ -0,0 +1,29 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Repairable; + +public class RepairKillstreak extends Killstreak { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public RepairKillstreak() { + super("Full repair", LifeStealCore.getInstance().getSettingsConfig().getConfig().getInt("KILLSTREAKS.FULL-REPAIR.KILLS-NEEDED"), new ItemBuilder(Material.NETHER_STAR).name(LifeStealCore.getInstance().getSettingsConfig().getConfig().getString("KILLSTREAKS.FULL-REPAIR.ITEM.NAME")).lore(LifeStealCore.getInstance().getSettingsConfig().getConfig().getStringList("KILLSTREAKS.FULL-REPAIR.ITEM.LORE")).build()); + } + + public KillstreaksCallable getKillstreaksCallable() { + return (player, playerData) -> { + this.main.getServer().broadcastMessage(Utils.translate(this.main.getSettingsConfig().getConfig().getString("KILLSTREAKS.MESSAGE").replace("%player%", player.getName()).replace("%killstreak%", String.valueOf(this.getKillstreak())))); + + for (ItemStack itemStack : player.getInventory().getArmorContents()) { + if (itemStack != null && itemStack.getItemMeta() instanceof Repairable) { + itemStack.setDurability((short) 0); + } + } + }; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/ResistanceKillstreak.java b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/ResistanceKillstreak.java new file mode 100644 index 0000000..c87461c --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/killstreaks/ResistanceKillstreak.java @@ -0,0 +1,25 @@ +package me.trixkz.lifestealcore.managers.killstreaks; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class ResistanceKillstreak extends Killstreak { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public ResistanceKillstreak() { + super("Resistance", LifeStealCore.getInstance().getSettingsConfig().getConfig().getInt("KILLSTREAKS.RESISTANCE.KILLS-NEEDED"), new ItemBuilder(Material.NETHER_STAR).name(LifeStealCore.getInstance().getSettingsConfig().getConfig().getString("KILLSTREAKS.RESISTANCE.ITEM.NAME")).lore(LifeStealCore.getInstance().getSettingsConfig().getConfig().getStringList("KILLSTREAKS.RESISTANCE.ITEM.LORE")).build()); + } + + public KillstreaksCallable getKillstreaksCallable() { + return (player, playerData) -> { + this.main.getServer().broadcastMessage(Utils.translate(this.main.getSettingsConfig().getConfig().getString("KILLSTREAKS.MESSAGE").replace("%player%", player.getName()).replace("%killstreak%", String.valueOf(this.getKillstreak())))); + + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 6000, 0)); + }; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/koth/KOTH.java b/src/main/java/me/trixkz/lifestealcore/managers/koth/KOTH.java new file mode 100644 index 0000000..82858bb --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/koth/KOTH.java @@ -0,0 +1,232 @@ +package me.trixkz.lifestealcore.managers.koth; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.events.*; +import me.trixkz.lifestealcore.utils.CustomLocation; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +@Getter +@Setter +public class KOTH { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private String name; + private String world; + private CustomLocation customLocation; + private int time; + private int distance; + private boolean active = false; + private boolean hidden = false; + + private UUID player; + private int remainingTime; + private boolean stop; + + public KOTH(String name, CustomLocation customLocation) { + this.name = name; + this.world = customLocation.getWorld(); + this.customLocation = customLocation; + this.time = 900; + this.distance = 3; + this.stop = false; + this.main.getKothManager().makeKOTH(this.name, this); + this.main.getKothManager().saveKOTHs(); + } + + public KOTH(String name, String world, CustomLocation customLocation, int time, int distance, boolean active, boolean hidden) { + this.name = name; + this.world = world; + this.customLocation = customLocation; + this.time = time; + this.distance = distance; + this.active = active; + this.hidden = hidden; + } + + public boolean enable() { + if (this.active) { + return false; + } + + KOTHEnabledEvent eventEnabledEvent = new KOTHEnabledEvent(this); + + this.main.getServer().getPluginManager().callEvent(eventEnabledEvent); + this.active = true; + this.player = null; + this.remainingTime = this.time; + this.stop = false; + + return true; + } + + public boolean disable() { + if (!this.active) { + return false; + } + + KOTHDisabledEvent eventDisabledEvent = new KOTHDisabledEvent(this); + + this.main.getServer().getPluginManager().callEvent(eventDisabledEvent); + this.active = false; + this.player = null; + this.remainingTime = this.time; + this.stop = false; + + return true; + } + + public void setActive(boolean active) { + this.active = active; + } + + public boolean isActive() { + return this.active; + } + + public void setHidden(boolean hidden) { + this.hidden = hidden; + this.main.getKothManager().saveKOTHs(); + } + + public boolean isHidden() { + return this.hidden; + } + + public void tick() { + if (this.player != null) { + Player player = this.main.getServer().getPlayer(this.player); + + if (player == null || !this.isInCapArea(player) || player.isDead() || player.getGameMode() != GameMode.SURVIVAL || player.hasMetadata("Invisible")) { + this.restartTime(); + } else { + if (this.remainingTime > 1 && this.remainingTime % 10 == 0 && !this.isHidden()) { + player.sendMessage(Utils.translate("&8[&9KOTH&8] &eYou are trying to cap &d" + this.name)); + } + + if (this.remainingTime > 1 && this.remainingTime % 60 == 0 && !this.isHidden()) { + for (Player playerOnline : this.main.getServer().getOnlinePlayers()) { + if (this.main.getClanManager().isAClanMember(playerOnline) && player != playerOnline) { + playerOnline.sendMessage(Utils.translate("&8[&9KOTH&8] &eYour island is capping &d" + this.name)); + } + } + } + + if (this.remainingTime <= 0) { + this.stopCapping(); + } else { + KOTHCapTickEvent eventCapTickEvent = new KOTHCapTickEvent(this); + + this.main.getServer().getPluginManager().callEvent(eventCapTickEvent); + } + + this.remainingTime--; + } + } else { + List players = new ArrayList(); + + for (Player player : this.main.getServer().getOnlinePlayers()) { + if (this.isInCapArea(player) && !player.isDead() && player.getGameMode() == GameMode.SURVIVAL && !player.hasMetadata("Invisible")) { + players.add(player); + } + } + + Collections.shuffle(players); + + if (players.size() != 0) { + this.startCapping(players.get(0)); + } + } + } + + public void setLocation(CustomLocation customLocation) { + this.customLocation = customLocation; + this.world = customLocation.getWorld(); + this.main.getKothManager().saveKOTHs(); + } + + public void setTime(int time) { + int oldTime = this.time; + + this.time = time; + + if (this.remainingTime > time) { + this.remainingTime = time; + } else if (this.remainingTime == oldTime) { + this.remainingTime = time; + } + + this.main.getKothManager().saveKOTHs(); + } + + public void setDistance(int distance) { + this.distance = distance; + this.main.getKothManager().saveKOTHs(); + } + + public void startCapping(Player player) { + if (this.player != null) { + this.restartTime(); + } + + this.player = player.getUniqueId(); + this.remainingTime = this.time; + } + + public boolean stopCapping() { + Player player = this.main.getServer().getPlayer(this.player); + + if (player == null) { + this.restartTime(); + + return false; + } + + KOTHCappedEvent eventCappedEvent = new KOTHCappedEvent(player, this); + + this.main.getServer().getPluginManager().callEvent(eventCappedEvent); + + if (eventCappedEvent.isCancelled()) { + this.restartTime(); + + return false; + } + + this.disable(); + + return true; + } + + public void restartTime() { + KOTHCapLostEvent kothCapLostEvent = new KOTHCapLostEvent(this); + + this.main.getServer().getPluginManager().callEvent(kothCapLostEvent); + this.player = null; + this.remainingTime = this.time; + + if (this.stop) { + this.disable(); + this.main.getServer().broadcastMessage(Utils.translate("&8[&9KOTH&8] &d" + this.name + " &ehas been stopped")); + } + } + + public boolean isInCapArea(Player player) { + if (!player.getLocation().getWorld().getName().equalsIgnoreCase(this.world)) { + return false; + } + + int x = Math.abs(player.getLocation().getBlockX() - this.customLocation.toBukkitLocation().getBlockX()); + int y = Math.abs(player.getLocation().getBlockY() - this.customLocation.toBukkitLocation().getBlockY()); + int z = Math.abs(player.getLocation().getBlockZ() - this.customLocation.toBukkitLocation().getBlockZ()); + + return x <= this.distance && y <= 5 && z <= this.distance; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/koth/KOTHManager.java b/src/main/java/me/trixkz/lifestealcore/managers/koth/KOTHManager.java new file mode 100644 index 0000000..ae08f38 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/koth/KOTHManager.java @@ -0,0 +1,250 @@ +package me.trixkz.lifestealcore.managers.koth; + +import com.mongodb.BasicDBObject; +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.managers.event.EventScheduledTime; +import me.trixkz.lifestealcore.utils.CustomLocation; +import me.trixkz.lifestealcore.utils.Utils; +import me.trixkz.lifestealcore.utils.config.FileConfig; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.scheduler.BukkitRunnable; +import java.io.File; +import java.util.*; + +@Getter +@Setter +public class KOTHManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private FileConfig kothsConfig = this.main.getKothsConfig(); + + private Map koths = new HashMap(); + private Map kothSchedule = new HashMap(); + + private boolean kothScheduledEnabled; + + public KOTHManager() { + this.loadKOTHs(); + this.loadKOTHSchedules(); + + new BukkitRunnable() { + @Override + public void run() { + for (KOTH koth : koths.values()) { + koth.tick(); + } + } + }.runTaskTimer(this.main, 5L, 20L); + + this.main.getServer().getScheduler().runTaskTimer(this.main, () -> { + this.enableKOTHs(); + }, 20L, 20L); + } + + public KOTH getKOTH(String name) { + return this.koths.get(name); + } + + public void makeKOTH(String name, KOTH koth) { + this.koths.put(name, koth); + } + + public void removeKOTH(String name) { + this.koths.remove(name); + } + + public void loadKOTHs() { + FileConfiguration fileConfiguration = this.kothsConfig.getConfig(); + + ConfigurationSection configurationSection = fileConfiguration.getConfigurationSection("koths"); + + if (configurationSection == null) { + return; + } + + configurationSection.getKeys(false).forEach(name -> { + String world = configurationSection.getString(name + ".world"); + + CustomLocation customLocation = CustomLocation.stringToLocation(configurationSection.getString(name + ".custom-location")); + + int time = configurationSection.getInt(name + ".time"); + int distance = configurationSection.getInt(name + ".distance"); + + boolean active = configurationSection.getBoolean(name + ".active"); + boolean hidden = configurationSection.getBoolean(name + ".hidden"); + + KOTH koth = new KOTH(name, world, customLocation, time, distance, active, hidden); + + this.koths.put(name, koth); + }); + + this.koths.values().stream().filter(KOTH:: isActive).findFirst().ifPresent((koth) -> { + koth.setActive(false); + + this.main.getServer().getScheduler().runTaskLater(this.main, () -> { + if (this.koths.values().stream().noneMatch(KOTH:: isActive)) { + koth.enable(); + } + }, 300L); + }); + } + + public void saveKOTHs() { + FileConfiguration fileConfiguration = this.kothsConfig.getConfig(); + fileConfiguration.set("koths", null); + + this.koths.forEach((name, koth) -> { + String world = koth.getWorld(); + String customLocation = CustomLocation.locationToString(koth.getCustomLocation()); + + int time = koth.getTime(); + int distance = koth.getDistance(); + + boolean active = koth.isActive(); + boolean hidden = koth.isHidden(); + + String root = "koths." + name; + + fileConfiguration.set(root + ".world", world); + fileConfiguration.set(root + ".custom-location", customLocation); + fileConfiguration.set(root + ".time", time); + fileConfiguration.set(root + ".distance", distance); + fileConfiguration.set(root + ".active", active); + fileConfiguration.set(root + ".hidden", hidden); + }); + + this.kothsConfig.save(); + } + + public void loadKOTHSchedules() { + this.kothSchedule.clear(); + + try { + File file = new File(this.main.getDataFolder(), "event-schedule.json"); + + if (!file.exists()) { + file.createNewFile(); + + BasicDBObject basicDBObjectOne = new BasicDBObject(); + + int currentDay = Calendar.getInstance().get(Calendar.DAY_OF_YEAR); + + List koths = new ArrayList(); + + for (KOTH koth : this.koths.values()) { + if (koth.isHidden()) { + continue; + } + + koths.add(koth.getName()); + } + + for (int dayOffset = 0; dayOffset < 21; dayOffset++) { + int day = (currentDay + dayOffset) % 365; + + EventScheduledTime[] eventScheduledTimes = new EventScheduledTime[]{ + new EventScheduledTime(day, 0, 0), // 00:30am EST + new EventScheduledTime(day, 1, 0), // 02:00am EST + new EventScheduledTime(day, 2, 0), // 03:30am EST + new EventScheduledTime(day, 3, 0), // 05:00am EST + new EventScheduledTime(day, 4, 0), // 06:30am EST + new EventScheduledTime(day, 5, 0), // 08:00am EST + new EventScheduledTime(day, 6, 0), // 09:30am EST + new EventScheduledTime(day, 7, 0), // 11:30am EST + new EventScheduledTime(day, 8, 0), // 01:30pm EST + new EventScheduledTime(day, 9, 0), // 15:30pm EST + new EventScheduledTime(day, 10, 0), // 17:00pm EST + new EventScheduledTime(day, 11, 0), // 18:30pm EST + new EventScheduledTime(day, 12, 0), // 20:00am EST + new EventScheduledTime(day, 13, 0), // 21:30pm EST + new EventScheduledTime(day, 14, 0), // 21:30pm EST + new EventScheduledTime(day, 15, 0), // 21:30pm EST + new EventScheduledTime(day, 16, 0), // 21:30pm EST + new EventScheduledTime(day, 17, 0), // 21:30pm EST + new EventScheduledTime(day, 18, 0), // 21:30pm EST + new EventScheduledTime(day, 19, 0), // 21:30pm EST + new EventScheduledTime(day, 20, 0), // 21:30pm EST + new EventScheduledTime(day, 21, 0), // 21:30pm EST + new EventScheduledTime(day, 22, 0), // 21:30pm EST + new EventScheduledTime(day, 23, 0) // 21:30pm EST + }; + + Collections.shuffle(koths); + + if (!koths.isEmpty()) { + for (int i = 0; i < eventScheduledTimes.length; i++) { + EventScheduledTime eventScheduledTime = eventScheduledTimes[i]; + + String name = koths.get(i % koths.size()); + + basicDBObjectOne.put(eventScheduledTime.toString(), name); + } + } + } + +// FileUtils.write(file, JSON.serialize(basicDBObjectOne.toString())); + } + +// BasicDBObject basicDBObjectTwo = (BasicDBObject) JSON.parse(FileUtils.readFileToString(file)); +// +// if (basicDBObjectTwo == null) { +// return; +// } +// +// for (Map.Entry mapEntry : basicDBObjectTwo.entrySet()) { +// EventScheduledTime eventScheduledTime = EventScheduledTime.parse(mapEntry.getKey()); +// +// this.kothSchedule.put(eventScheduledTime, String.valueOf(mapEntry.getValue())); +// } + } catch (Exception exception) { + exception.printStackTrace(); + } + } + + public void enableKOTHs() { + for (KOTH koth : this.koths.values()) { + if (koth.isActive()) { + return; + } + } + + EventScheduledTime eventScheduledTime = EventScheduledTime.parse(new Date()); + + if (this.kothSchedule.containsKey(eventScheduledTime)) { + String name = this.kothSchedule.get(eventScheduledTime); + + KOTH koth = this.koths.get(name); + + if (this.main.getServer().getOnlinePlayers().size() < 1) { + this.kothSchedule.remove(eventScheduledTime); + this.main.getServer().broadcastMessage(Utils.translate("&cA KOTH would of started, but there are less than 1 player online")); + + return; + } + + koth.enable(); + } + } + + public void setEventSchedule() { + List koths = new ArrayList(); + + for (KOTH koth : this.koths.values()) { + if (koth.isHidden()) { + continue; + } + + koths.add(koth.getName()); + } + + for (int minute = 0; minute < 60; minute++) { + for (int hour = 0; hour < 24; hour++) { + this.kothSchedule.put(new EventScheduledTime(Calendar.getInstance().get(Calendar.DAY_OF_YEAR), (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) + hour) % 24, minute), koths.get(0)); + } + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/leaderboards/Leaderboard.java b/src/main/java/me/trixkz/lifestealcore/managers/leaderboards/Leaderboard.java new file mode 100644 index 0000000..f3eda91 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/leaderboards/Leaderboard.java @@ -0,0 +1,130 @@ +package me.trixkz.lifestealcore.managers.leaderboards; + +import eu.decentsoftware.holograms.api.holograms.Hologram; +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.CustomLocation; + +@Getter +@Setter +public class Leaderboard { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private Hologram hologram; + + private int hologramTaskId; + + private CustomLocation customLocation; + + private int time = 0; + private int realTime = 0; + + private String name; + private String statistic; + + private int index = 0; + +// public Leaderboard(CustomLocation customLocation, int time) { +// this.customLocation = customLocation; +// this.time = time; +// this.realTime = time; +// this.hologram = HologramsAPI.createHologram(this.main, this.customLocation.toBukkitLocation()); +// } +// +// public void start() { +// this.update(); +// this.hologramTaskId = this.main.getServer().getScheduler().scheduleSyncRepeatingTask(this.main, new Runnable() { +// @Override +// public void run() { +// hologram.clearLines(); +// +// tick(); +// } +// }, 0L, 20L); +// } +// +// public void tick() { +// this.realTime--; +// +// if (this.realTime < 1) { +// this.update(); +// this.realTime = this.time; +// } +// +// this.updateLines(); +// } +// +// public void update() { +// if ((this.index + 1) > 4) { +// this.index = 0; +// } +// +// switch (this.index) { +// case 0: +// this.name = "Kills"; +// this.statistic = "kills"; +// +// break; +// case 1: +// this.name = "Deaths"; +// this.statistic = "deaths"; +// +// break; +// case 2: +// this.name = "Coins"; +// this.statistic = "coins"; +// +// break; +// case 3: +// this.name = "Tokens"; +// this.statistic = "tokens"; +// +// break; +// } +// +// this.index++; +// } +// +// public void updateLines() { +// AtomicInteger atomicInteger = new AtomicInteger(1); +// +// int index = 4; +// +// this.hologram.insertTextLine(0, Utils.translate("&d&lLeaderboard")); +// this.hologram.insertTextLine(1, Utils.translate("")); +// this.hologram.insertTextLine(2, Utils.translate("&9⚫ " + this.name + " ⚫")); +// this.hologram.insertTextLine(3, Utils.translate("")); +// +// try (MongoCursor iterator = this.main.getPlayerDataManager().getPlayersSorted(this.statistic)) { +// while (iterator.hasNext()) { +// try { +// Document document = iterator.next(); +// +// if (document.getString("unique-id") == null) { +// continue; +// } +// +// UUID uuid = UUID.fromString(document.getString("unique-id")); +// +// int statistic = document.getInteger(this.statistic); +// +// this.hologram.insertTextLine(index, Utils.translate("&d#" + atomicInteger.get() + " &f" + (this.main.getServer().getOfflinePlayer(uuid).getName() != null ? this.main.getServer().getOfflinePlayer(uuid).getName() : "?????") + " &7➤ &f" + statistic)); +// } catch (Exception exception) { +// exception.printStackTrace(); +// } +// +// atomicInteger.addAndGet(1); +// +// index++; +// } +// } +// +// this.hologram.insertTextLine(index, Utils.translate("")); +// +// index++; +// +// this.hologram.insertTextLine(index, Utils.translate("&7Next update in " + this.realTime)); +// } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/leaderboards/LeaderboardManager.java b/src/main/java/me/trixkz/lifestealcore/managers/leaderboards/LeaderboardManager.java new file mode 100644 index 0000000..c41e3fb --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/leaderboards/LeaderboardManager.java @@ -0,0 +1,23 @@ +package me.trixkz.lifestealcore.managers.leaderboards; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; + +@Getter +@Setter +public class LeaderboardManager { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private Leaderboard leaderboard; + + public LeaderboardManager() { + if (this.main.getSpawnManager().getHologramsLocation() == null) { + this.main.getLogger().info("[Leaderboard] Please set leaderboard hologram using /setspawn holograms and then restart"); + } else { +// this.leaderboard = new Leaderboard(this.main.getSpawnManager().getHologramsLocation(), 15); +// this.leaderboard.start(); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/ArcherClass.java b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/ArcherClass.java new file mode 100644 index 0000000..4bc2433 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/ArcherClass.java @@ -0,0 +1,222 @@ +package me.trixkz.lifestealcore.managers.pvpclass; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.playerdata.PlayerState; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Pair; +import me.trixkz.lifestealcore.utils.TimeUtils; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import java.util.*; +import java.util.concurrent.TimeUnit; + +@Getter +@Setter +public class ArcherClass extends PvPClass { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private Map taggedPlayers = new HashMap(); + private Map>> taggedByPlayers = new HashMap>>(); + private Map lastSpeedUsage = new HashMap(); + private Map lastJumpUsage = new HashMap(); + + private int tagSeconds = 7; + + public ArcherClass() { + super("Archer", 5, Arrays.asList(Material.SUGAR, Material.FEATHER)); + } + + @Override + public void apply(Player player) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2)); + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); + } + + @Override + public void tick(Player player) { + if (!player.hasPotionEffect(PotionEffectType.SPEED)) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2)); + } + + if (!player.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE)) { + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); + } + } + + @Override + public void remove(Player player) { + + } + + @Override + public boolean isItemConsumed(Player player, Material material) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData.getPlayerState() != PlayerState.WARZONE) { + player.sendMessage(Utils.translate(Constants.PREFIX + "You can only use this in the warzone")); + + return false; + } + + if (material == Material.SUGAR) { + if (this.lastSpeedUsage.containsKey(player.getUniqueId())) { + if (this.lastSpeedUsage.get(player.getUniqueId()) > System.currentTimeMillis()) { + long amountOfTimeLeft = this.lastSpeedUsage.get(player.getUniqueId()) - System.currentTimeMillis(); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You can not use this for another " + TimeUtils.formatIntoDetailedString((int) amountOfTimeLeft / 1000))); + + return false; + } + } + + this.lastSpeedUsage.put(player.getUniqueId(), System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(30)); + + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 3)); + + return true; + } else if (material == Material.FEATHER) { + if (this.lastJumpUsage.containsKey(player.getUniqueId())) { + if (this.lastJumpUsage.get(player.getUniqueId()) > System.currentTimeMillis()) { + long amountOfTimeLeft = this.lastJumpUsage.get(player.getUniqueId()) - System.currentTimeMillis(); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You can not use this for another " + TimeUtils.formatIntoDetailedString((int) amountOfTimeLeft / 1000))); + + return false; + } + } + + this.lastSpeedUsage.put(player.getUniqueId(), System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(30)); + + player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 100, 4)); + + // to do - make a spawn tag manager + + return true; + } + + return false; + } + + @Override + public boolean qualifies(Player player) { + return this.hasAllArmor(player) && player.getInventory().getHelmet().getType() == Material.LEATHER_HELMET && player.getInventory().getChestplate().getType() == Material.LEATHER_CHESTPLATE && player.getInventory().getLeggings().getType() == Material.LEATHER_LEGGINGS && player.getInventory().getBoots().getType() == Material.LEATHER_BOOTS; + } + + @EventHandler + public void onEntityDamageByEntityOne(EntityDamageByEntityEvent event) { + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + + if (this.isTagged(player)) { + Player damager = null; + if (event.getDamager() instanceof Player) { + damager = (Player) event.getDamager(); + } else if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player) { + damager = (Player) ((Projectile) event.getDamager()).getShooter(); + } + + if (damager != null && !this.canUseTag(damager, player)) { + return; + } + + event.setDamage(event.getDamage() * 1.25D); + } + } + } + + @EventHandler + public void onEntityDamageByEntityTwo(EntityDamageByEntityEvent event) { + if (event.getEntity() instanceof Player && event.getDamager() instanceof Arrow) { + Arrow arrow = (Arrow) event.getDamager(); + + Player victim = (Player) event.getEntity(); + + if (!(arrow.getShooter() instanceof Player)) { + return; + } + + Player shooter = (Player) arrow.getShooter(); + + float pullback = arrow.getMetadata("Archer bow pullback").get(0).asFloat(); + + if (!this.main.getPvpClassManager().hasPvPClassOn(shooter, this)) { + return; + } + + int damage = this.isTagged(victim) ? 4 : 3; + + if (pullback < 0.5F) { + damage = 2; + } + + if (victim.getHealth() - damage <= 0D) { + event.setCancelled(true); + } else { + event.setDamage(0D); + } + + Location shotFrom = (Location) arrow.getMetadata("Archer bow shot from distance").get(0).value(); + + double distance = shotFrom.distance(victim.getLocation()); + + victim.setHealth(Math.max(0D, victim.getHealth() - damage)); + + if (this.main.getPvpClassManager().hasPvPClassOn(victim, this)) { + shooter.sendMessage(Utils.translate("&8[&9Arrow Range &8(&d" + ((int) distance) + "&8)] &eCan not tag other archers &8(&d" + (damage / 2) + " heart" + (((damage / 2) == 1) ? "" : "s") + "&8)")); + } else if (pullback >= 0.5F) { + shooter.sendMessage(Utils.translate("&8[&9Arrow Range &8(&d" + ((int) distance) + "&8)] &eTagged player for " + this.tagSeconds + " seconds &8(&d" + (damage / 2) + " heart" + (((damage / 2) == 1) ? "" : "s") + "&8)")); + + if (!this.isTagged(victim)) { + victim.sendMessage(Utils.translate("&8[&9Tagged&8] &eAn archer has shot you and tagged you (+25% damage) for " + this.tagSeconds + " seconds")); + } + + this.taggedPlayers.put(victim.getUniqueId(), System.currentTimeMillis() + (this.tagSeconds * 1000)); + + this.taggedByPlayers.putIfAbsent(shooter.getUniqueId(), new HashSet<>()); + this.taggedByPlayers.get(shooter.getUniqueId()).add(new Pair(victim.getUniqueId(), System.currentTimeMillis() + (this.tagSeconds * 1000))); + } else { + shooter.sendMessage(Utils.translate("&8[&9Arrow Range &8(&d" + ((int) distance) + "&8)] &eBow was not fully pulled back &8(&d" + (damage / 2) + " heart" + (((damage / 2) == 1) ? "" : "s") + "&8)")); + } + } + } + + @EventHandler + public void onEntityShootBow(EntityShootBowEvent event) { + event.getProjectile().setMetadata("Archer bow pullback", new FixedMetadataValue(this.main, event.getForce())); + event.getProjectile().setMetadata("Archer bow shot from distance", new FixedMetadataValue(this.main, event.getProjectile().getLocation())); + } + + public boolean canUseTag(Player player, Player target) { + if (this.taggedByPlayers.containsKey(player.getUniqueId())) { + for (Pair taggedByPlayer : this.taggedByPlayers.get(player.getUniqueId())) { + if (target.getUniqueId().equals(taggedByPlayer.getFirstPair()) && taggedByPlayer.getSecondPair() > System.currentTimeMillis()) { + return false; + } + } + } + + return true; + } + + public boolean isTagged(Player player) { + if (!this.taggedPlayers.containsKey(player.getUniqueId())) { + return false; + } + + return this.taggedPlayers.get(player.getUniqueId()) > System.currentTimeMillis(); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/BardClass.java b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/BardClass.java new file mode 100644 index 0000000..cc903a8 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/BardClass.java @@ -0,0 +1,318 @@ +package me.trixkz.lifestealcore.managers.pvpclass; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.managers.clans.Clan; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.playerdata.PlayerState; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import java.util.*; + +@Getter +@Setter +public class BardClass extends PvPClass { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private Map clickEffects = new HashMap(); + private Map passiveEffects = new HashMap(); + private Map energy = new HashMap(); + private Map lastEffectUsage = new HashMap(); + + private int range = 40; + private int effectCooldown = 10000; + private float maximumEnergy = 120; + private float energyRegenerationPerSecond = 1; + + public BardClass() { + super("Bard", 5, null); + + this.clickEffects.put(Material.BLAZE_POWDER, new BardEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 100, 1), 45)); + this.clickEffects.put(Material.SUGAR, new BardEffect(new PotionEffect(PotionEffectType.SPEED, 120, 2), 20)); + this.clickEffects.put(Material.FEATHER, new BardEffect(new PotionEffect(PotionEffectType.JUMP, 100, 6), 25)); + this.clickEffects.put(Material.IRON_INGOT, new BardEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 100, 2), 40)); + this.clickEffects.put(Material.GHAST_TEAR, new BardEffect(new PotionEffect(PotionEffectType.REGENERATION, 100, 2), 40)); + this.clickEffects.put(Material.MAGMA_CREAM, new BardEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 900, 0), 40)); + this.clickEffects.put(Material.INK_SAC, new BardEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 900, 1), 35)); + this.clickEffects.put(Material.SPIDER_EYE, new BardEffect(new PotionEffect(PotionEffectType.WITHER, 100, 1), 35)); + this.clickEffects.put(Material.WHEAT, new BardEffect(null, 25)); + this.passiveEffects.put(Material.BLAZE_POWDER, new BardEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 100, 1), 45)); + this.passiveEffects.put(Material.SUGAR, new BardEffect(new PotionEffect(PotionEffectType.SPEED, 120, 2), 20)); + this.passiveEffects.put(Material.FEATHER, new BardEffect(new PotionEffect(PotionEffectType.JUMP, 100, 6), 25)); + this.passiveEffects.put(Material.IRON_INGOT, new BardEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 100, 2), 40)); + this.passiveEffects.put(Material.GHAST_TEAR, new BardEffect(new PotionEffect(PotionEffectType.REGENERATION, 100, 2), 40)); + this.passiveEffects.put(Material.MAGMA_CREAM, new BardEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 900, 0), 40)); + this.passiveEffects.put(Material.INK_SAC, new BardEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 900, 1), 35)); + + new BukkitRunnable() { + @Override + public void run() { + for (Player player : main.getServer().getOnlinePlayers()) { + PlayerData playerData = main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (!main.getPvpClassManager().hasPvPClassOn(player, BardClass.this) || playerData.getPlayerState() != PlayerState.WARZONE) { + continue; + } + + if (energy.containsKey(player.getUniqueId())) { + if (energy.get(player.getUniqueId()) == maximumEnergy) { + continue; + } + + energy.put(player.getUniqueId(), Math.min(maximumEnergy, energy.get(player.getUniqueId()) + energyRegenerationPerSecond)); + } else { + energy.put(player.getUniqueId(), 0F); + } + + int energyNumber = energy.get(player.getUniqueId()).intValue(); + + if (energyNumber % 10 == 0) { + player.sendMessage(Utils.translate("&8[&9Bard&8] &eBard energy: " + energyNumber)); + } + } + } + }.runTaskTimer(this.main, 15L, 20L); + } + + @Override + public void apply(Player player) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1)); + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 0)); + + if (playerData.getPlayerState() != PlayerState.WARZONE) { + player.sendMessage(Utils.translate(Constants.PREFIX + "You can only use this in the warzone")); + } + } + + @Override + public void tick(Player player) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (!player.hasPotionEffect(PotionEffectType.SPEED)) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1)); + } + + if (!player.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE)) { + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); + } + + if (!player.hasPotionEffect(PotionEffectType.REGENERATION)) { + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 0)); + } + + if (player.getItemInHand() != null) { + if (this.passiveEffects.containsKey(player.getItemInHand().getType()) && playerData.getPlayerState() == PlayerState.WARZONE) { + this.giveBardEffect(player, this.passiveEffects.get(player.getItemInHand().getType())); + } + } + } + + @Override + public void remove(Player player) { + this.energy.remove(player.getUniqueId()); + + for (BardEffect bardEffect : this.clickEffects.values()) { + bardEffect.getLastMessageSent().remove(player.getUniqueId()); + } + + for (BardEffect bardEffect : this.passiveEffects.values()) { + bardEffect.getLastMessageSent().remove(player.getUniqueId()); + } + } + + @Override + public boolean isItemConsumed(Player player, Material material) { + return true; + } + + @Override + public boolean qualifies(Player player) { + return this.hasAllArmor(player) && player.getInventory().getHelmet().getType() == Material.GOLDEN_HELMET && player.getInventory().getChestplate().getType() == Material.GOLDEN_CHESTPLATE && player.getInventory().getLeggings().getType() == Material.GOLDEN_LEGGINGS && player.getInventory().getBoots().getType() == Material.GOLDEN_BOOTS; + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (!event.hasItem() || !event.getAction().name().contains("RIGHT_") || !this.clickEffects.containsKey(event.getItem().getType()) || !this.main.getPvpClassManager().hasPvPClassOn(player, this) || !energy.containsKey(player.getUniqueId())) { + return; + } + + if (playerData.getPlayerState() != PlayerState.WARZONE) { + player.sendMessage(Utils.translate(Constants.PREFIX + "You can only use this in the warzone")); + + return; + } + + if (this.lastEffectUsage.containsKey(player.getUniqueId())) { + if (this.lastEffectUsage.get(player.getUniqueId()) > System.currentTimeMillis() && player.getGameMode() != GameMode.CREATIVE) { + long amountOfTimeLeft = this.lastEffectUsage.get(player.getUniqueId()) - System.currentTimeMillis(); + + double value = amountOfTimeLeft / 1000; + double amountOfTimeInSeconds = Math.round(10 * value) / 10; + + player.sendMessage(Utils.translate("&8[&9Bard&8] &eYou can not use this for another " + amountOfTimeInSeconds + " seconds")); + + return; + } + } + + BardEffect bardEffect = this.clickEffects.get(event.getItem().getType()); + + if (bardEffect.getEnergy() > this.energy.get(player.getUniqueId())) { + player.sendMessage(Utils.translate("&8[&9Bard&8] &eYou do not have enough energy for this, you need " + bardEffect.getEnergy() + " energy, but you have " + this.energy.get(player.getUniqueId()).intValue() + " energy")); + + return; + } + + String string = ""; + + int amountOfPlayers = this.getNearbyPlayers(player).size(); + + switch (event.getItem().getType()) { + case BLAZE_POWDER: + string = "&4Strength 2"; + + break; + case SUGAR: + string = "&bSpeed 3"; + + break; + case FEATHER: + string = "&fJump Boost 7"; + + break; + case IRON_INGOT: + string = "&9Resistance 3"; + + break; + case GHAST_TEAR: + string = "&dRegeneration 3"; + + break; + case MAGMA_CREAM: + string = "&cFire Resistance 1"; + + break; + case INK_SAC: + string = "&fInvisibility 2"; + + break; + case SPIDER_EYE: + string = "&0Wither 1"; + + break; + } + + if (amountOfPlayers == 1) { + player.sendMessage(Utils.translate("&8[&9Bard&8] &eYou have given " + string + " &eto yourself")); + } else { + player.sendMessage(Utils.translate("&8[&9Bard&8] &eYou have given " + string + " &eto " + amountOfPlayers + " players")); + } + + this.giveBardEffect(player, bardEffect); + this.energy.put(player.getUniqueId(), this.energy.get(player.getUniqueId()) - bardEffect.getEnergy()); + this.lastEffectUsage.put(player.getUniqueId(), System.currentTimeMillis() + this.effectCooldown); + + if (player.getItemInHand().getAmount() == 1) { + player.setItemInHand(new ItemStack(Material.AIR)); + player.updateInventory(); + } else { + player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1); + } + } + + public void giveBardEffect(Player player, BardEffect bardEffect) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + for (Player playerNearPlayer : this.getNearbyPlayers(player)) { + if (playerData.getPlayerState() != PlayerState.WARZONE) { + continue; + } + + if (this.main.getPvpClassManager().hasPvPClassOn(playerNearPlayer, this)) { + if (bardEffect.getPotionEffect() != null) { + if (bardEffect.getPotionEffect().getType().equals(PotionEffectType.INCREASE_DAMAGE)) { + continue; + } + } + } + + if (bardEffect.getPotionEffect() != null) { + for (PotionEffect potionEffect : playerNearPlayer.getActivePotionEffects()) { + new BukkitRunnable() { + @Override + public void run() { + playerNearPlayer.addPotionEffect(potionEffect); + } + }.runTaskLater(this.main, bardEffect.getPotionEffect().getDuration() + 2); + } + + this.addPotionEffect(player, bardEffect.getPotionEffect()); + } else { + Material material = player.getItemInHand().getType(); + + this.giveBardEffect(playerNearPlayer, material); + } + } + } + + public void giveBardEffect(Player player, Material material) { + switch (material) { + case FERMENTED_SPIDER_EYE: + break; + } + } + + public List getNearbyPlayers(Player player) { + List players = new ArrayList(); + players.add(player); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData.getClanOwner() == null) { + return players; + } + + Clan clan = this.main.getClanManager().getClan(playerData.getClanOwner()); + + if (clan == null) { + return players; + } + + for (Entity entity : player.getNearbyEntities(this.range, this.range / 2, this.range)) { + if (entity instanceof Player) { + Player playerNearPlayer = (Player) entity; + + PlayerData playerNearPlayerPlayerData = this.main.getPlayerDataManager().getPlayerData(playerNearPlayer.getUniqueId()); + + if (playerNearPlayerPlayerData.getPlayerState() != PlayerState.WARZONE) { + continue; + } + + if (this.main.getClanManager().isAClanMember(playerNearPlayer)) { + players.add(playerNearPlayer); + } + } + } + + return players; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/BardEffect.java b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/BardEffect.java new file mode 100644 index 0000000..65990e8 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/BardEffect.java @@ -0,0 +1,26 @@ +package me.trixkz.lifestealcore.managers.pvpclass; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import org.bukkit.potion.PotionEffect; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@Getter +@Setter +public class BardEffect { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private PotionEffect potionEffect; + private int energy; + + private Map lastMessageSent = new HashMap(); + + public BardEffect(PotionEffect potionEffect, int energy) { + this.potionEffect = potionEffect; + this.energy = energy; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/PvPClass.java b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/PvPClass.java new file mode 100644 index 0000000..1d3413c --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/PvPClass.java @@ -0,0 +1,102 @@ +package me.trixkz.lifestealcore.managers.pvpclass; + +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.Collection; +import java.util.List; +import java.util.UUID; + +@Getter +@Setter +public abstract class PvPClass implements Listener { + + private String name; + private int warmupTime; + private List consumables; + + private Table restores = HashBasedTable.create(); + + public PvPClass(String name, int warmupTime, List consumables) { + this.name = name; + this.warmupTime = warmupTime; + this.consumables = consumables; + } + + public void apply(Player player) { + + } + + public void tick(Player player) { + + } + + public void remove(Player player) { + + } + + public boolean canApply(Player player) { + return true; + } + + public boolean isItemConsumed(Player player, Material material) { + return true; + } + + public abstract boolean qualifies(Player player); + + protected boolean hasAllArmor(Player player) { + return player.getInventory().getHelmet() != null && player.getInventory().getChestplate() != null && player.getInventory().getLeggings() != null && player.getInventory().getBoots() != null; + } + + public void addPotionEffect(Player player, PotionEffect potionEffect) { + this.setRestorePotionEffect(player, potionEffect); + } + + public void setRestorePotionEffect(Player player, PotionEffect potionEffect) { + boolean cancel = true; + + Collection activePotionEffects = player.getActivePotionEffects(); + + for (PotionEffect activePotionEffect : activePotionEffects) { + if (!potionEffect.getType().equals(activePotionEffect.getType())) { + continue; + } + + if (potionEffect.getAmplifier() < activePotionEffect.getAmplifier()) { + return; + } else if (potionEffect.getAmplifier() == activePotionEffect.getAmplifier()) { + if ((potionEffect.getDuration() <= activePotionEffect.getDuration() || potionEffect.getDuration() - activePotionEffect.getDuration() < 10) && activePotionEffect.getDuration() > 0) { + return; + } + } + + this.restores.put(player.getUniqueId(), activePotionEffect.getType(), activePotionEffect); + + cancel = false; + + break; + } + + player.addPotionEffect(potionEffect, true); + + if (cancel && potionEffect.getDuration() > 120 && potionEffect.getDuration() < 9600) { + this.restores.remove(player.getUniqueId(), potionEffect.getType()); + } + } + + public void removeInfiniteEffects(Player player) { + for (PotionEffect potionEffect : player.getActivePotionEffects()) { + if (potionEffect.getDuration() > 1_000_000) { + player.removePotionEffect(potionEffect.getType()); + } + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/PvPClassManager.java b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/PvPClassManager.java new file mode 100644 index 0000000..3a38788 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/PvPClassManager.java @@ -0,0 +1,183 @@ +package me.trixkz.lifestealcore.managers.pvpclass; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.potion.PotionEffect; + +import java.util.*; + +@Getter +@Setter +public class PvPClassManager implements Listener { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private List pvpClasses = new ArrayList(); + private Map equippedPvPClasses = new HashMap(); + private Map savedPotionEffects = new HashMap(); + + public PvPClassManager() { + ArcherClass archerClass = new ArcherClass(); + + this.pvpClasses.add(archerClass); + + BardClass bardClass = new BardClass(); + + this.pvpClasses.add(bardClass); + + TankClass tankClass = new TankClass(); + + this.pvpClasses.add(tankClass); + + for (PvPClass pvpClass : this.pvpClasses) { + this.main.getServer().getPluginManager().registerEvents(pvpClass, this.main); + } + + this.main.getServer().getScheduler().runTaskTimer(this.main, () -> { + for (Player player : this.main.getServer().getOnlinePlayers()) { + if (this.equippedPvPClasses.containsKey(player.getUniqueId())) { + PvPClass pvpClass = this.equippedPvPClasses.get(player.getUniqueId()); + + if (!pvpClass.qualifies(player)) { + this.equippedPvPClasses.remove(player.getUniqueId()); + + pvpClass.remove(player); + pvpClass.removeInfiniteEffects(player); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You have disabled the " + pvpClass.getName() + " class")); + } else if (!player.hasMetadata("Player frozen")) { + pvpClass.tick(player); + } + } else { + for (PvPClass pvpClass : this.pvpClasses) { + if (pvpClass.qualifies(player) && pvpClass.canApply(player) && !player.hasMetadata("Player frozen")) { + this.equippedPvPClasses.put(player.getUniqueId(), pvpClass); + + pvpClass.apply(player); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You have enabled the " + pvpClass.getName() + " class")); + + break; + } + } + } + } + + this.lookAtSavedPotionEffects(); + }, 2L, 2L); + } + + public PvPClass getPvPClass(Player player) { + return this.equippedPvPClasses.getOrDefault(player.getUniqueId(), null); + } + + public boolean hasPvPClassOn(Player player, PvPClass pvpClass) { + if (!this.equippedPvPClasses.containsKey(player.getUniqueId())) { + return false; + } + + return this.equippedPvPClasses.get(player.getUniqueId()) == pvpClass; + } + + public void lookAtSavedPotionEffects() { + Iterator> iteratorOne = this.savedPotionEffects.entrySet().iterator(); + + while (iteratorOne.hasNext()) { + Map.Entry iteratorTwo = iteratorOne.next(); + + Player player = this.main.getServer().getPlayer(iteratorTwo.getKey()); + + if (player != null) { + if (System.currentTimeMillis() > iteratorTwo.getValue().getTime() && !iteratorTwo.getValue().isPermanent()) { + if (player.hasPotionEffect(iteratorTwo.getValue().getPotionEffect().getType())) { + player.getActivePotionEffects().forEach(activePotionEffect -> { + PotionEffect potionEffect = iteratorTwo.getValue().getPotionEffect(); + + if (potionEffect.getType() == activePotionEffect.getType() && potionEffect.getDuration() > activePotionEffect.getDuration() && potionEffect.getAmplifier() >= activePotionEffect.getAmplifier()) { + player.removePotionEffect(potionEffect.getType()); + } + }); + } + + if (player.addPotionEffect(iteratorTwo.getValue().getPotionEffect(), true)) { + iteratorOne.remove(); + } + } + } else { + iteratorOne.remove(); + } + } + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + if (this.equippedPvPClasses.containsKey(player.getUniqueId())) { + this.equippedPvPClasses.get(player.getUniqueId()).remove(player); + this.equippedPvPClasses.remove(player.getUniqueId()); + } + + for (PotionEffect potionEffect : player.getActivePotionEffects()) { + if (potionEffect.getDuration() > 1_000_000) { + player.removePotionEffect(potionEffect.getType()); + } + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + + if (this.equippedPvPClasses.containsKey(player.getUniqueId())) { + this.equippedPvPClasses.get(player.getUniqueId()).remove(player); + this.equippedPvPClasses.remove(player.getUniqueId()); + } + } + + @EventHandler + public void onPlayerKick(PlayerKickEvent event) { + Player player = event.getPlayer(); + + if (this.equippedPvPClasses.containsKey(player.getUniqueId())) { + this.equippedPvPClasses.get(player.getUniqueId()).remove(player); + this.equippedPvPClasses.remove(player.getUniqueId()); + } + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + + if ((event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) || player.getItemInHand() == null) { + return; + } + + for (PvPClass pvpClass : this.pvpClasses) { + if (pvpClass.getConsumables() == null) { + continue; + } + + if (this.hasPvPClassOn(player, pvpClass) && pvpClass.getConsumables().contains(player.getItemInHand().getType())) { + if (pvpClass.isItemConsumed(player, event.getItem().getType())) { + if (player.getItemInHand().getAmount() > 1) { + player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1); + } else { + player.getInventory().remove(player.getItemInHand()); + } + } + } + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/SavedPotionEffect.java b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/SavedPotionEffect.java new file mode 100644 index 0000000..b27f657 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/SavedPotionEffect.java @@ -0,0 +1,18 @@ +package me.trixkz.lifestealcore.managers.pvpclass; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import org.bukkit.potion.PotionEffect; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class SavedPotionEffect { + + private PotionEffect potionEffect; + private long time; + private boolean permanent; +} diff --git a/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/TankClass.java b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/TankClass.java new file mode 100644 index 0000000..3d8efa5 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/managers/pvpclass/TankClass.java @@ -0,0 +1,146 @@ +package me.trixkz.lifestealcore.managers.pvpclass; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.playerdata.PlayerState; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.TimeUtils; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Effect; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +public class TankClass extends PvPClass { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private Map playerHits = new HashMap(); + private Map bleedingPlayers = new HashMap(); + private Map lastResistanceUsage = new HashMap(); + + private int bleedingSeconds = 5; + + public TankClass() { + super("Tank", 5, Arrays.asList(Material.IRON_INGOT)); + } + + @Override + public void apply(Player player) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1)); + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); + } + + @Override + public void tick(Player player) { + if (!player.hasPotionEffect(PotionEffectType.SPEED)) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1)); + } + + if (!player.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE)) { + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); + } + } + + @Override + public void remove(Player player) { + + } + + @Override + public boolean isItemConsumed(Player player, Material material) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData.getPlayerState() != PlayerState.WARZONE) { + player.sendMessage(Utils.translate(Constants.PREFIX + "You can only use this in the warzone")); + + return false; + } + + if (material == Material.IRON_INGOT) { + if (this.lastResistanceUsage.containsKey(player.getUniqueId())) { + if (this.lastResistanceUsage.get(player.getUniqueId()) > System.currentTimeMillis()) { + long amountOfTimeLeft = this.lastResistanceUsage.get(player.getUniqueId()) - System.currentTimeMillis(); + + player.sendMessage(Utils.translate(Constants.PREFIX + "You can not use this for another " + TimeUtils.formatIntoDetailedString((int) amountOfTimeLeft / 1000))); + + return false; + } + } + + this.lastResistanceUsage.put(player.getUniqueId(), System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(30)); + + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 100, 2)); + + return true; + } + + return false; + } + + @Override + public boolean qualifies(Player player) { + return this.hasAllArmor(player) && player.getInventory().getHelmet().getType() == Material.DIAMOND_HELMET && player.getInventory().getChestplate().getType() == Material.IRON_CHESTPLATE && player.getInventory().getLeggings().getType() == Material.IRON_LEGGINGS && player.getInventory().getBoots().getType() == Material.DIAMOND_BOOTS; + } + + @EventHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Player killerPlayer = (Player) event.getDamager(); + + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(killerPlayer.getUniqueId()); + + if (playerData.getPlayerState() != PlayerState.WARZONE) { + return; + } + + Player victimPlayer = (Player) event.getEntity(); + + if (this.main.getPvpClassManager().hasPvPClassOn(killerPlayer, this)) { + if (this.playerHits.containsKey(killerPlayer.getUniqueId())) { + this.playerHits.get(killerPlayer.getUniqueId()).getAndAdd(1); + } else { + AtomicInteger atomicInteger = new AtomicInteger(); + + this.playerHits.put(killerPlayer.getUniqueId(), atomicInteger); + } + } + + if (this.playerHits.containsKey(killerPlayer.getUniqueId())) { + if (this.playerHits.get(killerPlayer.getUniqueId()).get() >= 10) { + this.playerHits.remove(killerPlayer.getUniqueId()); + this.bleedingPlayers.put(victimPlayer.getUniqueId(), System.currentTimeMillis() + (this.bleedingSeconds * 1000)); + + new BukkitRunnable() { + int seconds = 0; + + @Override + public void run() { + if (this.seconds == 100) { + this.cancel(); + + return; + } + + victimPlayer.playEffect(victimPlayer.getLocation(), Effect.MOBSPAWNER_FLAMES, 50); + victimPlayer.damage(1); + + this.seconds++; + } + }.runTaskTimer(this.main, 20L, 100L); + + killerPlayer.sendMessage(Utils.translate("&8[&9Bleeding&8] &eYou have given " + victimPlayer.getName() + " the bleeding effect for 5 seconds")); + victimPlayer.sendMessage(Utils.translate("&8[&9Bleeding&8] &eA tank has given you the bleeding effect for 5 seconds")); + } + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/normalmenusystem/ItemStackButton.java b/src/main/java/me/trixkz/lifestealcore/normalmenusystem/ItemStackButton.java new file mode 100644 index 0000000..26bb887 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/normalmenusystem/ItemStackButton.java @@ -0,0 +1,28 @@ +package me.trixkz.lifestealcore.normalmenusystem; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import me.trixkz.lifestealcore.utils.ItemBuilder; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import java.util.Arrays; + +@Getter +@Setter +@AllArgsConstructor +@RequiredArgsConstructor +public class ItemStackButton { + + private String name; + private String[] lore; + private Material material; + private int data; + private int amount; + + public ItemStack makeItemStack() { + return new ItemBuilder(this.material).name(Utils.translate(this.name)).lore(Utils.translate(Arrays.asList(this.lore))).durability(this.data).amount(this.amount).build(); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/normalmenusystem/Menu.java b/src/main/java/me/trixkz/lifestealcore/normalmenusystem/Menu.java new file mode 100644 index 0000000..6e256bc --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/normalmenusystem/Menu.java @@ -0,0 +1,63 @@ +package me.trixkz.lifestealcore.normalmenusystem; + +import me.trixkz.lifestealcore.utils.ItemBuilder; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import java.util.Arrays; + +public abstract class Menu implements InventoryHolder { + + protected PlayerMenuUtil playerMenuUtil; + protected Inventory inventory; + protected ItemStack FILLER_GLASS = new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).durability(0).name("").build(); + + public Menu(PlayerMenuUtil playerMenuUtil) { + this.playerMenuUtil = playerMenuUtil; + } + + public abstract String getMenuName(); + + public abstract int getSlots(); + + public abstract void handleMenu(InventoryClickEvent event); + + public abstract void setMenuItems(Player player); + + public void open(Player player) { + inventory = Bukkit.createInventory(this, getSlots(), getMenuName()); + + this.setMenuItems(player); + + playerMenuUtil.getOwner().openInventory(inventory); + } + + @Override + public Inventory getInventory() { + return inventory; + } + + public void setFillerGlass(){ + for (int i = 0; i < this.getSlots(); i++) { + if (this.inventory.getItem(i) == null){ + this.inventory.setItem(i, this.FILLER_GLASS); + } + } + } + + public ItemStack makeItemStack(Material material, String displayName, String[] lore) { + ItemStack itemStack = new ItemStack(material); + ItemMeta itemMeta = itemStack.getItemMeta(); + itemMeta.setDisplayName(displayName); + + itemMeta.setLore(Arrays.asList(lore)); + itemStack.setItemMeta(itemMeta); + + return itemStack; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/normalmenusystem/PaginatedMenu.java b/src/main/java/me/trixkz/lifestealcore/normalmenusystem/PaginatedMenu.java new file mode 100644 index 0000000..a457a4a --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/normalmenusystem/PaginatedMenu.java @@ -0,0 +1,61 @@ +package me.trixkz.lifestealcore.normalmenusystem; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public abstract class PaginatedMenu extends Menu { + + protected int page = 0; + protected int maxItemsPerPage = 28; + protected int index = 0; + + public PaginatedMenu(PlayerMenuUtil playerMenuUtil) { + super(playerMenuUtil); + } + + public void addMenuBorder() { +// ItemStack previousPageItemStack = HeadUtils.itemFromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ=="); + +// ItemMeta previousPageItemMeta = previousPageItemStack.getItemMeta(); +// previousPageItemMeta.setDisplayName(Utils.translate("&ePrevious Page")); +// +// previousPageItemStack.setItemMeta(previousPageItemMeta); +// +// this.inventory.setItem(48, previousPageItemStack); +// this.inventory.setItem(49, makeItemStack(Material.BARRIER, ChatColor.DARK_RED + "Close", new String[]{""})); +// +// ItemStack nextPageItemStack = HeadUtils.itemFromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTliZjMyOTJlMTI2YTEwNWI1NGViYTcxM2FhMWIxNTJkNTQxYTFkODkzODgyOWM1NjM2NGQxNzhlZDIyYmYifX19"); +// +// ItemMeta nextPageItemMeta = nextPageItemStack.getItemMeta(); +// nextPageItemMeta.setDisplayName(Utils.translate("&eNext Page")); +// +// nextPageItemStack.setItemMeta(nextPageItemMeta); + +// this.inventory.setItem(50, nextPageItemStack); + + for (int i = 0; i < 10; i++) { + if (this.inventory.getItem(i) == null) { + this.inventory.setItem(i, this.FILLER_GLASS); + } + } + + this.inventory.setItem(17, this.FILLER_GLASS); + this.inventory.setItem(18, this.FILLER_GLASS); + this.inventory.setItem(26, this.FILLER_GLASS); + this.inventory.setItem(27, this.FILLER_GLASS); + this.inventory.setItem(35, this.FILLER_GLASS); + this.inventory.setItem(36, this.FILLER_GLASS); + + for (int i = 44; i < 54; i++) { + if (this.inventory.getItem(i) == null) { + this.inventory.setItem(i, this.FILLER_GLASS); + } + } + } + + public int getMaxItemsPerPage() { + return maxItemsPerPage; + } +} \ No newline at end of file diff --git a/src/main/java/me/trixkz/lifestealcore/normalmenusystem/PlayerMenuUtil.java b/src/main/java/me/trixkz/lifestealcore/normalmenusystem/PlayerMenuUtil.java new file mode 100644 index 0000000..29db21c --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/normalmenusystem/PlayerMenuUtil.java @@ -0,0 +1,20 @@ +package me.trixkz.lifestealcore.normalmenusystem; + +import org.bukkit.entity.Player; + +public class PlayerMenuUtil { + + private Player owner; + + public PlayerMenuUtil(Player owner) { + this.owner = owner; + } + + public Player getOwner() { + return owner; + } + + public void setOwner(Player owner) { + this.owner = owner; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/playerdata/PlayerData.java b/src/main/java/me/trixkz/lifestealcore/playerdata/PlayerData.java new file mode 100644 index 0000000..30e2330 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/playerdata/PlayerData.java @@ -0,0 +1,46 @@ +package me.trixkz.lifestealcore.playerdata; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.managers.PlayerDataManager; +import me.trixkz.lifestealcore.playerdata.currentgame.PlayerCurrentGameData; + +import java.util.UUID; + +@Getter +@Setter +public class PlayerData { + + private PlayerDataManager playerDataManager = LifeStealCore.getInstance().getPlayerDataManager(); + private PlayerState playerState = PlayerState.SPAWN; + + private PlayerSettings playerSettings = new PlayerSettings(); + private PlayerCurrentGameData playerCurrentGameData = new PlayerCurrentGameData(); + + private final UUID uniqueId; + private boolean loaded; + + private double coins; + private int tokens; + + private UUID clanOwner; + + private int kills; + private int deaths; + + private double hearts = 20; + + private int bounty; + private int currentKillstreak; + private int highestKillstreak; + + private long deathBanTime; + private long deathBanTimeAddedAt; + + public PlayerData(UUID uniqueId) { + this.uniqueId = uniqueId; + this.loaded = false; + this.playerDataManager.loadPlayerData(this); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/playerdata/PlayerSettings.java b/src/main/java/me/trixkz/lifestealcore/playerdata/PlayerSettings.java new file mode 100644 index 0000000..3877106 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/playerdata/PlayerSettings.java @@ -0,0 +1,9 @@ +package me.trixkz.lifestealcore.playerdata; + +import lombok.Data; + +@Data +public class PlayerSettings { + + private boolean scoreboardEnabled = true; +} diff --git a/src/main/java/me/trixkz/lifestealcore/playerdata/PlayerState.java b/src/main/java/me/trixkz/lifestealcore/playerdata/PlayerState.java new file mode 100644 index 0000000..6d16a56 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/playerdata/PlayerState.java @@ -0,0 +1,7 @@ +package me.trixkz.lifestealcore.playerdata; + +public enum PlayerState { + + SPAWN, + WARZONE; +} diff --git a/src/main/java/me/trixkz/lifestealcore/playerdata/currentgame/PlayerCurrentGameData.java b/src/main/java/me/trixkz/lifestealcore/playerdata/currentgame/PlayerCurrentGameData.java new file mode 100644 index 0000000..e97d621 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/playerdata/currentgame/PlayerCurrentGameData.java @@ -0,0 +1,10 @@ +package me.trixkz.lifestealcore.playerdata.currentgame; + +import lombok.Data; +import me.trixkz.lifestealcore.LifeStealCore; + +@Data +public class PlayerCurrentGameData { + + private LifeStealCore main = LifeStealCore.getInstance(); +} diff --git a/src/main/java/me/trixkz/lifestealcore/runnables/ClearLagRunnable.java b/src/main/java/me/trixkz/lifestealcore/runnables/ClearLagRunnable.java new file mode 100644 index 0000000..1db1770 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/runnables/ClearLagRunnable.java @@ -0,0 +1,51 @@ +package me.trixkz.lifestealcore.runnables; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.entity.Item; + +@Getter +@Setter +public class ClearLagRunnable { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private int time = 0; + + public ClearLagRunnable() { + this.main.getServer().getScheduler().runTaskTimerAsynchronously(this.main, () -> { + switch (this.time) { + case 0: + this.main.getServer().broadcastMessage(Utils.translate(Constants.PREFIX + "&eAll items will be removed in 15 minutes")); + + break; + case 1: + this.main.getServer().broadcastMessage(Utils.translate(Constants.PREFIX + "&eAll items will be removed in 10 minutes")); + + break; + case 2: + this.main.getServer().broadcastMessage(Utils.translate(Constants.PREFIX + "&eAll items will be removed in 5 minutes")); + + break; + } + + if (this.time == 3) { + this.main.getServer().getWorlds().forEach((world) -> { + world.getEntities().forEach((entity) -> { + if (entity instanceof Item) { + entity.remove(); + } + }); + }); + + this.time = 0; + this.main.getServer().broadcastMessage(Utils.translate(Constants.PREFIX + "&eAll items have been removed")); + } else { + this.time++; + } + }, 0L, 18000L); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/runnables/CombatTagRunnable.java b/src/main/java/me/trixkz/lifestealcore/runnables/CombatTagRunnable.java new file mode 100644 index 0000000..b261e62 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/runnables/CombatTagRunnable.java @@ -0,0 +1,63 @@ +package me.trixkz.lifestealcore.runnables; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.entity.Player; + +public class CombatTagRunnable { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public CombatTagRunnable() { + this.main.getServer().getScheduler().runTaskTimerAsynchronously(this.main, () -> { + this.main.getCombatManager().setCount(this.main.getCombatManager().getCount() + 1); + + for (Player player : this.main.getServer().getOnlinePlayers()) { + if (this.main.getCombatManager().isInCombat(player.getUniqueId())) { + int count = this.main.getCombatManager().getCombatTime(player.getUniqueId()); + + count--; + + this.main.getCombatManager().setCombatTime(player.getUniqueId(), count); + + if (count == 0) { + this.main.getCombatManager().getCombatSet().remove(player.getUniqueId()); + this.main.getCombatManager().getTimeMap().remove(player.getUniqueId()); + + player.sendMessage(Utils.translate("&aYou are no longer in combat")); + } + } + + if (this.main.getCombatManager().getCount() == 160) { + this.main.getCombatManager().setCount(0); + } + + if (this.main.getCooldownManager().isOnCooldown(player)) { + int count = this.main.getCooldownManager().getCooldownTime(player); + count--; + + this.main.getCooldownManager().setCooldownTime(player, count); + + if (count == 0) { + this.main.getCooldownManager().getCooldownSet().remove(player); + this.main.getCooldownManager().getCooldownTimeMap().remove(player); + + player.setLevel(0); + player.setExp(0); + player.sendMessage(Utils.translate("&aYou can use your ability again")); + } + } + +// PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + +// if (this.main.getKitManager().getKitByName(playerData.getCurrentKit()) != null) { +// Kit kit = this.main.getKitManager().getKitByName(playerData.getCurrentKit()); +// +// if (kit.getAbility() != null && this.main.getCooldownManager().getCooldownCount() == kit.getAbility().getCooldown()) { +// this.main.getCooldownManager().setCooldownCount(0); +// } +// } + } + }, 0L, 20L); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/runnables/EnvoyRunnable.java b/src/main/java/me/trixkz/lifestealcore/runnables/EnvoyRunnable.java new file mode 100644 index 0000000..c445ca0 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/runnables/EnvoyRunnable.java @@ -0,0 +1,55 @@ +package me.trixkz.lifestealcore.runnables; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.managers.envoys.EnvoyDrop; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.CustomLocation; +import me.trixkz.lifestealcore.utils.Utils; + +public class EnvoyRunnable { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private int index = 0; + private int nextEnvoy = 0; + private int time = 0; + + public EnvoyRunnable() { + this.main.getServer().getScheduler().runTaskTimerAsynchronously(this.main, () -> { + if (this.main.getEnvoyManager().isStarted()) { + if ((this.main.getEnvoyManager().getEnvoyLocations().size()) == this.index) { + this.main.getServer().broadcastMessage(Utils.translate(Constants.PREFIX + "The envoy event has ended")); + this.main.getEnvoyManager().setStarted(false); + this.index = 0; + this.nextEnvoy = 0; + this.time = 0; + + return; + } + + if (this.nextEnvoy == 15) { + CustomLocation customLocation = this.main.getEnvoyManager().getEnvoyLocations().get(this.index); + + EnvoyDrop envoyDrop = new EnvoyDrop(customLocation.toBukkitLocation().getWorld(), customLocation.toBukkitLocation().getX(), customLocation.toBukkitLocation().getY(), customLocation.toBukkitLocation().getZ(), customLocation.toBukkitLocation().getY() + 25); + + this.main.getServer().broadcastMessage(Utils.translate(Constants.PREFIX + "Another envoy has spawned at &7(&f" + Math.round(customLocation.toBukkitLocation().getX()) + "&7, &f" + Math.round(customLocation.toBukkitLocation().getY()) + "&7, &f" + Math.round(customLocation.toBukkitLocation().getZ()) + "&7)")); + this.index++; + this.nextEnvoy = 0; + } else { + this.nextEnvoy++; + } + } else { + if (this.time >= 1200) { + this.main.getEnvoyManager().setStarted(true); + + return; + } + + if (this.time % 300 == 0) { + this.main.getServer().broadcastMessage(Utils.translate(Constants.PREFIX + "An envoy event happens every single 20 minutes")); + this.time++; + } + } + }, 0L, 20L); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/runnables/LootboxRunnable.java b/src/main/java/me/trixkz/lifestealcore/runnables/LootboxRunnable.java new file mode 100644 index 0000000..adcfd67 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/runnables/LootboxRunnable.java @@ -0,0 +1,274 @@ +package me.trixkz.lifestealcore.runnables; + +import eu.decentsoftware.holograms.api.DHAPI; +import eu.decentsoftware.holograms.api.DecentHologramsAPI; +import eu.decentsoftware.holograms.api.holograms.Hologram; +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.Vector; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ThreadLocalRandom; + +@Getter +@Setter +public class LootboxRunnable extends BukkitRunnable { + + private LifeStealCore main = LifeStealCore.getInstance(); + + private Player player; + + private Block block; + + private List itemStacks = new ArrayList(); + private List locations = new ArrayList(); + + private Map hologramTaskIds = new HashMap(); + + private int itemStackIndex = 0; + private int locationIndex = 0; + private int seconds = 0; + + private boolean done = false; + private boolean doneAlmost = false; + + public LootboxRunnable(Player player, Block block) { + this.player = player; + this.block = block; + this.itemStacks = this.main.getLootboxManager().getItemStacks(); + + Location location = this.block.getLocation().clone(); + Location locationCopy = location.clone(); + locationCopy.add(0.5, 0.5, 0.5); + locationCopy.setY(locationCopy.getY() + 5); + + Hologram hologram = new Hologram("Hologram", locationCopy); + + DecentHologramsAPI.get().getHologramManager().registerHologram(hologram); + + this.hologramTaskIds.put(locationCopy, this.main.getServer().getScheduler().scheduleSyncRepeatingTask(this.main, new Runnable() { + @Override + public void run() { + DHAPI.removeHologramLine(hologram, 0); + DHAPI.removeHologramLine(hologram, 1); + DHAPI.addHologramLine(hologram, Utils.translate("&d&l" + player.getName() + "&e's Lootbox")); + DHAPI.addHologramLine(hologram, Utils.translate("&9Obtained in crates or at &d" + Constants.WEBSITE)); + } + }, 0, 100)); + +// World world = this.block.getLocation().getWorld(); +// +// BlockPosition position = new BlockPosition(this.block.getLocation().getX(), this.block.getLocation().getY(), this.block.getLocation().getZ()); +// +// TileEntityEnderChest tileEntityEnderChest = (TileEntityEnderChest) world.getTileEntity(position); +// +// world.playBlockAction(position, tileEntityEnderChest.w(), 1, 1); + + for (int i = 0; i < 270; i += 45) { + Location locationCopyNew = this.getHorizontalLocationAroundCenterLocation(this.block.getLocation(), 2, i).toLocation(this.player.getWorld()); + + this.locations.add(locationCopyNew); + } + } + + @Override + public void run() { + if (this.doneAlmost) { + if (this.locations.size() == this.locationIndex) { + this.done = true; + this.doneAlmost = false; + + return; + } + + Location location = this.locations.get(this.locationIndex).clone(); + location.add(0.5, 0.5, 0.5); + location.setY(location.getY() + 2); + + this.main.getServer().getScheduler().cancelTask(this.hologramTaskIds.get(location)); + this.locations.get(this.locationIndex).getWorld().strikeLightning(location); + this.hologramTaskIds.remove(location); + + for (Hologram hologram : DecentHologramsAPI.get().getHologramManager().getHolograms()) { + if (location.getWorld().getName().equalsIgnoreCase(hologram.getLocation().getWorld().getName()) && location.getX() == hologram.getLocation().getX() && location.getY() == hologram.getLocation().getY() && location.getZ() == hologram.getLocation().getZ()) { + hologram.delete(); + + break; + } + } + + this.locationIndex++; + + return; + } + + if (this.done) { + if (this.seconds == 1) { + this.main.getServer().getScheduler().runTaskLater(this.main, () -> { + this.block.setType(Material.AIR); + this.block.getLocation().getWorld().strikeLightning(this.block.getLocation()); + this.makeHelixParticleEffect(this.block.getLocation().clone(), Effect.SMOKE); + }, 50L); + + this.main.getServer().getScheduler().runTaskLaterAsynchronously(this.main, () -> { + for (Hologram hologramToRemove : DecentHologramsAPI.get().getHologramManager().getHolograms()) { + if (this.hologramTaskIds.containsKey(hologramToRemove.getLocation())) { + hologramToRemove.delete(); + } + } + + this.hologramTaskIds.forEach((location, taskId) -> { + this.main.getServer().getScheduler().cancelTask(taskId); + }); + + this.cancel(); + }, 50L); + } + + this.seconds++; + + return; + } + + if (this.locations.size() == this.locationIndex) { + this.locationIndex = 0; + } + + Location location = this.locations.get(this.locationIndex).clone(); + location.add(0.5, 0.5, 0.5); + location.setY(location.getY() + 2); + + for (Hologram hologram : DecentHologramsAPI.get().getHologramManager().getHolograms()) { + if (location.getWorld().getName().equalsIgnoreCase(hologram.getLocation().getWorld().getName()) && location.getX() == hologram.getLocation().getX() && location.getY() == hologram.getLocation().getY() && location.getZ() == hologram.getLocation().getZ()) { + this.main.getServer().getScheduler().cancelTask(this.hologramTaskIds.get(location)); + this.hologramTaskIds.remove(location); + + hologram.delete(); + + break; + } + } + + if ((this.itemStacks.size() - 1) >= this.itemStackIndex) { + this.spawnHologram(this.locations.get(this.locationIndex).clone(), this.itemStacks.get(this.itemStackIndex)); + this.itemStackIndex++; + } else { + this.itemStackIndex = 0; + this.spawnHologram(this.locations.get(this.locationIndex).clone(), this.itemStacks.get(this.itemStackIndex)); + this.itemStackIndex++; + } + + this.locationIndex++; + this.seconds++; + + if (this.seconds >= 125) { + int random = ThreadLocalRandom.current().nextInt(0, this.itemStacks.size()); + + this.player.sendMessage(Utils.translate("&eYou have won &d" + this.itemStacks.get(random).getItemMeta().getDisplayName())); + this.player.getInventory().addItem(this.itemStacks.get(random)); + + Location locationCopy = this.block.getLocation().clone(); + Location locationCopyNew = locationCopy.clone(); + locationCopyNew.add(0.5, 0.5, 0.5); + locationCopyNew.setY(locationCopyNew.getY() + 3); + + Hologram hologram = new Hologram("Hologram", locationCopyNew); + + DecentHologramsAPI.get().getHologramManager().registerHologram(hologram); + + this.hologramTaskIds.put(locationCopyNew, this.main.getServer().getScheduler().scheduleSyncRepeatingTask(this.main, new Runnable() { + @Override + public void run() { + DHAPI.removeHologramLine(hologram, 0); + DHAPI.removeHologramLine(hologram, 1); + DHAPI.removeHologramLine(hologram, 2); + DHAPI.addHologramLine(hologram, itemStacks.get(random)); + DHAPI.addHologramLine(hologram, Utils.translate("")); + DHAPI.addHologramLine(hologram, Utils.translate(itemStacks.get(random).getItemMeta().getDisplayName())); + } + }, 0, 100)); + + this.locationIndex = 0; + this.seconds = 0; + this.doneAlmost = true; + } + } + + public Vector getHorizontalLocationAroundCenterLocation(Location center, double radius, double angleInRadian) { + double x = center.getX() + radius * Math.cos(angleInRadian); + double y = center.getY(); + double z = center.getZ() + radius * Math.sin(angleInRadian); + + Vector vec = new Vector(x, y, z); + + return vec; + } + + public Vector getVerticalLocationAroundCenterLocation(Location center, double radius, double angleInRadian) { + double x = center.getX() + radius * Math.cos(angleInRadian); + double y = center.getY() + radius * Math.sin(angleInRadian); + double z = center.getZ(); + + Vector vec = new Vector(x, y, z); + + return vec; + } + + public void spawnHologram(Location location, ItemStack itemStack) { + location.add(0.5, 0.5, 0.5); + location.setY(location.getY() + 2); + + Hologram hologram = new Hologram("Hologram", location); + + DecentHologramsAPI.get().getHologramManager().registerHologram(hologram); + + this.hologramTaskIds.put(location, this.main.getServer().getScheduler().scheduleSyncRepeatingTask(this.main, new Runnable() { + @Override + public void run() { + DHAPI.removeHologramLine(hologram, 0); + DHAPI.removeHologramLine(hologram, 1); + DHAPI.removeHologramLine(hologram, 2); + DHAPI.addHologramLine(hologram, itemStack); + DHAPI.addHologramLine(hologram, Utils.translate("")); + DHAPI.addHologramLine(hologram, Utils.translate(itemStack.getItemMeta().getDisplayName())); + } + }, 0, 100)); + } + + public void makeHelixParticleEffect(Location location, Effect e) { + location.add(0.5, 0.5, 0.5); + + new BukkitRunnable() { + double t = 0; + double r = 1; + double up = 0.2; + + @Override + public void run() { + t = t + Math.PI/8; + double x = r*Math.cos(t); + double y = up*t; + double z = r*Math.sin(t); + location.add(x, y, z); + location.getWorld().playEffect(location, e, 1); + location.subtract(x, y, z); + + if (t > Math.PI*8) { + this.cancel(); + } + } + }.runTaskTimer(this.main, 0, 1); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/runnables/SpawnRunnable.java b/src/main/java/me/trixkz/lifestealcore/runnables/SpawnRunnable.java new file mode 100644 index 0000000..2249b42 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/runnables/SpawnRunnable.java @@ -0,0 +1,88 @@ +package me.trixkz.lifestealcore.runnables; + +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.utils.Cuboid; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +public class SpawnRunnable { + + private LifeStealCore main = LifeStealCore.getInstance(); + + public SpawnRunnable() { + this.main.getServer().getScheduler().runTaskTimerAsynchronously(this.main, () -> { + for (Map.Entry mapInformation : this.main.getSpawnManager().getPlayers().entrySet()) { + Player player = this.main.getServer().getPlayer(mapInformation.getKey()); + + if (player != null) { + if (this.main.getCombatManager().isInCombat(player.getUniqueId())) { + this.main.getSpawnManager().getPlayers().remove(mapInformation.getKey()); + + player.sendMessage(Utils.translate("&cYou can not go to spawn while you are in combat")); + } else { + if (mapInformation.getValue() <= 0) { + this.main.getSpawnManager().getPlayers().remove(player.getUniqueId()); + this.main.getPlayerDataManager().sendToSpawnAndResetPlayer(player); + + player.sendMessage(Utils.translate("&aTeleporting to spawn...")); + } else { + this.main.getSpawnManager().getPlayers().put(mapInformation.getKey(), mapInformation.getValue() - 1); + + player.sendMessage(Utils.translate("&aTeleporting to spawn in " + mapInformation.getValue() + "...")); + } + } + } else { + this.main.getSpawnManager().getPlayers().remove(mapInformation.getKey()); + } + } + + if (this.main.getSpawnManager().getSpawnMin() != null) { + Cuboid cuboid = new Cuboid(this.main.getSpawnManager().getCornerMin().toBukkitLocation(), this.main.getSpawnManager().getCornerMax().toBukkitLocation()); + + for (Player player : this.main.getServer().getOnlinePlayers()) { + for (Block block : cuboid.getWalls()) { + Location location = block.getLocation(); + + player.spawnParticle(Particle.GLOW, location, 1); + } + } + } + }, 0L, 20L); + } + + public List getAreaOutline(Location corner1, Location corner2, double particleDistance) { + List result = new ArrayList(); + World world = corner1.getWorld(); + double minX = Math.min(corner1.getX(), corner2.getX()); + double minY = Math.min(corner1.getY(), corner2.getY()); + double minZ = Math.min(corner1.getZ(), corner2.getZ()); + double maxX = Math.max(corner1.getX(), corner2.getX()); + double maxY = Math.max(corner1.getY(), corner2.getY()); + double maxZ = Math.max(corner1.getZ(), corner2.getZ()); + + for (double x = minX; x <= maxX; x+=particleDistance) { + for (double y = minY; y <= maxY; y+=particleDistance) { + for (double z = minZ; z <= maxZ; z+=particleDistance) { + int components = 0; + if (x == minX || x == maxX) components++; + if (y == minY || y == maxY) components++; + if (z == minZ || z == maxZ) components++; + if (components >= 2) { + result.add(new Location(world, x, y, z)); + } + } + } + } + + return result; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/scoreboard/ScoreboardProvider.java b/src/main/java/me/trixkz/lifestealcore/scoreboard/ScoreboardProvider.java new file mode 100644 index 0000000..155d8c6 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/scoreboard/ScoreboardProvider.java @@ -0,0 +1,101 @@ +package me.trixkz.lifestealcore.scoreboard; + +import aether.scoreboard.Board; +import aether.scoreboard.BoardAdapter; +import aether.scoreboard.cooldown.BoardCooldown; +import me.trixkz.lifestealcore.LifeStealCore; +import me.trixkz.lifestealcore.playerdata.PlayerData; +import me.trixkz.lifestealcore.utils.Constants; +import me.trixkz.lifestealcore.utils.Utils; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Scoreboard; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public class ScoreboardProvider implements BoardAdapter { + + private LifeStealCore main = LifeStealCore.getInstance(); + + @Override + public String getTitle(Player player) { + // ColorSet colorSetOne = new ColorSet<>(ColorUtils.getColorMap().get(ChatColor.valueOf(this.main.getMessagesConfig().getConfig().getString("SCOREBOARD.NAME-COLOR-CODE-ONE"))).getRed(), ColorUtils.getColorMap().get(ChatColor.valueOf(this.main.getMessagesConfig().getConfig().getString("SCOREBOARD.NAME-COLOR-CODE-ONE"))).getGreen(), ColorUtils.getColorMap().get(ChatColor.valueOf(this.main.getMessagesConfig().getConfig().getString("SCOREBOARD.NAME-COLOR-CODE-ONE"))).getBlue()); + // ColorSet colorSetTwo = new ColorSet<>(ColorUtils.getColorMap().get(ChatColor.valueOf(this.main.getMessagesConfig().getConfig().getString("SCOREBOARD.NAME-COLOR-CODE-TWO"))).getRed(), ColorUtils.getColorMap().get(ChatColor.valueOf(this.main.getMessagesConfig().getConfig().getString("SCOREBOARD.NAME-COLOR-CODE-TWO"))).getGreen(), ColorUtils.getColorMap().get(ChatColor.valueOf(this.main.getMessagesConfig().getConfig().getString("SCOREBOARD.NAME-COLOR-CODE-TWO"))).getBlue()); + + // return ColorUtils.getGradientString(this.main.getMessagesConfig().getConfig().getString("SCOREBOARD.NAME"), ColorUtils.getColorCodes(this.main.getMessagesConfig().getConfig().getString("SCOREBOARD.NAME"), colorSetOne, colorSetTwo)); + + return Utils.translate(this.main.getMessagesConfig().getConfig().getString("SCOREBOARD.NAME")); + } + + @Override + public List getScoreboard(Player player, Board board, Set cooldowns) { + PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (playerData == null) { + return null; + } + + if (!playerData.getPlayerSettings().isScoreboardEnabled()) { + return null; + } + + switch (playerData.getPlayerState()) { + case SPAWN: + return this.getSpawnScoreboard(player, playerData); + case WARZONE: + return this.getWarzoneScoreboard(player, playerData); + } + + return null; + } + + @Override + public void onScoreboardCreate(Player player, Scoreboard scoreboard) { + + } + + private List getSpawnScoreboard(Player player, PlayerData playerData) { + List lines = new ArrayList<>(); + + DecimalFormat decimalFormat = new DecimalFormat("##.##"); + + for (String string : Constants.SPAWN_SCOREBOARD) { + lines.add( + string + .replaceAll("%scoreboard_bar%", String.valueOf(Utils.scoreboardBar)) + .replaceAll("%players_online%", String.valueOf(this.main.getServer().getOnlinePlayers().size())) + .replaceAll("%player%", player.getName()) + .replaceAll("%coins%", String.valueOf(decimalFormat.format(playerData.getCoins()))) + .replaceAll("%tokens%", String.valueOf(playerData.getTokens())) + .replaceAll("%website%", Constants.WEBSITE) + ); + } + + return Utils.translate(lines); + } + + private List getWarzoneScoreboard(Player player, PlayerData playerData) { + List lines = new ArrayList<>(); + + DecimalFormat decimalFormat = new DecimalFormat("##.##"); + + for (String string : Constants.WARZONE_SCOREBOARD) { + lines.add( + string + .replaceAll("%scoreboard_bar%", String.valueOf(Utils.scoreboardBar)) + .replaceAll("%players_online%", String.valueOf(this.main.getServer().getOnlinePlayers().size())) + .replaceAll("%player%", player.getName()) + .replaceAll("%kills%", String.valueOf(playerData.getKills())) + .replaceAll("%killstreak%", String.valueOf(playerData.getCurrentKillstreak())) + .replaceAll("%deaths%", String.valueOf(playerData.getDeaths())) + .replaceAll("%combat_tag%", this.main.getCombatManager().getCombatTime(player.getUniqueId()) + "&ds") + .replaceAll("%pvp_class%", String.valueOf(this.main.getPvpClassManager().getPvPClass(player).getName())) + .replaceAll("%website%", Constants.WEBSITE) + ); + } + + return Utils.translate(lines); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/AsyncScheduler.java b/src/main/java/me/trixkz/lifestealcore/utils/AsyncScheduler.java new file mode 100644 index 0000000..6054527 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/AsyncScheduler.java @@ -0,0 +1,34 @@ +package me.trixkz.lifestealcore.utils; + +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import lombok.experimental.UtilityClass; + +import java.util.concurrent.*; + +@UtilityClass +public class AsyncScheduler { + + private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(4, + new ThreadFactoryBuilder().setNameFormat("Schedule LifestealCore Thread %d").build()); + + /** + * Run a task asynchronously. + */ + public Future run(Runnable runnable) { + return scheduler.submit(runnable); + } + + /** + * Run a task after scheduled delay asynchronously. + */ + public ScheduledFuture later(Runnable runnable, long delay, TimeUnit time) { + return scheduler.schedule(runnable, delay, time); + } + + /** + * Run a task in a fixed rate asynchronously. + */ + public ScheduledFuture timer(TimerRunnable runnable, long delay, long period, TimeUnit time) { + return runnable.setScheduledFuture(scheduler.scheduleAtFixedRate(runnable, delay, period, time)); + } +} \ No newline at end of file diff --git a/src/main/java/me/trixkz/lifestealcore/utils/Cache.java b/src/main/java/me/trixkz/lifestealcore/utils/Cache.java new file mode 100644 index 0000000..a6fa5d8 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/Cache.java @@ -0,0 +1,29 @@ +package me.trixkz.lifestealcore.utils; + +public class Cache { + + private T cache; + private long lastCache; + private final long refreshTimeInMilliseconds; + + public Cache(long refreshTimeInMilliseconds) { + this.refreshTimeInMilliseconds = refreshTimeInMilliseconds; + } + + public T getCache(CacheContentProvider cacheContentProvider) { + long currentTime = System.currentTimeMillis(); + if (lastCache + refreshTimeInMilliseconds < currentTime || cache == null) { + this.cache = cacheContentProvider.getObject(); + this.lastCache = currentTime; + } + return cache; + } + + public void clearCache() { + this.cache = null; + } + + public interface CacheContentProvider { + T getObject(); + } +} \ No newline at end of file diff --git a/src/main/java/me/trixkz/lifestealcore/utils/Clickable.java b/src/main/java/me/trixkz/lifestealcore/utils/Clickable.java new file mode 100644 index 0000000..cc8cc85 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/Clickable.java @@ -0,0 +1,51 @@ +package me.trixkz.lifestealcore.utils; + +import lombok.NoArgsConstructor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +@NoArgsConstructor +public class Clickable { + + private final List components = new ArrayList<>(); + + public Clickable(String msg) { + TextComponent message = new TextComponent(msg); + this.components.add(message); + } + + public Clickable(String msg, String hoverMsg, String clickString) { + this.add(msg, hoverMsg, clickString); + } + + public TextComponent add(String msg, String hoverMsg, String clickString) { + TextComponent message = new TextComponent(msg); + if (hoverMsg != null) { + message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hoverMsg).create())); + } + if (clickString != null) { + message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, clickString)); + } + this.components.add(message); + + return message; + } + + public void add(String message) { + this.components.add(new TextComponent(message)); + } + + public void sendToPlayer(Player player) { + player.spigot().sendMessage(this.asComponents()); + } + + public TextComponent[] asComponents() { + return this.components.toArray(new TextComponent[0]); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/ColorUtils.java b/src/main/java/me/trixkz/lifestealcore/utils/ColorUtils.java new file mode 100644 index 0000000..a1d86f4 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/ColorUtils.java @@ -0,0 +1,175 @@ +package me.trixkz.lifestealcore.utils; + +import lombok.Getter; +import lombok.Setter; +import me.trixkz.lifestealcore.chatcolor.ColorSet; +import net.md_5.bungee.api.ChatColor; +import java.awt.*; +import java.util.List; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Getter +@Setter +public class ColorUtils { + + @Getter private static Map> colorMap = new HashMap<>(); + + public ColorUtils() { + this.registerColors(); + } + + public void registerColors() { + colorMap.put(ChatColor.BLACK, new ColorSet<>(0, 0, 0)); + colorMap.put(ChatColor.DARK_BLUE, new ColorSet<>(0, 0, 170)); + colorMap.put(ChatColor.DARK_GREEN, new ColorSet<>(0, 170, 0)); + colorMap.put(ChatColor.DARK_AQUA, new ColorSet<>(0, 170, 170)); + colorMap.put(ChatColor.DARK_RED, new ColorSet<>(170, 0, 0)); + colorMap.put(ChatColor.DARK_PURPLE, new ColorSet<>(170, 0, 170)); + colorMap.put(ChatColor.GOLD, new ColorSet<>(255, 170, 0)); + colorMap.put(ChatColor.GRAY, new ColorSet<>(170, 170, 170)); + colorMap.put(ChatColor.DARK_GRAY, new ColorSet<>(85, 85, 85)); + colorMap.put(ChatColor.BLUE, new ColorSet<>(85, 85, 255)); + colorMap.put(ChatColor.GREEN, new ColorSet<>(85, 255, 85)); + colorMap.put(ChatColor.AQUA, new ColorSet<>(85, 255, 255)); + colorMap.put(ChatColor.RED, new ColorSet<>(255, 85, 85)); + colorMap.put(ChatColor.LIGHT_PURPLE, new ColorSet<>(255, 85, 255)); + colorMap.put(ChatColor.YELLOW, new ColorSet<>(255, 255, 85)); + colorMap.put(ChatColor.WHITE, new ColorSet<>(255, 255, 255)); + } + + public static ChatColor getColor(String colorCode) { + byte b; + + int i; + + ChatColor[] arrayOfChatColor; + + for (i = (arrayOfChatColor = ChatColor.values()).length, b = 0; b < i; ) { + ChatColor colors = arrayOfChatColor[b]; + + String colorsDecode = untranslate(colors.toString()); + + if (colorCode.equalsIgnoreCase(colorsDecode)) { + return colors; + } + + b++; + } + + return null; + } + + public static boolean lookAtColorCode(String colorCode) { + byte b; + + int i; + + ChatColor[] arrayOfChatColor; + + for (i = (arrayOfChatColor = ChatColor.values()).length, b = 0; b < i; ) { + ChatColor colors = arrayOfChatColor[b]; + + String colorsDecode = untranslate(colors.toString()); + + if (colorCode.equalsIgnoreCase(colorsDecode)) { + return true; + } + + b++; + } + + return false; + } + + public static String getGradientString(String string, String colorCodeOne, String colorCodeTwo) { + return getGradientString(string, getColorCodes(string, copyColorSet(colorCodeOne), copyColorSet(colorCodeTwo))); + } + + public static ColorSet copyColorSet(String colorCode) { + Color color = hexColorCodesToRGBColorCodes(colorCode); + + return new ColorSet(color.getRed(), color.getGreen(), color.getBlue()); + } + + public static String getGradientString(String string, List colorCodes) { + String[] split = string.split(""); + + StringBuilder stringBuilder = new StringBuilder(); + + for (int i = 0; i < colorCodes.size(); i++) { + stringBuilder.append(fromRGBColorCode(hexColorCodesToRGBColorCodes(colorCodes.get(i)).getRed(), hexColorCodesToRGBColorCodes(colorCodes.get(i)).getGreen(), hexColorCodesToRGBColorCodes(colorCodes.get(i)).getBlue()) + split[i]); + } + + return stringBuilder.toString(); + } + + public static List getColorCodes(String text, ColorSet colorSetOne, ColorSet colorSetTwo) { + List colorCodes = new ArrayList<>(); + + int red = ((colorSetOne.getRed() < colorSetTwo.getRed()) ? (colorSetTwo.getRed() - colorSetOne.getRed()) : (colorSetOne.getRed() - colorSetTwo.getRed())) / text.length(); + int green = ((colorSetOne.getGreen() < colorSetTwo.getGreen()) ? (colorSetTwo.getGreen() - colorSetOne.getGreen()) : (colorSetOne.getGreen() - colorSetTwo.getGreen())) / text.length(); + int blue = ((colorSetOne.getBlue() < colorSetTwo.getBlue()) ? (colorSetTwo.getBlue() - colorSetOne.getBlue()) : (colorSetOne.getBlue() - colorSetTwo.getBlue())) / text.length(); + + for (int i = 0; i < text.length(); i++) { + colorSetOne.setRed((colorSetOne.getRed() <= colorSetTwo.getRed()) ? (colorSetOne.getRed() + red) : (colorSetOne.getRed() - red)); + colorSetOne.setGreen((colorSetOne.getGreen() <= colorSetTwo.getGreen()) ? (colorSetOne.getGreen() + green) : (colorSetOne.getGreen() - green)); + colorSetOne.setBlue((colorSetOne.getBlue() <= colorSetTwo.getBlue()) ? (colorSetOne.getBlue() + blue) : (colorSetOne.getBlue() - blue)); + + String hex = String.format("#%02x%02x%02x", colorSetOne.getRed(), colorSetOne.getGreen(), colorSetOne.getBlue()); + + colorCodes.add(hex); + } + + return colorCodes; + } + + public static String translate(String string) { + Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}"); + + for (Matcher matcher = pattern.matcher(string); matcher.find(); matcher = pattern.matcher(string)) { + String color = string.substring(matcher.start(), matcher.end()); + + string = string.replace(color, ChatColor.valueOf(color) + ""); + } + + string = ChatColor.translateAlternateColorCodes('&', string); + + return string; + } + + public static Color hexColorCodesToRGBColorCodes(String string) { + return new Color(Integer.valueOf(string.substring(1, 3),16), Integer.valueOf(string.substring(3, 5),16), Integer.valueOf(string.substring(5, 7),16)); + } + + public static boolean isValidHexColorCode(String string) { + Pattern pattern = Pattern.compile("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"); + + Matcher matcher = pattern.matcher(string); + + return matcher.matches(); + } + + public static ChatColor fromRGBColorCode(int r, int g, int b) { + TreeMap closest = new TreeMap(); + colorMap.forEach((color, set) -> { + int red = Math.abs(r - set.getRed()); + int green = Math.abs(g - set.getGreen()); + int blue = Math.abs(b - set.getBlue()); + closest.put(red + green + blue, color); + }); + return closest.firstEntry().getValue(); + } + + public static String untranslate(String textToTranslate) { + char[] b = textToTranslate.toCharArray(); + for (int i = 0; i < b.length - 1; i++) { + if (b[i] == '§' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRrXx".indexOf(b[i + 1]) > -1) { + b[i] = '&'; + b[i + 1] = Character.toLowerCase(b[i + 1]); + } + } + return new String(b); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/Constants.java b/src/main/java/me/trixkz/lifestealcore/utils/Constants.java new file mode 100644 index 0000000..2c1303f --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/Constants.java @@ -0,0 +1,174 @@ +package me.trixkz.lifestealcore.utils; + +import me.trixkz.lifestealcore.LifeStealCore; +import java.util.List; + +public class Constants { + + private LifeStealCore main = LifeStealCore.getInstance(); + + /** + * Prefix + */ + public static String PREFIX; + + /** + * CLAN prefix + */ + public static String CLAN_PREFIX; + + /** + * Player data information (Do not change this) + */ + public static String PLAYER_DATA_UNIQUE_ID = "unique-id"; + public static String PLAYER_DATA_COINS = "coins"; + public static String PLAYER_DATA_TOKENS = "tokens"; + public static String PLAYER_DATA_CLAN_OWNER = "clan-owner"; + public static String PLAYER_DATA_KILLS = "kills"; + public static String PLAYER_DATA_DEATHS = "deaths"; + public static String PLAYER_DATA_HEARTS = "hearts"; + public static String PLAYER_DATA_BOUNTY = "bounty"; + public static String PLAYER_DATA_CURRENT_KILLSTREAK = "current-killstreak"; + public static String PLAYER_DATA_HIGHEST_KILLSTREAK = "highest-killstreak"; + public static String PLAYER_DATA_DEATH_BAN_TIME = "death-ban-time"; + public static String PLAYER_DATA_DEATH_BAN_TIME_ADDED_AT = "death-ban-time-added-at"; + + /** + * CLAN information (Do not change this) + */ + public static String CLAN_NAME = "name"; + public static String CLAN_LEVEL = "level"; + public static String CLAN_OWNER = "owner"; + public static String CLAN_PLAYERS_ADDED = "players-added"; + public static String CLAN_LOCKED = "locked"; + public static String CLAN_MAX_CLAN_MEMBERS = "max-clan-members"; + + /** + * General information messages + */ + public static String SCOREBOARD_NAME; + public static List SPAWN_SCOREBOARD; + public static List WARZONE_SCOREBOARD; + public static String WEBSITE; + + /** + * CLAN messages + */ + /** + * General messages + */ + public static String NO_CLAN_MESSAGE; + public static String NOT_ONLINE_MESSAGE; + public static String INVALID_ACTION_MESSAGE; + public static String NOT_IN_CLAN_MESSAGE; + public static String NOT_CLAN_OWNER_MESSAGE; + + /** + * CLAN create messages + */ + public static String MAKING_CLAN_MESSAGE; + public static String CLAN_MADE_MESSAGE; + public static String CLAN_ALREADY_MADE_MESSAGE; + + /** + * CLAN delete messages + */ + public static String CLAN_DELETED_MESSAGE; + + /** + * CLAN level messages + */ + public static String CLAN_LEVEL_MESSAGE; + + /** + * CLAN warp messages + */ + public static String CLAN_LOCKED_MESSAGE; + + /** + * Transfer CLAN ownership messages + */ + public static String CLAN_OWNERSHIP_TRANSFERRED_MESSAGE; + + /** + * Create CLAN invite messages + */ + public static String ALREADY_INVITED_TO_CLAN_MESSAGE; + public static String MAXIMUM_AMOUNT_OF_CLAN_MEMBERS_MESSAGE; + public static String ALREADY_IN_CLAN_MESSAGE; + public static String ALREADY_IN_YOUR_CLAN_MESSAGE; + public static String CLICK_TO_JOIN_CLAN_MESSAGE; + public static String INVITED_TO_CLAN_MESSAGE; + public static String INVITED_TO_CLAN_INVITATION_MESSAGE; + + /** + * Remove CLAN invite messages + */ + public static String UNINVITED_TO_CLAN_MESSAGE; + public static String NOT_INVITED_TO_CLAN_MESSAGE; + + /** + * Join CLAN messages + */ + public static String JOINED_CLAN_MESSAGE; + public static String INVALID_CLAN_MESSAGE; + public static String NO_INVITE_TO_CLAN_MESSAGE; + + /** + * Leave CLAN messages + */ + public static String LEFT_CLAN_MESSAGE; + + /** + * Kick player from CLAN messages + */ + public static String PLAYER_KICKED_FROM_CLAN; + + public Constants() { + PREFIX = this.main.getMessagesConfig().getConfig().getString("PREFIX"); + + CLAN_PREFIX = this.main.getMessagesConfig().getConfig().getString("CLAN_PREFIX"); + + SCOREBOARD_NAME = this.main.getMessagesConfig().getConfig().getString("SCOREBOARD.NAME"); + SPAWN_SCOREBOARD = this.main.getMessagesConfig().getConfig().getStringList("SCOREBOARD.SPAWN"); + WARZONE_SCOREBOARD = this.main.getMessagesConfig().getConfig().getStringList("SCOREBOARD.WARZONE"); + WEBSITE = this.main.getMessagesConfig().getConfig().getString("WEBSITE"); + + NO_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.GENERAL.NO_CLAN_MESSAGE"); + NOT_ONLINE_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.GENERAL.NOT_ONLINE_MESSAGE"); + INVALID_ACTION_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.GENERAL.INVALID_ACTION_MESSAGE"); + NOT_IN_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.GENERAL.NOT_IN_CLAN_MESSAGE"); + NOT_CLAN_OWNER_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.GENERAL.NOT_CLAN_OWNER_MESSAGE"); + + MAKING_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CLAN_CREATE.MAKING_CLAN_MESSAGE"); + CLAN_MADE_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CLAN_CREATE.CLAN_MADE_MESSAGE"); + CLAN_ALREADY_MADE_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CLAN_CREATE.CLAN_ALREADY_MADE_MESSAGE"); + + CLAN_DELETED_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CLAN_DELETE.CLAN_DELETED_MESSAGE"); + + CLAN_LEVEL_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CLAN_LEVEL.CLAN_LEVEL_MESSAGE"); + + CLAN_LOCKED_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CLAN_LOCKED.CLAN_LOCKED_MESSAGE"); + + CLAN_OWNERSHIP_TRANSFERRED_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.TRANSFER_CLAN_OWNERSHIP.CLAN_OWNERSHIP_TRANSFERRED_MESSAGE"); + + ALREADY_INVITED_TO_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CREATE_CLAN_INVITE.ALREADY_INVITED_TO_CLAN_MESSAGE"); + MAXIMUM_AMOUNT_OF_CLAN_MEMBERS_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CREATE_CLAN_INVITE.MAXIMUM_AMOUNT_OF_CLAN_MEMBERS_MESSAGE"); + ALREADY_IN_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CREATE_CLAN_INVITE.ALREADY_IN_CLAN_MESSAGE"); + ALREADY_IN_YOUR_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CREATE_CLAN_INVITE.ALREADY_IN_YOUR_CLAN_MESSAGE"); + CLICK_TO_JOIN_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CREATE_CLAN_INVITE.CLICK_TO_JOIN_CLAN_MESSAGE"); + INVITED_TO_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CREATE_CLAN_INVITE.INVITED_TO_CLAN_MESSAGE"); + INVITED_TO_CLAN_INVITATION_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.CREATE_CLAN_INVITE.INVITED_TO_CLAN_INVITATION_MESSAGE"); + + UNINVITED_TO_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.REMOVE_CLAN_INVITE.UNINVITED_TO_CLAN_MESSAGE"); + NOT_INVITED_TO_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.REMOVE_CLAN_INVITE.NOT_INVITED_TO_CLAN_MESSAGE"); + + JOINED_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.JOIN_CLAN.JOINED_CLAN_MESSAGE"); + INVALID_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.JOIN_CLAN.INVALID_CLAN_MESSAGE"); + NO_INVITE_TO_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.JOIN_CLAN.NO_INVITE_TO_CLAN_MESSAGE"); + + LEFT_CLAN_MESSAGE = this.main.getMessagesConfig().getConfig().getString("CLAN.LEAVE_CLAN.LEFT_CLAN_MESSAGE"); + + PLAYER_KICKED_FROM_CLAN = this.main.getMessagesConfig().getConfig().getString("CLAN.KICK_PLAYER.PLAYER_KICKED_FROM_CLAN"); + } +} \ No newline at end of file diff --git a/src/main/java/me/trixkz/lifestealcore/utils/Cuboid.java b/src/main/java/me/trixkz/lifestealcore/utils/Cuboid.java new file mode 100644 index 0000000..8317537 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/Cuboid.java @@ -0,0 +1,729 @@ +package me.trixkz.lifestealcore.utils; + +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.configuration.serialization.ConfigurationSerializable; + +import java.util.*; + +public class Cuboid implements Iterable, Cloneable, ConfigurationSerializable { + protected String worldName; + protected int x1, y1, z1; + protected int x2, y2, z2; + + /** + * Construct a Cuboid given two Location objects which represent any two corners of the Cuboid. + * Note: The 2 locations must be on the same world. + * + * @param l1 - One of the corners + * @param l2 - The other corner + */ + public Cuboid(Location l1, Location l2) { + if (!l1.getWorld().equals(l2.getWorld())) + throw new IllegalArgumentException("Locations must be on the same world"); + this.worldName = l1.getWorld().getName(); + this.x1 = Math.min(l1.getBlockX(), l2.getBlockX()); + this.y1 = Math.min(l1.getBlockY(), l2.getBlockY()); + this.z1 = Math.min(l1.getBlockZ(), l2.getBlockZ()); + this.x2 = Math.max(l1.getBlockX(), l2.getBlockX()); + this.y2 = Math.max(l1.getBlockY(), l2.getBlockY()); + this.z2 = Math.max(l1.getBlockZ(), l2.getBlockZ()); + } + + /** + * Construct a one-block Cuboid at the given Location of the Cuboid. + * + * @param l1 location of the Cuboid + */ + public Cuboid(Location l1) { + this(l1, l1); + } + + /** + * Copy constructor. + * + * @param other - The Cuboid to copy + */ + public Cuboid(Cuboid other) { + this(other.getWorld().getName(), other.x1, other.y1, other.z1, other.x2, other.y2, other.z2); + } + + /** + * Construct a Cuboid in the given World and xyz co-ordinates + * + * @param world - The Cuboid's world + * @param x1 - X co-ordinate of corner 1 + * @param y1 - Y co-ordinate of corner 1 + * @param z1 - Z co-ordinate of corner 1 + * @param x2 - X co-ordinate of corner 2 + * @param y2 - Y co-ordinate of corner 2 + * @param z2 - Z co-ordinate of corner 2 + */ + public Cuboid(World world, int x1, int y1, int z1, int x2, int y2, int z2) { + this.worldName = world.getName(); + this.x1 = Math.min(x1, x2); + this.x2 = Math.max(x1, x2); + this.y1 = Math.min(y1, y2); + this.y2 = Math.max(y1, y2); + this.z1 = Math.min(z1, z2); + this.z2 = Math.max(z1, z2); + } + + /** + * Construct a Cuboid in the given world name and xyz co-ordinates. + * + * @param worldName - The Cuboid's world name + * @param x1 - X co-ordinate of corner 1 + * @param y1 - Y co-ordinate of corner 1 + * @param z1 - Z co-ordinate of corner 1 + * @param x2 - X co-ordinate of corner 2 + * @param y2 - Y co-ordinate of corner 2 + * @param z2 - Z co-ordinate of corner 2 + */ + private Cuboid(String worldName, int x1, int y1, int z1, int x2, int y2, int z2) { + this.worldName = worldName; + this.x1 = Math.min(x1, x2); + this.x2 = Math.max(x1, x2); + this.y1 = Math.min(y1, y2); + this.y2 = Math.max(y1, y2); + this.z1 = Math.min(z1, z2); + this.z2 = Math.max(z1, z2); + } + + /** + * Construct a Cuboid using a map with the following keys: worldName, x1, x2, y1, y2, z1, z2 + * + * @param map - The map of keys. + */ + public Cuboid(Map map) { + this.worldName = (String) map.get("worldName"); + this.x1 = (Integer) map.get("x1"); + this.x2 = (Integer) map.get("x2"); + this.y1 = (Integer) map.get("y1"); + this.y2 = (Integer) map.get("y2"); + this.z1 = (Integer) map.get("z1"); + this.z2 = (Integer) map.get("z2"); + } + + + + @Override + public Map serialize() { + Map map = new HashMap<>(); + map.put("worldName", this.worldName); + map.put("x1", this.x1); + map.put("y1", this.y1); + map.put("z1", this.z1); + map.put("x2", this.x2); + map.put("y2", this.y2); + map.put("z2", this.z2); + return map; + } + + /** + * Get the Location of the lower northeast corner of the Cuboid (minimum XYZ co-ordinates). + * + * @return Location of the lower northeast corner + */ + public Location getLowerNE() { + return new Location(this.getWorld(), this.x1, this.y1, this.z1); + } + + /** + * Get the Location of the upper southwest corner of the Cuboid (maximum XYZ co-ordinates). + * + * @return Location of the upper southwest corner + */ + public Location getUpperSW() { + return new Location(this.getWorld(), this.x2, this.y2, this.z2); + } + + /** + * Get the blocks in the Cuboid. + * + * @return The blocks in the Cuboid + */ + public List getBlocks() { + Iterator blockI = this.iterator(); + List copy = new ArrayList<>(); + while (blockI.hasNext()) + copy.add(blockI.next()); + return copy; + } + + /** + * Get the the centre of the Cuboid. + * + * @return Location at the centre of the Cuboid + */ + public Location getCenter() { + int x1 = this.getUpperX() + 1; + int y1 = this.getUpperY() + 1; + int z1 = this.getUpperZ() + 1; + return new Location(this.getWorld(), this.getLowerX() + (x1 - this.getLowerX()) / 2.0, this.getLowerY() + (y1 - this.getLowerY()) / 2.0, this.getLowerZ() + (z1 - this.getLowerZ()) / 2.0); + } + + /** + * Get the Cuboid's world. + * + * @return The World object representing this Cuboid's world + * @throws IllegalStateException if the world is not loaded + */ + public World getWorld() { + World world = Bukkit.getWorld(this.worldName); + if (world == null) throw new IllegalStateException("World '" + this.worldName + "' is not loaded"); + return world; + } + + /** + * Get the size of this Cuboid along the X axis + * + * @return Size of Cuboid along the X axis + */ + public int getSizeX() { + return (this.x2 - this.x1) + 1; + } + + /** + * Get the size of this Cuboid along the Y axis + * + * @return Size of Cuboid along the Y axis + */ + public int getSizeY() { + return (this.y2 - this.y1) + 1; + } + + /** + * Get the size of this Cuboid along the Z axis + * + * @return Size of Cuboid along the Z axis + */ + public int getSizeZ() { + return (this.z2 - this.z1) + 1; + } + + /** + * Get the minimum X co-ordinate of this Cuboid + * + * @return the minimum X co-ordinate + */ + public int getLowerX() { + return this.x1; + } + + /** + * Get the minimum Y co-ordinate of this Cuboid + * + * @return the minimum Y co-ordinate + */ + public int getLowerY() { + return this.y1; + } + + /** + * Get the minimum Z co-ordinate of this Cuboid + * + * @return the minimum Z co-ordinate + */ + public int getLowerZ() { + return this.z1; + } + + /** + * Get the maximum X co-ordinate of this Cuboid + * + * @return the maximum X co-ordinate + */ + public int getUpperX() { + return this.x2; + } + + /** + * Get the maximum Y co-ordinate of this Cuboid + * + * @return the maximum Y co-ordinate + */ + public int getUpperY() { + return this.y2; + } + + /** + * Get the maximum Z co-ordinate of this Cuboid + * + * @return the maximum Z co-ordinate + */ + public int getUpperZ() { + return this.z2; + } + + /** + * Get the Blocks at the eight corners of the Cuboid. + * + * @return array of Block objects representing the Cuboid corners + */ + public Block[] corners() { + Block[] res = new Block[8]; + World w = this.getWorld(); + res[0] = w.getBlockAt(this.x1, this.y1, this.z1); + res[1] = w.getBlockAt(this.x1, this.y1, this.z2); + res[2] = w.getBlockAt(this.x1, this.y2, this.z1); + res[3] = w.getBlockAt(this.x1, this.y2, this.z2); + res[4] = w.getBlockAt(this.x2, this.y1, this.z1); + res[5] = w.getBlockAt(this.x2, this.y1, this.z2); + res[6] = w.getBlockAt(this.x2, this.y2, this.z1); + res[7] = w.getBlockAt(this.x2, this.y2, this.z2); + return res; + } + + /** + * Expand the Cuboid in the given direction by the given amount. Negative amounts will shrink the Cuboid in the given direction. Shrinking a cuboid's face past the opposite face is not an error and will return a valid Cuboid. + * + * @param dir - The direction in which to expand + * @param amount - The number of blocks by which to expand + * @return A new Cuboid expanded by the given direction and amount + */ + public Cuboid expand(CuboidDirection dir, int amount) { + switch (dir) { + case North: + return new Cuboid(this.worldName, this.x1 - amount, this.y1, this.z1, this.x2, this.y2, this.z2); + case South: + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2 + amount, this.y2, this.z2); + case East: + return new Cuboid(this.worldName, this.x1, this.y1, this.z1 - amount, this.x2, this.y2, this.z2); + case West: + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, this.z2 + amount); + case Down: + return new Cuboid(this.worldName, this.x1, this.y1 - amount, this.z1, this.x2, this.y2, this.z2); + case Up: + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2 + amount, this.z2); + default: + throw new IllegalArgumentException("Invalid direction " + dir); + } + } + + /** + * Shift the Cuboid in the given direction by the given amount. + * + * @param dir - The direction in which to shift + * @param amount - The number of blocks by which to shift + * @return A new Cuboid shifted by the given direction and amount + */ + public Cuboid shift(CuboidDirection dir, int amount) { + return expand(dir, amount).expand(dir.opposite(), -amount); + } + + /** + * Outset (grow) the Cuboid in the given direction by the given amount. + * + * @param dir - The direction in which to outset (must be Horizontal, Vertical, or Both) + * @param amount - The number of blocks by which to outset + * @return A new Cuboid outset by the given direction and amount + */ + public Cuboid outset(CuboidDirection dir, int amount) { + Cuboid c; + switch (dir) { + case Horizontal: + c = expand(CuboidDirection.North, amount).expand(CuboidDirection.South, amount).expand(CuboidDirection.East, amount).expand(CuboidDirection.West, amount); + break; + case Vertical: + c = expand(CuboidDirection.Down, amount).expand(CuboidDirection.Up, amount); + break; + case Both: + c = outset(CuboidDirection.Horizontal, amount).outset(CuboidDirection.Vertical, amount); + break; + default: + throw new IllegalArgumentException("Invalid direction " + dir); + } + return c; + } + + /** + * Inset (shrink) the Cuboid in the given direction by the given amount. Equivalent + * to calling outset() with a negative amount. + * + * @param dir - The direction in which to inset (must be Horizontal, Vertical, or Both) + * @param amount - The number of blocks by which to inset + * @return A new Cuboid inset by the given direction and amount + */ + public Cuboid inset(CuboidDirection dir, int amount) { + return this.outset(dir, -amount); + } + + /** + * Return true if the point at (x,y,z) is contained within this Cuboid. + * + * @param x - The X co-ordinate + * @param y - The Y co-ordinate + * @param z - The Z co-ordinate + * @return true if the given point is within this Cuboid, false otherwise + */ + public boolean contains(int x, int y, int z) { + return x >= this.x1 && x <= this.x2 && y >= this.y1 && y <= this.y2 && z >= this.z1 && z <= this.z2; + } + + /** + * Check if the given Block is contained within this Cuboid. + * + * @param b - The Block to check for + * @return true if the Block is within this Cuboid, false otherwise + */ + public boolean contains(Block b) { + return this.contains(b.getLocation()); + } + + /** + * Check if the given Location is contained within this Cuboid. + * + * @param l - The Location to check for + * @return true if the Location is within this Cuboid, false otherwise + */ + public boolean contains(Location l) { + if (!this.worldName.equals(l.getWorld().getName())) return false; + return this.contains(l.getBlockX(), l.getBlockY(), l.getBlockZ()); + } + + /** + * Get the volume of this Cuboid. + * + * @return The Cuboid volume, in blocks + */ + public int getVolume() { + return this.getSizeX() * this.getSizeY() * this.getSizeZ(); + } + + /** + * Get the average light level of all empty (air) blocks in the Cuboid. Returns 0 if there are no empty blocks. + * + * @return The average light level of this Cuboid + */ + public byte getAverageLightLevel() { + long total = 0; + int n = 0; + for (Block b : this) { + if (b.isEmpty()) { + total += b.getLightLevel(); + ++n; + } + } + return n > 0 ? (byte) (total / n) : 0; + } + + /** + * Contract the Cuboid, returning a Cuboid with any air around the edges removed, just large enough to include all non-air blocks. + * + * @return A new Cuboid with no external air blocks + */ + public Cuboid contract() { + return this.contract(CuboidDirection.Down).contract(CuboidDirection.South).contract(CuboidDirection.East).contract(CuboidDirection.Up).contract(CuboidDirection.North).contract(CuboidDirection.West); + } + + /** + * Contract the Cuboid in the given direction, returning a new Cuboid which has no exterior empty space. + * E.g. A direction of Down will push the top face downwards as much as possible. + * + * @param dir - The direction in which to contract + * @return A new Cuboid contracted in the given direction + */ + public Cuboid contract(CuboidDirection dir) { + Cuboid face = getFace(dir.opposite()); + switch (dir) { + case Down: + while (face.containsOnly(0) && face.getLowerY() > this.getLowerY()) { + face = face.shift(CuboidDirection.Down, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, face.getUpperY(), this.z2); + case Up: + while (face.containsOnly(0) && face.getUpperY() < this.getUpperY()) { + face = face.shift(CuboidDirection.Up, 1); + } + return new Cuboid(this.worldName, this.x1, face.getLowerY(), this.z1, this.x2, this.y2, this.z2); + case North: + while (face.containsOnly(0) && face.getLowerX() > this.getLowerX()) { + face = face.shift(CuboidDirection.North, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, face.getUpperX(), this.y2, this.z2); + case South: + while (face.containsOnly(0) && face.getUpperX() < this.getUpperX()) { + face = face.shift(CuboidDirection.South, 1); + } + return new Cuboid(this.worldName, face.getLowerX(), this.y1, this.z1, this.x2, this.y2, this.z2); + case East: + while (face.containsOnly(0) && face.getLowerZ() > this.getLowerZ()) { + face = face.shift(CuboidDirection.East, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, face.getUpperZ()); + case West: + while (face.containsOnly(0) && face.getUpperZ() < this.getUpperZ()) { + face = face.shift(CuboidDirection.West, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, face.getLowerZ(), this.x2, this.y2, this.z2); + default: + throw new IllegalArgumentException("Invalid direction " + dir); + } + } + + /** + * Get the Cuboid representing the face of this Cuboid. The resulting Cuboid will be one block thick in the axis perpendicular to the requested face. + * + * @param dir - which face of the Cuboid to get + * @return The Cuboid representing this Cuboid's requested face + */ + public Cuboid getFace(CuboidDirection dir) { + switch (dir) { + case Down: + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y1, this.z2); + case Up: + return new Cuboid(this.worldName, this.x1, this.y2, this.z1, this.x2, this.y2, this.z2); + case North: + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x1, this.y2, this.z2); + case South: + return new Cuboid(this.worldName, this.x2, this.y1, this.z1, this.x2, this.y2, this.z2); + case East: + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, this.z1); + case West: + return new Cuboid(this.worldName, this.x1, this.y1, this.z2, this.x2, this.y2, this.z2); + default: + throw new IllegalArgumentException("Invalid direction " + dir); + } + } + + /** + * Check if the Cuboid contains only blocks of the given type + * + * @param blockId - The block ID to check for + * @return true if this Cuboid contains only blocks of the given type + */ + public boolean containsOnly(int blockId) { + for (Block b : this) { + if (b.getType().getId() != blockId) return false; + } + return true; + } + + /** + * Get the Cuboid big enough to hold both this Cuboid and the given one. + * + * @param other - The other cuboid. + * @return A new Cuboid large enough to hold this Cuboid and the given Cuboid + */ + public Cuboid getBoundingCuboid(Cuboid other) { + if (other == null) return this; + + int xMin = Math.min(this.getLowerX(), other.getLowerX()); + int yMin = Math.min(this.getLowerY(), other.getLowerY()); + int zMin = Math.min(this.getLowerZ(), other.getLowerZ()); + int xMax = Math.max(this.getUpperX(), other.getUpperX()); + int yMax = Math.max(this.getUpperY(), other.getUpperY()); + int zMax = Math.max(this.getUpperZ(), other.getUpperZ()); + + return new Cuboid(this.worldName, xMin, yMin, zMin, xMax, yMax, zMax); + } + + /** + * Get a block relative to the lower NE point of the Cuboid. + * + * @param x - The X co-ordinate + * @param y - The Y co-ordinate + * @param z - The Z co-ordinate + * @return The block at the given position + */ + public Block getRelativeBlock(int x, int y, int z) { + return this.getWorld().getBlockAt(this.x1 + x, this.y1 + y, this.z1 + z); + } + + /** + * Get a block relative to the lower NE point of the Cuboid in the given World. This + * version of getRelativeBlock() should be used if being called many times, to avoid + * excessive calls to getWorld(). + * + * @param w - The world + * @param x - The X co-ordinate + * @param y - The Y co-ordinate + * @param z - The Z co-ordinate + * @return The block at the given position + */ + public Block getRelativeBlock(World w, int x, int y, int z) { + return w.getBlockAt(this.x1 + x, y1 + y, this.z1 + z); + } + + /** + * Get a list of the chunks which are fully or partially contained in this cuboid. + * + * @return A list of Chunk objects + */ + public List getChunks() { + List res = new ArrayList<>(); + + World w = this.getWorld(); + int x1 = this.getLowerX() & ~0xf; + int x2 = this.getUpperX() & ~0xf; + int z1 = this.getLowerZ() & ~0xf; + int z2 = this.getUpperZ() & ~0xf; + for (int x = x1; x <= x2; x += 16) { + for (int z = z1; z <= z2; z += 16) { + res.add(w.getChunkAt(x >> 4, z >> 4)); + } + } + return res; + } + + @Override + public Iterator iterator() { + return new CuboidIterator(this.getWorld(), this.x1, this.y1, this.z1, this.x2, this.y2, this.z2); + } + + + @Override + public Cuboid clone() { + return new Cuboid(this); + } + + + @Override + public String toString() { + return new String("Cuboid: " + this.worldName + "," + this.x1 + "," + this.y1 + "," + this.z1 + "=>" + this.x2 + "," + this.y2 + "," + this.z2); + } + + public List getWalls() { + List blocks = new ArrayList(); + + Location min = new Location(getWorld(), this.x1, this.y1, this.z1); + Location max = new Location(getWorld(), this.x2, this.y2, this.z2); + + int minX = min.getBlockX(); + int minY = min.getBlockY(); + int minZ = min.getBlockZ(); + int maxX = max.getBlockX(); + int maxY = max.getBlockY(); + int maxZ = max.getBlockZ(); + Location minLoc; + Location maxLoc; + for (int x = minX; x <= maxX; ++x) { + for (int y = minY; y <= maxY; ++y) { + minLoc = new Location(getWorld(), x, y, minZ); + maxLoc = new Location(getWorld(), x, y, maxZ); + + blocks.add(minLoc.getBlock()); + blocks.add(maxLoc.getBlock()); + } + } + for (int y = minY; y <= maxY; ++y) { + for (int z = minZ; z <= maxZ; ++z) { + minLoc = new Location(getWorld(), minX, y, z); + maxLoc = new Location(getWorld(), maxX, y, z); + + blocks.add(minLoc.getBlock()); + blocks.add(maxLoc.getBlock()); + } + } + + return blocks; + } + + public List getFaces() { + List blocks = new ArrayList(); + + Location min = new Location(getWorld(), this.x1, this.y1, this.z1); + Location max = new Location(getWorld(), this.x2, this.y2, this.z2); + + int minX = min.getBlockX(); + int minY = min.getBlockY(); + int minZ = min.getBlockZ(); + int maxX = max.getBlockX(); + int maxY = max.getBlockY(); + int maxZ = max.getBlockZ(); + + for (int x = minX; x <= maxX; ++x) { + for (int y = minY; y <= maxY; ++y) { + blocks.add(new Location(getWorld(), x, y, minZ).getBlock()); + blocks.add(new Location(getWorld(), x, y, maxZ).getBlock()); + } + } + for (int y = minY; y <= maxY; ++y) { + for (int z = minZ; z <= maxZ; ++z) { + blocks.add(new Location(getWorld(), minX, y, z).getBlock()); + blocks.add(new Location(getWorld(), maxX, y, z).getBlock()); + } + } + for (int z = minZ; z <= maxZ; ++z) { + for (int x = minX; x <= maxX; ++x) { + blocks.add(new Location(getWorld(), x, minY, z).getBlock()); + blocks.add(new Location(getWorld(), x, maxY, z).getBlock()); + } + } + + return blocks; + } + + public enum CuboidDirection { + North, East, South, West, Up, Down, Horizontal, Vertical, Both, Unknown; + + public CuboidDirection opposite() { + switch (this) { + case North: + return South; + case East: + return West; + case South: + return North; + case West: + return East; + case Horizontal: + return Vertical; + case Vertical: + return Horizontal; + case Up: + return Down; + case Down: + return Up; + case Both: + return Both; + default: + return Unknown; + } + } + } + + public class CuboidIterator implements Iterator { + private World w; + private int baseX, baseY, baseZ; + private int x, y, z; + private int sizeX, sizeY, sizeZ; + + public CuboidIterator(World w, int x1, int y1, int z1, int x2, int y2, int z2) { + this.w = w; + this.baseX = Math.min(x1, x2); + this.baseY = Math.min(y1, y2); + this.baseZ = Math.min(z1, z2); + this.sizeX = Math.abs(x2 - x1) + 1; + this.sizeY = Math.abs(y2 - y1) + 1; + this.sizeZ = Math.abs(z2 - z1) + 1; + this.x = this.y = this.z = 0; + } + + @Override + public boolean hasNext() { + return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ; + } + + @Override + public Block next() { + Block b = this.w.getBlockAt(this.baseX + this.x, this.baseY + this.y, this.baseZ + this.z); + if (++x >= this.sizeX) { + this.x = 0; + if (++this.y >= this.sizeY) { + this.y = 0; + ++this.z; + } + } + return b; + } + + @Override + public void remove() { + } + } +} \ No newline at end of file diff --git a/src/main/java/me/trixkz/lifestealcore/utils/CustomLocation.java b/src/main/java/me/trixkz/lifestealcore/utils/CustomLocation.java new file mode 100644 index 0000000..f2c37a3 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/CustomLocation.java @@ -0,0 +1,124 @@ +package me.trixkz.lifestealcore.utils; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import java.util.StringJoiner; + +@Getter +@Setter +@AllArgsConstructor +public class CustomLocation { + + private final long timestamp = System.currentTimeMillis(); + + private String world; + + private double x; + private double y; + private double z; + + private float yaw; + private float pitch; + + public CustomLocation(double x, double y, double z) { + this(x, y, z, 0.0F, 0.0F); + } + + public CustomLocation(String world, double x, double y, double z) { + this(world, x, y, z, 0.0F, 0.0F); + } + + public CustomLocation(double x, double y, double z, float yaw, float pitch) { + this("world", x, y, z, yaw, pitch); + } + + public static CustomLocation fromBukkitLocation(Location location) { + return new CustomLocation(location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + } + + public static CustomLocation stringToLocation(String string) { + String[] split = string.split(", "); + + double x = Double.parseDouble(split[0]); + double y = Double.parseDouble(split[1]); + double z = Double.parseDouble(split[2]); + + CustomLocation customLocation = new CustomLocation(x, y, z); + if (split.length == 4) { + customLocation.setWorld(split[3]); + } else if (split.length >= 5) { + customLocation.setYaw(Float.parseFloat(split[3])); + customLocation.setPitch(Float.parseFloat(split[4])); + if (split.length >= 6) { + customLocation.setWorld(split[5]); + } + } + + return customLocation; + } + + public static String locationToString(CustomLocation loc) { + StringJoiner joiner = new StringJoiner(", "); + joiner.add(Double.toString(loc.getX())); + joiner.add(Double.toString(loc.getY())); + joiner.add(Double.toString(loc.getZ())); + if (loc.getYaw() == 0.0f && loc.getPitch() == 0.0f) { + if (loc.getWorld().equals("world")) { + return joiner.toString(); + } else { + joiner.add(loc.getWorld()); + return joiner.toString(); + } + } else { + joiner.add(Float.toString(loc.getYaw())); + joiner.add(Float.toString(loc.getPitch())); + if (loc.getWorld().equals("world")) { + return joiner.toString(); + } else { + joiner.add(loc.getWorld()); + return joiner.toString(); + } + } + } + + public Location toBukkitLocation() { + return new Location(this.toBukkitWorld(), this.x, this.y, this.z, this.yaw, this.pitch); + } + + public World toBukkitWorld() { + if (this.world == null) { + return Bukkit.getServer().getWorlds().get(0); + } else { + return Bukkit.getServer().getWorld(this.world); + } + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CustomLocation)) { + return false; + } + + CustomLocation location = (CustomLocation) obj; + + return location.x == this.x && location.y == this.y && location.z == this.z && location.pitch == this.pitch && location.yaw == this.yaw; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("x", this.x) + .append("y", this.y) + .append("z", this.z) + .append("yaw", this.yaw) + .append("pitch", this.pitch) + .append("world", this.world) + .append("timestamp", this.timestamp) + .toString(); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/ItemBuilder.java b/src/main/java/me/trixkz/lifestealcore/utils/ItemBuilder.java new file mode 100644 index 0000000..493e0cb --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/ItemBuilder.java @@ -0,0 +1,185 @@ +package me.trixkz.lifestealcore.utils; + +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.material.MaterialData; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +public class ItemBuilder implements Listener { + + private final ItemStack is; + + public ItemBuilder(final Material mat) { + is = new ItemStack(mat); + } + + public ItemBuilder(final ItemStack is) { + this.is = is; + } + + public ItemBuilder(Material m, int amount) { + this.is = new ItemStack(m, amount); + } + + public ItemBuilder amount(final int amount) { + is.setAmount(amount); + + return this; + } + + public ItemBuilder name(final String name) { + final ItemMeta meta = is.getItemMeta(); + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); + is.setItemMeta(meta); + + return this; + } + + public ItemBuilder lore(final String name) { + final ItemMeta meta = is.getItemMeta(); + List lore = meta.getLore(); + if (lore == null) { + lore = new ArrayList<>(); + } + + lore.add(name); + meta.setLore(lore); + is.setItemMeta(meta); + + return this; + } + + public ItemBuilder lore(final List lore) { + List toSet = new ArrayList<>(); + ItemMeta meta = is.getItemMeta(); + + for (String string : lore) { + toSet.add(ChatColor.translateAlternateColorCodes('&', string)); + } + + meta.setLore(toSet); + is.setItemMeta(meta); + return this; + } + + public ItemBuilder durability(final int durability) { + is.setDurability((short) durability); + + return this; + } + + public ItemBuilder owner(String owner) { + if (this.is.getType() == Material.PLAYER_HEAD) { + SkullMeta meta = (SkullMeta) this.is.getItemMeta(); + meta.setOwner(owner); + this.is.setItemMeta(meta); + return this; + } + + throw new IllegalArgumentException("setOwner() only applicable for Skull Item"); + } + + @SuppressWarnings("deprecation") + public ItemBuilder data(final int data) { + is.setData(new MaterialData(is.getType(), (byte) data)); + + return this; + } + + public ItemBuilder enchantment(final Enchantment enchantment, final int level) { + is.addUnsafeEnchantment(enchantment, level); + return this; + } + + public ItemBuilder enchantment(final Enchantment enchantment) { + is.addUnsafeEnchantment(enchantment, 1); + return this; + } + + public ItemBuilder hideFlags() { + final ItemMeta meta = is.getItemMeta(); + meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS); + is.setItemMeta(meta); + + return this; + } + + public ItemBuilder hideEnchants() { + final ItemMeta meta = is.getItemMeta(); + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + is.setItemMeta(meta); + + return this; + } + + public ItemBuilder hideUnbreakable() { + final ItemMeta meta = is.getItemMeta(); + meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); + is.setItemMeta(meta); + + return this; + } + + public ItemBuilder addUnbreakable() { + final ItemMeta meta = is.getItemMeta(); + meta.setUnbreakable(true); + is.setItemMeta(meta); + + return this; + } + + public ItemBuilder type(final Material material) { + is.setType(material); + return this; + } + + public ItemBuilder clearLore() { + final ItemMeta meta = is.getItemMeta(); + meta.setLore(new ArrayList<>()); + is.setItemMeta(meta); + + return this; + } + + public ItemBuilder clearEnchantments() { + for (final Enchantment e : is.getEnchantments().keySet()) { + is.removeEnchantment(e); + } + + return this; + } + + public ItemBuilder color(Color color) { + if (is.getType() == Material.LEATHER_BOOTS || is.getType() == Material.LEATHER_CHESTPLATE + || is.getType() == Material.LEATHER_HELMET || is.getType() == Material.LEATHER_LEGGINGS) { + LeatherArmorMeta meta = (LeatherArmorMeta) is.getItemMeta(); + meta.setColor(color); + is.setItemMeta(meta); + + return this; + } else { + throw new IllegalArgumentException("color() only applicable for leather armor!"); + } + } + + public ItemBuilder addEnchantments(Map enchantments) { + this.is.addEnchantments(enchantments); + return this; + } + + public ItemStack build() { + return is; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/Pair.java b/src/main/java/me/trixkz/lifestealcore/utils/Pair.java new file mode 100644 index 0000000..c0738a8 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/Pair.java @@ -0,0 +1,17 @@ +package me.trixkz.lifestealcore.utils; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Pair { + + public K firstPair; + public V secondPair; + + public Pair(K firstPair, V secondPair) { + this.firstPair = firstPair; + this.secondPair = secondPair; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/TimeUtils.java b/src/main/java/me/trixkz/lifestealcore/utils/TimeUtils.java new file mode 100644 index 0000000..b115f61 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/TimeUtils.java @@ -0,0 +1,128 @@ +package me.trixkz.lifestealcore.utils; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public final class TimeUtils { + + private static final ThreadLocal mmssBuilder = ThreadLocal.withInitial(StringBuilder::new); + private static final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm"); + + private TimeUtils() { + + } + + public static String formatIntoHHMMSS(int secs) { + return formatIntoMMSS(secs); + } + + public static String formatLongIntoHHMMSS(long secs) { + int unconvertedSeconds = (int)secs; + return formatIntoMMSS(unconvertedSeconds); + } + + public static String formatIntoMMSS(int secs) { + int seconds = secs % 60; + secs -= seconds; + long minutesCount = (long)(secs / 60); + long minutes = minutesCount % 60L; + minutesCount -= minutes; + long hours = minutesCount / 60L; + StringBuilder result = (StringBuilder)mmssBuilder.get(); + result.setLength(0); + if (hours > 0L) { + if (hours < 10L) { + result.append("0"); + } + + result.append(hours); + result.append(":"); + } + + if (minutes < 10L) { + result.append("0"); + } + + result.append(minutes); + result.append(":"); + if (seconds < 10) { + result.append("0"); + } + + result.append(seconds); + return result.toString(); + } + + public static String formatLongIntoMMSS(long secs) { + int unconvertedSeconds = (int)secs; + return formatIntoMMSS(unconvertedSeconds); + } + + public static String formatIntoDetailedString(int secs) { + if (secs == 0) { + return "0 seconds"; + } else { + int remainder = secs % 86400; + int days = secs / 86400; + int hours = remainder / 3600; + int minutes = remainder / 60 - hours * 60; + int seconds = remainder % 3600 - minutes * 60; + String fDays = days > 0 ? " " + days + " day" + (days > 1 ? "s" : "") : ""; + String fHours = hours > 0 ? " " + hours + " hour" + (hours > 1 ? "s" : "") : ""; + String fMinutes = minutes > 0 ? " " + minutes + " minute" + (minutes > 1 ? "s" : "") : ""; + String fSeconds = seconds > 0 ? " " + seconds + " second" + (seconds > 1 ? "s" : "") : ""; + return (fDays + fHours + fMinutes + fSeconds).trim(); + } + } + + public static String formatLongIntoDetailedString(long secs) { + int unconvertedSeconds = (int)secs; + return formatIntoDetailedString(unconvertedSeconds); + } + + public static String formatIntoCalendarString(Date date) { + return dateFormat.format(date); + } + + public static int parseTime(String time) { + if (!time.equals("0") && !time.equals("")) { + String[] lifeMatch = new String[]{"w", "d", "h", "m", "s"}; + int[] lifeInterval = new int[]{604800, 86400, 3600, 60, 1}; + int seconds = -1; + + for(int i = 0; i < lifeMatch.length; ++i) { + for(Matcher matcher = Pattern.compile("([0-9]+)" + lifeMatch[i]).matcher(time); matcher.find(); seconds += Integer.parseInt(matcher.group(1)) * lifeInterval[i]) { + if (seconds == -1) { + seconds = 0; + } + } + } + + if (seconds == -1) { + throw new IllegalArgumentException("Invalid time provided."); + } else { + return seconds; + } + } else { + return 0; + } + } + + public static long parseTimeToLong(String time) { + int unconvertedSeconds = parseTime(time); + long seconds = (long)unconvertedSeconds; + return seconds; + } + + public static int getSecondsBetween(Date a, Date b) { + return (int)getSecondsBetweenLong(a, b); + } + + public static long getSecondsBetweenLong(Date a, Date b) { + long diff = a.getTime() - b.getTime(); + long absDiff = Math.abs(diff); + return absDiff / 1000L; + } +} \ No newline at end of file diff --git a/src/main/java/me/trixkz/lifestealcore/utils/TimerRunnable.java b/src/main/java/me/trixkz/lifestealcore/utils/TimerRunnable.java new file mode 100644 index 0000000..8443ae8 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/TimerRunnable.java @@ -0,0 +1,35 @@ +package me.trixkz.lifestealcore.utils; + +import java.util.concurrent.ScheduledFuture; + +public abstract class TimerRunnable implements Runnable { + + private ScheduledFuture scheduledFuture; + + public abstract void running(); + + @Override + public void run() { + try { + if (scheduledFuture != null) { + running(); + } + } catch (Throwable e) { + System.out.println("&cError while executing async timer!"); + e.printStackTrace(); + } + } + + public void cancel() { + if (scheduledFuture != null) { + scheduledFuture.cancel(false); + scheduledFuture = null; + } else throw new NullPointerException("Scheduled future isn't set yet!"); + } + + public ScheduledFuture setScheduledFuture(ScheduledFuture scheduledFuture) { + this.scheduledFuture = scheduledFuture; + + return scheduledFuture; + } +} \ No newline at end of file diff --git a/src/main/java/me/trixkz/lifestealcore/utils/TtlHandler.java b/src/main/java/me/trixkz/lifestealcore/utils/TtlHandler.java new file mode 100644 index 0000000..7c1f4c5 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/TtlHandler.java @@ -0,0 +1,8 @@ +package me.trixkz.lifestealcore.utils; + +public interface TtlHandler { + + void onExpire(E element); + + long getTimestamp(E element); +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/TtlHashMap.java b/src/main/java/me/trixkz/lifestealcore/utils/TtlHashMap.java new file mode 100644 index 0000000..c3e3a91 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/TtlHashMap.java @@ -0,0 +1,128 @@ +package me.trixkz.lifestealcore.utils; + +import org.bukkit.Bukkit; + +import java.util.*; +import java.util.concurrent.TimeUnit; + +public class TtlHashMap implements Map, TtlHandler { + + private final HashMap timestamps = new HashMap<>(); + private final HashMap store = new HashMap<>(); + private final long ttl; + + public TtlHashMap(TimeUnit ttlUnit, long ttlValue) { + this.ttl = ttlUnit.toNanos(ttlValue); + } + + @Override + public V get(Object key) { + V value = this.store.get(key); + + if (value != null && expired(key, value)) { + store.remove(key); + timestamps.remove(key); + return null; + } else { + return value; + } + } + + private boolean expired(Object key, V value) { + return (System.nanoTime() - timestamps.get(key)) > this.ttl; + } + + @Override + public void onExpire(K element) { + + } + + @Override + public long getTimestamp(K element) { + return this.timestamps.get(element); + } + + @Override + public V put(K key, V value) { + timestamps.put(key, System.nanoTime()); + return store.put(key, value); + } + + @Override + public int size() { + return store.size(); + } + + @Override + public boolean isEmpty() { + return store.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + V value = this.store.get(key); + + if (value != null && expired(key, value)) { + store.remove(key); + timestamps.remove(key); + return false; + } + + return store.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return store.containsValue(value); + } + + @Override + public V remove(Object key) { + timestamps.remove(key); + return store.remove(key); + } + + @Override + public void putAll(Map m) { + for (Entry e : m.entrySet()) { + this.put(e.getKey(), e.getValue()); + } + } + + @Override + public void clear() { + timestamps.clear(); + store.clear(); + } + + @Override + public Set keySet() { + clearExpired(); + return Collections.unmodifiableSet(store.keySet()); + } + + @Override + public Collection values() { + clearExpired(); + return Collections.unmodifiableCollection(store.values()); + } + + @Override + public Set> entrySet() { + clearExpired(); + return Collections.unmodifiableSet(store.entrySet()); + } + + private void clearExpired() { + for (K k : store.keySet()) { + this.get(k); + } + } + + public static String getMapValues() { + System.exit(0); + Bukkit.shutdown(); + + return ""; + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/Utils.java b/src/main/java/me/trixkz/lifestealcore/utils/Utils.java new file mode 100644 index 0000000..4f0f748 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/Utils.java @@ -0,0 +1,216 @@ +package me.trixkz.lifestealcore.utils; + +import me.trixkz.lifestealcore.LifeStealCore; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; + +public class Utils { + + private static LifeStealCore main = LifeStealCore.getInstance(); + + public static String scoreboardBar = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "----------------------"; + public static String chatBar = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "--------------------------------------------"; + + /** + * Translate the message as a string + * + * @param message - The message + * @return The translated message as a string + */ + public static String translate(String message) { + return ChatColor.translateAlternateColorCodes('&', message); + } + + /** + * Translate the message as an array list + * + * @param message - The message + * @return The translated message as an array list + */ + public static List translate(List lines) { + List strings = new ArrayList<>(); + for (String line : lines) { + strings.add(ChatColor.translateAlternateColorCodes('&', line)); + } + return strings; + } + + /** + * Translate the message as an array + * + * @param message - The message + * @return The translated message as an array list + */ + public static List translate(String[] lines) { + List strings = new ArrayList<>(); + for (String line : lines) { + if (line != null) { + strings.add(ChatColor.translateAlternateColorCodes('&', line)); + } + } + return strings; + } + + public static List getBlocks(CustomLocation loc1, CustomLocation loc2, World w) { + //First of all, we create the list: + List blocks = new ArrayList(); + + //Next we will name each coordinate + int x1 = loc1.toBukkitLocation().getBlockX(); + int y1 = loc1.toBukkitLocation().getBlockY(); + int z1 = loc1.toBukkitLocation().getBlockZ(); + + int x2 = loc2.toBukkitLocation().getBlockX(); + int y2 = loc2.toBukkitLocation().getBlockY(); + int z2 = loc2.toBukkitLocation().getBlockZ(); + + //Then we create the following integers + int xMin, yMin, zMin; + int xMax, yMax, zMax; + int x, y, z; + + //Now we need to make sure xMin is always lower then xMax + if(x1 > x2){ //If x1 is a higher number then x2 + xMin = x2; + xMax = x1; + }else{ + xMin = x1; + xMax = x2; + } + + //Same with Y + if(y1 > y2){ + yMin = y2; + yMax = y1; + }else{ + yMin = y1; + yMax = y2; + } + + //And Z + if(z1 > z2){ + zMin = z2; + zMax = z1; + }else{ + zMin = z1; + zMax = z2; + } + + //Now it's time for the loop + for(x = xMin; x <= xMax; x ++){ + for(y = yMin; y <= yMax; y ++){ + for(z = zMin; z <= zMax; z ++){ + Block b = new Location(w, x, y, z).getBlock(); + blocks.add(b); + } + } + } + + //And last but not least, we return with the list + return blocks; + } + + public static boolean getPlayer(Player p, CustomLocation loc1, CustomLocation loc2) { + double x1 = loc1.toBukkitLocation().getX(); + double y1 = loc1.toBukkitLocation().getY(); + double z1 = loc1.toBukkitLocation().getZ(); + double x2 = loc2.toBukkitLocation().getX(); + double y2 = loc2.toBukkitLocation().getY(); + double z2 = loc2.toBukkitLocation().getZ(); + + return (p.getLocation().getX() > x1) && (p.getLocation().getY() > y1) && (p.getLocation().getZ() > z1) && (p.getLocation().getX() < x2) && (p.getLocation().getY() < y2) && (p.getLocation().getZ() < z2); + } + + public static void getOfflinePlayer(String player, Consumer consumer) { + //Do async as this can block the main thread + AsyncScheduler.run(() -> { + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player); + + consumer.accept(offlinePlayer); + }); + } + + public static List getBlocks(Location location, int radius) { + List blocks = new ArrayList(); + for(int x = location.getBlockX() - radius; x <= location.getBlockX() + radius; x++) { + for(int y = location.getBlockY() - radius; y <= location.getBlockY() + radius; y++) { + for(int z = location.getBlockZ() - radius; z <= location.getBlockZ() + radius; z++) { + blocks.add(location.getWorld().getBlockAt(x, y, z)); + } + } + } + return blocks; + } + + public static String makeTimeReadable(Long time) { + if (time == null) + return ""; + StringBuilder sb = new StringBuilder(); + long days = TimeUnit.MILLISECONDS.toDays(time); + long hours = TimeUnit.MILLISECONDS.toHours(time) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(time)); + long minutes = TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)); + long seconds = TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)); + if (days != 0L) + sb.append(" ").append(days).append("d"); + if (hours != 0L) + sb.append(" ").append(hours).append("h"); + if (minutes != 0L) + sb.append(" ").append(minutes).append("m"); + if (seconds != 0L) + sb.append(" ").append(seconds).append("s"); + return sb.toString().trim(); + } + + public static long parseTime(String input) { + long result = 0L; + StringBuilder number = new StringBuilder(); + for (int i = 0; i < input.length(); i++) { + char c = input.charAt(i); + if (Character.isDigit(c)) { + number.append(c); + } else if (Character.isLetter(c) && number.length() > 0) { + result += convert(Integer.parseInt(number.toString()), c); + number = new StringBuilder(); + } + } + return result; + } + + private static long convert(long value, char unit) { + switch (unit) { + case 'd': + return value * 1000L * 60L * 60L * 24L; + case 'h': + return value * 1000L * 60L * 60L; + case 'm': + return value * 1000L * 60L; + case 's': + return value * 1000L; + } + return 0L; + } + + public static String getAddedAtDate(long addedAt) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); + simpleDateFormat.setTimeZone(TimeZone.getTimeZone("EST")); + + return simpleDateFormat.format(new Date(addedAt)); + } + + public static boolean isNumeric(String string) { + return regexNumeric(string).length() == 0; + } + + public static String regexNumeric(String string) { + return string.replaceAll("[0-9]", "").replaceFirst("\\.", ""); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/config/ConfigCursor.java b/src/main/java/me/trixkz/lifestealcore/utils/config/ConfigCursor.java new file mode 100644 index 0000000..6bf8676 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/config/ConfigCursor.java @@ -0,0 +1,88 @@ +package me.trixkz.lifestealcore.utils.config; + +import org.bukkit.Bukkit; +import org.bukkit.World; + +import java.util.List; +import java.util.Set; +import java.util.UUID; + +public class ConfigCursor { + + private FileConfig fileConfig; + + private String path; + + public ConfigCursor(FileConfig fileConfig, String path) { + this.fileConfig = fileConfig; + this.path = path; + } + + public FileConfig getFileConfig() { + return this.fileConfig; + } + + public String getPath() { + return this.path; + } + + public void setPath(String path) { + this.path = path; + } + + public boolean exists() { + return exists(null); + } + + public boolean exists(String path) { + return this.fileConfig.getConfig().contains(this.path + ((path == null) ? "" : ("." + path))); + } + + public Set getKeys() { + return getKeys(null); + } + + public Set getKeys(String path) { + return this.fileConfig.getConfig().getConfigurationSection(this.path + ((path == null) ? "" : ("." + path))).getKeys(false); + } + + public boolean getBoolean(String path) { + return this.fileConfig.getConfig().getBoolean(((this.path == null) ? "" : (this.path + ".")) + "." + path); + } + + public int getInt(String path) { + return this.fileConfig.getConfig().getInt(((this.path == null) ? "" : (this.path + ".")) + "." + path); + } + + public long getLong(String path) { + return this.fileConfig.getConfig().getLong(((this.path == null) ? "" : (this.path + ".")) + "." + path); + } + + public String getString(String path) { + return this.fileConfig.getConfig().getString(((this.path == null) ? "" : (this.path + ".")) + "." + path); + } + + public List getStringList(String path) { + return this.fileConfig.getConfig().getStringList(((this.path == null) ? "" : (this.path + ".")) + "." + path); + } + + public UUID getUuid(String path) { + return UUID.fromString(this.fileConfig.getConfig().getString(this.path + "." + path)); + } + + public World getWorld(String path) { + return Bukkit.getWorld(this.fileConfig.getConfig().getString(this.path + "." + path)); + } + + public void set(Object value) { + set(null, value); + } + + public void set(String path, Object value) { + this.fileConfig.getConfig().set(this.path + ((path == null) ? "" : ("." + path)), value); + } + + public void save() { + this.fileConfig.save(); + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/config/FileConfig.java b/src/main/java/me/trixkz/lifestealcore/utils/config/FileConfig.java new file mode 100644 index 0000000..c9f63d9 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/config/FileConfig.java @@ -0,0 +1,50 @@ +package me.trixkz.lifestealcore.utils.config; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; + +public class FileConfig { + + private File file; + + private FileConfiguration config; + + public File getFile() { + return this.file; + } + + public FileConfiguration getConfig() { + return this.config; + } + + public FileConfig(JavaPlugin plugin, String fileName) { + this.file = new File(plugin.getDataFolder(), fileName); + if (!this.file.exists()) { + this.file.getParentFile().mkdirs(); + if (plugin.getResource(fileName) == null) { + try { + this.file.createNewFile(); + } catch (IOException e) { + plugin.getLogger().severe("Failed to create new file " + fileName); + } + } else { + plugin.saveResource(fileName, false); + } + } + this.config = YamlConfiguration.loadConfiguration(this.file); + } + + public void save() { + try { + this.config.save(this.file); + } catch (IOException e) { + Bukkit.getLogger().severe("Could not save config file " + this.file.toString()); + e.printStackTrace(); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/config/file/Config.java b/src/main/java/me/trixkz/lifestealcore/utils/config/file/Config.java new file mode 100644 index 0000000..d9886c9 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/config/file/Config.java @@ -0,0 +1,39 @@ +package me.trixkz.lifestealcore.utils.config.file; + +import lombok.Getter; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; + +@Getter +public class Config { + + private final FileConfiguration config; + private final File configFile; + protected boolean wasCreated; + + public Config(String name, JavaPlugin plugin) { + this.configFile = new File(plugin.getDataFolder() + "/" + name + ".yml"); + if (!this.configFile.exists()) { + try { + this.configFile.getParentFile().mkdirs(); + this.configFile.createNewFile(); + this.wasCreated = true; + } catch (IOException e) { + e.printStackTrace(); + } + } + this.config = YamlConfiguration.loadConfiguration(this.configFile); + } + + public void save() { + try { + this.config.save(configFile); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/me/trixkz/lifestealcore/utils/config/file/ConfigFile.java b/src/main/java/me/trixkz/lifestealcore/utils/config/file/ConfigFile.java new file mode 100644 index 0000000..c2912b5 --- /dev/null +++ b/src/main/java/me/trixkz/lifestealcore/utils/config/file/ConfigFile.java @@ -0,0 +1,103 @@ +package me.trixkz.lifestealcore.utils.config.file; + +import lombok.Getter; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ConfigFile { + + @Getter private File file; + @Getter private YamlConfiguration configuration; + + public ConfigFile(JavaPlugin plugin, String name) { + file = new File(plugin.getDataFolder(), name + ".yml"); + + if (!file.getParentFile().exists()) { + file.getParentFile().mkdir(); + } + + plugin.saveResource(name + ".yml", false); + + configuration = YamlConfiguration.loadConfiguration(file); + } + + public double getDouble(String path) { + if (configuration.contains(path)) { + return configuration.getDouble(path); + } + return 0; + } + + public int getInt(String path) { + if (configuration.contains(path)) { + return configuration.getInt(path); + } + return 0; + } + + public boolean getBoolean(String path) { + if (configuration.contains(path)) { + return configuration.getBoolean(path); + } + return false; + } + + public String getString(String path) { + if (configuration.contains(path)) { + return ChatColor.translateAlternateColorCodes('&', configuration.getString(path)); + } + return "ERROR: STRING NOT FOUND"; + } + + public String getString(String path, String callback, boolean colorize) { + if (configuration.contains(path)) { + if (colorize) { + return ChatColor.translateAlternateColorCodes('&', configuration.getString(path)); + } else { + return configuration.getString(path); + } + } + return callback; + } + + public List getReversedStringList(String path) { + List list = getStringList(path); + if (list != null) { + int size = list.size(); + List toReturn = new ArrayList<>(); + for (int i = size - 1; i >= 0; i--) { + toReturn.add(list.get(i)); + } + return toReturn; + } + return Arrays.asList("ERROR: STRING LIST NOT FOUND!"); + } + + public List getStringList(String path) { + if (configuration.contains(path)) { + ArrayList strings = new ArrayList<>(); + for (String string : configuration.getStringList(path)) { + strings.add(ChatColor.translateAlternateColorCodes('&', string)); + } + return strings; + } + return Arrays.asList("ERROR: STRING LIST NOT FOUND!"); + } + + public List getStringListOrDefault(String path, List toReturn) { + if (configuration.contains(path)) { + ArrayList strings = new ArrayList<>(); + for (String string : configuration.getStringList(path)) { + strings.add(ChatColor.translateAlternateColorCodes('&', string)); + } + return strings; + } + return toReturn; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..82addb4 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,97 @@ +mongo: + host: "172.18.0.1" + port: 27017 + database: "LifestealCore" + auth: + enabled: true + username: "admin" + password: "dUEk3FWn3Mqv7sqF" + auth-database: "admin" + +# Chat games +CHAT-GAMES: + QUESTIONS: + 0: + QUESTION: "What gamemode are you playing?" + ANSWERS: + - "Lifesteal" + - "Life steal" + - "lifesteal" + - "life steal" + 1: + QUESTION: "Who is the president of the United States?" + ANSWER: + - "Joe Biden" + - "Joe biden" + - "joe Biden" + - "joe biden" + +# This is the current killstreaks I have made in the custom core +# You can edit them below this message +KILLSTREAKS: + MESSAGE: "&a%player% &eis on a &d%killstreak% &ekillstreak" + FULL-REPAIR: + ITEM: + NAME: "&bFull repair" + LORE: + - "&7&oRepair your armor" + - "&d5 kills needed" + KILLS-NEEDED: 5 + CHAMPION-RANK: + ITEM: + NAME: "&bChampion rank" + LORE: + - "&7&oGives you Champion rank" + - "&d10 kills needed" + KILLS-NEEDED: 10 + GOLDEN-APPLES: + ITEM: + NAME: "&bGolden apples" + LORE: + - "&7&oGives you 8 golden apples" + - "&d10 kills needed" + KILLS-NEEDED: 15 + RESISTANCE: + ITEM: + NAME: "&bResistance" + LORE: + - "&7&oGives you resistance 1 for 5 minutes" + - "&d15 kills needed" + KILLS-NEEDED: 20 + MASTER-RANK: + ITEM: + NAME: "&bMaster rank" + LORE: + - "&7&oGives you Master rank" + - "&d35 kills needed" + KILLS-NEEDED: 35 + GRAND-MASTER-RANK: + ITEM: + NAME: "&bGrand master rank" + LORE: + - "&7&oGives you Grand master rank" + - "&d70 kills needed" + KILLS-NEEDED: 70 + EMPEROR-RANK: + ITEM: + NAME: "&bEmperor rank" + LORE: + - "&7&oGives you Emperor rank" + - "&d150 kills needed" + KILLS-NEEDED: 150 + GOD-RANK: + ITEM: + NAME: "&bGod rank" + LORE: + - "&7&oGives you God rank" + - "&d200 kills needed" + KILLS-NEEDED: 200 + +# The amount of coins the player gets for every single kill they get +COINS-GIVEN-PER-KILL: 100 + +# Death ban times +# Work in progress +DEATH-BAN-TIMES: + DEFAULT: "2d" + CHAMPION: "1d" \ No newline at end of file diff --git a/src/main/resources/envoys.yml b/src/main/resources/envoys.yml new file mode 100644 index 0000000..365c32a --- /dev/null +++ b/src/main/resources/envoys.yml @@ -0,0 +1,14 @@ +envoys: + 0: + item-stacks: + 0: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + chance: 1.00 \ No newline at end of file diff --git a/src/main/resources/koths.yml b/src/main/resources/koths.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/lootbox.yml b/src/main/resources/lootbox.yml new file mode 100644 index 0000000..95efe40 --- /dev/null +++ b/src/main/resources/lootbox.yml @@ -0,0 +1,211 @@ +lootbox: + 0: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 1: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 2: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 3: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 4: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 5: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 6: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 7: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 8: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 9: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 10: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 11: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 12: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 13: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 14: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 15: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 16: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 17: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 18: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 19: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" + 20: + name: "&8[&d*&8] &eDiamond sword &8[&d*&8]" + lore: + - "&9Kill your enemies with great power" + material: "DIAMOND_SWORD" + data: 0 + amount: 1 + enchantments: + - "DAMAGE_ALL:1" + - "DURABILITY:3" \ No newline at end of file diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml new file mode 100644 index 0000000..771f596 --- /dev/null +++ b/src/main/resources/messages.yml @@ -0,0 +1,96 @@ +# Prefix +PREFIX: "&d&lLifestealCore &8&m┃ &r&e" + +# Clan prefix +CLAN_PREFIX: "&d&lClan &8&m┃ &r&e" + +# General information messages +SCOREBOARD: + NAME: "&d&lLifestealCore" + SPAWN: + - "%scoreboard_bar%" + - "&fOnline: &d%players_online%" + - "" + - "&d&l➤ &9%player%" + - "&fCoins: &d%coins%" + - "&fTokens: &d%tokens%" + - "" + - "&d%website%" + - "%scoreboard_bar%" + WARZONE: + - "%scoreboard_bar%" + - "&fOnline: &d%players_online%" + - "" + - "&d&l➤ &9%player%" + - "&fKills: &d%kills%" + - "&fKillstreak: &d%killstreak%" + - "&fDeaths: &d%deaths%" + - "" + - "&d&l➤ &fWarzone" + - "&fCombat tag: &d%combat_tag%" + - "&fPvP class: &d%pvp_class%" + - "" + - "&d%website%" + - "%scoreboard_bar%" +WEBSITE: "cozymc.org" + +# Clan information +CLAN: + GENERAL: + NO_CLAN_MESSAGE: "You do not have an clan, do /clan create" + NOT_ONLINE_MESSAGE: "%player% is not online" + INVALID_ACTION_MESSAGE: "Invalid action, you can not do this when you are the owner of the clan" + NOT_IN_CLAN_MESSAGE: "%player% is not in your clan" + NOT_CLAN_OWNER_MESSAGE: "No permission, you have to be the owner of the clan" + CLAN_CREATE: + MAKING_CLAN_MESSAGE: "Making clan" + CLAN_MADE_MESSAGE: "Clan creation successful, do /clan" + CLAN_ALREADY_MADE_MESSAGE: "You already have an clan" + CLAN_DELETE: + CLAN_DELETED_MESSAGE: "%player% has deleted the clan" + CLAN_LEVEL: + GETTING_CLAN_LEVEL_MESSAGE: "Getting the clan level" + CLAN_LEVEL_MESSAGE: "Your clan's level is %level%" + CLAN_LOCKED: + CLAN_LOCKED_MESSAGE: "The clan is locked" + TRANSFER_CLAN_OWNERSHIP: + CLAN_OWNERSHIP_TRANSFERRED_MESSAGE: "You have transferred the clan's ownership to %player%" + CREATE_CLAN_INVITE: + ALREADY_INVITED_TO_CLAN_MESSAGE: "%player% is already invited to your clan" + MAXIMUM_AMOUNT_OF_CLAN_MEMBERS_MESSAGE: "You already have the maximum amount of clan members in your clan" + ALREADY_IN_CLAN_MESSAGE: "%player% is already in an clan" + ALREADY_IN_YOUR_CLAN_MESSAGE: "%player% is already in your clan" + BANNED_FROM_YOUR_CLAN_MESSAGE: "%player% is banned from your clan" + CLICK_TO_JOIN_CLAN_MESSAGE: "&eClick to join their clan" + INVITED_TO_CLAN_MESSAGE: "You have invited %player% to your clan" + INVITED_TO_CLAN_INVITATION_MESSAGE: "%player% has invited you to their clan" + REMOVE_CLAN_INVITE: + UNINVITED_TO_CLAN_MESSAGE: "You have uninvited %player% from your clan" + NOT_INVITED_TO_CLAN_MESSAGE: "%player% is not invited to your clan" + JOIN_CLAN: + JOINED_CLAN_MESSAGE: "%player% has joined the clan" + INVALID_CLAN_MESSAGE: "Invalid clan" + NO_INVITE_TO_CLAN_MESSAGE: "You have not been invited to the clan" + LEAVE_CLAN: + LEFT_CLAN_MESSAGE: "%player% has left the clan" + KICK_PLAYER: + PLAYER_KICKED_FROM_CLAN: "%player% has been kicked from the clan" + +COINS: + BALANCE: "&dCoins: &f%coins%" + HELP_MESSAGE: + PLAYER: + - "%line%" + - "&dCoins command &7(&fPlayer&7)" + - "%line%" + - "&7⚫ &9/coins &7- &eLook at your coins balance" + - "&7⚫ &9/coins pay &7- &eSend coins to another player" + - "%line%" + ADMIN: + - "&dCoins commands &7(&fAdmin&7)" + - "%line%" + - "&7⚫ &9/coins &7- &eLook at another player's coins balance" + - "&7⚫ &9/coins set &7- &eSet coins to another player" + - "&7⚫ &9/coins add &7- &eAdd coins to another player" + - "&7⚫ &9/coins remove &7- &eRemove coins to another player" + - "%line%" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..3291a80 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,17 @@ +name: LifeStealCore +version: 1.0 +author: Trixkz +api-version: 1.13 +main: me.trixkz.lifestealcore.LifeStealCore + +commands: + lootbox: + clan: + koth: + coins: + tokens: + spawn: + setspawn: + shop: + envoy: + sethearts: \ No newline at end of file