-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
86 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
src/main/kotlin/one/oktw/galaxy/proxy/resourcepack/ResourcePackHelper.kt
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/one/oktw/galaxy/proxy/resourcepack/ResourcePackManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package one.oktw.galaxy.proxy.resourcepack | ||
|
||
import com.velocitypowered.api.proxy.Player | ||
import com.velocitypowered.api.proxy.player.ResourcePackInfo | ||
import one.oktw.galaxy.proxy.Main.Companion.main | ||
import kotlin.math.min | ||
|
||
class ResourcePackManager { | ||
private val appliedPacks: MutableMap<Player, List<ResourcePackInfo>> = mutableMapOf() | ||
|
||
fun updatePlayerResourcePacks(player: Player, galaxy: String) { | ||
val new = main.config.galaxies[galaxy]?.ResourcePacks?.mapNotNull { main.config.resourcePacks[it]?.packInfo() } ?: emptyList() | ||
val old = this.appliedPacks.getOrElse(player) { listOf() } | ||
|
||
// Matching new resource packs | ||
var updateIndex = old.lastIndex | ||
for (i in 0..min(old.size, new.size)) { | ||
if (old.getOrNull(i)?.hash != new.getOrNull(i)?.hash) { | ||
updateIndex = i | ||
break | ||
} | ||
} | ||
|
||
// Remove not match resource packs | ||
old.subList(updateIndex, old.size).forEach(player::removeResourcePacks) | ||
|
||
// Add new resource packs | ||
new.subList(updateIndex, new.size).forEach(player::sendResourcePacks) | ||
|
||
// Save player resource packs state | ||
appliedPacks[player] = new.toList() | ||
} | ||
|
||
// Remove player resource packs state | ||
fun removePlayer(player: Player) { | ||
appliedPacks.remove(player) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"base": "", | ||
"lobby": "" | ||
} |