项目作者: rqbik

项目描述 :
(Q/H)ologram API
高级语言: Java
项目地址: git://github.com/rqbik/QologramAPI.git
创建时间: 2020-09-19T16:12:38Z
项目社区:https://github.com/rqbik/QologramAPI

开源协议:

下载


QologramAPI

Modern hologram API written in Kotlin.

Usage:

  1. repositories {
  2. maven { setUrl("https://jitpack.io/") }
  3. }
  4. dependencies {
  5. implementation("com.github.rqbik", "QologramAPI", "1.0.8")
  6. }
  1. class MyPlugin : JavaPlugin(), Listener {
  2. override fun onEnable() {
  3. // Initialize QologramAPI
  4. QologramAPI.initialize(this)
  5. }
  6. companion object {
  7. fun createHologram(player: Player, location: Location) {
  8. // A simple one line hologram
  9. val hologram = Qologram(player, location, "Hello world!")
  10. // Show hologram
  11. hologram.show()
  12. // A more complex multiline hologram
  13. val multilineHologram = MultilineQologram(player, location) {
  14. // Let's add some lines!
  15. // Beware that they will be positioned from bottom to top.
  16. // We can add lines that have interact event handlers
  17. addLine("An interactive text!") { event ->
  18. if (event.type == InteractType.RIGHT_CLICK)
  19. event.player.sendMessage("You clicked on me!")
  20. // Hide this hologram after click
  21. event.hologram.hide()
  22. }
  23. // ...and we can add lines that don't!
  24. addLine("A simple text.")
  25. // We also can listen to events on any of lines:
  26. onInteract { event ->
  27. event.player.sendMessage("You clicked on hologram with text: ${event.line.text}")
  28. }
  29. }
  30. multilineHologram.show()
  31. // An even more complex _multipage_ hologram!
  32. val multipageHologram = MultipageQologram(player, location) {
  33. // The first page is automatically the one that is visible
  34. addPage {
  35. addLine("Click on me to go to the next page!") {
  36. // Increment `currentPage` to go to the next page.
  37. currentPage++
  38. }
  39. }
  40. addPage {
  41. addLine("Click on me to go to the previous page!") {
  42. // Decrement `currentPage` to go to the previous page.
  43. currentPage--
  44. }
  45. addLine("Go to the next page") {
  46. currentPage++
  47. }
  48. }
  49. addPage {
  50. addLine("Go back to first one") {
  51. // Set `currentPage` to 0 to go to the first page.
  52. currentPage = 0
  53. }
  54. addLine("I can't be interacted with.") {
  55. // This will never fire!
  56. }.apply {
  57. // Remove collision
  58. // This allows you to shoot projectiles through hologram,
  59. // but prevents you from interacting with it.
  60. hasCollision = false
  61. }
  62. }
  63. onInteract { event ->
  64. if (event.interactType == InteractType.LEFT_CLICK)
  65. event.player.sendMessage("Hey! Don't attack holograms. They have feelings too!")
  66. }
  67. }
  68. multipageHologram.show()
  69. }
  70. }
  71. }