下面列出了怎么用org.bukkit.TravelAgent的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void shouldTeleportBecauseNotItem() {
// given
Pig entity = mock(Pig.class);
World world = mock(World.class);
Location from = new Location(world, 1, 2, 3);
World worldNether = mock(World.class);
Location to = new Location(worldNether, 1, 2, 3);
EntityPortalEvent event = new EntityPortalEvent(entity, from, to, mock(TravelAgent.class));
// when
listener.onEntityPortalTeleport(event);
// then
assertThat(event.isCancelled(), equalTo(false));
}
@Test
public void shouldTeleportBecauseSameGroup() {
// given
Group group = mockGroup("test_group", GameMode.SURVIVAL, false);
Item entity = mock(Item.class);
World world = mock(World.class);
given(world.getName()).willReturn("test_group");
Location from = new Location(world, 1, 2, 3);
World worldNether = mock(World.class);
given(worldNether.getName()).willReturn("test_group_nether");
Location to = new Location(worldNether, 1, 2, 3);
given(groupManager.getGroupFromWorld("test_group")).willReturn(group);
given(groupManager.getGroupFromWorld("test_group_nether")).willReturn(group);
EntityPortalEvent event = new EntityPortalEvent(entity, from, to, mock(TravelAgent.class));
// when
listener.onEntityPortalTeleport(event);
// then
assertThat(event.isCancelled(), equalTo(false));
}
@Test
public void shouldTeleportBecauseNotItem() {
// given
Pig entity = mock(Pig.class);
World world = mock(World.class);
Location from = new Location(world, 1, 2, 3);
World worldNether = mock(World.class);
Location to = new Location(worldNether, 1, 2, 3);
EntityPortalEvent event = new EntityPortalEvent(entity, from, to, mock(TravelAgent.class));
// when
listener.onEntityPortalTeleport(event);
// then
assertThat(event.isCancelled(), equalTo(false));
}
@Test
public void shouldTeleportBecauseSameGroup() {
// given
Group group = mockGroup("test_group", GameMode.SURVIVAL, false);
Item entity = mock(Item.class);
World world = mock(World.class);
given(world.getName()).willReturn("test_group");
Location from = new Location(world, 1, 2, 3);
World worldNether = mock(World.class);
given(worldNether.getName()).willReturn("test_group_nether");
Location to = new Location(worldNether, 1, 2, 3);
given(groupManager.getGroupFromWorld("test_group")).willReturn(group);
given(groupManager.getGroupFromWorld("test_group_nether")).willReturn(group);
EntityPortalEvent event = new EntityPortalEvent(entity, from, to, mock(TravelAgent.class));
// when
listener.onEntityPortalTeleport(event);
// then
assertThat(event.isCancelled(), equalTo(false));
}
@Test
public void shouldNotTeleportBecauseDifferentGroups() {
// given
Group group = mockGroup("test_group", GameMode.SURVIVAL, false);
Group otherGroup = mockGroup("other_group", GameMode.SURVIVAL, false);
Item entity = mock(Item.class);
World world = mock(World.class);
given(world.getName()).willReturn("test_group");
Location from = new Location(world, 1, 2, 3);
World worldNether = mock(World.class);
given(worldNether.getName()).willReturn("other_group_nether");
Location to = new Location(worldNether, 1, 2, 3);
given(groupManager.getGroupFromWorld("test_group")).willReturn(group);
given(groupManager.getGroupFromWorld("other_group_nether")).willReturn(otherGroup);
EntityPortalEvent event = new EntityPortalEvent(entity, from, to, mock(TravelAgent.class));
// when
listener.onEntityPortalTeleport(event);
// then
assertThat(event.isCancelled(), equalTo(true));
}
@Test
public void shouldNotTeleportBecauseDifferentGroups() {
// given
Group group = mockGroup("test_group", GameMode.SURVIVAL, false);
Group otherGroup = mockGroup("other_group", GameMode.SURVIVAL, false);
Item entity = mock(Item.class);
World world = mock(World.class);
given(world.getName()).willReturn("test_group");
Location from = new Location(world, 1, 2, 3);
World worldNether = mock(World.class);
given(worldNether.getName()).willReturn("other_group_nether");
Location to = new Location(worldNether, 1, 2, 3);
given(groupManager.getGroupFromWorld("test_group")).willReturn(group);
given(groupManager.getGroupFromWorld("other_group_nether")).willReturn(otherGroup);
EntityPortalEvent event = new EntityPortalEvent(entity, from, to, mock(TravelAgent.class));
// when
listener.onEntityPortalTeleport(event);
// then
assertThat(event.isCancelled(), equalTo(true));
}
public EntityPortalEvent(final Entity entity, final Location from, final Location to, final TravelAgent pta) {
super(entity, from, to);
this.travelAgent = pta;
}
public PlayerPortalEvent(final Player player, final Location from, final Location to, final TravelAgent pta) {
super(player, from, to);
this.travelAgent = pta;
}
public PlayerPortalEvent(Player player, Location from, Location to, TravelAgent pta, TeleportCause cause) {
super(player, from, to, cause);
this.travelAgent = pta;
}
@Override
public TravelAgent setSearchRadius(int radius) {
this.searchRadius = radius;
return this;
}
@Override
public TravelAgent setCreationRadius(int radius) {
this.creationRadius = radius < 2 ? 0 : radius;
return this;
}
public TravelAgent setSearchRadius(int radius) {
this.searchRadius = radius;
return this;
}
public TravelAgent setCreationRadius(int radius) {
this.creationRadius = radius < 2 ? 0 : radius;
return this;
}
/**
* Gets the Travel Agent used (or not) in this event.
*
* @return the Travel Agent used (or not) in this event
*/
public TravelAgent getPortalTravelAgent() {
return this.travelAgent;
}
/**
* Sets the Travel Agent used (or not) in this event.
*
* @param travelAgent the Travel Agent used (or not) in this event
*/
public void setPortalTravelAgent(TravelAgent travelAgent) {
this.travelAgent = travelAgent;
}
/**
* Gets the Travel Agent used (or not) in this event.
*
* @return the Travel Agent used (or not) in this event
*/
public TravelAgent getPortalTravelAgent() {
return this.travelAgent;
}
/**
* Sets the Travel Agent used (or not) in this event.
*
* @param travelAgent the Travel Agent used (or not) in this event
*/
public void setPortalTravelAgent(TravelAgent travelAgent) {
this.travelAgent = travelAgent;
}