From cad28639d685e1835130e3a3b5e3e67d45a95076 Mon Sep 17 00:00:00 2001 From: Atrius Date: Mon, 23 Aug 2021 06:02:16 -0400 Subject: [PATCH 01/14] Update spigot version to 1.16.5 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 725c75e..fc6c604 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ repositories { } dependencies { - compileOnly 'org.spigotmc:spigot-api:1.16.3-R0.1-SNAPSHOT' + compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } From 4cae2577aa1d225b87db120e2100d0da6f228da0 Mon Sep 17 00:00:00 2001 From: Atrius Date: Mon, 23 Aug 2021 06:02:50 -0400 Subject: [PATCH 02/14] Rename ratios to environment names --- src/main/resources/ratios.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/ratios.json b/src/main/resources/ratios.json index 9bf2a5d..061a5c7 100644 --- a/src/main/resources/ratios.json +++ b/src/main/resources/ratios.json @@ -1,5 +1,5 @@ { - "world": 1, - "world_nether": 8, - "world_end": 1 + "normal": 1, + "nether": 8, + "the_end": 1 } \ No newline at end of file From e9d3a9cdde8dc471e691b4f4c85d4997d028ce78 Mon Sep 17 00:00:00 2001 From: Atrius Date: Mon, 23 Aug 2021 06:12:24 -0400 Subject: [PATCH 03/14] Update ratio service to mirror the new values as well as add support for dynamically modifying the values --- .../xyz/atrius/waystones/data/JsonFile.kt | 6 +++--- .../waystones/service/WorldRatioService.kt | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/xyz/atrius/waystones/data/JsonFile.kt b/src/main/kotlin/xyz/atrius/waystones/data/JsonFile.kt index 14d3d80..9363abb 100644 --- a/src/main/kotlin/xyz/atrius/waystones/data/JsonFile.kt +++ b/src/main/kotlin/xyz/atrius/waystones/data/JsonFile.kt @@ -5,8 +5,6 @@ import xyz.atrius.waystones.plugin import java.io.File import java.io.FileReader import java.nio.file.Files -import java.nio.file.StandardOpenOption.CREATE -import java.nio.file.StandardOpenOption.WRITE open class JsonFile(name: String) { private val file = File(plugin.dataFolder, "$name.json") @@ -23,7 +21,9 @@ open class JsonFile(name: String) { data = json.fromJson(FileReader(file), HashMap()::class.java) } - fun save() { + fun save(forceLowercase: Boolean = false) { + if (forceLowercase) + data.mapKeysTo(data) { (key) -> key.toLowerCase() } val json = json.toJson(data) Files.write(file.toPath(), json.toByteArray()) } diff --git a/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt b/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt index adb1982..c9bbe5e 100644 --- a/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt +++ b/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt @@ -6,5 +6,22 @@ import xyz.atrius.waystones.data.JsonFile object WorldRatioService : JsonFile("ratios") { operator fun get(world: World): Double = - data.getOrDefault(world.name, 1.0) + data.getOrDefault(world.environment.name.toLowerCase(), 1.0) + + operator fun get(name: String, asEnvironment: Boolean): Double { + val key = if (asEnvironment) name else "name:$name" + return data.getOrDefault(key.toLowerCase(), 1.0) + } + + fun add(value: String, asEnvironment: Boolean, ratio: Double) { + val key = if (asEnvironment) value else "name:$value" + data[key.toLowerCase()] = ratio + save(true) + } + + fun remove(value: String, asEnvironment: Boolean) { + val key = if (asEnvironment) value else "name:$value" + data.remove(key) + save(true) + } } \ No newline at end of file From 0f553975c7eb1040d905c44f634644a6e3478959 Mon Sep 17 00:00:00 2001 From: Atrius Date: Tue, 24 Aug 2021 04:21:46 -0400 Subject: [PATCH 04/14] Add localized messages for ratio command --- src/main/resources/locale-cn.yml | 7 +++++++ src/main/resources/locale-en.yml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/resources/locale-cn.yml b/src/main/resources/locale-cn.yml index 9bb26cc..b787e17 100644 --- a/src/main/resources/locale-cn.yml +++ b/src/main/resources/locale-cn.yml @@ -4,6 +4,13 @@ command-config-set: "&7[&d传送石&7] &b成功设置 &e{0} &b为 &a{1}!" command-config-set-fail: "&7[&d传送石&7] &c修改设置 {0} 失败." command-give-key: "&7[&d传送石&7]&f 给予 &b{0}个&r 传送石钥匙 给玩家 &a{1}&r" command-reload: "&7[&d传送石&7] &a配置文件已重载!" +command-ratio-invalid-command: "" +command-no-arguments: "" +command-ratio-bad-sender: "" +command-ratio-world-not-found: "" +command-ratio-added-successfully: "" +command-ratio-removed-successfully: "" +command-ratio-no-ratios: "" waystone-info: "&3&l名称: {0} | {1}" waystone-status: "状态: {0}{1,choice,-2#|-1#' | 距离: {1,choice,-1#无限|0#{1}}'}" waystone-status-active: "激活" diff --git a/src/main/resources/locale-en.yml b/src/main/resources/locale-en.yml index 2d66c2d..abca3f9 100644 --- a/src/main/resources/locale-en.yml +++ b/src/main/resources/locale-en.yml @@ -4,6 +4,13 @@ command-config-set: "&7[&dWaystones&7] &bSuccessfully updated &e{0} &bto &a{1}!" command-config-set-fail: "&7[&dWaystones&7] &cFailed to update setting {0}." command-give-key: "&7[&dWaystones&7]&f Gave &bx{0}&r {0,choice,1#WarpKey|1 Date: Tue, 24 Aug 2021 04:22:52 -0400 Subject: [PATCH 05/14] Update command execute method with flag support --- .../waystones/commands/CommandNamespace.kt | 8 +- .../waystones/commands/ConfigCommand.kt | 2 +- .../xyz/atrius/waystones/commands/Flags.kt | 11 +++ .../waystones/commands/GetKeyCommand.kt | 2 +- .../atrius/waystones/commands/InfoCommand.kt | 2 +- .../atrius/waystones/commands/RatioCommand.kt | 77 +++++++++++++++++++ .../waystones/commands/ReloadCommand.kt | 3 +- .../waystones/commands/SimpleCommand.kt | 2 +- 8 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/xyz/atrius/waystones/commands/Flags.kt create mode 100644 src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt diff --git a/src/main/kotlin/xyz/atrius/waystones/commands/CommandNamespace.kt b/src/main/kotlin/xyz/atrius/waystones/commands/CommandNamespace.kt index 98bf57a..1268985 100644 --- a/src/main/kotlin/xyz/atrius/waystones/commands/CommandNamespace.kt +++ b/src/main/kotlin/xyz/atrius/waystones/commands/CommandNamespace.kt @@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import xyz.atrius.waystones.data.MultiReferencable import xyz.atrius.waystones.utility.message +import xyz.atrius.waystones.utility.split class CommandNamespace( override vararg val aliases: String @@ -31,7 +32,12 @@ class CommandNamespace( // Execute the given command for (c in commands) { if (args[0] in c.aliases) { - c.execute(sender, args.drop(1).toTypedArray()) + val (arguments, flags) = args.drop(1).split { !it.startsWith("-") } + c.execute( + sender, + arguments.map(String::toLowerCase).toTypedArray(), + Flags(flags.toSet()) + ) return true } } diff --git a/src/main/kotlin/xyz/atrius/waystones/commands/ConfigCommand.kt b/src/main/kotlin/xyz/atrius/waystones/commands/ConfigCommand.kt index e070158..8e82853 100644 --- a/src/main/kotlin/xyz/atrius/waystones/commands/ConfigCommand.kt +++ b/src/main/kotlin/xyz/atrius/waystones/commands/ConfigCommand.kt @@ -7,7 +7,7 @@ import xyz.atrius.waystones.utility.message object ConfigCommand : SimpleCommand("config", "conf", "co", "c") { - override fun execute(sender: CommandSender, args: Array) { + override fun execute(sender: CommandSender, args: Array, flags: Flags) { // Permissions Check if (!sender.hasPermission("waystones.config")) return sender.message(localization["command-no-permission"]) diff --git a/src/main/kotlin/xyz/atrius/waystones/commands/Flags.kt b/src/main/kotlin/xyz/atrius/waystones/commands/Flags.kt new file mode 100644 index 0000000..e30b2af --- /dev/null +++ b/src/main/kotlin/xyz/atrius/waystones/commands/Flags.kt @@ -0,0 +1,11 @@ +package xyz.atrius.waystones.commands + +class Flags( + values: Set +) : Set by (values.map { + it.toLowerCase().removePrefix("-") +}.toSet()) { + + operator fun contains(values: Collection): Boolean = + values.map(String::toLowerCase).any(::contains) +} \ No newline at end of file diff --git a/src/main/kotlin/xyz/atrius/waystones/commands/GetKeyCommand.kt b/src/main/kotlin/xyz/atrius/waystones/commands/GetKeyCommand.kt index 249af6d..eee28a4 100644 --- a/src/main/kotlin/xyz/atrius/waystones/commands/GetKeyCommand.kt +++ b/src/main/kotlin/xyz/atrius/waystones/commands/GetKeyCommand.kt @@ -16,7 +16,7 @@ object GetKeyCommand : SimpleCommand("getkey", "gk", "key", "k") { return player to amount } - override fun execute(sender: CommandSender, args: Array) { + override fun execute(sender: CommandSender, args: Array, flags: Flags) { // Set Amount and Player to give WarpKeys to val (player, amount) = getPlayerAndAmount( sender as? Player, diff --git a/src/main/kotlin/xyz/atrius/waystones/commands/InfoCommand.kt b/src/main/kotlin/xyz/atrius/waystones/commands/InfoCommand.kt index b750c07..b839e19 100644 --- a/src/main/kotlin/xyz/atrius/waystones/commands/InfoCommand.kt +++ b/src/main/kotlin/xyz/atrius/waystones/commands/InfoCommand.kt @@ -23,6 +23,6 @@ object InfoCommand : SimpleCommand("info", "i") { |&7---------------&b-&d-&f-&d-&b-&7--------------- """.trimMargin().translateColors() - override fun execute(sender: CommandSender, args: Array) = + override fun execute(sender: CommandSender, args: Array, flags: Flags) = sender.sendMessage(infoMsg) } \ No newline at end of file diff --git a/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt b/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt new file mode 100644 index 0000000..97f4c91 --- /dev/null +++ b/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt @@ -0,0 +1,77 @@ +package xyz.atrius.waystones.commands + +import org.bukkit.Bukkit +import org.bukkit.World +import org.bukkit.command.CommandSender +import org.bukkit.command.ConsoleCommandSender +import org.bukkit.entity.Player +import xyz.atrius.waystones.localization +import xyz.atrius.waystones.service.WorldRatioService +import xyz.atrius.waystones.utility.message +import xyz.atrius.waystones.utility.toInt + + +// /waystones ratio [ set [name] [-environment] | remove [name] [-environment] | list ] +object RatioCommand : SimpleCommand("ratio", "ra", "r") { + + override fun execute(sender: CommandSender, args: Array, flags: Flags) { + if (!sender.hasPermission("waystones.ratios")) + return sender.message(localization["command-no-permission"]) + if (args.isEmpty()) + return sender.message(localization["command-no-arguments"]) + val environment = setOf("environment", "env", "e") in flags + val world = (sender as? Player)?.world + when (args[0]) { + in setOf("s", "set") -> set(sender, args, world, environment) + in setOf("r", "rem", "remove") -> remove(sender, args, world, environment) + in setOf("l", "list") -> list(sender) + else -> sender.message(localization["command-ratio-invalid-command", args[0]]) + } + } + + private fun set(sender: CommandSender, args: Array, world: World?, environment: Boolean) { + if (args.size < 2) + return sender.message(localization["command-no-arguments"]) + val selection = args.getOrNull(2)?.let(Bukkit::getWorld) ?: world + val message = if (args.size > 2) + localization["command-ratio-world-not-found", environment.toInt(), args[2]] + else + localization["command-ratio-bad-sender"] + WorldRatioService.add( + selection + ?: return sender.message(message), + environment, + args[1].toDoubleOrNull() + ?: return sender.message(localization["command-ratio-bad-ratio", args[1]]) + ) + val name = if (environment) selection.environment.name else selection.name + sender.message(localization["command-ratio-added-successfully", environment.toInt(), name.capitalize(), args[1]]) + } + + private fun remove(sender: CommandSender, args: Array, world: World?, environment: Boolean) { + if (args.size < 2 && sender is ConsoleCommandSender) + return sender.message(localization["command-no-arguments"]) + val selection = Bukkit.getWorld(args[1]) ?: world + val message = if (args.size > 1) + localization["command-ratio-world-not-found", environment.toInt(), args[1]] + else + localization["command-ratio-bad-sender"] + WorldRatioService.remove( + selection + ?: return sender.message(message), + environment + ) + val name = if (environment) selection.environment.name else selection.name + sender.message(localization["command-ratio-removed-successfully", environment.toInt(), name.capitalize()]) + } + + private fun list(sender: CommandSender) { + if (WorldRatioService.isEmpty()) + return sender.message(localization["command-ratio-no-ratios"]) + sender.message("&7--------- &dWaystones Ratios &7----------&r") + // Display each config property + for ((item, ratio) in WorldRatioService) + sender.message("&f$item&f: &b$ratio") + sender.message("&7-----------------------------------") + } +} \ No newline at end of file diff --git a/src/main/kotlin/xyz/atrius/waystones/commands/ReloadCommand.kt b/src/main/kotlin/xyz/atrius/waystones/commands/ReloadCommand.kt index b75fea4..1493fb5 100644 --- a/src/main/kotlin/xyz/atrius/waystones/commands/ReloadCommand.kt +++ b/src/main/kotlin/xyz/atrius/waystones/commands/ReloadCommand.kt @@ -1,14 +1,13 @@ package xyz.atrius.waystones.commands import org.bukkit.command.CommandSender -import xyz.atrius.waystones.configuration import xyz.atrius.waystones.data.config.ConfigManager import xyz.atrius.waystones.localization import xyz.atrius.waystones.utility.message object ReloadCommand : SimpleCommand("reload", "rl") { - override fun execute(sender: CommandSender, args: Array) { + override fun execute(sender: CommandSender, args: Array, flags: Flags) { if (!sender.hasPermission("waystones.reload")) { sender.message(localization["command-no-permission"]) return diff --git a/src/main/kotlin/xyz/atrius/waystones/commands/SimpleCommand.kt b/src/main/kotlin/xyz/atrius/waystones/commands/SimpleCommand.kt index 4ca759b..ca00c94 100644 --- a/src/main/kotlin/xyz/atrius/waystones/commands/SimpleCommand.kt +++ b/src/main/kotlin/xyz/atrius/waystones/commands/SimpleCommand.kt @@ -13,5 +13,5 @@ abstract class SimpleCommand( } } - abstract fun execute(sender: CommandSender, args: Array) + abstract fun execute(sender: CommandSender, args: Array, flags: Flags) } From b121a3dd501f17845aef0e08476444d1289adbef Mon Sep 17 00:00:00 2001 From: Atrius Date: Tue, 24 Aug 2021 04:23:06 -0400 Subject: [PATCH 06/14] Improve ratio service --- .../waystones/service/WorldRatioService.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt b/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt index c9bbe5e..c9298c1 100644 --- a/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt +++ b/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt @@ -3,25 +3,28 @@ package xyz.atrius.waystones.service import org.bukkit.World import xyz.atrius.waystones.data.JsonFile -object WorldRatioService : JsonFile("ratios") { +object WorldRatioService : JsonFile("ratios"), Iterable> { - operator fun get(world: World): Double = - data.getOrDefault(world.environment.name.toLowerCase(), 1.0) - - operator fun get(name: String, asEnvironment: Boolean): Double { - val key = if (asEnvironment) name else "name:$name" + operator fun get(world: World, asEnvironment: Boolean = false): Double { + val key = if (asEnvironment) world.environment.name else "name:${world.name}" return data.getOrDefault(key.toLowerCase(), 1.0) } - fun add(value: String, asEnvironment: Boolean, ratio: Double) { - val key = if (asEnvironment) value else "name:$value" + fun add(world: World, asEnvironment: Boolean, ratio: Double) { + val key = if (asEnvironment) world.environment.name else "name:${world.name}" data[key.toLowerCase()] = ratio save(true) } - fun remove(value: String, asEnvironment: Boolean) { - val key = if (asEnvironment) value else "name:$value" - data.remove(key) + fun remove(world: World, asEnvironment: Boolean) { + val key = if (asEnvironment) world.environment.name else "name:${world.name}" + data.remove(key.toLowerCase()) save(true) } + + fun isEmpty(): Boolean = + data.isEmpty() + + override fun iterator(): Iterator> = + data.iterator() } \ No newline at end of file From c126e7cf4460ce2477ce463f999b4a97f2affc45 Mon Sep 17 00:00:00 2001 From: Atrius Date: Tue, 24 Aug 2021 04:23:40 -0400 Subject: [PATCH 07/14] Include ratio command and add utility functions --- src/main/kotlin/xyz/atrius/waystones/Waystones.kt | 3 ++- .../kotlin/xyz/atrius/waystones/utility/String.kt | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/xyz/atrius/waystones/Waystones.kt b/src/main/kotlin/xyz/atrius/waystones/Waystones.kt index a5b739b..15f1110 100644 --- a/src/main/kotlin/xyz/atrius/waystones/Waystones.kt +++ b/src/main/kotlin/xyz/atrius/waystones/Waystones.kt @@ -44,7 +44,8 @@ class Waystones : KotlinPlugin() { InfoCommand, GetKeyCommand, ReloadCommand, - ConfigCommand + ConfigCommand, + RatioCommand ) ) logger.info("Waystones loaded!") diff --git a/src/main/kotlin/xyz/atrius/waystones/utility/String.kt b/src/main/kotlin/xyz/atrius/waystones/utility/String.kt index 2b84a87..9c88973 100644 --- a/src/main/kotlin/xyz/atrius/waystones/utility/String.kt +++ b/src/main/kotlin/xyz/atrius/waystones/utility/String.kt @@ -15,4 +15,17 @@ fun String.splitMultiline() = split("\n").toTypedArray() // Glues a list together into a single string -fun List.glue(): String = joinToString("") \ No newline at end of file +fun List.glue(): String = joinToString("") + +inline fun Collection.split(splitter: (T) -> Boolean): Pair, Array> { + val match = mutableListOf() + val rest = mutableListOf() + for (item in this) + if (splitter(item)) match += item else rest += item + return match.toTypedArray() to rest.toTypedArray() +} + +operator fun List.contains(values: Set): Boolean = + values.any(::contains) + +fun Boolean.toInt(): Int = if (this) 1 else 0 \ No newline at end of file From 2c4217e47373fd12a172a9f87210cdc33771acef Mon Sep 17 00:00:00 2001 From: Atrius Date: Tue, 24 Aug 2021 06:12:19 -0400 Subject: [PATCH 08/14] Update base ratios --- src/main/resources/ratios.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/ratios.json b/src/main/resources/ratios.json index 061a5c7..585d8f6 100644 --- a/src/main/resources/ratios.json +++ b/src/main/resources/ratios.json @@ -1,5 +1,6 @@ { "normal": 1, "nether": 8, - "the_end": 1 + "the_end": 1, + "custom:limbo": -1 } \ No newline at end of file From 1dce148b3c97065599bd3ed3963dea392ff9fdf6 Mon Sep 17 00:00:00 2001 From: Atrius Date: Tue, 24 Aug 2021 06:12:47 -0400 Subject: [PATCH 09/14] Simplify a couple utility functions --- src/main/kotlin/xyz/atrius/waystones/utility/Location.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/xyz/atrius/waystones/utility/Location.kt b/src/main/kotlin/xyz/atrius/waystones/utility/Location.kt index f898101..cb4b591 100644 --- a/src/main/kotlin/xyz/atrius/waystones/utility/Location.kt +++ b/src/main/kotlin/xyz/atrius/waystones/utility/Location.kt @@ -71,7 +71,7 @@ fun Location.rotateY(angle: Double, amp: Double = 1.0) = add(Vector(cos(angle) * amp, 2.0, sin(angle) * amp)) fun Location.sameDimension(other: Location) = - world == other.world ?: false + world == other.world /* * Synchronizes the world coordinates between 2 trans-dimensional locations. This is @@ -82,7 +82,7 @@ fun Location.synchronize(other: Location): TeleportType = if (sameDimension(other.world)) Normal else Interdimensional(world, other.world) fun Location.sameDimension(world: World?) = - world == this.world ?: false + world == this.world fun Location.playSound(sound: Sound, volume: Float = 1f, pitch: Float = 1f) = Bukkit.getOnlinePlayers() .forEach { if (it.world == world) it.playSound(this, sound, volume, pitch) } From edfd434e484a0ec7cf1e9740b86d126f7f7bbcda Mon Sep 17 00:00:00 2001 From: Atrius Date: Tue, 24 Aug 2021 06:13:37 -0400 Subject: [PATCH 10/14] Change ratio service to cascade ratio by name and fallback to environment if name not present (or 1 if nothing is present) --- .../xyz/atrius/waystones/service/WorldRatioService.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt b/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt index c9298c1..e7670ef 100644 --- a/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt +++ b/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt @@ -5,10 +5,10 @@ import xyz.atrius.waystones.data.JsonFile object WorldRatioService : JsonFile("ratios"), Iterable> { - operator fun get(world: World, asEnvironment: Boolean = false): Double { - val key = if (asEnvironment) world.environment.name else "name:${world.name}" - return data.getOrDefault(key.toLowerCase(), 1.0) - } + operator fun get(world: World): Double = + data["name${world.name.toLowerCase()}"] + ?: data[world.environment.name.toLowerCase()] + ?: 1.0 fun add(world: World, asEnvironment: Boolean, ratio: Double) { val key = if (asEnvironment) world.environment.name else "name:${world.name}" From b6c21cac2c6dabdc29bb02ac648d536c64160895 Mon Sep 17 00:00:00 2001 From: Atrius Date: Wed, 25 Aug 2021 06:09:35 -0400 Subject: [PATCH 11/14] Modify ratio system so that it isn't as strict --- .../atrius/waystones/commands/RatioCommand.kt | 23 ++++++++------ .../waystones/service/WorldRatioService.kt | 31 ++++++++++++++----- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt b/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt index 97f4c91..b0112c8 100644 --- a/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt +++ b/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt @@ -1,6 +1,5 @@ package xyz.atrius.waystones.commands -import org.bukkit.Bukkit import org.bukkit.World import org.bukkit.command.CommandSender import org.bukkit.command.ConsoleCommandSender @@ -32,37 +31,41 @@ object RatioCommand : SimpleCommand("ratio", "ra", "r") { private fun set(sender: CommandSender, args: Array, world: World?, environment: Boolean) { if (args.size < 2) return sender.message(localization["command-no-arguments"]) - val selection = args.getOrNull(2)?.let(Bukkit::getWorld) ?: world + val selection = args.getOrNull(2) + ?: if (environment) world?.environment?.name else world?.name val message = if (args.size > 2) localization["command-ratio-world-not-found", environment.toInt(), args[2]] else localization["command-ratio-bad-sender"] WorldRatioService.add( - selection + selection?.toLowerCase() ?: return sender.message(message), environment, args[1].toDoubleOrNull() ?: return sender.message(localization["command-ratio-bad-ratio", args[1]]) ) - val name = if (environment) selection.environment.name else selection.name - sender.message(localization["command-ratio-added-successfully", environment.toInt(), name.capitalize(), args[1]]) + sender.message( + localization["command-ratio-added-successfully", environment.toInt(), selection.capitalize(), args[1]] + ) } private fun remove(sender: CommandSender, args: Array, world: World?, environment: Boolean) { if (args.size < 2 && sender is ConsoleCommandSender) return sender.message(localization["command-no-arguments"]) - val selection = Bukkit.getWorld(args[1]) ?: world + val selection = args.getOrNull(1) + ?: if (environment) world?.environment?.name else world?.name val message = if (args.size > 1) localization["command-ratio-world-not-found", environment.toInt(), args[1]] else localization["command-ratio-bad-sender"] WorldRatioService.remove( - selection - ?: return sender.message(message), + selection?.toLowerCase() + ?: return sender.message(message), environment ) - val name = if (environment) selection.environment.name else selection.name - sender.message(localization["command-ratio-removed-successfully", environment.toInt(), name.capitalize()]) + sender.message( + localization["command-ratio-removed-successfully", environment.toInt(), selection.capitalize()] + ) } private fun list(sender: CommandSender) { diff --git a/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt b/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt index e7670ef..792eb37 100644 --- a/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt +++ b/src/main/kotlin/xyz/atrius/waystones/service/WorldRatioService.kt @@ -1,5 +1,6 @@ package xyz.atrius.waystones.service +import org.bukkit.Bukkit import org.bukkit.World import xyz.atrius.waystones.data.JsonFile @@ -10,16 +11,30 @@ object WorldRatioService : JsonFile("ratios"), Iterable Date: Wed, 25 Aug 2021 06:09:49 -0400 Subject: [PATCH 12/14] Add permission and command to readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e804efd..eab476c 100644 --- a/README.md +++ b/README.md @@ -59,8 +59,10 @@ Please note that this recipe is only used if **enable-key-items** is set to `tru ### Commands - **/waystones**: Provides info about the plugin -- **/waystones getkey [ count | player [count] ]***: Gives warpkeys to players +- **/waystones getkey [ count | player [count] ]**: Gives warpkeys to players +- **/waystones ratio [ set [name] [-environment] | remove [name] [-environment] | list ]**: Manages the plugin's ratios ### Permissions - **waystones.getkey.self** - Allows using the `getkey` command to give yourself a Warp Key - **waystones.getkey.all** - Allows using the `getkey` command to give any player a Warp Key +- **waystones.ratios** - Allows use of the `ratio` command to manage teleport ratios \ No newline at end of file From c8a902331949dd83b3d6a849d1968457b5338692 Mon Sep 17 00:00:00 2001 From: Atrius Date: Mon, 30 Aug 2021 21:07:52 -0400 Subject: [PATCH 13/14] Add failure message if item wasn't successfully added to the ratio config --- .../atrius/waystones/commands/RatioCommand.kt | 24 +++++++++++-------- src/main/resources/locale-en.yml | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt b/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt index b0112c8..20e1178 100644 --- a/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt +++ b/src/main/kotlin/xyz/atrius/waystones/commands/RatioCommand.kt @@ -9,8 +9,6 @@ import xyz.atrius.waystones.service.WorldRatioService import xyz.atrius.waystones.utility.message import xyz.atrius.waystones.utility.toInt - -// /waystones ratio [ set [name] [-environment] | remove [name] [-environment] | list ] object RatioCommand : SimpleCommand("ratio", "ra", "r") { override fun execute(sender: CommandSender, args: Array, flags: Flags) { @@ -31,13 +29,13 @@ object RatioCommand : SimpleCommand("ratio", "ra", "r") { private fun set(sender: CommandSender, args: Array, world: World?, environment: Boolean) { if (args.size < 2) return sender.message(localization["command-no-arguments"]) - val selection = args.getOrNull(2) - ?: if (environment) world?.environment?.name else world?.name + val selection = (args.getOrNull(2) + ?: if (environment) world?.environment?.name else world?.name)?.capitalize() val message = if (args.size > 2) localization["command-ratio-world-not-found", environment.toInt(), args[2]] else localization["command-ratio-bad-sender"] - WorldRatioService.add( + val added = WorldRatioService.add( selection?.toLowerCase() ?: return sender.message(message), environment, @@ -45,26 +43,32 @@ object RatioCommand : SimpleCommand("ratio", "ra", "r") { ?: return sender.message(localization["command-ratio-bad-ratio", args[1]]) ) sender.message( - localization["command-ratio-added-successfully", environment.toInt(), selection.capitalize(), args[1]] + if (added) + localization["command-ratio-added-successfully", environment.toInt(), selection, args[1]] + else + localization["command-ratio-addition-failed", selection] ) } private fun remove(sender: CommandSender, args: Array, world: World?, environment: Boolean) { if (args.size < 2 && sender is ConsoleCommandSender) return sender.message(localization["command-no-arguments"]) - val selection = args.getOrNull(1) - ?: if (environment) world?.environment?.name else world?.name + val selection = (args.getOrNull(1) + ?: if (environment) world?.environment?.name else world?.name)?.capitalize() val message = if (args.size > 1) localization["command-ratio-world-not-found", environment.toInt(), args[1]] else localization["command-ratio-bad-sender"] - WorldRatioService.remove( + val added = WorldRatioService.remove( selection?.toLowerCase() ?: return sender.message(message), environment ) sender.message( - localization["command-ratio-removed-successfully", environment.toInt(), selection.capitalize()] + if (added) + localization["command-ratio-removed-successfully", environment.toInt(), selection] + else + localization["command-ratio-removal-failed", selection] ) } diff --git a/src/main/resources/locale-en.yml b/src/main/resources/locale-en.yml index abca3f9..bcab2b3 100644 --- a/src/main/resources/locale-en.yml +++ b/src/main/resources/locale-en.yml @@ -9,7 +9,9 @@ command-no-arguments: "&7[&dWaystones&7] &cNo arguments were provided for the su command-ratio-bad-sender: "&7[&dWaystones&7] &cConsole users must supply a world or environment to use this command." command-ratio-world-not-found: "&7[&dWaystones&7] &cThe {0,choice,0#world|1#environment} {1} could not be found." command-ratio-added-successfully: "&7[&dWaystones&7] &aThe {0,choice,0#world|1#environment} {1} was added successfully!" +command-ratio-addition-failed: "&7[&dWaystones&7] &cFailed to add {0} to the config." command-ratio-removed-successfully: '&7[&dWaystones&7] &aThe {0,choice,0#world|1#environment} {1} was successfully removed!' +command-ratio-removal-failed: "&7[&dWaystones&7] &cFailed to remove {0} from the config." command-ratio-no-ratios: "&7[&dWaystones&7] &bNo ratios currently set!" waystone-info: "&3&lName: {0} | {1}" waystone-status: "Status: {0}{1,choice,-2#|-1#' | Range: {1,choice,-1#Infinity|0#{1}}'}" From b041b38a24ffbd1ffb80807f79b1e7c1bb4ca829 Mon Sep 17 00:00:00 2001 From: Atrius Date: Fri, 3 Sep 2021 18:58:57 -0400 Subject: [PATCH 14/14] Update english locale and add defaults for chinese locale --- src/main/resources/locale-cn.yml | 15 ++++++++------- src/main/resources/locale-en.yml | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/resources/locale-cn.yml b/src/main/resources/locale-cn.yml index b787e17..fe2b919 100644 --- a/src/main/resources/locale-cn.yml +++ b/src/main/resources/locale-cn.yml @@ -4,13 +4,14 @@ command-config-set: "&7[&d传送石&7] &b成功设置 &e{0} &b为 &a{1}!" command-config-set-fail: "&7[&d传送石&7] &c修改设置 {0} 失败." command-give-key: "&7[&d传送石&7]&f 给予 &b{0}个&r 传送石钥匙 给玩家 &a{1}&r" command-reload: "&7[&d传送石&7] &a配置文件已重载!" -command-ratio-invalid-command: "" -command-no-arguments: "" -command-ratio-bad-sender: "" -command-ratio-world-not-found: "" -command-ratio-added-successfully: "" -command-ratio-removed-successfully: "" -command-ratio-no-ratios: "" +command-ratio-bad-sender: "&7[&dWaystones&7] &cConsole users must supply a world or environment to use this command." +command-ratio-world-not-found: "&7[&dWaystones&7] &cThe {0,choice,0#world|1#environment} {1} could not be found." +command-ratio-added-successfully: "&7[&dWaystones&7] &aThe {0,choice,0#world|1#environment} {1} was successfully set!" +command-ratio-addition-failed: "&7[&dWaystones&7] &cFailed to add {0} to the config." +command-ratio-removed-successfully: '&7[&dWaystones&7] &aThe {0,choice,0#world|1#environment} {1} was successfully removed!' +command-ratio-removal-failed: "&7[&dWaystones&7] &cFailed to remove {0} from the config." +command-ratio-no-ratios: "&7[&dWaystones&7] &bNo ratios currently set!" +command-ratio-bad-ratio: "&7[&dWaystones&7] &cImproper ratio provided: {0}" waystone-info: "&3&l名称: {0} | {1}" waystone-status: "状态: {0}{1,choice,-2#|-1#' | 距离: {1,choice,-1#无限|0#{1}}'}" waystone-status-active: "激活" diff --git a/src/main/resources/locale-en.yml b/src/main/resources/locale-en.yml index bcab2b3..ca5898b 100644 --- a/src/main/resources/locale-en.yml +++ b/src/main/resources/locale-en.yml @@ -8,11 +8,12 @@ command-ratio-invalid-command: "&7[&dWaystones&7] &cInvalid subcommand: {0}" command-no-arguments: "&7[&dWaystones&7] &cNo arguments were provided for the subcommand." command-ratio-bad-sender: "&7[&dWaystones&7] &cConsole users must supply a world or environment to use this command." command-ratio-world-not-found: "&7[&dWaystones&7] &cThe {0,choice,0#world|1#environment} {1} could not be found." -command-ratio-added-successfully: "&7[&dWaystones&7] &aThe {0,choice,0#world|1#environment} {1} was added successfully!" +command-ratio-added-successfully: "&7[&dWaystones&7] &aThe {0,choice,0#world|1#environment} {1} was successfully set!" command-ratio-addition-failed: "&7[&dWaystones&7] &cFailed to add {0} to the config." command-ratio-removed-successfully: '&7[&dWaystones&7] &aThe {0,choice,0#world|1#environment} {1} was successfully removed!' command-ratio-removal-failed: "&7[&dWaystones&7] &cFailed to remove {0} from the config." command-ratio-no-ratios: "&7[&dWaystones&7] &bNo ratios currently set!" +command-ratio-bad-ratio: "&7[&dWaystones&7] &cImproper ratio provided: {0}" waystone-info: "&3&lName: {0} | {1}" waystone-status: "Status: {0}{1,choice,-2#|-1#' | Range: {1,choice,-1#Infinity|0#{1}}'}" waystone-status-active: "Active"