/** * Called when the portal is ready to take the player to the destination. * * @param event The Portal event. */ @EventHandler public void playerPortal(PlayerPortalEvent event) { if (event.isCancelled()) { return; } PortalDetector detector = new PortalDetector(this.plugin); try { String destString = detector.getNotchPortalDestination(event.getPlayer(), event.getFrom()); if (destString != null) { this.plugin.log(Level.FINER, "Found a Multiverse Sign"); DestinationFactory df = this.plugin.getCore().getDestFactory(); event.useTravelAgent(true); MVDestination dest = df.getDestination(destString); event.setPortalTravelAgent( new MVTravelAgent(this.plugin.getCore(), dest, event.getPlayer())); event.setTo(dest.getLocation(event.getPlayer())); } } catch (NoMultiverseSignFoundException e) { // This will simply act as a notch portal. this.plugin.log(Level.FINER, "Did NOT find a Multiverse Sign"); } catch (MoreThanOneSignFoundException e) { this.plugin .getCore() .getMessaging() .sendMessage( event.getPlayer(), String.format( "%sSorry %sbut more than 1 sign was found where the second line was [mv] or [multiverse]. Please remove one of the signs.", ChatColor.RED, ChatColor.WHITE), false); event.setCancelled(true); } }
private void takePlayerToDestination(Player player, String destString) { if (destString != null) { this.plugin.log(Level.FINER, "Found a SignPortal! (" + destString + ")"); SafeTTeleporter teleporter = this.plugin.getCore().getSafeTTeleporter(); DestinationFactory df = this.plugin.getCore().getDestFactory(); MVDestination d = df.getDestination(destString); this.plugin.log(Level.FINER, "Found a Destination! (" + d + ")"); if (this.pd.playerCanGoToDestination(player, d)) { TeleportResult result = teleporter.safelyTeleport(player, player, d); if (result == TeleportResult.FAIL_UNSAFE) { player.sendMessage( "The Destination was not safe! (" + ChatColor.RED + d + ChatColor.WHITE + ")"); } } else { this.plugin.log(Level.FINER, "Denied permission to go to destination!"); } } else { player.sendMessage("The Destination was not set on the sign!"); } }