diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 1a55759..0000000 --- a/build.gradle +++ /dev/null @@ -1,124 +0,0 @@ -plugins { - id 'fabric-loom' version '0.5-SNAPSHOT' - id 'maven-publish' -} - -repositories { - // Carpet mod - maven { - url 'https://jitpack.io' - } - maven { - url 'https://masa.dy.fi/maven' - } -} - -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 - -archivesBaseName = project.archives_base_name -version = "${project.mod_version}-${project.minecraft_version}" -group = project.maven_group - -minecraft { -} - -dependencies { - //to change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - - - // Password hashing - // Argon2 - implementation "de.mkammerer:argon2-jvm:${argon2_version}" - include "de.mkammerer:argon2-jvm:${argon2_version}" - - // BCrypt - implementation "at.favre.lib:bcrypt:${bcrypt_version}" - implementation "at.favre.lib:bytes:${bytes_version}" - include "at.favre.lib:bcrypt:${bcrypt_version}" - include "at.favre.lib:bytes:${bytes_version}" - - // Storage - // LevelDB database - implementation group: 'org.iq80.leveldb', name: 'leveldb', version: '0.12' - implementation group: 'org.iq80.leveldb', name: 'leveldb-api', version: '0.12' - include group: 'org.iq80.leveldb', name: 'leveldb', version: '0.12' - include group: 'org.iq80.leveldb', name: 'leveldb-api', version: '0.12' - - // MongoDB driver - implementation 'org.mongodb:mongodb-driver-sync:4.1.0' - include 'org.mongodb:mongodb-driver-sync:4.1.0' - - - - // JNA lib - include 'net.java.dev.jna:jna:5.5.0' - - // carpetMod - // from masa's maven - //modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}" - //modImplementation "carpet:fabric-carpet:1.16-${project.carpet_core_version}" - // jitpack for quicker updating - modImplementation "com.github.gnembon:fabric-carpet:${project.carpet_branch}-SNAPSHOT" -} - -processResources { - inputs.property "version", project.version - - from(sourceSets.main.resources.srcDirs) { - include "fabric.mod.json" - expand "version": project.version - } - - from(sourceSets.main.resources.srcDirs) { - exclude "fabric.mod.json" - } -} - -// ensure that the encoding is set to UTF-8, no matter what the system default is -// this fixes some edge cases with special characters not displaying correctly -// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" -} - -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = "sources" - from sourceSets.main.allSource -} - -jar { - from "LICENSE" -} - -// configure the maven publication -publishing { - publications { - mavenJava(MavenPublication) { - // add all the jars that should be included when publishing to maven - artifact(remapJar) { - builtBy remapJar - } - artifact(sourcesJar) { - builtBy remapSourcesJar - } - } - } - - // select the repositories you want to publish to - repositories { - // uncomment to publish to the local maven - // mavenLocal() - mavenCentral() - } -} - diff --git a/src/main/java/org/samo_lego/simpleauth/commands/AccountCommand.java b/common/src/main/java/org/samo_lego/simpleauth/commands/AccountCommand.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/commands/AccountCommand.java rename to common/src/main/java/org/samo_lego/simpleauth/commands/AccountCommand.java diff --git a/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java b/common/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java rename to common/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java diff --git a/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java b/common/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java rename to common/src/main/java/org/samo_lego/simpleauth/commands/LoginCommand.java diff --git a/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java b/common/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java rename to common/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java diff --git a/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java b/common/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java rename to common/src/main/java/org/samo_lego/simpleauth/commands/RegisterCommand.java diff --git a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java b/common/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java similarity index 95% rename from src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java rename to common/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java index 760d4cf..7e1ca6c 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/common/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -4,7 +4,6 @@ import com.mojang.authlib.GameProfile; import net.minecraft.block.Blocks; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; @@ -15,7 +14,6 @@ import net.minecraft.util.math.BlockPos; import org.samo_lego.simpleauth.storage.PlayerCache; import org.samo_lego.simpleauth.utils.PlayerAuth; -import java.net.SocketAddress; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -28,9 +26,15 @@ import static org.samo_lego.simpleauth.SimpleAuth.playerCacheMap; */ public class AuthEventHandler { - // Player pre-join - // Returns text as a reason for disconnect or null to pass - public static LiteralText checkCanPlayerJoinServer(SocketAddress socketAddress, GameProfile profile, PlayerManager manager) { + /** + * Player pre-join. + * Returns text as a reason for disconnect or null to pass + * + * @param profile GameProfile of the player + * @param manager PlayerManager + * @return TExt if player should be disconnected + */ + public static LiteralText checkCanPlayerJoinServer(GameProfile profile, PlayerManager manager) { // Getting the player String incomingPlayerUsername = profile.getName(); PlayerEntity onlinePlayer = manager.getPlayer(incomingPlayerUsername); diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java rename to common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java similarity index 85% rename from src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java rename to common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java index 73655f2..68f74ba 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java +++ b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java @@ -3,7 +3,7 @@ package org.samo_lego.simpleauth.mixin; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; -import org.samo_lego.simpleauth.event.item.DropItemCallback; +import org.samo_lego.simpleauth.event.AuthEventHandler; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,7 +17,7 @@ public class MixinPlayerEntity { @Inject(method = "dropSelectedItem(Z)Z", at = @At("HEAD"), cancellable = true) private void dropSelectedItem(boolean dropEntireStack, CallbackInfoReturnable cir) { ServerPlayerEntity player = (ServerPlayerEntity) (Object) this; - ActionResult result = DropItemCallback.EVENT.invoker().onDropItem(player); + ActionResult result = AuthEventHandler.onDropItem(player); if (result == ActionResult.FAIL) { cir.setReturnValue(false); diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java similarity index 93% rename from src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java rename to common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java index 4579633..d0837ab 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java +++ b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java @@ -9,6 +9,7 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.stat.ServerStatHandler; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; +import org.samo_lego.simpleauth.event.AuthEventHandler; import org.samo_lego.simpleauth.event.entity.player.PlayerJoinServerCallback; import org.samo_lego.simpleauth.event.entity.player.PlayerLeaveServerCallback; import org.samo_lego.simpleauth.event.entity.player.PrePlayerJoinCallback; @@ -36,12 +37,12 @@ public abstract class MixinPlayerManager { @Inject(method = "onPlayerConnect(Lnet/minecraft/network/ClientConnection;Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At("RETURN")) private void onPlayerConnect(ClientConnection clientConnection, ServerPlayerEntity serverPlayerEntity, CallbackInfo ci) { - PlayerJoinServerCallback.EVENT.invoker().onPlayerJoin(serverPlayerEntity); + AuthEventHandler.onPlayerJoin(serverPlayerEntity); } @Inject(method = "remove(Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At("HEAD")) private void onPlayerLeave(ServerPlayerEntity serverPlayerEntity, CallbackInfo ci) { - PlayerLeaveServerCallback.EVENT.invoker().onPlayerLeave(serverPlayerEntity); + AuthEventHandler.onPlayerLeave(serverPlayerEntity); } @Inject(method = "checkCanJoin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/text/Text;", at = @At("HEAD"), cancellable = true) @@ -49,7 +50,7 @@ public abstract class MixinPlayerManager { // Getting the player that is trying to join the server PlayerManager manager = (PlayerManager) (Object) this; - LiteralText returnText = PrePlayerJoinCallback.EVENT.invoker().checkCanPlayerJoinServer(socketAddress, profile, manager); + LiteralText returnText = AuthEventHandler.checkCanPlayerJoinServer(profile, manager); if(returnText != null) { // Canceling player joining with the returnText message diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java rename to common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java similarity index 91% rename from src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java rename to common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java index 4437a03..7525342 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java +++ b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayNetworkHandler.java @@ -7,6 +7,7 @@ import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; +import org.samo_lego.simpleauth.event.AuthEventHandler; import org.samo_lego.simpleauth.event.entity.player.ChatCallback; import org.samo_lego.simpleauth.event.entity.player.PlayerMoveCallback; import org.samo_lego.simpleauth.event.item.TakeItemCallback; @@ -33,7 +34,7 @@ public abstract class MixinServerPlayNetworkHandler { cancellable = true ) private void onPlayerChat(String message, CallbackInfo ci) { - ActionResult result = ChatCallback.EVENT.invoker().onPlayerChat(this.player, message); + ActionResult result = AuthEventHandler.onPlayerChat(this.player, message); if (result == ActionResult.FAIL) { ci.cancel(); } @@ -50,7 +51,7 @@ public abstract class MixinServerPlayNetworkHandler { ) private void onPlayerAction(PlayerActionC2SPacket packet, CallbackInfo ci) { if(packet.getAction() == SWAP_ITEM_WITH_OFFHAND) { - ActionResult result = TakeItemCallback.EVENT.invoker().onTakeItem(this.player); + ActionResult result = AuthEventHandler.onTakeItem(this.player); if (result == ActionResult.FAIL) { ci.cancel(); } @@ -67,7 +68,7 @@ public abstract class MixinServerPlayNetworkHandler { cancellable = true ) private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket, CallbackInfo ci) { - ActionResult result = PlayerMoveCallback.EVENT.invoker().onPlayerMove(player); + ActionResult result = AuthEventHandler.onPlayerMove(player); if (result == ActionResult.FAIL) { // A bit ugly, I know. (we need to update player position) player.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.yaw, player.pitch); @@ -85,7 +86,7 @@ public abstract class MixinServerPlayNetworkHandler { cancellable = true ) public void onCreativeInventoryAction(CreativeInventoryActionC2SPacket packet, CallbackInfo ci) { - ActionResult result = TakeItemCallback.EVENT.invoker().onTakeItem(this.player); + ActionResult result = AuthEventHandler.onTakeItem(this.player); if (result == ActionResult.FAIL) { // Canceling the item taking diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java rename to common/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinSlot.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinSlot.java similarity index 92% rename from src/main/java/org/samo_lego/simpleauth/mixin/MixinSlot.java rename to common/src/main/java/org/samo_lego/simpleauth/mixin/MixinSlot.java index 0bb514a..2d3ffe5 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinSlot.java +++ b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinSlot.java @@ -5,6 +5,7 @@ import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; import net.minecraft.screen.slot.Slot; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; +import org.samo_lego.simpleauth.event.AuthEventHandler; import org.samo_lego.simpleauth.event.item.TakeItemCallback; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -17,7 +18,7 @@ public abstract class MixinSlot { @Inject(method = "canTakeItems(Lnet/minecraft/entity/player/PlayerEntity;)Z", at = @At(value = "HEAD"), cancellable = true) private void canTakeItems(PlayerEntity playerEntity, CallbackInfoReturnable cir) { ServerPlayerEntity player = (ServerPlayerEntity) playerEntity; - ActionResult result = TakeItemCallback.EVENT.invoker().onTakeItem(player); + ActionResult result = AuthEventHandler.onTakeItem(player); if (result == ActionResult.FAIL) { // Canceling the item taking diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinWorldSaveHandler.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinWorldSaveHandler.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/mixin/MixinWorldSaveHandler.java rename to common/src/main/java/org/samo_lego/simpleauth/mixin/MixinWorldSaveHandler.java diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/ServerStatHandlerAccessor.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/ServerStatHandlerAccessor.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/mixin/ServerStatHandlerAccessor.java rename to common/src/main/java/org/samo_lego/simpleauth/mixin/ServerStatHandlerAccessor.java diff --git a/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java b/common/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java rename to common/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java diff --git a/src/main/java/org/samo_lego/simpleauth/storage/DBHelper.java b/common/src/main/java/org/samo_lego/simpleauth/storage/DBHelper.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/storage/DBHelper.java rename to common/src/main/java/org/samo_lego/simpleauth/storage/DBHelper.java diff --git a/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java b/common/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java rename to common/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java diff --git a/src/main/java/org/samo_lego/simpleauth/storage/database/LevelDB.java b/common/src/main/java/org/samo_lego/simpleauth/storage/database/LevelDB.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/storage/database/LevelDB.java rename to common/src/main/java/org/samo_lego/simpleauth/storage/database/LevelDB.java diff --git a/src/main/java/org/samo_lego/simpleauth/storage/database/MongoDB.java b/common/src/main/java/org/samo_lego/simpleauth/storage/database/MongoDB.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/storage/database/MongoDB.java rename to common/src/main/java/org/samo_lego/simpleauth/storage/database/MongoDB.java diff --git a/src/main/java/org/samo_lego/simpleauth/utils/AuthHelper.java b/common/src/main/java/org/samo_lego/simpleauth/utils/AuthHelper.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/utils/AuthHelper.java rename to common/src/main/java/org/samo_lego/simpleauth/utils/AuthHelper.java diff --git a/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java b/common/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java rename to common/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java diff --git a/src/main/java/org/samo_lego/simpleauth/utils/PlayerAuth.java b/common/src/main/java/org/samo_lego/simpleauth/utils/PlayerAuth.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/utils/PlayerAuth.java rename to common/src/main/java/org/samo_lego/simpleauth/utils/PlayerAuth.java diff --git a/src/main/java/org/samo_lego/simpleauth/utils/SimpleLogger.java b/common/src/main/java/org/samo_lego/simpleauth/utils/SimpleLogger.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/utils/SimpleLogger.java rename to common/src/main/java/org/samo_lego/simpleauth/utils/SimpleLogger.java diff --git a/src/main/java/org/samo_lego/simpleauth/utils/hashing/HasherArgon2.java b/common/src/main/java/org/samo_lego/simpleauth/utils/hashing/HasherArgon2.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/utils/hashing/HasherArgon2.java rename to common/src/main/java/org/samo_lego/simpleauth/utils/hashing/HasherArgon2.java diff --git a/src/main/java/org/samo_lego/simpleauth/utils/hashing/HasherBCrypt.java b/common/src/main/java/org/samo_lego/simpleauth/utils/hashing/HasherBCrypt.java similarity index 100% rename from src/main/java/org/samo_lego/simpleauth/utils/hashing/HasherBCrypt.java rename to common/src/main/java/org/samo_lego/simpleauth/utils/hashing/HasherBCrypt.java diff --git a/src/main/resources/fabric.mod.json b/common/src/main/resources/fabric.mod.json similarity index 100% rename from src/main/resources/fabric.mod.json rename to common/src/main/resources/fabric.mod.json diff --git a/src/main/resources/mixins.simpleauth.json b/common/src/main/resources/mixins.simpleauth.json similarity index 100% rename from src/main/resources/mixins.simpleauth.json rename to common/src/main/resources/mixins.simpleauth.json diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 0000000..f4ab495 --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,68 @@ +plugins { + id "com.github.johnrengelman.shadow" version "5.0.0" +} + +repositories { + // Carpet mod + maven { + url 'https://jitpack.io' + } + maven { + url 'https://masa.dy.fi/maven' + } +} + +configurations { + shadow +} + +architectury { + platformSetupLoomIde() +} + +dependencies { + minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" + mappings("net.fabricmc:yarn:${rootProject.yarn_mappings}:v2") + modImplementation "net.fabricmc:fabric-loader:${rootProject.loader_version}" + + // Fabric API. This is technically optional, but you probably want it anyway. + modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}" + + compileOnly(project(path: ":common")) { + transitive = false + exclude(module: "fabric-api") + } + runtimeOnly(project(path: ":common", configuration: "transformedRuntime")) { + transitive = false + exclude(module: "fabric-api") + } + shadow(project(path: ":common", configuration: "transformed")) { + transitive = false + exclude(module: "fabric-api") + } + + // carpetMod + // from masa's maven + //modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}" + //modImplementation "carpet:fabric-carpet:1.16-${project.carpet_core_version}" + // jitpack for quicker updating + modImplementation "com.github.gnembon:fabric-carpet:${project.carpet_branch}-SNAPSHOT" +} + +processResources { + filesMatching("fabric.mod.json") { + expand "version": project.version + } + inputs.property "version", project.version +} + +shadowJar { + configurations = [project.configurations.shadow] + classifier "shadow" +} + +remapJar { + dependsOn(shadowJar) + input.set(shadowJar.archivePath) + archiveClassifier = "fabric" +} diff --git a/fabric/src/main/java/org/samo_lego/simpleauth/SimpleAuthFabric.java b/fabric/src/main/java/org/samo_lego/simpleauth/SimpleAuthFabric.java new file mode 100644 index 0000000..924573b --- /dev/null +++ b/fabric/src/main/java/org/samo_lego/simpleauth/SimpleAuthFabric.java @@ -0,0 +1,39 @@ +package org.samo_lego.simpleauth; + +import net.fabricmc.api.DedicatedServerModInitializer; +import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.fabricmc.fabric.api.event.player.*; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.server.MinecraftServer; + +public class SimpleAuthFabric implements DedicatedServerModInitializer { + + @Override + public void onInitializeServer() { + SimpleAuth.init(FabricLoader.getInstance().getGameDir()); + + + // Registering the commands + CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> { + RegisterCommand.registerCommand(dispatcher); + LoginCommand.registerCommand(dispatcher); + LogoutCommand.registerCommand(dispatcher); + AuthCommand.registerCommand(dispatcher); + AccountCommand.registerCommand(dispatcher); + }); + + // From Fabric API + PlayerBlockBreakEvents.BEFORE.register((world, player, blockPos, blockState, blockEntity) -> AuthEventHandler.onBreakBlock(player)); + UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> AuthEventHandler.onUseBlock(player)); + UseItemCallback.EVENT.register((player, world, hand) -> AuthEventHandler.onUseItem(player)); + AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onAttackEntity(player)); + UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onUseEntity(player)); + ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> AuthEventHandler.reloadConfig(null)); + ServerLifecycleEvents.SERVER_STOPPED.register(this::onStopServer); + } + + private void onStopServer(MinecraftServer server) { + SimpleAuth.stop(); + } +} diff --git a/forge/gradle.properties b/forge/gradle.properties new file mode 100644 index 0000000..5997976 --- /dev/null +++ b/forge/gradle.properties @@ -0,0 +1 @@ +loom.forge = true \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index b3dbcc4..86a285d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,16 +9,23 @@ loader_version=0.10.8 #Fabric api fabric_version=0.28.0+1.16 +# Forge +forge_version = 35.1.0 + + # Mod Properties mod_version = 1.7.4 maven_group = org.samo_lego archives_base_name = simpleauth -# Hashing +# Hashing libs argon2_version = 2.7 bcrypt_version = 0.9.0 bytes_version = 1.3.0 +# Architectury +architectury_version=1.3.78 + # Carpet for debugging carpet_core_version = 1.4.16+v201105 carpet_branch = master diff --git a/settings.gradle b/settings.gradle index 5b60df3..515c93f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,6 +5,14 @@ pluginManagement { name = 'Fabric' url = 'https://maven.fabricmc.net/' } + maven { url "https://dl.bintray.com/shedaniel/cloth" } + maven { url "https://files.minecraftforge.net/maven/" } gradlePluginPortal() } } + +include("common") +include("fabric") +include("forge") + +rootProject.name = "simpleauth" \ No newline at end of file diff --git a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java deleted file mode 100644 index 16b053c..0000000 --- a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java +++ /dev/null @@ -1,136 +0,0 @@ -package org.samo_lego.simpleauth; - -import net.fabricmc.api.DedicatedServerModInitializer; -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; -import net.fabricmc.fabric.api.event.player.*; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.server.MinecraftServer; -import org.samo_lego.simpleauth.commands.*; -import org.samo_lego.simpleauth.event.AuthEventHandler; -import org.samo_lego.simpleauth.event.entity.player.*; -import org.samo_lego.simpleauth.event.item.DropItemCallback; -import org.samo_lego.simpleauth.event.item.TakeItemCallback; -import org.samo_lego.simpleauth.storage.AuthConfig; -import org.samo_lego.simpleauth.storage.DBHelper; -import org.samo_lego.simpleauth.storage.PlayerCache; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Properties; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import static org.samo_lego.simpleauth.commands.AuthCommand.reloadConfig; -import static org.samo_lego.simpleauth.event.AuthEventHandler.*; -import static org.samo_lego.simpleauth.utils.SimpleLogger.logError; -import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo; - -public class SimpleAuth implements DedicatedServerModInitializer { - - public static DBHelper DB = new DBHelper(); - - public static final ExecutorService THREADPOOL = Executors.newCachedThreadPool(); - - /** - * HashMap of players that have joined the server. - * It's cleared on server stop in order to save some interactions with database during runtime. - * Stores their data as {@link org.samo_lego.simpleauth.storage.PlayerCache PlayerCache} object. - */ - public static final HashMap playerCacheMap = new HashMap<>(); - - /** - * HashSet of player names that have Mojang accounts. - * If player is saved in here, they will be treated as online-mode ones. - */ - public static final HashSet mojangAccountNamesCache = new HashSet<>(); - - // Getting game directory - public static final Path gameDirectory = FabricLoader.getInstance().getGameDir(); - - // Server properties - public static final Properties serverProp = new Properties(); - - /** - * Config of the SimpleAuth mod. - */ - public static AuthConfig config; - - @Override - public void onInitializeServer() { - // Info I guess :D - logInfo("SimpleAuth mod by samo_lego."); - // The support on discord was great! I really appreciate your help. - logInfo("This mod wouldn't exist without the awesome Fabric Community. TYSM guys!"); - - try { - serverProp.load(new FileReader(gameDirectory + "/server.properties")); - } catch (IOException e) { - logError("Error while reading server properties: " + e.getMessage()); - } - - // Creating data directory (database and config files are stored there) - File file = new File(gameDirectory + "/mods/SimpleAuth/leveldbStore"); - if (!file.exists() && !file.mkdirs()) - throw new RuntimeException("[SimpleAuth] Error creating directory!"); - // Loading config - config = AuthConfig.load(new File(gameDirectory + "/mods/SimpleAuth/config.json")); - // Connecting to db - DB.openConnection(); - - - // Registering the commands - CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> { - RegisterCommand.registerCommand(dispatcher); - LoginCommand.registerCommand(dispatcher); - LogoutCommand.registerCommand(dispatcher); - AuthCommand.registerCommand(dispatcher); - AccountCommand.registerCommand(dispatcher); - }); - - // Registering the events - PrePlayerJoinCallback.EVENT.register(AuthEventHandler::checkCanPlayerJoinServer); - PlayerJoinServerCallback.EVENT.register(AuthEventHandler::onPlayerJoin); - PlayerLeaveServerCallback.EVENT.register(AuthEventHandler::onPlayerLeave); - DropItemCallback.EVENT.register(AuthEventHandler::onDropItem); - TakeItemCallback.EVENT.register(AuthEventHandler::onTakeItem); - ChatCallback.EVENT.register(AuthEventHandler::onPlayerChat); - PlayerMoveCallback.EVENT.register(AuthEventHandler::onPlayerMove); - - // From Fabric API - PlayerBlockBreakEvents.BEFORE.register((world, player, blockPos, blockState, blockEntity) -> onBreakBlock(player)); - UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> onUseBlock(player)); - UseItemCallback.EVENT.register((player, world, hand) -> onUseItem(player)); - AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> onAttackEntity(player)); - UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> onUseEntity(player)); - ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> reloadConfig(null)); - ServerLifecycleEvents.SERVER_STOPPED.register(this::onStopServer); - } - - /** - * Called on server stop. - */ - private void onStopServer(MinecraftServer server) { - logInfo("Shutting down SimpleAuth."); - DB.saveAll(playerCacheMap); - - // Closing threads - try { - THREADPOOL.shutdownNow(); - if (!THREADPOOL.awaitTermination(500, TimeUnit.MILLISECONDS)) { - Thread.currentThread().interrupt(); - } - } catch (InterruptedException e) { - logError(e.getMessage()); - THREADPOOL.shutdownNow(); - } - - // Closing DB connection - DB.close(); - } -} diff --git a/src/main/java/org/samo_lego/simpleauth/event/entity/player/ChatCallback.java b/src/main/java/org/samo_lego/simpleauth/event/entity/player/ChatCallback.java deleted file mode 100644 index ae1549f..0000000 --- a/src/main/java/org/samo_lego/simpleauth/event/entity/player/ChatCallback.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.samo_lego.simpleauth.event.entity.player; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; -import net.minecraft.util.ActionResult; - -public interface ChatCallback { - Event EVENT = EventFactory.createArrayBacked(ChatCallback.class, listeners -> (player, message) -> { - for (ChatCallback event : listeners) { - ActionResult result = event.onPlayerChat(player, message); - - if (result != ActionResult.PASS) { - return result; - } - } - return ActionResult.PASS; - }); - - ActionResult onPlayerChat(PlayerEntity player, String message); -} \ No newline at end of file diff --git a/src/main/java/org/samo_lego/simpleauth/event/entity/player/PlayerJoinServerCallback.java b/src/main/java/org/samo_lego/simpleauth/event/entity/player/PlayerJoinServerCallback.java deleted file mode 100644 index adfb59d..0000000 --- a/src/main/java/org/samo_lego/simpleauth/event/entity/player/PlayerJoinServerCallback.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.samo_lego.simpleauth.event.entity.player; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.server.network.ServerPlayerEntity; - -public interface PlayerJoinServerCallback { - Event EVENT = EventFactory.createArrayBacked(PlayerJoinServerCallback.class, listeners -> (player) -> { - for (PlayerJoinServerCallback callback : listeners) { - callback.onPlayerJoin(player); - } - }); - void onPlayerJoin(ServerPlayerEntity player); -} \ No newline at end of file diff --git a/src/main/java/org/samo_lego/simpleauth/event/entity/player/PlayerLeaveServerCallback.java b/src/main/java/org/samo_lego/simpleauth/event/entity/player/PlayerLeaveServerCallback.java deleted file mode 100644 index 9090130..0000000 --- a/src/main/java/org/samo_lego/simpleauth/event/entity/player/PlayerLeaveServerCallback.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.samo_lego.simpleauth.event.entity.player; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.server.network.ServerPlayerEntity; - -public interface PlayerLeaveServerCallback { - - Event EVENT = EventFactory.createArrayBacked(PlayerLeaveServerCallback.class, listeners -> (player) -> { - for (PlayerLeaveServerCallback callback : listeners) { - callback.onPlayerLeave(player); - } - }); - void onPlayerLeave(ServerPlayerEntity player); -} \ No newline at end of file diff --git a/src/main/java/org/samo_lego/simpleauth/event/entity/player/PlayerMoveCallback.java b/src/main/java/org/samo_lego/simpleauth/event/entity/player/PlayerMoveCallback.java deleted file mode 100644 index 6ec185f..0000000 --- a/src/main/java/org/samo_lego/simpleauth/event/entity/player/PlayerMoveCallback.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.samo_lego.simpleauth.event.entity.player; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; - -public interface PlayerMoveCallback { - Event EVENT = EventFactory.createArrayBacked(PlayerMoveCallback.class, listeners -> (player) -> { - for (PlayerMoveCallback event : listeners) { - ActionResult result = event.onPlayerMove(player); - - if (result != ActionResult.PASS) { - return result; - } - } - return ActionResult.PASS; - }); - - ActionResult onPlayerMove(PlayerEntity player); -} \ No newline at end of file diff --git a/src/main/java/org/samo_lego/simpleauth/event/entity/player/PrePlayerJoinCallback.java b/src/main/java/org/samo_lego/simpleauth/event/entity/player/PrePlayerJoinCallback.java deleted file mode 100644 index bedc3b0..0000000 --- a/src/main/java/org/samo_lego/simpleauth/event/entity/player/PrePlayerJoinCallback.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.samo_lego.simpleauth.event.entity.player; - -import com.mojang.authlib.GameProfile; -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.server.PlayerManager; -import net.minecraft.text.LiteralText; - -import java.net.SocketAddress; - -public interface PrePlayerJoinCallback { - Event EVENT = EventFactory.createArrayBacked( - PrePlayerJoinCallback.class, listeners -> ( - socketAddress, profile, manager - ) -> { - for (PrePlayerJoinCallback event : listeners) { - - LiteralText returnText = event.checkCanPlayerJoinServer(socketAddress, profile, manager); - - if (returnText != null) { - return returnText; - } - } - return null; - }); - - LiteralText checkCanPlayerJoinServer(SocketAddress socketAddress, GameProfile profile, PlayerManager manager); -} \ No newline at end of file diff --git a/src/main/java/org/samo_lego/simpleauth/event/item/DropItemCallback.java b/src/main/java/org/samo_lego/simpleauth/event/item/DropItemCallback.java deleted file mode 100644 index 79b59c5..0000000 --- a/src/main/java/org/samo_lego/simpleauth/event/item/DropItemCallback.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.samo_lego.simpleauth.event.item; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; - -public interface DropItemCallback { - Event EVENT = EventFactory.createArrayBacked(DropItemCallback.class, listeners -> (player) -> { - for (DropItemCallback event : listeners) { - ActionResult result = event.onDropItem(player); - if (result != ActionResult.PASS) { - return result; - } - } - return ActionResult.PASS; - }); - - ActionResult onDropItem(PlayerEntity player); -} \ No newline at end of file diff --git a/src/main/java/org/samo_lego/simpleauth/event/item/TakeItemCallback.java b/src/main/java/org/samo_lego/simpleauth/event/item/TakeItemCallback.java deleted file mode 100644 index 9b2aa43..0000000 --- a/src/main/java/org/samo_lego/simpleauth/event/item/TakeItemCallback.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.samo_lego.simpleauth.event.item; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; - -public interface TakeItemCallback { - Event EVENT = EventFactory.createArrayBacked(TakeItemCallback.class, listeners -> (player) -> { - for (TakeItemCallback event : listeners) { - ActionResult result = event.onTakeItem(player); - if (result != ActionResult.PASS) { - return result; - } - } - return ActionResult.PASS; - }); - - ActionResult onTakeItem(PlayerEntity player); -}