Skip to content

Commit eaafe38

Browse files
committed
a lot of changes
1 parent 71dc640 commit eaafe38

File tree

26 files changed

+1511
-1330
lines changed

26 files changed

+1511
-1330
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,40 @@ You can combine it with `use-group-permissions` and your group policies.
6363
## Placeholders (PlaceholderAPI)
6464
- `%extendedhorizons_view_distance%` — current effective distance
6565

66+
---
67+
68+
## API for Developers
69+
70+
ExtendedHorizons provides a comprehensive API for other plugins to interact with fake chunks.
71+
72+
### Documentation
73+
- **[Full API Documentation](API-USAGE.md)** - Complete guide with examples
74+
- **[Example Plugin](examples/)** - Working example showing all API features
75+
76+
### Quick Example
77+
```java
78+
// Access the API
79+
ExtendedHorizonsAPI api = ExtendedHorizonsPlugin.getService(ExtendedHorizonsAPI.class);
80+
81+
// Check if player is looking at a fake chunk
82+
int chunkX = player.getLocation().getBlockX() >> 4;
83+
int chunkZ = player.getLocation().getBlockZ() >> 4;
84+
if (api.isFakeChunk(player, chunkX, chunkZ)) {
85+
player.sendMessage("You're in a fake chunk!");
86+
}
87+
88+
// Get all fake chunks for a player
89+
Set<ChunkCoordinate> chunks = api.getFakeChunksForPlayer(player);
90+
player.sendMessage("Loaded: " + chunks.size() + " fake chunks");
91+
```
92+
93+
### Available Events
94+
- `FakeChunkLoadEvent` - When a fake chunk is loaded (cancellable)
95+
- `FakeChunkUnloadEvent` - When a fake chunk is unloaded
96+
- `FakeChunkBatchLoadEvent` - When multiple chunks are loaded at once
97+
98+
See **[API-USAGE.md](API-USAGE.md)** for complete documentation.
99+
66100
---
67101
# Support
68102
- Report issues and suggestions in the repository’s Issues section.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = 'me.mapacheee'
9-
version = '2.3.3'
9+
version = '2.3.4'
1010
description = 'ExtendedHorizons - Advanced view distance extension plugin'
1111

