类org.bukkit.TravelAgent源码实例Demo

下面列出了怎么用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));
}
 
源代码7 项目: Kettle   文件: EntityPortalEvent.java
public EntityPortalEvent(final Entity entity, final Location from, final Location to, final TravelAgent pta) {
    super(entity, from, to);
    this.travelAgent = pta;
}
 
源代码8 项目: Kettle   文件: PlayerPortalEvent.java
public PlayerPortalEvent(final Player player, final Location from, final Location to, final TravelAgent pta) {
    super(player, from, to);
    this.travelAgent = pta;
}
 
源代码9 项目: Kettle   文件: PlayerPortalEvent.java
public PlayerPortalEvent(Player player, Location from, Location to, TravelAgent pta, TeleportCause cause) {
    super(player, from, to, cause);
    this.travelAgent = pta;
}
 
源代码10 项目: Kettle   文件: CraftTravelAgent.java
@Override
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
 
源代码11 项目: Kettle   文件: CraftTravelAgent.java
@Override
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
 
源代码12 项目: Thermos   文件: CraftTravelAgent.java
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
 
源代码13 项目: Thermos   文件: CraftTravelAgent.java
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
 
源代码14 项目: Kettle   文件: EntityPortalEvent.java
/**
 * 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;
}
 
源代码15 项目: Kettle   文件: EntityPortalEvent.java
/**
 * 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;
}
 
源代码16 项目: Kettle   文件: PlayerPortalEvent.java
/**
 * 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;
}
 
源代码17 项目: Kettle   文件: PlayerPortalEvent.java
/**
 * 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;
}
 
 类所在包
 同包方法