Java 类org.bukkit.TravelAgent 实例源码

项目: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));
}
项目: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));
}
项目:ultrahardcore    文件:PortalsFeature.java   
/**
 * When a portal event happends
 *
 * @param entityPortalEvent the portal event
 */
@EventHandler
public void onPortalEvent(PlayerPortalEvent entityPortalEvent)
{
    //if we're enabled
    if(isEnabled()) {

        //create a travel agent for the portal
        TravelAgent ta = entityPortalEvent.getPortalTravelAgent();
        //if they're in the nether
        if(entityPortalEvent.getPlayer().getWorld().getEnvironment() == World.Environment.NETHER) {
            //set data from the nether
            ta.setCanCreatePortal(config.getBoolean("PortalRanges.from_nether.allowed"));
            ta.setCreationRadius(config.getInt("PortalRanges.from_nether.creation_radius"));
            ta.setSearchRadius(config.getInt("PortalRanges.from_nether.search_radius"));
        } else {
            //set the data to the nether
            ta.setCanCreatePortal(config.getBoolean("PortalRanges.to_nether.allowed"));
            ta.setCreationRadius(config.getInt("PortalRanges.to_nether.creation_radius"));
            ta.setSearchRadius(config.getInt("PortalRanges.to_nether.search_radius"));
        }
    }
}
项目:SurvivalAPI    文件:SecurityListener.java   
/**
 * Patch player teleporting through portals to be INSIDE the world border
 *
 * @param event Event
 */