1212
java {

examples/README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# ExtendedHorizons API Example Plugin
2+
3+
This is a complete, working example plugin that demonstrates how to use the ExtendedHorizons API.
4+
5+
6+
## Building This Example
7+
8+
1. **Copy the ExtendedHorizons JAR** to `libs/` folder:
9+
```bash
10+
mkdir libs
11+
cp ../build/libs/ExtendedHorizons-2.3.3.jar libs/
12+
```
13+
14+
2. **Build the plugin**:
15+
```bash
16+
./gradlew jar
17+
```
18+
19+
3. **Find the JAR** in `build/libs/ExamplePlugin-1.0.0.jar`
20+
21+
## Testing This Example
22+
23+
1. Install both ExtendedHorizons and ExamplePlugin on your server
24+
2. Join the server
25+
3. Use the commands:
26+
- `/fakechunkinfo` - Shows your current fake chunk status
27+
- `/clearfakechunks` - Clears all your fake chunks
28+
- `/refreshfakechunks` - Refreshes your fake chunks
29+
30+
## Files Explained
31+
32+
### build.gradle
33+
Shows how to configure your Gradle build to depend on ExtendedHorizons.
34+
35+
**Key points:**
36+
- Uses `compileOnly` for ExtendedHorizons (it will be on the server at runtime)
37+
- Includes the JAR from a local `libs/` folder
38+
- Sets up Paper API dependency
39+
40+
### plugin.yml
41+
Shows the required configuration.
42+
43+
**Key points:**
44+
- `depend: [ExtendedHorizons]` ensures ExtendedHorizons loads first
45+
- Defines commands for testing
46+
47+
### ExamplePlugin.java
48+
The main plugin class showing all API features.
49+
50+
**Key sections:**
51+
- `setupAPI()` - How to safely access the API
52+
- `displayAPIStats()` - Using cache statistics methods
53+
- `showFakeChunkInfo()` - Using player-specific methods
54+
- Event handlers - How to listen to chunk events
55+
56+
## Using This as a Template
57+
58+
1. Copy this `examples/` folder as your project base
59+
2. Rename the package from `com.example.exampleplugin` to your own
60+
3. Update `plugin.yml` with your plugin information
61+
4. Modify `ExamplePlugin.java` to add your own logic
62+
5. Build and test!
63+
64+
## Common Modifications
65+
66+
### Make ExtendedHorizons Optional
67+
68+
Change `plugin.yml`:
69+
```yaml
70+
softdepend: [ExtendedHorizons] # Instead of depend
71+
```
72+
73+
Then check if it's available:
74+
```java
75+
@Override
76+
public void onEnable() {
77+
if (!setupAPI()) {
78+
getLogger().warning("ExtendedHorizons not found, some features disabled");
79+
// Continue loading with limited features
80+
}
81+
}
82+
```
83+
84+
### Track Chunk Statistics
85+
86+
```java
87+
private int totalChunksLoaded = 0;
88+
private int totalChunksUnloaded = 0;
89+
90+
@EventHandler
91+
public void onFakeChunkLoad(FakeChunkLoadEvent event) {
92+
totalChunksLoaded++;
93+
}
94+
95+
@EventHandler
96+
public void onFakeChunkUnload(FakeChunkUnloadEvent event) {
97+
totalChunksUnloaded++;
98+
}
99+
```
100+
101+
### Restrict Fake Chunks to Specific Regions
102+
103+
```java
104+
@EventHandler
105+
public void onFakeChunkLoad(FakeChunkLoadEvent event) {
106+
int chunkX = event.getChunkX();
107+
int chunkZ = event.getChunkZ();
108+
109+
// Only allow fake chunks in spawn area (-100 to +100)
110+
if (Math.abs(chunkX) > 100 || Math.abs(chunkZ) > 100) {
111+
event.setCancelled(true);
112+
}
113+
}
114+
```
115+
116+
## Troubleshooting
117+
118+
### "Cannot find symbol" errors when building
119+
120+
Make sure:
121+
1. ExtendedHorizons JAR is in the `libs/` folder
122+
2. The JAR filename matches what's in `build.gradle`
123+
3. You've run `./gradlew build` at least once
124+
125+
### "ExtendedHorizons" plugin not found error
126+
127+
Make sure:
128+
1. ExtendedHorizons is installed on your server
129+
2. It's in the `plugins/` folder
130+
3. It loads before your plugin (check `depend:` in plugin.yml)
131+
132+
### API returns null
133+
134+
This usually means:
135+
1. ExtendedHorizons isn't properly loaded
136+
2. You're calling `getService()` too early (before plugin is enabled)
137+
3. Version mismatch between your plugin and ExtendedHorizons
138+
139+
## More Information
140+
141+
See [API-USAGE.md](../API-USAGE.md) for complete API documentation.

examples/build.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group = 'com.example'
6+
version = '1.0.0'
7+
8+
repositories {
9+
mavenCentral()
10+
maven {
11+
name = 'papermc-repo'
12+
url = 'https://repo.papermc.io/repository/maven-public/'
13+
}
14+
}
15+
16+
dependencies {
17+
// Paper API
18+
compileOnly 'io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT'
19+
20+
// ExtendedHorizons API
21+
compileOnly('ExtendedHorizons-2.3.3.jar')
22+
}
23+
24+
java {
25+
toolchain.languageVersion = JavaLanguageVersion.of(21)
26+
}
27+
28+
tasks.withType(JavaCompile).configureEach {
29+
options.encoding = 'UTF-8'
30+
}
31+
32+
jar {
33+
archiveBaseName = 'ExamplePlugin'
34+
archiveVersion = project.version
35+
}

0 commit comments

Comments
 (0)