diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java index 341869063..e58409e02 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java @@ -2,7 +2,9 @@ package mineplex.core.achievement; public enum Achievement { - GEM_HUNTER("Gem Hunter", new String[] {"Global.GemsEarned"}, new int[] {10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000}); + GLOBAL_GEM_HUNTER("Gem Hunter", new String[] {"Global.GemsEarned"}, new int[] {10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000}), + + GAME_SPLEEF_SMASHER("Spleef Smasher", new String[] {"Super Spleef.BlocksBroken"}, new int[] {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200}); private String _name; private String[] _stats; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementLog.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementLog.java new file mode 100644 index 000000000..6d6e37f91 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementLog.java @@ -0,0 +1,13 @@ +package mineplex.core.achievement; + +public class AchievementLog +{ + public int Amount; + public boolean LevelUp; + + public AchievementLog(int amount, boolean levelUp) + { + Amount = amount; + LevelUp = levelUp; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java index a11d891e2..7a6976c15 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java @@ -1,11 +1,11 @@ package mineplex.core.achievement; -import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerQuitEvent; import mineplex.core.MiniPlugin; -import mineplex.core.common.util.F; +import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilPlayer; import mineplex.core.stats.StatsManager; import mineplex.core.stats.event.StatChangeEvent; @@ -14,7 +14,7 @@ public class AchievementManager extends MiniPlugin { private StatsManager _statsManager; - private boolean debug = true; + private NautHashMap> _log = new NautHashMap>(); public AchievementManager(StatsManager statsManager) { @@ -35,9 +35,6 @@ public class AchievementManager extends MiniPlugin for (String stat : type.getStats()) { exp += _statsManager.Get(playerName).getStat(stat); - - if (debug) - System.out.println(type.getName() + " Value [" + stat + "] is [" + _statsManager.Get(playerName).getStat(stat) + "]"); } return type.getLevelData(exp); @@ -56,19 +53,59 @@ public class AchievementManager extends MiniPlugin { if (stat.equalsIgnoreCase(event.getStatName())) { - if (debug) - System.out.println(player.getName() + " - " + type.getName() + - " [" + type.getLevelData(event.getValueAfter()).getLevel() + " & " + type.getLevelData(event.getValueBefore()).getLevel() + "]"); + if (!_log.containsKey(player.getName())) + _log.put(player.getName(), new NautHashMap()); + //Record that achievement has leveled up if (type.getLevelData(event.getValueAfter()).getLevel() > type.getLevelData(event.getValueBefore()).getLevel()) { - UtilPlayer.message(player, F.main("Achievement", - "You leveled up " + F.elem(type.getName()) + " to " + F.elem("Level " + type.getLevelData(event.getValueAfter()).getLevel()))); - - player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1f); + //Add new + if (!_log.get(player.getName()).containsKey(type)) + { + _log.get(player.getName()).put(type, new AchievementLog(event.getValueAfter() - event.getValueBefore(), true)); + } + //Edit previous + else + { + AchievementLog log = _log.get(player.getName()).get(type); + log.Amount += event.getValueAfter() - event.getValueBefore(); + log.LevelUp = true; + } + + } + //Record that there has been changes in this Achievement + else if (!_log.get(player.getName()).containsKey(type)) + { + //Add new + if (!_log.get(player.getName()).containsKey(type)) + { + _log.get(player.getName()).put(type, new AchievementLog(event.getValueAfter() - event.getValueBefore(), false)); + } + //Edit previous + else + { + AchievementLog log = _log.get(player.getName()).get(type); + log.Amount += event.getValueAfter() - event.getValueBefore(); + } } } } } } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + _log.remove(event.getPlayer().getName()); + } + + public void clearLog(Player player) + { + _log.remove(player.getName()); + } + + public NautHashMap getLog(Player player) + { + return _log.remove(player.getName()); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/PlayerStats.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/PlayerStats.java index 2f4d3b802..02b67752a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/PlayerStats.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/PlayerStats.java @@ -15,11 +15,9 @@ public class PlayerStats _statHash.put(statName, 0); } - int current = _statHash.get(statName); + _statHash.put(statName, _statHash.get(statName) + value); - _statHash.put(statName, current + value); - - return current+value; + return _statHash.get(statName); } public int getStat(String statName) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java index 7f6e8a758..5384a45a5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java @@ -51,6 +51,8 @@ public class StatsManager extends MiniClientPlugin public void incrementStat(Player player, final String statName, int value) { int newValue = Get(player).addStat(statName, Get(player).getStat(statName) + value); + + System.out.println(player.getName() + " - " + statName + " - " + value + " ? " + newValue); //Event UtilServer.getServer().getPluginManager().callEvent(new StatChangeEvent(player.getName(), statName, newValue - value, newValue)); @@ -69,7 +71,7 @@ public class StatsManager extends MiniClientPlugin _statUploadQueue.get(uuidString).put(statName, 0); } - _statUploadQueue.get(uuidString).put(statName, _statUploadQueue.get(uuidString).get(statName) + value); + _statUploadQueue.get(uuidString).put(statName, value); } // Verify stat is in our local cache, if not add it remotely. diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java index 274c08232..5b33dfd18 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java @@ -19,7 +19,7 @@ public class StatsRepository extends RepositoryBase private static String CREATE_STAT_RELATION_TABLE = "CREATE TABLE IF NOT EXISTS accountStats (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, statId INT NOT NULL, value INT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id), UNIQUE INDEX accountStatIndex (accountId, statId));"; private static String RETRIEVE_PLAYER_STATS = "SELECT stats.name, value FROM accountStats INNER JOIN stats ON stats.id = accountStats.statId INNER JOIN accounts ON accountStats.accountId = accounts.id WHERE accounts.uuid = ?;"; - private static String INSERT_PLAYER_STAT = "INSERT INTO accountStats (accountId, statId, value) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE value=VALUES(value);"; + private static String INSERT_PLAYER_STAT = "INSERT INTO accountStats (accountId, statId, value) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE value=value+VALUES(value);"; private static String RETRIEVE_STATS = "SELECT id, name FROM stats;"; private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);"; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 2364af280..d908e9295 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -47,6 +47,7 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; @@ -551,7 +552,15 @@ public class HubManager extends MiniClientPlugin { if (event.isCancelled()) return; - + + //Dont Let Chat Near Spawn! + if (UtilMath.offset(GetSpawn(), event.getPlayer().getLocation()) < 4) + { + UtilPlayer.message(event.getPlayer(), F.main("Chat", "You must leave spawn before you can chat!")); + event.setCancelled(true); + return; + } + Player player = event.getPlayer(); Rank rank = GetClients().Get(player).GetRank(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 98c56aa45..e9c02c49e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -217,6 +217,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation _gameLobbyManager = new GameLobbyManager(this, packetHandler); new GameFlagManager(this); new GamePlayerManager(this); + new GameAchievementManager(this); _gameWorldManager = new GameWorldManager(this); _miscManager = new MiscManager(this); new IdleManager(this); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index c19aec6cd..1cf72a623 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -94,8 +94,11 @@ public abstract class Game implements Listener //Player Preferences protected NautHashMap _playerKit = new NautHashMap(); private NautHashMap> _teamPreference = new NautHashMap>(); - private NautHashMap> _gemCount = new NautHashMap>(); - + + //Player Data + private NautHashMap> _gemCount = new NautHashMap>(); + private NautHashMap> _stats = new NautHashMap>(); + //Player Location Store private NautHashMap _playerLocationStore = new NautHashMap(); @@ -1057,7 +1060,7 @@ public abstract class Game implements Listener return; } - Announce(F.elem(player.getName()) + " used a " + F.elem("Gem Booster") + " for " + F.elem("+" + (100-(GemBoosters.size()*25)) + "% Gems") + "!"); + Announce(F.elem(player.getName()) + " used a " + F.elem(C.cGreen + "Gem Booster") + " for " + F.elem("+" + (100-(GemBoosters.size()*25)) + "% Gems") + "!"); GemBoosters.add(player.getName()); } @@ -1071,4 +1074,26 @@ public abstract class Game implements Listener return 0; } + + public void AddStat(Player player, String stat, int amount, boolean global) + { + if (!_stats.containsKey(player)) + _stats.put(player, new HashMap()); + + if (global) + stat = "Global." + stat; + else + stat = GetName() + "." + stat; + + int past = 0; + if (_stats.get(player).containsKey(stat)) + past = _stats.get(player).get(stat); + + _stats.get(player).put(stat, past + amount); + } + + public NautHashMap> GetStats() + { + return _stats; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/spleef/Spleef.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/spleef/Spleef.java index aed17da5f..05a5e9f8a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/spleef/Spleef.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/spleef/Spleef.java @@ -1,6 +1,7 @@ package nautilus.game.arcade.game.games.spleef; import java.lang.reflect.Field; +import java.util.HashMap; import org.bukkit.Effect; import org.bukkit.block.Block; @@ -133,6 +134,8 @@ public class Spleef extends SoloGame public void BlockFade(Block block, Player player) { + AddStat(player, "BlocksBroken", 1, false); + UtilPlayer.hunger(player, 1); //Wool and Stained Clay diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java index 174fc8758..de21660b5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java @@ -115,7 +115,7 @@ public class GameGemManager implements Listener RewardGems(event.GetGame(), event.GetPlayer(), false); } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR) public void GameStateChange(GameStateChangeEvent event) { if (Manager.IsTournamentServer()) @@ -165,12 +165,12 @@ public class GameGemManager implements Listener total += (int)(earned * game.GetGemBoostAmount()); //Gem Finder - int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GEM_HUNTER).getLevel(); + int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GLOBAL_GEM_HUNTER).getLevel(); if (gemFinder > 0) { total += (int)(earned * (gemFinder * 0.25)); } - + if (DoubleGem) total += earned; @@ -180,8 +180,8 @@ public class GameGemManager implements Listener Manager.GetStatsManager().incrementStat(player, "Global.GemsEarned", total); Manager.GetStatsManager().incrementStat(player, game.GetName()+".GemsEarned", total); } - - public void AnnounceGems(Game game, Player player, HashMap gems, boolean give) + + public void AnnounceGems(Game game, Player player, HashMap gems, boolean give) { if (Manager.IsTournamentServer()) return; @@ -194,9 +194,9 @@ public class GameGemManager implements Listener UtilPlayer.message(player, ""); UtilPlayer.message(player, ArcadeFormat.Line); - UtilPlayer.message(player, "§aGame - §f§l" + game.GetName()); + UtilPlayer.message(player, "§f§lGems Earned"); UtilPlayer.message(player, ""); - + int earnedGems = 0; for (String type : gems.keySet()) @@ -222,15 +222,15 @@ public class GameGemManager implements Listener //Gem Booster if (game.GetGemBoostAmount() > 0) { - UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems*game.GetGemBoostAmount()) + " Gems") + " for " + - F.elem(game.GemBoosters.size() + " Gem Booster " + C.cGreen + "+" + (int)(game.GetGemBoostAmount()*100))); + UtilPlayer.message(player, F.elem(C.cGreen + "+" + (int)(earnedGems*game.GetGemBoostAmount()) + " Gems") + " for " + + F.elem(game.GemBoosters.size() + " Gem Boosters " + C.cGreen + "+" + (int)(game.GetGemBoostAmount()*100) + "%")); totalGems += earnedGems * game.GetGemBoostAmount(); } //Gem Finder - int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GEM_HUNTER).getLevel(); + int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GLOBAL_GEM_HUNTER).getLevel(); if (gemFinder > 0) { UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems*(gemFinder * 0.25) + " Gems") + " for " + diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java index 95ad437f2..22bc140d5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java @@ -29,7 +29,10 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; @@ -41,12 +44,14 @@ import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText.TextAlign; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; import mineplex.core.donation.Donor; +import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.packethandler.IPacketRunnable; import mineplex.core.packethandler.PacketHandler; import mineplex.core.packethandler.PacketVerifier; @@ -1104,4 +1109,64 @@ public class GameLobbyManager implements IPacketRunnable, Listener } } } + + @EventHandler + public void GemBoosterUpdate(UpdateEvent event) + { + if (Manager.IsTournamentServer()) + return; + + if (event.getType() != UpdateType.SEC) + return; + + if (Manager.GetGame() == null) + return; + + if (Manager.GetGame().GetState() != GameState.Recruit) + return; + + for (Player player : UtilServer.getPlayers()) + { + if (!player.getInventory().contains(Material.EMERALD)) + { + player.getInventory().setItem( + 7, + ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, (short) 0, C.cGreen + + "Gem Booster", new String[] { "", ChatColor.RESET + "Boosts Gems earned for", + ChatColor.RESET + "everyone in the game." })); + } + + for (int i : player.getInventory().all(Material.EMERALD).keySet()) + { + ItemStack stack = player.getInventory().getItem(i); + + ItemMeta itemMeta = stack.getItemMeta(); + itemMeta.setDisplayName(C.cGreen + "Gem Booster" + + " " + C.cWhite + "Click for " + (100-Manager.GetGame().GemBoosters.size()*25) + "% Boost"); + stack.setItemMeta(itemMeta); + + player.getInventory().setItem(i, stack); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void HubClockInteract(PlayerInteractEvent event) + { + if (Manager.IsTournamentServer()) + return; + + Player player = event.getPlayer(); + + if (player.getItemInHand() == null) + return; + + if (player.getItemInHand().getType() != Material.EMERALD) + return; + + if (Manager.GetGame() == null) + return; + + Manager.GetGame().AddGemBooster(player); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java index 87a23365a..697c218e6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java @@ -249,6 +249,21 @@ public class GameManager implements Listener event.GetGame().DeregisterKits(); } + + @EventHandler + public void StatRegister(GameStateChangeEvent event) + { + if (event.GetState() != GameState.End) + return; + + for (Player player : event.GetGame().GetStats().keySet()) + { + for (String stat : event.GetGame().GetStats().get(player).keySet()) + { + Manager.GetStatsManager().incrementStat(player, stat, event.GetGame().GetStats().get(player).get(stat)); + } + } + } @EventHandler(priority = EventPriority.LOWEST) //BEFORE PARSE DATA public void TeamGeneration(GameStateChangeEvent event) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameWorldManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameWorldManager.java index 27779fcc1..791588a8f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameWorldManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameWorldManager.java @@ -17,7 +17,7 @@ import org.bukkit.event.world.ChunkUnloadEvent; public class GameWorldManager implements Listener { ArcadeManager Manager; - + private HashSet _worldLoader = new HashSet(); public GameWorldManager(ArcadeManager manager) @@ -32,7 +32,7 @@ public class GameWorldManager implements Listener { if (event.getType() != UpdateType.TICK) return; - + Iterator worldIterator = _worldLoader.iterator(); long endTime = System.currentTimeMillis() + 25;