Work towards another memory fix.

This commit is contained in:
Jonathan Williams 2014-12-29 06:42:43 -05:00
parent 5a57c5f372
commit a7f77c09fe

View File

@ -1,59 +1,102 @@
package mineplex.core.memory;
import java.lang.reflect.Field;
import java.util.Iterator;
import mineplex.core.MiniPlugin;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import net.minecraft.server.v1_7_R4.CraftingManager;
import net.minecraft.server.v1_7_R4.EntityTracker;
import net.minecraft.server.v1_7_R4.IInventory;
import net.minecraft.server.v1_7_R4.IntHashMap;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
public class MemoryFix
public class MemoryFix extends MiniPlugin
{
private JavaPlugin _plugin;
private static Field _intHashMap;
public MemoryFix(JavaPlugin plugin)
{
_plugin = plugin;
super("Memory Fix", plugin);
_plugin.getServer().getScheduler().scheduleSyncRepeatingTask(_plugin, new Runnable()
//_intHashMap = IntHashMap.class.
}
@EventHandler
public void fixInventoryLeaks(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW)
return;
for (World world : Bukkit.getWorlds())
{
public void run()
for (Object tileEntity : ((CraftWorld)world).getHandle().tileEntityList)
{
for (World world : Bukkit.getWorlds())
if (tileEntity instanceof IInventory)
{
for (Object tileEntity : ((CraftWorld)world).getHandle().tileEntityList)
Iterator<HumanEntity> entityIterator = ((IInventory)tileEntity).getViewers().iterator();
while (entityIterator.hasNext())
{
if (tileEntity instanceof IInventory)
HumanEntity entity = entityIterator.next();
if (entity instanceof CraftPlayer && !((CraftPlayer)entity).isOnline())
{
Iterator<HumanEntity> entityIterator = ((IInventory)tileEntity).getViewers().iterator();
while (entityIterator.hasNext())
{
HumanEntity entity = entityIterator.next();
if (entity instanceof CraftPlayer && !((CraftPlayer)entity).isOnline())
{
entityIterator.remove();
}
}
entityIterator.remove();
}
}
}
}
}, 100L, 100L);
}
_plugin.getServer().getScheduler().scheduleSyncRepeatingTask(_plugin, new Runnable()
CraftingManager.getInstance().lastCraftView = null;
CraftingManager.getInstance().lastRecipe = null;
}
@EventHandler
public void fixEntityTrackerLeak(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW)
return;
// NEED TO FIX STUCK NETWORKMANAGERS.....
/*
for (World world : Bukkit.getWorlds())
{
public void run()
{
CraftingManager.getInstance().lastCraftView = null;
CraftingManager.getInstance().lastRecipe = null;
}
}, 100L, 100L);
EntityTracker tracker = ((CraftWorld)world).getHandle().getTracker();
EntityTrackerEntry entitytrackerentry1 = (EntityTrackerEntry) tracker.trackedEntities.d(entity.getId());
if (entitytrackerentry1 != null) {
this.c.remove(entitytrackerentry1);
entitytrackerentry1.a();
}
}
if (entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
while (iterator.hasNext()) {
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next();
entitytrackerentry.a(entityplayer);
}
}
EntityTrackerEntry entitytrackerentry1 = (EntityTrackerEntry) this.trackedEntities.d(entity.getId());
if (entitytrackerentry1 != null) {
this.c.remove(entitytrackerentry1);
entitytrackerentry1.a();
}
*/
}
}