Skip to content

Commit 736cd64

Browse files
committed
Holy christ... Holy christ... There's nothing left... (RoboCop 2014)
1 parent 64bd539 commit 736cd64

29 files changed

+176
-916
lines changed

build.gradle.kts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
44
import dev.deftu.gradle.utils.GameSide
55
import dev.deftu.gradle.utils.includeOrShade
6+
import dev.deftu.gradle.utils.version.MinecraftVersions
67

78
plugins {
89
java
@@ -22,20 +23,6 @@ repositories {
2223
}
2324

2425
toolkitLoomHelper {
25-
useOneConfig {
26-
version = "1.0.0-alpha.177"
27-
loaderVersion = "1.1.0-alpha.53"
28-
29-
usePolyMixin = true
30-
polyMixinVersion = "0.8.4+build.7"
31-
32-
applyLoaderTweaker = true
33-
34-
for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) {
35-
+module
36-
}
37-
}
38-
3926
useDevAuth("1.2.1")
4027
useMixinExtras("0.5.0")
4128

@@ -54,6 +41,19 @@ toolkitLoomHelper {
5441
}
5542

5643
dependencies {
44+
modImplementation("dev.deftu:textile-$mcData:1.0.0-beta.13")
45+
modImplementation("dev.deftu:omnicore-$mcData:1.0.0-beta.40")
46+
if (mcData.version <= MinecraftVersions.VERSION_1_12_2) {
47+
implementation(includeOrShade("org.spongepowered:mixin:0.7.11-SNAPSHOT")!!)
48+
49+
includeOrShade("dev.deftu:textile-$mcData:1.0.0-beta.13")
50+
includeOrShade("dev.deftu:omnicore-$mcData:1.0.0-beta.41")
51+
52+
includeOrShade("org.jetbrains.kotlinx:atomicfu:0.29.0")
53+
}
54+
55+
implementation("org.jetbrains.kotlinx:atomicfu:0.29.0")
56+
5757
implementation(libs.discord.game.sdk4j)
5858
includeOrShade(libs.discord.game.sdk4j)
5959

src/main/java/org/polyfrost/polyplus/mixin/client/Mixin_AddCosmeticsPage.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.polyfrost.polyplus.mixin.client;
2+
3+
import dev.deftu.omnicore.api.OmniCore;
4+
import net.minecraft.client.multiplayer.WorldClient;
5+
import net.minecraft.world.World;
6+
import org.polyfrost.polyplus.client.events.LevelLoadEvent;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
12+
@Mixin(WorldClient.class)
13+
public class Mixin_LevelLoadEvent {
14+
@Inject(method = "<init>", at = @At("RETURN"))
15+
private void polyplus$onLevelLoad(CallbackInfo ci) {
16+
OmniCore.getEventBus().post(new LevelLoadEvent((World) (Object) this));
17+
}
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.polyfrost.polyplus.mixin.client;
2+
3+
import dev.deftu.omnicore.api.OmniCore;
4+
import io.netty.channel.ChannelHandlerContext;
5+
import net.minecraft.network.NetworkManager;
6+
import net.minecraft.network.Packet;
7+
import org.polyfrost.polyplus.client.events.ReceivePacketEvent;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
@Mixin(NetworkManager.class)
14+
public class Mixin_ReceivePacketEvent {
15+
@Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
16+
private void polyplus$onPacketReceived(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
17+
ReceivePacketEvent event = new ReceivePacketEvent(packet);
18+
OmniCore.getEventBus().post(event);
19+
if (event.isCancelled()) {
20+
ci.cancel();
21+
}
22+
}
23+
}

src/main/java/org/polyfrost/polyplus/mixin/Mixin_ReplaceIcon.java renamed to src/main/java/org/polyfrost/polyplus/mixin/client/Mixin_ReplaceIcon.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.polyfrost.polyplus.mixin;
1+
package org.polyfrost.polyplus.mixin.client;
22

33
import net.minecraft.client.Minecraft;
44
import org.lwjgl.opengl.Display;
@@ -10,13 +10,11 @@
1010
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1111

1212
import javax.imageio.ImageIO;
13-
import javax.swing.*;
1413
import java.io.InputStream;
1514
import java.util.Objects;
1615

1716
@Mixin(value = Minecraft.class, priority = Integer.MIN_VALUE)
1817
public class Mixin_ReplaceIcon {
19-
2018
@Inject(method = "setWindowIcon", at = @At("HEAD"), cancellable = true)
2119
private void setWindowIcon(CallbackInfo ci) {
2220
try (InputStream stream = PolyPlusClient.class.getResourceAsStream("/assets/polyplus/PolyPlusIcon.png")) {

src/main/java/org/polyfrost/polyplus/mixin/client/Mixin_ReplaceOneConfigLogo.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/kotlin/org/polyfrost/polyplus/BackendUrl.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package org.polyfrost.polyplus
22

3-
enum class BackendUrl(val url: String) {
3+
import dev.deftu.omnicore.api.commands.CommandCompletable
4+
5+
enum class BackendUrl(val url: String) : CommandCompletable {
46
PRODUCTION("https://plus.polyfrost.org"),
57
STAGING("https://plus-staging.polyfrost.org"),
68
LOCAL("http://localhost:8080");
79

10+
override val id: String
11+
get() = name.lowercase()
12+
813
operator fun plus(other: String): String {
914
return this + other
1015
}

src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusClient.kt

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package org.polyfrost.polyplus.client
22

33
import dev.deftu.omnicore.api.client.commands.OmniClientCommands
4+
import dev.deftu.omnicore.api.client.commands.argument
5+
import dev.deftu.omnicore.api.client.commands.command
46
import dev.deftu.omnicore.api.client.player.playerUuid
7+
import dev.deftu.omnicore.api.commands.types.enumerable.EnumArgumentType
8+
import dev.deftu.omnicore.api.configDirectory
59
import dev.deftu.textile.Text
610
import dev.deftu.textile.minecraft.MCTextStyle
711
import dev.deftu.textile.minecraft.TextColors
@@ -18,22 +22,22 @@ import kotlinx.coroutines.SupervisorJob
1822
import kotlinx.coroutines.launch
1923
import kotlinx.serialization.json.Json
2024
import org.apache.logging.log4j.LogManager
21-
import org.polyfrost.oneconfig.utils.v1.dsl.addDefaultCommand
25+
import org.polyfrost.polyplus.BackendUrl
2226
import org.polyfrost.polyplus.PolyPlusConstants
2327
import org.polyfrost.polyplus.client.cosmetics.ApplyCosmetics
2428
import org.polyfrost.polyplus.client.cosmetics.CosmeticManager
25-
import org.polyfrost.polyplus.client.discord.DiscordPresence
26-
import org.polyfrost.polyplus.client.gui.FullscreenBrowserUI
2729
import org.polyfrost.polyplus.client.network.http.PolyAuthorization
2830
import org.polyfrost.polyplus.client.network.http.PolyCosmetics
2931
import org.polyfrost.polyplus.client.network.websocket.PolyConnection
3032
import org.polyfrost.polyplus.client.network.websocket.ServerboundPacket
3133
import org.polyfrost.polyplus.utils.EarlyInitializable
32-
import org.polyfrost.polyui.data.PolyImage
33-
import org.polyfrost.polyui.utils.image
34+
import kotlin.io.path.exists
35+
import kotlin.io.path.readText
36+
import kotlin.io.path.writeText
3437

3538
object PolyPlusClient {
3639
private val LOGGER = LogManager.getLogger(PolyPlusConstants.NAME)
40+
private var _cachedApiUrl: BackendUrl? = null
3741

3842
@JvmField val SCOPE = CoroutineScope(SupervisorJob() + Dispatchers.Default)
3943

@@ -54,14 +58,35 @@ object PolyPlusClient {
5458
install(WebSockets)
5559
}
5660

57-
fun initialize() {
58-
PolyPlusConfig.preload()
61+
@JvmStatic var apiUrl: BackendUrl
62+
get() {
63+
if (_cachedApiUrl != null) {
64+
return _cachedApiUrl!!
65+
}
66+
67+
val file = configDirectory.resolve("${PolyPlusConstants.ID}_api_url.txt")
68+
val url = if (file.exists()) {
69+
val text = file.readText().trim()
70+
BackendUrl.entries.find { it.url == text } ?: BackendUrl.PRODUCTION
71+
} else {
72+
BackendUrl.PRODUCTION
73+
}
74+
75+
_cachedApiUrl = url
76+
return url
77+
}
78+
set(value) {
79+
_cachedApiUrl = value
80+
81+
val file = configDirectory.resolve("${PolyPlusConstants.ID}_api_url.txt")
82+
file.writeText(value.url)
83+
}
5984

85+
fun initialize() {
6086
listOf(
6187
ApplyCosmetics
6288
).forEach(EarlyInitializable::earlyInitialize)
6389

64-
DiscordPresence.initialize()
6590
PolyConnection.initialize {
6691
LOGGER.info("Connected to PolyPlus WebSocket server.")
6792

@@ -72,26 +97,33 @@ object PolyPlusClient {
7297
}
7398

7499
refresh()
75-
PolyPlusConfig.addDefaultCommand(PolyPlusConstants.ID)
76-
.then(OmniClientCommands.literal("locker")
77-
.executes { ctx ->
78-
ctx.source.openScreen(FullscreenBrowserUI.create())
79-
})
80-
.then(OmniClientCommands.literal("refresh")
81-
.executes { ctx ->
82-
refresh()
83-
LOGGER.info("PolyPlus Client refresh triggered via command.")
84-
val text = Text.literal("PolyPlus will refresh in the background.")
85-
.setStyle(MCTextStyle.color(TextColors.GREEN))
86-
ctx.source.replyChat(text)
87-
})
88-
.then(OmniClientCommands.literal("version")
89-
.executes { ctx ->
100+
101+
OmniClientCommands.command(PolyPlusConstants.ID) {
102+
then("version") {
103+
runs { ctx ->
90104
val text = Text.literal("PolyPlus Client version: ${PolyPlusConstants.VERSION}")
91105
.setStyle(MCTextStyle.color(TextColors.AQUA))
92106
ctx.source.replyChat(text)
93-
})
94-
.apply(OmniClientCommands::register)
107+
}
108+
}
109+
110+
then("api") {
111+
argument("url", EnumArgumentType.of(BackendUrl.entries.toTypedArray())) {
112+
runs { ctx ->
113+
val url = ctx.argument<BackendUrl>("url")
114+
apiUrl = url
115+
116+
LOGGER.info("API URL changed to $apiUrl, refreshing API data...")
117+
118+
PolyConnection.reconnect() // Reconnect WebSocket under new URL
119+
refresh() // Refresh API tokens, cosmetic data, etc.
120+
121+
ctx.source.replyChat(Text.literal("API URL changed to ${url.url}, refreshing data...")
122+
.setStyle(MCTextStyle.color(TextColors.GREEN)))
123+
}
124+
}
125+
}
126+
}.register()
95127
}
96128

97129
fun refresh() {
@@ -119,10 +151,4 @@ object PolyPlusClient {
119151
runCatching { PolyCosmetics.updateOwned() }
120152
}
121153
}
122-
123-
@JvmStatic
124-
fun getOneClientLogo(): PolyImage {
125-
val image = "assets/polyplus/brand/oneclient.svg".image()
126-
return image
127-
}
128154
}

src/main/kotlin/org/polyfrost/polyplus/client/PolyPlusConfig.kt

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)