From ca2f88e60de3fde633374cf897e704e34536b142 Mon Sep 17 00:00:00 2001 From: copyandexecute <58366920+copyandexecute@users.noreply.github.com> Date: Fri, 27 Aug 2021 19:20:25 +0200 Subject: [PATCH 1/6] Simple Extensions maybe rename dispatchCommand to something shorter --- .../kspigot/extensions/bukkit/ConsoleSenderExtensions.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt index 8bdd0b5d..5ab65bf0 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt @@ -2,6 +2,7 @@ package net.axay.kspigot.extensions.bukkit import net.axay.kspigot.main.PluginInstance import net.md_5.bungee.api.ChatColor +import org.bukkit.Bukkit import org.bukkit.command.CommandSender import org.bukkit.plugin.Plugin @@ -30,3 +31,9 @@ fun CommandSender.error(text: String, plugin: Plugin? = PluginInstance) = */ fun CommandSender.printColoredPrefix(text: String, textColor: ChatColor, prefix: String, prefixColor: ChatColor) = sendMessage("${prefixColor}[${prefix}]${textColor} $text") + +/** + * Dispatches a command sent by Console + */ +fun dispatchCommand(commandLine: String) = Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandLine) + From d9da143f7b89a99f0975fec30d42198910b1b855 Mon Sep 17 00:00:00 2001 From: copyandexecute <58366920+copyandexecute@users.noreply.github.com> Date: Fri, 27 Aug 2021 19:26:41 +0200 Subject: [PATCH 2/6] Used "KSpigot" console instance --- .../axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt index 5ab65bf0..d6a48e8d 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt @@ -1,5 +1,6 @@ package net.axay.kspigot.extensions.bukkit +import net.axay.kspigot.extensions.console import net.axay.kspigot.main.PluginInstance import net.md_5.bungee.api.ChatColor import org.bukkit.Bukkit @@ -35,5 +36,5 @@ fun CommandSender.printColoredPrefix(text: String, textColor: ChatColor, prefix: /** * Dispatches a command sent by Console */ -fun dispatchCommand(commandLine: String) = Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandLine) +fun dispatchCommand(commandLine: String) = Bukkit.dispatchCommand(console, commandLine) From 424945d562c8449d9e679016673208a6e92e4a56 Mon Sep 17 00:00:00 2001 From: copyandexecute <58366920+copyandexecute@users.noreply.github.com> Date: Fri, 27 Aug 2021 19:27:14 +0200 Subject: [PATCH 3/6] Added method to print location in a more readable way --- .../net/axay/kspigot/extensions/geometry/KSpigotLocations.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt b/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt index 6c0d362e..46241393 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt @@ -40,3 +40,5 @@ fun SimpleLocation3D.withWorld(world: World) = Location(world, x, y, z).apply { fun SimpleChunkLocation.withWorld(world: World) = world.getChunkAt(x, z) fun Vector.toSimpleLoc() = SimpleLocation3D(x, y, z) fun SimpleLocation3D.toVector() = Vector(x, y, z) +fun Location.printSimple(): String = "[$x, $y, $z]" + From 87e1b836da03d67d68573b186f54383ba450213c Mon Sep 17 00:00:00 2001 From: copyandexecute <58366920+copyandexecute@users.noreply.github.com> Date: Fri, 27 Aug 2021 19:28:42 +0200 Subject: [PATCH 4/6] Shortcut for getting all worlds --- .../net/axay/kspigot/extensions/GeneralExtensions.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt index 592764fe..8d38b1d9 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt @@ -3,6 +3,7 @@ package net.axay.kspigot.extensions import net.axay.kspigot.main.PluginInstance import org.bukkit.Bukkit import org.bukkit.NamespacedKey +import org.bukkit.World import org.bukkit.command.CommandSender import org.bukkit.entity.Player @@ -47,3 +48,9 @@ val console get() = Bukkit.getConsoleSender() * Shortcut for creating a new [NamespacedKey] */ fun pluginKey(key: String) = NamespacedKey(PluginInstance, key) + +/** + * Shortcut to get a collection of all worlds + */ +val worlds: Collection get() = Bukkit.getWorlds() + From d8d2d7ae88ef84f8d2c139f5e642d0ef349a5b19 Mon Sep 17 00:00:00 2001 From: copyandexecute <58366920+copyandexecute@users.noreply.github.com> Date: Fri, 27 Aug 2021 19:34:47 +0200 Subject: [PATCH 5/6] Added isOnMaterial(material: Material) extension --- .../net/axay/kspigot/extensions/bukkit/EntityExtensions.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt index c9fa3221..bac89dc2 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt @@ -29,6 +29,12 @@ val Entity.isFeetInWater: Boolean get() = this.location.block.type == Material.W */ val Entity.isGroundSolid: Boolean get() = this.location.add(0.0, -0.01, 0.0).block.type.isSolid +/** + * Checks if the entity stands on a specific material. + * @param material the material you are looking for + */ +fun Entity.isOnMaterial(material: Material): Boolean = location.block.type == material + /** * Kills the damageable. */ From 044129caaec1ff3ab8b482846e933dda43e4fa17 Mon Sep 17 00:00:00 2001 From: Jakob K Date: Fri, 27 Aug 2021 20:17:47 +0200 Subject: [PATCH 6/6] Improve proposed extensions --- .../net/axay/kspigot/extensions/GeneralExtensions.kt | 3 +-- .../kspigot/extensions/bukkit/ConsoleSenderExtensions.kt | 9 +++++---- .../axay/kspigot/extensions/bukkit/EntityExtensions.kt | 5 ++--- .../axay/kspigot/extensions/geometry/KSpigotLocations.kt | 5 ++++- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt index 8d38b1d9..27b61599 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt @@ -52,5 +52,4 @@ fun pluginKey(key: String) = NamespacedKey(PluginInstance, key) /** * Shortcut to get a collection of all worlds */ -val worlds: Collection get() = Bukkit.getWorlds() - +val worlds: List get() = Bukkit.getWorlds() diff --git a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt index d6a48e8d..8732d561 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt @@ -1,6 +1,5 @@ package net.axay.kspigot.extensions.bukkit -import net.axay.kspigot.extensions.console import net.axay.kspigot.main.PluginInstance import net.md_5.bungee.api.ChatColor import org.bukkit.Bukkit @@ -34,7 +33,9 @@ fun CommandSender.printColoredPrefix(text: String, textColor: ChatColor, prefix: sendMessage("${prefixColor}[${prefix}]${textColor} $text") /** - * Dispatches a command sent by Console + * Dispatches the command given by [commandLine]. + * + * @param commandLine the command without a leading / */ -fun dispatchCommand(commandLine: String) = Bukkit.dispatchCommand(console, commandLine) - +fun CommandSender.dispatchCommand(commandLine: String) = + Bukkit.dispatchCommand(this, commandLine) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt index bac89dc2..08a1e73b 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt @@ -30,10 +30,9 @@ val Entity.isFeetInWater: Boolean get() = this.location.block.type == Material.W val Entity.isGroundSolid: Boolean get() = this.location.add(0.0, -0.01, 0.0).block.type.isSolid /** - * Checks if the entity stands on a specific material. - * @param material the material you are looking for + * Returns the material that is present under the feet of this entity. */ -fun Entity.isOnMaterial(material: Material): Boolean = location.block.type == material +val Entity.groundMaterial get() = this.location.add(0.0, -0.01, 0.0).block.type /** * Kills the damageable. diff --git a/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt b/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt index 46241393..dd413096 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt @@ -40,5 +40,8 @@ fun SimpleLocation3D.withWorld(world: World) = Location(world, x, y, z).apply { fun SimpleChunkLocation.withWorld(world: World) = world.getChunkAt(x, z) fun Vector.toSimpleLoc() = SimpleLocation3D(x, y, z) fun SimpleLocation3D.toVector() = Vector(x, y, z) -fun Location.printSimple(): String = "[$x, $y, $z]" +/** + * Returns a simple string in the format of `[x, y, z]`. + */ +fun Location.toSimpleString() = "[$x, $y, $z]"