Skip to content
Permalink
Browse files
Merge pull request #1240 from Murreey/day-functions
Add get/set functions for world day
  • Loading branch information
PseudoKnight committed Aug 15, 2020
2 parents 5a47114 + 2cac88e commit cdc6c62ad30daed9b1c24e102cd7381273916116
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
@@ -134,6 +134,10 @@ public interface MCWorld extends MCMetadatable {

long getTime();

void setFullTime(long time);

long getFullTime();

CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation location, Target t);

MCFallingBlock spawnFallingBlock(MCLocation loc, MCBlockData data);
@@ -474,6 +474,16 @@ public long getTime() {
return w.getTime();
}

@Override
public void setFullTime(long time) {
w.setFullTime(time);
}

@Override
public long getFullTime() {
return w.getFullTime();
}

@Override
public MCBiomeType getBiome(int x, int z) {
return BukkitMCBiomeType.valueOfConcrete(w.getBiome(x, z));
@@ -880,6 +880,121 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
}
}

@api(environments = CommandHelperEnvironment.class)
public static class set_world_day extends AbstractFunction {

@Override
public String getName() {
return "set_world_day";
}

@Override
public Integer[] numArgs() {
return new Integer[]{1, 2};
}

@Override
public String docs() {
return "void {[world], day} Set the current day number of a given world";
}

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREInvalidWorldException.class};
}

@Override
public boolean isRestricted() {
return true;
}

@Override
public MSVersion since() {
return MSVersion.V3_3_4;
}

@Override
public Boolean runAsync() {
return false;
}

@Override
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
MCWorld w = null;
if(environment.getEnv(CommandHelperEnvironment.class).GetPlayer() != null) {
w = environment.getEnv(CommandHelperEnvironment.class).GetPlayer().getWorld();
}
if(args.length == 2) {
w = Static.getServer().getWorld(args[0].val());
}
if(w == null) {
throw new CREInvalidWorldException("No world specified", t);
}

int day = ArgumentValidation.getInt32((args.length == 1 ? args[0] : args[1]), t);
if(day < 0) {
throw new CRERangeException("Day cannot be negative.", t);
}

w.setFullTime((day * 24000) + w.getTime());
return CVoid.VOID;
}
}

@api(environments = CommandHelperEnvironment.class)
public static class get_world_day extends AbstractFunction {

@Override
public String getName() {
return "get_world_day";
}

@Override
public Integer[] numArgs() {
return new Integer[]{0, 1};
}

@Override
public String docs() {
return "int {[world]} Returns the current day number of the specified world";
}

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREInvalidWorldException.class};
}

@Override
public boolean isRestricted() {
return true;
}

@Override
public MSVersion since() {
return MSVersion.V3_3_4;
}

@Override
public Boolean runAsync() {
return false;
}

@Override
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
MCWorld w = null;
if(environment.getEnv(CommandHelperEnvironment.class).GetPlayer() != null) {
w = environment.getEnv(CommandHelperEnvironment.class).GetPlayer().getWorld();
}
if(args.length == 1) {
w = Static.getServer().getWorld(args[0].val());
}
if(w == null) {
throw new CREInvalidWorldException("No world specified", t);
}
return new CInt((long) java.lang.Math.floor(w.getFullTime() / 24000), t);
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class create_world extends AbstractFunction {

0 comments on commit cdc6c62

Please sign in to comment.