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);
}
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);
}
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));
}
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());
}
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);
}
Aggregations