本文整理汇总了Java中org.bukkit.event.player.PlayerPortalEvent.useTravelAgent方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerPortalEvent.useTravelAgent方法的具体用法?Java PlayerPortalEvent.useTravelAgent怎么用?Java PlayerPortalEvent.useTravelAgent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.player.PlayerPortalEvent
的用法示例。
在下文中一共展示了PlayerPortalEvent.useTravelAgent方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlayerPortal
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerPortal(PlayerPortalEvent event) {
if (event.getCause() != PlayerTeleportEvent.TeleportCause.END_PORTAL) {
return;
}
if (event.getTo() != null) {
World toWorld = event.getTo().getWorld();
if (toWorld != null && toWorld.getEnvironment() == World.Environment.THE_END) {
event.useTravelAgent(false);
event.setTo(toWorld.getSpawnLocation());
return;
}
}
World fromWorld = event.getFrom().getWorld();
if (fromWorld != null && fromWorld.getEnvironment() == World.Environment.THE_END) {
event.useTravelAgent(false);
event.setTo(endExit);
}
}
示例2: onPlayerPortal
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
@EventHandler
public void onPlayerPortal(PlayerPortalEvent event) {
if (!event.getCause().equals(TeleportCause.NETHER_PORTAL)) { return; }
Location cornerLocation = PortalUtils.findCornerBlock(event.getFrom()).orElse(null);
if (cornerLocation == null) { debug("Couldnt find cornerLoc for loc: " + Utility.toString(event.getFrom())); return; }
Portal portal = this.module.storage.getPortal(cornerLocation).orElse(null);
if (portal == null) { debug("Couldnt find portal for cornerLoc: " + Utility.toString(cornerLocation)); return; }
CraftoPlayer player = CraftoPlayer.getPlayer(event.getPlayer()).orElse(null);
if (!event.getPlayer().hasPermission("craftoplugin.portal.always-teleport")) {
if (player != null && player.getPlaytime().toMinutes() < this.minPlaytime.toMinutes()) {
debug(event.getPlayer().getName() + " failed to teleport because he doesn't have permission!");
CraftoMessenger.sendFailure(event.getPlayer(), "Du kannst erst ab " + this.minPlaytime.toMinutes() + " Minuten Spielzeit das Portal nutzen!");
event.setCancelled(true);
return;
}
}
event.useTravelAgent(false);
event.setTo(portal.getDestination());
debug("Teleported " + event.getPlayer().getName() + " to dest of portal '" + portal.getName() + "'");
}
示例3: onPlayerPortal
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
/**
* 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);
}
}
示例4: onPlayerPortal
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
@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());
}
示例5: onPlayerUsePortal
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onPlayerUsePortal(final PlayerPortalEvent event) {
this.plugin.entering(this.getClass(), "onPlayerUsePortal", "player=" + event.getPlayer().getName() + ";from=" + NLocation.toString(event.getFrom()) + ";to=" + NLocation.toString(event.getTo()));
final GeneralWorld world = this.plugin.getWorlds().get(event.getFrom().getWorld().getName());
if (GeneralWorld.WorldType.isStock(world)) {
return;
}
if (world.getType() == WorldType.ADDITIONAL) {
final AdditionalWorld additionalWorld = (AdditionalWorld)world;
if (event.getCause() == TeleportCause.NETHER_PORTAL && !additionalWorld.hasNether()) {
event.setCancelled(true);
this.plugin.exiting(this.getClass(), "onPlayerUsePortal", "doesn't have required subworld (nether)");
return;
} else if (event.getCause() == TeleportCause.END_PORTAL && !additionalWorld.hasEnd()) {
event.setCancelled(true);
this.plugin.exiting(this.getClass(), "onPlayerUsePortal", "doesn't have required subworld (end)");
return;
}
}
final PortalEventResult result = this.handlePortalEvent(event.getFrom(), event.getCause(), event.getPortalTravelAgent());
if (result == 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(), "onPlayerUsePortal");
}
示例6: onPortalEnter
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPortalEnter(PlayerPortalEvent event) {
if (event.getCause() != PlayerTeleportEvent.TeleportCause.END_PORTAL) {
return;
}
Location to = event.getTo();
World toWorld = to.getWorld();
if (toWorld == null)
return; // safe-guard if the End or Nether is disabled
if (toWorld.getEnvironment() == World.Environment.THE_END) {
Player player = event.getPlayer();
// Prevent entering the end if it's closed.
if (false /* TODO:plugin.getEndManager().isOpened() */) {
message(player, ChatColor.RED + "The End is currently closed.");
event.setCancelled(true);
return;
}
// Prevent entering the end if the player is Spawn Tagged.
PlayerTimer timer = plugin.getTimerManager().getCombatTimer();
long remaining;
if ((remaining = timer.getRemaining(player)) > 0L) {
message(player, ChatColor.RED + "You cannot enter the End whilst your " + timer.getDisplayName() + ChatColor.RED + " timer is active [" + ChatColor.BOLD
+ DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + " remaining]");
event.setCancelled(true);
return;
}
// Prevent entering the end if the player is PVP Protected.
timer = plugin.getTimerManager().getInvincibilityTimer();
if ((remaining = timer.getRemaining(player)) > 0L) {
message(player, ChatColor.RED + "You cannot enter the End whilst your " + timer.getDisplayName() + ChatColor.RED + " timer is active [" + ChatColor.BOLD
+ DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + " remaining]");
event.setCancelled(true);
return;
}
event.useTravelAgent(false);
event.setTo(toWorld.getSpawnLocation().add(0.5, 0, 0.5));
}
}
示例7: changeDimension
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
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
}
示例8: onPlayerPortal
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerPortal(PlayerPortalEvent event) {
// If the nether is disabled then quit immediately
if (!Settings.createNether) {
return;
}
Location currentLocation = event.getFrom().clone();
String currentWorld = currentLocation.getWorld().getName();
if (!currentWorld.equalsIgnoreCase(Settings.worldName) && !currentWorld.equalsIgnoreCase(Settings.worldName + "_nether")
&& !currentWorld.equalsIgnoreCase(Settings.worldName + "_the_end")) {
return;
}
// Determine what portal it is
switch (event.getCause()) {
case END_PORTAL:
if (Settings.createEnd) {
// Same action for all worlds except the end itself
if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) {
if (ASkyGrid.getEndWorld() != null) {
// The end exists
event.setCancelled(true);
// Convert current location to end world location
Location end_place = event.getPlayer().getLocation().toVector().toLocation(ASkyGrid.getEndWorld());
// Set the height to the top of the end grid
end_place.setY(Settings.gridHeight);
if (GridManager.isSafeLocation(end_place)) {
event.getPlayer().teleport(end_place);
return;
} else {
end_place = plugin.getGrid().bigScan(end_place, 10);
if (end_place != null) {
event.getPlayer().teleport(end_place);
} else {
// Try the spawn
end_place = ASkyGrid.getEndWorld().getSpawnLocation();
if (GridManager.isSafeLocation(end_place)) {
event.getPlayer().teleport(end_place);
return;
} else {
event.getPlayer().sendMessage(ChatColor.RED + plugin.myLocale(event.getPlayer().getUniqueId()).warpserrorNotSafe);
}
}
return;
}
}
} else {
// Returning from the end - just go home
event.setCancelled(true);
plugin.getGrid().homeTeleport(event.getPlayer());
}
}
break;
case NETHER_PORTAL:
// Get the home world of this player
if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) {
// Going to Nether
event.setTo(event.getFrom().toVector().toLocation(ASkyGrid.getNetherWorld()));
event.useTravelAgent(true);
} else {
// Returning
event.setTo(event.getFrom().toVector().toLocation(ASkyGrid.getGridWorld()));
event.useTravelAgent(true);
}
break;
default:
break;
}
}
示例9: changeDimension
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
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
}
示例10: changeDimension
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
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();
org.bukkit.event.player.PlayerTeleportEvent tpEvent = new org.bukkit.event.player.PlayerTeleportEvent(entityplayer.getBukkitEntity(), enter, exit, cause);
Bukkit.getServer().getPluginManager().callEvent(tpEvent);
if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
return;
}
Vector velocity = entityplayer.getBukkitEntity().getVelocity();
exitWorld.getTravelAgent().adjustExit(entityplayer, exit, velocity);
entityplayer.ck = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds
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);
}
}
示例11: onEnter
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST)
public void onEnter(PlayerPortalEvent e) {
if(e.isCancelled()) {
return;
}
e.setCancelled(true);
Block block = getPortalNearby(e.getPlayer().getLocation().getBlock());
if(!(block instanceof Block)) {
return;
}
for(Portal portal : pl.getConfiguration().getPortalConfig().getPortals().values()) {
if(portal.getInnerBlocks().contains(block)) {
if(pl.getConfiguration().getPortalConfig().getCooldown() > 0) {
if(time.containsKey(e.getPlayer().getName())) {
if(time.get(e.getPlayer().getName()) < System.currentTimeMillis()) {
time.remove(e.getPlayer().getName());
} else {
e.setCancelled(true);
Long millis = (time.get(e.getPlayer().getName())-System.currentTimeMillis());
String msg = String.format("%d:%s", TimeUnit.MILLISECONDS.toMinutes(millis), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
sendMessage(e.getPlayer(), ChatColor.GRAY + "cooldown please wait: " + ChatColor.GREEN + msg + ChatColor.GRAY + " minutes");
return;
}
} else {
Date date = new Date(System.currentTimeMillis());
date.setSeconds(date.getSeconds()+pl.getConfiguration().getPortalConfig().getCooldown());
time.put(e.getPlayer().getName(), date.getTime());
}
}
e.useTravelAgent(false);
if(portal.isLinked()) {
Portal linked = portal.getLinkedPortal();
if(!(linked instanceof Portal)) {
e.setCancelled(true);
return;
}
//e.setTo(linked.getInnerBlocks()[(linked.getInnerBlocks().length-1)].getLocation());
e.setTo(linked.getExitLocation());
e.setCancelled(false);
} else {
e.setCancelled(true);
}
break;
}
}
e.setCancelled(false);
}
示例12: changeDimension
import org.bukkit.event.player.PlayerPortalEvent; //导入方法依赖的package包/类
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().s() : 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.s().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
}