geforkt von Mirrors/Paper
5bb81b75c7
Currently, CraftTravelAgent will call s() on the passed-in WorldServer in order to set DEFAULT. However, s() will always return null at this point, because WorldServer.P will still be null, as it is set after the constructor is called. Instead, we set CraftTravelAgent.DEFAULT to the instance that is being constructed.
80 Zeilen
2.6 KiB
Java
80 Zeilen
2.6 KiB
Java
package org.bukkit.craftbukkit;
|
|
|
|
import net.minecraft.server.ChunkCoordinates;
|
|
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 {
|
|
|
|
public static TravelAgent DEFAULT = null;
|
|
|
|
private int searchRadius = 128;
|
|
private int creationRadius = 16;
|
|
private boolean canCreatePortal = true;
|
|
|
|
public CraftTravelAgent(WorldServer worldserver) {
|
|
super(worldserver);
|
|
if (DEFAULT == null && worldserver.dimension == 0) {
|
|
DEFAULT = this;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public Location findPortal(Location location) {
|
|
PortalTravelAgent pta = ((CraftWorld) location.getWorld()).getHandle().s();
|
|
ChunkCoordinates found = pta.findPortal(location.getX(), location.getY(), location.getZ(), this.getSearchRadius());
|
|
return found != null ? new Location(location.getWorld(), found.x, found.y, found.z, location.getYaw(), location.getPitch()) : null;
|
|
}
|
|
|
|
public boolean createPortal(Location location) {
|
|
PortalTravelAgent pta = ((CraftWorld) location.getWorld()).getHandle().s();
|
|
return pta.createPortal(location.getX(), location.getY(), location.getZ(), this.getCreationRadius());
|
|
}
|
|
|
|
public TravelAgent setSearchRadius(int radius) {
|
|
this.searchRadius = radius;
|
|
return this;
|
|
}
|
|
|
|
public int getSearchRadius() {
|
|
return this.searchRadius;
|
|
}
|
|
|
|
public TravelAgent setCreationRadius(int radius) {
|
|
this.creationRadius = radius < 2 ? 0 : radius;
|
|
return this;
|
|
}
|
|
|
|
public int getCreationRadius() {
|
|
return this.creationRadius;
|
|
}
|
|
|
|
public boolean getCanCreatePortal() {
|
|
return this.canCreatePortal;
|
|
}
|
|
|
|
public void setCanCreatePortal(boolean create) {
|
|
this.canCreatePortal = create;
|
|
}
|
|
}
|