@EventHandler public static void onPortalTravel(PlayerPortalEvent event) throws Exception { if (event.getCause() == PlayerPortalEvent.TeleportCause.END_PORTAL) { int x = event.getPlayer().getLocation().getBlockX(); int y = event.getPlayer().getLocation().getBlockY(); int z = event.getPlayer().getLocation().getBlockZ(); String[] data = getPageData("http://example.com/game.php?type=getRealm&location="+x+":"+y+":"+z).split(":"); // THIS RETURNS <username>:<oldblockid> String realm = data[0]; int oldID = Integer.parseInt(data[1].trim()); Bukkit.getServer().getWorld("world").getBlockAt(x, y, z).setTypeId(oldID); World world = Bukkit.getWorld("realms/" + realm); if(world == null){ //Loads a world with the name given in the constructor WorldCreator wc = new WorldCreator("realms/" + realm); world = Bukkit.createWorld(wc); } event.getPlayer().teleport(new Location(world, 1, 65,16.5)); } }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerPortal(PlayerPortalEvent e) { if (e.getCause().equals(TeleportCause.NETHER_PORTAL)) { checkIsland(e, e.getFrom(), Flags.NETHER_PORTAL); } else if (e.getCause().equals(TeleportCause.END_PORTAL)) { checkIsland(e, e.getFrom(), Flags.END_PORTAL); } } }
/** * When returning from the standard nether, teleport to the player's island * @param e */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onNetherPortalStandardNether(PlayerPortalEvent e) { World fromWorld = e.getFrom().getWorld(); if (e.getCause().equals(TeleportCause.NETHER_PORTAL) && plugin.getIWM().inWorld(Util.getWorld(fromWorld)) && !plugin.getIWM().isNetherIslands(fromWorld) && fromWorld.getEnvironment().equals(Environment.NETHER) && plugin.getPlayers().isKnown(e.getPlayer().getUniqueId())) { e.setCancelled(true); plugin.getIslands().homeTeleport(Util.getWorld(fromWorld), e.getPlayer()); } }
/** * Handle end portals * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onEndIslandPortal(PlayerPortalEvent e) { if (!e.getCause().equals(TeleportCause.END_PORTAL) || !plugin.getIWM().inWorld(e.getFrom())) { return; } World overWorld = Util.getWorld(e.getFrom().getWorld()); // If entering a portal in the end, teleport home if you have one, else do nothing if (e.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) { if (plugin.getIslands().hasIsland(overWorld, e.getPlayer().getUniqueId())) { e.setCancelled(true); plugin.getIslands().homeTeleport(overWorld, e.getPlayer()); } return; } // Going to the end, then go to the same location in the end world if (plugin.getIWM().isEndGenerate(overWorld) && plugin.getIWM().isEndIslands(overWorld)) { World endWorld = plugin.getIWM().getEndWorld(overWorld); // End exists and end islands are being used Location to = plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.THE_END)).orElse(e.getFrom().toVector().toLocation(endWorld)); e.setCancelled(true); new SafeSpotTeleport.Builder(plugin) .entity(e.getPlayer()) .location(to) .build(); } }
if (!e.getCause().equals(TeleportCause.NETHER_PORTAL) || !plugin.getIWM().inWorld(e.getFrom()) || !plugin.getIWM().isNetherGenerate(fromWorld)) {
if(event.getCause() == TeleportCause.NETHER_PORTAL)
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getTo().getWorld())); if (!wcfg.regionNetherPortalProtection) return; if (event.getCause() != TeleportCause.NETHER_PORTAL) { return;