From 8acba5649d04893008e22731d5ff5ed02148bd65 Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Sun, 27 Sep 2020 11:15:50 +0200 Subject: [PATCH 1/6] New fapi block break event --- .../java/org/samo_lego/simpleauth/SimpleAuth.java | 14 ++++++++------ .../simpleauth/event/AuthEventHandler.java | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java index 76b0876..b0bb451 100644 --- a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java +++ b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java @@ -39,6 +39,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import static org.iq80.leveldb.impl.Iq80DBFactory.bytes; +import static org.samo_lego.simpleauth.commands.AuthCommand.reloadConfig; +import static org.samo_lego.simpleauth.event.AuthEventHandler.*; import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake; import static org.samo_lego.simpleauth.utils.SimpleLogger.logError; import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo; @@ -122,12 +124,12 @@ public class SimpleAuth implements DedicatedServerModInitializer { PlayerMoveCallback.EVENT.register(AuthEventHandler::onPlayerMove); // From Fabric API - AttackBlockCallback.EVENT.register((playerEntity, world, hand, blockPos, direction) -> AuthEventHandler.onAttackBlock(playerEntity)); - 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) -> AuthCommand.reloadConfig(null)); + PlayerBlockBreakEvents.BEFORE.register((world, playerEntity, blockPos, blockState, blockEntity) -> onBreakBlock(playerEntity)); + 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); } diff --git a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java index 8c01114..4040a4d 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -174,13 +174,13 @@ public class AuthEventHandler { return ActionResult.PASS; } - // Punching a block - public static ActionResult onAttackBlock(PlayerEntity player) { + // Breaking a block + public static boolean onBreakBlock(PlayerEntity player) { if(!isAuthenticated((ServerPlayerEntity) player) && !config.experimental.allowBlockPunch) { player.sendMessage(notAuthenticated(player), false); - return ActionResult.FAIL; + return false; } - return ActionResult.PASS; + return true; } // Using an item From 3d6d9c2d936ed3af3e73aa36f5031f7f974a9f38 Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Sat, 10 Oct 2020 20:46:02 +0200 Subject: [PATCH 2/6] Loom update --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c8f4d4a..b212613 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.4-SNAPSHOT' + id 'fabric-loom' version '0.5-SNAPSHOT' id 'maven-publish' } From 57f702f824b8b60c494351b41fe5bcacf5794617 Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Sat, 10 Oct 2020 22:23:57 +0200 Subject: [PATCH 3/6] Fixing #18 --- gradle.properties | 2 +- .../java/org/samo_lego/simpleauth/storage/PlayerCache.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9540256..441c091 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ loader_version=0.9.3+build.207 fabric_version=0.20.2+build.402-1.16 # Mod Properties -mod_version = 1.5.2 +mod_version = 1.5.3 maven_group = org.samo_lego archives_base_name = simpleauth diff --git a/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java b/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java index 426bbf2..b1df3b0 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java @@ -63,7 +63,7 @@ public class PlayerCache { if(player != null) { if(config.experimental.debugMode) - logInfo("Creating cache for " + player.getName()); + logInfo("Creating cache for " + player.getName().asString()); this.lastIp = player.getIp(); this.lastAir = player.getAir(); @@ -99,7 +99,7 @@ public class PlayerCache { } else { this.password = passwordElement.getAsString(); - this.isRegistered = true; + this.isRegistered = !this.password.isEmpty(); } @@ -131,6 +131,6 @@ public class PlayerCache { this.isAuthenticated = false; this.loginTries = 0; if(config.experimental.debugMode) - logInfo("Cache created. Registered: " + this.isRegistered + ", hashed password: " + this.password); + logInfo("Cache created. Registered: " + this.isRegistered + ", hashed password: " + this.password + "."); } } From fcab8f8a4605aa32438864e8dab006f4b6b05232 Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Sun, 11 Oct 2020 17:33:25 +0200 Subject: [PATCH 4/6] Fixing #25 --- .../simpleauth/event/AuthEventHandler.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java index 4040a4d..d42395c 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -121,14 +121,16 @@ public class AuthEventHandler { playerCache.lastAir = player.getAir(); playerCache.wasOnFire = player.isOnFire(); playerCache.wasInPortal = player.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL); - playerCache.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue()); - playerCache.lastX = player.getX(); - playerCache.lastY = player.getY(); - playerCache.lastZ = player.getZ(); + if(isAuthenticated(player)) { + playerCache.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue()); + playerCache.lastX = player.getX(); + playerCache.lastY = player.getY(); + playerCache.lastZ = player.getZ(); - // Setting the session expire time - if(isAuthenticated(player) && config.main.sessionTimeoutTime != -1) - playerCache.validUntil = System.currentTimeMillis() + config.main.sessionTimeoutTime * 1000; + // Setting the session expire time + if(config.main.sessionTimeoutTime != -1) + playerCache.validUntil = System.currentTimeMillis() + config.main.sessionTimeoutTime * 1000; + } } // Player chatting From 25cdfc961cbb761020681e36a2f9a648a22d745d Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Sun, 11 Oct 2020 22:03:34 +0200 Subject: [PATCH 5/6] Implementing #26 --- .../org/samo_lego/simpleauth/SimpleAuth.java | 41 +++++++++++-------- .../simpleauth/commands/AuthCommand.java | 29 +++++++++---- .../simpleauth/commands/LogoutCommand.java | 13 +++++- .../simpleauth/event/AuthEventHandler.java | 10 +++-- .../simpleauth/storage/AuthConfig.java | 16 ++++---- .../simpleauth/storage/PlayerCache.java | 39 +++++++++++------- 6 files changed, 93 insertions(+), 55 deletions(-) diff --git a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java index b0bb451..004a859 100644 --- a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java +++ b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java @@ -146,10 +146,10 @@ public class SimpleAuth implements DedicatedServerModInitializer { data.addProperty("password", playerCache.password); JsonObject lastLocation = new JsonObject(); - lastLocation.addProperty("dim", playerCache.lastDim); - lastLocation.addProperty("x", playerCache.lastX); - lastLocation.addProperty("y", playerCache.lastY); - lastLocation.addProperty("z", playerCache.lastZ); + lastLocation.addProperty("dim", playerCache.lastLocation.lastDim); + lastLocation.addProperty("x", playerCache.lastLocation.lastX); + lastLocation.addProperty("y", playerCache.lastLocation.lastY); + lastLocation.addProperty("z", playerCache.lastLocation.lastZ); data.addProperty("lastLocation", lastLocation.toString()); @@ -248,8 +248,13 @@ public class SimpleAuth implements DedicatedServerModInitializer { // Marking player as not authenticated String uuid = convertUuid(player); - playerCacheMap.put(uuid, new PlayerCache(uuid, player)); - playerCacheMap.get(uuid).isAuthenticated = false; + PlayerCache cache = playerCacheMap.get(uuid); + if(cache == null) { + cache = new PlayerCache(uuid, player); + playerCacheMap.put(uuid, cache); + } + cache.isAuthenticated = false; + // Teleporting player to spawn to hide its position if(config.main.spawnOnJoin) @@ -303,8 +308,8 @@ public class SimpleAuth implements DedicatedServerModInitializer { config.worldSpawn.x, config.worldSpawn.y, config.worldSpawn.z, - 90, - 90 + config.worldSpawn.yaw, + config.worldSpawn.pitch ); return; } @@ -312,22 +317,22 @@ public class SimpleAuth implements DedicatedServerModInitializer { // Puts player to last cached position try { player.teleport( - server.getWorld(RegistryKey.of(Registry.DIMENSION, new Identifier(cache.lastDim))), - cache.lastX, - cache.lastY, - cache.lastZ, - 0, - 0 + server.getWorld(RegistryKey.of(Registry.DIMENSION, new Identifier(cache.lastLocation.lastDim))), + cache.lastLocation.lastX, + cache.lastLocation.lastY, + cache.lastLocation.lastZ, + cache.lastLocation.lastYaw, + cache.lastLocation.lastPitch ); } catch (Error e) { player.sendMessage(new LiteralText(config.lang.corruptedPlayerData), false); logError("Couldn't teleport player " + player.getName().asString()); logError( String.format("Last recorded position is X: %s, Y: %s, Z: %s in dimension %s", - cache.lastX, - cache.lastY, - cache.lastZ, - cache.lastDim + cache.lastLocation.lastX, + cache.lastLocation.lastY, + cache.lastLocation.lastZ, + cache.lastLocation.lastDim )); } } diff --git a/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java index 7667984..0a9bf53 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java @@ -3,6 +3,7 @@ package org.samo_lego.simpleauth.commands; import com.mojang.brigadier.CommandDispatcher; import net.minecraft.command.argument.BlockPosArgumentType; import net.minecraft.command.argument.DimensionArgumentType; +import net.minecraft.command.argument.RotationArgumentType; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.command.ServerCommandSource; @@ -48,17 +49,23 @@ public class AuthCommand { ctx.getSource().getEntityOrThrow().getEntityWorld().getRegistryKey().getValue(), ctx.getSource().getEntityOrThrow().getX(), ctx.getSource().getEntityOrThrow().getY(), - ctx.getSource().getEntityOrThrow().getZ() + ctx.getSource().getEntityOrThrow().getZ(), + ctx.getSource().getEntityOrThrow().yaw, + ctx.getSource().getEntityOrThrow().pitch )) .then(argument("dimension", DimensionArgumentType.dimension()) .then(argument("position", BlockPosArgumentType.blockPos()) - .executes(ctx -> setSpawn( - ctx.getSource(), - DimensionArgumentType.getDimensionArgument(ctx, "dimension").getRegistryKey().getValue(), - BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getX(), - // +1 to not spawn player in ground - BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getY() + 1, - BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getZ() + .then(argument("angle", RotationArgumentType.rotation()) + .executes(ctx -> setSpawn( + ctx.getSource(), + DimensionArgumentType.getDimensionArgument(ctx, "dimension").getRegistryKey().getValue(), + BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getX(), + // +1 to not spawn player in ground + BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getY() + 1, + BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getZ(), + RotationArgumentType.getRotation(ctx, "angle").toAbsoluteRotation(ctx.getSource()).y, + RotationArgumentType.getRotation(ctx, "angle").toAbsoluteRotation(ctx.getSource()).x + ) ) ) ) @@ -146,14 +153,18 @@ public class AuthCommand { * @param x x coordinate of the global spawn * @param y y coordinate of the global spawn * @param z z coordinate of the global spawn + * @param yaw player yaw (y rotation) + * @param pitch player pitch (x rotation) * @return 0 */ - private static int setSpawn(ServerCommandSource source, Identifier world, double x, double y, double z) { + private static int setSpawn(ServerCommandSource source, Identifier world, double x, double y, double z, float yaw, float pitch) { // Setting config values and saving config.worldSpawn.dimension = String.valueOf(world); config.worldSpawn.x = x; config.worldSpawn.y = y; config.worldSpawn.z = z; + config.worldSpawn.yaw = yaw; + config.worldSpawn.pitch = pitch; config.main.spawnOnJoin = true; config.save(new File("./mods/SimpleAuth/config.json")); diff --git a/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java index 18eafbd..1ffd8ee 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java @@ -5,10 +5,11 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; +import org.samo_lego.simpleauth.storage.PlayerCache; import static net.minecraft.server.command.CommandManager.literal; -import static org.samo_lego.simpleauth.SimpleAuth.config; -import static org.samo_lego.simpleauth.SimpleAuth.deauthenticatePlayer; +import static org.samo_lego.simpleauth.SimpleAuth.*; +import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid; public class LogoutCommand { @@ -21,6 +22,14 @@ public class LogoutCommand { private static int logout(ServerCommandSource serverCommandSource) throws CommandSyntaxException { ServerPlayerEntity player = serverCommandSource.getPlayer(); + PlayerCache playerCache = playerCacheMap.get(convertUuid(player)); + playerCache.lastLocation.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue()); + playerCache.lastLocation.lastX = player.getX(); + playerCache.lastLocation.lastY = player.getY(); + playerCache.lastLocation.lastZ = player.getZ(); + playerCache.lastLocation.lastYaw = player.yaw; + playerCache.lastLocation.lastPitch = player.pitch; + deauthenticatePlayer(player); player.sendMessage(new LiteralText(config.lang.successfulLogout), false); return 1; diff --git a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java index d42395c..d02ecdf 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -122,10 +122,12 @@ public class AuthEventHandler { playerCache.wasOnFire = player.isOnFire(); playerCache.wasInPortal = player.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL); if(isAuthenticated(player)) { - playerCache.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue()); - playerCache.lastX = player.getX(); - playerCache.lastY = player.getY(); - playerCache.lastZ = player.getZ(); + playerCache.lastLocation.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue()); + playerCache.lastLocation.lastX = player.getX(); + playerCache.lastLocation.lastY = player.getY(); + playerCache.lastLocation.lastZ = player.getZ(); + playerCache.lastLocation.lastYaw = player.yaw; + playerCache.lastLocation.lastPitch = player.pitch; // Setting the session expire time if(config.main.sessionTimeoutTime != -1) diff --git a/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java b/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java index dfa379c..1aeaace 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java @@ -95,13 +95,15 @@ public class AuthConfig { * @see wiki */ public static class WorldSpawn { - /** - * Dimension id, e.g. "minecraft:overworld" - */ - public String dimension; - public double x; - public double y; - public double z; + /** + * Dimension id, e.g. "minecraft:overworld" + */ + public String dimension; + public double x; + public double y; + public double z; + public float yaw; + public float pitch; } } public static class LangConfig { diff --git a/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java b/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java index b1df3b0..7880644 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java @@ -50,10 +50,17 @@ public class PlayerCache { /** * Last recorded position before de-authentication. */ - public String lastDim; - public double lastX; - public double lastY; - public double lastZ; + public static class LastLocation { + public String lastDim; + public double lastX; + public double lastY; + public double lastZ; + public float lastYaw; + public float lastPitch; + } + + public PlayerCache.LastLocation lastLocation = new PlayerCache.LastLocation(); + private static final Gson gson = new Gson(); @@ -70,11 +77,13 @@ public class PlayerCache { this.wasOnFire = player.isOnFire(); // Setting position cache - this.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue()); + this.lastLocation.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue()); this.wasInPortal = player.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL); - this.lastX = player.getX(); - this.lastY = player.getY(); - this.lastZ = player.getZ(); + this.lastLocation.lastX = player.getX(); + this.lastLocation.lastY = player.getY(); + this.lastLocation.lastZ = player.getZ(); + this.lastLocation.lastYaw = player.yaw; + this.lastLocation.lastPitch = player.pitch; } else { this.wasOnFire = false; @@ -110,14 +119,13 @@ public class PlayerCache { if (lastLoc != null) { // Getting DB coords JsonObject lastLocation = gson.fromJson(lastLoc.getAsString(), JsonObject.class); - this.lastDim = lastLocation.get("dim").isJsonNull() ? config.worldSpawn.dimension : lastLocation.get("dim").getAsString(); - this.lastX = lastLocation.get("x").isJsonNull() ? config.worldSpawn.x : lastLocation.get("x").getAsDouble(); - this.lastY = lastLocation.get("y").isJsonNull() ? config.worldSpawn.y : lastLocation.get("y").getAsDouble(); - this.lastZ = lastLocation.get("z").isJsonNull() ? config.worldSpawn.z : lastLocation.get("z").getAsDouble(); + this.lastLocation.lastDim = lastLocation.get("dim").isJsonNull() ? config.worldSpawn.dimension : lastLocation.get("dim").getAsString(); + this.lastLocation.lastX = lastLocation.get("x").isJsonNull() ? config.worldSpawn.x : lastLocation.get("x").getAsDouble(); + this.lastLocation.lastY = lastLocation.get("y").isJsonNull() ? config.worldSpawn.y : lastLocation.get("y").getAsDouble(); + this.lastLocation.lastZ = lastLocation.get("z").isJsonNull() ? config.worldSpawn.z : lastLocation.get("z").getAsDouble(); + this.lastLocation.lastYaw = lastLocation.get("yaw") == null ? 90 : lastLocation.get("yaw").getAsFloat(); + this.lastLocation.lastPitch = lastLocation.get("pitch") == null ? 0 : lastLocation.get("pitch").getAsFloat(); - // Removing location data from DB - json.remove("lastLocation"); - DB.updateUserData(uuid, json.toString()); } } catch (JsonSyntaxException ignored) { // Player didn't have any coords in db to tp to @@ -130,6 +138,7 @@ public class PlayerCache { } this.isAuthenticated = false; this.loginTries = 0; + if(config.experimental.debugMode) logInfo("Cache created. Registered: " + this.isRegistered + ", hashed password: " + this.password + "."); } From 44bd676f669cc24b411df94fd98436756796f4d0 Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Sun, 11 Oct 2020 22:04:51 +0200 Subject: [PATCH 6/6] Auto-releasing on version change --- .github/workflows/ci_fabric-stable.yml | 32 ++++++++++++++++++++++--- .github/workflows/main.sh | 33 ++++++++++++++++++++++++++ .github/workflows/renaming.sh | 17 ------------- 3 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/main.sh delete mode 100644 .github/workflows/renaming.sh diff --git a/.github/workflows/ci_fabric-stable.yml b/.github/workflows/ci_fabric-stable.yml index 00737b7..7e98176 100644 --- a/.github/workflows/ci_fabric-stable.yml +++ b/.github/workflows/ci_fabric-stable.yml @@ -28,9 +28,9 @@ jobs: - name: Build with Gradle run: ./gradlew build - name: Execute permission for renaming script - run: chmod +x ./.github/workflows/renaming.sh - - name: Running renaming script - run: ./.github/workflows/renaming.sh + run: chmod +x ./.github/workflows/main.sh + - name: Running main script + run: ./.github/workflows/main.sh # Artifact upload - name: Uploading artifacts @@ -39,3 +39,29 @@ jobs: #name: ${{ env.BUILDNAME }}.jar name: UNZIP_ME_${{ env.BUILDNAME }} path: build/libs/${{ env.BUILDNAME }}.jar + - name: Create a Release + if: ${{ env.SHOULD_PUBLISH }} + id: create_release + uses: actions/create-release@v1.1.4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + # The name of the tag. This should come from the webhook payload, `github.GITHUB_REF` when a user pushes a new tag + tag_name: ${{ env.VERSION }} + # The name of the release. For example, `Release v1.0.1` + release_name: SimpleAuth ${{ env.VERSION }} + # Text describing the contents of the tag. + body: This release was created automatically, since version was bumped. Should be stable unless I messed up something. + - name: Upload a Release Asset + if: ${{ env.SHOULD_PUBLISH }} + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + # The URL for uploading assets to the release + upload_url: ${{ steps.create_release.outputs.upload_url }} + # The path to the asset you want to upload + asset_path: build/libs/${{ env.BUILDNAME }}.jar + # The name of the asset you want to upload + asset_name: ${{ env.BUILDNAME }} + asset_content_type: application/zip \ No newline at end of file diff --git a/.github/workflows/main.sh b/.github/workflows/main.sh new file mode 100644 index 0000000..0a145b7 --- /dev/null +++ b/.github/workflows/main.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Setting the variables +projectId="$(grep 'archives_base_name' gradle.properties | sed 's/archives_base_name = //g;s/ //g;s/,//g;s/"//g')" +version="$(grep 'mod_version' gradle.properties | grep -o '[0-9]*\.[0-9]*\.[0-9]*')" +mcVersion="$(grep 'minecraft_version' gradle.properties | sed 's/minecraft_version=//g;s/ //g;s/,//g;s/"//g')" + +cd ./build/libs || exit + +buildName="$projectId-$version-devbuild_$GITHUB_RUN_NUMBER-MC_$mcVersion" + +echo "Build is going to be renamed: $buildName.jar" +# Renaming the dev build +mv "$projectId-$version-$mcVersion.jar" "$buildName.jar" + +# Setting the buildname for GH actions +echo "BUILDNAME=$buildName" >> $GITHUB_ENV +echo "PROJECT_ID=$projectId" >> $GITHUB_ENV +echo "VERSION=$version" >> $GITHUB_ENV +echo "MC_VERSION=$mcVersion" >> $GITHUB_ENV + + +# Checks if build is stable (I always bump version when I release stable, uploadable version) +latestRelease=$(curl -s "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/latest" | grep -oP '"tag_name": "\K(.*)(?=")') +echo "Latest release is: $latestRelease" + + +if [ "$latestRelease" == "$version" ]; then + echo "No need to publish release. Not necesarry stable yet." +else + echo "Hooray! New release!" + echo "SHOULD_PUBLISH=true" >> $GITHUB_ENV +fi \ No newline at end of file diff --git a/.github/workflows/renaming.sh b/.github/workflows/renaming.sh deleted file mode 100644 index 19ce17a..0000000 --- a/.github/workflows/renaming.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Setting the variables -projectId="$(grep 'archives_base_name' gradle.properties | sed 's/archives_base_name = //g;s/ //g;s/,//g;s/"//g')" -version="$(grep 'mod_version' gradle.properties | grep -o '[0-9]*\.[0-9]*\.[0-9]*')" -mcVersion="$(grep 'minecraft_version' gradle.properties | sed 's/minecraft_version=//g;s/ //g;s/,//g;s/"//g')" - -cd ./build/libs || exit - -buildName="$projectId-$version-devbuild_$GITHUB_RUN_NUMBER-MC_$mcVersion" - -echo "Build is going to be renamed: $buildName.jar" -# Renaming the dev build -mv "$projectId-$version-$mcVersion.jar" "$buildName.jar" - -#Setting the buildname for GH actions -echo "::set-env name=BUILDNAME::$buildName"