Skip to content

Commit

Permalink
1.3.0 - CCA not required anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Oct 20, 2020
1 parent 38c5078 commit 5fbab39
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 269 deletions.
47 changes: 35 additions & 12 deletions .github/workflows/building.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,40 @@ jobs:
- name: Build with Gradle
run: ./gradlew build
- name: Execute permission for renaming script
run: chmod +x renaming.sh
- name: Running renaming script
run: ./renaming.sh

# Publishing to dev-builds branch
- name: GitHub Pages
if: success()
uses: crazy-max/[email protected]
run: chmod +x main.sh
- name: Running main script
run: ./.github/workflows/main.sh

# Artifact upload
- name: Uploading artifacts
uses: actions/upload-artifact@v2
with:
#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/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
build_dir: build/libs
target_branch: dev-builds
keep_history: false
# 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/[email protected]
env:
GITHUB_PAT: ${{ secrets.pat }}
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.PROJECT_ID }}_fabric-${{ env.VERSION }}-${{ env.MC_VERSION }}.jar
asset_content_type: application/zip
33 changes: 33 additions & 0 deletions .github/workflows/main.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,9 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Cardinal Components
modImplementation "io.github.onyxstudios.Cardinal-Components-API:${project.cca_module}:${project.cca_version}"
modImplementation "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:${project.cca_version}"
//modImplementation "carpet:fabric-carpet:1.16-${project.carpet_core_version}"
modImplementation "com.github.gnembon:fabric-carpet:${project.carpet_branch}-SNAPSHOT"


// Includes Cardinal Components API as a Jar-in-Jar dependency (optional)
//include "io.github.OnyxStudios:Cardinal-Components-API:${project.cca_module}:${project.cca_version}"
}

