Skip to content

Commit de9bca2

Browse files
authored
Merge pull request #31 from Sukikui/feature/port-api-refine
Refine local API config and CORS
2 parents 7871fb4 + 61ebf28 commit de9bca2

21 files changed

Lines changed: 1142 additions & 432 deletions

File tree

README.md

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PlayerCoordsAPI provides real-time access to your Minecraft player coordinates t
1818
- Lightweight HTTP server running only on localhost providing your coordinates
1919
- Client-side only - no server-side components needed
2020
- Works in singleplayer and multiplayer
21-
- Mod menu integration allowing you to enable/disable the API and configure CORS
21+
- Mod menu integration allowing you to enable/disable the API, change its port, and configure requests with or without an `Origin` header
2222

2323
## 🚀 Installation
2424

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

30-
## 🔌 API Usage
30+
## ⚙️ Configuration
3131

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

36-
### Response Format
39+
Requests with an `Origin` can be handled in three different modes:
40+
- `Allow all`
41+
- `Local origins`
42+
- `Whitelist`
3743

38-
```json
39-
{
40-
"x": 123.45,
41-
"y": 64.00,
42-
"z": -789.12,
43-
"yaw": 180.00,
44-
"pitch": 12.50,
45-
"world": "minecraft:overworld",
46-
"biome": "minecraft:plains",
47-
"uuid": "550e8400-e29b-41d4-a716-446655440000",
48-
"username": "PlayerName"
49-
}
50-
```
44+
In `Whitelist` mode, you can configure each allowed origin with a scheme, host/IP, and optional port.
45+
46+
## 🔌 API Usage
47+
48+
| Endpoint | Method | Description |
49+
|---------------|-----------------|----------------------------------------------------------|
50+
| `/api/coords` | `GET`, `OPTIONS` | Returns the player's current coordinates and world infos |
5151

5252
### Response Fields
5353

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

74-
## 🔒 Security
74+
### Response Format Example
7575

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

8290
## 🛠️ Examples
8391

92+
Replace `25565` with your configured port if you changed it in the Mod Menu.
93+
8494
### cURL
8595
```bash
8696
curl http://localhost:25565/api/coords

build.gradle

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ base {
1111
}
1212

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

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

44-
// Fabric API. This is technically optional, but you probably want it anyway.
4538
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
46-
47-
// Sun's HTTP server is included in JDK, no additional dependency needed
48-
49-
// Mod Menu
5039
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
51-
52-
// Cloth Config
5340
modImplementation "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}"
5441
}
5542

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

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

8770
sourceCompatibility = JavaVersion.VERSION_21
@@ -100,7 +83,6 @@ jar {
10083
}
10184
}
10285

103-
// configure the maven publication
10486
publishing {
10587
publications {
10688
create("mavenJava", MavenPublication) {
@@ -109,11 +91,6 @@ publishing {
10991
}
11092
}
11193

112-
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
11394
repositories {
114-
// Add repositories to publish to here.
115-
// Notice: This block does NOT have the same function as the block in the top level.
116-
// The repositories here will be used for publishing your artifact, not for
117-
// retrieving dependencies.
11895
}
11996
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ loader_version=0.18.4
99
loom_version=1.15.4
1010

1111
# Mod Properties
12-
mod_version=0.1.5
12+
mod_version=0.2.0
1313
maven_group=fr.sukikui.playercoordsapi
1414
archives_base_name=playercoordsapi
1515

0 commit comments

Comments
 (0)