Fixed gun stats between games

This commit is contained in:
xGamingDudex 2016-04-16 18:16:53 +02:00
parent ffc0459e5a
commit 696088b57e
2 changed files with 34 additions and 12 deletions

View File

@ -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)
{
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<String, Integer> stats = game.GetStats().get(owner);
if(stats != null)
HashMap<String, Integer> localStatsMap = game.GetStats().get(owner);
if(localStatsMap != null)
{
Integer kills = stats.get(game.GetName() + "." + getStatNameKills());
Integer kills = localStatsMap.get(game.GetName() + "." + getStatNameKills());
if(kills != null)
{
_kills = kills.intValue();
_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);
@ -354,6 +371,10 @@ public class Gun extends StrikeItem
}
}
public void incrementKill() {
_kills++;
}
public double getDropOff()
{
return _gunStats.getDropoff();

View File

@ -48,6 +48,7 @@ public class MineStrikeGunStats extends StatTracker<Game>
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());
}