|
23 | 23 | import cn.nukkit.blockstate.BlockState; |
24 | 24 | import cn.nukkit.entity.Entity; |
25 | 25 | import cn.nukkit.level.Level; |
26 | | -import cn.nukkit.level.Location; |
27 | 26 | import cn.nukkit.level.format.FullChunk; |
28 | 27 | import cn.nukkit.level.format.generic.BaseFullChunk; |
29 | 28 | import cn.nukkit.math.BlockVector3; |
@@ -510,6 +509,7 @@ private void finishPlotUnlink(List<PlotId> plots) { |
510 | 509 | final Plot plot = this.getPlotById(plotId); |
511 | 510 | this.changeBorder(plot, plot.hasOwner() ? claimBlock : wallBlock); |
512 | 511 | this.changeWall(plot, wallFillingBlock); |
| 512 | + this.clearWallAbove(plot); |
513 | 513 | plot.recalculateOrigin(); |
514 | 514 | this.savePlots(); |
515 | 515 | } |
@@ -794,6 +794,93 @@ public void changeBorder(Plot plot, BlockState blockState) { |
794 | 794 | asyncLevelWorker.runQueue(); |
795 | 795 | } |
796 | 796 |
|
| 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 | + |
797 | 884 | public void changeWall(Plot plot, BlockState blockState) { |
798 | 885 | final BlockVector3 bottom = this.getExtendedBottomPlotPos(plot).subtract(plot.isMerged(3) ? 1 : 0, 0, plot.isMerged(0) ? 1 : 0); |
799 | 886 | final BlockVector3 top = this.getExtendedTopPlotPos(plot).add(1, 0, 1); |
@@ -1038,23 +1125,43 @@ public void teleportPlayerToPlot(Player player, Plot plot) { |
1038 | 1125 | } |
1039 | 1126 |
|
1040 | 1127 | 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; |
1046 | 1129 |
|
1047 | 1130 | if(homeAllowed) { |
1048 | 1131 | final Vector3 homePosition = plot.getHomePosition(); |
1049 | 1132 | 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 | + } |
1050 | 1142 | } |
1051 | 1143 |
|
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; |
1055 | 1162 | } |
1056 | 1163 |
|
1057 | | - player.teleport(plotVec); |
| 1164 | + player.teleport(plotVec.add(0, 0.1, 0)); |
1058 | 1165 | } |
1059 | 1166 |
|
1060 | 1167 | } |
0 commit comments