Search in sources :

Example 1 with MCWorld

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

the class PlayerManangementTest method testSetPloc.

public void testSetPloc() throws Exception, Exception {
    MCWorld w = GetWorld("world");
    CommandHelperPlugin.myServer = fakeServer;
    String name = fakePlayer.getName();
    when(fakeServer.getPlayer(name)).thenReturn(fakePlayer);
    when(fakePlayer.getWorld()).thenReturn(w);
    MCLocation loc = StaticTest.GetFakeLocation(w, 0, 0, 0);
    when(fakePlayer.getLocation()).thenReturn(loc);
    Run("set_ploc(1, 1, 1)", fakePlayer);
    // when(StaticLayer.GetLocation(w, 1, 2, 1)).thenReturn(loc);
    MCLocation loc1 = StaticTest.GetFakeLocation(w, 1, 2, 1);
    // verify(fakePlayer).teleport(loc1);
    assertEquals(fakePlayer.getLocation().getX(), loc1.getX(), 0.00000000000001);
    Run("set_ploc(array(2, 2, 2))", fakePlayer);
    verify(fakePlayer).teleport(StaticLayer.GetLocation(w, 2, 3, 2, 0, 0));
    Run("set_ploc('" + fakePlayer.getName() + "', 3, 3, 3)", fakePlayer);
    verify(fakePlayer).teleport(StaticLayer.GetLocation(w, 3, 4, 3, 0, 0));
    Run("set_ploc('" + fakePlayer.getName() + "', array(4, 4, 4))", fakePlayer);
    verify(fakePlayer).teleport(StaticLayer.GetLocation(w, 4, 5, 4, 0, 0));
}
Also used : MCLocation(com.laytonsmith.abstraction.MCLocation) MCWorld(com.laytonsmith.abstraction.MCWorld) BukkitMCWorld(com.laytonsmith.abstraction.bukkit.BukkitMCWorld)

Example 2 with MCWorld

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

the class PlayerManangementTest method testPcursor.

@Test(timeout = 10000)
public void testPcursor() throws Exception, Exception {
    MCBlock b = mock(MCBlock.class);
    CommandHelperPlugin.myServer = fakeServer;
    when(fakeServer.getPlayer(fakePlayer.getName())).thenReturn(fakePlayer);
    when(fakePlayer.getTargetBlock((HashSet) eq(null), anyInt())).thenReturn(b);
    MCWorld w = mock(MCWorld.class);
    MCLocation loc = StaticTest.GetFakeLocation(w, 0, 0, 0);
    when(b.getLocation()).thenReturn(loc);
    when(b.getWorld()).thenReturn(w);
    Run("pcursor()", fakePlayer);
    verify(fakePlayer, times(1)).getTargetBlock((HashSet) eq(null), anyInt());
}
Also used : MCLocation(com.laytonsmith.abstraction.MCLocation) MCBlock(com.laytonsmith.abstraction.blocks.MCBlock) MCWorld(com.laytonsmith.abstraction.MCWorld) BukkitMCWorld(com.laytonsmith.abstraction.bukkit.BukkitMCWorld) Test(org.junit.Test) StaticTest(com.laytonsmith.testing.StaticTest)

Example 3 with MCWorld

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

the class PermissionsTest method setUp.

@Before
public void setUp() throws Exception {
    fakePlayer = StaticTest.GetOnlinePlayer();
    MCWorld fakeWorld = mock(MCWorld.class);
    // when(fakeWorld.getName()).thenReturn("world");
    // when(fakePlayer.getWorld()).thenReturn(fakeWorld);
    fakeServer = StaticTest.GetFakeServer();
    env = Static.GenerateStandaloneEnvironment();
    env.getEnv(CommandHelperEnvironment.class).SetPlayer(fakePlayer);
}
Also used : CommandHelperEnvironment(com.laytonsmith.core.environments.CommandHelperEnvironment) MCWorld(com.laytonsmith.abstraction.MCWorld) Before(org.junit.Before)

Example 4 with MCWorld

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

the class StaticTest method GetOnlinePlayer.

public static MCPlayer GetOnlinePlayer(String name, String worldName, MCServer s) {
    MCPlayer p = mock(MCPlayer.class);
    MCWorld w = mock(MCWorld.class);
    MCLocation fakeLocation = StaticTest.GetFakeLocation(w, 0, 0, 0);
    MCItemStack fakeItemStack = mock(MCItemStack.class);
    when(w.getName()).thenReturn(worldName);
    when(p.getWorld()).thenReturn(w);
    when(p.isOnline()).thenReturn(true);
    when(p.getName()).thenReturn(name);
    when(p.getServer()).thenReturn(s);
    when(p.isOp()).thenReturn(true);
    if (s != null && s.getOnlinePlayers() != null) {
        Collection<MCPlayer> online = s.getOnlinePlayers();
        boolean alreadyOnline = false;
        for (MCPlayer o : online) {
            if (o.getName().equals(name)) {
                alreadyOnline = true;
                break;
            }
        }
        if (!alreadyOnline) {
            online.add(p);
            when(s.getOnlinePlayers()).thenReturn(new HashSet<MCPlayer>());
        }
    }
    // Plethora of fake data
    when(p.getCompassTarget()).thenReturn(fakeLocation);
    when(p.getItemAt((Integer) Mockito.any())).thenReturn(fakeItemStack);
    return p;
}
Also used : BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) MCLocation(com.laytonsmith.abstraction.MCLocation) MCItemStack(com.laytonsmith.abstraction.MCItemStack) MCPlayer(com.laytonsmith.abstraction.MCPlayer) MCWorld(com.laytonsmith.abstraction.MCWorld) BukkitMCWorld(com.laytonsmith.abstraction.bukkit.BukkitMCWorld)

