Skip to content

Commit

Permalink
1.0.7 - Aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
rqbik committed Dec 27, 2020
1 parent 402b8c7 commit 433b285
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ jobs:
release_name: Release ${{ github.ref }}
body: |
#### Release ${{ steps.get_tag.outputs.tag }}
Dependency:
```kotlin
repositories {
maven { setUrl("https://jitpack.io/") }
}
dependencies {
implementation("com.github.rqbik", "QologramAPI", "${{ steps.get_tag.outputs.tag }}")
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
}

dependencies {
implementation("com.github.rqbik", "QologramAPI", "1.0.5")
implementation("com.github.rqbik", "QologramAPI", "1.0.7")
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,32 @@ open class MultilineQologram(
var location = location
private set

fun setLocation(newLocation: Location, updateY: Boolean = true) {
fun setLocation(location: Location, updateY: Boolean = true) =
setLocation(location.x, location.y, location.z, location.yaw, location.pitch, updateY)

fun setLocation(
x: Double = location.x,
y: Double = location.y,
z: Double = location.z,
yaw: Float = location.yaw,
pitch: Float = location.pitch,
updateY: Boolean = true
) {
_lines.forEachIndexed { idx, it ->
it.setLocation(
newLocation.x,
if (updateY) newLocation.y + idx * margin else newLocation.y + (it.location.y - location.y),
newLocation.z
x,
if (updateY) y + idx * margin else y + (it.location.y - location.y),
z
)
}
location = newLocation

location.apply {
this.x = x
this.y = y
this.z = z
this.yaw = yaw
this.pitch = pitch
}
}

var margin = DEFAULT_MARGIN
Expand Down Expand Up @@ -72,6 +89,8 @@ open class MultilineQologram(
_lines.add(it)
}

fun addLines(lines: Iterable<String>) = lines.forEach(::addLine)

fun removeLine(line: Qologram, updateMargin: Boolean = true) = line.hide().also {
_lines.remove(line)
if (updateMargin) updateLineMargin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ open class MultipageQologram(val player: Player, location: Location, val builder
var location = location
private set

fun setLocation(location: Location, updateY: Boolean = true) {
pages.forEach { it.setLocation(location, updateY) }
}
fun setLocation(x: Double, y: Double, z: Double, yaw: Float, pitch: Float, updateY: Boolean = true) =
pages.forEach { it.setLocation(x, y, z, yaw, pitch, updateY) }

fun setLocation(location: Location, updateY: Boolean = true) =
setLocation(location.x, location.y, location.z, location.yaw, location.pitch, updateY)

fun addPage(builder: MultilineQologram.() -> Unit = {}) =
pages.add(MultilineQologram(player, location, builder).build())

fun show() { pages[currentPage].show() }
fun hide() { pages[currentPage].hide() }
fun show() = pages[currentPage].show()
fun hide() = pages[currentPage].hide()

internal var handler: InteractEventHandler<MultipageQologramInteractEvent>? = null

Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/com/github/rqbik/qologram/general/Qologram.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ open class Qologram(
player.handle.playerConnection.sendPacket(packet)
}

fun setLocation(
location: Location
) = setLocation(location.x, location.y, location.z, location.yaw, location.pitch)

private fun sendMetadata() {
val packetMeta = PacketPlayOutEntityMetadata(
id,
Expand Down

0 comments on commit 433b285

Please sign in to comment.