Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import me.testaccount666.serversystem.clickablesigns.executables.weather.ActionW
import me.testaccount666.serversystem.clickablesigns.executables.weather.ConfiguratorWeatherSign

enum class SignType(private val _key: String, val signName: String, val clickAction: SignClickAction, val configurator: SignConfigurator) {
GIVE("Give", "&#3F3FD1[Give]", ActionGiveSign(), ConfiguratorGiveSign()),
GIVE("Give", "&#3F3FD1[GIVE]", ActionGiveSign(), ConfiguratorGiveSign()),
KIT("Kit", "&#3F3FD1[KIT]", ActionKitSign(), ConfiguratorKitSign()),
WARP("Warp", "&#3F3FD1[WARP]", ActionWarpSign(), ConfiguratorWarpSign()),
TIME("Time", "&#3F3FD1[TIME]", ActionTimeSign(), ConfiguratorTimeSign()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import me.testaccount666.serversystem.ServerSystem.Companion.instance
import me.testaccount666.serversystem.ServerSystem.Companion.log
import me.testaccount666.serversystem.commands.ServerSystemCommand
import me.testaccount666.serversystem.commands.executables.AbstractServerSystemCommand
import me.testaccount666.serversystem.managers.PermissionManager.hasCommandPermission
import me.testaccount666.serversystem.managers.config.ConfigurationManager
import me.testaccount666.serversystem.userdata.User
import me.testaccount666.serversystem.userdata.teleport.TeleportRunnable.Companion.teleportLater
import me.testaccount666.serversystem.userdata.teleport.TeleportRunnable.Companion.teleportNow
import me.testaccount666.serversystem.utils.MessageBuilder.Companion.command
import me.testaccount666.serversystem.utils.MessageBuilder.Companion.general
import org.bukkit.Bukkit
Expand Down Expand Up @@ -53,7 +56,6 @@ open class CommandSpawn : AbstractServerSystemCommand {
if (!spawnConfiguration.isSet("Spawn")) return

val worldName = spawnConfiguration.getString("Spawn.World") ?: return

val world = Bukkit.getWorld(worldName) ?: return

val x = spawnConfiguration.getDouble("Spawn.X")
Expand All @@ -67,17 +69,17 @@ open class CommandSpawn : AbstractServerSystemCommand {

override fun execute(commandSender: User, command: Command, label: String, vararg arguments: String) {
if (command.name.equals("spawn", true)) {
handleSpawnCommand(commandSender, label, *arguments)
handleSpawnCommand(commandSender, label, true, *arguments)
return
}

handleSetSpawnCommand(commandSender, label)
}

fun handleSpawnCommand(commandSender: User, label: String, vararg arguments: String) {
fun handleSpawnCommand(commandSender: User, label: String, fromCommand: Boolean, vararg arguments: String) {
if (isConsoleWithNoTarget(commandSender, getSyntaxPath(null), label, arguments = arguments)) return

if (spawnLocation == null) {
val spawnLocation = spawnLocation ?: run {
command("Spawn.NoSpawnSet", commandSender).build()
return
}
Expand All @@ -86,16 +88,28 @@ open class CommandSpawn : AbstractServerSystemCommand {
general("PlayerNotFound", commandSender) { target(arguments[0]) }.build()
return
}

val targetPlayer = targetUser.getPlayer()!!
val isSelf = targetUser === commandSender

if (!isSelf && !checkPermission(commandSender, "Spawn.Other", targetPlayer.name)) return
if (!isSelf && !checkPermission(commandSender, "Spawn.Other", targetUser.getNameSafe())) return

val instantTeleport = !fromCommand || !isSelf || hasCommandPermission(commandSender, "Spawn.InstantTeleport", false)

if (instantTeleport) {
targetUser.teleportNow(spawnLocation)
sendSuccessMessage(commandSender, targetUser, isSelf)
return
}

targetPlayer.teleport(spawnLocation!!)
command("Spawn.Teleporting", commandSender) { target(targetUser.getNameSafe()) }.build()
targetUser.teleportLater(spawnLocation).apply {
onSuccess = { sendSuccessMessage(commandSender, targetUser, true) }
onFailure = { command("Spawn.Moved", commandSender).build() }
}
}

private fun sendSuccessMessage(commandSender: User, targetUser: User, isSelf: Boolean) {
val messagePath = if (isSelf) "Spawn.Success" else "Spawn.SuccessOther"
command(messagePath, commandSender) { target(targetPlayer.name) }.build()
command(messagePath, commandSender) { target(targetUser.getNameSafe()) }.build()

if (isSelf) return
command("Spawn.Success", targetUser) { sender(commandSender.getNameSafe()) }.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ListenerSpawn : Listener {
if (cachedUser.isOfflineUser) return@Runnable

val user = cachedUser.offlineUser as User
_commandSpawn.handleSpawnCommand(user, "spawn")
_commandSpawn.handleSpawnCommand(user, "spawn", false)
}, 20L)
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package me.testaccount666.serversystem.commands.executables.teleportask

import me.testaccount666.serversystem.ServerSystem.Companion.instance
import me.testaccount666.serversystem.ServerSystem.Companion.log
import me.testaccount666.serversystem.commands.ServerSystemCommand
import me.testaccount666.serversystem.commands.executables.AbstractServerSystemCommand
import me.testaccount666.serversystem.managers.PermissionManager.hasCommandPermission
import me.testaccount666.serversystem.managers.messages.MessageManager.applyPlaceholders
import me.testaccount666.serversystem.userdata.User
import me.testaccount666.serversystem.userdata.teleport.TeleportRequest
import me.testaccount666.serversystem.userdata.teleport.TeleportRunnable.Companion.teleportLater
import me.testaccount666.serversystem.userdata.teleport.TeleportRunnable.Companion.teleportNow
import me.testaccount666.serversystem.utils.ComponentColor.translateToComponent
import me.testaccount666.serversystem.utils.MessageBuilder.Companion.command
import me.testaccount666.serversystem.utils.MessageBuilder.Companion.general
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.event.ClickEvent
import net.kyori.adventure.text.event.HoverEvent
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.Particle
import org.bukkit.Sound
import org.bukkit.command.Command

@ServerSystemCommand("teleportask", ["teleporthereask", "teleportaccept", "teleportdeny", "teleporttoggle"])
Expand Down Expand Up @@ -212,6 +210,7 @@ class CommandTeleportAsk : AbstractServerSystemCommand() {

private fun handleTeleportAccept(commandSender: User) {
val teleportRequest = validateTeleportRequest(commandSender) ?: return
teleportRequest.isCancelled = true

val requester = teleportRequest.sender
commandSender.teleportRequest = null
Expand All @@ -221,15 +220,7 @@ class CommandTeleportAsk : AbstractServerSystemCommand() {
val teleporter = if (teleportRequest.isTeleportHere) commandSender else requester
val target = if (teleportRequest.isTeleportHere) requester else commandSender

val canInstantTeleport = hasCommandPermission(teleporter, "TeleportAsk.InstantTeleport", false)

if (canInstantTeleport) {
executeTeleport(teleporter, target)
return
}

command("TeleportAsk.StartingTeleporting", teleporter) { target(target.getNameSafe()) }.build()
startTeleportTimer(teleporter, target, teleportRequest)
executeTeleport(teleporter, target)
}

private fun handleTeleportDeny(commandSender: User) {
Expand All @@ -242,20 +233,6 @@ class CommandTeleportAsk : AbstractServerSystemCommand() {
command("TeleportDeny.SuccessOther", requester) { target(commandSender.getNameSafe()) }.build()
}

private fun startTeleportTimer(teleporter: User, target: User, teleportRequest: TeleportRequest) {
val teleporterPlayer = teleporter.getPlayer()
val targetPlayer = target.getPlayer()

activeTeleportRequests.add(teleportRequest)
(Bukkit.getScheduler().scheduleSyncDelayedTask(instance, {
if (teleporterPlayer == null || !teleporterPlayer.isOnline) return@scheduleSyncDelayedTask
if (targetPlayer == null || !targetPlayer.isOnline) return@scheduleSyncDelayedTask

executeTeleport(teleporter, target)
activeTeleportRequests.remove(teleportRequest)
}, 20L * 5)).also { teleportRequest.timerId = it }
}

/**
* Executes the teleport with animation and notification
*
Expand All @@ -265,11 +242,16 @@ class CommandTeleportAsk : AbstractServerSystemCommand() {
private fun executeTeleport(teleporter: User, target: User) {
val targetLocation = target.getPlayer()!!.location

playAnimation(targetLocation)
teleporter.getPlayer()!!.teleport(targetLocation)
playAnimation(targetLocation)

command("TeleportAsk.TeleportFinished", teleporter) { target(target.getNameSafe()) }.build()
if (!hasCommandPermission(teleporter, "TeleportAsk.InstantTeleport", false)) {
command("TeleportAsk.StartingTeleporting", teleporter) { target(target.getNameSafe()) }.build()
teleporter.teleportLater(targetLocation).apply {
onFailure = { command("TeleportAsk.Moved", user).build() }
onSuccess = { command("TeleportAsk.TeleportFinished", user).build() }
}
} else {
teleporter.teleportNow(targetLocation)
command("TeleportAsk.TeleportFinished", teleporter) { target(target.getNameSafe()) }.build()
}
}


Expand All @@ -290,16 +272,6 @@ class CommandTeleportAsk : AbstractServerSystemCommand() {
.asComponent()
}

/**
* Plays a teleportation animation effect at the given location
*
* @param location The location to play the animation at
*/
private fun playAnimation(location: Location) {
location.world.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.0f)
location.world.spawnParticle(Particle.PORTAL, location, 100, 0.5, 0.5, 0.5, 0.05)
}

private fun handleTeleportToggle(commandSender: User, command: Command, label: String, vararg arguments: String) {
if (isConsoleWithNoTarget(commandSender, getSyntaxPath(command), label, arguments = arguments)) return

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package me.testaccount666.serversystem.commands.executables.waypoints

import me.testaccount666.serversystem.commands.executables.AbstractServerSystemCommand
import me.testaccount666.serversystem.userdata.User
import me.testaccount666.serversystem.userdata.teleport.TeleportRunnable.Companion.teleportLater
import me.testaccount666.serversystem.userdata.teleport.TeleportRunnable.Companion.teleportNow
import me.testaccount666.serversystem.utils.MessageBuilder.Companion.command
import me.testaccount666.serversystem.utils.MessageBuilder.Companion.general
import me.testaccount666.serversystem.utils.tuples.Tuple
import org.bukkit.Location
import org.bukkit.Particle
import org.bukkit.Sound
import org.bukkit.command.Command

abstract class AbstractCommandWaypoint<T : WaypointManager<P>, P : Waypoint> : AbstractServerSystemCommand() {
Expand Down Expand Up @@ -75,16 +75,25 @@ abstract class AbstractCommandWaypoint<T : WaypointManager<P>, P : Waypoint> : A
}

val pointLocation = point.location
val player = commandSender.getPlayer()!!

playAnimation(player.location)
player.teleport(pointLocation)
playAnimation(pointLocation)

command("${getPrefix(command)}.Success", commandSender) {
target(target.getNameSafe())
postModifier { it.replace(getPlaceholder(), point.displayName) }
}.build()
if (!canInstantTeleport(command, commandSender)) {
commandSender.teleportLater(pointLocation).apply {
onFailure = { command("${getPrefix(command)}.Moved", commandSender) { target(target.getNameSafe()) }.build() }
onSuccess = {
command("${getPrefix(command)}.Success", user) {
target(target.getNameSafe())
postModifier { it.replace(getPlaceholder(), point.displayName) }
}.build()
}
}
command("${getPrefix(command)}.Teleporting", commandSender) { target(target.getNameSafe()) }.build()
} else {
commandSender.teleportNow(pointLocation)
command("${getPrefix(command)}.Success", commandSender) {
target(target.getNameSafe())
postModifier { it.replace(getPlaceholder(), point.displayName) }
}.build()
}
}

private fun resolveTargetAndPoint(commandSender: User, command: Command, vararg arguments: String): Tuple<User, String>? {
Expand Down Expand Up @@ -114,11 +123,6 @@ abstract class AbstractCommandWaypoint<T : WaypointManager<P>, P : Waypoint> : A
}.build()
}

private fun playAnimation(location: Location) {
location.world.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.0f)
location.world.spawnParticle(Particle.PORTAL, location, 100, 0.5, 0.5, 0.5, 0.05)
}

abstract fun argsBeforePoint(command: Command): Int
abstract fun getWaypointManager(command: Command, targetUser: User): T
abstract fun getCommandType(command: Command): CommandType
Expand All @@ -127,6 +131,7 @@ abstract class AbstractCommandWaypoint<T : WaypointManager<P>, P : Waypoint> : A

abstract fun getPrefix(command: Command): String
abstract fun getPlaceholder(): String
abstract fun canInstantTeleport(command: Command, user: User): Boolean
}

enum class CommandType { CREATE, DELETE, TELEPORT }
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.testaccount666.serversystem.commands.executables.waypoints.home.admin

import me.testaccount666.serversystem.commands.executables.waypoints.CommandType
import me.testaccount666.serversystem.commands.executables.waypoints.home.AbstractCommandHome
import me.testaccount666.serversystem.userdata.User
import me.testaccount666.serversystem.userdata.home.HomeManager
import org.bukkit.command.Command

Expand Down Expand Up @@ -41,6 +42,6 @@ class CommandAdminHome : AbstractCommandHome() {
}

override fun getSyntaxPath(command: Command?) = "AdminHome"

override fun canAddPoints(pointManager: HomeManager, command: Command) = true
override fun canInstantTeleport(command: Command, user: User) = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import me.testaccount666.serversystem.commands.ServerSystemCommand
import me.testaccount666.serversystem.commands.executables.waypoints.CommandType
import me.testaccount666.serversystem.commands.executables.waypoints.home.AbstractCommandHome
import me.testaccount666.serversystem.commands.executables.waypoints.home.admin.CommandAdminHome
import me.testaccount666.serversystem.managers.PermissionManager.hasCommandPermission
import me.testaccount666.serversystem.userdata.User
import me.testaccount666.serversystem.userdata.home.HomeManager
import org.bukkit.command.Command

Expand Down Expand Up @@ -63,5 +65,10 @@ class CommandHome : AbstractCommandHome() {
}
}

override fun canInstantTeleport(command: Command, user: User): Boolean {
if (isAdminCommand(command)) return _commandAdminHome.canInstantTeleport(command, user)
return hasCommandPermission(user, "Home.InstantTeleport", false)
}

private fun isAdminCommand(command: Command?) = command?.name?.startsWith("admin", true) ?: false
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import me.testaccount666.serversystem.commands.executables.waypoints.AbstractCom
import me.testaccount666.serversystem.commands.executables.waypoints.CommandType
import me.testaccount666.serversystem.commands.executables.waypoints.warp.manager.Warp
import me.testaccount666.serversystem.commands.executables.waypoints.warp.manager.WarpManager
import me.testaccount666.serversystem.managers.PermissionManager.hasCommandPermission
import me.testaccount666.serversystem.userdata.User
import org.bukkit.Location
import org.bukkit.command.Command
Expand Down Expand Up @@ -43,4 +44,8 @@ class CommandWarp : AbstractCommandWaypoint<WarpManager, Warp>() {
CommandType.TELEPORT -> "Warp.Teleport"
}
}

override fun canInstantTeleport(command: Command, user: User): Boolean {
return hasCommandPermission(user, "Warp.InstantTeleport", false)
}
}
Loading