Skip to content

Commit

Permalink
ci: Upload workflow file build.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Oct 30, 2024
1 parent 1e5c3d7 commit 6447cc9
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 16 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.5.1

- name: Gradle Build
run: |
chmod 755 ./gradlew
./gradlew clean shadowJarAll
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: eSync Package
path: build/libs/*.jar
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import org.bukkit.inventory.ItemStack
class EnderChestEntity : IEntity {
val items = mutableMapOf<Int, ItemStack>()

override fun apply(player: Any) {
override fun apply(player: Any): Boolean {
if (player is Player) {
player.enderChest.clear()
items.forEach { slot, item -> player.enderChest.setItem(slot, item) }
items.forEach { (slot, item) -> player.enderChest.setItem(slot, item) }
return true
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import org.bukkit.inventory.ItemStack
class PlayerInventoryEntity : IEntity {
val inventory = mutableMapOf<Int, ItemStack>()

override fun apply(player: Any) {
override fun apply(player: Any): Boolean {
if (player is Player) {
player.inventory.clear()
inventory.forEach { (slot, item) -> player.inventory.setItem(slot, item) }
return true
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class PlayerStatusEntity : IEntity {
var health = 20.0
var maxHealth = 20.0

override fun apply(player: Any) {
override fun apply(player: Any): Boolean {
if (player is Player) {
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).baseValue = maxHealth
player.health = health
potions.forEach { player.addPotionEffect(it) }
return true
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class EnderChestModuleImpl(
}
}

override fun apply(uuid: UUID) {
override fun apply(uuid: UUID): Boolean {
val player = Bukkit.getPlayer(uuid)
this.find(uuid)?.apply(player)
return this.find(uuid)?.apply(player) ?: false
}

override fun toByteArray(uuid: UUID): ByteArray? {
Expand Down Expand Up @@ -65,7 +65,8 @@ class EnderChestModuleImpl(
for (i in 0 until count) {
val slot = byteBuf.readInt()
val length = byteBuf.readInt()
val bytes = byteBuf.readBytes(length).array()
val bytes = ByteArray(length)
byteBuf.readBytes(bytes)
val item = SerializerUtil.deserializerItem(bytes)
entity.items[slot] = item
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class InventoryModuleImpl(
}
}

override fun apply(uuid: UUID) {
override fun apply(uuid: UUID): Boolean {
val player = Bukkit.getPlayer(uuid)
this.find(uuid)?.apply(player)
return this.find(uuid)?.apply(player) ?: false
}

override fun toByteArray(uuid: UUID): ByteArray? {
Expand Down Expand Up @@ -67,7 +67,8 @@ class InventoryModuleImpl(
for (i in 0 until count) {
val slot = byteBuf.readInt()
val length = byteBuf.readInt()
val bytes = byteBuf.readBytes(length).array()
val bytes = ByteArray(length)
byteBuf.readBytes(length)
val item = SerializerUtil.deserializerItem(bytes)
entity.inventory[slot] = item
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class PlayerStatusModuleImpl(
}
}

override fun apply(uuid: UUID) {
override fun apply(uuid: UUID): Boolean {
val player = Bukkit.getPlayer(uuid)
this.find(uuid)?.apply(player)
return this.find(uuid)?.apply(player) ?: false
}

override fun toByteArray(uuid: UUID): ByteArray? {
Expand Down Expand Up @@ -69,7 +69,8 @@ class PlayerStatusModuleImpl(
val size = buf.readInt()
for (i in 0 until size) {
val length = buf.readInt()
val byteArray = buf.readBytes(length).array()
val byteArray = ByteArray(length)
buf.readBytes(byteArray)
val str = String(byteArray, Charsets.UTF_8)
val yaml = YamlConfiguration()
yaml.loadFromString(str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class SyncTransaction(
repository.updateState(uuid, it, SyncState.LOCKED)
val module = ModuleHandler.findByKey(it)!!
module.apply(player.uniqueId)
CacheHandler.playerCaches[uuid]!!.load(it)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.aiyostudio.esync.common.module

interface IEntity {

fun apply(player: Any)
fun apply(player: Any): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface IModule<out T : IEntity> {
/**
* Apply after data loading is complete.
*/
fun apply(uuid: UUID)
fun apply(uuid: UUID): Boolean

fun find(uuid: UUID): T?

Expand Down

0 comments on commit 6447cc9

Please sign in to comment.