-Cached scripted player objects so their tempdata is persisted after death.
This commit is contained in:
Luis C.M committed 2023-06-03 16:55:03 -05:00
1 parent 5c3b7e7c79
commit 065b5eba16
1 file changed
+7 -2
@@ -73,6 +73,7 @@ public class NpcAPI extends AbstractNpcAPI {
private static final Map<Integer, ScriptWorld> worldCache = new LRUHashMap<>(10);
private static final CacheHashMap<ItemStack, CacheHashMap.CachedObject<ScriptItemStack>> scriptItemCache = new CacheHashMap<>(60*1000);
public static final HashMap<String,Object> engineObjects = new HashMap<>();
public static final HashMap<String,ScriptEntityData> playerCache = new HashMap<>();
public static final EventBus EVENT_BUS = new EventBus();
private static AbstractNpcAPI instance = null;
@@ -195,8 +196,12 @@ public class NpcAPI extends AbstractNpcAPI {
ScriptEntityData data = (ScriptEntityData) entity.getExtendedProperties("ScriptedObject");
if(data != null)
return data.base;
if(entity instanceof EntityPlayerMP)
data = new ScriptEntityData(new ScriptPlayer<>((EntityPlayerMP) entity));
if(entity instanceof EntityPlayerMP) {
if (!playerCache.containsKey(((EntityPlayerMP) entity).getDisplayName())) {
playerCache.put(((EntityPlayerMP) entity).getDisplayName(),new ScriptEntityData(new ScriptPlayer<>((EntityPlayerMP) entity)));
}
data = playerCache.get(((EntityPlayerMP) entity).getDisplayName());
}
else if(PixelmonHelper.isPixelmon(entity))
return new ScriptPixelmon<EntityTameable>((EntityTameable) entity);
else if(entity instanceof EntityAnimal)