66import com .sk89q .worldedit .regions .CuboidRegion ;
77import dev .frankheijden .insights .api .addons .InsightsAddon ;
88import dev .frankheijden .insights .api .addons .Region ;
9- import dev .frankheijden .insights .api .addons . SimpleMultiCuboidRegion ;
9+ import dev .frankheijden .insights .api .objects . chunk . ChunkPart ;
1010import dev .frankheijden .insights .api .objects .math .Cuboid ;
1111import dev .frankheijden .insights .api .objects .math .Vector3 ;
1212import org .bukkit .World ;
13- import java .util .ArrayList ;
1413import java .util .Collection ;
1514import java .util .List ;
1615import java .util .Optional ;
1716import java .util .Set ;
17+ import java .util .stream .Collectors ;
1818
1919public class PlotSquaredAddon implements InsightsAddon {
2020
@@ -29,27 +29,26 @@ private String getRawId(Collection<? extends Plot> plots) {
2929 }
3030 return sb .substring (1 );
3131 }
32+
33+ private Cuboid adapt (CuboidRegion region , World world ) {
34+ BlockVector3 min = region .getMinimumPoint ();
35+ BlockVector3 max = region .getMaximumPoint ();
36+ return new Cuboid (
37+ world ,
38+ new Vector3 (min .getX (), min .getY (), min .getZ ()),
39+ new Vector3 (max .getX (), max .getY (), max .getZ ())
40+ );
41+ }
3242
3343 public Optional <Region > adapt (Plot basePlot , World world ) {
3444 if (basePlot == null ) return Optional .empty ();
3545
36- Set <CuboidRegion > regions = basePlot .getRegions ();
37- if (regions .isEmpty ()) return Optional .empty ();
38-
39- List <Cuboid > cuboids = new ArrayList <>(regions .size ());
40- for (CuboidRegion region : regions ) {
41- BlockVector3 min = region .getMinimumPoint ();
42- BlockVector3 max = region .getMaximumPoint ();
43- cuboids .add (new Cuboid (
44- world ,
45- new Vector3 (min .getX (), min .getY (), min .getZ ()),
46- new Vector3 (max .getX (), max .getY (), max .getZ ())
47- ));
48- }
46+ Set <CuboidRegion > cuboids = basePlot .getRegions ();
47+ if (cuboids .isEmpty ()) return Optional .empty ();
4948
50- return Optional .of (new SimpleMultiCuboidRegion (
49+ return Optional .of (new PlotSquaredRegion (
50+ world ,
5151 cuboids ,
52- getPluginName (),
5352 getId (basePlot .getConnectedPlots ())
5453 ));
5554 }
@@ -78,4 +77,34 @@ public Optional<Region> getRegion(org.bukkit.Location location) {
7877 location .getBlockZ ()
7978 ).getOwnedPlotAbs (), location .getWorld ());
8079 }
80+
81+ public class PlotSquaredRegion implements Region {
82+
83+ private final World world ;
84+ private final Set <CuboidRegion > cuboids ;
85+ private final String key ;
86+
87+ public PlotSquaredRegion (World world , Set <CuboidRegion > cuboids , String key ) {
88+ this .world = world ;
89+ this .cuboids = cuboids ;
90+ this .key = key ;
91+ }
92+
93+ @ Override
94+ public String getAddon () {
95+ return getPluginName ();
96+ }
97+
98+ @ Override
99+ public String getKey () {
100+ return key ;
101+ }
102+
103+ @ Override
104+ public List <ChunkPart > toChunkParts () {
105+ return cuboids .stream ()
106+ .flatMap (cuboid -> adapt (cuboid , world ).toChunkParts ().stream ())
107+ .collect (Collectors .toList ());
108+ }
109+ }
81110}
0 commit comments