Skip to content

Commit

Permalink
Add get|set_entity_saves_on_unload()
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Jan 1, 2025
1 parent f753951 commit 82f4897
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/EntityManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit 82f4897

Please sign in to comment.