Skip to content

Commit

Permalink
修复 全息API
Browse files Browse the repository at this point in the history
修复 全息API
  • Loading branch information
Glomzzz committed Jun 21, 2023
1 parent c41c521 commit b96cecc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ private fun `null`() = prefixParser {
result { null }
}

@AsahiPrefix(["null-str"], "lang")
private fun nullStr() = prefixParser {
result { "null" }
}

@AsahiPrefix(["pass"], "lang")
private fun pass() = prefixParser {
result { "" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class HologramBuilder(private val location: Location) {
* @return 构建好的Hologram
*/
fun build(): IHologram {
val hologram = hologramManager.createHologram(location.clone(), content)
val hologram = hologramManager.createHologram(location.clone(), content, viewers)
if (stay != -1L) {
each?.also { vector ->
var count = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@ package com.skillw.pouvoir.api.feature.hologram

import com.skillw.pouvoir.api.plugin.map.component.Keyable
import org.bukkit.Location
import org.bukkit.entity.Player

/** 全息接口 */
interface IHologram : Keyable<String> {

/** 坐标 */
var location: Location

/** 内容 */
val content: List<String>

/** 可看到的玩家 */
val viewers: MutableSet<Player>

/**
* 传送
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.skillw.pouvoir.api.manager.sub
import com.skillw.pouvoir.api.feature.hologram.IHologram
import com.skillw.pouvoir.api.manager.Manager
import org.bukkit.Location
import org.bukkit.entity.Player

/**
* HologramManager
Expand All @@ -17,5 +18,5 @@ abstract class HologramManager : Manager {
* @param content
* @return
*/
abstract fun createHologram(location: Location, content: List<String>): IHologram
abstract fun createHologram(location: Location, content: List<String>, players: Set<Player>): IHologram
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ import org.bukkit.Location
import org.bukkit.entity.Player
import java.util.concurrent.ConcurrentHashMap

class Hologram(override var location: Location, override val content: List<String>) : IHologram {
class Hologram private constructor(var location: Location, val content: List<String>) : IHologram {

override val key = (location.toString().hashCode() + content.hashCode()).toString()
override val viewers = ConcurrentHashSet<Player>()
val viewers = ConcurrentHashSet<Player>()

constructor(location: Location, content: List<String>, vararg viewers: Player) : this(location, content) {
this.viewers.addAll(viewers)

private val lines = ConcurrentHashMap<Int, HologramLine>()

init {
content.forEachIndexed { index, line ->
lines[index] =
HologramLine(location.clone().add(0.0, (((content.size - 1) - index) * 0.3), 0.0), line, this.viewers)
}
}

constructor(location: Location, content: List<String>, viewers: Set<Player>) : this(location, content) {
constructor(location: Location, content: List<String>, vararg viewers: Player) : this(location, content) {
this.viewers.addAll(viewers)
content.forEachIndexed { index, line ->
lines[index] =
HologramLine(location.clone().add(0.0, (((content.size - 1) - index) * 0.3), 0.0), line, this.viewers)
}
}

private val lines = ConcurrentHashMap<Int, HologramLine>()
constructor(location: Location, content: List<String>, viewers: Set<Player>) : this(location, content) {
this.viewers.addAll(viewers)
}

override fun teleport(location: Location) {
this.location = location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import com.skillw.pouvoir.api.feature.hologram.IHologram
import com.skillw.pouvoir.api.manager.sub.HologramManager
import com.skillw.pouvoir.internal.feature.hologram.Hologram
import org.bukkit.Location
import org.bukkit.entity.Player

internal object HologramManagerImpl : HologramManager() {
override val key = "HologramManagerImpl"
override val priority = 3
override val subPouvoir = Pouvoir

override fun createHologram(location: Location, content: List<String>): IHologram {
return Hologram(location, content)
override fun createHologram(location: Location, content: List<String>, players: Set<Player>): IHologram {
return Hologram(location, content, players)
}
}

0 comments on commit b96cecc

Please sign in to comment.