diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java index cadd50328..ec9395305 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java @@ -1471,7 +1471,7 @@ public enum Achievement 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}, + new int[]{2,10,50,100,500}, "I", new String[] {"II","III","IV","V","X"}, AchievementCategory.NANO_GAMES), @@ -1494,12 +1494,6 @@ public enum Achievement 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"}, diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java index 658f481fd..8f8670547 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java @@ -1,5 +1,7 @@ package mineplex.core.achievement; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import org.bukkit.entity.Player; @@ -14,7 +16,6 @@ import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.achievement.command.StatsCommand; import mineplex.core.achievement.ui.AchievementShop; -import mineplex.core.common.util.NautHashMap; import mineplex.core.donation.DonationManager; import mineplex.core.elo.EloManager; import mineplex.core.gadget.GadgetManager; @@ -46,7 +47,7 @@ public class AchievementManager extends MiniPlugin private final AchievementShop _shop; - private final NautHashMap> _log = new NautHashMap<>(); + private final Map> _log = new HashMap<>(); public AchievementManager(StatsManager statsManager, CoreClientManager clientManager, DonationManager donationManager, IncognitoManager incognitoManager, EloManager eloManager) { @@ -116,8 +117,7 @@ public class AchievementManager extends MiniPlugin { if (stat.equalsIgnoreCase(event.getStatName())) { - if (!_log.containsKey(player.getName())) - _log.put(player.getName(), new NautHashMap<>()); + _log.computeIfAbsent(player.getName(), k -> new HashMap<>()); //Record that achievement has leveled up if (type.getLevelData(event.getValueAfter()).getLevel() > type.getLevelData(event.getValueBefore()).getLevel()) @@ -194,7 +194,7 @@ public class AchievementManager extends MiniPlugin _log.remove(player.getName()); } - public NautHashMap getLog(Player player) + public Map getLog(Player player) { return _log.get(player.getName()); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/noteblock/LoopedNotePlayer.java b/Plugins/Mineplex.Core/src/mineplex/core/noteblock/LoopedNotePlayer.java index 8894f92c7..fec5cdbfd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/noteblock/LoopedNotePlayer.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/noteblock/LoopedNotePlayer.java @@ -49,9 +49,11 @@ public class LoopedNotePlayer implements Runnable, Component, Lifetimed this(lifetime, song, listeners, null); } - public LoopedNotePlayer(Lifetime lifetime, NoteSong song, Player listener, int sleepMillis) + private LoopedNotePlayer(Lifetime lifetime, NoteSong song, Player listener, int sleepMillis) { this(lifetime, song, sleepMillis, Collections.singleton(listener), null); + + activate(); } public LoopedNotePlayer(Lifetime lifetime, NoteSong song, Collection listeners, Predicate shouldPlay) @@ -164,9 +166,7 @@ public class LoopedNotePlayer implements Runnable, Component, Lifetimed public LoopedNotePlayer cloneForPlayer(Player player, float tempoFactor) { - LoopedNotePlayer notePlayer = new LoopedNotePlayer(getLifetime(), _song, player, (int) (_sleepMillis * tempoFactor)); - notePlayer.setTick(_tick); - return notePlayer; + return new LoopedNotePlayer(getLifetime(), _song, player, (int) (_sleepMillis * tempoFactor)); } @Override 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 e8a47e456..e097a8ca8 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,6 @@ import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Player; -import mineplex.core.achievement.Achievement; import mineplex.core.antihack.AntiHack; import mineplex.core.common.util.UtilServer; import mineplex.core.lifetimes.Lifetimed; @@ -333,12 +332,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed, TeamC _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 6cdced3f7..27db0f9a4 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 @@ -201,8 +201,6 @@ public class GameCurrencyManager extends GameManager implements CurrencyComponen { 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 index 681f48a2c..406b43842 100644 --- 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 @@ -9,6 +9,7 @@ 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.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -81,12 +82,6 @@ public class GameStatsComponent extends GameComponent implements StatsComp _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 @@ -104,15 +99,17 @@ public class GameStatsComponent extends GameComponent implements StatsComp for (Player player : UtilServer.getPlayersCollection()) { - if (manager.getLog(player) == null) + Map logs = manager.getLog(player); + + if (logs == null) { continue; } - manager.getLog(player).entrySet().forEach(entry -> + logs.forEach((achievement, log) -> { - Achievement achievement = entry.getKey(); - AchievementLog log = entry.getValue(); + player.sendMessage(achievement.getName() + " - " + log.LevelUp + " " + log.Amount); + AchievementData data = manager.get(player, achievement); if (log.LevelUp) @@ -133,14 +130,17 @@ public class GameStatsComponent extends GameComponent implements StatsComp { title = C.cPurpleB + "Achievement Get! "; - _taskManager.completedTask(success -> + if (!_taskManager.hasCompletedTask(player, achievement.getName())) { - if (success) + _taskManager.completedTask(success -> { - _donationManager.rewardCurrencyUntilSuccess(GlobalCurrency.GEM, player, achievement.getName(), achievement.getGemReward()); - rewardPlayer(player, achievement, rewards); - } - }, player, achievement.getName()); + if (success) + { + _donationManager.rewardCurrencyUntilSuccess(GlobalCurrency.GEM, player, achievement.getName(), achievement.getGemReward()); + rewardPlayer(player, achievement, rewards); + } + }, player, achievement.getName()); + } } else { @@ -151,12 +151,17 @@ public class GameStatsComponent extends GameComponent implements StatsComp 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) + message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(C.cAquaB + nameLevel + "\n" + C.cDAqua + description.toString().substring(1) + " " + reward) .create())); + player.sendMessage(""); player.spigot().sendMessage(message); + player.sendMessage(""); + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1); } }); + + manager.clearLog(player); } } @@ -212,7 +217,7 @@ public class GameStatsComponent extends GameComponent implements StatsComp { reward += C.cGoldB + "+" + crowns + " Crowns "; } - if (xp > 0 && !_taskManager.hasCompletedTask(player, Achievement.GLOBAL_MINEPLEX_LEVEL.getName())) + if (xp > 0) { reward += C.cYellowB + "+" + xp + " EXP "; } @@ -236,7 +241,8 @@ public class GameStatsComponent extends GameComponent implements StatsComp } if (xp > 0) { - _statsManager.incrementStat(player, Achievement.GLOBAL_MINEPLEX_LEVEL.getStats()[0], xp); + // Need to delay a tick so we don't CME the achievement log loop + _statsManager.runSyncLater(() -> _statsManager.incrementStat(player, Achievement.GLOBAL_MINEPLEX_LEVEL.getStats()[0], xp), 0); } } } 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 index 1b3afc8fb..5bb994a31 100644 --- 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 @@ -6,7 +6,6 @@ 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; @@ -83,12 +82,12 @@ public class GeneralStatsTracker extends StatTracker if (second != null) { - second.forEach(player -> rewardAchievement(player, Achievement.NANO_SECOND_PLACE)); + second.forEach(player -> addStat(player, "SecondPlace", 1, true, false)); } if (third != null) { - third.forEach(player -> rewardAchievement(player, Achievement.NANO_THIRD_PLACE)); + third.forEach(player -> addStat(player, "ThirdPlace", 1, true, false)); } } } 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 index dd2609428..37389db5e 100644 --- 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 @@ -4,7 +4,6 @@ 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; @@ -26,10 +25,4 @@ public class StatTracker extends ListenerComponent implements St { _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 index b30400ce3..2c5fc58c5 100644 --- 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 @@ -2,13 +2,9 @@ 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 14e08b37b..c9d9d2c38 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 @@ -1,6 +1,9 @@ package mineplex.game.nano.game.games.minekart; +import java.io.File; +import java.io.FileNotFoundException; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -40,6 +43,9 @@ import mineplex.core.common.util.UtilShapes; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.noteblock.LoopedNotePlayer; +import mineplex.core.noteblock.NBSReader; +import mineplex.core.noteblock.NoteSong; import mineplex.core.packethandler.IPacketHandler; import mineplex.core.packethandler.PacketInfo; import mineplex.core.recharge.Recharge; @@ -103,6 +109,8 @@ public class MineKart extends SoloGame implements IPacketHandler .addLore("Click to reset your kart", "back on the track.") .build(); + private final LoopedNotePlayer _notePlayer; + public MineKart(NanoManager manager) { super(manager, GameType.MINEKART, new String[] @@ -115,6 +123,33 @@ public class MineKart extends SoloGame implements IPacketHandler _karts = new HashMap<>(); _positions = new ArrayList<>(); + NoteSong song; + + try + { + song = NBSReader.loadSong(".." + File.separator + ".." + File.separator + "update" + File.separator + "songs" + File.separator + "minekart.nbs"); + } + catch (FileNotFoundException e) + { + song = null; + e.printStackTrace(); + } + + if (song != null) + { + _notePlayer = new LoopedNotePlayer(getLifetime(), song, player -> + { + Kart kart = _karts.get(player); + + return kart != null && kart.getLap() < LAPS; + }); + getLifetime().register(_notePlayer, Collections.singleton(GameState.Live)); + } + else + { + _notePlayer = null; + } + _teamComponent.setAdjustSpawnYaw(false); _damageComponent.setDamage(false); @@ -369,6 +404,11 @@ public class MineKart extends SoloGame implements IPacketHandler boolean finalLap = lap == LAPS; + if (finalLap && _notePlayer != null) + { + _notePlayer.cloneForPlayer(player, 0.75F); + } + UtilTextMiddle.display(C.cYellowB + "Lap " + lap, finalLap ? C.cAquaB + "FINAL LAP" : "", 10, 40, 10, player); player.sendMessage(F.main(getManager().getName(), "Lap " + F.count(lap) + (finalLap ? F.color(" FINAL LAP", C.cAquaB) : "") + "!")); } diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengePlayMusic.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengePlayMusic.java index d8581e3ac..2c11d6a99 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengePlayMusic.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengePlayMusic.java @@ -90,7 +90,7 @@ public class ChallengePlayMusic extends Challenge int tick = _songTick.getOrDefault(player, 0); _songTick.put(player, tick + 1); - _song.getLayers().forEach(layer -> + _song.getLayerMap().values().forEach(layer -> { Note note = layer.getNote(tick); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/components/AchievementSummaryComponent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/components/AchievementSummaryComponent.java index 7257bbf38..9b662933f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/components/AchievementSummaryComponent.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/components/AchievementSummaryComponent.java @@ -6,7 +6,6 @@ import org.bukkit.entity.Player; import mineplex.core.achievement.Achievement; 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.jsonchat.HoverEvent; @@ -43,10 +42,8 @@ public class AchievementSummaryComponent extends ComplexSummaryComponent AtomicInteger progressFor = new AtomicInteger(); StringBuilder hoverTextBuilder = new StringBuilder(100); - _achievementManager.getLog(player).entrySet().forEach(entry -> + _achievementManager.getLog(player).forEach((achievement, log) -> { - Achievement achievement = entry.getKey(); - AchievementLog log = entry.getValue(); AchievementData data = _achievementManager.get(player, achievement); if (log.LevelUp)