Skip to content

Commit

Permalink
fix some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
l4zs committed Oct 30, 2022
1 parent 4b95a18 commit 185e540
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 186 deletions.
36 changes: 26 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,38 +1,54 @@
val javaVersion = 17
val kspigotVersion = "1.19.0"

plugins {
kotlin("jvm") version "1.7.0"
kotlin("jvm") version "1.7.20"
id("io.papermc.paperweight.userdev") version "1.3.8"
id("net.minecrell.plugin-yml.bukkit") version "0.5.2"
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
id("io.papermc.paperweight.userdev") version "1.3.6"
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
id("com.github.johnrengelman.shadow") version "7.1.2"
}

group = "de.l4zs"
version = "1.1.2"

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
// PaperMC Dependency
paperDevBundle("1.19-R0.1-SNAPSHOT")
paperDevBundle("1.19.2-R0.1-SNAPSHOT")

// KSpigot dependency
implementation("net.axay", "kspigot", "1.19.0")
shadow("net.axay", "kspigot", kspigotVersion)

shadow("de.l4zs", "translations", "1.0.0-SNAPSHOT-22-08-02-23-15")
}

tasks {
jar {
enabled = false
}
assemble {
dependsOn(reobfJar, shadowJar)
}
shadowJar {
configurations = listOf(project.configurations.shadow.get())
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = listOf(
"-Xjdk-release=17"
"-Xjdk-release=$javaVersion",
"-opt-in=kotlin.RequiresOptIn",
)
jvmTarget = "17"
freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn"
jvmTarget = "$javaVersion"
}
}
compileJava {
options.encoding = "UTF-8"
options.release.set(17)
options.release.set(javaVersion)
}
}

Expand All @@ -45,6 +61,6 @@ bukkit {
main = "$group.tpa.TPA"
version = getVersion().toString()
libraries = listOf(
"net.axay:kspigot:1.19.0",
// "net.axay:kspigot:1.19.0",
)
}
6 changes: 3 additions & 3 deletions src/main/kotlin/de/l4zs/tpa/TPA.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

package de.l4zs.tpa

import de.l4zs.tpa.command.BackCommand
import de.l4zs.tpa.back.BackCommand
import de.l4zs.tpa.back.BackListener
import de.l4zs.tpa.command.TpaCommand
import de.l4zs.tpa.command.TpacceptCommand
import de.l4zs.tpa.command.TpahereCommand
Expand All @@ -28,7 +29,6 @@ import de.l4zs.tpa.command.TpdenyCommand
import de.l4zs.tpa.command.TptoggleCommand
import de.l4zs.tpa.config.ConfigManager
import de.l4zs.tpa.i18n.TranslationsProvider
import de.l4zs.tpa.listener.BackListener
import de.l4zs.tpa.util.TpaManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -56,7 +56,7 @@ class TPA : KSpigot() {
TpcancelCommand(),
TpdenyCommand(),
TptoggleCommand()
).filter { !configManager.config.disabledCommands.contains(it.commandName) }.map { it.register(this) }
).filter { !configManager.config.disabledCommands.contains(it.commandName) }.forEach { it.register(this) }

BackListener().register()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package de.l4zs.tpa.command
package de.l4zs.tpa.back

import de.l4zs.tpa.TPA
import de.l4zs.tpa.listener.backLocation
import de.l4zs.tpa.command.RegisterableCommand
import de.l4zs.tpa.util.Message
import net.axay.kspigot.commands.command
import net.axay.kspigot.commands.requiresPermission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package de.l4zs.tpa.listener
package de.l4zs.tpa.back

import net.axay.kspigot.event.listen
import net.axay.kspigot.extensions.pluginKey
import net.axay.kspigot.extensions.server
import org.bukkit.Location
import org.bukkit.NamespacedKey
import org.bukkit.entity.Player
import org.bukkit.event.entity.PlayerDeathEvent
import org.bukkit.persistence.PersistentDataAdapterContext
import org.bukkit.persistence.PersistentDataContainer
import org.bukkit.persistence.PersistentDataType
Expand Down Expand Up @@ -85,10 +83,3 @@ var Player.backLocation: Location?
persistentDataContainer.set(backNamespace, LOCATION_TAG_TYPE, value)
}
}

