diff --git a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java index b871b2a..ea979cc 100644 --- a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java +++ b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java @@ -11,16 +11,17 @@ import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.World; import org.samo_lego.simpleauth.storage.PlayerCache; +import org.samo_lego.simpleauth.utils.PlatformSpecific; import org.samo_lego.simpleauth.utils.PlayerAuth; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import static org.samo_lego.simpleauth.SimpleAuth.*; -import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake; import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo; @Mixin(ServerPlayerEntity.class) @@ -29,10 +30,9 @@ public class MixinServerPlayerEntity implements PlayerAuth { private final ServerPlayerEntity player = (ServerPlayerEntity) (Object) this; // * 20 for 20 ticks in second + @Unique private int kickTimer = config.main.kickTime * 20; - private final boolean isRunningCarpet = false;//FabricLoader.getInstance().isModLoaded("carpet"); //todo - @Final @Shadow public MinecraftServer server; @@ -158,8 +158,7 @@ public class MixinServerPlayerEntity implements PlayerAuth { */ @Override public boolean canSkipAuth() { - // We ask CarpetHelper class since it has the imports needed - return (this.isRunningCarpet && isPlayerCarpetFake(this.player)) || (isUsingMojangAccount() && config.main.premiumAutologin); + return PlatformSpecific.isPlayerFake(this.player) || (isUsingMojangAccount() && config.main.premiumAutologin); } /** diff --git a/common/src/main/java/org/samo_lego/simpleauth/utils/PlatformSpecific.java b/common/src/main/java/org/samo_lego/simpleauth/utils/PlatformSpecific.java new file mode 100644 index 0000000..e2804bf --- /dev/null +++ b/common/src/main/java/org/samo_lego/simpleauth/utils/PlatformSpecific.java @@ -0,0 +1,12 @@ +package org.samo_lego.simpleauth.utils; + +import me.shedaniel.architectury.annotations.ExpectPlatform; +import net.minecraft.entity.player.PlayerEntity; + +public class PlatformSpecific { + @ExpectPlatform + public static boolean isPlayerFake(PlayerEntity player) { + // Replaced by Architectury + throw new AssertionError(); + } +} diff --git a/common/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java b/fabric/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java similarity index 54% rename from common/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java rename to fabric/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java index 8f74364..daf8b0b 100644 --- a/common/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java +++ b/fabric/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java @@ -1,17 +1,16 @@ package org.samo_lego.simpleauth.utils; -//import carpet.patches.EntityPlayerMPFake; +import carpet.patches.EntityPlayerMPFake; import net.minecraft.entity.player.PlayerEntity; public class CarpetHelper { /** * Checks if player is actually a fake one. - * Fake players are counted as ones, summoned with Carpet mod. * * @param player player to check * @return true if it's fake, otherwise false */ - public static boolean isPlayerCarpetFake(PlayerEntity player) { - return false;//player instanceof EntityPlayerMPFake; + public static boolean isPlayerFake(PlayerEntity player) { + return player instanceof EntityPlayerMPFake; } } diff --git a/fabric/src/main/java/org/samo_lego/simpleauth/utils/fabric/PlatformSpecificImpl.java b/fabric/src/main/java/org/samo_lego/simpleauth/utils/fabric/PlatformSpecificImpl.java new file mode 100644 index 0000000..5225eb2 --- /dev/null +++ b/fabric/src/main/java/org/samo_lego/simpleauth/utils/fabric/PlatformSpecificImpl.java @@ -0,0 +1,17 @@ +package org.samo_lego.simpleauth.utils.fabric; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.entity.player.PlayerEntity; +import org.samo_lego.simpleauth.utils.CarpetHelper; + +public class PlatformSpecificImpl { + /** + * Checks if player is actually a fake one. + * + * @param player player to check + * @return true if it's fake, otherwise false + */ + public static boolean isPlayerFake(PlayerEntity player) { + return FabricLoader.getInstance().isModLoaded("carpet") && CarpetHelper.isPlayerFake(player); + } +} diff --git a/forge/src/main/java/org/samo_lego/simpleauth/SimpleAuthForge.java b/forge/src/main/java/org/samo_lego/simpleauth/SimpleAuthForge.java index c6922c8..87f0048 100644 --- a/forge/src/main/java/org/samo_lego/simpleauth/SimpleAuthForge.java +++ b/forge/src/main/java/org/samo_lego/simpleauth/SimpleAuthForge.java @@ -3,6 +3,7 @@ package org.samo_lego.simpleauth; import com.mojang.brigadier.CommandDispatcher; import me.shedaniel.architectury.platform.forge.EventBuses; import net.minecraft.server.command.ServerCommandSource; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -15,8 +16,9 @@ import org.samo_lego.simpleauth.commands.*; public class SimpleAuthForge { public SimpleAuthForge() { // Submit our event bus to let architectury register our content on the right time - EventBuses.registerModEventBus(SimpleAuth.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus()); + //EventBuses.registerModEventBus(SimpleAuth.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus()); SimpleAuth.init(FMLPaths.GAMEDIR.get()); + MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent diff --git a/forge/src/main/java/org/samo_lego/simpleauth/utils/forge/PlatformSpecificImpl.java b/forge/src/main/java/org/samo_lego/simpleauth/utils/forge/PlatformSpecificImpl.java new file mode 100644 index 0000000..7552bb9 --- /dev/null +++ b/forge/src/main/java/org/samo_lego/simpleauth/utils/forge/PlatformSpecificImpl.java @@ -0,0 +1,11 @@ +package org.samo_lego.simpleauth.utils.forge; + +import net.minecraft.entity.player.PlayerEntity; + +public class PlatformSpecificImpl { + public static boolean isPlayerFake(PlayerEntity player) { + // Are there any forge mods with NPCs that don't work with SimpleAuth? + // Let me know! + return false; + } +} diff --git a/gradle.properties b/gradle.properties index 764bd07..7c2bc2c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ forge_version=36.0.4 # Mod Properties -mod_version = 1.7.4 +mod_version = 1.7.5 maven_group = org.samo_lego archives_base_name = simpleauth