Messy fix for now, code cleanup will happen later

This commit is contained in:
nossr50 2020-10-12 12:50:18 -07:00
parent 29722511b7
commit bc71f586d7
4 changed files with 31 additions and 12 deletions

View File

@ -1,5 +1,5 @@
Version 2.1.149
Added new config file 'persistentdata.yml'
Added new config file 'persistent_data.yml'
Almost all persistent mob data is now off by default and needs to be turned on in persistentdata.yml (new config file) for performance concerns
NOTES:
@ -8,6 +8,9 @@ Version 2.1.149
Persistent data on mobs is a new feature that was introduced in 2.1.148, it was not in mcMMO for the last 10 years and most of you probably didn't even know that it was missing.
An example of persistent data would be, normally mcMMO would give 0 XP for a mob from a mob spawner, in the last 10 years if the server rebooted then those existing mobs would give XP again. But with the persistent data option turned on in persistentdata.yml they will be saved to disk, and mcMMO will not forget about them upon reboot.
For now it is not recommended to use persistent data without monitoring performance of ticks afterwards to make sure it was something your server could handle.
I have a solution in mind to make persistent data not so expensive, but writing the code for that will take some time. This will serve as an interim fix.
Version 2.1.148
Fixed a memory leak involving entity metadata
Alchemy progression is now more reasonable (delete skillranks.yml or edit it yourself to receive the change, see notes)

View File

@ -6,7 +6,7 @@ public class PersistentDataConfig extends AutoUpdateConfigLoader {
private static PersistentDataConfig instance;
private PersistentDataConfig() {
super("persistentdata.yml");
super("persistent_data.yml");
validate();
}
@ -29,9 +29,9 @@ public class PersistentDataConfig extends AutoUpdateConfigLoader {
}
//Persistent Data Toggles
public boolean isMobPersistent(MobMetaFlagType mobMetaFlagType) {
String key = "Persistent_Data.Mobs.Flags." + mobMetaFlagType.toString() + ".Saved_To_Disk";
return config.getBoolean(key, false);
}
}

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.util.compat.layers.persistentdata;
import com.gmail.nossr50.api.exceptions.IncompleteNamespacedKeyRegister;
import com.gmail.nossr50.config.PersistentDataConfig;
import com.gmail.nossr50.mcMMO;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
@ -69,13 +70,17 @@ public class SpigotPersistentDataLayer_1_14 extends AbstractPersistentDataLayer
@Override
public boolean hasMobFlag(@NotNull MobMetaFlagType flag, @NotNull LivingEntity livingEntity) {
if(PersistentDataConfig.getInstance().isMobPersistent(flag)) {
return livingEntity.getPersistentDataContainer().has(mobFlagKeyMap.get(flag), PersistentDataType.BYTE);
} else {
return transientLayer.hasMobFlag(flag, livingEntity);
}
}
@Override
public boolean hasMobFlags(@NotNull LivingEntity livingEntity) {
for(NamespacedKey currentKey : mobFlagKeyMap.values()) {
if(livingEntity.getPersistentDataContainer().has(currentKey, PersistentDataType.BYTE)) {
for(MobMetaFlagType currentFlag : MobMetaFlagType.values()) {
if(hasMobFlag(currentFlag, livingEntity)) {
return true;
}
}
@ -94,18 +99,26 @@ public class SpigotPersistentDataLayer_1_14 extends AbstractPersistentDataLayer
@Override
public void flagMetadata(@NotNull MobMetaFlagType flag, @NotNull LivingEntity livingEntity) {
if(PersistentDataConfig.getInstance().isMobPersistent(flag)) {
if(!hasMobFlag(flag, livingEntity)) {
PersistentDataContainer persistentDataContainer = livingEntity.getPersistentDataContainer();
persistentDataContainer.set(mobFlagKeyMap.get(flag), PersistentDataType.BYTE, SIMPLE_FLAG_VALUE);
}
} else {
transientLayer.flagMetadata(flag, livingEntity);
}
}
@Override
public void removeMobFlag(@NotNull MobMetaFlagType flag, @NotNull LivingEntity livingEntity) {
if(PersistentDataConfig.getInstance().isMobPersistent(flag)) {
if(hasMobFlag(flag, livingEntity)) {
PersistentDataContainer persistentDataContainer = livingEntity.getPersistentDataContainer();
persistentDataContainer.remove(mobFlagKeyMap.get(flag));
}
} else {
transientLayer.removeMobFlag(flag, livingEntity);
}
}
@Override

View File

@ -2,6 +2,9 @@
# For 10 years mcMMO had transient data (temporary) for a lot of things and recently in October 2020 I added the option to have things be persistent (saved to disk and permanently remembered)
# However, this is Minecraft, and Minecraft has a lot of entities, and when you start to make data persistent there is a performance cost associated with that
# Any option you turn on, is another thing your disk has to save when a chunk is being unloaded with that entity inside of it, Minecraft can quickly build up tens of thousands of entities so keep this in mind.
#
# I am considering alternative to using Spigots NBT API to avoid this performance cost, but the code for those will take some time to write and test, for now it is not recommended
# to turn any of these settings on without monitoring the TPS of your server afterwards. With the exception of the COTW setting which will probably have almost no performance impact if left on.
Persistent_Data:
Mobs:
Flags: