From 696088b57ef836fc8b4fde7d95f9000a5077ff3f Mon Sep 17 00:00:00 2001 From: xGamingDudex Date: Sat, 16 Apr 2016 18:16:53 +0200 Subject: [PATCH] Fixed gun stats between games --- .../game/games/minestrike/items/guns/Gun.java | 45 ++++++++++++++----- .../game/arcade/stats/MineStrikeGunStats.java | 1 + 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java index ae5647c6b..bd07405eb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java @@ -1,5 +1,6 @@ package nautilus.game.arcade.game.games.minestrike.items.guns; +import java.sql.SQLException; import java.util.HashMap; import org.bukkit.Bukkit; @@ -14,6 +15,7 @@ import org.bukkit.entity.Snowball; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import mineplex.core.common.util.C; @@ -34,6 +36,7 @@ import mineplex.core.gadget.types.gamemodifiers.GameModifierType; import mineplex.core.gadget.types.gamemodifiers.minestrike.GameModifierMineStrikeSkin; import mineplex.core.recharge.Recharge; import mineplex.core.recharge.RechargedEvent; +import mineplex.core.stats.PlayerStats; import nautilus.game.arcade.game.games.minestrike.MineStrike; import nautilus.game.arcade.game.games.minestrike.data.Bullet; import nautilus.game.arcade.game.games.minestrike.items.StrikeItem; @@ -56,7 +59,7 @@ public class Gun extends StrikeItem protected boolean _reloadTick = false; - protected int _kills = 0; + protected int _kills = -1; protected String _activeSkinName = "Default"; public Gun(GunStats gunStats) @@ -326,22 +329,36 @@ public class Gun extends StrikeItem { if(game != null) { - Player owner = UtilPlayer.searchExact(getOwnerName()); - if(owner != null) { - HashMap stats = game.GetStats().get(owner); - if(stats != null) - { - Integer kills = stats.get(game.GetName() + "." + getStatNameKills()); - if(kills != null) - { - _kills = kills.intValue(); + if(_kills == -1) + { + new BukkitRunnable() { + public void run() { + PlayerStats remoteStats = game.getArcadeManager().GetStatsManager().Get(player);; + _kills = (int) remoteStats.getStat(game.GetName() + "." + getStatNameKills()); + + Player owner = UtilPlayer.searchExact(getOwnerName()); + if(owner != null) { + HashMap localStatsMap = game.GetStats().get(owner); + if(localStatsMap != null) + { + Integer kills = localStatsMap.get(game.GetName() + "." + getStatNameKills()); + if(kills != null) + { + _kills += kills.intValue(); + } + } + } + updateWeaponName(player, null); } - } + }.runTaskAsynchronously(game.getArcadeManager().getPlugin()); } } + int kls = _kills; + if(kls == -1) kls = 0; + String owner = C.Reset + (getOwnerName() == null ? "" : getOwnerName() + "'s "); String reload = C.Bold + getName() + (_reloadTick ? ChatColor.RED : ChatColor.WHITE); - String kills = C.cYellow + " " + _kills + " kills"; + String kills = C.cYellow + " " + kls + " kills"; ItemMeta meta = getStack().getItemMeta(); meta.setDisplayName(owner + reload + kills); @@ -353,6 +370,10 @@ public class Gun extends StrikeItem _reloadTick = !_reloadTick; } } + + public void incrementKill() { + _kills++; + } public double getDropOff() { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/MineStrikeGunStats.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/MineStrikeGunStats.java index 9c14849b9..0293d0435 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/MineStrikeGunStats.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/MineStrikeGunStats.java @@ -48,6 +48,7 @@ public class MineStrikeGunStats extends StatTracker String stat = event.getBullet().Gun.getStatNameKills(); addStat(event.getBullet().Shooter, stat, 1, false, false); + event.getBullet().Gun.incrementKill(); event.getBullet().Gun.updateWeaponName(event.getBullet().Shooter, event.getGame()); }