Skip to content

Commit 6a4cd97

Browse files
committed
Add some small example for patter usage inside of the worldedit context for edit regions by plugins.
This example describe so far it possible the edit process and the async process to edit a region with a specific biome.
1 parent 0eeb156 commit 6a4cd97

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Filling a region using a pattern
2+
3+
## Foreword
4+
First of all, patterns usually come from the core part of Worleedit or FAWE. The patterns can be found in the following path: [worldedit-core/src/main/java/com/fastasyncworldedit/core/function/pattern](https://intellectualsites.github.io/fastasyncworldedit-javadocs/worldedit-core/com/fastasyncworldedit/core/extension/factory/parser/pattern/package-summary.html)
5+
6+
_The link refers you to the JavaDocs with the correct package_
7+
8+
In this example, we only refer to one pattern for the time being.
9+
10+
## Biome Cuboid Example
11+
Given are 3 things:
12+
- Position1: X=300, y=-64, z=300
13+
- Position2: X=600, y=128, z=600
14+
- BiomeType: Badlands
15+
16+
```java
17+
// Here we must first adapt the world as in the WorldEdit example or translate it into the WorldEdit specialized object.
18+
World faweWorld = BukkitAdapter.adapt(world);
19+
20+
// Here we set our position 1 and 2
21+
BlockVector3 position1 = BlockVector3.at(300,-64,300);
22+
BlockVector3 position2 = BlockVector3.at(600,128,600);
23+
24+
//Now we define a square region using our 2 positions
25+
CuboidRegion cuboidRegion = new CuboidRegion(position1, position2);
26+
27+
// Now we open an EditSession, which contains the complete process or information during an edit process in the world. Through the try-and-catch-with-resources we let Java automatically close the resource EditSession after use
28+
try (EditSession editSession = WorldEdit.getInstance().newEditSession(faweWorld)) {
29+
// Here we create our biome pattern
30+
var pattern = new BiomeApplyingPattern(editSession, BiomeTypes.BADLANDS);
31+
32+
//This sets the pattern to the region
33+
editSession.setBlocks((Region) cuboidRegion, pattern);
34+
}
35+
```
36+
_This code is still Fawe unspecific and can also be used in WorldEdit in this way_
37+
38+
### Let's set blocks async with FAWE
39+
{% hint style="info" %}
40+
**Recommended**
41+
42+
If no plug-in instance is available, you can also use the Task Manger. See below
43+
{% endhint %}
44+
Now we run the code Async to let Fawe manage server resources:
45+
```java
46+
// Now we wrap our code in a runnable with a functional interface and have it executed by Bukkit's scheduler system
47+
Runnable executeCode = () -> {
48+
// Now we open an EditSession, which contains the complete process or information during an edit process in the world. Through the try-and-catch-with-resources we let Java automatically close the resource EditSession after use
49+
try (EditSession editSession = WorldEdit.getInstance().newEditSession(faweWorld)) {
50+
// Here we create our biome pattern
51+
var pattern = new BiomeApplyingPattern(editSession, BiomeTypes.BADLANDS);
52+
53+
//This sets the pattern to the region
54+
editSession.setBlocks((Region) cuboidRegion, pattern);
55+
}
56+
};
57+
Bukkit.getScheduler().runTask(Bukkit.getPluginManager().getPlugin("YourPluginNameHere"), executeCode);
58+
```
59+
60+
---
61+
62+
We can also use the TaskManger from Fawe. To do this, we only need to replace a call.
63+
64+
65+
```java
66+
// Now we wrap our code in a runnable with a functional interface and have it executed by Bukkit's scheduler system
67+
Runnable executeCode = () -> {
68+
// Now we open an EditSession, which contains the complete process or information during an edit process in the world. Through the try-and-catch-with-resources we let Java automatically close the resource EditSession after use
69+
try (EditSession editSession = WorldEdit.getInstance().newEditSession(faweWorld)) {
70+
// Here we create our biome pattern
71+
var pattern = new BiomeApplyingPattern(editSession, BiomeTypes.BADLANDS);
72+
73+
//This sets the pattern to the region
74+
editSession.setBlocks((Region) cuboidRegion, pattern);
75+
}
76+
};
77+
TaskManager.taskManager().taskNow(executeCode, true); // The second parameter specifies whether it should run async or sync.
78+
```

fastasyncworldedit/API/api-usage.md renamed to fastasyncworldedit/API/get-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# API Usage
1+
# Get Started
22

33
## Maven & Gradle Examples
44

fastasyncworldedit/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
## API
2424

25-
* [API Usage](./API/api-usage.md)
25+
* [API Usage](./API/get-started)
2626

2727
## Basic Commands
2828

0 commit comments

Comments
 (0)