From e1d3c769903d44930d427c1af17d5f909488d001 Mon Sep 17 00:00:00 2001 From: Izzel_Aliz Date: Tue, 2 Oct 2018 11:17:12 +0800 Subject: [PATCH] scala api change --- src/main/scala/com/ilummc/tlib/scala/AsyncTask.scala | 6 +++--- src/main/scala/com/ilummc/tlib/scala/Example.scala | 12 +++++++++++- .../com/ilummc/tlib/scala/ScalaTaskExecutor.scala | 4 ++-- src/main/scala/com/ilummc/tlib/scala/Task.scala | 6 +++--- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/scala/com/ilummc/tlib/scala/AsyncTask.scala b/src/main/scala/com/ilummc/tlib/scala/AsyncTask.scala index 8dca649..c5706ed 100644 --- a/src/main/scala/com/ilummc/tlib/scala/AsyncTask.scala +++ b/src/main/scala/com/ilummc/tlib/scala/AsyncTask.scala @@ -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 } diff --git a/src/main/scala/com/ilummc/tlib/scala/Example.scala b/src/main/scala/com/ilummc/tlib/scala/Example.scala index 5c40747..83d181a 100644 --- a/src/main/scala/com/ilummc/tlib/scala/Example.scala +++ b/src/main/scala/com/ilummc/tlib/scala/Example.scala @@ -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])) } } diff --git a/src/main/scala/com/ilummc/tlib/scala/ScalaTaskExecutor.scala b/src/main/scala/com/ilummc/tlib/scala/ScalaTaskExecutor.scala index 35fe59a..06a88f3 100644 --- a/src/main/scala/com/ilummc/tlib/scala/ScalaTaskExecutor.scala +++ b/src/main/scala/com/ilummc/tlib/scala/ScalaTaskExecutor.scala @@ -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 { diff --git a/src/main/scala/com/ilummc/tlib/scala/Task.scala b/src/main/scala/com/ilummc/tlib/scala/Task.scala index 6c8245c..0c889fe 100644 --- a/src/main/scala/com/ilummc/tlib/scala/Task.scala +++ b/src/main/scala/com/ilummc/tlib/scala/Task.scala @@ -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 }