Skip to content

Commit

Permalink
refactor: forced -> required
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jun 12, 2024
1 parent 1e8ce81 commit e897ca7
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 35 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=0.5
idofrontVersion=0.24.0
idofrontVersion=0.24.7
8 changes: 4 additions & 4 deletions src/main/kotlin/com/mineinabyss/packy/PackyGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object PackyGenerator {
?.let { packy.defaultPack.packMeta(packy.config.mcmeta.format, it.miniMsg()) }

// Add all forced packs to defaultPack
packy.templates.filter { it.value.forced }.values.mapNotNull { it.path.toFile().readPack() }.forEach {
packy.templates.filter { it.value.required }.values.mapNotNull { it.path.toFile().readPack() }.forEach {
packy.defaultPack.mergeWith(it)
}

Expand All @@ -55,14 +55,14 @@ object PackyGenerator {
val cachedPack = ResourcePack.resourcePack()
cachedPack.mergeWith(packy.defaultPack)

// Filters out all forced files as they are already in defaultPack
// Filters out all required files as they are already in defaultPack
// Filter all TemplatePacks that are not default or not in players enabledPackAddons
packy.templates.values.filter { !it.forced && it.id in templateIds }
packy.templates.values.filter { !it.required && it.id in templateIds }
.mapNotNull { it.path.toFile().readPack() }.forEach { cachedPack.mergeWith(it) }

cachedPack.sortItemOverrides()
if (packy.config.obfuscate) PackObfuscator.obfuscatePack(cachedPack)
MinecraftResourcePackWriter.minecraft().writeToDirectory(packy.plugin.dataFolder.resolve("test"), cachedPack)

MinecraftResourcePackWriter.minecraft().build(cachedPack).let {
val packyPack = PackyPack(it.hash(), packy.config.server.publicUrl(it.hash(), templateIds), it)
cachedPacks[templateIds] = packyPack
Expand Down
19 changes: 1 addition & 18 deletions src/main/kotlin/com/mineinabyss/packy/PackyPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,21 @@ import com.charleskorn.kaml.PolymorphismStyle
import com.charleskorn.kaml.SingleLineStringStyle
import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration
import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.geary.autoscan.autoscan
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.papermc.datastore.decode
import com.mineinabyss.idofront.config.ConfigFormats
import com.mineinabyss.idofront.config.Format
import com.mineinabyss.idofront.config.config
import com.mineinabyss.idofront.di.DI
import com.mineinabyss.idofront.messaging.observeLogger
import com.mineinabyss.idofront.nms.nbt.getOfflinePDC
import com.mineinabyss.idofront.plugin.listeners
import com.mineinabyss.idofront.textcomponents.miniMsg
import com.mineinabyss.packy.components.PackyData
import com.mineinabyss.packy.config.*
import com.mineinabyss.packy.listener.PlayerListener
import com.mineinabyss.packy.listener.TemplateLoadTriggers
import io.netty.channel.Channel
import io.netty.channel.ChannelDuplexHandler
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelPromise
import io.papermc.paper.adventure.PaperAdventure
import io.papermc.paper.network.ChannelInitializeListenerHolder
import kotlinx.coroutines.Job
import kotlinx.serialization.modules.EmptySerializersModule
import net.minecraft.network.Connection
import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket
import net.minecraft.network.protocol.common.ServerboundResourcePackPacket
import net.minecraft.network.protocol.configuration.ClientboundFinishConfigurationPacket
import org.bukkit.NamespacedKey
import org.bukkit.plugin.java.JavaPlugin
import team.unnamed.creative.ResourcePack
import java.util.*

class PackyPlugin : JavaPlugin() {

Expand Down Expand Up @@ -81,7 +64,7 @@ class PackyPlugin : JavaPlugin() {
TemplateLoadTriggers.registerTemplateHandlers()
PackyGenerator.setupForcedPackFiles()

PackyServer.registerConfigurationPacketListener()
PackyServer.registerConfigPacketHandler()
}


Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/mineinabyss/packy/PackyServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mineinabyss.packy
import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mccoroutine.bukkit.ticks
import com.mineinabyss.geary.papermc.datastore.decode
import com.mineinabyss.idofront.nms.interceptClientbound
import com.mineinabyss.idofront.nms.nbt.getOfflinePDC
import com.mineinabyss.idofront.textcomponents.miniMsg
import com.mineinabyss.packy.components.PackyData
Expand Down Expand Up @@ -58,7 +59,7 @@ object PackyServer {
delay(10.ticks)
}

fun registerConfigurationPacketListener() {
fun registerConfigPacketHandler() {
val key = NamespacedKey.fromString("configuration_listener", packy.plugin)
ChannelInitializeListenerHolder.addListener(key!!) { channel: Channel ->
channel.pipeline().addBefore("packet_handler", key.toString(), object : ChannelDuplexHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import com.mineinabyss.packy.config.packy
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.bukkit.entity.Player
import org.jetbrains.annotations.Unmodifiable

@Serializable
@SerialName("packy:packy_data")
data class PackyData(val enabledPackAddons: MutableSet<PackyTemplate> = packy.templates.values.filter { !it.forced && it.default }.toMutableSet(), var bypassForced: Boolean = false) {
data class PackyData(val enabledPackAddons: MutableSet<PackyTemplate> = packy.templates.values.filter { !it.required && it.default }.toMutableSet(), var bypassForced: Boolean = false) {
val enabledPackIds get() = enabledPackAddons.map { it.id }.toSortedSet()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class PackyTemplates(val templates: List<PackyTemplate> = listOf()) {
data class PackyTemplate(
val name: String,
val default: Boolean = false,
val forced: Boolean = false,
val required: Boolean = false,
@EncodeDefault(NEVER) val conflictsWith: Set<String> = setOf(),
@EncodeDefault(NEVER) val githubDownload: GithubDownload? = null,
@EncodeDefault(NEVER) val loadTrigger: LoadTrigger = LoadTrigger.NoTrigger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@ import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent

class PlayerListener : Listener {
/*@EventHandler(priority = EventPriority.HIGHEST)
fun PlayerJoinEvent.sendPack() {
if (PackyServer.packServer != null && !player.hasResourcePack()) packy.plugin.launch {
delay(packy.config.packSendDelay)
PackyServer.sendPack(player)
}
}*/

@EventHandler(priority = EventPriority.NORMAL)
fun PlayerJoinEvent.filterPackyData() {
// Remove old or forced keys from enabledPackAddons
player.packyData.enabledPackAddons.removeIf { t -> t.id !in packy.templates.keys || t.forced }
player.packyData.enabledPackAddons.removeIf { t -> t.id !in packy.templates.keys || t.required }
// Ensure that PackyTemplates are up-to-date
player.packyData.enabledPackAddons.filter { it in packy.templates.values }.forEach { template ->
player.packyData.enabledPackAddons -= template
Expand Down

0 comments on commit e897ca7

Please sign in to comment.