Skip to content

Commit 82f4897

Browse files
committed
Add get|set_entity_saves_on_unload()
1 parent f753951 commit 82f4897

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

src/main/java/com/laytonsmith/abstraction/MCEntity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public interface MCEntity extends MCMetadatable {
5757

5858
void remove();
5959

60+
boolean savesOnUnload();
61+
62+
void setSavesOnUnload(boolean remove);
63+
6064
void setFallDistance(float distance);
6165

6266
void setFireTicks(int ticks);

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCEntity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ public void remove() {
194194
e.remove();
195195
}
196196

197+
@Override
198+
public boolean savesOnUnload() {
199+
return e.isPersistent();
200+
}
201+
202+
@Override
203+
public void setSavesOnUnload(boolean saves) {
204+
e.setPersistent(saves);
205+
}
206+
197207
@Override
198208
public void setFallDistance(float distance) {
199209
e.setFallDistance(distance);

src/main/java/com/laytonsmith/core/functions/EntityManagement.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,61 @@ public MSVersion since() {
642642

643643
}
644644

645+
@api(environments = {CommandHelperEnvironment.class})
646+
public static class get_entity_saves_on_unload extends EntityGetterFunction {
647+
648+
@Override
649+
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
650+
MCEntity ent = Static.getEntity(args[0], t);
651+
return CBoolean.get(ent.savesOnUnload());
652+
}
653+
654+
@Override
655+
public String getName() {
656+
return "get_entity_saves_on_unload";
657+
}
658+
659+
@Override
660+
public String docs() {
661+
return "void {entityUUID} Gets whether the entity will be saved to disk when it is unloaded.";
662+
}
663+
664+
@Override
665+
public MSVersion since() {
666+
return MSVersion.V3_3_5;
667+
}
668+
669+
}
670+
671+
@api(environments = {CommandHelperEnvironment.class})
672+
public static class set_entity_saves_on_unload extends EntitySetterFunction {
673+
674+
@Override
675+
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
676+
MCEntity ent = Static.getEntity(args[0], t);
677+
ent.setSavesOnUnload(ArgumentValidation.getBooleanObject(args[1], t));
678+
return CVoid.VOID;
679+
}
680+
681+
@Override
682+
public String getName() {
683+
return "set_entity_saves_on_unload";
684+
}
685+
686+
@Override
687+
public String docs() {
688+
return "void {entityUUID, boolean} Sets whether the entity is saved to disk when it is unloaded."
689+
+ " By default an entity is saved. Setting this to false disables that."
690+
+ " Can be used on players to disable player data saving on quit.";
691+
}
692+
693+
@Override
694+
public MSVersion since() {
695+
return MSVersion.V3_3_5;
696+
}
697+
698+
}
699+
645700
@api(environments = {CommandHelperEnvironment.class})
646701
public static class entity_type extends EntityGetterFunction {
647702

0 commit comments

Comments
 (0)