Skip to content

Commit 436c4a0

Browse files
authored
Sleeping ignored (#1398)
Adds is/set_player_sleeping_ignored.
1 parent 18b901d commit 436c4a0

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
public interface MCPlayer extends MCCommandSender, MCHumanEntity, MCOfflinePlayer {
1818

19+
void setSleepingIgnored(boolean value);
20+
21+
boolean isSleepingIgnored();
22+
1923
boolean canSee(MCPlayer p);
2024

2125
void chat(String chat);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ public Player _Player() {
8181
return p;
8282
}
8383

84+
@Override
85+
public void setSleepingIgnored(boolean value) {
86+
p.setSleepingIgnored(value);
87+
}
88+
89+
@Override
90+
public boolean isSleepingIgnored() {
91+
return p.isSleepingIgnored();
92+
}
93+
8494
@Override
8595
public boolean canSee(MCPlayer p) {
8696
return this.p.canSee(((BukkitMCPlayer) p)._Player());

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

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7307,4 +7307,111 @@ public Boolean runAsync() {
73077307
return false;
73087308
}
73097309
}
7310+
7311+
@api
7312+
public static class set_player_sleeping_ignored extends AbstractFunction {
7313+
7314+
@Override public String getName() {
7315+
return "set_player_sleeping_ignored";
7316+
}
7317+
7318+
@Override public Integer[] numArgs() {
7319+
return new Integer[]{1, 2};
7320+
}
7321+
7322+
@Override
7323+
public Mixed exec(Target t, Environment env, Mixed... args)
7324+
throws ConfigRuntimeException {
7325+
final MCPlayer player;
7326+
final boolean value;
7327+
if(args.length == 1) {
7328+
player = env.getEnv(CommandHelperEnvironment.class).GetPlayer();
7329+
Static.AssertPlayerNonNull(player, t);
7330+
value = ArgumentValidation.getBoolean(args[0], t);
7331+
} else {
7332+
player = Static.GetPlayer(args[0], t);
7333+
value = ArgumentValidation.getBoolean(args[1], t);
7334+
}
7335+
player.setSleepingIgnored(value);
7336+
return CVoid.VOID;
7337+
}
7338+
7339+
@Override
7340+
public Class<? extends CREThrowable>[] thrown() {
7341+
return new Class[]{
7342+
CREPlayerOfflineException.class,
7343+
CREInsufficientArgumentsException.class,
7344+
CRECastException.class
7345+
};
7346+
}
7347+
7348+
@Override public boolean isRestricted() {
7349+
return false;
7350+
}
7351+
7352+
@Override public Boolean runAsync() {
7353+
return false;
7354+
}
7355+
7356+
@Override public MSVersion since() {
7357+
return MSVersion.V3_3_5;
7358+
}
7359+
7360+
@Override
7361+
public String docs() {
7362+
return "void {[player], boolean} Sets whether <player> is ignored when "
7363+
+ "counting sleepers to skip night.";
7364+
}
7365+
}
7366+
7367+
@api
7368+
public static class is_player_sleeping_ignored extends AbstractFunction {
7369+
7370+
@Override public String getName() {
7371+
return "is_player_sleeping_ignored";
7372+
}
7373+
7374+
@Override public Integer[] numArgs() {
7375+
return new Integer[]{0, 1};
7376+
}
7377+
7378+
@Override
7379+
public Mixed exec(Target t, Environment env, Mixed... args)
7380+
throws ConfigRuntimeException {
7381+
final MCPlayer player;
7382+
if(args.length == 0) {
7383+
player = env.getEnv(CommandHelperEnvironment.class).GetPlayer();
7384+
Static.AssertPlayerNonNull(player, t);
7385+
} else {
7386+
player = Static.GetPlayer(args[0], t);
7387+
}
7388+
return CBoolean.get(player.isSleepingIgnored());
7389+
}
7390+
7391+
@Override
7392+
public Class<? extends CREThrowable>[] thrown() {
7393+
return new Class[] {
7394+
CREPlayerOfflineException.class,
7395+
CREInsufficientArgumentsException.class
7396+
};
7397+
}
7398+
7399+
@Override public boolean isRestricted() {
7400+
return false;
7401+
}
7402+
7403+
@Override public Boolean runAsync() {
7404+
return false;
7405+
}
7406+
7407+
@Override public MSVersion since() {
7408+
return MSVersion.V3_3_5;
7409+
}
7410+
7411+
@Override
7412+
public String docs() {
7413+
return "boolean {[player]} Returns whether <player> is currently ignored "
7414+
+ "by the night-skip sleep check.";
7415+
}
7416+
}
73107417
}

0 commit comments

Comments
 (0)