From e813159cc96e562c6d8771a98b18981cbeebf404 Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 2 Sep 2021 01:24:38 -0600 Subject: [PATCH] Made the rewrite work on with proxy servers --- .gitignore | 118 ++++++++++++++++++ gradle.properties | 2 +- src/main/java/mrnavastar/invsync/Invsync.java | 37 +++--- .../api/events/PlayerJoinCallback.java | 21 ---- .../api/events/PlayerLeaveCallback.java | 21 ---- .../invsync/api/mixin/PlayerManagerMixin.java | 23 ---- .../mixin/ServerPlayNetworkHandlerMixin.java | 27 ---- .../mrnavastar/invsync/util/Converter.java | 1 - src/main/resources/fabric.mod.json | 6 +- src/main/resources/invsync.mixins.json | 4 - 10 files changed, 138 insertions(+), 122 deletions(-) create mode 100644 .gitignore delete mode 100644 src/main/java/mrnavastar/invsync/api/events/PlayerJoinCallback.java delete mode 100644 src/main/java/mrnavastar/invsync/api/events/PlayerLeaveCallback.java delete mode 100644 src/main/java/mrnavastar/invsync/api/mixin/PlayerManagerMixin.java delete mode 100644 src/main/java/mrnavastar/invsync/api/mixin/ServerPlayNetworkHandlerMixin.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a2c5769 --- /dev/null +++ b/.gitignore @@ -0,0 +1,118 @@ +# User-specific stuff +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Cache of project +.gradletasknamecache + +**/build/ + +# Common working directory +/run/ + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index aeb1f2f..bd5f46d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,5 +12,5 @@ archives_base_name=invsync # Dependencies # check this on https://modmuss50.me/fabric.html fabric_version=0.39.2+1.17 -sqlib_version=v1.0.0 +sqlib_version=v1.1.0 cloth_version=5.0.38 \ No newline at end of file diff --git a/src/main/java/mrnavastar/invsync/Invsync.java b/src/main/java/mrnavastar/invsync/Invsync.java index 1935440..570e900 100644 --- a/src/main/java/mrnavastar/invsync/Invsync.java +++ b/src/main/java/mrnavastar/invsync/Invsync.java @@ -2,18 +2,17 @@ import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; -import mrnavastar.invsync.api.events.PlayerJoinCallback; -import mrnavastar.invsync.api.events.PlayerLeaveCallback; import mrnavastar.invsync.util.Converter; import mrnavastar.invsync.util.Settings; import mrnavastar.sqlib.api.SqlTypes; import mrnavastar.sqlib.api.Table; import mrnavastar.sqlib.util.Database; import net.fabricmc.api.ModInitializer; -import net.minecraft.util.ActionResult; +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import java.util.concurrent.TimeUnit; public class Invsync implements ModInitializer { @@ -51,14 +50,21 @@ public void onInitialize() { Database.init(); playerData = new Table(MODID + "PlayerData"); - PlayerJoinCallback.EVENT.register((player, server) -> { - Converter.updatePlayerData(player); - return ActionResult.PASS; + ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { + try { + TimeUnit.SECONDS.sleep(1); //Maybe we can find a less shit solution in the future + playerData.beginTransaction(); + Converter.updatePlayerData(handler.getPlayer()); + playerData.endTransaction(); + } catch (InterruptedException e) { + e.printStackTrace(); + } }); - PlayerLeaveCallback.EVENT.register((player, server) -> { - Converter.savePlayerData(player); - return ActionResult.PASS; + ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> { + playerData.beginTransaction(); + Converter.savePlayerData(handler.getPlayer()); + playerData.endTransaction(); }); log(Level.INFO, "Complete!"); @@ -66,14 +72,7 @@ public void onInitialize() { else log(Level.INFO, "Halting initialization! You need to change some settings in InvSync.toml."); } - //Stuff for console logging - public static final Logger LOGGER = LogManager.getLogger(); - - public static void log(Level level, String message) { - log(level, message, (Object) null); - } - - public static void log(Level level, String message, Object ... fields){ - LOGGER.log(level, "[" + MODID + "] " + message, fields); + public static void log(Level level, String message){ + LogManager.getLogger().log(level, "[" + MODID + "] " + message); } } \ No newline at end of file diff --git a/src/main/java/mrnavastar/invsync/api/events/PlayerJoinCallback.java b/src/main/java/mrnavastar/invsync/api/events/PlayerJoinCallback.java deleted file mode 100644 index 05222ac..0000000 --- a/src/main/java/mrnavastar/invsync/api/events/PlayerJoinCallback.java +++ /dev/null @@ -1,21 +0,0 @@ -package mrnavastar.invsync.api.events; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.ActionResult; - -public interface PlayerJoinCallback { - Event EVENT = EventFactory.createArrayBacked(PlayerJoinCallback.class, (listeners) -> (player, server) -> { - for (PlayerJoinCallback listener : listeners) { - ActionResult result = listener.joinServer(player, server); - - if (result != ActionResult.PASS) { - return result; - } - } - return ActionResult.PASS; - }); - ActionResult joinServer(ServerPlayerEntity player, MinecraftServer server); -} diff --git a/src/main/java/mrnavastar/invsync/api/events/PlayerLeaveCallback.java b/src/main/java/mrnavastar/invsync/api/events/PlayerLeaveCallback.java deleted file mode 100644 index 05f8004..0000000 --- a/src/main/java/mrnavastar/invsync/api/events/PlayerLeaveCallback.java +++ /dev/null @@ -1,21 +0,0 @@ -package mrnavastar.invsync.api.events; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.ActionResult; - -public interface PlayerLeaveCallback { - Event EVENT = EventFactory.createArrayBacked(PlayerLeaveCallback.class, (listeners) -> (player, server) -> { - for (PlayerLeaveCallback listener : listeners) { - ActionResult result = listener.leaveServer(player, server); - - if (result != ActionResult.PASS) { - return result; - } - } - return ActionResult.PASS; - }); - ActionResult leaveServer(ServerPlayerEntity player, MinecraftServer server); -} diff --git a/src/main/java/mrnavastar/invsync/api/mixin/PlayerManagerMixin.java b/src/main/java/mrnavastar/invsync/api/mixin/PlayerManagerMixin.java deleted file mode 100644 index d2ab24d..0000000 --- a/src/main/java/mrnavastar/invsync/api/mixin/PlayerManagerMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package mrnavastar.invsync.api.mixin; - -import mrnavastar.invsync.api.events.PlayerJoinCallback; -import net.minecraft.network.ClientConnection; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.ActionResult; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(PlayerManager.class) -public class PlayerManagerMixin { - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;onSpawn()V"), method = "onPlayerConnect", cancellable = true) - private void onPlayerJoin(ClientConnection connection, ServerPlayerEntity player, CallbackInfo info) { - ActionResult result = PlayerJoinCallback.EVENT.invoker().joinServer(player, player.getServer()); - - if (result == ActionResult.FAIL) { - info.cancel(); - } - } -} diff --git a/src/main/java/mrnavastar/invsync/api/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/mrnavastar/invsync/api/mixin/ServerPlayNetworkHandlerMixin.java deleted file mode 100644 index de7c5ec..0000000 --- a/src/main/java/mrnavastar/invsync/api/mixin/ServerPlayNetworkHandlerMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package mrnavastar.invsync.api.mixin; - -import mrnavastar.invsync.api.events.PlayerLeaveCallback; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ServerPlayNetworkHandler.class) -public class ServerPlayNetworkHandlerMixin { - @Shadow - public ServerPlayerEntity player; - - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;onDisconnect()V"), method = "onDisconnected", cancellable = true) - private void onPlayerLeave(Text reason, CallbackInfo info) { - ActionResult result = PlayerLeaveCallback.EVENT.invoker().leaveServer(this.player, this.player.getServer()); - - if (result == ActionResult.FAIL) { - info.cancel(); - } - } -} diff --git a/src/main/java/mrnavastar/invsync/util/Converter.java b/src/main/java/mrnavastar/invsync/util/Converter.java index 17e631b..d514257 100644 --- a/src/main/java/mrnavastar/invsync/util/Converter.java +++ b/src/main/java/mrnavastar/invsync/util/Converter.java @@ -42,7 +42,6 @@ public static void updatePlayerData(PlayerEntity player) { } } } - } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e8210b5..c4b6b25 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -7,12 +7,8 @@ "authors": [], "contact": {}, "license": "MIT", - "icon": "assets/invsync/icon.png", "environment": "*", "entrypoints": { - "client": [ - "mrnavastar.invsync.client.InvsyncClient" - ], "main": [ "mrnavastar.invsync.Invsync" ] @@ -23,6 +19,6 @@ "depends": { "fabricloader": ">=0.11.6", "fabric": "*", - "minecraft": "1.17.1" + "minecraft": "1.17.x" } } diff --git a/src/main/resources/invsync.mixins.json b/src/main/resources/invsync.mixins.json index d740dec..67f6bdd 100644 --- a/src/main/resources/invsync.mixins.json +++ b/src/main/resources/invsync.mixins.json @@ -4,10 +4,6 @@ "package": "mrnavastar.invsync.api.mixin", "compatibilityLevel": "JAVA_16", "mixins": [ - "PlayerManagerMixin", - "ServerPlayNetworkHandlerMixin" - ], - "client": [ ], "injectors": { "defaultRequire": 1