mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 10:14:43 +02:00
Messy fix for now, code cleanup will happen later
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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) {
|
||||
return livingEntity.getPersistentDataContainer().has(mobFlagKeyMap.get(flag), PersistentDataType.BYTE);
|
||||
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,17 +99,25 @@ public class SpigotPersistentDataLayer_1_14 extends AbstractPersistentDataLayer
|
||||
|
||||
@Override
|
||||
public void flagMetadata(@NotNull MobMetaFlagType flag, @NotNull LivingEntity livingEntity) {
|
||||
if(!hasMobFlag(flag, livingEntity)) {
|
||||
PersistentDataContainer persistentDataContainer = livingEntity.getPersistentDataContainer();
|
||||
persistentDataContainer.set(mobFlagKeyMap.get(flag), PersistentDataType.BYTE, SIMPLE_FLAG_VALUE);
|
||||
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(hasMobFlag(flag, livingEntity)) {
|
||||
PersistentDataContainer persistentDataContainer = livingEntity.getPersistentDataContainer();
|
||||
persistentDataContainer.remove(mobFlagKeyMap.get(flag));
|
||||
if(PersistentDataConfig.getInstance().isMobPersistent(flag)) {
|
||||
if(hasMobFlag(flag, livingEntity)) {
|
||||
PersistentDataContainer persistentDataContainer = livingEntity.getPersistentDataContainer();
|
||||
persistentDataContainer.remove(mobFlagKeyMap.get(flag));
|
||||
}
|
||||
} else {
|
||||
transientLayer.removeMobFlag(flag, livingEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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:
|
Reference in New Issue
Block a user