mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Wrap the travel agent in an adapter.
(cherry picked from commit 253ede1c9a
)
This commit is contained in:
parent
3c1c54ae3d
commit
4d4a9c101f
@ -7,6 +7,10 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
@ -29,10 +33,6 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Multiverse's {@link Listener} for players.
|
||||
*/
|
||||
@ -304,8 +304,16 @@ public class MVPlayerListener implements Listener {
|
||||
+ "' 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());
|
||||
if (!plugin.getMVConfig().isUsingDefaultPortalSearch()) {
|
||||
try {
|
||||
Class.forName("org.bukkit.TravelAgent");
|
||||
if (event.getPortalTravelAgent() != null) {
|
||||
event.getPortalTravelAgent().setSearchRadius(plugin.getMVConfig().getPortalSearchRadius());
|
||||
}
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
plugin.log(Level.WARNING, "TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,110 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.destination.CannonDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TravelAgent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
|
||||
public class BukkitTravelAgent implements TravelAgent {
|
||||
private final MVTravelAgent agent;
|
||||
|
||||
public BukkitTravelAgent(MVTravelAgent agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BukkitTravelAgent setSearchRadius(int radius) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getSearchRadius() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BukkitTravelAgent setCreationRadius(int radius) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getCreationRadius() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getCanCreatePortal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setCanCreatePortal(boolean create) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location findOrCreate(Location location) {
|
||||
return this.getSafeLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location findPortal(Location location) {
|
||||
return this.getSafeLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean createPortal(Location location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Location getSafeLocation() {
|
||||
// At this time, these can never use the velocity.
|
||||
if (agent.destination instanceof CannonDestination) {
|
||||
agent.core.log(Level.FINE, "Using Stock TP method. This cannon will have 0 velocity");
|
||||
}
|
||||
SafeTTeleporter teleporter = agent.core.getSafeTTeleporter();
|
||||
Location newLoc = agent.destination.getLocation(agent.player);
|
||||
if (agent.destination.useSafeTeleporter()) {
|
||||
newLoc = teleporter.getSafeLocation(agent.player, agent.destination);
|
||||
}
|
||||
if (newLoc == null) {
|
||||
return agent.player.getLocation();
|
||||
}
|
||||
return newLoc;
|
||||
|
||||
}
|
||||
|
||||
public void setPortalEventTravelAgent(PlayerPortalEvent event) {
|
||||
event.setPortalTravelAgent(this);
|
||||
event.useTravelAgent(true);
|
||||
}
|
||||
}
|
@ -9,114 +9,19 @@ package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.destination.CannonDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TravelAgent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The Multiverse-{@link TravelAgent}.
|
||||
* The Multiverse TravelAgent.
|
||||
*/
|
||||
public class MVTravelAgent implements TravelAgent {
|
||||
private MVDestination destination;
|
||||
private MultiverseCore core;
|
||||
private Player player;
|
||||
public class MVTravelAgent {
|
||||
protected MVDestination destination;
|
||||
protected MultiverseCore core;
|
||||
protected Player player;
|
||||
|
||||
public MVTravelAgent(MultiverseCore multiverseCore, MVDestination d, Player p) {
|
||||
this.destination = d;
|
||||
this.core = multiverseCore;
|
||||
this.player = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public TravelAgent setSearchRadius(int radius) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getSearchRadius() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public TravelAgent setCreationRadius(int radius) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getCreationRadius() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getCanCreatePortal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setCanCreatePortal(boolean create) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location findOrCreate(Location location) {
|
||||
return this.getSafeLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location findPortal(Location location) {
|
||||
return this.getSafeLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean createPortal(Location location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Location getSafeLocation() {
|
||||
// At this time, these can never use the velocity.
|
||||
if (this.destination instanceof CannonDestination) {
|
||||
this.core.log(Level.FINE, "Using Stock TP method. This cannon will have 0 velocity");
|
||||
}
|
||||
SafeTTeleporter teleporter = this.core.getSafeTTeleporter();
|
||||
Location newLoc = this.destination.getLocation(this.player);
|
||||
if (this.destination.useSafeTeleporter()) {
|
||||
newLoc = teleporter.getSafeLocation(this.player, this.destination);
|
||||
}
|
||||
if (newLoc == null) {
|
||||
return this.player.getLocation();
|
||||
}
|
||||
return newLoc;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user