From 2e06140e801e9ebb786d8109164f62948582a681 Mon Sep 17 00:00:00 2001 From: sauilitired Date: Sun, 24 May 2015 03:15:30 +0200 Subject: [PATCH] Fixes #199 --- .../plot/commands/Set.java | 4 +- .../plot/database/SQLManager.java | 4 +- .../plot/object/BlockLoc.java | 37 ++++++++++++++++++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java index de9b86ada..8998d2eff 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -163,9 +163,9 @@ public class Set extends SubCommand { final Location base = MainUtil.getPlotBottomLoc(world, plot.id); base.setY(0); final Location relative = plr.getLocation().subtract(base.getX(), base.getY(), base.getZ()); - final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ()); + final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ(), relative.getY(), relative.getPitch()); plot.settings.setPosition(blockloc); - DBFunc.setPosition(loc.getWorld(), plot, relative.getX() + "," + relative.getY() + "," + relative.getZ()); + DBFunc.setPosition(loc.getWorld(), plot, blockloc.toString()); return MainUtil.sendMessage(plr, C.POSITION_SET); } if (args[0].equalsIgnoreCase("alias")) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 3fa6f9628..0403a3b92 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -913,9 +913,7 @@ public class SQLManager implements AbstractDB { break; default: try { - final String[] split = pos.split(","); - final BlockLoc loc = new BlockLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])); - plot.settings.setPosition(loc); + plot.settings.setPosition(BlockLoc.fromString(pos)); } catch (final Exception e) { } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java index b2bf235c3..9c3bdf075 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java @@ -5,10 +5,19 @@ public class BlockLoc { public int y; public int z; - public BlockLoc(final int x, final int y, final int z) { + public float yaw, pitch; + + public BlockLoc(final int x, final int y, final int z, final float yaw, final float pitch) { this.x = x; this.y = y; this.z = z; + + this.yaw = yaw; + this.pitch = pitch; + } + + public BlockLoc(final int x, final int y, final int z) { + this(x, y, z, 0f, 0f); } @Override @@ -35,4 +44,30 @@ public class BlockLoc { final BlockLoc other = (BlockLoc) obj; return ((this.x == other.x) && (this.y == other.y) && (this.z == other.z)); } + + @Override + public String toString() { + return + x + "," + y + "," + z + "," + yaw + "," + pitch; + } + + public static BlockLoc fromString(final String string) { + String[] parts = string.split(","); + + float yaw, pitch; + if (parts.length == 3) { + yaw = 0f; + pitch = 0f; + } if (parts.length == 5) { + yaw = Float.parseFloat(parts[3]); + pitch = Float.parseFloat(parts[4]); + } else { + return new BlockLoc(0, 0, 0); + } + int x = Integer.parseInt(parts[0]); + int y = Integer.parseInt(parts[1]); + int z = Integer.parseInt(parts[2]); + + return new BlockLoc(x, y, z, yaw, pitch); + } }