@Override public void onPlayerMove(PlayerMoveEvent event) { Location loc = event.getTo(); World world = loc.getWorld(); Block b = world.getBlockAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); if (!b.getType().equals(Material.PORTAL)) { // Not a portal. return; } if (world.getEnvironment().equals(Environment.NORMAL)) { // First of all see if there IS a nether yet // Here we use "netherworld" World nether = main.getServer().getWorld("netherworld"); if (nether == null) { nether = main.getServer().createWorld("netherworld", Environment.NETHER); } if (!nether.getEnvironment().equals(Environment.NETHER)) { // Don't teleport to a non-nether world return; } // Try to find a portal near where the player should land Block dest = nether.getBlockAt(b.getX() / 8, b.getY(), b.getZ() / 8); NetherPortal portal = NetherPortal.findPortal(dest); if (portal == null) { portal = NetherPortal.createPortal(dest); main.log(event.getPlayer().getName() + " portals to Nether [NEW]"); } else { main.log(event.getPlayer().getName() + " portals to Nether"); } // Go! Location spawn = portal.getSpawn(); event.getPlayer().teleportTo(spawn); event.setTo(spawn); } else if (world.getEnvironment().equals(Environment.NETHER)) { // For now just head to the first world there. World normal = main.getServer().getWorlds().get(0); if (!normal.getEnvironment().equals(Environment.NORMAL)) { // Don't teleport to a non-normal world return; } // Try to find a portal near where the player should land Block dest = normal.getBlockAt(b.getX() * 8, b.getY(), b.getZ() * 8); NetherPortal portal = NetherPortal.findPortal(dest); if (portal == null) { portal = NetherPortal.createPortal(dest); main.log(event.getPlayer().getName() + " portals to normal world [NEW]"); } else { main.log(event.getPlayer().getName() + " portals to normal world"); } // Go! Location spawn = portal.getSpawn(); event.getPlayer().teleportTo(spawn); event.setTo(spawn); } }
@Override public void onPlayerMove(final PlayerMoveEvent event) { if (event.isCancelled()) { return; } final User user = ess.getUser(event.getPlayer()); if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) { final Location from = event.getFrom(); final Location to = event.getTo().clone(); to.setX(from.getX()); to.setY(from.getBlock().getTypeId() == 0 ? from.getY() - 1 : from.getY()); to.setZ(from.getZ()); event.setTo(to); return; } Location afk = user.getAfkPosition(); if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9) { user.updateActivity(true); } if (!ess.getSettings().getNetherPortalsEnabled()) { return; } final Block block = event .getPlayer() .getWorld() .getBlockAt( event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ()); final List<World> worlds = server.getWorlds(); if (block.getType() == Material.PORTAL && worlds.size() > 1 && user.isAuthorized("essentials.portal")) { if (user.getJustPortaled()) { return; } World nether = server.getWorld(ess.getSettings().getNetherName()); if (nether == null) { for (World world : worlds) { if (world.getEnvironment() == World.Environment.NETHER) { nether = world; break; } } if (nether == null) { return; } } final World world = user.getWorld() == nether ? worlds.get(0) : nether; double factor; if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL) { factor = ess.getSettings().getNetherRatio(); } else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER) { factor = 1.0 / ess.getSettings().getNetherRatio(); } else { factor = 1.0; } Location loc = event.getTo(); int x = loc.getBlockX(); int y = loc.getBlockY(); int z = loc.getBlockZ(); if (user.getWorld().getBlockAt(x, y, z - 1).getType() == Material.PORTAL) { z--; } if (user.getWorld().getBlockAt(x - 1, y, z).getType() == Material.PORTAL) { x--; } x = (int) (x * factor); z = (int) (z * factor); loc = new Location(world, x + .5, y, z + .5); Block dest = world.getBlockAt(x, y, z); NetherPortal portal = NetherPortal.findPortal(dest); if (portal == null) { if (world.getEnvironment() == World.Environment.NETHER || ess.getSettings().getGenerateExitPortals()) { portal = NetherPortal.createPortal(dest); LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName())); user.sendMessage(Util.i18n("generatingPortal")); loc = portal.getSpawn(); } } else { LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName())); user.sendMessage(Util.i18n("usingPortal")); loc = portal.getSpawn(); } event.setFrom(loc); event.setTo(loc); try { user.getTeleport().now(loc, new Trade("portal", ess)); } catch (Exception ex) { user.sendMessage(ex.getMessage()); } user.setJustPortaled(true); user.sendMessage(Util.i18n("teleportingPortal")); event.setCancelled(true); return; } user.setJustPortaled(false); }