Search in sources :

Example 1 with PlayerMoveEvent

use of org.bukkit.event.player.PlayerMoveEvent in project AuthMeReloaded by AuthMe.

the class PlayerListenerTest method shouldAllowUnlimitedMovement.

@Test
public void shouldAllowUnlimitedMovement() {
    // given
    given(settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)).willReturn(true);
    given(settings.getProperty(RestrictionSettings.ALLOWED_MOVEMENT_RADIUS)).willReturn(0);
    Player player = mock(Player.class);
    Location location = mock(Location.class);
    PlayerMoveEvent event = spy(new PlayerMoveEvent(player, location, location));
    // when
    listener.onPlayerMove(event);
    // then
    verifyZeroInteractions(event);
}
Also used : Player(org.bukkit.entity.Player) PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) Location(org.bukkit.Location) Test(org.junit.Test)

Example 2 with PlayerMoveEvent

use of org.bukkit.event.player.PlayerMoveEvent in project AuthMeReloaded by AuthMe.

the class PlayerListenerTest method shouldAllowMovementForAuthedPlayer.

@Test
public void shouldAllowMovementForAuthedPlayer() {
    // given
    given(settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)).willReturn(false);
    Player player = mock(Player.class);
    Location from = new Location(null, 100, 90, 200);
    Location to = new Location(null, 99, 90, 200);
    PlayerMoveEvent event = spy(new PlayerMoveEvent(player, from, to));
    given(listenerService.shouldCancelEvent(player)).willReturn(false);
    // when
    listener.onPlayerMove(event);
    // then
    verify(listenerService).shouldCancelEvent(player);
    verifyNoModifyingCalls(event);
}
Also used : Player(org.bukkit.entity.Player) PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) Location(org.bukkit.Location) Test(org.junit.Test)

Example 3 with PlayerMoveEvent

use of org.bukkit.event.player.PlayerMoveEvent in project Bukkit by Bukkit.

the class TimedRegisteredListenerTest method testEventClass.

@Test
public void testEventClass() throws EventException {
    Listener listener = new Listener() {
    };
    EventExecutor executor = new EventExecutor() {

        public void execute(Listener listener, Event event) {
        }
    };
    TestPlugin plugin = new TestPlugin("Test");
    PlayerInteractEvent interactEvent = new PlayerInteractEvent(null, null, null, null, null);
    PlayerMoveEvent moveEvent = new PlayerMoveEvent(null, null, null);
    BlockBreakEvent breakEvent = new BlockBreakEvent(null, null);
    TimedRegisteredListener trl = new TimedRegisteredListener(listener, executor, EventPriority.NORMAL, plugin, false);
    // Ensure that the correct event type is reported for a single event
    trl.callEvent(interactEvent);
    assertThat(trl.getEventClass(), is((Object) PlayerInteractEvent.class));
    // Ensure that no superclass is used in lieu of the actual event, after two identical event types
    trl.callEvent(interactEvent);
    assertThat(trl.getEventClass(), is((Object) PlayerInteractEvent.class));
    // Ensure that the closest superclass of the two events is chosen
    trl.callEvent(moveEvent);
    assertThat(trl.getEventClass(), is((Object) PlayerEvent.class));
    // As above, so below
    trl.callEvent(breakEvent);
    assertThat(trl.getEventClass(), is((Object) Event.class));
    // In the name of being thorough, check that it never travels down the hierarchy again.
    trl.callEvent(breakEvent);
    assertThat(trl.getEventClass(), is((Object) Event.class));
    trl = new TimedRegisteredListener(listener, executor, EventPriority.NORMAL, plugin, false);
    trl.callEvent(breakEvent);
    assertThat(trl.getEventClass(), is((Object) BlockBreakEvent.class));
    // Test moving up the class hierarchy by more than one class at a time
    trl.callEvent(moveEvent);
    assertThat(trl.getEventClass(), is((Object) Event.class));
}
Also used : Listener(org.bukkit.event.Listener) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) Event(org.bukkit.event.Event) PlayerEvent(org.bukkit.event.player.PlayerEvent) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) Test(org.junit.Test)

Example 4 with PlayerMoveEvent

use of org.bukkit.event.player.PlayerMoveEvent in project Denizen-For-Bukkit by DenizenScript.

the class PlayerStepsOnScriptEvent method onPlayerTeleport.

@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
    if (dEntity.isNPC(event.getPlayer())) {
        return;
    }
    PlayerMoveEvent evt = new PlayerMoveEvent(event.getPlayer(), event.getFrom(), event.getTo());
    onPlayerStepsOn(evt);
    event.setCancelled(evt.isCancelled());
}
Also used : PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) EventHandler(org.bukkit.event.EventHandler)

Example 5 with PlayerMoveEvent

use of org.bukkit.event.player.PlayerMoveEvent in project AuthMeReloaded by AuthMe.

the class PlayerListenerTest method shouldRejectMovementOutsideOfRadius.

@Test
public void shouldRejectMovementOutsideOfRadius() {
    // given
    given(settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)).willReturn(true);
    given(settings.getProperty(RestrictionSettings.ALLOWED_MOVEMENT_RADIUS)).willReturn(12);
    World world = mock(World.class);
    Player player = mock(Player.class);
    given(player.getWorld()).willReturn(world);
    Location from = new Location(world, 200, 70, 200);
    Location to = new Location(world, 199, 69, 201);
    PlayerMoveEvent event = spy(new PlayerMoveEvent(player, from, to));
    given(player.getLocation()).willReturn(from);
    given(listenerService.shouldCancelEvent(player)).willReturn(true);
    given(settings.getProperty(RestrictionSettings.NO_TELEPORT)).willReturn(false);
    // sqrt(15^2 + 2^2 + 4^2) = 16 > 12 (allowed movement radius)
    Location spawn = new Location(world, 185, 72, 204);
    given(spawnLoader.getSpawnLocation(player)).willReturn(spawn);
    // when
    listener.onPlayerMove(event);
    // then
    verify(listenerService).shouldCancelEvent(player);
    verify(player).teleport(spawn);
    verify(spawnLoader).getSpawnLocation(player);
    verifyNoModifyingCalls(event);
}
Also used : Player(org.bukkit.entity.Player) PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) World(org.bukkit.World) Location(org.bukkit.Location) Test(org.junit.Test)

Aggregations

PlayerMoveEvent (org.bukkit.event.player.PlayerMoveEvent)10 Location (org.bukkit.Location)8 Test (org.junit.Test)8 Player (org.bukkit.entity.Player)7 World (org.bukkit.World)4 GlowPlayer (net.glowstone.entity.GlowPlayer)1 PositionRotationMessage (net.glowstone.net.message.play.game.PositionRotationMessage)1 Event (org.bukkit.event.Event)1 EventHandler (org.bukkit.event.EventHandler)1 Listener (org.bukkit.event.Listener)1 BlockBreakEvent (org.bukkit.event.block.BlockBreakEvent)1 PlayerEvent (org.bukkit.event.player.PlayerEvent)1 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1 Vector (org.bukkit.util.Vector)1