org.bukkit.event.entity.EntityPortalEvent Java Examples

The following examples show how to use org.bukkit.event.entity.EntityPortalEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityPortalEventListener.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityPortalTeleport(EntityPortalEvent event) {
    if (!(event.getEntity() instanceof Item))
        return;

    ConsoleLogger.debug("[ENTITYPORTALEVENT] A '" + event.getEntity().getName() + "' is going through a portal!");

    String worldFrom = event.getFrom().getWorld().getName();

    // For some reason, event.getTo().getWorld().getName() is sometimes null
    if (event.getTo() == null || event.getTo().getWorld() == null) { // Not gonna bother checking name; its already a WTF that this is needed
        ConsoleLogger.debug("[ENTITYPORTALEVENT] event.getTo().getWorld().getName() would throw a NPE! Exiting method!");
        return;
    }

    String worldTo = event.getTo().getWorld().getName();
    Group from = groupManager.getGroupFromWorld(worldFrom);
    Group to = groupManager.getGroupFromWorld(worldTo);

    // If the groups are different, cancel the event
    if (!from.equals(to)) {
        ConsoleLogger.debug("[ENTITYPORTALEVENT] Group '" + from.getName() + "' and group '" + to.getName() + "' are different! Canceling event!");
        event.setCancelled(true);
    }
}
 
Example #2
Source File: EntityPortalEventListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@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));
}
 
Example #3
Source File: EntityPortalEventListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@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));
}
 
Example #4
Source File: EntityPortalEventListener.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityPortalTeleport(EntityPortalEvent event) {
    if (!(event.getEntity() instanceof Item))
        return;

    ConsoleLogger.debug("[ENTITYPORTALEVENT] A '" + event.getEntity().getName() + "' is going through a portal!");

    String worldFrom = event.getFrom().getWorld().getName();

    // For some reason, event.getTo().getWorld().getName() is sometimes null
    if (event.getTo() == null || event.getTo().getWorld() == null) { // Not gonna bother checking name; its already a WTF that this is needed
        ConsoleLogger.debug("[ENTITYPORTALEVENT] event.getTo().getWorld().getName() would throw a NPE! Exiting method!");
        return;
    }

    String worldTo = event.getTo().getWorld().getName();
    Group from = groupManager.getGroupFromWorld(worldFrom);
    Group to = groupManager.getGroupFromWorld(worldTo);

    // If the groups are different, cancel the event
    if (!from.equals(to)) {
        ConsoleLogger.debug("[ENTITYPORTALEVENT] Group '" + from.getName() + "' and group '" + to.getName() + "' are different! Canceling event!");
        event.setCancelled(true);
    }
}
 
Example #5
Source File: EntityPortalEventListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@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));
}
 
Example #6
Source File: EntityPortalEventListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@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));
}
 
Example #7
Source File: EntityPortalEventListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
@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));
}
 
Example #8
Source File: EndModule.java    From UHC with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void on(EntityPortalEvent event) {
    if (isEnabled()) return;
    if (event.getTo() == null) return;

    if (event.getTo().getWorld().getEnvironment() == World.Environment.THE_END) {
        event.setCancelled(true);
    }
}
 
Example #9
Source File: NetherModule.java    From UHC with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void on(EntityPortalEvent event) {
    if (isEnabled()) return;
    if (event.getTo() == null) return;

    if (event.getTo().getWorld().getEnvironment() == World.Environment.NETHER) {
        event.setCancelled(true);
    }
}
 
Example #10
Source File: EntityPortalEventListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
@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));
}
 
Example #11
Source File: NetherPortals.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This handles non-player portal use
 * Currently disables portal use by entities
 * 
 * @param event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityPortal(final EntityPortalEvent event) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: nether portal entity " + event.getFrom().getBlock().getType());
    // If the nether is disabled then quit immediately
    if (!Settings.createNether || ASkyBlock.getNetherWorld() == null) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Disabled nether: Settings create nether = " + Settings.createNether + " " + (ASkyBlock.getNetherWorld() == null ? "Nether world is null": "Nether world is not null"));
        return;
    }
    // Disable entity portal transfer due to dupe glitching
    event.setCancelled(true);
}
 
Example #12
Source File: EffectEventHandlers.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void portalPickupSafeguard(EntityPortalEvent event) {
    if (EntityTracker.isItemVisualEffect(event.getEntity()) || EntityTracker.isEliteMob(event.getEntity()))
        event.setCancelled(true);
}
 
Example #13
Source File: LivingEntityShopListener.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onEntityPortalTeleport(EntityPortalEvent event) {
	if (plugin.isShopkeeper(event.getEntity())) {
		event.setCancelled(true);
	}
}