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