Search in sources :

Example 1 with GlowBoat

use of net.glowstone.entity.objects.GlowBoat in project Glowstone by GlowstoneMC.

the class SteerBoatHandler method handle.

@Override
public void handle(GlowSession session, SteerBoatMessage message) {
    GlowPlayer player = session.getPlayer();
    if (!player.isInsideVehicle()) {
        return;
    }
    if (!(player.getVehicle() instanceof GlowBoat)) {
        return;
    }
    GlowBoat boat = (GlowBoat) player.getVehicle();
    boat.setRightPaddleTurning(message.isRightPaddleTurning());
    boat.setLeftPaddleTurning(message.isLeftPaddleTurning());
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) GlowBoat(net.glowstone.entity.objects.GlowBoat)

Example 2 with GlowBoat

use of net.glowstone.entity.objects.GlowBoat in project Glowstone by GlowstoneMC.

the class UseItemHandlerTest method testRightClickAir.

@Test
public void testRightClickAir() {
    // prepare objects under test
    Location location = new Location(world, 1.0, 1.0, 1.0);
    Location playerLocation = new Location(world, 2.0, 2.0, 2.0);
    GlowPlayerInventory inventory = new GlowPlayerInventory(player);
    ItemStack stack = new ItemStack(Material.JUNGLE_BOAT);
    GlowBoat boat = new GlowBoat(location);
    inventory.setItemInMainHand(stack);
    UseItemMessage message = new UseItemMessage(EquipmentSlot.HAND.ordinal());
    PlayerInteractEvent event = new PlayerInteractEvent(player, Action.RIGHT_CLICK_AIR, stack, null, null);
    // prepare mock behaviours
    Mockito.when(session.getPlayer()).thenReturn(player);
    Mockito.when(player.getInventory()).thenReturn(inventory);
    Mockito.when(player.getLocation()).thenReturn(playerLocation);
    Mockito.when(player.getTargetBlock((Set<Material>) null, 5)).thenReturn(targetBlock);
    Mockito.when(player.getGameMode()).thenReturn(GameMode.SURVIVAL);
    Mockito.when(eventFactory.onPlayerInteract(player, Action.RIGHT_CLICK_AIR, EquipmentSlot.HAND)).thenReturn(event);
    Mockito.when(emptyBlock.isEmpty()).thenReturn(Boolean.TRUE);
    Mockito.when(emptyBlock.getLocation()).thenReturn(location);
    Mockito.when(targetBlock.isEmpty()).thenReturn(Boolean.FALSE);
    Mockito.when(targetBlock.getRelative(BlockFace.UP)).thenReturn(emptyBlock);
    Mockito.when(targetBlock.getWorld()).thenReturn(world);
    Mockito.when(world.spawn(location, Boat.class)).thenReturn(boat);
    // run test
    Assert.assertTrue(inventory.contains(Material.JUNGLE_BOAT, 1));
    UseItemHandler handler = new UseItemHandler();
    handler.handle(session, message);
    // after calling use item and creating a boat, the inventory no longer contains a boat
    Assert.assertFalse(inventory.contains(Material.JUNGLE_BOAT, 1));
}
Also used : GlowBoat(net.glowstone.entity.objects.GlowBoat) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) UseItemMessage(net.glowstone.net.message.play.player.UseItemMessage) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) GlowPlayerInventory(net.glowstone.inventory.GlowPlayerInventory) Test(org.junit.Test)

Aggregations

GlowBoat (net.glowstone.entity.objects.GlowBoat)2 GlowPlayer (net.glowstone.entity.GlowPlayer)1 GlowPlayerInventory (net.glowstone.inventory.GlowPlayerInventory)1 UseItemMessage (net.glowstone.net.message.play.player.UseItemMessage)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1 Test (org.junit.Test)1