Skip to content

Commit cdc6c62

Browse files
authored
Merge pull request #1240 from Murreey/day-functions
Add get/set functions for world day
2 parents 5a47114 + 2cac88e commit cdc6c62

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

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

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

135135
long getTime();
136136

137+
void setFullTime(long time);
138+
139+
long getFullTime();
140+
137141
CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation location, Target t);
138142

139143
MCFallingBlock spawnFallingBlock(MCLocation loc, MCBlockData data);

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCWorld.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,16 @@ public long getTime() {
474474
return w.getTime();
475475
}
476476

477+
@Override
478+
public void setFullTime(long time) {
479+
w.setFullTime(time);
480+
}
481+
482+
@Override
483+
public long getFullTime() {
484+
return w.getFullTime();
485+
}
486+
477487
@Override
478488
public MCBiomeType getBiome(int x, int z) {
479489
return BukkitMCBiomeType.valueOfConcrete(w.getBiome(x, z));

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

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,121 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
880880
}
881881
}
882882

883+
@api(environments = CommandHelperEnvironment.class)
884+
public static class set_world_day extends AbstractFunction {
885+
886+
@Override
887+
public String getName() {
888+
return "set_world_day";
889+
}
890+
891+
@Override
892+
public Integer[] numArgs() {
893+
return new Integer[]{1, 2};
894+
}
895+
896+
@Override
897+
public String docs() {
898+
return "void {[world], day} Set the current day number of a given world";
899+
}
900+
901+
@Override
902+
public Class<? extends CREThrowable>[] thrown() {
903+
return new Class[]{CREInvalidWorldException.class};
904+
}
905+
906+
@Override
907+
public boolean isRestricted() {
908+
return true;
909+
}
910+
911+
@Override
912+
public MSVersion since() {
913+
return MSVersion.V3_3_4;
914+
}
915+
916+
@Override
917+
public Boolean runAsync() {
918+
return false;
919+
}
920+
921+
@Override
922+
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
923+
MCWorld w = null;
924+
if(environment.getEnv(CommandHelperEnvironment.class).GetPlayer() != null) {
925+
w = environment.getEnv(CommandHelperEnvironment.class).GetPlayer().getWorld();
926+
}
927+
if(args.length == 2) {
928+
w = Static.getServer().getWorld(args[0].val());
929+
}
930+
if(w == null) {
931+
throw new CREInvalidWorldException("No world specified", t);
932+
}
933+
934+
int day = ArgumentValidation.getInt32((args.length == 1 ? args[0] : args[1]), t);
935+
if(day < 0) {
936+
throw new CRERangeException("Day cannot be negative.", t);
937+
}
938+
939+
w.setFullTime((day * 24000) + w.getTime());
940+
return CVoid.VOID;
941+
}
942+
}
943+
944+
@api(environments = CommandHelperEnvironment.class)
945+
public static class get_world_day extends AbstractFunction {
946+
947+
@Override
948+
public String getName() {
949+
return "get_world_day";
950+
}
951+
952+
@Override
953+
public Integer[] numArgs() {
954+
return new Integer[]{0, 1};
955+
}
956+
957+
@Override
958+
public String docs() {
959+
return "int {[world]} Returns the current day number of the specified world";
960+
}
961+
962+
@Override
963+
public Class<? extends CREThrowable>[] thrown() {
964+
return new Class[]{CREInvalidWorldException.class};
965+
}
966+
967+
@Override
968+
public boolean isRestricted() {
969+
return true;
970+
}
971+
972+
@Override
973+
public MSVersion since() {
974+
return MSVersion.V3_3_4;
975+
}
976+
977+
@Override
978+
public Boolean runAsync() {
979+
return false;
980+
}
981+
982+
@Override
983+
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
984+
MCWorld w = null;
985+
if(environment.getEnv(CommandHelperEnvironment.class).GetPlayer() != null) {
986+
w = environment.getEnv(CommandHelperEnvironment.class).GetPlayer().getWorld();
987+
}
988+
if(args.length == 1) {
989+
w = Static.getServer().getWorld(args[0].val());
990+
}
991+
if(w == null) {
992+
throw new CREInvalidWorldException("No world specified", t);
993+
}
994+
return new CInt((long) java.lang.Math.floor(w.getFullTime() / 24000), t);
995+
}
996+
}
997+
883998
@api(environments = {CommandHelperEnvironment.class})
884999
public static class create_world extends AbstractFunction {
8851000

0 commit comments

Comments
 (0)