Fix teleportOnLogin error

This commit is contained in:
Jesse Boyd 2019-04-19 12:53:48 +10:00
parent 8ac23b92d8
commit 815e513093
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F

View File

@ -462,8 +462,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
*/ */
public void unregister() { public void unregister() {
Plot plot = getCurrentPlot(); Plot plot = getCurrentPlot();
if (plot != null && Settings.Enabled_Components.PERSISTENT_META && plot if (plot != null && Settings.Enabled_Components.PERSISTENT_META && plot.getArea() instanceof SinglePlotArea) {
.getArea() instanceof SinglePlotArea) {
PlotId id = plot.getId(); PlotId id = plot.getId();
int x = id.x; int x = id.x;
int z = id.y; int z = id.y;
@ -538,16 +537,28 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
@Override public void run(Map<String, byte[]> value) { @Override public void run(Map<String, byte[]> value) {
try { try {
PlotPlayer.this.metaMap = value; PlotPlayer.this.metaMap = value;
if (!value.isEmpty()) { if (value.isEmpty()) {
if (Settings.Enabled_Components.PERSISTENT_META) { return;
}
if (!Settings.Enabled_Components.PERSISTENT_META) {
return;
}
PlotAreaManager manager = PlotSquared.get().getPlotAreaManager(); PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) {
if (!(manager instanceof SinglePlotAreaManager)) {
return;
}
PlotArea area = ((SinglePlotAreaManager) manager).getArea(); PlotArea area = ((SinglePlotAreaManager) manager).getArea();
byte[] arr = PlotPlayer.this.getPersistentMeta("quitLoc"); byte[] arr = PlotPlayer.this.getPersistentMeta("quitLoc");
if (arr != null) { if (arr == null) {
return;
}
removePersistentMeta("quitLoc"); removePersistentMeta("quitLoc");
if (getMeta("teleportOnLogin", true)) { if (!getMeta("teleportOnLogin", true)) {
return;
}
ByteBuffer quitWorld = ByteBuffer.wrap(arr); ByteBuffer quitWorld = ByteBuffer.wrap(arr);
final int plotX = quitWorld.getShort(); final int plotX = quitWorld.getShort();
final int plotZ = quitWorld.getShort(); final int plotZ = quitWorld.getShort();
@ -556,44 +567,33 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
int y = quitWorld.get() & 0xFF; int y = quitWorld.get() & 0xFF;
int z = quitWorld.getInt(); int z = quitWorld.getInt();
Plot plot = area.getOwnedPlot(id); Plot plot = area.getOwnedPlot(id);
if (plot != null) {
final Location loc = if (plot == null) {
new Location(plot.getWorldName(), x, y, z); return;
}
final Location loc = new Location(plot.getWorldName(), x, y, z);
if (plot.isLoaded()) { if (plot.isLoaded()) {
TaskManager.runTask(() -> { TaskManager.runTask(() -> {
if (getMeta("teleportOnLogin", true)) { if (getMeta("teleportOnLogin", true)) {
teleport(loc); teleport(loc);
sendMessage( sendMessage(Captions.TELEPORTED_TO_PLOT.f() + " (quitLoc) (" + plotX + "," + plotZ + ")");
Captions.TELEPORTED_TO_PLOT.f()
+ " (quitLoc) (" + plotX + ","
+ plotZ + ")");
} }
}); });
} else if (!PlotSquared.get() } else if (!PlotSquared.get().isMainThread(Thread.currentThread())) {
.isMainThread(Thread.currentThread())) {
if (getMeta("teleportOnLogin", true)) { if (getMeta("teleportOnLogin", true)) {
if (plot.teleportPlayer(PlotPlayer.this)) { if (plot.teleportPlayer(PlotPlayer.this)) {
TaskManager.runTask(() -> { TaskManager.runTask(() -> {
if (getMeta("teleportOnLogin", if (getMeta("teleportOnLogin",true)) {
true)) { if (plot.isLoaded()) {
teleport(loc); teleport(loc);
sendMessage( sendMessage(Captions.TELEPORTED_TO_PLOT.f() + " (quitLoc-unloaded) (" + plotX + "," + plotZ + ")");
Captions.TELEPORTED_TO_PLOT }
.f()
+ " (quitLoc-unloaded) ("
+ plotX + "," + plotZ
+ ")");
} }
}); });
} }
} }
} }
}
}
}
}
}
}
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }