Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor, optimise and simplify the Cheese API #12

Merged
merged 10 commits into from
Mar 28, 2024
11 changes: 0 additions & 11 deletions .idea/runConfigurations/Benchmark_Cheese_10.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/runConfigurations/Benchmark_Cheese_11.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/runConfigurations/Benchmark_Cheese_12.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/runConfigurations/Benchmark_Cheese_13.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/runConfigurations/Benchmark_Cheese_14.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/runConfigurations/Benchmark_Cheese_15.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/runConfigurations/Benchmark_Cheese_16.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Benchmark_Unsafe_Cheese_10.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Benchmark_Unsafe_Cheese_11.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Benchmark_Unsafe_Cheese_12.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Benchmark_Unsafe_Cheese_13.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Benchmark_Unsafe_Cheese_14.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Benchmark_Unsafe_Cheese_15.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Benchmark_Unsafe_Cheese_16.xml

This file was deleted.

66 changes: 38 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,48 @@ BMSkin.getPlayerHeadIconAddress(BlueMapAPI, UUID playerUUID, BlueMapMap)
With the Cheese class, you can create a [BlueMap Shape](https://bluecolored.de/bluemapapi/latest/de/bluecolored/bluemap/api/math/Shape.html) from a collection of chunks.\
Useful for when you want to create a marker around a claimed area.

To get started, feed a list of Chunk coordinates into `createPlatterFromChunks()`.\
This will return a collection of Cheese objects, which you can use to create your markers.

The Platter functions return multiple Cheeses; a "platter" of them, if you will.\
It does this, because the input chunk coordinates might not be all connected,
which means you have to create multiple markers for the same claimed area.

<details>
<summary>Full code example</summary>
<summary>Full Platter code example</summary>

```java
@Event
void onPlayerClaimEvent(Player player, Town claimedTown) {
//assuming a class member of Map<World, MarkerSet> markerSetMap;
MarkerSet markerSet = markerSetMap.get(claimedTown.getWorld());

Collection<Vector2i> chunkCoordinates = claimedTown.getClaimedChunks().stream()
.map(chunk -> new Vector2i(chunk.getX(), chunk.getZ()))
.collect(Collectors.toList());

Cheese cheese = Cheese.createFromChunks(chunkCoordinates);
ExtrudeMarker.builder()
.label(claimedTown.getName())
.shape(cheese.getShape())
.holes(cheese.getHoles())
//...
.build();
Collection<Cheese> platter = Cheese.createPlatterFromChunks(chunkCoordinates);
for (int i = 0; i < platter.size(); i++) {
Cheese cheese = platter[i];
ShapeMarker chunkMarker = new ShapeMarker.Builder()
.label(claimedTown.getName())
.shape(cheese.getShape())
.holes(cheese.getHoles())
//...
.build();
markerSet.put("town-" + claimedTown.getName() + "-segment-" + i, chunkMarker);
}
}
```

**Note:** You should probably run this on a separate thread, as to not block the main server thread!
</details>

You can use `Cheese.createFromCells` to create a Cheese from a collection of non-16x16 cells,
in case your area data isn't chunk-based.

This function works only on areas that are all connected.
It will throw an `InvalidSelectionException` if the areas are separated.\
So for those situations where you have areas that are potentially separated,
you should use the `Cheese.createMultiCheeseFromChunks` function, instead.
If you're absolutely 100% sure your input chunk coordinates are all connected,
due to your chunk claiming system ensuring that already,
you can use `createSingleFromChunks()` to create a single Cheese.

<details>
<summary>Full code example</summary>
<summary>Full Single code example</summary>

```java
@Event
Expand All @@ -135,22 +145,22 @@ void onPlayerClaimEvent(Player player, Town claimedTown) {
.map(chunk -> new Vector2i(chunk.getX(), chunk.getZ()))
.collect(Collectors.toList());

Collection<Cheese> cheeses = Cheese.createMultiCheeseFromChunks(chunkCoordinates);
for (int i = 0; i < cheeses.size(); i++) {
Cheese cheese = cheeses[i];
ShapeMarker chunkMarker = new ShapeMarker.Builder()
.label(claimedTown.getName())
.shape(cheese.getShape())
.holes(cheese.getHoles())
//...
.build();
markerSet.put("town-" + claimedTown.getName() + "-segment-" + i, chunkMarker);
}
Cheese cheese = Cheese.createFromChunks(chunkCoordinates);
ShapeMarker chunkMarker = new ExtrudeMarker.builder()
.label(claimedTown.getName())
.shape(cheese.getShape())
.holes(cheese.getHoles())
//...
.build();
markerSet.put("town-" + claimedTown.getName(), chunkMarker);
}
```

</details>

If your area data isn't chunk-based, you can use the Cells functions, instead of the Chunks functions,
to create a Cheese from a collection of non-16x16 cells.

_Thanks to [@TBlueF](https://github.com/TBlueF) for contributing this function, and the funny name!_

### Expand/Shrink a Shape
Expand Down
Loading