class BackListener {

fun register() = listen<PlayerDeathEvent> {
it.player.backLocation = it.player.location
}
}
29 changes: 29 additions & 0 deletions src/main/kotlin/de/l4zs/tpa/back/BackListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* TPA is a simple plugin giving the ability to request teleports to others and go back to your death location if you die.
* Copyright (c) 2022 l4zs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package de.l4zs.tpa.back

import net.axay.kspigot.event.listen
import org.bukkit.event.entity.PlayerDeathEvent

class BackListener {

fun register() = listen<PlayerDeathEvent> {
it.player.backLocation = it.player.location
}
}
21 changes: 21 additions & 0 deletions src/main/kotlin/de/l4zs/tpa/command/RegisterableCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
package de.l4zs.tpa.command

import com.mojang.brigadier.builder.LiteralArgumentBuilder
import com.mojang.brigadier.builder.RequiredArgumentBuilder
import de.l4zs.tpa.TPA
import net.axay.kspigot.commands.getArgument
import net.axay.kspigot.commands.suggestListSuspending
import net.axay.kspigot.extensions.onlinePlayers
import net.minecraft.commands.CommandSourceStack

interface RegisterableCommand {
Expand All @@ -28,3 +32,20 @@ interface RegisterableCommand {

fun register(plugin: TPA): LiteralArgumentBuilder<CommandSourceStack>
}

fun RequiredArgumentBuilder<CommandSourceStack, *>.suggestOnlinePlayers() {
suggestListSuspending { suggest ->
onlinePlayers
.filter {
it.uniqueId != suggest.source.player?.uuid &&
try {
val input = suggest.getArgument<String>("player")
it.name.lowercase().startsWith(input.lowercase())
} catch (_: IllegalArgumentException) {
true
}
}
.map { it.name }
.sorted()
}
}
14 changes: 1 addition & 13 deletions src/main/kotlin/de/l4zs/tpa/command/TpaCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import net.axay.kspigot.chat.KColors
import net.axay.kspigot.chat.literalText
import net.axay.kspigot.commands.argument
import net.axay.kspigot.commands.command
import net.axay.kspigot.commands.getArgument
import net.axay.kspigot.commands.literal
import net.axay.kspigot.commands.requiresPermission
import net.axay.kspigot.commands.runs
import net.axay.kspigot.commands.suggestListSuspending
import net.axay.kspigot.extensions.onlinePlayers
import net.kyori.adventure.text.Component

Expand All @@ -40,17 +38,7 @@ class TpaCommand : RegisterableCommand {
override fun register(plugin: TPA) = command(commandName) {
requiresPermission("tpa.tpa")
argument("player", StringArgumentType.greedyString()) {
suggestListSuspending { suggest ->
onlinePlayers.filter {
if (it.name == suggest.source.player?.displayName) {
false
} else if (suggest.input != null && suggest.input.substring(suggest.input.length - 1) != " ") {
it.name.lowercase().startsWith(suggest.getArgument<String>("player").lowercase())
} else {
true
}
}.map { it.name }.sorted()
}
suggestOnlinePlayers()
runs {
val target = onlinePlayers.firstOrNull { it.name == getArgument<String>("player") }
?: return@runs player.sendMessage(
Expand Down
14 changes: 1 addition & 13 deletions src/main/kotlin/de/l4zs/tpa/command/TpacceptCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ import de.l4zs.tpa.TPA
import de.l4zs.tpa.util.Message
import net.axay.kspigot.commands.argument
import net.axay.kspigot.commands.command
import net.axay.kspigot.commands.getArgument
import net.axay.kspigot.commands.requiresPermission
import net.axay.kspigot.commands.runs
import net.axay.kspigot.commands.suggestListSuspending
import net.axay.kspigot.extensions.onlinePlayers

class TpacceptCommand : RegisterableCommand {
Expand All @@ -36,17 +34,7 @@ class TpacceptCommand : RegisterableCommand {
override fun register(plugin: TPA) = command(commandName) {
requiresPermission("tpa.tpaccept")
argument("player", StringArgumentType.greedyString()) {
suggestListSuspending { suggest ->
onlinePlayers.filter {
if (it.name == suggest.source.player?.displayName) {
false
} else if (suggest.input != null && suggest.input.substring(suggest.input.length - 1) != " ") {
it.name.lowercase().startsWith(suggest.getArgument<String>("player").lowercase())
} else {
true
}
}.map { it.name }.sorted()
}
suggestOnlinePlayers()
runs {
val targetName = getArgument<String>("player")
val target = onlinePlayers.firstOrNull { it.name == targetName }
Expand Down
16 changes: 1 addition & 15 deletions src/main/kotlin/de/l4zs/tpa/command/TpahereCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import com.mojang.brigadier.arguments.StringArgumentType
import de.l4zs.tpa.TPA
import net.axay.kspigot.commands.argument
import net.axay.kspigot.commands.command
import net.axay.kspigot.commands.getArgument
import net.axay.kspigot.commands.requiresPermission
import net.axay.kspigot.commands.runs
import net.axay.kspigot.commands.suggestListSuspending
import net.axay.kspigot.extensions.onlinePlayers
import net.kyori.adventure.text.Component

Expand All @@ -36,19 +34,7 @@ class TpahereCommand : RegisterableCommand {
override fun register(plugin: TPA) = command(commandName) {
requiresPermission("tpa.tpahere")
argument("player", StringArgumentType.greedyString()) {
suggestListSuspending { suggest ->
onlinePlayers.filter {
suggest.input != null && it.name.startsWith(suggest.getArgument<String>("player"))
}.map { it.name }.filter {
if (it == suggest.source.player?.displayName) {
false
} else if (suggest.input != null && suggest.input.substring(suggest.input.length - 1) != " ") {
it.lowercase().startsWith(suggest.getArgument<String>("player").lowercase())
} else {
true
}
}.sorted()
}
suggestOnlinePlayers()
runs {
val target = onlinePlayers.firstOrNull { it.name == getArgument<String>("player") }
?: return@runs player.sendMessage(
Expand Down
14 changes: 1 addition & 13 deletions src/main/kotlin/de/l4zs/tpa/command/TpcancelCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import com.mojang.brigadier.arguments.StringArgumentType
import de.l4zs.tpa.TPA
import net.axay.kspigot.commands.argument
import net.axay.kspigot.commands.command
import net.axay.kspigot.commands.getArgument
import net.axay.kspigot.commands.requiresPermission
import net.axay.kspigot.commands.runs
import net.axay.kspigot.commands.suggestListSuspending
import net.axay.kspigot.extensions.onlinePlayers
import net.kyori.adventure.text.Component

Expand All @@ -36,17 +34,7 @@ class TpcancelCommand : RegisterableCommand {
override fun register(plugin: TPA) = command(commandName) {
requiresPermission("tpa.tpcancel")
argument("player", StringArgumentType.greedyString()) {
suggestListSuspending { suggest ->
onlinePlayers.filter {
if (it.name == suggest.source.player?.displayName) {
false
} else if (suggest.input != null && suggest.input.substring(suggest.input.length - 1) != " ") {
it.name.lowercase().startsWith(suggest.getArgument<String>("player").lowercase())
} else {
true
}
}.map { it.name }.sorted()
}
suggestOnlinePlayers()
runs {
val target = onlinePlayers.firstOrNull { it.name == getArgument<String>("player") }
?: return@runs player.sendMessage(
Expand Down
14 changes: 1 addition & 13 deletions src/main/kotlin/de/l4zs/tpa/command/TpdenyCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import com.mojang.brigadier.arguments.StringArgumentType
import de.l4zs.tpa.TPA
import net.axay.kspigot.commands.argument
import net.axay.kspigot.commands.command
import net.axay.kspigot.commands.getArgument
import net.axay.kspigot.commands.requiresPermission
import net.axay.kspigot.commands.runs
import net.axay.kspigot.commands.suggestListSuspending
import net.axay.kspigot.extensions.onlinePlayers
import net.kyori.adventure.text.Component

Expand All @@ -36,17 +34,7 @@ class TpdenyCommand : RegisterableCommand {
override fun register(plugin: TPA) = command(commandName) {
requiresPermission("tpa.tpdeny")
argument("player", StringArgumentType.greedyString()) {
suggestListSuspending { suggest ->
onlinePlayers.filter {
if (it.name == suggest.source.player?.displayName) {
false
} else if (suggest.input != null && suggest.input.substring(suggest.input.length - 1) != " ") {
it.name.lowercase().startsWith(suggest.getArgument<String>("player").lowercase())
} else {
true
}
}.map { it.name }.sorted()
}
suggestOnlinePlayers()
runs {
val target = onlinePlayers.firstOrNull { it.name == getArgument<String>("player") }
?: return@runs player.sendMessage(
Expand Down
Loading

0 comments on commit 185e540

Please sign in to comment.