processResources {
Expand Down
6 changes: 1 addition & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ loader_version=0.9.3+build.207
fabric_version=0.20.2+build.402-1.16

# Mod Properties
mod_version = 1.2.0
mod_version = 1.3.0
maven_group = org.samo_lego
archives_base_name = fabrictailor

# Dependencies
cca_module = cardinal-components-entity
cca_version = 2.5.4

# Carpet for debugging
carpet_core_version = 1.4.0+v200623
carpet_branch = master
31 changes: 0 additions & 31 deletions renaming.sh

This file was deleted.

124 changes: 2 additions & 122 deletions src/main/java/org/samo_lego/fabrictailor/FabricTailor.java
Original file line number Diff line number Diff line change
@@ -1,81 +1,40 @@
package org.samo_lego.fabrictailor;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import nerdhub.cardinal.components.api.ComponentRegistry;
import nerdhub.cardinal.components.api.ComponentType;
import nerdhub.cardinal.components.api.event.EntityComponentCallback;
import nerdhub.cardinal.components.api.util.EntityComponents;
import nerdhub.cardinal.components.api.util.RespawnCopyStrategy;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.impl.networking.server.EntityTrackerStreamAccessor;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.util.Identifier;
import net.minecraft.world.biome.source.BiomeAccess;
import net.minecraft.world.chunk.ChunkManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.samo_lego.fabrictailor.command.SkinCommand;
import org.samo_lego.fabrictailor.event.PlayerJoinServerCallback;
import org.samo_lego.fabrictailor.mixin.EntityTrackerAccessor;
import org.samo_lego.fabrictailor.mixin.ThreadedAnvilChunkStorageAccessor;

import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import static org.samo_lego.fabrictailor.event.TailorEventHandler.onPlayerJoin;

public class FabricTailor implements ModInitializer {
public static final String MODID = "fabrictailor";

private static final Logger LOGGER = LogManager.getLogger();

public static ExecutorService THREADPOOL;

private static final ComponentType<SkinSaveData> SKIN_DATA = ComponentRegistry.INSTANCE.registerIfAbsent(new Identifier(MODID,"skin_data"), SkinSaveData.class);


@Override
public void onInitialize() {
// Registering /skin command
CommandRegistrationCallback.EVENT.register(SkinCommand::register);

// Registering player join event
// It passes the skin data to method as well, in order to apply skin at join
PlayerJoinServerCallback.EVENT.register(player -> onPlayerJoin(player, SKIN_DATA.get(player).getValue(), SKIN_DATA.get(player).getSignature()));

// Add the component to every instance of PlayerEntity
EntityComponentCallback.event(PlayerEntity.class).register((player, components) -> components.put(SKIN_DATA, new SkinSaver("", "")));
EntityComponents.setRespawnCopyStrategy(SKIN_DATA, RespawnCopyStrategy.ALWAYS_COPY);

// Stop server event
ServerLifecycleEvents.SERVER_STOPPED.register(this::onStopServer);
ServerLifecycleEvents.SERVER_STARTING.register(this::onStartServer);
}

// Logging methods
public static void infoLog(String info) {
LOGGER.info("[FabricTailor] " + info);
}
public static void errorLog(String error) {
LOGGER.error("[FabricTailor] An error occurred: " + error);
}

/**
* Called on server start
* Called on server start.
*/
private void onStartServer(MinecraftServer server) {
// Initialising executor service
Expand All @@ -88,91 +47,12 @@ private void onStartServer(MinecraftServer server) {
private void onStopServer(MinecraftServer server) {
try {
THREADPOOL.shutdownNow();
if (!THREADPOOL.awaitTermination(100, TimeUnit.MICROSECONDS)) {
if (!THREADPOOL.awaitTermination(500, TimeUnit.MILLISECONDS)) {
Thread.currentThread().interrupt();
}
} catch (InterruptedException e) {
errorLog(e.getMessage());
THREADPOOL.shutdownNow();
}
}
/**
* Sets the skin to the specified player and reloads it with {@link org.samo_lego.fabrictailor.FabricTailor#reloadSkin(ServerPlayerEntity)}
* @param player player whose skin needs to be changed
* @param value skin texture value
* @param signature skin texture signature
* @return true if it was successful, otherwise false
*/
public static boolean setPlayerSkin(ServerPlayerEntity player, String value, String signature) {
boolean result;
GameProfile gameProfile = player.getGameProfile();
PropertyMap map = gameProfile.getProperties();

try {
Property property = map.get("textures").iterator().next();
map.remove("textures", property);
} catch (Exception ignored) {
// Player has no skin data, no worries
}

try {
if(!value.equals("") && !signature.equals(""))
map.put("textures", new Property("textures", value, signature));

// Reloading is needed in order to see the new skin
reloadSkin(player);

// We need to save data as well
// Cardinal Components
// Thanks Pyro and UPcraft for helping me out :)
SKIN_DATA.get(player).setValue(value);
SKIN_DATA.get(player).setSignature(signature);

result = true;
} catch (Error e) {
// Something went wrong when trying to set the skin
errorLog(e.getMessage());
result = false;
}

return result;
}

/**
* <p>
* This method has been adapted from the Impersonate mod's <a href="https://github.com/Ladysnake/Impersonate/blob/1.16/src/main/java/io/github/ladysnake/impersonate/impl/ServerPlayerSkins.java">source code</a>
* under GNU Lesser General Public License.
*
* Reloads player's skin for all the players (including the one that has changed the skin)
* @param player player that wants to have the skin reloaded
*
* @author Pyrofab
*/
private static void reloadSkin(ServerPlayerEntity player) {
// Refreshing tablist for each player
PlayerManager playerManager = Objects.requireNonNull(player.getServer()).getPlayerManager();
playerManager.sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.REMOVE_PLAYER, player));
playerManager.sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, player));

ChunkManager manager = player.world.getChunkManager();
assert manager instanceof ServerChunkManager;
ThreadedAnvilChunkStorage storage = ((ServerChunkManager)manager).threadedAnvilChunkStorage;
EntityTrackerAccessor trackerEntry = ((ThreadedAnvilChunkStorageAccessor) storage).getEntityTrackers().get(player.getEntityId());

((EntityTrackerStreamAccessor) trackerEntry).fabric_getTrackingPlayers().forEach(tracking -> trackerEntry.getEntry().startTracking(tracking));

// need to change the player entity on the client
ServerWorld targetWorld = (ServerWorld) player.world;
player.networkHandler.sendPacket(new PlayerRespawnS2CPacket(targetWorld.getDimension(), targetWorld.getRegistryKey(), BiomeAccess.hashSeed(targetWorld.getSeed()), player.interactionManager.getGameMode(), player.interactionManager.method_30119(), targetWorld.isDebugWorld(), targetWorld.isFlat(), true));
player.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.yaw, player.pitch);
player.server.getPlayerManager().sendCommandTree(player);
player.networkHandler.sendPacket(new ExperienceBarUpdateS2CPacket(player.experienceProgress, player.totalExperience, player.experienceLevel));
player.networkHandler.sendPacket(new HealthUpdateS2CPacket(player.getHealth(), player.getHungerManager().getFoodLevel(), player.getHungerManager().getSaturationLevel()));
for (StatusEffectInstance statusEffect : player.getStatusEffects()) {
player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(player.getEntityId(), statusEffect));
}
player.sendAbilitiesUpdate();
player.server.getPlayerManager().sendWorldInfo(player, targetWorld);
player.server.getPlayerManager().sendPlayerStatus(player);
}
}
53 changes: 0 additions & 53 deletions src/main/java/org/samo_lego/fabrictailor/SkinSaver.java

This file was deleted.

Loading

0 comments on commit 5fbab39

Please sign in to comment.