}
this.plugin.log(Level.FINER, "onPlayerPortal called!");
PortalManager pm = this.plugin.getPortalManager();
Location playerPortalLoc = event.getPlayer().getLocation();
// Determine if we're in a portal
MVPortal portal = pm.getPortal(event.getPlayer(), playerPortalLoc);
Player p = event.getPlayer();
// Even if the location was null, we still have to see if
// someone wasn't exactly on (because they can do this).
if (portal == null) {
// Check around the player to make sure
playerPortalLoc = this.plugin.getCore().getSafeTTeleporter().findPortalBlockNextTo(event.getFrom());
if (playerPortalLoc != null) {
this.plugin.log(Level.FINER, "Player was outside of portal, The location has been successfully translated.");
portal = pm.getPortal(event.getPlayer(), playerPortalLoc);
}
}
if (portal != null) {
this.plugin.log(Level.FINER, "There was a portal found!");
MVDestination portalDest = portal.getDestination();
if (portalDest != null && !(portalDest instanceof InvalidDestination)) {
if (!portal.isFrameValid(playerPortalLoc)) {
event.getPlayer().sendMessage("This portal's frame is made of an " + ChatColor.RED + "incorrect material." + ChatColor.RED + " You should exit it now.");
event.setCancelled(true);
return;
}
PortalPlayerSession ps = this.plugin.getPortalSession(event.getPlayer());
if (portal.getHandlerScript() != null && !portal.getHandlerScript().isEmpty()) {
try {
if (helper.scriptPortal(event.getPlayer(), portalDest, portal, ps)) {
// Portal handled by script
} else {
event.setCancelled(true);
}
return;
} catch (IllegalStateException ignore) {
// Portal not handled by script
}
}
if (!ps.allowTeleportViaCooldown(new Date())) {
event.getPlayer().sendMessage(ps.getFriendlyRemainingTimeMessage());
event.setCancelled(true);
return;
}
// If they're using Access and they don't have permission and they're NOT excempt, return, they're not allowed to tp.
// No longer checking exemption status
if (MultiversePortals.EnforcePortalAccess && !this.plugin.getCore().getMVPerms().hasPermission(event.getPlayer(), portal.getPermission().getName(), true)) {
this.helper.stateFailure(p.getDisplayName(), portal.getName());
event.setCancelled(true);
return;
}
TravelAgent agent = new MVTravelAgent(this.plugin.getCore(), portalDest, event.getPlayer());
event.setTo(portalDest.getLocation(event.getPlayer()));
if (portalDest.useSafeTeleporter()) {
SafeTTeleporter teleporter = this.plugin.getCore().getSafeTTeleporter();
event.setTo(teleporter.getSafeLocation(event.getPlayer(), portalDest));
}
final Economy vaultEco = (portal.getCurrency() <= 0 && plugin.getCore().getVaultHandler().getEconomy() != null) ? plugin.getCore().getVaultHandler().getEconomy() : null;
final GenericBank bank = vaultEco == null ? plugin.getCore().getBank() : null;
boolean canAfford = false;
boolean shouldPay = false;
if (portal.getPrice() != 0D && !p.hasPermission(portal.getExempt())) {
shouldPay = true;
if (portal.getPrice() < 0D || (vaultEco != null && vaultEco.has(p.getName(), portal.getPrice())) || (bank != null && bank.hasEnough(event.getPlayer(), portal.getPrice(), portal.getCurrency(), "You need " + bank.getFormattedAmount(event.getPlayer(), portal.getPrice(), portal.getCurrency()) + " to enter the " + portal.getName() + " portal."))) {
canAfford = true;
} else if (vaultEco != null) {
p.sendMessage("You need " + vaultEco.format(portal.getPrice()) + " to enter the " + portal.getName() + " portal.");
event.setCancelled(true);
return;
} else if (bank != null) {
event.setCancelled(true);
return;
}
} else {
canAfford = true;
}
if (canAfford) {
event.setPortalTravelAgent(agent);
event.useTravelAgent(true);
MVPortalEvent portalEvent = new MVPortalEvent(portalDest, event.getPlayer(), agent, portal);
this.plugin.getServer().getPluginManager().callEvent(portalEvent);
if (portalEvent.isCancelled()) {
event.setCancelled(true);
this.plugin.log(Level.FINE, "Someone cancelled the MVPlayerPortal Event!");
return;
} else {
if (shouldPay) {
if (vaultEco != null) {
if (portal.getPrice() < 0D) {
p.sendMessage(String.format("You have earned %s for using %s.", vaultEco.format(-portal.getPrice()), portal.getName()));
vaultEco.depositPlayer(event.getPlayer().getName(), -portal.getPrice());
} else {
p.sendMessage(String.format("You have been charged %s for using %s.", vaultEco.format(portal.getPrice()), portal.getName()));
vaultEco.withdrawPlayer(event.getPlayer().getName(), portal.getPrice());
}
} else {
if (portal.getPrice() < 0D) {
bank.give(event.getPlayer(), -portal.getPrice(), portal.getCurrency());
} else {
bank.take(event.getPlayer(), portal.getPrice(), portal.getCurrency());
}
}
}
}
this.plugin.log(Level.FINE, "Sending player to a location via our Sexy Travel Agent!");