Skip to content

Commit bb05161

Browse files
Minecraft MCCBridge for shop item prices updates and returning spended velos to MCC DB added, worker updated to send velos to minecraft when distance updates received
1 parent f379a00 commit bb05161

102 files changed

Lines changed: 10920 additions & 561 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,7 @@ SECURITY_AUDIT.md
171171
mcc-web/db.sqlite3-shm
172172
mcc-web/db.sqlite3-wal
173173
mcc-web/mcc-web.pid
174+
175+
# mcc-bridge - Gradle
176+
mcc-bridge/build/
177+
mcc-bridge/.gradle/

‎mcc-bridge/README.md‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# MCC-Bridge (Paper Plugin)
2+
3+
Connects a Paper **26.1.x** server to MyCyclingCity:
4+
5+
- **Vault economy provider** for team Velos (`velos_spendable`)
6+
- **WebSocket client** for `SPEND_GROUP_VELOS`, `GET_TEAM_VELOS`, `SYNC_SHOP_CATALOG`, `HEARTBEAT`
7+
- **LuckPerms team mapping** (optional)
8+
9+
## Build
10+
11+
Requires **JDK 21+** and **Gradle 8.x**:
12+
13+
```bash
14+
# Gradle via SDKMAN (empfohlen)
15+
sdk install gradle 8.12.1
16+
sdk install java 21.0.9-amzn # Build-JDK
17+
18+
cd mcc-bridge
19+
gradle jar
20+
# Output: build/libs/MCC-Bridge-0.1.0-SNAPSHOT.jar
21+
```
22+
23+
**Hinweis Paper 26.1.2:** Die offizielle `paper-api:26.1.2.build.+` erfordert Java 25 zum Bauen.
24+
Dieses Projekt kompiliert daher gegen `paper-api:1.21.11-R0.1-SNAPSHOT` (Java 21) und läuft auf Paper 26.1.2.
25+
26+
Copy the JAR to the Minecraft server `plugins/` folder.
27+
28+
## Dependencies on the MC server
29+
30+
1. **VaultUnlocked** (or Vault)
31+
2. **LuckPerms** (recommended for team mapping)
32+
3. **EconomyShopGUI** (shop UI)
33+
4. **MCC Django** with WebSocket enabled
34+
35+
Install order (critical — MCC-Bridge must register Vault economy **before** EconomyShopGUI):
36+
37+
1. **VaultUnlocked** (Vault API)
38+
2. **LuckPerms** (optional, team mapping)
39+
3. **MCC-Bridge** (registers Velos economy via Vault)
40+
4. **EconomyShopGUI** (needs an economy provider at startup)
41+
42+
After changing plugin JARs always do a **full server restart** (not `/reload`).
43+
44+
If `/plugins` shows EconomyShopGUI in **red**, check `logs/latest.log` for the startup error.
45+
Common causes: no economy at ESGUI startup (wrong load order), or invalid YAML in
46+
`plugins/EconomyShopGUI/shops/`. Backups from MCC sync: `*.yml.bak` next to each shop file.
47+
48+
## Configuration
49+
50+
Edit `plugins/MCC-Bridge/config.yml`:
51+
52+
```yaml
53+
mcc:
54+
websocket_url: "wss://your-mcc-host/ws/minecraft/events/"
55+
shared_secret: "<MCC_MINECRAFT_WS_SHARED_SECRET>"
56+
server_id: "velo-stadt-1"
57+
# Keep Admin "Shop push" enabled (Django STALE_AFTER = 5 minutes)
58+
heartbeat_seconds: 60
59+
```
60+
61+
MCC `.env`:
62+
63+
```env
64+
MCC_MINECRAFT_WS_ENABLED=True
65+
MCC_MINECRAFT_WS_SHARED_SECRET=<same-secret>
66+
MCC_MINECRAFT_WS_ALLOWED_SERVER_IDS=velo-stadt-1
67+
```
68+
69+
Map LuckPerms groups to MCC team scoreboard names:
70+
71+
```yaml
72+
team:
73+
resolution: luckperms
74+
team_groups:
75+
team_alpha: TeamAlpha
76+
```
77+
78+
## Commands
79+
80+
- `/mccbridge status` — connection status
81+
- `/mccbridge reload` — reload config
82+
- `/mccbridge synccatalog` — pull shop catalog from MCC
83+
- `/mccbridge esguistatus` — EconomyShopGUI diagnostics
84+
- `/mccbridge esguireload` — reload EconomyShopGUI after YAML sync
85+
86+
## Shop catalog
87+
88+
Define categories/items in MCC Admin (`/admin/minecraft/` → Katalog verwalten).
89+
MCC-Bridge pulls the catalog via WebSocket and writes buy prices directly into
90+
**EconomyShopGUI** shop YAML files (`plugins/EconomyShopGUI/shops/*.yml`), then runs `/sreload`.
91+
92+
Admin button **Shop-Preise an Minecraft pushen** triggers the same sync remotely.

