forked from SuperRicky14/TpaPlusPlus
-
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.
- Loading branch information
1 parent
e721513
commit 9ac689d
Showing
13 changed files
with
162 additions
and
125 deletions.
There are no files selected for viewing
43 changes: 3 additions & 40 deletions
43
src/main/kotlin/net/superricky/tpaplusplus/async/AsyncCommand.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 |
---|---|---|
@@ -1,57 +1,20 @@ | ||
package net.superricky.tpaplusplus.async | ||
|
||
import net.superricky.tpaplusplus.utility.LevelBoundVec3 | ||
import net.superricky.tpaplusplus.utility.getDimension | ||
|
||
/** | ||
* Abstract class for asyncCommand | ||
*/ | ||
abstract class AsyncCommand { | ||
@JvmField | ||
protected var commandName: String = "" | ||
|
||
/** | ||
* This function is used to check if the player's movement | ||
* distance is within the limit when the command is executed | ||
*/ | ||
abstract fun checkWindupDistance(asyncCommandData: AsyncCommandData): Boolean | ||
|
||
abstract fun getCooldownTime(): Double | ||
|
||
abstract fun getDelayTime(): Double | ||
|
||
/** | ||
* Command names cannot be hot loaded | ||
*/ | ||
fun getCommandName(): String = commandName | ||
|
||
protected fun checkWindupDistance( | ||
asyncCommandData: AsyncCommandData, | ||
checkFunction: Function1<AsyncCommandData, Double>, | ||
minDistance: Double | ||
): Boolean { | ||
if (minDistance < 0) { | ||
return true | ||
} | ||
val distance = checkFunction.invoke(asyncCommandData) | ||
if (distance == -1.0) { | ||
return false | ||
} | ||
return distance <= minDistance | ||
} | ||
abstract fun getCooldownTime(): Double | ||
|
||
protected fun getSenderDistance(asyncCommandData: AsyncCommandData): Double { | ||
val originPos = asyncCommandData.getPos() | ||
val sender = asyncCommandData.getRequest().sender | ||
val nowPos = LevelBoundVec3(sender.getDimension(), sender.pos) | ||
return originPos.distance(nowPos) | ||
} | ||
abstract fun getDelayTime(): Double | ||
|
||
protected fun getReceiverDistance(asyncCommandData: AsyncCommandData): Double { | ||
val originPos = asyncCommandData.getPos() | ||
val receiver = asyncCommandData.getRequest().receiver | ||
require(receiver != null) { "Receiver not found" } | ||
val nowPos = LevelBoundVec3(receiver.getDimension(), receiver.pos) | ||
return originPos.distance(nowPos) | ||
} | ||
abstract fun getMinDistance(): Double | ||
} |
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
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
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
Oops, something went wrong.