Skip to content

Commit b977fdd

Browse files
committed
Broken Build
1 parent 18b901d commit b977fdd

File tree

4 files changed

+171
-0
lines changed

4 files changed

+171
-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) { // no explicit player
7328+
player = env.getEnv(CommandHelperEnvironment.class).GetPlayer();
7329+
Static.AssertPlayerNonNull(player, t); // may throw CREInsufficientArgumentsException
7330+
value = ArgumentValidation.getBoolean(args[0], t);
7331+
} else { // player supplied
7332+
player = Static.GetPlayer(args[0], t); // may throw CREPlayerOfflineException
7333+
value = ArgumentValidation.getBoolean(args[1], t); // may throw CRECastException
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) { // no explicit player
7383+
player = env.getEnv(CommandHelperEnvironment.class).GetPlayer();
7384+
Static.AssertPlayerNonNull(player, t); // may throw CREInsufficientArgumentsException
7385+
} else {
7386+
player = Static.GetPlayer(args[0], t); // may throw CREPlayerOfflineException
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
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.laytonsmith.core.functions;
2+
3+
import com.laytonsmith.abstraction.MCPlayer;
4+
import com.laytonsmith.core.Static;
5+
import com.laytonsmith.core.environments.CommandHelperEnvironment;
6+
import com.laytonsmith.core.environments.Environment;
7+
import com.laytonsmith.testing.StaticTest;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
11+
import static org.junit.Assert.*;
12+
13+
public class SleepingIgnoredTest {
14+
15+
private MCPlayer player;
16+
private Environment env;
17+
18+
@Before
19+
public void setUp() throws Exception {
20+
player = StaticTest.GetOnlinePlayer();
21+
22+
env = Static.GenerateStandaloneEnvironment()
23+
.cloneAndAdd(new CommandHelperEnvironment());
24+
env.getEnv(CommandHelperEnvironment.class).SetPlayer(player);
25+
26+
player.setSleepingIgnored(false); // start from a known state
27+
}
28+
29+
@Test
30+
public void testImplicitAndExplicitForms() throws Exception {
31+
32+
/* ---------- implicit-player form ---------- */
33+
assertFalse(player.isSleepingIgnored());
34+
StaticTest.SRun("set_player_sleeping_ignored(true)", player, env);
35+
assertTrue(player.isSleepingIgnored());
36+
37+
/* ---------- explicit-player form ---------- */
38+
String pLiteral = "p@" + player.getName(); // literal player constant
39+
40+
StaticTest.SRun("set_player_sleeping_ignored(" + pLiteral + ", false)", player, env);
41+
42+
String raw = StaticTest.SRun("is_player_sleeping_ignored(" + pLiteral + ")", player, env);
43+
assertFalse(parseBool(raw)); // now really off
44+
}
45+
46+
/** CommandHelper returns “:true” / “:false”. */
47+
private static boolean parseBool(String s) {
48+
return s.trim().replaceFirst("^:", "").equalsIgnoreCase("true");
49+
}
50+
}

0 commit comments

Comments
 (0)