Skip to content

Commit 7b69860

Browse files
authored
Update 1.2.2
Fix PlotManager#getMergedPlot again and optimize PlotManager#getPlotById
1 parent 66cb85c commit 7b69860

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

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.2.1</version>
9+
<version>1.2.2</version>
1010

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

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,23 @@ public Plot getMergedPlot(int x, int z) {
127127
final int plotSize = this.levelSettings.getPlotSize();
128128
final int totalSize = this.levelSettings.getTotalSize();
129129

130-
final int idX = x >= 0 ? x / totalSize : (x / totalSize) - 1;
131-
final int idZ = x >= 0 ? z / totalSize : (z / totalSize) - 1;
130+
final int idX = x >= 0 ? x / totalSize : ((x + 1) / totalSize) - 1;
131+
final int idZ = z >= 0 ? z / totalSize : ((z + 1) / totalSize) - 1;
132132

133-
final int difX = x >= 0 ? x % totalSize : Math.abs((x - plotSize + 1) % totalSize);
134-
final int difZ = z >= 0 ? z % totalSize : Math.abs((z - plotSize + 1) % totalSize);
133+
final int difX = x >= 0 ? (x + 1) % totalSize : totalSize + ((x + 1) % totalSize);
134+
final int difZ = z >= 0 ? (z + 1) % totalSize : totalSize + ((z + 1) % totalSize);
135+
136+
final boolean xOnRoad = difX > plotSize || difX == 0;
137+
final boolean zOnRoad = difZ > plotSize || difZ == 0;
135138

136139
final Plot plot = this.getPlotById(PlotId.of(idX, idZ));
137-
if(difX > plotSize - 1 && difZ > plotSize - 1) {
140+
if(xOnRoad && zOnRoad) {
138141
if(plot.isMerged(5)) return plot;
139142
return null;
140-
} else if(difX > plotSize - 1) {
143+
} else if(xOnRoad) {
141144
if(plot.isMerged(1)) return plot;
142145
return null;
143-
} else if(difZ > plotSize - 1) {
146+
} else if(zOnRoad) {
144147
if(plot.isMerged(2)) return plot;
145148
return null;
146149
} else {
@@ -159,13 +162,16 @@ private PlotId getPlotIdByPos(int x, int z) {
159162
final int plotSize = this.levelSettings.getPlotSize();
160163
final int totalSize = plotSize + this.levelSettings.getRoadSize();
161164

162-
final int idX = x >= 0 ? x / totalSize : (x / totalSize) - 1;
163-
final int idZ = x >= 0 ? z / totalSize : (z / totalSize) - 1;
165+
final int idX = x >= 0 ? x / totalSize : ((x + 1) / totalSize) - 1;
166+
final int idZ = z >= 0 ? z / totalSize : ((z + 1) / totalSize) - 1;
167+
168+
final int difX = x >= 0 ? (x + 1) % totalSize : totalSize + ((x + 1) % totalSize);
169+
final int difZ = z >= 0 ? (z + 1) % totalSize : totalSize + ((z + 1) % totalSize);
164170

165-
final int difX = x >= 0 ? x % totalSize : Math.abs((x - plotSize + 1) % totalSize);
166-
final int difZ = z >= 0 ? z % totalSize : Math.abs((z - plotSize + 1) % totalSize);
171+
final boolean xOnRoad = difX > plotSize || difX == 0;
172+
final boolean zOnRoad = difZ > plotSize || difZ == 0;
167173

168-
if((difX > plotSize - 1) || (difZ > plotSize - 1)) return null;
174+
if(xOnRoad || zOnRoad) return null;
169175
return PlotId.of(idX, idZ);
170176
}
171177

@@ -1162,21 +1168,16 @@ public ShapeType[] getShapes(int x, int z) {
11621168
final int plotSize = this.levelSettings.getPlotSize();
11631169
final ShapeType[] shapes = new ShapeType[256];
11641170

1165-
int posX;
1166-
if(x >= 0) posX = x % totalSize;
1167-
else posX = totalSize - Math.abs(x % totalSize);
1168-
1169-
int posZ;
1170-
if(z >= 0) posZ = z % totalSize;
1171-
else posZ = totalSize - Math.abs(z % totalSize);
1171+
int posX = x >= 0 ? x % totalSize : totalSize + (x % totalSize);
1172+
int posZ = z >= 0 ? z % totalSize : totalSize + (z % totalSize);
11721173

1173-
int startX = posX;
1174+
final int startX = posX;
11741175
for(int zBlock = 0; zBlock < 16; zBlock++, posZ++) {
11751176
if(posZ == totalSize) posZ = 0;
11761177

11771178
final ShapeType typeZ;
11781179
if(posZ < plotSize) typeZ = ShapeType.PLOT;
1179-
else if(posZ == plotSize || posZ == (totalSize - 1)) typeZ = ShapeType.WALL;
1180+
else if(posZ == plotSize || posZ == totalSize - 1) typeZ = ShapeType.WALL;
11801181
else typeZ = ShapeType.ROAD;
11811182

11821183
posX = startX;
@@ -1185,7 +1186,7 @@ public ShapeType[] getShapes(int x, int z) {
11851186

11861187
final ShapeType typeX;
11871188
if(posX < plotSize) typeX = ShapeType.PLOT;
1188-
else if(posX == plotSize || posX == (totalSize - 1)) typeX = ShapeType.WALL;
1189+
else if(posX == plotSize || posX == totalSize - 1) typeX = ShapeType.WALL;
11891190
else typeX = ShapeType.ROAD;
11901191

11911192
final ShapeType type;

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.2.1"
2+
version: "1.2.2"
33
api: [ "1.0.13" ]
44
author: Kevims
55
main: ms.kevi.plotplugin.PlotPlugin

0 commit comments

Comments
 (0)