Skip to content

Commit 42f289f

Browse files
authored
Update 1.0.6: Calculate safe spawn and fix plot unlink not clearing blocks above the wall (#7)
* Check if custom plot home position is on the plot * Fix plot unlink not clearing blocks above the wall * Bump version to 1.0.6
1 parent 13826a0 commit 42f289f

4 files changed

Lines changed: 123 additions & 14 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ms.kevi</groupId>
88
<artifactId>plotplugin</artifactId>
9-
<version>1.0.5</version>
9+
<version>1.0.6</version>
1010

1111
<properties>
1212
<maven.compiler.source>17</maven.compiler.source>

src/main/java/ms/kevi/plotplugin/manager/PlotManager.java

Lines changed: 117 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import cn.nukkit.blockstate.BlockState;
2424
import cn.nukkit.entity.Entity;
2525
import cn.nukkit.level.Level;
26-
import cn.nukkit.level.Location;
2726
import cn.nukkit.level.format.FullChunk;
2827
import cn.nukkit.level.format.generic.BaseFullChunk;
2928
import cn.nukkit.math.BlockVector3;
@@ -510,6 +509,7 @@ private void finishPlotUnlink(List<PlotId> plots) {
510509
final Plot plot = this.getPlotById(plotId);
511510
this.changeBorder(plot, plot.hasOwner() ? claimBlock : wallBlock);
512511
this.changeWall(plot, wallFillingBlock);
512+
this.clearWallAbove(plot);
513513
plot.recalculateOrigin();
514514
this.savePlots();
515515
}
@@ -794,6 +794,93 @@ public void changeBorder(Plot plot, BlockState blockState) {
794794
asyncLevelWorker.runQueue();
795795
}
796796

797+
public void clearWallAbove(Plot plot) {
798+
final BlockState blockState = BlockState.AIR;
799+
final BlockVector3 bottom = this.getExtendedBottomPlotPos(plot).subtract(plot.isMerged(3) ? 1 : 0, 0, plot.isMerged(0) ? 1 : 0);
800+
final BlockVector3 top = this.getExtendedTopPlotPos(plot).add(1, 0, 1);
801+
final AsyncLevelWorker asyncLevelWorker = new AsyncLevelWorker(this.level);
802+
final int minY = LevelUtils.getChunkMinY(this.levelSettings.getDimension()) + this.levelSettings.getGroundHeight() + 2;
803+
final int maxY = LevelUtils.getChunkMaxY(this.levelSettings.getDimension());
804+
805+
if(!plot.isMerged(0)) {
806+
final int z = bottom.getZ();
807+
asyncLevelWorker.queueFill(
808+
new BlockVector3(bottom.getX(), minY, z),
809+
new BlockVector3(top.getX() - 1, maxY, z),
810+
blockState
811+
);
812+
} else {
813+
final Plot rPlot = this.getPlotById(plot.getRelative(0));
814+
if(rPlot.isMerged(1) && !plot.isMerged(1)) {
815+
final int z = bottom.getZ();
816+
asyncLevelWorker.queueFill(
817+
new BlockVector3(top.getX(), minY, z),
818+
new BlockVector3(this.getExtendedTopPlotPos(rPlot).getX() - 1, maxY, z),
819+
blockState
820+
);
821+
}
822+
}
823+
824+
if(!plot.isMerged(3)) {
825+
final int x = bottom.getX();
826+
asyncLevelWorker.queueFill(
827+
new BlockVector3(x, minY, bottom.getZ()),
828+
new BlockVector3(x, maxY, top.getZ() - 1),
829+
blockState
830+
);
831+
} else {
832+
final Plot rPlot = this.getPlotById(plot.getRelative(3));
833+
if(rPlot.isMerged(0) && !plot.isMerged(0)) {
834+
final int z = this.getBottomPlotPos(plot).getZ();
835+
asyncLevelWorker.queueFill(
836+
new BlockVector3(this.getBottomPlotPos(plot).getX(), minY, z),
837+
new BlockVector3(bottom.getX() - 1, maxY, z),
838+
blockState
839+
);
840+
}
841+
}
842+
843+
if(!plot.isMerged(2)) {
844+
final int z = top.getZ();
845+
asyncLevelWorker.queueFill(
846+
new BlockVector3(bottom.getX(), minY, z),
847+
new BlockVector3(top.getX() + (plot.isMerged(1) ? -1 : 0), maxY, z),
848+
blockState
849+
);
850+
} else {
851+
final Plot rPlot = this.getPlotById(plot.getRelative(2));
852+
if(rPlot.isMerged(3) && !plot.isMerged(3)) {
853+
final int z = top.getZ() - 1;
854+
asyncLevelWorker.queueFill(
855+
new BlockVector3(this.getExtendedBottomPlotPos(rPlot).getX() - 1, minY, z),
856+
new BlockVector3(bottom.getX() - 1, maxY, z),
857+
blockState
858+
);
859+
}
860+
}
861+
862+
if(!plot.isMerged(1)) {
863+
final int x = top.getX();
864+
asyncLevelWorker.queueFill(
865+
new BlockVector3(x, minY, bottom.getZ()),
866+
new BlockVector3(x, maxY, top.getZ() + (plot.isMerged(2) ? -1 : 0)),
867+
blockState
868+
);
869+
} else {
870+
final Plot rPlot = this.getPlotById(plot.getRelative(1));
871+
if(rPlot.isMerged(2) && !plot.isMerged(2)) {
872+
final int x = top.getX() - 1;
873+
asyncLevelWorker.queueFill(
874+
new BlockVector3(x, minY, top.getZ()),
875+
new BlockVector3(x, maxY, this.getExtendedTopPlotPos(rPlot).getZ() - 1),
876+
blockState
877+
);
878+
}
879+
}
880+
881+
asyncLevelWorker.runQueue();
882+
}
883+
797884
public void changeWall(Plot plot, BlockState blockState) {
798885
final BlockVector3 bottom = this.getExtendedBottomPlotPos(plot).subtract(plot.isMerged(3) ? 1 : 0, 0, plot.isMerged(0) ? 1 : 0);
799886
final BlockVector3 top = this.getExtendedTopPlotPos(plot).add(1, 0, 1);
@@ -1038,23 +1125,43 @@ public void teleportPlayerToPlot(Player player, Plot plot) {
10381125
}
10391126

10401127
public void teleportPlayerToPlot(Player player, Plot plot, boolean homeAllowed) {
1041-
Vector3 plotVec = this.getPosByPlot(plot.getBasePlot()).add(
1042-
((float) this.levelSettings.getPlotSize() / 2),
1043-
1f,
1044-
-1.5f
1045-
);
1128+
Vector3 plotVec = null;
10461129

10471130
if(homeAllowed) {
10481131
final Vector3 homePosition = plot.getHomePosition();
10491132
if(homePosition != null) plotVec = homePosition.clone();
1133+
1134+
if(plotVec != null) {
1135+
final Plot mergedPlot = this.getMergedPlot(plotVec.getFloorX(), plotVec.getFloorZ());
1136+
if(mergedPlot == null || !plot.getBasePlot().equals(mergedPlot.getBasePlot())) {
1137+
plot.setHomePosition(null);
1138+
this.savePlots();
1139+
plotVec = null;
1140+
}
1141+
}
10501142
}
10511143

1052-
for(int y = plotVec.getFloorY(); this.level.isOverWorld() ? y <= 319 : y <= 255; y++) {
1053-
plotVec.setY(y);
1054-
if(this.level.standable(plotVec)) break;
1144+
if(plotVec == null)
1145+
plotVec = this.getPosByPlot(plot.getBasePlot()).add(
1146+
((float) this.levelSettings.getPlotSize() / 2),
1147+
1f,
1148+
-1.5f
1149+
);
1150+
1151+
final int y = plotVec.getFloorY();
1152+
final int minY = LevelUtils.getChunkMinY(this.levelSettings.getDimension());
1153+
final int maxY = LevelUtils.getChunkMaxY(this.levelSettings.getDimension());
1154+
for(int offset = 0; ; offset++) {
1155+
if(plotVec.getY() < minY && plotVec.getY() > maxY) break;
1156+
1157+
plotVec.setY(y - offset);
1158+
if(plotVec.getY() >= minY && plotVec.getY() <= maxY && this.level.standable(plotVec)) break;
1159+
1160+
plotVec.setY(y + offset);
1161+
if(plotVec.getY() >= minY && plotVec.getY() <= maxY && this.level.standable(plotVec)) break;
10551162
}
10561163

1057-
player.teleport(plotVec);
1164+
player.teleport(plotVec.add(0, 0.1, 0));
10581165
}
10591166

10601167
}

src/main/java/ms/kevi/plotplugin/util/async/AsyncLevelWorker.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ public void queueFill(BlockVector3 startPos, BlockVector3 endPos, BlockState blo
5454
if(fullChunk == null) continue;
5555
this.addChunk(fullChunk);
5656

57-
for(int y = startPos.getY(); y <= endPos.getY(); y++)
58-
fullChunk.setBlockState(x & 15, y, z & 15, blockState);
57+
for(int y = startPos.getY(); y <= endPos.getY(); y++) {
58+
fullChunk.setBlockStateAtLayer(x & 15, y, z & 15, 0, blockState);
59+
fullChunk.setBlockStateAtLayer(x & 15, y, z & 15, 1, blockState);
60+
}
5961
}
6062
}
6163
});

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Plots
2-
version: "1.0.5"
2+
version: "1.0.6"
33
api: [ "1.0.13" ]
44
author: Kevims
55
main: ms.kevi.plotplugin.PlotPlugin

0 commit comments

Comments
 (0)