Merge branch 'master' of github.com:bluefireoly/KSpigot into master
This commit is contained in:
@@ -13,37 +13,37 @@ class GamePhaseSystem(vararg gamePhases: GamePhase) {
|
|||||||
fun buildCounterMessageCallback(
|
fun buildCounterMessageCallback(
|
||||||
beforeTime: String? = null,
|
beforeTime: String? = null,
|
||||||
afterTime: String? = null,
|
afterTime: String? = null,
|
||||||
hours: String = "h",
|
hourPlural: String = "h",
|
||||||
minutes: String = "m",
|
minutePlural: String = "m",
|
||||||
seconds: String = "s"
|
secondPlural: String = "s",
|
||||||
|
hourSingular: String = hourPlural,
|
||||||
|
minuteSingular: String = minutePlural,
|
||||||
|
secondSingular: String = secondPlural
|
||||||
): (Long) -> String = { curSeconds ->
|
): (Long) -> String = { curSeconds ->
|
||||||
|
|
||||||
StringBuilder().apply {
|
StringBuilder().apply {
|
||||||
|
if (beforeTime != null)
|
||||||
append(beforeTime)
|
append(beforeTime)
|
||||||
|
|
||||||
val hourTime = (curSeconds / 3600)
|
val hourTime = (curSeconds / 3600)
|
||||||
val minuteTime = ((curSeconds % 3600) / 60)
|
val minuteTime = ((curSeconds % 3600) / 60)
|
||||||
val secondsTime = (curSeconds % 60)
|
val secondsTime = (curSeconds % 60)
|
||||||
|
|
||||||
if (hourTime != 0L)
|
if (hourTime != 0L) {
|
||||||
append("${hourTime.toString().run { if (length < 2) "0$this" else this }}:")
|
append("$hourTime ${if (hourTime == 1L) hourSingular else hourPlural}")
|
||||||
|
if (minuteTime != 0L) append(" ")
|
||||||
if ((hourTime != 0L && secondsTime != 0L) || (minuteTime != 0L && secondsTime != 0L))
|
|
||||||
append("${minuteTime.toString().run { if (length < 2) "0$this" else this }}:")
|
|
||||||
else if (minuteTime != 0L)
|
|
||||||
append(minuteTime.toString().run { if (length < 2) "0$this" else this })
|
|
||||||
|
|
||||||
if (secondsTime != 0L)
|
|
||||||
append(secondsTime.toString().run { if (length < 2) "0$this" else this })
|
|
||||||
|
|
||||||
append(" ").append(kotlin.run {
|
|
||||||
return@run when {
|
|
||||||
secondsTime != 0L -> seconds
|
|
||||||
minuteTime != 0L -> minutes
|
|
||||||
else -> hours
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
|
if (minuteTime != 0L) {
|
||||||
|
append("$minuteTime ${if (minuteTime == 1L) minuteSingular else minutePlural}")
|
||||||
|
if (secondsTime != 0L) append(" ")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (secondsTime != 0L || (hourTime == 0L && minuteTime == 0L)) {
|
||||||
|
append("$secondsTime ${if (secondsTime == 1L) secondSingular else secondPlural}")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (afterTime != null)
|
||||||
append(afterTime)
|
append(afterTime)
|
||||||
}.toString()
|
}.toString()
|
||||||
|
|
||||||
|
@@ -24,79 +24,3 @@ abstract class InventoryGUIElement<T : ForInventory>(
|
|||||||
protected abstract fun onClickElement(clickEvent: InventoryGUIClickEvent<T>)
|
protected abstract fun onClickElement(clickEvent: InventoryGUIClickEvent<T>)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Element implementations
|
|
||||||
|
|
||||||
open class InventoryGUIButton<T : ForInventory>(
|
|
||||||
inventoryGUIElementData: InventoryGUIElementData,
|
|
||||||
val action: (InventoryGUIClickEvent<T>) -> Unit,
|
|
||||||
) : InventoryGUIElement<T>(inventoryGUIElementData) {
|
|
||||||
|
|
||||||
override fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) {
|
|
||||||
clickEvent.bukkitEvent.isCancelled = true
|
|
||||||
action(clickEvent)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class InventoryGUIPlaceholder<T : ForInventory>(
|
|
||||||
inventoryGUIElementData: InventoryGUIElementData
|
|
||||||
) : InventoryGUIElement<T>(inventoryGUIElementData) {
|
|
||||||
|
|
||||||
override fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) {
|
|
||||||
clickEvent.bukkitEvent.isCancelled = true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class InventoryGUIButtonPageChange<T : ForInventory>(
|
|
||||||
inventoryGUIElementData: InventoryGUIElementData,
|
|
||||||
calculator: InventoryGUIPageChangeCalculator,
|
|
||||||
onChange: ((InventoryGUIClickEvent<T>) -> Unit)?
|
|
||||||
)
|
|
||||||
: InventoryGUIButton<T>(inventoryGUIElementData, {
|
|
||||||
|
|
||||||
val currentPage = it.gui.currentPage
|
|
||||||
val newPage = it.gui.getPage(calculator.calculateNewPage(it.gui.currentPageInt, it.gui.data.pages.keys))
|
|
||||||
if (newPage != null) {
|
|
||||||
|
|
||||||
val effect = (newPage.transitionTo ?: currentPage.transitionFrom)
|
|
||||||
?: PageChangeEffect.INSTANT
|
|
||||||
|
|
||||||
it.gui.changePage(effect, currentPage, newPage)
|
|
||||||
|
|
||||||
onChange?.invoke(it)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
class InventoryGUIButtonInventoryChange<T : ForInventory>(
|
|
||||||
inventoryGUIElementData: InventoryGUIElementData,
|
|
||||||
changeToGUICallback: () -> InventoryGUI<*>,
|
|
||||||
changeToPageInt: Int?,
|
|
||||||
onChange: ((InventoryGUIClickEvent<T>) -> Unit)?
|
|
||||||
)
|
|
||||||
: InventoryGUIButton<T>(inventoryGUIElementData, {
|
|
||||||
|
|
||||||
val changeToGUI = changeToGUICallback.invoke()
|
|
||||||
|
|
||||||
val effect = (changeToGUI.data.transitionTo ?: it.gui.data.transitionFrom)
|
|
||||||
?: InventoryChangeEffect.INSTANT
|
|
||||||
|
|
||||||
val changeToPage = changeToGUI.getPage(changeToPageInt) ?: changeToGUI.currentPage
|
|
||||||
|
|
||||||
changeToGUI.changeGUI(effect, it.gui.currentPage, changeToPage)
|
|
||||||
|
|
||||||
it.bukkitEvent.whoClicked.openGUI(changeToGUI)
|
|
||||||
|
|
||||||
onChange?.invoke(it)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
// FREE SLOT
|
|
||||||
|
|
||||||
class InventoryGUIFreeSlot<T : ForInventory> : InventoryGUISlot<T>() {
|
|
||||||
override fun onClick(clickEvent: InventoryGUIClickEvent<T>) { /* do nothing */ }
|
|
||||||
}
|
|
@@ -0,0 +1,18 @@
|
|||||||
|
package net.axay.kspigot.inventory.elements
|
||||||
|
|
||||||
|
import net.axay.kspigot.inventory.ForInventory
|
||||||
|
import net.axay.kspigot.inventory.InventoryGUIClickEvent
|
||||||
|
import net.axay.kspigot.inventory.InventoryGUIElement
|
||||||
|
import net.axay.kspigot.inventory.InventoryGUIElementData
|
||||||
|
|
||||||
|
open class InventoryGUIButton<T : ForInventory>(
|
||||||
|
inventoryGUIElementData: InventoryGUIElementData,
|
||||||
|
val action: (InventoryGUIClickEvent<T>) -> Unit,
|
||||||
|
) : InventoryGUIElement<T>(inventoryGUIElementData) {
|
||||||
|
|
||||||
|
override fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) {
|
||||||
|
clickEvent.bukkitEvent.isCancelled = true
|
||||||
|
action(clickEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,26 @@
|
|||||||
|
package net.axay.kspigot.inventory.elements
|
||||||
|
|
||||||
|
import net.axay.kspigot.inventory.*
|
||||||
|
|
||||||
|
class InventoryGUIButtonInventoryChange<T : ForInventory>(
|
||||||
|
inventoryGUIElementData: InventoryGUIElementData,
|
||||||
|
changeToGUICallback: () -> InventoryGUI<*>,
|
||||||
|
changeToPageInt: Int?,
|
||||||
|
onChange: ((InventoryGUIClickEvent<T>) -> Unit)?
|
||||||
|
)
|
||||||
|
: InventoryGUIButton<T>(inventoryGUIElementData, {
|
||||||
|
|
||||||
|
val changeToGUI = changeToGUICallback.invoke()
|
||||||
|
|
||||||
|
val effect = (changeToGUI.data.transitionTo ?: it.gui.data.transitionFrom)
|
||||||
|
?: InventoryChangeEffect.INSTANT
|
||||||
|
|
||||||
|
val changeToPage = changeToGUI.getPage(changeToPageInt) ?: changeToGUI.currentPage
|
||||||
|
|
||||||
|
changeToGUI.changeGUI(effect, it.gui.currentPage, changeToPage)
|
||||||
|
|
||||||
|
it.bukkitEvent.whoClicked.openGUI(changeToGUI)
|
||||||
|
|
||||||
|
onChange?.invoke(it)
|
||||||
|
|
||||||
|
})
|
@@ -0,0 +1,25 @@
|
|||||||
|
package net.axay.kspigot.inventory.elements
|
||||||
|
|
||||||
|
import net.axay.kspigot.inventory.*
|
||||||
|
|
||||||
|
class InventoryGUIButtonPageChange<T : ForInventory>(
|
||||||
|
inventoryGUIElementData: InventoryGUIElementData,
|
||||||
|
calculator: InventoryGUIPageChangeCalculator,
|
||||||
|
onChange: ((InventoryGUIClickEvent<T>) -> Unit)?
|
||||||
|
)
|
||||||
|
: InventoryGUIButton<T>(inventoryGUIElementData, {
|
||||||
|
|
||||||
|
val currentPage = it.gui.currentPage
|
||||||
|
val newPage = it.gui.getPage(calculator.calculateNewPage(it.gui.currentPageInt, it.gui.data.pages.keys))
|
||||||
|
if (newPage != null) {
|
||||||
|
|
||||||
|
val effect = (newPage.transitionTo ?: currentPage.transitionFrom)
|
||||||
|
?: PageChangeEffect.INSTANT
|
||||||
|
|
||||||
|
it.gui.changePage(effect, currentPage, newPage)
|
||||||
|
|
||||||
|
onChange?.invoke(it)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
@@ -0,0 +1,9 @@
|
|||||||
|
package net.axay.kspigot.inventory.elements
|
||||||
|
|
||||||
|
import net.axay.kspigot.inventory.ForInventory
|
||||||
|
import net.axay.kspigot.inventory.InventoryGUIClickEvent
|
||||||
|
import net.axay.kspigot.inventory.InventoryGUISlot
|
||||||
|
|
||||||
|
class InventoryGUIFreeSlot<T : ForInventory> : InventoryGUISlot<T>() {
|
||||||
|
override fun onClick(clickEvent: InventoryGUIClickEvent<T>) { /* do nothing */ }
|
||||||
|
}
|
@@ -0,0 +1,16 @@
|
|||||||
|
package net.axay.kspigot.inventory.elements
|
||||||
|
|
||||||
|
import net.axay.kspigot.inventory.ForInventory
|
||||||
|
import net.axay.kspigot.inventory.InventoryGUIClickEvent
|
||||||
|
import net.axay.kspigot.inventory.InventoryGUIElement
|
||||||
|
import net.axay.kspigot.inventory.InventoryGUIElementData
|
||||||
|
|
||||||
|
class InventoryGUIPlaceholder<T : ForInventory>(
|
||||||
|
inventoryGUIElementData: InventoryGUIElementData
|
||||||
|
) : InventoryGUIElement<T>(inventoryGUIElementData) {
|
||||||
|
|
||||||
|
override fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) {
|
||||||
|
clickEvent.bukkitEvent.isCancelled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user