Java 类org.bukkit.event.entity.EntityPortalEvent 实例源码
项目:NeverLag
文件:ThroughPortalDisabler.java
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityPortal(EntityPortalEvent e) {
if (!cm.portalDisallowEnabled) {
return;
}
Entity entity = e.getEntity();
if (entity == null || NeverLagUtils.checkCustomNpc(entity)) {
return;
}
if ((entity instanceof Monster && cm.portalDisallowMonster)
|| (entity instanceof Animals && cm.portalDisallowAnimals)
|| (entity instanceof Item && cm.portalDisallowItem)
|| (entity instanceof Projectile && cm.portalDisallowProjectile)) {
e.setCancelled(true);
}
}
项目:PerWorldInventory
文件:EntityPortalEventListener.java
@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);
}
}
项目:PerWorldInventory
文件:EntityPortalEventListenerTest.java
@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));
}
项目:PerWorldInventory
文件:EntityPortalEventListenerTest.java
@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));
}
项目:Peacecraft
文件:PortalListener.java
@EventHandler
public void onEntityPortal(EntityPortalEvent event) {
Location portalLoc = null;
for(BlockFace face : BlockFace.values()) {
Block block = event.getFrom().getBlock().getRelative(face);
if(block.getType() == Material.PORTAL || block.getType() == Material.ENDER_PORTAL) {
portalLoc = block.getLocation();
}
}
if(portalLoc != null) {
String portal = this.module.getPortalManager().getPortal(portalLoc);
if(portal != null) {
event.setCancelled(true);
if(!(event.getEntity() instanceof Player)) {
String destPortal = this.module.getPortalManager().getDestPortal(portal);
if(destPortal != null && this.module.getPortalManager().isPortal(destPortal)) {
Location dest = this.module.getPortalManager().getPortalPoint(destPortal);
event.getEntity().teleport(dest);
}
}
}
}
}
项目:askygrid
文件:NetherPortals.java
/**
* This handles non-player portal use
* Currently disables portal use by entities
*
* @param event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
public void onEntityPortal(EntityPortalEvent event) {
// If the nether is disabled then quit immediately
if (!Settings.createNether) {
return;
}
if (event.getEntity() == null) {
return;
}
// If this is not ASkyGrid then return
if (!event.getFrom().getWorld().equals(ASkyGrid.getGridWorld()) && !event.getFrom().getWorld().equals(ASkyGrid.getNetherWorld())) {
return;
}
// Entities don't go through sky grid portals, sorry.
event.setCancelled(true);
}
项目:PerWorldInventory
文件:EntityPortalEventListener.java
@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);
}
}
项目:PerWorldInventory
文件:EntityPortalEventListenerTest.java
@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));
}
项目:PerWorldInventory
文件:EntityPortalEventListenerTest.java
@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));
}
项目:NPlugins
文件:ItemListener.java
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onItemPortal(final EntityPortalEvent event) {
this.plugin.entering(this.getClass(), "onItemPortal");
final Location loc = event.getEntity().getLocation();
final Altar altar = this.plugin.getAltars().get(new ChunkCoord(loc.getChunk()));
if (altar != null && altar.getState() == AltarState.EGG_PROVIDED && event.getEntity().isValid()) {
this.plugin.debug("Teleportation caused by an Altar.");
if (event.getEntityType() == EntityType.DROPPED_ITEM) {
this.plugin.debug("Teleporting entity is a Dropped Item, handling it...");
altar.getBuilder().addItem(((Item)event.getEntity()).getItemStack());
event.getEntity().remove();
this.plugin.debug("Entity handled by an Altar. Location=" + altar.getCenterLocation());
}
this.plugin.debug("Entity not an item, not handled");
event.setCancelled(true);
} else {
this.plugin.debug("Entity not handled");
}
this.plugin.exiting(this.getClass(), "onItemPortal");
}
项目:EscapeLag
文件:AntiPortalInfItem.java
@EventHandler
public void PortalCheck(EntityPortalEvent event) {
if (ConfigPatch.fixPortalInfItem) {
if (event.getEntityType() == EntityType.MINECART_CHEST || event.getEntityType() == EntityType.MINECART_FURNACE || event.getEntityType() == EntityType.MINECART_HOPPER) {
event.setCancelled(true);
event.getEntity().remove();
AzureAPI.bc(ConfigPatch.AntiPortalInfItemWarnMessage);
}
}
}
项目:NeverLag
文件:AntiMinecartPortal.java
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityPortal(EntityPortalEvent e) {
if (!cm.isAntiMinecartPortal) {
return;
}
if (e.getEntity() instanceof Minecart) {
e.setCancelled(true);
}
}
项目:MundoSK
文件:ExprNewPortal.java
@Override
protected Location[] get(Event event) {
if (event instanceof PlayerPortalEvent) {
return new Location[]{createPortal(targetLoc.getSingle(event), radius.getSingle(event).intValue(), ((PlayerPortalEvent) event).getPortalTravelAgent())};
} else if (event instanceof EntityPortalEvent) {
return new Location[]{createPortal(targetLoc.getSingle(event), radius.getSingle(event).intValue(), ((EntityPortalEvent) event).getPortalTravelAgent())};
}
throw new IllegalArgumentException("The event " + event + " should be a PlayerPortalEvent or EntityPortalEvent");
}
项目:MundoSK
文件:ExprNewPortal.java
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
if (!ScriptLoader.isCurrentEvent(PlayerPortalEvent.class, EntityPortalEvent.class)) {
Skript.error("'new nether portal' can only be used in an 'on teleport' event!");
return false;
}
radius = (Expression<Number>) expressions[0];
targetLoc = (Expression<Location>) expressions[1];
return false;
}
项目:Arcade2
文件:GeneralListeners.java
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPortalUse(EntityPortalEvent event) {
event.setCancelled(true);
Entity creator = event.getEntity();
if (creator instanceof Player) {
creator.sendMessage(String.format(PORTAL_MESSAGE, "use"));
}
}
项目:PerWorldInventory
文件:EntityPortalEventListenerTest.java
@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));
}
项目:AncientGates
文件:TeleportUtil.java
public static void teleportEntity(final EntityPortalEvent event, final Location location) {
checkChunkLoad(location.getBlock());
final Entity entity = event.getEntity();
if (entity.getType().isSpawnable() && !EntityUtil.isEchoPet(entity)) {
entity.teleport(location);
} else if (entity.getType() == EntityType.DROPPED_ITEM) {
entity.remove();
location.getWorld().dropItemNaturally(location, ((Item) entity).getItemStack());
}
}
项目:AncientGates
文件:PluginEntityListener.java
@EventHandler
public void onEntityPortal(final EntityPortalEvent event) {
if (event.isCancelled()) {
return;
}
if (!(event.getEntity() instanceof Player) && !(event.getEntity().getPassenger() instanceof Player)) {
// Ok so an entity portal event begins
// Find the nearest gate!
final WorldCoord entityCoord = new WorldCoord(event.getEntity().getLocation());
final Gate nearestGate = GateUtil.nearestGate(entityCoord, true);
if (nearestGate != null) {
event.setCancelled(true);
/*
* Teleport non-living vehicles - Only when useVanillaPortals is enabled Boolean
* Expression: Rtrn = VanilFlag' InstVeh InstLiv';
*/
if (!Conf.useVanillaPortals && event.getEntity() instanceof Vehicle && !(event.getEntity() instanceof LivingEntity)) {
return;
}
/*
* Teleport entities (incl. living vehicles) - If they're allowed Teleport
* non-living vehicles if they're allowed Boolean Expression: Tele = EntFlag
* InstVeh' + EntFlag InstLiv + VehFlag InstVeh InstLiv';
*/
if (nearestGate.getTeleportEntities() && !(event.getEntity() instanceof Vehicle) || nearestGate.getTeleportEntities() && event.getEntity() instanceof LivingEntity
|| nearestGate.getTeleportVehicles() && event.getEntity() instanceof Vehicle && !(event.getEntity() instanceof LivingEntity)) {
if (nearestGate.getBungeeTo() == null) {
TeleportUtil.teleportEntity(event, nearestGate.getTo());
} else {
TeleportUtil.teleportEntity(event, nearestGate.getBungeeTo());
}
}
}
}
}
项目:Peacecraft
文件:PortalListener.java
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerPortal(PlayerPortalEvent event) {
EntityPortalEvent e = new EntityPortalEvent(event.getPlayer(), event.getFrom(), event.getTo(), event.getPortalTravelAgent());
this.onEntityPortal(e);
event.setFrom(e.getFrom());
event.setTo(e.getTo());
event.setPortalTravelAgent(e.getPortalTravelAgent());
event.useTravelAgent(e.useTravelAgent());
}
项目:Peacecraft
文件:WorldListener.java
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerPortal(PlayerPortalEvent event) {
EntityPortalEvent e = new EntityPortalEvent(event.getPlayer(), event.getFrom(), event.getTo(), event.getPortalTravelAgent());
this.onEntityPortal(e);
event.setFrom(e.getFrom());
event.setTo(e.getTo());
event.setPortalTravelAgent(e.getPortalTravelAgent());
event.useTravelAgent(e.useTravelAgent());
}
项目:PerWorldInventory
文件:EntityPortalEventListenerTest.java
@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));
}
项目:Cauldron
文件:Entity.java
public void travelToDimension(int p_71027_1_)
{
if (!this.worldObj.isRemote && !this.isDead)
{
this.worldObj.theProfiler.startSection("changeDimension");
MinecraftServer minecraftserver = MinecraftServer.getServer();
// CraftBukkit start - Move logic into new function "teleportToLocation"
// int j = this.dimension;
// Cauldron start - Allow Forge hotloading on teleport
WorldServer exitWorld = minecraftserver.worldServerForDimension(p_71027_1_);
Location enter = this.getBukkitEntity().getLocation();
Location exit = exitWorld != null ? minecraftserver.getConfigurationManager().calculateTarget(enter, minecraftserver.worldServerForDimension(p_71027_1_)) : null;
boolean useTravelAgent = exitWorld != null && !(this.dimension == 1 && exitWorld.dimension == 1); // don't use agent for custom worlds or return from THE_END
// Cauldron start - check if teleporter is instance of TravelAgent before attempting to cast to it
Teleporter teleporter = exit != null ? ((CraftWorld) exit.getWorld()).getHandle().getDefaultTeleporter() : null;
TravelAgent agent = (teleporter != null && teleporter instanceof TravelAgent) ? (TravelAgent)teleporter : org.bukkit.craftbukkit.CraftTravelAgent.DEFAULT; // return arbitrary TA to compensate for implementation dependent plugins
// Cauldron end
EntityPortalEvent event = new EntityPortalEvent(this.getBukkitEntity(), enter, exit, agent);
event.useTravelAgent(useTravelAgent);
event.getEntity().getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null || !this.isEntityAlive())
{
return;
}
exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(event.getTo()) : event.getTo();
this.teleportTo(exit, true);
}
}
项目:ultrahardcore
文件:NetherFeature.java
@EventHandler
public void onPortalEvent(EntityPortalEvent epe)
{
//if it's enabled
if(isEnabled() && epe.getEntity() instanceof Permissible) {
//if they're going into the nether cancel it
if(!((Permissible) epe.getEntity()).hasPermission(ALLOW_NETHER)) {
if(epe.getTo().getWorld().getEnvironment() == World.Environment.NETHER) {
epe.setCancelled(true);
}
}
}
}
项目:TradeCraft
文件:TradeCraftListener.java
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void EntityPortalEvent(EntityPortalEvent event)
{
if (event.getEntityType() == EntityType.VILLAGER)
{
final Entity villager = event.getEntity();
TradeCraftVillager tcv = Villagers.getVillager(villager.getUniqueId().toString());
if(tcv != null)
{
Logs.debug("Portal enter " + tcv.getUUID());
tcv.setPortaling(true);
}
}
}
项目:ProtectPlugin
文件:AntiCopyItem.java
@EventHandler
public void handle(EntityPortalEvent event) {
String type = event.getEntity().getType().name();
if (type.contains("MINECART")) {
event.setCancelled(true);
}
}
项目:xEssentials-deprecated-bukkit
文件:PortalEvent.java
@EventHandler
public void onEntityPortal(EntityPortalEvent e) {
if(e.isCancelled()) {
return;
}
e.setCancelled(true);
Block block = getPortalNearby(e.getEntity().getLocation().getBlock());
if(!(block instanceof Block)) {
return;
}
for(Portal portal : pl.getConfiguration().getPortalConfig().getPortals().values()) {
if(portal.getInnerBlocks().contains(block)) {
if(e.getEntity() instanceof Item) {
e.setCancelled(true);
return;
}
e.useTravelAgent(false);
if(portal.isLinked()) {
Portal linked = portal.getLinkedPortal();
if(!(linked instanceof Portal)) {
e.setCancelled(true);
return;
}
e.setTo(linked.getInnerBlocks().get(linked.getInnerBlocks().size()-1).getLocation());
e.setCancelled(false);
} else {
e.setCancelled(true);
}
break;
}
}
e.setCancelled(false);
}
项目:DiscoSheep
文件:PartyEvents.java
/**
* Prevent party members from going through portals (end, nether).
* @param e The portal event.
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityPortalEvent(EntityPortalEvent e) {
if (isFromParty(e.getEntity())) {
e.setCancelled(true);
}
}
项目:MausWasHere
文件:EntityListener.java
@EventHandler
public void onPortalTravel(EntityPortalEvent e)
{
if(!(e.getEntity() instanceof Player))
{
e.setCancelled(true);
e.getEntity().teleport(e.getEntity().getLocation().add(0,15,0));
}
}
项目:bskyblock
文件:NetherPortals.java
/**
* This handles non-player portal use
* Currently disables portal use by entities
*
* @param event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityPortal(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.netherGenerate || IslandWorld.getNetherWorld() == null) {
return;
}
if (event.getEntity() == null) {
return;
}
if (event.getFrom() != null && event.getFrom().getBlock().getType().equals(Material.ENDER_PORTAL)) {
event.setCancelled(true);
// Same action for all worlds except the end itself
if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) {
if (plugin.getServer().getWorld(Settings.worldName + "_the_end") != null) {
// The end exists
Location end_place = plugin.getServer().getWorld(Settings.worldName + "_the_end").getSpawnLocation();
event.getEntity().teleport(end_place);
if (DEBUG)
plugin.getLogger().info("DEBUG: Result teleported " + event.getEntityType() + " to " + end_place);
return;
}
}
return;
}
Location currentLocation = event.getFrom().clone();
String currentWorld = currentLocation.getWorld().getName();
// Only operate if this is Island territory
if (!currentWorld.equalsIgnoreCase(Settings.worldName) && !currentWorld.equalsIgnoreCase(Settings.worldName + "_nether")) {
return;
}
// No entities may pass with the old nether
if (!Settings.netherIslands) {
event.setCancelled(true);
return;
}
// New nether
// Entities can pass only if there are adjoining portals
Location dest = event.getFrom().toVector().toLocation(IslandWorld.getIslandWorld());
if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) {
dest = event.getFrom().toVector().toLocation(IslandWorld.getNetherWorld());
}
// Vehicles
if (event.getEntity() instanceof Vehicle) {
Vehicle vehicle = (Vehicle)event.getEntity();
vehicle.eject();
}
new SafeSpotTeleport(plugin, event.getEntity(), dest);
event.setCancelled(true);
}
项目:bskyblock
文件:NetherEvents.java
/**
* This handles non-player portal use
* Currently disables portal use by entities
*
* @param event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityPortal(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.netherGenerate || IslandWorld.getNetherWorld() == null) {
return;
}
if (event.getEntity() == null) {
return;
}
if (event.getFrom() != null && event.getFrom().getBlock().getType().equals(Material.ENDER_PORTAL)) {
event.setCancelled(true);
// Same action for all worlds except the end itself
if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) {
if (plugin.getServer().getWorld(Settings.worldName + "_the_end") != null) {
// The end exists
Location end_place = plugin.getServer().getWorld(Settings.worldName + "_the_end").getSpawnLocation();
event.getEntity().teleport(end_place);
if (DEBUG)
plugin.getLogger().info("DEBUG: Result teleported " + event.getEntityType() + " to " + end_place);
return;
}
}
return;
}
Location currentLocation = event.getFrom().clone();
String currentWorld = currentLocation.getWorld().getName();
// Only operate if this is Island territory
if (!currentWorld.equalsIgnoreCase(Settings.worldName) && !currentWorld.equalsIgnoreCase(Settings.worldName + "_nether")) {
return;
}
// No entities may pass with the old nether
if (!Settings.netherIslands) {
event.setCancelled(true);
return;
}
// New nether
// Entities can pass only if there are adjoining portals
Location dest = event.getFrom().toVector().toLocation(IslandWorld.getIslandWorld());
if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) {
dest = event.getFrom().toVector().toLocation(IslandWorld.getNetherWorld());
}
// Vehicles
if (event.getEntity() instanceof Vehicle) {
Vehicle vehicle = (Vehicle)event.getEntity();
vehicle.eject();
}
new SafeSpotTeleport(plugin, event.getEntity(), dest);
event.setCancelled(true);
}
项目:HCFCore
文件:PortalListener.java
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onEntityPortal(EntityPortalEvent event) {
if (event.getEntity() instanceof EnderDragon) {
event.setCancelled(true);
}
}
项目:HCFCore
文件:WorldListener.java
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onEntityPortalEnter(EntityPortalEvent event) {
if (event.getEntity() instanceof EnderDragon) {
event.setCancelled(true);
}
}
项目:HCFCore
文件:PortalListener.java
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onEntityPortal(EntityPortalEvent event) {
if (event.getEntity() instanceof EnderDragon) {
event.setCancelled(true);
}
}
项目:HCFCore
文件:WorldListener.java
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onEntityPortalEnter(EntityPortalEvent event) {
if (event.getEntity() instanceof EnderDragon) {
event.setCancelled(true);
}
}
项目:AncientGates
文件:TeleportUtil.java
public static void teleportEntity(final EntityPortalEvent event, final Map<String, String> location) {
if (Conf.bungeeCordSupport && (event.getEntityType().isSpawnable() && !EntityUtil.isEchoPet(event.getEntity()) || event.getEntityType() == EntityType.DROPPED_ITEM)) {
// Send spawn command packet via BungeeCord
if (!Conf.useSocketComms || Plugin.serv == null) {
// Send AGBungeeSpawn packet
final PluginMessage msg = new PluginMessage(event.getEntityType(), event.getEntity(), location);
// Send over the AGBungeeTele BungeeCord channel
if (Plugin.instance.getServer().getOnlinePlayers().size() > 0) {
// Use any player to send the plugin message
Iterables.getFirst(Bukkit.getOnlinePlayers(), null).sendPluginMessage(Plugin.instance, "BungeeCord", msg.toByteArray());
// Imitate teleport by removing entity
event.getEntity().remove();
}
// Send spawn command packet via client socket
} else if (!entityCache.asMap().containsKey(event.getEntity().getEntityId())) {
// Put entity in cache so we don't end up with duplicate entities
entityCache.put(event.getEntity().getEntityId(), event.getEntity());
// Get server
final Server server = Server.get(location.get(SERVER));
// Construct spawn entity packet
final Packet packet = new Packet(event.getEntity(), event.getEntityType(), location);
// Setup socket client and listener
final SocketClient client = new SocketClient(server.getAddress(), server.getPort(), server.getPassword());
client.setListener(new SocketClientEventListener() {
@Override
public void onServerMessageRecieve(final SocketClient client1, final Packets packets) {
for (final Packet packet1 : packets.packets) {
if (packet1.command.toLowerCase().equals("removeentity")) {
// Extract receiving packet arguments
final String world = String.valueOf(packet1.args[0]);
final int entityId = Integer.parseInt(packet1.args[1]);
// Iterate and remove teleported entity
final List<Entity> entities = Bukkit.getServer().getWorld(world).getEntities();
final Iterator<Entity> it = entities.iterator();
while (it.hasNext()) {
final Entity entity = it.next();
if (entity.getEntityId() == entityId) {
entityCache.invalidate(entityId);
entity.remove();
break;
}
}
}
}
client1.close();
}
@Override
public void onServerMessageError() {
}
});
// Connect and send packet
try {
client.connect();
client.send(packet);
} catch (final Exception e) {
Plugin.log(Level.SEVERE, "Error sending spawn packet to the server.");
}
}
}
}
项目:acidisland
文件:NetherPortals.java
/**
* This handles non-player portal use
* Currently disables portal use by entities
*
* @param event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityPortal(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;
}
if (event.getEntity() == null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: entity is null");
return;
}
if (event.getFrom() != null && event.getFrom().getBlock().getType().equals(Material.ENDER_PORTAL)) {
event.setCancelled(true);
// Same action for all worlds except the end itself
if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) {
if (plugin.getServer().getWorld(Settings.worldName + "_the_end") != null) {
// The end exists
Location end_place = plugin.getServer().getWorld(Settings.worldName + "_the_end").getSpawnLocation();
event.getEntity().teleport(end_place);
if (DEBUG)
plugin.getLogger().info("DEBUG: Result teleported " + event.getEntityType() + " to " + end_place);
return;
}
}
return;
}
Location currentLocation = event.getFrom().clone();
String currentWorld = currentLocation.getWorld().getName();
// Only operate if this is Island territory
if (!currentWorld.equalsIgnoreCase(Settings.worldName) && !currentWorld.equalsIgnoreCase(Settings.worldName + "_nether")) {
if (DEBUG)
plugin.getLogger().info("DEBUG: not an island world");
return;
}
// No entities may pass with the old nether
if (!Settings.newNether) {
if (DEBUG)
plugin.getLogger().info("DEBUG: no entities may pass with old nether");
event.setCancelled(true);
return;
}
// New nether
// Entities can pass only if there are adjoining portals
Location dest = event.getFrom().toVector().toLocation(ASkyBlock.getIslandWorld());
if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) {
dest = event.getFrom().toVector().toLocation(ASkyBlock.getNetherWorld());
}
// Vehicles
if (event.getEntity() instanceof Vehicle) {
Vehicle vehicle = (Vehicle)event.getEntity();
vehicle.eject();
}
new SafeSpotTeleport(plugin, event.getEntity(), dest);
event.setCancelled(true);
}
项目:askyblock
文件:NetherPortals.java
/**
* This handles non-player portal use
* Currently disables portal use by entities
*
* @param event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityPortal(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;
}
if (event.getEntity() == null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: entity is null");
return;
}
if (event.getFrom() != null && event.getFrom().getBlock().getType().equals(Material.ENDER_PORTAL)) {
event.setCancelled(true);
// Same action for all worlds except the end itself
if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) {
if (plugin.getServer().getWorld(Settings.worldName + "_the_end") != null) {
// The end exists
Location end_place = plugin.getServer().getWorld(Settings.worldName + "_the_end").getSpawnLocation();
event.getEntity().teleport(end_place);
if (DEBUG)
plugin.getLogger().info("DEBUG: Result teleported " + event.getEntityType() + " to " + end_place);
return;
}
}
return;
}
Location currentLocation = event.getFrom().clone();
String currentWorld = currentLocation.getWorld().getName();
// Only operate if this is Island territory
if (!currentWorld.equalsIgnoreCase(Settings.worldName) && !currentWorld.equalsIgnoreCase(Settings.worldName + "_nether")) {
if (DEBUG)
plugin.getLogger().info("DEBUG: not an island world");
return;
}
// No entities may pass with the old nether
if (!Settings.newNether) {
if (DEBUG)
plugin.getLogger().info("DEBUG: no entities may pass with old nether");
event.setCancelled(true);
return;
}
// New nether
// Entities can pass only if there are adjoining portals
Location dest = event.getFrom().toVector().toLocation(ASkyBlock.getIslandWorld());
if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) {
dest = event.getFrom().toVector().toLocation(ASkyBlock.getNetherWorld());
}
// Vehicles
if (event.getEntity() instanceof Vehicle) {
Vehicle vehicle = (Vehicle)event.getEntity();
vehicle.eject();
}
new SafeSpotTeleport(plugin, event.getEntity(), dest);
event.setCancelled(true);
}
项目:NPlugins
文件:NListener.java
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onEntityUsePortal(final EntityPortalEvent event) {
this.plugin.entering(this.getClass(), "onEntityUsePortal", "entity=" + event.getEntityType() + ";from=" + NLocation.toString(event.getFrom()) + ";to=" + NLocation.toString(event.getTo()));
if (event.getEntityType() == EntityType.ENDER_DRAGON) {
this.plugin.exiting(this.getClass(), "onEntityUsePortal", "EnderDragon should really stay in the End!");
event.setCancelled(true);
return;
}
final GeneralWorld world = this.plugin.getWorlds().get(event.getFrom().getWorld().getName());
if (GeneralWorld.WorldType.isStock(world)) {
this.plugin.exiting(this.getClass(), "onEntityUsePortal", "Stock world!");
return;
}
// Build a fake TeleportCause based on From and To locations
PlayerTeleportEvent.TeleportCause cause = null;
final Block block = event.getFrom().getBlock();
switch (block.getType()) {
case PORTAL:
cause = PlayerTeleportEvent.TeleportCause.NETHER_PORTAL;
break;
case ENDER_PORTAL:
cause = PlayerTeleportEvent.TeleportCause.END_PORTAL;
break;
default:
this.plugin.debug("Strange block found: " + block.getType() + ", trying to find a portal block near the Location");
for (final BlockFace face : blockFaces) {
if (block.getRelative(face).getType() == Material.PORTAL) {
cause = PlayerTeleportEvent.TeleportCause.NETHER_PORTAL;
this.plugin.debug("Found a Nether Portal block at " + NLocation.toString(block.getRelative(face).getLocation()));
break;
} else if (block.getRelative(face).getType() == Material.ENDER_PORTAL) {
cause = PlayerTeleportEvent.TeleportCause.END_PORTAL;
this.plugin.debug("Found an End Portal block at " + NLocation.toString(block.getRelative(face).getLocation()));
break;
}
}
if (cause == null) {
cause = PlayerTeleportEvent.TeleportCause.PLUGIN;
}
break;
}
if (world.getType() == WorldType.ADDITIONAL) {
final AdditionalWorld additionalWorld = (AdditionalWorld)world;
if (cause == TeleportCause.NETHER_PORTAL && !additionalWorld.hasNether()) {
event.setCancelled(true);
this.plugin.exiting(this.getClass(), "onEntityUsePortal", "doesn't have required subworld (nether)");
return;
} else if (cause == TeleportCause.END_PORTAL && !additionalWorld.hasEnd()) {
event.setCancelled(true);
this.plugin.exiting(this.getClass(), "onEntityUsePortal", "doesn't have required subworld (end)");
return;
}
}
final PortalEventResult result = this.handlePortalEvent(event.getFrom(), cause, event.getPortalTravelAgent());
if (result == null) {
this.plugin.exiting(this.getClass(), "onEntityUsePortal", "result is null");
return;
}
if (result.destination != null) {
event.setTo(result.destination);
}
if (result.useTravelAgent) {
event.useTravelAgent(true);
}
if (result.cancelEvent) {
event.setCancelled(true);
}
this.plugin.exiting(this.getClass(), "onEntityUsePortal");
}
项目:Shopkeepers
文件:LivingEntityShopListener.java
@EventHandler(ignoreCancelled = true)
void onEntityPortalTeleport(EntityPortalEvent event) {
if (plugin.isShopkeeper(event.getEntity())) {
event.setCancelled(true);
}
}
项目:Spigot-Plus
文件:TeleportManager.java
@EventHandler
public void onEntityPortalEvent(EntityPortalEvent evt) {
}