diff --git a/src/main/java/com/laytonsmith/abstraction/MCEntity.java b/src/main/java/com/laytonsmith/abstraction/MCEntity.java index aa818ec0d..fbaa76c31 100644 --- a/src/main/java/com/laytonsmith/abstraction/MCEntity.java +++ b/src/main/java/com/laytonsmith/abstraction/MCEntity.java @@ -57,6 +57,10 @@ public interface MCEntity extends MCMetadatable { void remove(); + boolean savesOnUnload(); + + void setSavesOnUnload(boolean remove); + void setFallDistance(float distance); void setFireTicks(int ticks); diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCEntity.java b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCEntity.java index fc9714262..0595e0850 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCEntity.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCEntity.java @@ -194,6 +194,16 @@ public void remove() { e.remove(); } + @Override + public boolean savesOnUnload() { + return e.isPersistent(); + } + + @Override + public void setSavesOnUnload(boolean saves) { + e.setPersistent(saves); + } + @Override public void setFallDistance(float distance) { e.setFallDistance(distance); diff --git a/src/main/java/com/laytonsmith/core/functions/EntityManagement.java b/src/main/java/com/laytonsmith/core/functions/EntityManagement.java index a6b7c4a97..20f4ff393 100644 --- a/src/main/java/com/laytonsmith/core/functions/EntityManagement.java +++ b/src/main/java/com/laytonsmith/core/functions/EntityManagement.java @@ -642,6 +642,61 @@ public MSVersion since() { } + @api(environments = {CommandHelperEnvironment.class}) + public static class get_entity_saves_on_unload extends EntityGetterFunction { + + @Override + public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { + MCEntity ent = Static.getEntity(args[0], t); + return CBoolean.get(ent.savesOnUnload()); + } + + @Override + public String getName() { + return "get_entity_saves_on_unload"; + } + + @Override + public String docs() { + return "void {entityUUID} Gets whether the entity will be saved to disk when it is unloaded."; + } + + @Override + public MSVersion since() { + return MSVersion.V3_3_5; + } + + } + + @api(environments = {CommandHelperEnvironment.class}) + public static class set_entity_saves_on_unload extends EntitySetterFunction { + + @Override + public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { + MCEntity ent = Static.getEntity(args[0], t); + ent.setSavesOnUnload(ArgumentValidation.getBooleanObject(args[1], t)); + return CVoid.VOID; + } + + @Override + public String getName() { + return "set_entity_saves_on_unload"; + } + + @Override + public String docs() { + return "void {entityUUID, boolean} Sets whether the entity is saved to disk when it is unloaded." + + " By default an entity is saved. Setting this to false disables that." + + " Can be used on players to disable player data saving on quit."; + } + + @Override + public MSVersion since() { + return MSVersion.V3_3_5; + } + + } + @api(environments = {CommandHelperEnvironment.class}) public static class entity_type extends EntityGetterFunction {