-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add SuperItemEvent.kt ✨ Add Feature ScheduleTask.kt
- Loading branch information
Showing
10 changed files
with
128 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/cf/wayzer/SuperItem/events/SuperItemEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cf.wayzer.SuperItem.events | ||
|
||
import cf.wayzer.SuperItem.Main | ||
import org.bukkit.event.Cancellable | ||
import org.bukkit.event.Event | ||
import org.bukkit.event.HandlerList | ||
|
||
/** | ||
* Use for script custom event | ||
*/ | ||
data class SuperItemEvent(val type:String,private var data:Any) : Event(), Cancellable { | ||
init { | ||
try { | ||
Class.forName(data::class.java.name,false,Main::class.java.classLoader) | ||
}catch (e: Exception){ | ||
throw Error("Can only use common Type as data",e) | ||
} | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
operator fun <T> invoke(): T { | ||
return data as T | ||
} | ||
private var isCancelled = false | ||
override fun getHandlers(): HandlerList { | ||
return handlerList | ||
} | ||
|
||
override fun setCancelled(cancel: Boolean) { | ||
isCancelled = cancel | ||
} | ||
|
||
override fun isCancelled(): Boolean { | ||
return isCancelled | ||
} | ||
companion object{ | ||
val handlerList = HandlerList() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/cf/wayzer/SuperItem/features/ScheduleTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cf.wayzer.SuperItem.features | ||
|
||
import cf.wayzer.SuperItem.Feature | ||
import cf.wayzer.SuperItem.Main | ||
import org.bukkit.scheduler.BukkitRunnable | ||
|
||
class ScheduleTask : Feature<Nothing>(),Feature.OnDisable { | ||
private val list = mutableListOf<BukkitRunnable>() | ||
override val defaultData: Nothing? = null | ||
override fun onDisable(main: Main) { | ||
list.forEach { it.cancel() } | ||
} | ||
fun create(autoCancel:Boolean =true,runH: BukkitRunnable.()->Unit):BukkitRunnable{ | ||
val runnable = object: BukkitRunnable(){ | ||
override fun run(){ | ||
cancel() | ||
runH(this) | ||
if(autoCancel&&isCancelled) | ||
list.remove(this) | ||
} | ||
} | ||
if(autoCancel)list.add(runnable) | ||
return runnable | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters