Skip to content

Commit

Permalink
Update Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Arasple committed Feb 12, 2021
1 parent be4628f commit 2ca292b
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 126 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'me.arasple.mc.trhologram'
version '2.0-BETA1'
version '2.0-BETA2'

task buildJar(dependsOn: [clean, shadowJar])

Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/me/arasple/mc/trhologram/api/base/TickEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.arasple.mc.trhologram.api.base

import me.arasple.mc.trhologram.api.hologram.HologramComponent

/**
* @author Arasple
* @date 2021/2/12 20:38
*/
fun interface TickEvent {

fun run(hologramComponent: HologramComponent)

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import me.arasple.mc.trhologram.api.Position
import me.arasple.mc.trhologram.api.base.BaseCondition
import me.arasple.mc.trhologram.api.base.ClickHandler
import me.arasple.mc.trhologram.api.base.ItemTexture
import me.arasple.mc.trhologram.api.base.TickEvent
import me.arasple.mc.trhologram.module.display.Hologram
import org.bukkit.Location
import java.util.*
Expand Down Expand Up @@ -43,7 +44,7 @@ class HologramBuilder(
text: String,
update: Long = -1,
offset: Double = this.offset,
onTick: (HologramComponent) -> Unit = {}
onTick: TickEvent? = null
): HologramBuilder {
interspace(offset)
components.add(TextHologram(text, position, update, onTick))
Expand All @@ -58,7 +59,7 @@ class HologramBuilder(
texture: ItemTexture,
update: Long = -1,
offset: Double = this.offset,
onTick: (HologramComponent) -> Unit = {}
onTick: TickEvent? = null
): HologramBuilder {
interspace(0.5 + offset)
components.add(ItemHologram(texture, position, update, onTick))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.arasple.mc.trhologram.api.hologram
import io.izzel.taboolib.kotlin.Tasks
import me.arasple.mc.trhologram.api.Position
import me.arasple.mc.trhologram.api.TrHologramAPI
import me.arasple.mc.trhologram.api.base.TickEvent
import me.arasple.mc.trhologram.api.nms.packet.PacketEntityDestroy
import me.arasple.mc.trhologram.util.Tasks.shut
import org.bukkit.Bukkit
Expand All @@ -17,7 +18,7 @@ import kotlin.properties.Delegates
abstract class HologramComponent(
val position: Position,
tick: Long = -1,
val onTick: (HologramComponent) -> Unit = {}
val onTick: TickEvent?
) {

abstract fun spawn(player: Player)
Expand Down Expand Up @@ -46,7 +47,7 @@ abstract class HologramComponent(
player == null || !player.isOnline
}
onTick()
onTick(this)
onTick?.run(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.arasple.mc.trhologram.api.hologram
import me.arasple.mc.trhologram.api.Position
import me.arasple.mc.trhologram.api.TrHologramAPI
import me.arasple.mc.trhologram.api.base.ItemTexture
import me.arasple.mc.trhologram.api.base.TickEvent
import me.arasple.mc.trhologram.api.nms.packet.*
import me.arasple.mc.trhologram.module.display.texture.Texture
import me.arasple.mc.trhologram.module.service.Performance
Expand All @@ -20,7 +21,7 @@ class ItemHologram(
texture: ItemTexture,
position: Position,
tick: Long = -1,
onTick: (HologramComponent) -> Unit = {}
onTick: TickEvent? = null
) : HologramComponent(position.clone(y = 1.3), tick, onTick) {

constructor(
Expand Down Expand Up @@ -58,7 +59,7 @@ class ItemHologram(

Tasks.delay {
PacketEntityMount(teid, IntArray(1) { entityId }).send(player)
Tasks.delay { PacketEntityDestroy(teid).send(player) }
Tasks.delay(5) { PacketEntityDestroy(teid).send(player) }
}

viewers.add(player.name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.arasple.mc.trhologram.api.hologram

import me.arasple.mc.trhologram.api.Position
import me.arasple.mc.trhologram.api.base.TickEvent
import me.arasple.mc.trhologram.api.nms.packet.PacketArmorStandModify
import me.arasple.mc.trhologram.api.nms.packet.PacketArmorStandName
import me.arasple.mc.trhologram.api.nms.packet.PacketEntitySpawn
Expand All @@ -18,7 +19,7 @@ class TextHologram(
name: String,
position: Position,
tick: Long,
onTick: (HologramComponent) -> Unit = {}
onTick: TickEvent? = null
) : HologramComponent(position, tick, onTick) {

var text: String = name
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/me/arasple/mc/trhologram/api/nms/NMS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.arasple.mc.trhologram.api.nms

import com.mojang.authlib.GameProfile
import io.izzel.taboolib.kotlin.Reflex
import io.izzel.taboolib.module.inject.TInject
import io.izzel.taboolib.module.packet.TPacketHandler
import io.izzel.taboolib.util.asm.AsmVersionControl
import me.arasple.mc.trhologram.TrHologram
Expand All @@ -20,9 +21,8 @@ abstract class NMS {
/**
* @see NMSImpl
*/
val INSTANCE: NMS =
AsmVersionControl.createNMS("me.arasple.mc.trhologram.api.nms.NMSImpl").translate(TrHologram.plugin)
.newInstance() as NMS
@TInject(asm = "me.arasple.mc.trhologram.api.nms.NMSImpl")
lateinit var INSTANCE: NMS

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,16 @@ class CommandHandler : BaseMainCommand() {
)
val create: BaseSubCommand = CommandCreate()


@SubCommand(
permission = "trhologram.command.delete",
description = "Delete an existed hologram",
type = CommandType.PLAYER
)
@SubCommand(description = "Delete an existed hologram", type = CommandType.PLAYER)
val delete: BaseSubCommand = CommandDelete()

@SubCommand(
permission = "trhologram.command.list",
description = "List loaded holograms"
)
@SubCommand(permission = "trhologram.command.list", description = "List loaded holograms")
val list: BaseSubCommand = CommandList()

@SubCommand(permission = "trhologram.command.movehere", description = "Teleport hologram to your location")
val movehere: BaseSubCommand = CommandMovehere()

@SubCommand(
permission = "trhologram.command.reload",
description = "Reload holograms"
)
@SubCommand(permission = "trhologram.command.reload", description = "Reload holograms")
val reload: BaseSubCommand = CommandReload()

@SubCommand(permission = "trhologram.command.mirror", description = "Monitor performance")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CommandCreate : BaseSubCommand() {
return
}

HologramLoader.create(args[0], player.location.clone().add(0.0, 4.0, 0.0)).refreshVisibility(player)
HologramLoader.create(args[0], player.location.clone().add(0.0, 2.0, 0.0)).refreshVisibility(player)
TLocale.sendTo(sender, "Command.Created")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.izzel.taboolib.module.locale.TLocale
import me.arasple.mc.trhologram.module.display.Hologram
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import java.io.File

/**
* @author Arasple
Expand All @@ -22,12 +22,12 @@ class CommandDelete : BaseSubCommand() {

override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<String>) {
val hologram = Hologram.findHologram { it.id.equals(args[0], true) }
val player = sender as Player

if (hologram == null) {
TLocale.sendTo(sender, "Command.Not-Exists", args[0])
return
}
hologram.loadedPath?.let { File(it).delete() }
hologram.destroy()
Hologram.holograms.remove(hologram)
TLocale.sendTo(sender, "Command.Deleted", args[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import io.izzel.taboolib.module.command.base.BaseSubCommand
import io.izzel.taboolib.module.locale.TLocale
import me.arasple.mc.trhologram.module.display.Hologram
import me.arasple.mc.trhologram.module.editor.Editor
import me.arasple.mc.trhologram.util.Parser
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

/**
* @author Arasple
* @date 2021/2/12 17:41
* @date 2021/2/12 20:45
*/
class CommandEdit : BaseSubCommand() {
class CommandMovehere : BaseSubCommand() {

override fun getArguments() = arrayOf(
Argument("Id", true) {
Expand All @@ -26,11 +27,13 @@ class CommandEdit : BaseSubCommand() {
val player = sender as Player

if (hologram == null) {
TLocale.sendTo(sender, "Command.Existed")
TLocale.sendTo(sender, "Command.Not-Exists", args[0])
return
}

Editor.contentEditor(player, hologram)
Editor.modify(hologram) {
it["Location"] = Parser.fromLocation(player.location)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import kotlin.system.measureNanoTime
*/
object HologramLoader {

private val folder = Files.file(TrHologram.plugin.dataFolder, "holograms")
private val folder = Files.folder(TrHologram.plugin.dataFolder, "holograms")

fun create(id: String, location: Location): Hologram {
val hologram =
Expand All @@ -39,11 +39,11 @@ object HologramLoader {
Contents:
- '&7Hello, &2Tr&aHologram&7!'
- '{item: emerald}'
- ''
- '&3Nice to meet you, &a{{player name}}'
- '&3Author: &aArasple{offset=0.35}'
Actions:
All: 'tell color *&bHi, you just clicked this hologram'
All: 'tell color *"&bHi, you just clicked this hologram"'
""".trimIndent()

Files.file(folder, "$id.yml").also {
Expand Down
Loading

0 comments on commit 2ca292b

Please sign in to comment.