/** * This method is called when a player actually portals via a vanilla style portal. * * @param event The Event that was fired. */ @EventHandler(priority = EventPriority.HIGH) public void playerPortal(PlayerPortalEvent event) { if (event.isCancelled() || (event.getFrom() == null)) { return; } // The adjust should have happened much earlier. if (event.getTo() == null) { return; } MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); if (event.getFrom().getWorld().equals(event.getTo().getWorld())) { // The player is Portaling to the same world. this.plugin.log( Level.FINER, "Player '" + event.getPlayer().getName() + "' is portaling to the same world."); return; } event.setCancelled( !pt.playerHasMoneyToEnter(fromWorld, toWorld, event.getPlayer(), event.getPlayer(), true)); if (event.isCancelled()) { this.plugin.log( Level.FINE, "Player '" + event.getPlayer().getName() + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() + "' because they don't have the FUNDS required to enter."); return; } if (plugin.getMVConfig().getEnforceAccess()) { event.setCancelled( !pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer())); if (event.isCancelled()) { this.plugin.log( Level.FINE, "Player '" + event.getPlayer().getName() + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() + "' because they don't have: multiverse.access." + event.getTo().getWorld().getName()); } } else { this.plugin.log( Level.FINE, "Player '" + event.getPlayer().getName() + "' was allowed to go to '" + event.getTo().getWorld().getName() + "' because enforceaccess is off."); } if (!plugin.getMVConfig().isUsingDefaultPortalSearch() && event.getPortalTravelAgent() != null) { event.getPortalTravelAgent().setSearchRadius(plugin.getMVConfig().getPortalSearchRadius()); } }
/** * This method is called when a player teleports anywhere. * * @param event The Event that was fired. */ @EventHandler(priority = EventPriority.HIGHEST) public void playerTeleport(PlayerTeleportEvent event) { this.plugin.log( Level.FINER, "Got teleport event for player '" + event.getPlayer().getName() + "' with cause '" + event.getCause() + "'"); if (event.isCancelled()) { return; } Player teleportee = event.getPlayer(); CommandSender teleporter = null; String teleporterName = MultiverseCore.getPlayerTeleporter(teleportee.getName()); if (teleporterName != null) { if (teleporterName.equals("CONSOLE")) { this.plugin.log(Level.FINER, "We know the teleporter is the console! Magical!"); teleporter = this.plugin.getServer().getConsoleSender(); } else { teleporter = this.plugin.getServer().getPlayer(teleporterName); } } this.plugin.log( Level.FINER, "Inferred sender '" + teleporter + "' from name '" + teleporterName + "', fetched from name '" + teleportee.getName() + "'"); MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); if (toWorld == null) { this.plugin.log( Level.FINE, "Player '" + teleportee.getName() + "' is teleporting to world '" + event.getTo().getWorld().getName() + "' which is not managed by Multiverse-Core. No further " + "actions will be taken by Multiverse-Core."); return; } if (event.getFrom().getWorld().equals(event.getTo().getWorld())) { // The player is Teleporting to the same world. this.plugin.log( Level.FINER, "Player '" + teleportee.getName() + "' is teleporting to the same world."); this.stateSuccess(teleportee.getName(), toWorld.getAlias()); return; } // TODO: Refactor these lines. // Charge the teleporter event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, teleporter, teleportee, true)); if (event.isCancelled() && teleporter != null) { this.plugin.log( Level.FINE, "Player '" + teleportee.getName() + "' was DENIED ACCESS to '" + toWorld.getAlias() + "' because '" + teleporter.getName() + "' don't have the FUNDS required to enter it."); return; } // Check if player is allowed to enter the world if we're enforcing permissions if (plugin.getMVConfig().getEnforceAccess()) { event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee)); if (event.isCancelled() && teleporter != null) { this.plugin.log( Level.FINE, "Player '" + teleportee.getName() + "' was DENIED ACCESS to '" + toWorld.getAlias() + "' because '" + teleporter.getName() + "' don't have: multiverse.access." + event.getTo().getWorld().getName()); return; } } else { this.plugin.log( Level.FINE, "Player '" + teleportee.getName() + "' was allowed to go to '" + toWorld.getAlias() + "' because enforceaccess is off."); } // Does a limit actually exist? if (toWorld.getPlayerLimit() > -1) { // Are there equal or more people on the world than the limit? if (toWorld.getCBWorld().getPlayers().size() >= toWorld.getPlayerLimit()) { // Ouch the world is full, lets see if the player can bypass that limitation if (!pt.playerCanBypassPlayerLimit(toWorld, teleporter, teleportee)) { this.plugin.log( Level.FINE, "Player '" + teleportee.getName() + "' was DENIED ACCESS to '" + toWorld.getAlias() + "' because the world is full and '" + teleporter.getName() + "' doesn't have: mv.bypass.playerlimit." + event.getTo().getWorld().getName()); event.setCancelled(true); return; } } } // By this point anything cancelling the event has returned on the method, meaning the teleport // is a success \o/ this.stateSuccess(teleportee.getName(), toWorld.getAlias()); }