@EventHandler
public void onPlayerPortal(PlayerPortalEvent event)
{
    if (!this.game.getPlugin().getServer().getAllowNether() || this.game.getSurvivalGameLoop().isNetherClosed())
    {
        event.setCancelled(true);
        return;
    }
    TravelAgent travelAgent = event.getPortalTravelAgent();
    Location destination = travelAgent.findPortal(event.getTo());

    if (destination != null)
    {
        if (!SafePortalsUtils.isInsideBorder(destination))
        {
            event.useTravelAgent(false);
            boolean success = travelAgent.createPortal(event.getTo());

            if (success)
            {
                event.setTo(travelAgent.findPortal(event.getTo()));

                if (!SafePortalsUtils.isSafeSpot(event.getTo()))
                {
                    Location safeTo = SafePortalsUtils.searchSafeSpot(event.getTo());
                    if (safeTo != null)
                    {
                        event.setTo(safeTo);
                    }
                }
            }
        }
    }
    else
    {
        event.useTravelAgent(true);
    }
}
项目:MundoSK    文件:ExprNewPortal.java   
public static Location createPortal(Location targetLoc, int radius, TravelAgent travelAgent) {
    travelAgent.setCanCreatePortal(true);
    travelAgent.setCreationRadius(radius);
    travelAgent.setSearchRadius(radius);
    if (travelAgent.createPortal(targetLoc)) {
        return travelAgent.findPortal(targetLoc);
    } else {
        return null;
    }
}
项目: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));
}
项目: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);
    }
}
项目:Uranium    文件:CraftTravelAgent.java   
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:Uranium    文件:CraftTravelAgent.java   
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:ThermosRebased    文件:CraftTravelAgent.java   
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:ThermosRebased    文件:CraftTravelAgent.java   
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:Thermos-Bukkit    文件:EntityPortalEvent.java   
public EntityPortalEvent(final Entity entity, final Location from, final Location to, final TravelAgent pta) {
    super(entity, from, to);
    this.travelAgent = pta;
}
项目:Thermos-Bukkit    文件:PlayerPortalEvent.java   
public PlayerPortalEvent(final Player player, final Location from, final Location to, final TravelAgent pta) {
    super(player, from, to);
    this.travelAgent = pta;
}
项目:Thermos-Bukkit    文件:PlayerPortalEvent.java   
public PlayerPortalEvent(Player player, Location from, Location to, TravelAgent pta, TeleportCause cause) {
    super(player, from, to, cause);
    this.travelAgent = pta;
}
项目:Thermos    文件:CraftTravelAgent.java   
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:Thermos    文件:CraftTravelAgent.java   
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:KCauldron    文件:CraftTravelAgent.java   
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:KCauldron    文件:CraftTravelAgent.java   
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:CauldronGit    文件:EntityPortalEvent.java   
public EntityPortalEvent(final Entity entity, final Location from, final Location to, final TravelAgent pta) {
    super(entity, from, to);
    this.travelAgent = pta;
}
项目:CauldronGit    文件:PlayerPortalEvent.java   
public PlayerPortalEvent(final Player player, final Location from, final Location to, final TravelAgent pta) {
    super(player, from, to);
    this.travelAgent = pta;
}
项目:CauldronGit    文件:PlayerPortalEvent.java   
public PlayerPortalEvent(Player player, Location from, Location to, TravelAgent pta, TeleportCause cause) {
    super(player, from, to, cause);
    this.travelAgent = pta;
}
项目:CauldronGit    文件:CraftTravelAgent.java   
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:CauldronGit    文件:CraftTravelAgent.java   
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:Cauldron-Old    文件:CraftTravelAgent.java   
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:Cauldron-Old    文件:CraftTravelAgent.java   
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:Cauldron-Reloaded    文件:CraftTravelAgent.java   
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:Cauldron-Reloaded    文件:CraftTravelAgent.java   
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:FFoKC    文件:CraftTravelAgent.java   
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:FFoKC    文件:CraftTravelAgent.java   
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:CraftBukkit    文件:CraftTravelAgent.java   
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:CraftBukkit    文件:CraftTravelAgent.java   
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:CraftBukkit    文件:PlayerList.java   
public void changeDimension(EntityPlayer entityplayer, int i, TeleportCause cause) {
    WorldServer exitWorld = null;
    if (entityplayer.dimension < CraftWorld.CUSTOM_DIMENSION_OFFSET) { // plugins must specify exit from custom Bukkit worlds
        // only target existing worlds (compensate for allow-nether/allow-end as false)
        for (WorldServer world : this.server.worlds) {
            if (world.dimension == i) {
                exitWorld = world;
            }
        }
    }

    Location enter = entityplayer.getBukkitEntity().getLocation();
    Location exit = null;
    boolean useTravelAgent = false; // don't use agent for custom worlds or return from THE_END
    if (exitWorld != null) {
        if ((cause == TeleportCause.END_PORTAL) && (i == 0)) {
            // THE_END -> NORMAL; use bed if available, otherwise default spawn
            exit = ((org.bukkit.craftbukkit.entity.CraftPlayer) entityplayer.getBukkitEntity()).getBedSpawnLocation();
            if (exit == null || ((CraftWorld) exit.getWorld()).getHandle().dimension != 0) {
                exit = exitWorld.getWorld().getSpawnLocation();
            }
        } else {
            // NORMAL <-> NETHER or NORMAL -> THE_END
            exit = this.calculateTarget(enter, exitWorld);
            useTravelAgent = true;
        }
    }

    TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().getTravelAgent() : org.bukkit.craftbukkit.CraftTravelAgent.DEFAULT; // return arbitrary TA to compensate for implementation dependent plugins
    PlayerPortalEvent event = new PlayerPortalEvent(entityplayer.getBukkitEntity(), enter, exit, agent, cause);
    event.useTravelAgent(useTravelAgent);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled() || event.getTo() == null) {
        return;
    }

    exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(event.getTo()) : event.getTo();
    if (exit == null) {
        return;
    }
    exitWorld = ((CraftWorld) exit.getWorld()).getHandle();

    Vector velocity = entityplayer.getBukkitEntity().getVelocity();
    boolean before = exitWorld.chunkProviderServer.forceChunkLoad;
    exitWorld.chunkProviderServer.forceChunkLoad = true;
    exitWorld.getTravelAgent().adjustExit(entityplayer, exit, velocity);
    exitWorld.chunkProviderServer.forceChunkLoad = before;

    this.moveToWorld(entityplayer, exitWorld.dimension, true, exit, false); // Vanilla doesn't check for suffocation when handling portals, so neither should we
    if (entityplayer.motX != velocity.getX() || entityplayer.motY != velocity.getY() || entityplayer.motZ != velocity.getZ()) {
        entityplayer.getBukkitEntity().setVelocity(velocity);
    }
    // CraftBukkit end
}
项目:Craftbukkit    文件:CraftTravelAgent.java   
@Override
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:Craftbukkit    文件:CraftTravelAgent.java   
@Override
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:Almura-Server    文件:CraftTravelAgent.java   
public TravelAgent setSearchRadius(int radius) {
    this.searchRadius = radius;
    return this;
}
项目:Almura-Server    文件:CraftTravelAgent.java   
public TravelAgent setCreationRadius(int radius) {
    this.creationRadius = radius < 2 ? 0 : radius;
    return this;
}
项目:Almura-Server    文件:PlayerList.java   
public void changeDimension(EntityPlayer entityplayer, int i, TeleportCause cause) {
    WorldServer exitWorld = null;
    if (entityplayer.dimension < CraftWorld.CUSTOM_DIMENSION_OFFSET) { // plugins must specify exit from custom Bukkit worlds
        // only target existing worlds (compensate for allow-nether/allow-end as false)
        for (WorldServer world : this.server.worlds) {
            if (world.dimension == i) {
                exitWorld = world;
            }
        }
    }

    Location enter = entityplayer.getBukkitEntity().getLocation();
    Location exit = null;
    boolean useTravelAgent = false; // don't use agent for custom worlds or return from THE_END
    if (exitWorld != null) {
        if ((cause == TeleportCause.END_PORTAL) && (i == 0)) {
            // THE_END -> NORMAL; use bed if available, otherwise default spawn
            exit = ((org.bukkit.craftbukkit.entity.CraftPlayer) entityplayer.getBukkitEntity()).getBedSpawnLocation();
            if (exit == null || ((CraftWorld) exit.getWorld()).getHandle().dimension != 0) {
                exit = exitWorld.getWorld().getSpawnLocation();
            }
        } else {
            // NORMAL <-> NETHER or NORMAL -> THE_END
            exit = this.calculateTarget(enter, exitWorld);
            useTravelAgent = true;
        }
    }

    TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().t() : org.bukkit.craftbukkit.CraftTravelAgent.DEFAULT; // return arbitrary TA to compensate for implementation dependent plugins
    PlayerPortalEvent event = new PlayerPortalEvent(entityplayer.getBukkitEntity(), enter, exit, agent, cause);
    event.useTravelAgent(useTravelAgent);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled() || event.getTo() == null) {
        return;
    }

    exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(event.getTo()) : event.getTo();
    if (exit == null) {
        return;
    }
    exitWorld = ((CraftWorld) exit.getWorld()).getHandle();

    Vector velocity = entityplayer.getBukkitEntity().getVelocity();
    boolean before = exitWorld.chunkProviderServer.forceChunkLoad;
    exitWorld.chunkProviderServer.forceChunkLoad = true;
    exitWorld.t().adjustExit(entityplayer, exit, velocity); // Should be getTravelAgent
    exitWorld.chunkProviderServer.forceChunkLoad = before;

    this.moveToWorld(entityplayer, exitWorld.dimension, true, exit, false); // Vanilla doesn't check for suffocation when handling portals, so neither should we
    if (entityplayer.motX != velocity.getX() || entityplayer.motY != velocity.getY() || entityplayer.motZ != velocity.getZ()) {
        entityplayer.getBukkitEntity().setVelocity(velocity);
    }
    // CraftBukkit end
}