From 1dd451ed42175a5a8b94280760643359dcdd9cb8 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 13 Sep 2018 23:00:56 +0100 Subject: [PATCH] Add some Nano Games achievements --- .../core/achievement/Achievement.java | 40 +++ .../core/achievement/AchievementCategory.java | 144 ++++++----- .../src/mineplex/game/nano/NanoGames.java | 2 + .../src/mineplex/game/nano/NanoManager.java | 8 + .../src/mineplex/game/nano/game/Game.java | 29 ++- .../currency/GameCurrencyManager.java | 21 +- .../components/stats/GameStatsComponent.java | 242 ++++++++++++++++++ .../components/stats/GeneralStatsTracker.java | 94 +++++++ .../game/components/stats/StatTracker.java | 35 +++ .../game/components/stats/StatsComponent.java | 14 + .../nano/game/games/minekart/MineKart.java | 15 +- 11 files changed, 560 insertions(+), 84 deletions(-) create mode 100644 Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/GameStatsComponent.java create mode 100644 Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/GeneralStatsTracker.java create mode 100644 Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/StatTracker.java create mode 100644 Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/StatsComponent.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java index 3d07b269d..cadd50328 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java @@ -1466,6 +1466,46 @@ public enum Achievement new int[]{1}, AchievementCategory.CAKE_WARS), + // Nano Games + NANO_WINNER("Nano Winner", 0, + new String[]{"Nano Games.Wins"}, + new String[]{"Win Nano Games"}, + new int[][] {new int[] {100,0,1000}, new int[] {0,0,5000}, new int[]{0,0,10000}, new int[]{0,0,25000}, new int[]{0,0,50000}}, + new int[]{1,10,50,100,500}, + "I", + new String[] {"II","III","IV","V","X"}, + AchievementCategory.NANO_GAMES), + + NANO_PLAY_IN_A_ROW("Player 1", 6000, + new String[]{"Nano Games.PlayInARow"}, + new String[]{"Play 100 Games in a row"}, + new int[]{1}, + AchievementCategory.NANO_GAMES), + + NANO_SECOND_PLACE("Better than last!", 500, + new String[]{"Nano Games.SecondPlace"}, + new String[]{"Get second place"}, + new int[]{1}, + AchievementCategory.NANO_GAMES), + + NANO_THIRD_PLACE("Still better than last!", 500, + new String[]{"Nano Games.ThirdPlace"}, + new String[]{"Get third place"}, + new int[]{1}, + AchievementCategory.NANO_GAMES), + + NANO_CASH_OUT("Cha-Ching", 500, + new String[]{"Nano Games.CashOut"}, + new String[]{"Cash out for the first time"}, + new int[]{1}, + AchievementCategory.NANO_GAMES), + + NANO_PLAY("Nani Games?", 500, + new String[]{"Nano Games.Wins", "Nano Games.Losses"}, + new String[]{"Play a Nano Game"}, + new int[]{1}, + AchievementCategory.NANO_GAMES), + ; private final String _name; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java index c980b3d73..13ae82cd3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java @@ -28,34 +28,34 @@ public enum AchievementCategory new StatDisplay("Times Voted", "DailyVote"), null, new StatDisplay("Chests Opened", "Treasure.Old", "Treasure.Ancient", "Treasure.Mythical") - }, Material.EMERALD, 0, GameCategory.GLOBAL, "None", false, -1), + }, Material.EMERALD, 0, GameCategory.STAND_ALONE, "None", false, -1), HOLIDAY("Holiday Achievements", null, - new StatDisplay[] {}, - Material.CAKE, 0, GameCategory.HOLIDAY, "None", false, -1), + new StatDisplay[]{}, + Material.CAKE, 0, GameCategory.STAND_ALONE, "None", false, -1), BRIDGES("The Bridges", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, - Material.IRON_PICKAXE, 0, GameCategory.SURVIVAL, "Destructor Kit", false, GameDisplay.Bridge.getGameId()), + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, + Material.IRON_PICKAXE, 0, GameCategory.GAME, "Destructor Kit", false, GameDisplay.Bridge.getGameId()), SURVIVAL_GAMES("Survival Games", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, null, null, new StatDisplay(C.Bold + "Teams Stats", true), null, StatDisplay.fromGame("Wins", GameDisplay.SurvivalGamesTeams, "Wins"), StatDisplay.fromGame("Games Played", GameDisplay.SurvivalGamesTeams, "Wins", "Losses"), StatDisplay.fromGame("Kills", GameDisplay.SurvivalGamesTeams, "Kills"), StatDisplay.fromGame("Deaths", GameDisplay.SurvivalGamesTeams, "Deaths"), - StatDisplay.fromGame("Gems Earned", GameDisplay.SurvivalGamesTeams, "GemsEarned") }, - Material.DIAMOND_SWORD, 0, GameCategory.SURVIVAL, "Horseman Kit", false, GameDisplay.SurvivalGames.getGameId(), GameDisplay.SurvivalGamesTeams.getGameId()), + StatDisplay.fromGame("Gems Earned", GameDisplay.SurvivalGamesTeams, "GemsEarned")}, + Material.DIAMOND_SWORD, 0, GameCategory.GAME, "Horseman Kit", false, GameDisplay.SurvivalGames.getGameId(), GameDisplay.SurvivalGamesTeams.getGameId()), - SKYWARS("Skywars",null, + SKYWARS("Skywars", null, new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, null, null, new StatDisplay(C.Bold + "Team Stats", true), null, StatDisplay.fromGame("Wins", GameDisplay.SkywarsTeams, "Wins"), StatDisplay.fromGame("Games Played", GameDisplay.SkywarsTeams, "Wins", "Losses"), StatDisplay.fromGame("Kills", GameDisplay.SkywarsTeams, "Kills"), StatDisplay.fromGame("Deaths", GameDisplay.SkywarsTeams, "Deaths"), - StatDisplay.fromGame("Gems Earned", GameDisplay.SkywarsTeams, "GemsEarned") }, - Material.FEATHER, 0, GameCategory.SURVIVAL, "Earth Kit", false, GameDisplay.Skywars.getGameId(), GameDisplay.SkywarsTeams.getGameId()), + StatDisplay.fromGame("Gems Earned", GameDisplay.SkywarsTeams, "GemsEarned")}, + Material.FEATHER, 0, GameCategory.GAME, "Earth Kit", false, GameDisplay.Skywars.getGameId(), GameDisplay.SkywarsTeams.getGameId()), UHC("Ultra Hardcore", null, - new StatDisplay[] { + new StatDisplay[]{ new StatDisplay(C.Bold + "Solo Stats", true), null, StatDisplay.fromGame("Wins", GameDisplay.UHCSolo, "Wins"), StatDisplay.fromGame("Games Played", GameDisplay.UHCSolo, "Wins", "Losses"), @@ -67,11 +67,11 @@ public enum AchievementCategory null, StatDisplay.fromGame("Wins", GameDisplay.UHC, "Wins"), StatDisplay.fromGame("Games Played", GameDisplay.UHC, "Wins", "Losses"), StatDisplay.fromGame("Kills", GameDisplay.UHC, "Kills"), StatDisplay.fromGame("Deaths", GameDisplay.UHC, "Deaths"), - StatDisplay.fromGame("Gems Earned", GameDisplay.UHC, "GemsEarned") }, + StatDisplay.fromGame("Gems Earned", GameDisplay.UHC, "GemsEarned")}, Material.GOLDEN_APPLE, 0, GameCategory.UHC, "None", false, GameDisplay.UHCSolo.getGameId(), GameDisplay.UHC.getGameId()), UHC_SPEED("Ultra Hardcore Speed", null, - new StatDisplay[] { + new StatDisplay[]{ new StatDisplay(C.Bold + "Solo Stats", true), null, StatDisplay.fromGame("Wins", GameDisplay.UHCSoloSpeed, "Wins"), StatDisplay.fromGame("Games Played", GameDisplay.UHCSoloSpeed, "Wins", "Losses"), @@ -83,7 +83,7 @@ public enum AchievementCategory null, StatDisplay.fromGame("Wins", GameDisplay.UHCTeamsSpeed, "Wins"), StatDisplay.fromGame("Games Played", GameDisplay.UHCTeamsSpeed, "Wins", "Losses"), StatDisplay.fromGame("Kills", GameDisplay.UHCTeamsSpeed, "Kills"), StatDisplay.fromGame("Deaths", GameDisplay.UHCTeamsSpeed, "Deaths"), - StatDisplay.fromGame("Gems Earned", GameDisplay.UHCTeamsSpeed, "GemsEarned") }, + StatDisplay.fromGame("Gems Earned", GameDisplay.UHCTeamsSpeed, "GemsEarned")}, Material.GOLDEN_APPLE, 0, GameCategory.UHC, "None", false, GameDisplay.UHCSoloSpeed.getGameId(), GameDisplay.UHCTeamsSpeed.getGameId()), /*MC_LEAGUE("MC League", null, @@ -91,12 +91,12 @@ public enum AchievementCategory Material.IRON_CHESTPLATE, 0, GameCategory.SURVIVAL, "None", true, GameDisplay.Minecraft_League.getGameId()),*/ WIZARDS("Wizards", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, - Material.BLAZE_ROD, 0, GameCategory.SURVIVAL, "Witch Doctor Kit", false, GameDisplay.Wizards.getGameId()), + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, + Material.BLAZE_ROD, 0, GameCategory.GAME, "Witch Doctor Kit", false, GameDisplay.Wizards.getGameId()), - CASTLE_ASSAULT("Castle Assault", new String[] {"Castle Assault", "Castle Assault TDM"}, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.CROWNS_EARNED }, - Material.DIAMOND_CHESTPLATE, 0, GameCategory.CLASSICS, null, false, GameDisplay.CastleAssault.getGameId(), GameDisplay.CastleAssaultTDM.getGameId()), + CASTLE_ASSAULT("Castle Assault", new String[]{"Castle Assault", "Castle Assault TDM"}, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.CROWNS_EARNED}, + Material.DIAMOND_CHESTPLATE, 0, GameCategory.GAME, null, false, GameDisplay.CastleAssault.getGameId(), GameDisplay.CastleAssaultTDM.getGameId()), CASTLE_SIEGE("Castle Siege", null, new StatDisplay[] @@ -123,11 +123,11 @@ public enum AchievementCategory null, StatDisplay.GEMS_EARNED, }, - Material.DIAMOND_CHESTPLATE, 0, GameCategory.CLASSICS, "Undead Summoner & Castle Paladin Kit", false, GameDisplay.CastleSiege.getGameId()), + Material.DIAMOND_CHESTPLATE, 0, GameCategory.GAME, "Undead Summoner & Castle Paladin Kit", false, GameDisplay.CastleSiege.getGameId()), BAWK_BAWK_BATTLES("Bawk Bawk Battles", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED }, - Material.EGG, 0, GameCategory.CLASSICS, null, false, GameDisplay.BawkBawkBattles.getGameId()), + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED}, + Material.EGG, 0, GameCategory.GAME, null, false, GameDisplay.BawkBawkBattles.getGameId()), BLOCK_HUNT("Block Hunt", null, new StatDisplay[] @@ -139,75 +139,75 @@ public enum AchievementCategory StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, - Material.GRASS, 0, GameCategory.CLASSICS, "Infestor Kit", false, GameDisplay.HideSeek.getGameId()), + Material.GRASS, 0, GameCategory.GAME, "Infestor Kit", false, GameDisplay.HideSeek.getGameId()), SMASH_MOBS("Super Smash Mobs", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, null, null, new StatDisplay(C.Bold + "Team Stats", true), null, StatDisplay.fromGame("Wins", GameDisplay.SmashTeams, "Wins"), StatDisplay.fromGame("Games Played", GameDisplay.SmashTeams, "Wins", "Losses"), StatDisplay.fromGame("Kills", GameDisplay.SmashTeams, "Kills"), StatDisplay.fromGame("Deaths", GameDisplay.SmashTeams, "Deaths"), StatDisplay.fromGame("Gems Earned", GameDisplay.SmashTeams, "GemsEarned")}, - Material.SKULL_ITEM, 4, GameCategory.CLASSICS, "Sheep Kit", false, GameDisplay.Smash.getGameId(), GameDisplay.SmashTeams.getGameId()), + Material.SKULL_ITEM, 4, GameCategory.GAME, "Sheep Kit", false, GameDisplay.Smash.getGameId(), GameDisplay.SmashTeams.getGameId()), MINE_STRIKE("MineStrike", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, - Material.TNT, 0, GameCategory.CLASSICS, "None", false, GameDisplay.MineStrike.getGameId()), + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, + Material.TNT, 0, GameCategory.GAME, "None", false, GameDisplay.MineStrike.getGameId()), DRAW_MY_THING("Draw My Thing", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED }, - Material.BOOK_AND_QUILL, 0, GameCategory.CLASSICS, "None", false, GameDisplay.Draw.getGameId()), + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED}, + Material.BOOK_AND_QUILL, 0, GameCategory.GAME, "None", false, GameDisplay.Draw.getGameId()), - CHAMPIONS("Champions", new String[] {"Champions Domination", "Champions TDM", "Champions CTF"}, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, new StatDisplay("Flags Captured", "Captures") }, - Material.BEACON, 0, GameCategory.CHAMPIONS, "Extra Class Skills", false, GameDisplay.ChampionsCTF.getGameId(), GameDisplay.ChampionsDominate.getGameId(), GameDisplay.ChampionsTDM.getGameId()), + CHAMPIONS("Champions", new String[]{"Champions Domination", "Champions TDM", "Champions CTF"}, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, new StatDisplay("Flags Captured", "Captures")}, + Material.BEACON, 0, GameCategory.GAME, "Extra Class Skills", false, GameDisplay.ChampionsCTF.getGameId(), GameDisplay.ChampionsDominate.getGameId(), GameDisplay.ChampionsTDM.getGameId()), MASTER_BUILDERS("Master Builders", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED }, - Material.WOOD, 0, GameCategory.CLASSICS, "None", false, GameDisplay.Build.getGameId()), + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED}, + Material.WOOD, 0, GameCategory.GAME, "None", false, GameDisplay.Build.getGameId()), //Arcade DRAGONS("Dragons", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED}, Material.ENDER_STONE, 0, GameCategory.ARCADE, null, false, GameDisplay.Dragons.getGameId()), DRAGON_ESCAPE("Dragon Escape", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED}, Material.DRAGON_EGG, 0, GameCategory.ARCADE, "Digger Kit", false, GameDisplay.DragonEscape.getGameId()), SHEEP_QUEST("Sheep Quest", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.WOOL, 0, GameCategory.ARCADE, null, false, GameDisplay.Sheep.getGameId()), SNEAKY_ASSASSINS("Sneaky Assassins", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.INK_SACK, 0, GameCategory.ARCADE, "Briber Kit", false, GameDisplay.SneakyAssassins.getGameId()), ONE_IN_THE_QUIVER("One in the Quiver", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.BOW, 0, GameCategory.ARCADE, "Ninja Kit", false, GameDisplay.Quiver.getGameId()), SUPER_PAINTBALL("Super Paintball", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.ENDER_PEARL, 0, GameCategory.ARCADE, "Sniper Kit", false, GameDisplay.Paintball.getGameId()), TURF_WARS("Turf Wars", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.HARD_CLAY, 14, GameCategory.ARCADE, null, false, GameDisplay.TurfWars.getGameId()), RUNNER("Runner", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.LEATHER_BOOTS, 0, GameCategory.ARCADE, null, false, GameDisplay.Runner.getGameId()), SPLEEF("Super Spleef", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.IRON_SPADE, 0, GameCategory.ARCADE, null, false, GameDisplay.Spleef.getGameId()), DEATH_TAG("Death Tag", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.SKULL_ITEM, 0, GameCategory.ARCADE, null, false, GameDisplay.DeathTag.getGameId()), SNAKE("Snake", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.WOOL, 4, GameCategory.ARCADE, "Reversal Snake Kit", false, GameDisplay.Snake.getGameId()), BACON_BRAWL( @@ -223,23 +223,23 @@ public enum AchievementCategory }, Material.PORK, 0, GameCategory.ARCADE, "Chris P Bacon", false, GameDisplay.BaconBrawl.getGameId()), MICRO_BATTLE("Micro Battle", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.LAVA_BUCKET, 0, GameCategory.ARCADE, null, false, GameDisplay.Micro.getGameId()), BOMB_LOBBERS("Bomb Lobbers", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.FIREBALL, 0, GameCategory.ARCADE, "Waller Kit", false, GameDisplay.Lobbers.getGameId()), EVOLUTION("Evolution", null, - new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.MONSTER_EGG, 55 /* slime */, GameCategory.ARCADE, "Harvester Kit", false, GameDisplay.Evolution.getGameId()), MONSTER_MAZE("Monster Maze", null, - new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.ROTTEN_FLESH, 0, GameCategory.ARCADE, "SoonTM", false, GameDisplay.MonsterMaze.getGameId()), GLADIATORS("Gladiators", null, - new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED}, Material.IRON_SWORD, 0, GameCategory.ARCADE, null, false, GameDisplay.Gladiators.getGameId()), /*TYPE_WARS("Type Wars", null, @@ -247,28 +247,28 @@ public enum AchievementCategory Material.NAME_TAG, 0, GameCategory.CLASSICS, null),*/ SPEED_BUILDERS("Speed Builders", null, - new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED, null, new StatDisplay("Perfect Builds", "PerfectBuild")}, - Material.QUARTZ_BLOCK, 0, GameCategory.CLASSICS, null, false, GameDisplay.SpeedBuilders.getGameId()), + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED, null, new StatDisplay("Perfect Builds", "PerfectBuild")}, + Material.QUARTZ_BLOCK, 0, GameCategory.GAME, null, false, GameDisplay.SpeedBuilders.getGameId()), /*ONE_IN_THE_QUIVER_PAYLOAD("One in the Quiver Payload", null, new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED}, Material.EXPLOSIVE_MINECART, 0, GameCategory.CLASSICS, "Sky Warrior Kit", false, GameDisplay.QuiverPayload.getGameId()),*/ SKYFALL("Skyfall", null, - new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, null, new StatDisplay("Booster Rings", "Rings"), + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, null, new StatDisplay("Booster Rings", "Rings"), null, null, new StatDisplay(C.Bold + "Team Stats", true), null, StatDisplay.fromGame("Wins", GameDisplay.SkyfallTeams, "Wins"), StatDisplay.fromGame("Games Played", GameDisplay.SkyfallTeams, "Wins", "Losses"), StatDisplay.fromGame("Kills", GameDisplay.SkyfallTeams, "Kills"), StatDisplay.fromGame("Deaths", GameDisplay.SkyfallTeams, "Deaths"), StatDisplay.fromGame("Gems Earned", GameDisplay.SkyfallTeams, "GemsEarned"), null, StatDisplay.fromGame("Booster Rings", GameDisplay.SkyfallTeams, "Rings")}, - Material.DIAMOND_BOOTS, 0, GameCategory.SURVIVAL, null, false, GameDisplay.Skyfall.getGameId(), GameDisplay.SkyfallTeams.getGameId()), + Material.DIAMOND_BOOTS, 0, GameCategory.GAME, null, false, GameDisplay.Skyfall.getGameId(), GameDisplay.SkyfallTeams.getGameId()), GEM_HUNTERS("Gem Hunters", null, - new StatDisplay[] {StatDisplay.KILLS, StatDisplay.GEMS_EARNED, StatDisplay.fromGame("Quests Completed", GameDisplay.GemHunters, "QuestsCompleted"), StatDisplay.fromGame("Chests Opened", GameDisplay.GemHunters, "ChestsOpened")}, - Material.EMERALD, 0, GameCategory.SURVIVAL, null, false, GameDisplay.GemHunters.getGameId()), + new StatDisplay[]{StatDisplay.KILLS, StatDisplay.GEMS_EARNED, StatDisplay.fromGame("Quests Completed", GameDisplay.GemHunters, "QuestsCompleted"), StatDisplay.fromGame("Chests Opened", GameDisplay.GemHunters, "ChestsOpened")}, + Material.EMERALD, 0, GameCategory.GAME, null, false, GameDisplay.GemHunters.getGameId()), MOBA("Heroes of GWEN", null, - new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, null, StatDisplay.fromGame("Gold Earned", GameDisplay.MOBA, "GoldEarned")}, - Material.PRISMARINE_SHARD, 0, GameCategory.CLASSICS, null, false, GameDisplay.MOBA.getGameId()), + new StatDisplay[]{StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, null, StatDisplay.fromGame("Gold Earned", GameDisplay.MOBA, "GoldEarned")}, + Material.PRISMARINE_SHARD, 0, GameCategory.GAME, null, false, GameDisplay.MOBA.getGameId()), CAKE_WARS("Cake Wars", null, new StatDisplay[] @@ -292,7 +292,17 @@ public enum AchievementCategory StatDisplay.fromGame("Cake Bites", GameDisplay.CakeWarsDuos, "Bites"), StatDisplay.fromGame("Whole Cakes", GameDisplay.CakeWarsDuos, "EatWholeCake"), }, - Material.CAKE, 0, GameCategory.CLASSICS, "Frosting Kit", false, GameDisplay.CakeWars4.getGameId(), GameDisplay.CakeWarsDuos.getGameId()); + Material.CAKE, 0, GameCategory.GAME, "Frosting Kit", false, GameDisplay.CakeWars4.getGameId(), GameDisplay.CakeWarsDuos.getGameId()), + + NANO_GAMES("Nano Games", null, new StatDisplay[] + { + StatDisplay.WINS, + StatDisplay.GAMES_PLAYED, + StatDisplay.KILLS, + StatDisplay.DEATHS, + }, Material.EGG, 0, GameCategory.GAME, null, false, GameDisplay.NanoGames.getGameId()), + + ; private String _name; private String[] _statsToPull; @@ -311,10 +321,10 @@ public enum AchievementCategory if (statsToPull != null) _statsToPull = statsToPull; else - _statsToPull = new String[] {name}; + _statsToPull = new String[]{name}; _statDisplays = statDisplays; _icon = icon; - _iconData = (byte)iconData; + _iconData = (byte) iconData; _gameCategory = gameCategory; _kitReward = kitReward; @@ -400,15 +410,15 @@ public enum AchievementCategory { for (String statName : _statDisplays[i].getStats()) { - if(_statDisplays[i].isDivideStats()) + if (_statDisplays[i].isDivideStats()) { - if(statNumber == 0) + if (statNumber == 0) { statNumber = targetStats.getStat(statToPull + "." + statName); continue; } double stat = targetStats.getStat(statToPull + "." + statName); - if(stat == 0) + if (stat == 0) statNumber = statNumber / 1; else statNumber = (double) statNumber / stat; @@ -426,7 +436,7 @@ public enum AchievementCategory if (displayName.equalsIgnoreCase("Words Per Minute")) { statString = C.cWhite + (double) statNumber; - if(statString.length() > 7) + if (statString.length() > 7) statString = statString.substring(0, 7); lore.add(C.cYellow + displayName + ": " + statString); @@ -446,6 +456,6 @@ public enum AchievementCategory public enum GameCategory { - GLOBAL, HOLIDAY, SURVIVAL, CLASSICS, CHAMPIONS, ARCADE, UHC + STAND_ALONE, GAME, ARCADE, UHC, NANO_GAME } } \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/NanoGames.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/NanoGames.java index c9d1f6da9..fa420e285 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/NanoGames.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/NanoGames.java @@ -58,6 +58,7 @@ import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.sound.SoundNotifier; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; +import mineplex.core.task.TaskManager; import mineplex.core.teamspeak.TeamspeakManager; import mineplex.core.teleport.Teleport; import mineplex.core.thank.ThankManager; @@ -140,6 +141,7 @@ public class NanoGames extends JavaPlugin StatsManager statsManager = new StatsManager(this, clientManager); EloManager eloManager = new EloManager(this, clientManager); AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager); + TaskManager taskManager = new TaskManager(this, clientManager); PartyManager partyManager = new PartyManager(); diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/NanoManager.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/NanoManager.java index 85eaeb65f..15959d85d 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/NanoManager.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/NanoManager.java @@ -40,6 +40,7 @@ import mineplex.core.packethandler.PacketHandler; import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; +import mineplex.core.task.TaskManager; import mineplex.game.nano.commands.game.GameCommand; import mineplex.game.nano.commands.spectator.SpectatorCommand; import mineplex.game.nano.cycle.GameCycle; @@ -91,6 +92,7 @@ public class NanoManager extends MiniPlugin implements IRelation // Achievement private final StatsManager _statsManager; private final AchievementManager _achievementManager; + private final TaskManager _taskManager; // Chat private final Chat _chat; @@ -156,6 +158,7 @@ public class NanoManager extends MiniPlugin implements IRelation _statsManager = require(StatsManager.class); _achievementManager = require(AchievementManager.class); + _taskManager = require(TaskManager.class); _chat = require(Chat.class); _chat.setFormatComponents( @@ -383,6 +386,11 @@ public class NanoManager extends MiniPlugin implements IRelation return _achievementManager; } + public TaskManager getTaskManager() + { + return _taskManager; + } + public Chat getChat() { return _chat; diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/Game.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/Game.java index 582566a82..e8a47e456 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/Game.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/Game.java @@ -8,7 +8,7 @@ import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Player; -import mineplex.core.Managers; +import mineplex.core.achievement.Achievement; import mineplex.core.antihack.AntiHack; import mineplex.core.common.util.UtilServer; import mineplex.core.lifetimes.Lifetimed; @@ -25,15 +25,18 @@ import mineplex.game.nano.game.components.prepare.GamePrepareComponent; import mineplex.game.nano.game.components.scoreboard.GameScoreboardComponent; import mineplex.game.nano.game.components.spectator.GameSpectatorComponent; import mineplex.game.nano.game.components.spectator.SpectatorComponent; +import mineplex.game.nano.game.components.stats.GameStatsComponent; +import mineplex.game.nano.game.components.stats.GeneralStatsTracker; +import mineplex.game.nano.game.components.stats.StatsComponent; import mineplex.game.nano.game.components.team.GameTeam; import mineplex.game.nano.game.components.team.GameTeamComponent; import mineplex.game.nano.game.components.team.TeamComponent; -import mineplex.game.nano.game.components.world.GameWorldComponent; import mineplex.game.nano.game.components.world.GameWaterComponent; +import mineplex.game.nano.game.components.world.GameWorldComponent; import mineplex.game.nano.game.event.GameStateChangeEvent; import mineplex.game.nano.world.GameWorld; -public abstract class Game extends ListenerComponent implements Lifetimed, TeamComponent, SpectatorComponent, CurrencyComponent +public abstract class Game extends ListenerComponent implements Lifetimed, TeamComponent, SpectatorComponent, CurrencyComponent, StatsComponent { public enum GameState @@ -64,6 +67,7 @@ public abstract class Game extends ListenerComponent implements Lifetimed, TeamC protected final GamePlayerComponent _playerComponent; protected final GameWaterComponent _waterComponent; protected final GameCompassComponent _compassComponent; + protected final GameStatsComponent _statsComponent; protected final GameEndComponent _endComponent; // Winners @@ -89,7 +93,10 @@ public abstract class Game extends ListenerComponent implements Lifetimed, TeamC _playerComponent = new GamePlayerComponent(this); _waterComponent = new GameWaterComponent(this); _compassComponent = new GameCompassComponent(this); + _statsComponent = new GameStatsComponent(this); _endComponent = new GameEndComponent(this); + + new GeneralStatsTracker(this); } public final void setupGameWorld(File mapZip) @@ -316,6 +323,22 @@ public abstract class Game extends ListenerComponent implements Lifetimed, TeamC _manager.getCurrencyManager().addGems(player, amount); } + /* + Stats + */ + + @Override + public void addStat(Player player, String stat, int amount, boolean limitTo1, boolean global) + { + _statsComponent.addStat(player, stat, amount, limitTo1, global); + } + + @Override + public void rewardAchievement(Player player, Achievement achievement) + { + _statsComponent.rewardAchievement(player, achievement); + } + /* Component Getters */ diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/currency/GameCurrencyManager.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/currency/GameCurrencyManager.java index 6e2d3fe57..6cdced3f7 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/currency/GameCurrencyManager.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/currency/GameCurrencyManager.java @@ -21,6 +21,7 @@ import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.C; import mineplex.core.portal.events.GenericServerTransferEvent; import mineplex.core.portal.events.ServerTransferEvent; +import mineplex.core.stats.StatsManager; import mineplex.core.titles.tracks.TrackManager; import mineplex.core.titles.tracks.standard.GemCollectorTrack; import mineplex.game.nano.GameManager; @@ -139,6 +140,7 @@ public class GameCurrencyManager extends GameManager implements CurrencyComponen return; } + StatsManager statsManager = _manager.getStatsManager(); CoreClient client = _manager.getClientManager().Get(player); String gameName = NanoManager.getGameDisplay().getName(); @@ -188,14 +190,19 @@ public class GameCurrencyManager extends GameManager implements CurrencyComponen { int gamesPlayed = (int) Math.floor(data.Games / 5D); - // TODO enable game specific stats after beta - _manager.getStatsManager().incrementStat(player, "Global.GemsEarned", gems); - //_manager.getStatsManager().incrementStat(player, gameName + ".GemsEarned", gems); - _manager.getStatsManager().incrementStat(player, "Global.ExpEarned", exp); - //_manager.getStatsManager().incrementStat(player, gameName + ".ExpEarned", exp); - _manager.getStatsManager().incrementStat(player, "Global.GamesPlayed", gamesPlayed); - //_manager.getStatsManager().incrementStat(player, gameName + ".GamesPlayed", data.Games); + statsManager.incrementStat(player, "Global.GemsEarned", gems); + statsManager.incrementStat(player, gameName + ".GemsEarned", gems); + statsManager.incrementStat(player, "Global.ExpEarned", exp); + statsManager.incrementStat(player, gameName + ".ExpEarned", exp); + statsManager.incrementStat(player, "Global.GamesPlayed", gamesPlayed); require(TrackManager.class).getTrack(GemCollectorTrack.class).earnedGems(player, gems); + + if (data.Games >= 100) + { + statsManager.incrementStat(player, gameName + ".PlayInARow", 1); + } + + statsManager.incrementStat(player, gameName + ".CashOut", 1); } // Remove from session diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/GameStatsComponent.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/GameStatsComponent.java new file mode 100644 index 000000000..681f48a2c --- /dev/null +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/GameStatsComponent.java @@ -0,0 +1,242 @@ +package mineplex.game.nano.game.components.stats; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +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 org.bukkit.event.EventHandler; + +import mineplex.core.achievement.Achievement; +import mineplex.core.achievement.AchievementCategory; +import mineplex.core.achievement.AchievementData; +import mineplex.core.achievement.AchievementLog; +import mineplex.core.achievement.AchievementManager; +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilServer; +import mineplex.core.donation.DonationManager; +import mineplex.core.stats.StatsManager; +import mineplex.core.task.TaskManager; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.nano.game.Game; +import mineplex.game.nano.game.GameComponent; + +public class GameStatsComponent extends GameComponent implements StatsComponent +{ + + private final StatsManager _statsManager; + private final TaskManager _taskManager; + private final DonationManager _donationManager; + + private final Map> _statsGiven; + + public GameStatsComponent(Game game) + { + super(game); + + _statsManager = game.getManager().getStatsManager(); + _taskManager = game.getManager().getTaskManager(); + _donationManager = game.getManager().getDonationManager(); + + _statsGiven = new HashMap<>(); + } + + @Override + public void disable() + { + + } + + @Override + public void addStat(Player player, String stat, int amount, boolean limitTo1, boolean global) + { + if (!getGame().getManager().getServerGroup().getRewardStats()) + { + return; + } + + Set statsGiven = _statsGiven.computeIfAbsent(player, k -> new HashSet<>()); + + if (global) + { + stat = AchievementCategory.GLOBAL.getFriendlyName() + "." + stat; + } + else + { + stat = AchievementCategory.NANO_GAMES.getFriendlyName() + "." + stat; + } + + if (!statsGiven.add(stat) && limitTo1) + { + return; + } + + _statsManager.incrementStat(player, stat, amount); + } + + @Override + public void rewardAchievement(Player player, Achievement achievement) + { + getGame().addStat(player, achievement.getStats()[0], 1, true, achievement.getCategory() == AchievementCategory.GLOBAL); + } + + /* + Copied from AchievementSummaryComponent + // TODO Replace and reinvent when reimplementing achievements + */ + + @EventHandler + public void updateAchievements(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW) + { + return; + } + + AchievementManager manager = getGame().getManager().getAchievementManager(); + + for (Player player : UtilServer.getPlayersCollection()) + { + if (manager.getLog(player) == null) + { + continue; + } + + manager.getLog(player).entrySet().forEach(entry -> + { + Achievement achievement = entry.getKey(); + AchievementLog log = entry.getValue(); + AchievementData data = manager.get(player, achievement); + + if (log.LevelUp) + { + String nameLevel = getAchievementName(achievement, data); + StringBuilder description = new StringBuilder(); + + for (String line : achievement.getDesc()) + { + description.append("\n").append(C.cDAqua).append(line); + } + + int[] rewards = getRewards(achievement, data.getLevel()); + String title; + String reward = getRewardsString(player, rewards); + + if (data.getLevel() >= achievement.getMaxLevel()) + { + title = C.cPurpleB + "Achievement Get! "; + + _taskManager.completedTask(success -> + { + if (success) + { + _donationManager.rewardCurrencyUntilSuccess(GlobalCurrency.GEM, player, achievement.getName(), achievement.getGemReward()); + rewardPlayer(player, achievement, rewards); + } + }, player, achievement.getName()); + } + else + { + title = C.cPurpleB + "Achievement Level Up! "; + + rewardPlayer(player, achievement, rewards); + } + + TextComponent message = new TextComponent(title + C.cGray + nameLevel); + + message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(C.cAquaB + nameLevel + "\n" + C.cDAqua + description.toString().substring(1) + reward) + .create())); + + player.spigot().sendMessage(message); + } + }); + } + } + + private String getAchievementName(Achievement achievement, AchievementData data) + { + String nameLevel = achievement.getName(); + + if (achievement.getMaxLevel() > 1) + { + if (achievement.hasLevelNames()) + { + String tier = data.getLevel() == 0 ? achievement.getDefaultLevelName() : achievement.getLevelNames()[Math.min(data.getLevel(), achievement.getLevelNames().length) - 1]; + nameLevel += " " + tier; + } + else + { + nameLevel += " " + (data.getLevel() + (achievement == Achievement.GLOBAL_GEM_HUNTER ? 1 : 0)); + } + } + + return nameLevel; + } + + private int[] getRewards(Achievement achievement, int level) + { + int gems = 0; + int crowns = 0; + int xp = 0; + + if (achievement.getLevelUpRewards().length > 0) + { + int[] rewards = achievement.getLevelUpRewards()[Math.min(level, achievement.getLevelUpRewards().length) - 1]; + gems += rewards[0]; + crowns += rewards[1]; + xp += rewards[2]; + } + + return new int[]{gems, crowns, xp}; + } + + private String getRewardsString(Player player, int[] rewards) + { + String reward = ""; + int gems = rewards[0]; + int crowns = rewards[1]; + int xp = rewards[2]; + + if (gems > 0) + { + reward += C.cGreenB + "+" + gems + " Gems "; + } + if (crowns > 0) + { + reward += C.cGoldB + "+" + crowns + " Crowns "; + } + if (xp > 0 && !_taskManager.hasCompletedTask(player, Achievement.GLOBAL_MINEPLEX_LEVEL.getName())) + { + reward += C.cYellowB + "+" + xp + " EXP "; + } + + return reward; + } + + private void rewardPlayer(Player player, Achievement achievement, int[] rewards) + { + int gems = rewards[0]; + int crowns = rewards[1]; + int xp = rewards[2]; + + if (gems > 0) + { + _donationManager.rewardCurrency(GlobalCurrency.GEM, player, achievement.getName(), gems); + } + if (crowns > 0) + { + _donationManager.rewardCrowns(crowns, player); + } + if (xp > 0) + { + _statsManager.incrementStat(player, Achievement.GLOBAL_MINEPLEX_LEVEL.getStats()[0], xp); + } + } +} diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/GeneralStatsTracker.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/GeneralStatsTracker.java new file mode 100644 index 000000000..1b3afc8fb --- /dev/null +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/GeneralStatsTracker.java @@ -0,0 +1,94 @@ +package mineplex.game.nano.game.components.stats; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.achievement.Achievement; +import mineplex.core.common.util.UtilPlayer; +import mineplex.game.nano.game.Game; +import mineplex.game.nano.game.Game.GameState; +import mineplex.game.nano.game.GamePlacements; +import mineplex.game.nano.game.event.GameStateChangeEvent; +import mineplex.minecraft.game.core.combat.CombatComponent; +import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; + +public class GeneralStatsTracker extends StatTracker +{ + + private long _gameStartTime; + + public GeneralStatsTracker(Game game) + { + super(game); + } + + @EventHandler + public void live(GameStateChangeEvent event) + { + if (event.getState() != GameState.Live) + { + return; + } + + _gameStartTime = System.currentTimeMillis(); + } + + @EventHandler + public void killsAndDeaths(CombatDeathEvent event) + { + Player player = event.GetEvent().getEntity(); + + addStat(player, "Deaths", 1, false, false); + + CombatComponent killerComponent = event.GetLog().GetKiller(); + + if (killerComponent != null) + { + Player killer = UtilPlayer.searchExact(killerComponent.getUniqueIdOfEntity()); + + if (killer != null) + { + addStat(killer, "Kills", 1, false, false); + } + } + } + + @EventHandler + public void winsAndPlayed(GameStateChangeEvent event) + { + if (event.getState() != GameState.End) + { + return; + } + + GamePlacements placements = _game.getGamePlacements(); + List allPlayers = _game.getAllPlayers(); + List winners = placements.getWinners(); + + // Time In Game + int timeInGame = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - _gameStartTime); + allPlayers.forEach(player -> addStat(player, "TimeInGame", timeInGame, true, true)); + + allPlayers.removeAll(winners); + + // Wins & Losses + winners.forEach(player -> addStat(player, "Wins", 1, true, false)); + allPlayers.forEach(player -> addStat(player, "Losses", 1, true, false)); + + // Second & Third + List second = placements.getPlayersAtPlace(1), third = placements.getPlayersAtPlace(2); + + if (second != null) + { + second.forEach(player -> rewardAchievement(player, Achievement.NANO_SECOND_PLACE)); + } + + if (third != null) + { + third.forEach(player -> rewardAchievement(player, Achievement.NANO_THIRD_PLACE)); + } + } +} diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/StatTracker.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/StatTracker.java new file mode 100644 index 000000000..dd2609428 --- /dev/null +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/StatTracker.java @@ -0,0 +1,35 @@ +package mineplex.game.nano.game.components.stats; + +import java.util.Arrays; + +import org.bukkit.entity.Player; + +import mineplex.core.achievement.Achievement; +import mineplex.core.lifetimes.ListenerComponent; +import mineplex.game.nano.game.Game; +import mineplex.game.nano.game.Game.GameState; + +public class StatTracker extends ListenerComponent implements StatsComponent +{ + + protected final T _game; + + protected StatTracker(T game) + { + _game = game; + + game.getLifetime().register(this, Arrays.asList(GameState.Live, GameState.End)); + } + + @Override + public void addStat(Player player, String stat, int amount, boolean limitTo1, boolean global) + { + _game.addStat(player, stat, amount, limitTo1, global); + } + + @Override + public void rewardAchievement(Player player, Achievement achievement) + { + _game.rewardAchievement(player, achievement); + } +} diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/StatsComponent.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/StatsComponent.java new file mode 100644 index 000000000..b30400ce3 --- /dev/null +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/stats/StatsComponent.java @@ -0,0 +1,14 @@ +package mineplex.game.nano.game.components.stats; + +import org.bukkit.entity.Player; + +import mineplex.core.achievement.Achievement; + +public interface StatsComponent +{ + + void addStat(Player player, String stat, int amount, boolean limitTo1, boolean global); + + void rewardAchievement(Player player, Achievement achievement); + +} diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/MineKart.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/MineKart.java index f0e0df622..14e08b37b 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/MineKart.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/MineKart.java @@ -85,16 +85,16 @@ public class MineKart extends SoloGame implements IPacketHandler return 1; } - if (o1.getLap() != o2.getLap()) - { - return Integer.compare(o2.getLap(), o1.getLap()); - } - if (o1.getLapKeyCheckpoint() != o2.getLapKeyCheckpoint()) { return Integer.compare(o2.getLapKeyCheckpoint(), o1.getLapKeyCheckpoint()); } + if (o1.getLap() != o2.getLap()) + { + return Integer.compare(o2.getLap(), o1.getLap()); + } + return Integer.compare(o2.getLapCheckpoint(), o1.getLapCheckpoint()); }; @@ -207,10 +207,11 @@ public class MineKart extends SoloGame implements IPacketHandler if (a.getY() == b.getY()) { + a.subtract(0, 1, 0); b.add(0, 1, 0); } - KartCheckpoint checkpoint = new KartCheckpoint(locations.get(0), locations.get(1), index, args.length > 2); + KartCheckpoint checkpoint = new KartCheckpoint(a, b, index, args.length > 2); _checkpoints.add(checkpoint); @@ -483,7 +484,7 @@ public class MineKart extends SoloGame implements IPacketHandler { if (!event.isAlive()) { - Kart kart = _karts.remove(event.getPlayer()); + Kart kart = _karts.get(event.getPlayer()); if (kart != null) {