Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPA #2

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/kotlin/me/gserv/fabrikommander/Common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ object Common : ModInitializer {
HomesCommand(dispatcher).register()
SetHomeCommand(dispatcher).register()

// Teleport commands
TpaCommand(dispatcher).register()
YTG1234 marked this conversation as resolved.
Show resolved Hide resolved

// Misc comands
PingCommand(dispatcher).register()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import me.gserv.fabrikommander.data.PlayerDataManager
import me.gserv.fabrikommander.data.spec.Home
import me.gserv.fabrikommander.utils.*
import net.minecraft.server.command.CommandManager
import net.minecraft.text.LiteralText

class SetHomeCommand(val dispatcher: Dispatcher) {
fun register() {
Expand Down
36 changes: 36 additions & 0 deletions src/main/kotlin/me/gserv/fabrikommander/commands/TpaCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.gserv.fabrikommander.commands

import me.gserv.fabrikommander.data.TpaRequest
import me.gserv.fabrikommander.utils.Context
import me.gserv.fabrikommander.utils.Dispatcher
import net.minecraft.command.argument.EntityArgumentType
import net.minecraft.server.command.CommandManager.argument
YTG1234 marked this conversation as resolved.
Show resolved Hide resolved
import net.minecraft.server.command.CommandManager.literal

class TpaCommand(val dispatcher: Dispatcher) {
fun register() {
dispatcher.register(
literal("tpa").then(
argument("target", EntityArgumentType.player()).executes {
tpaCommand(it, false)
}
)
)

dispatcher.register(
literal("tpahere").then(
argument("target", EntityArgumentType.player()).executes {
tpaCommand(it, true)
}
)
)
}

fun tpaCommand(context: Context, tpaHere: Boolean): Int {
val target = EntityArgumentType.getPlayer(context, "target")
val source = context.source.player
val request = TpaRequest(source = source, target = target, tpaHere = tpaHere)
request.notifyTarget()
return 1
}
}
47 changes: 47 additions & 0 deletions src/main/kotlin/me/gserv/fabrikommander/data/TpaRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package me.gserv.fabrikommander.data

import me.gserv.fabrikommander.utils.*
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.text.ClickEvent
import net.minecraft.text.HoverEvent
import net.minecraft.text.MutableText
import net.minecraft.util.Util

class TpaRequest(
val source: ServerPlayerEntity,
val target: ServerPlayerEntity,
val availableForTicks: Int = 6000,
val tpaHere: Boolean
) {
fun apply() {
if (tpaHere) target.teleport(source.serverWorld, source.x, source.y, source.z, source.yaw, source.pitch)
source.teleport(target.serverWorld, target.x, target.y, target.z, target.yaw, target.pitch)
}

fun notifyTarget() {
// Message will be configurable later
val message = click(
YTG1234 marked this conversation as resolved.
Show resolved Hide resolved
hover(
source.displayName as MutableText + yellow(
" has requested " + when (tpaHere) {
true -> "you"
false -> "to"
} + " teleport to " + when (tpaHere) { // Will change to one when later, for now it's two
true -> "them"
false -> "you"
} + "."
),
HoverEvent(
HoverEvent.Action.SHOW_TEXT,
yellow("Click to teleport!")
)
),
ClickEvent(
ClickEvent.Action.RUN_COMMAND,
"/tpaccept " + source.uuidAsString // Command not implemented yet
)
)

target.sendSystemMessage(message, Util.NIL_UUID)
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/me/gserv/fabrikommander/utils/Text.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ fun hover(text: MutableText, event: HoverEvent) = text.setStyle(text.style.withH
// endregion

// region: Operators
operator fun MutableText.plus(other: MutableText): MutableText = this.append(other)
operator fun MutableText.plus(other: Text): MutableText = this.append(other)
gdude2002 marked this conversation as resolved.
Show resolved Hide resolved
// endregion