Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 35 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PlayerCoordsAPI provides real-time access to your Minecraft player coordinates t
- Lightweight HTTP server running only on localhost providing your coordinates
- Client-side only - no server-side components needed
- Works in singleplayer and multiplayer
- Mod menu integration allowing you to enable/disable the API and configure CORS
- Mod menu integration allowing you to enable/disable the API, change its port, and configure requests with or without an `Origin` header

## 🚀 Installation

Expand All @@ -27,27 +27,27 @@ PlayerCoordsAPI provides real-time access to your Minecraft player coordinates t
3. Place the jar in your `.minecraft/mods` folder
4. Launch Minecraft with the Fabric profile

## 🔌 API Usage
## ⚙️ Configuration

| Endpoint | Method | Description |
|---------------|--------|----------------------------------------------------------|
| `/api/coords` | `GET` | Returns the player's current coordinates and world infos |
The API is read-only and only accepts loopback connections such as `127.0.0.1` and `::1`.
From Mod Menu, you can configure:
- Whether the API is enabled
- Which port it listens on (default: `25565`)
- How requests without a CORS `Origin` header are handled
- How requests with a CORS `Origin` header are handled

### Response Format
Requests with an `Origin` can be handled in three different modes:
- `Allow all`
- `Local origins`
- `Whitelist`

```json
{
"x": 123.45,
"y": 64.00,
"z": -789.12,
"yaw": 180.00,
"pitch": 12.50,
"world": "minecraft:overworld",
"biome": "minecraft:plains",
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"username": "PlayerName"
}
```
In `Whitelist` mode, you can configure each allowed origin with a scheme, host/IP, and optional port.

## 🔌 API Usage

| Endpoint | Method | Description |
|---------------|-----------------|----------------------------------------------------------|
| `/api/coords` | `GET`, `OPTIONS` | Returns the player's current coordinates and world infos |

### Response Fields

Expand All @@ -71,16 +71,26 @@ PlayerCoordsAPI provides real-time access to your Minecraft player coordinates t
| `404` | Player not in world |
| `405` | Method not allowed |

## 🔒 Security
### Response Format Example

For security reasons, the API server:
- Only accepts connections from loopback addresses such as `127.0.0.1` and `::1`
- Runs on port `25565` by default
- Provides read-only access to player position data
- Uses a configurable CORS policy. By default it allows all origins for backward compatibility, but you can restrict it in the config screen
```json
{
"x": 123.45,
"y": 64.00,
"z": -789.12,
"yaw": 180.00,
"pitch": 12.50,
"world": "minecraft:overworld",
"biome": "minecraft:plains",
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"username": "PlayerName"
}
```

## 🛠️ Examples

Replace `25565` with your configured port if you changed it in the Mod Menu.

### cURL
```bash
curl http://localhost:25565/api/coords
Expand Down
23 changes: 0 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ base {
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven {
name = "Terraformers"
url = "https://maven.terraformersmc.com/releases" // Mod Menu repo requires explicit releases path on CI
Expand All @@ -36,25 +31,16 @@ loom {
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Sun's HTTP server is included in JDK, no additional dependency needed

// Mod Menu
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"

// Cloth Config
modImplementation "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}"
}

processResources {
// Keep fabric.mod.json versions in sync with gradle.properties
inputs.property "version", project.version
inputs.property "loader_version", project.loader_version
inputs.property "minecraft_version", project.minecraft_version
Expand All @@ -79,9 +65,6 @@ tasks.withType(JavaCompile).configureEach {
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
Expand All @@ -100,7 +83,6 @@ jar {
}
}

// configure the maven publication
publishing {
publications {
create("mavenJava", MavenPublication) {
Expand All @@ -109,11 +91,6 @@ publishing {
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loader_version=0.18.4
loom_version=1.15.4

# Mod Properties
mod_version=0.1.5
mod_version=0.2.0
maven_group=fr.sukikui.playercoordsapi
archives_base_name=playercoordsapi

Expand Down
Loading