scala api change
This commit is contained in:
parent
d04adbe647
commit
e1d3c76990
@ -4,15 +4,15 @@ import org.bukkit.plugin.Plugin
|
||||
|
||||
object AsyncTask {
|
||||
|
||||
def apply(task: => Unit)(implicit plugin: Plugin): Int = {
|
||||
def apply(task: => Any)(implicit plugin: Plugin): Int = {
|
||||
ScalaTaskExecutor(task).runTaskAsynchronously(plugin).getTaskId
|
||||
}
|
||||
|
||||
def apply(delay: Long)(task: => Unit)(implicit plugin: Plugin): Int = {
|
||||
def apply(delay: Long)(task: => Any)(implicit plugin: Plugin): Int = {
|
||||
ScalaTaskExecutor(task).runTaskLaterAsynchronously(plugin, delay).getTaskId
|
||||
}
|
||||
|
||||
def apply(init: Long, period: Long)(task: => Unit)(implicit plugin: Plugin): Int = {
|
||||
def apply(init: Long, period: Long)(task: => Any)(implicit plugin: Plugin): Int = {
|
||||
ScalaTaskExecutor(task).runTaskTimerAsynchronously(plugin, init, period).getTaskId
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,9 @@ import org.bukkit.event.{EventHandler, Listener}
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
|
||||
object Example extends JavaPlugin with Listener {
|
||||
class Example extends JavaPlugin with Listener {
|
||||
|
||||
implicit lazy val plugin: Example = this
|
||||
|
||||
@EventHandler
|
||||
def onJoin(event: PlayerJoinEvent): Unit = {
|
||||
@ -23,6 +25,14 @@ object Example extends JavaPlugin with Listener {
|
||||
event.getPlayer.openAnvil()
|
||||
event.getPlayer << "locale.node" << "node.2"
|
||||
event.getPlayer.teleport(event.getPlayer.getLocation + (1, 2, 3))
|
||||
Task {
|
||||
event.getPlayer << "test"
|
||||
}
|
||||
AsyncTask(20) {
|
||||
event.getPlayer << "later"
|
||||
}
|
||||
class a
|
||||
assert(this == JavaPlugin.getProvidingPlugin(classOf[a]))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package com.ilummc.tlib.scala
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable
|
||||
|
||||
private[scala] class ScalaTaskExecutor(task: => Unit) extends BukkitRunnable {
|
||||
private[scala] class ScalaTaskExecutor(task: => Any) extends BukkitRunnable {
|
||||
|
||||
override def run(): Unit = {
|
||||
try task catch {
|
||||
@ -14,7 +14,7 @@ private[scala] class ScalaTaskExecutor(task: => Unit) extends BukkitRunnable {
|
||||
}
|
||||
|
||||
object ScalaTaskExecutor {
|
||||
def apply(task: => Unit): ScalaTaskExecutor = new ScalaTaskExecutor(task)
|
||||
def apply(task: => Any): ScalaTaskExecutor = new ScalaTaskExecutor(task)
|
||||
}
|
||||
|
||||
class CancelException extends RuntimeException {
|
||||
|
@ -4,15 +4,15 @@ import org.bukkit.plugin.Plugin
|
||||
|
||||
object Task {
|
||||
|
||||
def apply(task: => Unit)(implicit plugin: Plugin): Int = {
|
||||
def apply(task: => Any)(implicit plugin: Plugin): Int = {
|
||||
ScalaTaskExecutor(task).runTask(plugin).getTaskId
|
||||
}
|
||||
|
||||
def apply(delay: Long)(task: => Unit)(implicit plugin: Plugin): Int = {
|
||||
def apply(delay: Long)(task: => Any)(implicit plugin: Plugin): Int = {
|
||||
ScalaTaskExecutor(task).runTaskLater(plugin, delay).getTaskId
|
||||
}
|
||||
|
||||
def apply(init: Long, period: Long)(task: => Unit)(implicit plugin: Plugin): Int = {
|
||||
def apply(init: Long, period: Long)(task: => Any)(implicit plugin: Plugin): Int = {
|
||||
ScalaTaskExecutor(task).runTaskTimer(plugin, init, period).getTaskId
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user