Skip to content

Commit

Permalink
#6 Support targeting a player as part of /log-event command
Browse files Browse the repository at this point in the history
4Ply committed Dec 30, 2023

Verified

This commit was signed with the committer’s verified signature.
4Ply Pawel
1 parent b35cce0 commit 6506568
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions src/main/kotlin/org/trackedout/citadel/commands/LogEventCommand.kt
Original file line number Diff line number Diff line change
@@ -2,12 +2,17 @@ package org.trackedout.citadel.commands

import co.aikar.commands.BaseCommand
import co.aikar.commands.annotation.*
import co.aikar.commands.bukkit.contexts.OnlinePlayer
import org.bukkit.command.BlockCommandSender
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.trackedout.citadel.Citadel
import org.trackedout.citadel.async
import org.trackedout.citadel.sendGreyMessage
import org.trackedout.client.apis.EventsApi
import org.trackedout.client.models.EventsPostRequest
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

@CommandAlias("log-event")
class LogEventCommand(
@@ -18,23 +23,49 @@ class LogEventCommand(


@Default
@Syntax("[event] [count]")
@Syntax("[event] [count] [player]")
@CommandPermission("decked-out.log-event")
@Description("Add Decked Out 2 card into player's DB inventory")
fun logEvent(sender: CommandSender, eventName: String, @Default("1") count: Int) {
fun logEvent(sender: CommandSender, eventName: String, @Default("1") count: Int, @Optional target: OnlinePlayer?) {
var player = target?.player
if (player == null && sender is OnlinePlayer) {
player = sender.player
}
if (player == null && sender is Player) {
player = sender
}
var x = player?.x ?: 0.0
var y = player?.y ?: 0.0
var z = player?.z ?: 0.0
var world = player?.world

if (player == null && sender is BlockCommandSender) {
x = sender.block.x.toDouble()
y = sender.block.y.toDouble()
z = sender.block.z.toDouble()
world = sender.block.world
}

plugin.async(sender) {
val playerName = player?.name ?: sender.name
eventsApi.eventsPost(
EventsPostRequest(
name = eventName,
server = plugin.serverName,
player = sender.name,
player = playerName,
// worldAge = world?.gameTime,
count = count,
x = 0.0,
y = 0.0,
z = 0.0,
x = x,
y = y,
z = z,
)
)
sender.sendGreyMessage("Sent $eventName (count = $count) to Dunga Dunga")

val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS")
val current = LocalDateTime.now().format(formatter)
val message = "[${current}/${world?.gameTime}] Sent { event=$eventName, count=$count, player=$playerName, location=[$x, $y, $z] } to Dunga Dunga"
plugin.logger.info(message)
sender.sendGreyMessage(message)
}
}
}

0 comments on commit 6506568

Please sign in to comment.