Search in sources :

Example 1 with MCConsoleCommandSender

use of com.laytonsmith.abstraction.MCConsoleCommandSender in project CommandHelper by EngineHub.

the class PlayerManangementTest method testPlayerFromConsole.

@Test
public void testPlayerFromConsole() throws Exception {
    MCConsoleCommandSender fakeConsole = mock(MCConsoleCommandSender.class);
    when(fakeConsole.getName()).thenReturn("CONSOLE");
    assertEquals("~console", SRun("player()", fakeConsole));
}
Also used : MCConsoleCommandSender(com.laytonsmith.abstraction.MCConsoleCommandSender) Test(org.junit.Test) StaticTest(com.laytonsmith.testing.StaticTest)

Example 2 with MCConsoleCommandSender

use of com.laytonsmith.abstraction.MCConsoleCommandSender in project CommandHelper by EngineHub.

the class StaticTest method GetFakeConsoleCommandSender.

public static MCConsoleCommandSender GetFakeConsoleCommandSender() {
    MCConsoleCommandSender c = mock(MCConsoleCommandSender.class);
    when(c.getName()).thenReturn("CONSOLE");
    MCServer s = GetFakeServer();
    when(c.getServer()).thenReturn(s);
    return c;
}
Also used : MCConsoleCommandSender(com.laytonsmith.abstraction.MCConsoleCommandSender) MCServer(com.laytonsmith.abstraction.MCServer)

Example 3 with MCConsoleCommandSender

use of com.laytonsmith.abstraction.MCConsoleCommandSender in project CommandHelper by EngineHub.

the class PlayerManangementTest method testPlayer2.

@Test(timeout = 10000)
public void testPlayer2() throws Exception {
    String script = "player()";
    MCConsoleCommandSender c = GetFakeConsoleCommandSender();
    assertEquals("~console", SRun(script, c));
}
Also used : MCConsoleCommandSender(com.laytonsmith.abstraction.MCConsoleCommandSender) Test(org.junit.Test) StaticTest(com.laytonsmith.testing.StaticTest)

Example 4 with MCConsoleCommandSender

use of com.laytonsmith.abstraction.MCConsoleCommandSender in project CommandHelper by EngineHub.

the class Static method SendMessage.

/**
 * This function sends a message to the player. If the player is not online, a CRE is thrown.
 *
 * @param m
 * @param msg
 */
public static void SendMessage(final MCCommandSender m, String msg, final Target t) {
    if (m != null && !(m instanceof MCConsoleCommandSender)) {
        if (m instanceof MCPlayer) {
            MCPlayer p = (MCPlayer) m;
            if (!p.isOnline()) {
                throw new CREPlayerOfflineException("The player " + p.getName() + " is not online", t);
            }
        }
        m.sendMessage(msg);
    } else {
        msg = Static.MCToANSIColors(msg);
        if (msg.contains("\033")) {
            // We have terminal colors, we need to reset them at the end
            msg += TermColors.reset();
        }
        StreamUtils.GetSystemOut().println(msg);
    }
}
Also used : CREPlayerOfflineException(com.laytonsmith.core.exceptions.CRE.CREPlayerOfflineException) MCPlayer(com.laytonsmith.abstraction.MCPlayer) MCConsoleCommandSender(com.laytonsmith.abstraction.MCConsoleCommandSender)

Aggregations

MCConsoleCommandSender (com.laytonsmith.abstraction.MCConsoleCommandSender)4 StaticTest (com.laytonsmith.testing.StaticTest)2 Test (org.junit.Test)2 MCPlayer (com.laytonsmith.abstraction.MCPlayer)1 MCServer (com.laytonsmith.abstraction.MCServer)1 CREPlayerOfflineException (com.laytonsmith.core.exceptions.CRE.CREPlayerOfflineException)1