2012-12-22 19:46:24 +01:00
|
|
|
package org.bukkit.craftbukkit;
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
import net.minecraft.server.BlockPosition;
|
2012-12-22 19:46:24 +01:00
|
|
|
import net.minecraft.server.PortalTravelAgent;
|
|
|
|
import net.minecraft.server.WorldServer;
|
|
|
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.TravelAgent;
|
|
|
|
|
|
|
|
public class CraftTravelAgent extends PortalTravelAgent implements TravelAgent {
|
|
|
|
|
2013-02-03 20:55:51 +01:00
|
|
|
public static TravelAgent DEFAULT = null;
|
|
|
|
|
2012-12-22 19:46:24 +01:00
|
|
|
private int searchRadius = 128;
|
|
|
|
private int creationRadius = 16;
|
|
|
|
private boolean canCreatePortal = true;
|
|
|
|
|
|
|
|
public CraftTravelAgent(WorldServer worldserver) {
|
|
|
|
super(worldserver);
|
2013-02-03 20:55:51 +01:00
|
|
|
if (DEFAULT == null && worldserver.dimension == 0) {
|
2013-02-05 21:34:02 +01:00
|
|
|
DEFAULT = this;
|
2013-02-03 20:55:51 +01:00
|
|
|
}
|
2012-12-22 19:46:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
@Override
|
2012-12-22 19:46:24 +01:00
|
|
|
public Location findOrCreate(Location target) {
|
|
|
|
WorldServer worldServer = ((CraftWorld) target.getWorld()).getHandle();
|
|
|
|
boolean before = worldServer.chunkProviderServer.forceChunkLoad;
|
|
|
|
worldServer.chunkProviderServer.forceChunkLoad = true;
|
|
|
|
|
|
|
|
Location found = this.findPortal(target);
|
|
|
|
if (found == null) {
|
|
|
|
if (this.getCanCreatePortal() && this.createPortal(target)) {
|
|
|
|
found = this.findPortal(target);
|
|
|
|
} else {
|
|
|
|
found = target; // fallback to original if unable to find or create
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
worldServer.chunkProviderServer.forceChunkLoad = before;
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
@Override
|
2012-12-22 19:46:24 +01:00
|
|
|
public Location findPortal(Location location) {
|
2014-03-21 05:26:30 +01:00
|
|
|
PortalTravelAgent pta = ((CraftWorld) location.getWorld()).getHandle().getTravelAgent();
|
2014-11-25 22:32:16 +01:00
|
|
|
BlockPosition found = pta.findPortal(location.getX(), location.getY(), location.getZ(), this.getSearchRadius());
|
|
|
|
return found != null ? new Location(location.getWorld(), found.getX(), found.getY(), found.getZ(), location.getYaw(), location.getPitch()) : null;
|
2012-12-22 19:46:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
@Override
|
2012-12-22 19:46:24 +01:00
|
|
|
public boolean createPortal(Location location) {
|
2014-03-21 05:26:30 +01:00
|
|
|
PortalTravelAgent pta = ((CraftWorld) location.getWorld()).getHandle().getTravelAgent();
|
2012-12-22 19:46:24 +01:00
|
|
|
return pta.createPortal(location.getX(), location.getY(), location.getZ(), this.getCreationRadius());
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
@Override
|
2012-12-22 19:46:24 +01:00
|
|
|
public TravelAgent setSearchRadius(int radius) {
|
|
|
|
this.searchRadius = radius;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
@Override
|
2012-12-22 19:46:24 +01:00
|
|
|
public int getSearchRadius() {
|
|
|
|
return this.searchRadius;
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
@Override
|
2012-12-22 19:46:24 +01:00
|
|
|
public TravelAgent setCreationRadius(int radius) {
|
|
|
|
this.creationRadius = radius < 2 ? 0 : radius;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
@Override
|
2012-12-22 19:46:24 +01:00
|
|
|
public int getCreationRadius() {
|
|
|
|
return this.creationRadius;
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
@Override
|
2012-12-22 19:46:24 +01:00
|
|
|
public boolean getCanCreatePortal() {
|
|
|
|
return this.canCreatePortal;
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
@Override
|
2012-12-22 19:46:24 +01:00
|
|
|
public void setCanCreatePortal(boolean create) {
|
|
|
|
this.canCreatePortal = create;
|
|
|
|
}
|
|
|
|
}
|