feat: add way to stop e4mc
This commit is contained in:
parent
df7ceb5911
commit
ab56f6dc19
7 changed files with 117 additions and 15 deletions
|
@ -3,5 +3,5 @@ org.gradle.jvmargs=-Xmx2G
|
||||||
|
|
||||||
mod.name=e4mc
|
mod.name=e4mc
|
||||||
mod.id=e4mc_minecraft
|
mod.id=e4mc_minecraft
|
||||||
mod.version=2.1.0
|
mod.version=3.0.0
|
||||||
mod.group=vg.skye
|
mod.group=vg.skye
|
|
@ -13,6 +13,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import vg.skye.e4mc_minecraft.E4mcClient;
|
||||||
import vg.skye.e4mc_minecraft.E4mcRelayHandler;
|
import vg.skye.e4mc_minecraft.E4mcRelayHandler;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -22,7 +23,6 @@ import java.net.InetAddress;
|
||||||
@Mixin(ServerNetworkIo.class)
|
@Mixin(ServerNetworkIo.class)
|
||||||
public abstract class ServerNetworkIoMixin {
|
public abstract class ServerNetworkIoMixin {
|
||||||
private static final ThreadLocal<Boolean> initializingE4mc = ThreadLocal.withInitial(() -> false);
|
private static final ThreadLocal<Boolean> initializingE4mc = ThreadLocal.withInitial(() -> false);
|
||||||
private static E4mcRelayHandler e4mcHandler = null;
|
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
public abstract void bind(@Nullable InetAddress address, int port) throws IOException;
|
public abstract void bind(@Nullable InetAddress address, int port) throws IOException;
|
||||||
|
@ -40,7 +40,7 @@ public abstract class ServerNetworkIoMixin {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
E4mcRelayHandler handler = new E4mcRelayHandler();
|
E4mcRelayHandler handler = new E4mcRelayHandler();
|
||||||
e4mcHandler = handler;
|
E4mcClient.HANDLER = handler;
|
||||||
handler.connect();
|
handler.connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,10 @@ public abstract class ServerNetworkIoMixin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "stop", at = @At("HEAD"))
|
@Inject(method = "stop", at = @At("HEAD"))
|
||||||
private void bind(CallbackInfo ci) {
|
private void stop(CallbackInfo ci) {
|
||||||
e4mcHandler.close();
|
if (E4mcClient.HANDLER != null) {
|
||||||
|
E4mcClient.HANDLER.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,27 +2,100 @@ package vg.skye.e4mc_minecraft
|
||||||
|
|
||||||
//#if FABRIC==1
|
//#if FABRIC==1
|
||||||
import net.fabricmc.api.ModInitializer
|
import net.fabricmc.api.ModInitializer
|
||||||
|
//#if MC>=11904
|
||||||
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
|
||||||
|
//#else
|
||||||
|
//$$ import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback
|
||||||
|
//#endif
|
||||||
//#else
|
//#else
|
||||||
//$$ import net.minecraftforge.fml.common.Mod
|
//$$ import net.minecraftforge.fml.common.Mod
|
||||||
|
//$$ import net.minecraftforge.eventbus.api.SubscribeEvent
|
||||||
|
//$$ import net.minecraftforge.event.RegisterCommandsEvent
|
||||||
|
//#endif
|
||||||
|
import net.minecraft.server.command.CommandManager.*
|
||||||
|
//#if MC>=11904
|
||||||
|
import net.minecraft.text.Text
|
||||||
|
//#elseif FABRIC==1
|
||||||
|
//$$ import net.minecraft.text.TranslatableText
|
||||||
|
//#else
|
||||||
|
//$$ import net.minecraft.network.chat.TranslatableComponent
|
||||||
//#endif
|
//#endif
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
|
|
||||||
//#if FORGE==1
|
//#if FORGE==1
|
||||||
//$$ @Mod("e4mc_minecraft")
|
//$$ @Mod("e4mc_minecraft")
|
||||||
|
//$$ @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||||
//$$ object E4mcClient {
|
//$$ object E4mcClient {
|
||||||
//#else
|
//#else
|
||||||
object E4mcClient : ModInitializer {
|
object E4mcClient : ModInitializer {
|
||||||
//#endif
|
//#endif
|
||||||
const val NAME = "e4mc"
|
const val NAME = "e4mc"
|
||||||
const val ID = "e4mc_minecraft"
|
const val ID = "e4mc_minecraft"
|
||||||
const val VERSION = "2.1.0"
|
const val VERSION = "3.0.0"
|
||||||
@JvmField
|
@JvmField
|
||||||
val LOGGER: Logger = LoggerFactory.getLogger("e4mc")
|
val LOGGER: Logger = LoggerFactory.getLogger("e4mc")
|
||||||
|
@JvmField
|
||||||
|
var HANDLER: E4mcRelayHandler? = null
|
||||||
|
|
||||||
//#if FABRIC==1
|
//#if FABRIC==1
|
||||||
override fun onInitialize() {
|
override fun onInitialize() {
|
||||||
// nothing needed
|
//#if MC>=11904
|
||||||
|
CommandRegistrationCallback.EVENT.register { dispatcher, _, _ ->
|
||||||
|
//#else
|
||||||
|
//$$ CommandRegistrationCallback.EVENT.register { dispatcher, _ ->
|
||||||
|
//#endif
|
||||||
|
dispatcher.register(literal("e4mc")
|
||||||
|
.then(
|
||||||
|
literal("stop")
|
||||||
|
.executes { context ->
|
||||||
|
if (HANDLER != null) {
|
||||||
|
HANDLER!!.close()
|
||||||
|
HANDLER = null
|
||||||
|
//#if MC>=11904
|
||||||
|
context.source.sendMessage(Text.translatable("text.e4mc_minecraft.closeServer"))
|
||||||
|
//#else
|
||||||
|
//$$ context.source.sendFeedback(TranslatableText("text.e4mc_minecraft.closeServer"), false)
|
||||||
|
//#endif
|
||||||
|
} else {
|
||||||
|
//#if MC>=11904
|
||||||
|
context.source.sendMessage(Text.translatable("text.e4mc_minecraft.serverAlreadyClosed"))
|
||||||
|
//#else
|
||||||
|
//$$ context.source.sendFeedback(TranslatableText("text.e4mc_minecraft.serverAlreadyClosed"), false)
|
||||||
|
//#endif
|
||||||
}
|
}
|
||||||
|
1
|
||||||
|
}
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//#else
|
||||||
|
//$$ @SubscribeEvent
|
||||||
|
//$$ fun onRegisterCommandEvent(event: RegisterCommandsEvent) {
|
||||||
|
//$$ val commandDispatcher = event.getDispatcher()
|
||||||
|
//$$ commandDispatcher.register(literal("e4mc")
|
||||||
|
//$$ .then(
|
||||||
|
//$$ literal("stop")
|
||||||
|
//$$ .executes { context ->
|
||||||
|
//$$ if (HANDLER != null) {
|
||||||
|
//$$ HANDLER!!.close()
|
||||||
|
//$$ HANDLER = null
|
||||||
|
//$$ //#if MC>=11904
|
||||||
|
//$$ context.source.sendSuccess(Component.translatable("text.e4mc_minecraft.closeServer"), false)
|
||||||
|
//$$ //#else
|
||||||
|
//$$ //$$ context.source.sendSuccess(TranslatableComponent("text.e4mc_minecraft.closeServer"), false)
|
||||||
|
//$$ //#endif
|
||||||
|
//$$ } else {
|
||||||
|
//$$ //#if MC>=11904
|
||||||
|
//$$ context.source.sendFailure(Component.translatable("text.e4mc_minecraft.serverAlreadyClosed"))
|
||||||
|
//$$ //#else
|
||||||
|
//$$ //$$ context.source.sendFailure(TranslatableComponent("text.e4mc_minecraft.serverAlreadyClosed"))
|
||||||
|
//$$ //#endif
|
||||||
|
//$$ }
|
||||||
|
//$$ 1
|
||||||
|
//$$ }
|
||||||
|
//$$ ))
|
||||||
|
//$$ }
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,28 +122,46 @@ class E4mcRelayHandler: WebSocketClient(URI("wss://ingress.e4mc.link")) {
|
||||||
private fun createMessage(domain: String): Text {
|
private fun createMessage(domain: String): Text {
|
||||||
//#if MC>=11900
|
//#if MC>=11900
|
||||||
return Text.translatable(
|
return Text.translatable(
|
||||||
"text.e4mc_quilt.domainAssigned",
|
"text.e4mc_minecraft.domainAssigned",
|
||||||
Text.literal(domain).styled {
|
Text.literal(domain).styled {
|
||||||
it
|
it
|
||||||
.withClickEvent(ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, domain))
|
.withClickEvent(ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, domain))
|
||||||
.withColor(Formatting.GREEN)
|
.withColor(Formatting.GREEN)
|
||||||
.withHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click")))
|
.withHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click")))
|
||||||
}
|
}
|
||||||
|
).append(
|
||||||
|
Text.translatable("text.e4mc_minecraft.clickToStop").styled {
|
||||||
|
it
|
||||||
|
.withClickEvent(ClickEvent(ClickEvent.Action.RUN_COMMAND, "/e4mc stop"))
|
||||||
|
.withColor(Formatting.GRAY)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
//#elseif FABRIC==1
|
//#elseif FABRIC==1
|
||||||
//$$ return TranslatableText("text.e4mc_quilt.domainAssigned", LiteralText(domain).styled {
|
//$$ return TranslatableText("text.e4mc_minecraft.domainAssigned", LiteralText(domain).styled {
|
||||||
//$$ return@styled it
|
//$$ return@styled it
|
||||||
//$$ .withClickEvent(ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, domain))
|
//$$ .withClickEvent(ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, domain))
|
||||||
//$$ .withColor(Formatting.GREEN)
|
//$$ .withColor(Formatting.GREEN)
|
||||||
//$$ .withHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, TranslatableText("chat.copy.click")))
|
//$$ .withHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, TranslatableText("chat.copy.click")))
|
||||||
//$$ })
|
//$$ }).append(
|
||||||
|
//$$ TranslatableText("text.e4mc_minecraft.clickToStop").styled {
|
||||||
|
//$$ return@styled it
|
||||||
|
//$$ .withClickEvent(ClickEvent(ClickEvent.Action.RUN_COMMAND, "/e4mc stop"))
|
||||||
|
//$$ .withColor(Formatting.GRAY)
|
||||||
|
//$$ }
|
||||||
|
//$$ )
|
||||||
//#else
|
//#else
|
||||||
//$$ return TranslatableComponent("text.e4mc_quilt.domainAssigned", TextComponent(domain).withStyle {
|
//$$ return TranslatableComponent("text.e4mc_minecraft.domainAssigned", TextComponent(domain).withStyle {
|
||||||
//$$ return@withStyle it
|
//$$ return@withStyle it
|
||||||
//$$ .withClickEvent(ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, domain))
|
//$$ .withClickEvent(ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, domain))
|
||||||
//$$ .withColor(ChatFormatting.GREEN)
|
//$$ .withColor(ChatFormatting.GREEN)
|
||||||
//$$ .withHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, TranslatableComponent("chat.copy.click")))
|
//$$ .withHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, TranslatableComponent("chat.copy.click")))
|
||||||
//$$ })
|
//$$ }).append(
|
||||||
|
//$$ TranslatableComponent("text.e4mc_minecraft.clickToStop").withStyle {
|
||||||
|
//$$ return@withStyle it
|
||||||
|
//$$ .withClickEvent(ClickEvent(ClickEvent.Action.RUN_COMMAND, "/e4mc stop"))
|
||||||
|
//$$ .withColor(ChatFormatting.GRAY)
|
||||||
|
//$$ }
|
||||||
|
//$$ )
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
{
|
{
|
||||||
"text.e4mc_quilt.domainAssigned": "Τοπικό παιχνίδι εξυπηρετήται στη διεύθηνση [%s]"
|
"text.e4mc_minecraft.domainAssigned": "Τοπικό παιχνίδι εξυπηρετήται στη διεύθηνση [%s]",
|
||||||
|
"text.e4mc_minecraft.closeServer": "Το τοπικό παιχνίδι δεν εξυπηρετήται δημόσια πλέον",
|
||||||
|
"text.e4mc_minecraft.serverAlreadyClosed": "Το τοπικό παιχνίδι δεν εξυπηρετήται δημόσια",
|
||||||
|
"text.e4mc_minecraft.clickToStop": " (Πατήστε εδώ για απενεργοποίηση)"
|
||||||
}
|
}
|
|
@ -1,3 +1,6 @@
|
||||||
{
|
{
|
||||||
"text.e4mc_quilt.domainAssigned": "Local game hosted on domain [%s]"
|
"text.e4mc_minecraft.domainAssigned": "Local game hosted on domain [%s]",
|
||||||
|
"text.e4mc_minecraft.closeServer": "Local game no longer publicly hosted",
|
||||||
|
"text.e4mc_minecraft.serverAlreadyClosed": "Local game not publicly hosted",
|
||||||
|
"text.e4mc_minecraft.clickToStop": " (Click here to stop)"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
{
|
{
|
||||||
"text.e4mc_quilt.domainAssigned": "Kohalik mäng on üles seatud domeenil [%s]"
|
"text.e4mc_minecraft.domainAssigned": "Kohalik mäng on üles seatud domeenil [%s]",
|
||||||
|
"text.e4mc_minecraft.closeServer": "Kohalik mäng ei ole enam avalikult hostitud",
|
||||||
|
"text.e4mc_minecraft.serverAlreadyClosed": "Kohalik mäng ei ole avalikult hostitud",
|
||||||
|
"text.e4mc_minecraft.clickToStop": " (Klõpsa lõpetamiseks)"
|
||||||
}
|
}
|
Loading…
Reference in a new issue