Example 5 with MCWorld

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

the class RandomTests method testStaticGetLocation.

/*@Test*/
public void testStaticGetLocation() {
    MCWorld fakeWorld = mock(MCWorld.class);
    MCServer fakeServer = mock(MCServer.class);
    when(fakeServer.getWorld("world")).thenReturn(fakeWorld);
    CommandHelperPlugin.myServer = fakeServer;
    CArray ca1 = new CArray(Target.UNKNOWN, C.onstruct(1), C.onstruct(2), C.onstruct(3));
    CArray ca2 = new CArray(Target.UNKNOWN, C.onstruct(1), C.onstruct(2), C.onstruct(3), C.onstruct("world"));
    CArray ca3 = new CArray(Target.UNKNOWN, C.onstruct(1), C.onstruct(2), C.onstruct(3), C.onstruct(45), C.onstruct(50));
    CArray ca4 = new CArray(Target.UNKNOWN, C.onstruct(1), C.onstruct(2), C.onstruct(3), C.onstruct("world"), C.onstruct(45), C.onstruct(50));
    MCLocation l1 = ObjectGenerator.GetGenerator().location(ca1, fakeWorld, Target.UNKNOWN);
    MCLocation l2 = ObjectGenerator.GetGenerator().location(ca2, fakeWorld, Target.UNKNOWN);
    MCLocation l3 = ObjectGenerator.GetGenerator().location(ca3, fakeWorld, Target.UNKNOWN);
    MCLocation l4 = ObjectGenerator.GetGenerator().location(ca4, fakeWorld, Target.UNKNOWN);
    assertEquals(fakeWorld, l1.getWorld());
    assertEquals(fakeWorld, l2.getWorld());
    assertEquals(fakeWorld, l3.getWorld());
    assertEquals(fakeWorld, l4.getWorld());
    assertEquals(1, l1.getX(), 0.00000000000000001);
    assertEquals(1, l2.getX(), 0.00000000000000001);
    assertEquals(1, l4.getX(), 0.00000000000000001);
    assertEquals(1, l4.getX(), 0.00000000000000001);
    assertEquals(2, l1.getY(), 0.00000000000000001);
    assertEquals(2, l2.getY(), 0.00000000000000001);
    assertEquals(2, l3.getY(), 0.00000000000000001);
    assertEquals(2, l4.getY(), 0.00000000000000001);
    assertEquals(3, l1.getZ(), 0.00000000000000001);
    assertEquals(3, l2.getZ(), 0.00000000000000001);
    assertEquals(3, l3.getZ(), 0.00000000000000001);
    assertEquals(3, l4.getZ(), 0.00000000000000001);
    assertEquals(0, l1.getYaw(), 0.0000000000000000001);
    assertEquals(0, l2.getYaw(), 0.0000000000000000001);
    assertEquals(45, l3.getYaw(), 0.0000000000000000001);
    assertEquals(45, l4.getYaw(), 0.0000000000000000001);
    assertEquals(0, l1.getPitch(), 0.0000000000000000001);
    assertEquals(0, l2.getPitch(), 0.0000000000000000001);
    assertEquals(50, l3.getPitch(), 0.0000000000000000001);
    assertEquals(50, l4.getPitch(), 0.0000000000000000001);
    CommandHelperPlugin.myServer = null;
}
Also used : MCLocation(com.laytonsmith.abstraction.MCLocation) CArray(com.laytonsmith.core.constructs.CArray) MCServer(com.laytonsmith.abstraction.MCServer) MCWorld(com.laytonsmith.abstraction.MCWorld)

Aggregations

MCWorld (com.laytonsmith.abstraction.MCWorld)6 MCLocation (com.laytonsmith.abstraction.MCLocation)4 BukkitMCWorld (com.laytonsmith.abstraction.bukkit.BukkitMCWorld)3 CArray (com.laytonsmith.core.constructs.CArray)2 MCItemStack (com.laytonsmith.abstraction.MCItemStack)1 MCPlayer (com.laytonsmith.abstraction.MCPlayer)1 MCServer (com.laytonsmith.abstraction.MCServer)1 MCBlock (com.laytonsmith.abstraction.blocks.MCBlock)1 BukkitMCLocation (com.laytonsmith.abstraction.bukkit.BukkitMCLocation)1 CommandHelperEnvironment (com.laytonsmith.core.environments.CommandHelperEnvironment)1 CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)1 CREInvalidWorldException (com.laytonsmith.core.exceptions.CRE.CREInvalidWorldException)1 StaticTest (com.laytonsmith.testing.StaticTest)1 Before (org.junit.Before)1 Test (org.junit.Test)1