From 774dbbc2917ca7a11185415bacad06890eef0b2b Mon Sep 17 00:00:00 2001 From: Cola Date: Thu, 1 Jul 2021 12:21:53 +0100 Subject: [PATCH 1/4] v1.10.2 - Java 16 & 1.17 --- pom.xml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index e0fb7e8..cad192d 100644 --- a/pom.xml +++ b/pom.xml @@ -10,9 +10,8 @@ 1.0.0 - com.wimbli.WorldBorder WorldBorder - 1.10.1 + 1.10.2 WorldBorder https://github.com/Civclassic/WorldBorder @@ -25,14 +24,18 @@ dynmap-repo https://repo.mikeprimm.com/ + + papermc + https://papermc.io/repo/repository/maven-public/ + - com.destroystokyo.paper + io.papermc.paper paper-api - 1.16.4-R0.1-SNAPSHOT + 1.17-R0.1-SNAPSHOT provided From 5005cbdc6f998e1d335a355a526483b0501076fb Mon Sep 17 00:00:00 2001 From: Cola Date: Thu, 1 Jul 2021 12:24:40 +0100 Subject: [PATCH 2/4] Commit taken from PryPurity, attempt to fix WB killing/spawn issue --- .../com/wimbli/WorldBorder/BorderData.java | 157 +++++++++++++++++- 1 file changed, 152 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/wimbli/WorldBorder/BorderData.java b/src/main/java/com/wimbli/WorldBorder/BorderData.java index b64144e..abe470d 100644 --- a/src/main/java/com/wimbli/WorldBorder/BorderData.java +++ b/src/main/java/com/wimbli/WorldBorder/BorderData.java @@ -486,9 +486,156 @@ else if (obj == null || obj.getClass() != this.getClass()) return test.x == this.x && test.z == this.z && test.radiusX == this.radiusX && test.radiusZ == this.radiusZ; } - @Override - public int hashCode() - { - return (((int)(this.x * 10) << 4) + (int)this.z + (this.radiusX << 2) + (this.radiusZ << 3)); - } + double xLoc = loc.getX(); + double zLoc = loc.getZ(); + double yLoc = loc.getY(); + + // square border + if (!round) { + if (wrapping) { + if (xLoc <= minX) + xLoc = maxX - Config.KnockBack(); + else if (xLoc >= maxX) + xLoc = minX + Config.KnockBack(); + if (zLoc <= minZ) + zLoc = maxZ - Config.KnockBack(); + else if (zLoc >= maxZ) + zLoc = minZ + Config.KnockBack(); + } else { + if (xLoc <= minX) + xLoc = minX + Config.KnockBack(); + else if (xLoc >= maxX) + xLoc = maxX - Config.KnockBack(); + if (zLoc <= minZ) + zLoc = minZ + Config.KnockBack(); + else if (zLoc >= maxZ) + zLoc = maxZ - Config.KnockBack(); + } + } + + // round border + else { + // algorithm originally from: http://stackoverflow.com/questions/300871/best-way-to-find-a-point-on-a-circle-closest-to-a-given-point + // modified by Lang Lukas to support elliptical border shape + + //Transform the ellipse to a circle with radius 1 (we need to transform the point the same way) + double dX = xLoc - x; + double dZ = zLoc - z; + double dU = Math.sqrt(dX * dX + dZ * dZ); //distance of the untransformed point from the center + double dT = Math.sqrt(dX * dX / radiusXSquared + dZ * dZ / radiusZSquared); //distance of the transformed point from the center + double f = (1 / dT - Config.KnockBack() / dU); //"correction" factor for the distances + if (wrapping) { + xLoc = x - dX * f; + zLoc = z - dZ * f; + } else { + xLoc = x + dX * f; + zLoc = z + dZ * f; + } + } + + int ixLoc = Location.locToBlock(xLoc); + int izLoc = Location.locToBlock(zLoc); + + // Make sure the chunk we're checking in is actually loaded + Chunk tChunk = loc.getWorld().getChunkAt(CoordXZ.blockToChunk(ixLoc), CoordXZ.blockToChunk(izLoc)); + if (!tChunk.isLoaded()) + tChunk.load(); + + yLoc = getSafeY(loc.getWorld(), ixLoc, Location.locToBlock(yLoc), izLoc, flying); + if (yLoc == -1) + return null; + + return new Location(loc.getWorld(), Math.floor(xLoc) + 0.5, yLoc, Math.floor(zLoc) + 0.5, loc.getYaw(), loc.getPitch()); + } + + public Location correctedPosition(Location loc, boolean round) { + return correctedPosition(loc, round, false); + } + + public Location correctedPosition(Location loc) { + return correctedPosition(loc, Config.ShapeRound(), false); + } + + // check if a particular spot consists of 2 breathable blocks over something relatively solid + private boolean isSafeSpot(World world, int X, int Y, int Z, boolean flying) { + boolean safe = + // target block open and safe or is above maximum Y coordinate + (Y == world.getMaxHeight() + || (safeOpenBlocks.contains(world.getBlockAt(X, Y, Z).getType()) + // above target block open and safe or is above maximum Y coordinate + && (Y + 1 == world.getMaxHeight() + || safeOpenBlocks.contains(world.getBlockAt(X, Y + 1, Z).getType())))); + if (!safe || flying) + return safe; + + Material below = world.getBlockAt(X, Y - 1, Z).getType(); + // below target block not open/breathable (so presumably solid), or is water + // below target block not painful + // below target block not painful + return (!safeOpenBlocks.contains(below) || below == Material.WATER) && !painfulBlocks.contains(below); + } + + // find closest safe Y position from the starting position + private double getSafeY(World world, int X, int Y, int Z, boolean flying) { + // artificial height limit of 127 added for Nether worlds since CraftBukkit still incorrectly returns 255 for their max height, leading to players sent to the "roof" of the Nether + final boolean isNether = world.getEnvironment() == World.Environment.NETHER; + int limTop = isNether ? 125 : world.getMaxHeight(); + final int highestBlockBoundary = Math.min(world.getHighestBlockYAt(X, Z) + 1, limTop); + + // if Y is larger than the world can be and user can fly, return Y - Unless we are in the Nether, we might not want players on the roof + if (flying && Y > limTop && !isNether) + return Y; + + // make sure Y values are within the boundaries of the world. + if (Y > limTop) { + if (isNether) + Y = limTop; // because of the roof, the nether can not rely on highestBlockBoundary, so limTop has to be used + else { + if (flying) + Y = limTop; + else + Y = highestBlockBoundary; // there will never be a save block to stand on for Y values > highestBlockBoundary + } + } + if (Y < limBot) + Y = limBot; + + // for non Nether worlds we don't need to check upwards to the world-limit, it is enough to check up to the highestBlockBoundary, unless player is flying + if (!isNether && !flying) + limTop = highestBlockBoundary + 1; + // Expanding Y search method adapted from Acru's code in the Nether plugin + + for (int y1 = Y, y2 = Y; (y1 > limBot) || (y2 < limTop); y1--, y2++) { + // Look below. + if (y1 > limBot) { + if (isSafeSpot(world, X, y1, Z, flying)) + return y1; + } + + // Look above. + if (y2 <= limTop && y2 != y1) { + if (isSafeSpot(world, X, y2, Z, flying)) + return y2; + } + } + + return -1.0; // no safe Y location?!?!? Must be a rare spot in a Nether world or something + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + else if (obj == null || obj.getClass() != this.getClass()) + return false; + + BorderData test = (BorderData) obj; + return test.x == this.x && test.z == this.z && test.radiusX == this.radiusX && test.radiusZ == this.radiusZ; + } + + @Override + public int hashCode() { + return (((int) (this.x * 10) << 4) + (int) this.z + (this.radiusX << 2) + (this.radiusZ << 3)); + } } From cfacb1dcf4545f3cd4779caa4947820aec05d7ab Mon Sep 17 00:00:00 2001 From: Cola Date: Thu, 1 Jul 2021 12:24:40 +0100 Subject: [PATCH 3/4] Revert "Commit taken from PryPurity, attempt to fix WB killing/spawn issue" This reverts commit 5005cbdc6f998e1d335a355a526483b0501076fb. --- .../com/wimbli/WorldBorder/BorderData.java | 157 +----------------- 1 file changed, 5 insertions(+), 152 deletions(-) diff --git a/src/main/java/com/wimbli/WorldBorder/BorderData.java b/src/main/java/com/wimbli/WorldBorder/BorderData.java index abe470d..b64144e 100644 --- a/src/main/java/com/wimbli/WorldBorder/BorderData.java +++ b/src/main/java/com/wimbli/WorldBorder/BorderData.java @@ -486,156 +486,9 @@ else if (obj == null || obj.getClass() != this.getClass()) return test.x == this.x && test.z == this.z && test.radiusX == this.radiusX && test.radiusZ == this.radiusZ; } - double xLoc = loc.getX(); - double zLoc = loc.getZ(); - double yLoc = loc.getY(); - - // square border - if (!round) { - if (wrapping) { - if (xLoc <= minX) - xLoc = maxX - Config.KnockBack(); - else if (xLoc >= maxX) - xLoc = minX + Config.KnockBack(); - if (zLoc <= minZ) - zLoc = maxZ - Config.KnockBack(); - else if (zLoc >= maxZ) - zLoc = minZ + Config.KnockBack(); - } else { - if (xLoc <= minX) - xLoc = minX + Config.KnockBack(); - else if (xLoc >= maxX) - xLoc = maxX - Config.KnockBack(); - if (zLoc <= minZ) - zLoc = minZ + Config.KnockBack(); - else if (zLoc >= maxZ) - zLoc = maxZ - Config.KnockBack(); - } - } - - // round border - else { - // algorithm originally from: http://stackoverflow.com/questions/300871/best-way-to-find-a-point-on-a-circle-closest-to-a-given-point - // modified by Lang Lukas to support elliptical border shape - - //Transform the ellipse to a circle with radius 1 (we need to transform the point the same way) - double dX = xLoc - x; - double dZ = zLoc - z; - double dU = Math.sqrt(dX * dX + dZ * dZ); //distance of the untransformed point from the center - double dT = Math.sqrt(dX * dX / radiusXSquared + dZ * dZ / radiusZSquared); //distance of the transformed point from the center - double f = (1 / dT - Config.KnockBack() / dU); //"correction" factor for the distances - if (wrapping) { - xLoc = x - dX * f; - zLoc = z - dZ * f; - } else { - xLoc = x + dX * f; - zLoc = z + dZ * f; - } - } - - int ixLoc = Location.locToBlock(xLoc); - int izLoc = Location.locToBlock(zLoc); - - // Make sure the chunk we're checking in is actually loaded - Chunk tChunk = loc.getWorld().getChunkAt(CoordXZ.blockToChunk(ixLoc), CoordXZ.blockToChunk(izLoc)); - if (!tChunk.isLoaded()) - tChunk.load(); - - yLoc = getSafeY(loc.getWorld(), ixLoc, Location.locToBlock(yLoc), izLoc, flying); - if (yLoc == -1) - return null; - - return new Location(loc.getWorld(), Math.floor(xLoc) + 0.5, yLoc, Math.floor(zLoc) + 0.5, loc.getYaw(), loc.getPitch()); - } - - public Location correctedPosition(Location loc, boolean round) { - return correctedPosition(loc, round, false); - } - - public Location correctedPosition(Location loc) { - return correctedPosition(loc, Config.ShapeRound(), false); - } - - // check if a particular spot consists of 2 breathable blocks over something relatively solid - private boolean isSafeSpot(World world, int X, int Y, int Z, boolean flying) { - boolean safe = - // target block open and safe or is above maximum Y coordinate - (Y == world.getMaxHeight() - || (safeOpenBlocks.contains(world.getBlockAt(X, Y, Z).getType()) - // above target block open and safe or is above maximum Y coordinate - && (Y + 1 == world.getMaxHeight() - || safeOpenBlocks.contains(world.getBlockAt(X, Y + 1, Z).getType())))); - if (!safe || flying) - return safe; - - Material below = world.getBlockAt(X, Y - 1, Z).getType(); - // below target block not open/breathable (so presumably solid), or is water - // below target block not painful - // below target block not painful - return (!safeOpenBlocks.contains(below) || below == Material.WATER) && !painfulBlocks.contains(below); - } - - // find closest safe Y position from the starting position - private double getSafeY(World world, int X, int Y, int Z, boolean flying) { - // artificial height limit of 127 added for Nether worlds since CraftBukkit still incorrectly returns 255 for their max height, leading to players sent to the "roof" of the Nether - final boolean isNether = world.getEnvironment() == World.Environment.NETHER; - int limTop = isNether ? 125 : world.getMaxHeight(); - final int highestBlockBoundary = Math.min(world.getHighestBlockYAt(X, Z) + 1, limTop); - - // if Y is larger than the world can be and user can fly, return Y - Unless we are in the Nether, we might not want players on the roof - if (flying && Y > limTop && !isNether) - return Y; - - // make sure Y values are within the boundaries of the world. - if (Y > limTop) { - if (isNether) - Y = limTop; // because of the roof, the nether can not rely on highestBlockBoundary, so limTop has to be used - else { - if (flying) - Y = limTop; - else - Y = highestBlockBoundary; // there will never be a save block to stand on for Y values > highestBlockBoundary - } - } - if (Y < limBot) - Y = limBot; - - // for non Nether worlds we don't need to check upwards to the world-limit, it is enough to check up to the highestBlockBoundary, unless player is flying - if (!isNether && !flying) - limTop = highestBlockBoundary + 1; - // Expanding Y search method adapted from Acru's code in the Nether plugin - - for (int y1 = Y, y2 = Y; (y1 > limBot) || (y2 < limTop); y1--, y2++) { - // Look below. - if (y1 > limBot) { - if (isSafeSpot(world, X, y1, Z, flying)) - return y1; - } - - // Look above. - if (y2 <= limTop && y2 != y1) { - if (isSafeSpot(world, X, y2, Z, flying)) - return y2; - } - } - - return -1.0; // no safe Y location?!?!? Must be a rare spot in a Nether world or something - } - - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - else if (obj == null || obj.getClass() != this.getClass()) - return false; - - BorderData test = (BorderData) obj; - return test.x == this.x && test.z == this.z && test.radiusX == this.radiusX && test.radiusZ == this.radiusZ; - } - - @Override - public int hashCode() { - return (((int) (this.x * 10) << 4) + (int) this.z + (this.radiusX << 2) + (this.radiusZ << 3)); - } + @Override + public int hashCode() + { + return (((int)(this.x * 10) << 4) + (int)this.z + (this.radiusX << 2) + (this.radiusZ << 3)); + } } From 61bc82ce450d231a2cb082e19679615014b0b84e Mon Sep 17 00:00:00 2001 From: Cola Date: Sat, 17 Jul 2021 13:31:56 +0100 Subject: [PATCH 4/4] Copy commit from PryPurity/WorldBorder ffcf3ab5f81117e14900f3f8da240aaa4411d249 --- .../java/com/wimbli/WorldBorder/BorderData.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/wimbli/WorldBorder/BorderData.java b/src/main/java/com/wimbli/WorldBorder/BorderData.java index b64144e..5e134da 100644 --- a/src/main/java/com/wimbli/WorldBorder/BorderData.java +++ b/src/main/java/com/wimbli/WorldBorder/BorderData.java @@ -407,8 +407,13 @@ public Location correctedPosition(Location loc) // check if a particular spot consists of 2 breathable blocks over something relatively solid private boolean isSafeSpot(World world, int X, int Y, int Z, boolean flying) { - boolean safe = safeOpenBlocks.contains(world.getBlockAt(X, Y, Z).getType()) // target block open and safe - && safeOpenBlocks.contains(world.getBlockAt(X, Y + 1, Z).getType()); // above target block open and safe + boolean safe = + // target block open and safe or is above maximum Y coordinate + (Y == world.getMaxHeight() + || (safeOpenBlocks.contains(world.getBlockAt(X, Y, Z).getType()) + // above target block open and safe or is above maximum Y coordinate + && (Y + 1 == world.getMaxHeight() + || safeOpenBlocks.contains(world.getBlockAt(X, Y + 1, Z).getType())))); if (!safe || flying) return safe; @@ -426,7 +431,7 @@ private double getSafeY(World world, int X, int Y, int Z, boolean flying) { // artificial height limit of 127 added for Nether worlds since CraftBukkit still incorrectly returns 255 for their max height, leading to players sent to the "roof" of the Nether final boolean isNether = world.getEnvironment() == World.Environment.NETHER; - int limTop = isNether ? 125 : world.getMaxHeight() - 2; + int limTop = isNether ? 125 : world.getMaxHeight(); final int highestBlockBoundary = Math.min(world.getHighestBlockYAt(X, Z) + 1, limTop); // if Y is larger than the world can be and user can fly, return Y - Unless we are in the Nether, we might not want players on the roof @@ -451,7 +456,7 @@ private double getSafeY(World world, int X, int Y, int Z, boolean flying) // for non Nether worlds we don't need to check upwards to the world-limit, it is enough to check up to the highestBlockBoundary, unless player is flying if (!isNether && !flying) - limTop = highestBlockBoundary; + limTop = highestBlockBoundary + 1; // Expanding Y search method adapted from Acru's code in the Nether plugin for(int y1 = Y, y2 = Y; (y1 > limBot) || (y2 < limTop); y1--, y2++){ @@ -463,7 +468,7 @@ private double getSafeY(World world, int X, int Y, int Z, boolean flying) } // Look above. - if(y2 < limTop && y2 != y1) + if(y2 <= limTop && y2 != y1) { if (isSafeSpot(world, X, y2, Z, flying)) return y2;