Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
45f60aee9d
@ -1,6 +1,6 @@
|
|||||||
package com.ilummc.tlib.scala
|
package com.ilummc.tlib.scala
|
||||||
|
|
||||||
import com.ilummc.tlib.scala.Implicits._
|
import com.ilummc.tlib.scala.Prelude._
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.event.player.PlayerJoinEvent
|
import org.bukkit.event.player.PlayerJoinEvent
|
||||||
import org.bukkit.event.{EventHandler, Listener}
|
import org.bukkit.event.{EventHandler, Listener}
|
||||||
|
@ -5,7 +5,7 @@ import org.bukkit.entity.Player
|
|||||||
import org.bukkit.util.Vector
|
import org.bukkit.util.Vector
|
||||||
import org.bukkit.{Location, OfflinePlayer, World, util}
|
import org.bukkit.{Location, OfflinePlayer, World, util}
|
||||||
|
|
||||||
object Implicits {
|
abstract class Implicits {
|
||||||
|
|
||||||
implicit def player2rich(player: Player): RichPlayer = player
|
implicit def player2rich(player: Player): RichPlayer = player
|
||||||
|
|
||||||
|
47
src/main/scala/com/ilummc/tlib/scala/Prelude.scala
Normal file
47
src/main/scala/com/ilummc/tlib/scala/Prelude.scala
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package com.ilummc.tlib.scala
|
||||||
|
|
||||||
|
import com.ilummc.tlib.resources.TLocale.Logger
|
||||||
|
import org.bukkit.Bukkit
|
||||||
|
import org.bukkit.event.{Event, EventException, EventPriority, Listener}
|
||||||
|
import org.bukkit.plugin.{EventExecutor, Plugin}
|
||||||
|
|
||||||
|
object Prelude extends Implicits {
|
||||||
|
|
||||||
|
def listen[T <: Event](clazz: Class[T],
|
||||||
|
ignoreCancelled: Boolean = true,
|
||||||
|
priority: EventPriority = EventPriority.NORMAL)
|
||||||
|
(handler: T => Unit)
|
||||||
|
(implicit plugin: Plugin): Unit = {
|
||||||
|
val listener = new SingleListener(handler)
|
||||||
|
Bukkit.getPluginManager.registerEvent(clazz, listener, priority, listener, plugin, ignoreCancelled)
|
||||||
|
}
|
||||||
|
|
||||||
|
def runTask(task: => Unit)(implicit plugin: Plugin): Unit = Task(task)
|
||||||
|
|
||||||
|
def runTask(delay: Long)(task: => Unit)(implicit plugin: Plugin): Unit = Task(delay)(task)
|
||||||
|
|
||||||
|
def runTask(init: Long, period: Long)(task: => Unit)(implicit plugin: Plugin): Unit = Task(init, period)(task)
|
||||||
|
|
||||||
|
def runTaskAsync(task: => Unit)(implicit plugin: Plugin): Unit = AsyncTask(task)
|
||||||
|
|
||||||
|
def runTaskAsync(delay: Long)(task: => Unit)(implicit plugin: Plugin): Unit = AsyncTask(delay)(task)
|
||||||
|
|
||||||
|
def runTaskAsync(init: Long, period: Long)(task: => Unit)(implicit plugin: Plugin): Unit = AsyncTask(init, period)(task)
|
||||||
|
|
||||||
|
def info(node: String, params: String*): Unit = Logger.info(node, params: _*)
|
||||||
|
|
||||||
|
def error(node: String, params: String*): Unit = Logger.error(node, params: _*)
|
||||||
|
|
||||||
|
def fine(node: String, params: String*): Unit = Logger.fine(node, params: _*)
|
||||||
|
|
||||||
|
def debug(node: String, params: String*): Unit = Logger.verbose(node, params: _*)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private[this] class SingleListener[T <: Event](handler: T => Any) extends Listener with EventExecutor {
|
||||||
|
override def execute(listener: Listener, event: Event): Unit = {
|
||||||
|
try handler(event.asInstanceOf[T]) catch {
|
||||||
|
case e: Throwable => throw new EventException(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -54,8 +54,8 @@ class RichPlayer(private val player: Player) extends RichOfflinePlayer(player) {
|
|||||||
|
|
||||||
def locale(node: String, params: String*): Unit = sendLocalizedMessage(node, params: _*)
|
def locale(node: String, params: String*): Unit = sendLocalizedMessage(node, params: _*)
|
||||||
|
|
||||||
def <<(node: String): RichPlayer = {
|
def <<(text: String): RichPlayer = {
|
||||||
TLocale.sendTo(player, node)
|
player.sendMessage(text)
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user