Fix memory leak in CombatLogNPC

This commit is contained in:
samczsun 2016-09-30 19:34:04 -04:00 committed by Shaun Bennett
parent 0cbd4a9de2
commit 894e6b4a89
3 changed files with 29 additions and 13 deletions

View File

@ -261,7 +261,11 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
entityPlayer.playerConnection.networkManager.handle(((DisguisePlayer) originalDisguise).getUndisguiseInfoPackets(true));
if (reason != UndisguiseReason.QUIT)
{
entityPlayer.playerConnection.networkManager.handle(((DisguisePlayer) originalDisguise).getUndisguiseInfoPackets(false));
Packet add = ((DisguisePlayer) originalDisguise).getUndisguiseInfoPackets(false);
if (add != null)
{
entityPlayer.playerConnection.networkManager.handle(add);
}
}
}
}

View File

@ -228,6 +228,8 @@ public class CombatLogModule extends Module
teamGame.RejoinTeam.remove(logoutNpc.getPlayerInfo().getName());
teamGame.RejoinHealth.remove(logoutNpc.getPlayerInfo().getName());
}
_logoutNpcs.remove(logoutNpc.getPlayerInfo().getUniqueId());
}
@EventHandler(ignoreCancelled = true)
@ -274,10 +276,7 @@ public class CombatLogModule extends Module
{
if (event.getType() == UpdateType.FASTER)
{
for (CombatLogNPC npc : _logoutNpcs.values())
{
npc.update();
}
_logoutNpcs.values().forEach(CombatLogNPC::update);
}
if (event.getType() == UpdateType.SEC)
@ -297,7 +296,7 @@ public class CombatLogModule extends Module
else if (!npc.isAlive())
{
System.out.println("Removing NPC " + npc.getPlayerInfo().getName() + " for 2");
npc.remove();
npc.despawn();
iterator.remove();
}
else if (npc.getAliveDuation() > this._spawnTime)

View File

@ -3,6 +3,7 @@ package nautilus.game.arcade.game.modules.combatlog;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilTime;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseBase;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.hologram.Hologram;
import nautilus.game.arcade.ArcadeManager;
@ -33,6 +34,7 @@ public class CombatLogNPC
private double _maxHealth;
private LivingEntity _npc;
private DisguiseBase _disguise;
private EntityDamageEvent.DamageCause _lastDamageCause;
private Entity _lastDamager;
@ -59,7 +61,7 @@ public class CombatLogNPC
*/
public void onDeath()
{
_disguiseManager.undisguise(_npc);
despawn();
}
public void update()
@ -99,21 +101,30 @@ public class CombatLogNPC
public void despawn()
{
if (_disguise != null)
{
try
{
_disguiseManager.undisguise(_disguise);
_disguise = null;
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (_npc != null)
{
_npc.remove();
_npc = null;
}
if (_hologram != null)
{
_hologram.stop();
_hologram = null;
}
}
public void remove()
{
_hologram.stop();
_hologram = null;
}
public PlayerInfo getPlayerInfo()
{
return _playerInfo;
@ -149,6 +160,8 @@ public class CombatLogNPC
DisguisePlayer disguise = new DisguisePlayer(skel, ((CraftPlayer) player).getHandle().getProfile());
_disguiseManager.disguise(disguise);
_disguise = disguise;
return skel;
}