aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/lib
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2018-05-25 12:16:57 +1000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2018-05-25 12:16:57 +1000
commit2b73e75c4de865c05c5cb48bc9e91b1754a37c0c (patch)
tree99bb61b1857500a3d313417fd948acc7ce4cedd4 /src/Java/gtPlusPlus/core/lib
parent83a72ed129bafdf25ab87e45521a1a22a3afc23e (diff)
downloadGT5-Unofficial-2b73e75c4de865c05c5cb48bc9e91b1754a37c0c.tar.gz
GT5-Unofficial-2b73e75c4de865c05c5cb48bc9e91b1754a37c0c.tar.bz2
GT5-Unofficial-2b73e75c4de865c05c5cb48bc9e91b1754a37c0c.zip
+ Added a WeakRef type Automap.
+ Added getClassByName(String) to ReflectionUtils.java. + Added lots of handlers to ThaumcraftUtils.java. $ Improved Fake Player handling to only now be held by weak references. Should prevent worlds staying loaded.
Diffstat (limited to 'src/Java/gtPlusPlus/core/lib')
-rw-r--r--src/Java/gtPlusPlus/core/lib/CORE.java34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/Java/gtPlusPlus/core/lib/CORE.java b/src/Java/gtPlusPlus/core/lib/CORE.java
index 2c57d71785..8d89bf27dd 100644
--- a/src/Java/gtPlusPlus/core/lib/CORE.java
+++ b/src/Java/gtPlusPlus/core/lib/CORE.java
@@ -5,8 +5,12 @@ import java.util.concurrent.ConcurrentHashMap;
import com.mojang.authlib.GameProfile;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.world.World;
+import net.minecraft.world.WorldServer;
import gregtech.api.GregTech_API;
@@ -22,6 +26,7 @@ import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy;
import gtPlusPlus.xmod.gregtech.common.tileentities.automation.GT_MetaTileEntity_TesseractGenerator;
import gtPlusPlus.xmod.gregtech.common.tileentities.automation.GT_MetaTileEntity_TesseractTerminal;
import net.minecraftforge.common.config.Configuration;
+import net.minecraftforge.common.util.FakePlayerFactory;
public class CORE {
@@ -64,7 +69,7 @@ public class CORE {
//GT++ Fake Player Profile
public static GameProfile gameProfile = new GameProfile(UUID.nameUUIDFromBytes("gtplusplus.core".getBytes()), "[GT++]");
- ;
+ public static final WeakHashMap<World, EntityPlayerMP> fakePlayerCache = new WeakHashMap<World, EntityPlayerMP>();
//Tooltips;
public static final String GT_Tooltip = "Added by: " + EnumChatFormatting.DARK_GREEN+"Alkalus "+EnumChatFormatting.GRAY+"- "+EnumChatFormatting.RED+"[GT++]";
public static final String GT_Tooltip_Radioactive = EnumChatFormatting.GRAY+"Warning: "+EnumChatFormatting.GREEN+"Radioactive! "+EnumChatFormatting.GOLD+" Avoid direct handling without hazmat protection.";
@@ -128,7 +133,32 @@ public class CORE {
-
+ /** Used to create a {@link EntityPlayer} instance from {@link FakePlayerFactory}.
+ * If this instance already exists in the cache, we will return that instead.
+ * These instances are held via weak reference, if the world object is unloaded, they too will be removed.
+ * This is the suggested way to handle them, as suggested by Forge.
+ *
+ * @param world - The {@link World} object for which you want to check for in the cache.
+ * This object is used as a weak reference in a {@link WeakHashMap}.
+ * @return - An {@link EntityPlayerMP} instance, returned either from cache or created and cached prior to return.
+ */
+ public static EntityPlayerMP getFakePlayer(World world) {
+ if (fakePlayerCache.get(world) == null) {
+ fakePlayerCache.put(world, FakePlayerFactory.get((WorldServer) world, CORE.gameProfile));
+ }
+ return fakePlayerCache.get(world);
+ }
+
+
+
+
+
+
+
+
+
+
+