|
| 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. |
0 commit comments