-
Notifications
You must be signed in to change notification settings - Fork 0
/
CraftTravelAgent.java
85 lines (68 loc) · 2.49 KB
/
CraftTravelAgent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package org.bukkit.craftbukkit;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Teleporter;
import net.minecraft.world.WorldServer;
import org.bukkit.Location;
import org.bukkit.TravelAgent;
public class CraftTravelAgent extends Teleporter 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;
}
}
@Override
public Location findOrCreate(Location target) {
WorldServer worldServer = ((CraftWorld) target.getWorld()).getHandle();
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
}
}
return found;
}
@Override
public Location findPortal(Location location) {
Teleporter pta = ((CraftWorld) location.getWorld()).getHandle().getDefaultTeleporter();
BlockPos 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;
}
@Override
public boolean createPortal(Location location) {
Teleporter pta = ((CraftWorld) location.getWorld()).getHandle().getDefaultTeleporter();
return pta.createPortal(location.getX(), location.getY(), location.getZ(), this.getCreationRadius());
}
@Override
public TravelAgent setSearchRadius(int radius) {
this.searchRadius = radius;
return this;
}
@Override
public int getSearchRadius() {
return this.searchRadius;
}
@Override
public TravelAgent setCreationRadius(int radius) {
this.creationRadius = radius < 2 ? 0 : radius;
return this;
}
@Override
public int getCreationRadius() {
return this.creationRadius;
}
@Override
public boolean getCanCreatePortal() {
return this.canCreatePortal;
}
@Override
public void setCanCreatePortal(boolean create) {
this.canCreatePortal = create;
}
}