From a7f77c09fe77b6940958517eabe63091acbd78dc Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 29 Dec 2014 06:42:43 -0500 Subject: [PATCH] Work towards another memory fix. --- .../src/mineplex/core/memory/MemoryFix.java | 97 +++++++++++++------ 1 file changed, 70 insertions(+), 27 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/memory/MemoryFix.java b/Plugins/Mineplex.Core/src/mineplex/core/memory/MemoryFix.java index 0759877bd..5974b6091 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/memory/MemoryFix.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/memory/MemoryFix.java @@ -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 entityIterator = ((IInventory)tileEntity).getViewers().iterator(); + + while (entityIterator.hasNext()) { - if (tileEntity instanceof IInventory) + HumanEntity entity = entityIterator.next(); + + if (entity instanceof CraftPlayer && !((CraftPlayer)entity).isOnline()) { - Iterator 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(); + } + */ } }