-
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
Showing
8 changed files
with
277 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
|
||
- get_available_api | ||
- get_player_list | ||
- get_player_info | ||
|
||
### Events | ||
|
||
|
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
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/fyi/fyw/mc/pluginnonebot/api/internal/HandlerGetPlayerInfo.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,29 @@ | ||
package fyi.fyw.mc.pluginnonebot.api.internal | ||
|
||
import fyi.fyw.mc.pluginnonebot.api.ApiHandler | ||
import fyi.fyw.mc.pluginnonebot.models.NPlayer | ||
import fyi.fyw.mc.pluginnonebot.models.api.BaseApiResult | ||
import fyi.fyw.mc.pluginnonebot.models.api.ResultGetPlayerInfo | ||
import org.bukkit.Bukkit | ||
import java.util.* | ||
|
||
class HandlerGetPlayerInfo : ApiHandler { | ||
override val id: String = "get_player_info" | ||
private val uuidPattern: Regex = Regex("^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$") | ||
override fun handle(params: Map<String, Any>): BaseApiResult { | ||
val playerId = params.getOrDefault("player_id", "") as String | ||
return if (uuidPattern.matches(playerId)) { | ||
ResultGetPlayerInfo( | ||
NPlayer.from( | ||
Bukkit.getPlayer(UUID.fromString(playerId)) ?: throw Exception("Player not found online"), | ||
), | ||
) | ||
} else { | ||
ResultGetPlayerInfo( | ||
NPlayer.from( | ||
Bukkit.getPlayer(playerId) ?: throw Exception("Player not found online"), | ||
), | ||
) | ||
} | ||
} | ||
} |
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,3 +1,74 @@ | ||
package fyi.fyw.mc.pluginnonebot.models | ||
|
||
class NEntity | ||
import com.google.gson.annotations.SerializedName | ||
import org.bukkit.entity.Entity | ||
import org.bukkit.util.Vector | ||
|
||
open class NEntity( | ||
val velocity: NVelocity, | ||
val location: NLocation, | ||
val height: Double, | ||
val width: Double, | ||
@SerializedName("on_ground") val onGround: Boolean, | ||
@SerializedName("in_water") val inWater: Boolean, | ||
@SerializedName("entity_id") val entityId: Int, | ||
@SerializedName("fire_ticks") val fireTicks: Int, | ||
@SerializedName("max_fire_ticks") val maxFireTicks: Int, | ||
|
||
val vehicle: NEntity?, | ||
val passengers: List<NEntity>?, | ||
val empty: Boolean, | ||
@SerializedName("inside_vehicle") val insideVehicle: Boolean, | ||
|
||
@SerializedName("ticks_lived") val ticksLived: Int, | ||
@SerializedName("entity_type") val entityType: String, | ||
|
||
@SerializedName("custom_name_visible") val customNameVisible: Boolean, | ||
@SerializedName("custom_name") val customName: String?, | ||
|
||
val invulnerable: Boolean, | ||
@SerializedName("scoreboard_tags") val scoreboardTags: Set<String>, | ||
) { | ||
|
||
companion object { | ||
fun from(entity: Entity): NEntity { | ||
return NEntity( | ||
NVelocity.from(entity.velocity), | ||
NLocation.from(entity.location), | ||
entity.height, | ||
entity.width, | ||
entity.isOnGround, | ||
entity.isInWater, | ||
entity.entityId, | ||
entity.fireTicks, | ||
entity.maxFireTicks, | ||
entity.vehicle?.let { NEntity.from(it) }, | ||
entity.passengers.map { NEntity.from(it) }, | ||
entity.isEmpty, | ||
entity.isInsideVehicle, | ||
entity.ticksLived, | ||
entity.type.name, | ||
entity.isCustomNameVisible, | ||
entity.customName, | ||
entity.isInvulnerable, | ||
entity.scoreboardTags, | ||
) | ||
} | ||
} | ||
|
||
class NVelocity( | ||
val x: Double, | ||
val y: Double, | ||
val z: Double, | ||
) { | ||
companion object { | ||
fun from(velocity: Vector): NVelocity { | ||
return NVelocity( | ||
velocity.x, | ||
velocity.y, | ||
velocity.z, | ||
) | ||
} | ||
} | ||
} | ||
} |
162 changes: 162 additions & 0 deletions
162
src/main/kotlin/fyi/fyw/mc/pluginnonebot/models/NPlayer.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,162 @@ | ||
package fyi.fyw.mc.pluginnonebot.models | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.bukkit.OfflinePlayer | ||
import org.bukkit.entity.Player | ||
|
||
class NPlayer( | ||
@SerializedName("display_name") val displayName: String, | ||
@SerializedName("player_list_name") val playerListName: String, | ||
@SerializedName("player_list_header") val playerListHeader: String, | ||
@SerializedName("player_list_footer") val playerListFooter: String, | ||
|
||
val address: String, | ||
val ping: Int, | ||
val locale: String, | ||
|
||
val sneaking: Boolean, | ||
val sprinting: Boolean, | ||
val flying: Boolean, | ||
|
||
@SerializedName("bed_spawn_location") val bedSpawnLocation: NLocation?, | ||
|
||
val exp: Float, | ||
val level: Int, | ||
@SerializedName("total_experience") val totalExperience: Int, | ||
|
||
velocity: NVelocity, | ||
location: NLocation, | ||
height: Double, | ||
width: Double, | ||
onGround: Boolean, | ||
inWater: Boolean, | ||
entityId: Int, | ||
fireTicks: Int, | ||
maxFireTicks: Int, | ||
|
||
vehicle: NEntity?, | ||
passengers: List<NEntity>?, | ||
empty: Boolean, | ||
insideVehicle: Boolean, | ||
|
||
ticksLived: Int, | ||
entityType: String, | ||
|
||
customNameVisible: Boolean, | ||
customName: String?, | ||
|
||
invulnerable: Boolean, | ||
scoreboardTags: Set<String>, | ||
) : NEntity( | ||
velocity, | ||
location, | ||
height, | ||
width, | ||
onGround, | ||
inWater, | ||
entityId, | ||
fireTicks, | ||
maxFireTicks, | ||
|
||
vehicle, | ||
passengers, | ||
empty, | ||
insideVehicle, | ||
|
||
ticksLived, | ||
entityType, | ||
|
||
customNameVisible, | ||
customName, | ||
|
||
invulnerable, | ||
scoreboardTags, | ||
) { | ||
companion object { | ||
fun from(player: OfflinePlayer): NPlayer { | ||
return when (player) { | ||
is Player -> NPlayer( | ||
player.displayName, | ||
player.playerListName, | ||
player.playerListHeader ?: "", | ||
player.playerListFooter ?: "", | ||
|
||
player.address.toString(), | ||
player.ping, | ||
player.locale, | ||
|
||
player.isSneaking, | ||
player.isSprinting, | ||
player.isFlying, | ||
|
||
player.bedSpawnLocation?.let { NLocation.from(it) }, | ||
|
||
player.exp, | ||
player.level, | ||
player.totalExperience, | ||
|
||
NVelocity.from(player.velocity), | ||
NLocation.from(player.location), | ||
player.height, | ||
player.width, | ||
player.isOnGround, | ||
player.isInWater, | ||
player.entityId, | ||
player.fireTicks, | ||
player.maxFireTicks, | ||
player.vehicle?.let { NEntity.from(it) }, | ||
player.passengers.map { NEntity.from(it) }, | ||
player.isEmpty, | ||
player.isInsideVehicle, | ||
player.ticksLived, | ||
player.type.name, | ||
player.isCustomNameVisible, | ||
player.customName, | ||
player.isInvulnerable, | ||
player.scoreboardTags, | ||
) | ||
|
||
else -> NPlayer( | ||
player.name ?: "", | ||
player.name ?: "", | ||
"", | ||
"", | ||
|
||
"", | ||
0, | ||
"", | ||
|
||
false, | ||
false, | ||
false, | ||
|
||
null, | ||
|
||
0f, | ||
0, | ||
0, | ||
|
||
NVelocity(0.0, 0.0, 0.0), | ||
NLocation("Unknown World", 0.0, 0.0, 0.0, 0.0f, 0.0f), | ||
0.0, | ||
0.0, | ||
false, | ||
false, | ||
0, | ||
0, | ||
0, | ||
null, | ||
null, | ||
true, | ||
false, | ||
0, | ||
"", | ||
false, | ||
null, | ||
false, | ||
emptySet(), | ||
) | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/fyi/fyw/mc/pluginnonebot/models/api/ResultGetPlayerInfo.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,7 @@ | ||
package fyi.fyw.mc.pluginnonebot.models.api | ||
|
||
import fyi.fyw.mc.pluginnonebot.models.NPlayer | ||
|
||
class ResultGetPlayerInfo( | ||
val player: NPlayer, | ||
) : BaseApiResult |
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