‎mcc-bridge/build.gradle.kts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
plugins {
2+
java
3+
}
4+
5+
group = "de.sailab.mycyclingcity"
6+
version = findProperty("version") as String
7+
8+
java {
9+
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
10+
}
11+
12+
repositories {
13+
mavenCentral()
14+
maven("https://repo.papermc.io/repository/maven-public/")
15+
maven("https://jitpack.io")
16+
}
17+
18+
dependencies {
19+
// Paper 26.1.x API requires Java 25 to resolve; compile against 1.21.11 API (Java 21).
20+
// Runtime target: Paper 26.1.2 server.
21+
compileOnly("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
22+
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1")
23+
compileOnly("net.luckperms:api:5.4")
24+
implementation("com.squareup.okhttp3:okhttp:4.12.0")
25+
implementation("com.google.code.gson:gson:2.11.0")
26+
implementation("org.yaml:snakeyaml:2.2")
27+
}
28+
29+
tasks.withType<JavaCompile> {
30+
options.encoding = "UTF-8"
31+
options.release.set(21)
32+
}
33+
34+
tasks.processResources {
35+
filesMatching("plugin.yml") {
36+
expand("version" to project.version)
37+
}
38+
}
39+
40+
tasks.jar {
41+
archiveBaseName.set("MCC-Bridge")
42+
// Bundle OkHttp + Gson (not provided by the server)
43+
from(
44+
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
45+
)
46+
duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.EXCLUDE
47+
}

‎mcc-bridge/gradle.properties‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version=0.1.0-SNAPSHOT
2+
group=de.sailab.mycyclingcity

‎mcc-bridge/settings.gradle.kts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = "mcc-bridge"
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package de.sailab.mycyclingcity.mccbridge;
2+
3+
import org.bukkit.configuration.file.FileConfiguration;
4+
5+
import java.util.Collections;
6+
import java.util.LinkedHashMap;
7+
import java.util.Map;
8+
9+
public final class MccBridgeConfig {
10+
private String websocketUrl;
11+
private String sharedSecret;
12+
private String serverId;
13+
private int reconnectSeconds;
14+
private int heartbeatSeconds;
15+
private boolean catalogSyncOnConnect;
16+
private boolean esguiSyncOnCatalog;
17+
private boolean esguiAddMissingItems;
18+
private int esguiDefaultSellPrice;
19+
private boolean esguiReloadAfterSync;
20+
private boolean esguiReloadCycleFallback;
21+
private String currencyName;
22+
private String currencySymbol;
23+
private String resolution;
24+
private Map<String, String> staticTeamGroups = Collections.emptyMap();
25+
private final Map<String, String> runtimeTeamGroups = new LinkedHashMap<>();
26+
private Map<String, String> playerOverrides;
27+
28+
public void load(FileConfiguration config) {
29+
websocketUrl = config.getString("mcc.websocket_url", "ws://127.0.0.1:8000/ws/minecraft/events/");
30+
sharedSecret = config.getString("mcc.shared_secret", "SECRET");
31+
serverId = config.getString("mcc.server_id", "velo-stadt-1");
32+
reconnectSeconds = Math.max(5, config.getInt("mcc.reconnect_seconds", 15));
33+
heartbeatSeconds = config.getInt("mcc.heartbeat_seconds", 60);
34+
if (heartbeatSeconds < 0) {
35+
heartbeatSeconds = 0;
36+
} else if (heartbeatSeconds > 0 && heartbeatSeconds < 15) {
37+
// Keep presence fresher than MCC Admin STALE_AFTER (5 min)
38+
heartbeatSeconds = 15;
39+
}
40+
catalogSyncOnConnect = config.getBoolean("mcc.catalog_sync_on_connect", true);
41+
esguiSyncOnCatalog = config.getBoolean("mcc.esgui_sync_on_catalog", true);
42+
esguiAddMissingItems = config.getBoolean("mcc.esgui_add_missing_items", false);
43+
esguiDefaultSellPrice = config.getInt("mcc.esgui_default_sell_price", -1);
44+
esguiReloadAfterSync = config.getBoolean("mcc.esgui_reload_after_sync", true);
45+
esguiReloadCycleFallback = config.getBoolean("mcc.esgui_reload_cycle_fallback", true);
46+
currencyName = config.getString("vault.currency_name", "Velos");
47+
currencySymbol = config.getString("vault.currency_symbol", " Velos");
48+
resolution = config.getString("team.resolution", "luckperms");
49+
staticTeamGroups = readStringMap(config, "team.team_groups");
50+
runtimeTeamGroups.clear();
51+
playerOverrides = readStringMap(config, "team.player_overrides");
52+
}
53+
54+
public void upsertTeamGroup(String lpGroup, String mcUsername) {
55+
if (lpGroup == null || lpGroup.isBlank() || mcUsername == null || mcUsername.isBlank()) {
56+
return;
57+
}
58+
runtimeTeamGroups.put(lpGroup, mcUsername);
59+
}
60+
61+
public void removeTeamGroup(String lpGroup) {
62+
if (lpGroup == null || lpGroup.isBlank()) {
63+
return;
64+
}
65+
runtimeTeamGroups.remove(lpGroup);
66+
}
67+
68+
private Map<String, String> readStringMap(FileConfiguration config, String path) {
69+
if (!config.isConfigurationSection(path)) {
70+
return Collections.emptyMap();
71+
}
72+
Map<String, String> values = new LinkedHashMap<>();
73+
for (String key : config.getConfigurationSection(path).getKeys(false)) {
74+
String value = config.getString(path + "." + key);
75+
if (value != null && !value.isBlank()) {
76+
values.put(key, value);
77+
}
78+
}
79+
return values;
80+
}
81+
82+
public String websocketUrl() {
83+
return websocketUrl;
84+
}
85+
86+
public String sharedSecret() {
87+
return sharedSecret;
88+
}
89+
90+
public String serverId() {
91+
return serverId;
92+
}
93+
94+
public int reconnectSeconds() {
95+
return reconnectSeconds;
96+
}
97+
98+
/** Application HEARTBEAT interval in seconds; 0 disables. */
99+
public int heartbeatSeconds() {
100+
return heartbeatSeconds;
101+
}
102+
103+
public boolean catalogSyncOnConnect() {
104+
return catalogSyncOnConnect;
105+
}
106+
107+
public boolean esguiSyncOnCatalog() {
108+
return esguiSyncOnCatalog;
109+
}
110+
111+
public boolean esguiAddMissingItems() {
112+
return esguiAddMissingItems;
113+
}
114+
115+
public int esguiDefaultSellPrice() {
116+
return esguiDefaultSellPrice;
117+
}
118+
119+
public boolean esguiReloadAfterSync() {
120+
return esguiReloadAfterSync;
121+
}
122+
123+
public boolean esguiReloadCycleFallback() {
124+
return esguiReloadCycleFallback;
125+
}
126+
127+
public String currencyName() {
128+
return currencyName;
129+
}
130+
131+
public String currencySymbol() {
132+
return currencySymbol;
133+
}
134+
135+
public String resolution() {
136+
return resolution;
137+
}
138+
139+
public Map<String, String> teamGroups() {
140+
Map<String, String> merged = new LinkedHashMap<>(staticTeamGroups);
141+
merged.putAll(runtimeTeamGroups);
142+
return merged;
143+
}
144+
145+
public Map<String, String> playerOverrides() {
146+
return playerOverrides;
147+
}
148+
}

0 commit comments

Comments
 (0)