Compare commits

..

4 Commits

Author SHA1 Message Date
Auxilor
52c1b52f6d Fixed tab completion bug 2024-07-12 18:18:40 +01:00
Auxilor
f321296227 Updated to 6.71.5 2024-07-12 18:08:35 +01:00
Auxilor
ddd12db420 Fixed ExtendedPersistentDataContainerFactory 2024-07-12 18:07:53 +01:00
Auxilor
bd09791b5b Improved command tab-completion 2024-07-08 18:49:29 +01:00
3 changed files with 22 additions and 6 deletions

View File

@@ -126,14 +126,19 @@ abstract class HandledCommand(
* @return The tab completion results. * @return The tab completion results.
*/ */
private fun CommandBase.handleTabComplete(sender: CommandSender, args: List<String>): List<String> { private fun CommandBase.handleTabComplete(sender: CommandSender, args: List<String>): List<String> {
if (!sender.hasPermission(permission)) return emptyList() if (!sender.hasPermission(permission)) {
return emptyList()
}
if (args.size == 1) { if (args.size == 1) {
val completions = subcommands.filter { sender.hasPermission(it.permission) }.map { it.name } val completions = mutableListOf<String>()
val list = mutableListOf<String>() StringUtil.copyPartialMatches(
args[0],
subcommands.filter { sender.hasPermission(it.permission) }.map { it.name },
completions
)
StringUtil.copyPartialMatches(args[0], completions, list)
if (completions.isNotEmpty()) { if (completions.isNotEmpty()) {
return completions return completions
} }
@@ -156,9 +161,11 @@ abstract class HandledCommand(
} }
val completions = tabComplete(sender, args).toMutableList() val completions = tabComplete(sender, args).toMutableList()
if (sender is Player) { if (sender is Player) {
completions.addAll(tabComplete(sender, args)) completions.addAll(tabComplete(sender, args))
} }
return completions.sorted() return completions.sorted()
} }
} }

View File

@@ -10,6 +10,7 @@ import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataContainer import org.bukkit.persistence.PersistentDataContainer
import org.bukkit.persistence.PersistentDataType import org.bukkit.persistence.PersistentDataType
import java.lang.reflect.Field
class ExtendedPersistentDataContainerFactory : ExtendedPersistentDataContainerFactoryProxy { class ExtendedPersistentDataContainerFactory : ExtendedPersistentDataContainerFactoryProxy {
private val registry: CraftPersistentDataTypeRegistry private val registry: CraftPersistentDataTypeRegistry
@@ -21,7 +22,15 @@ class ExtendedPersistentDataContainerFactory : ExtendedPersistentDataContainerFa
*/ */
val item = CraftItemStack.asCraftCopy(ItemStack(Material.STONE)) val item = CraftItemStack.asCraftCopy(ItemStack(Material.STONE))
val pdc = item.itemMeta!!.persistentDataContainer val pdc = item.itemMeta!!.persistentDataContainer
this.registry = CraftPersistentDataContainer::class.java.getDeclaredField("registry")
// Cross-version compatibility:
val registryField: Field = try {
CraftPersistentDataContainer::class.java.getDeclaredField("registry")
} catch (e: NoSuchFieldException) {
CraftPersistentDataContainer::class.java.superclass.getDeclaredField("registry")
}
this.registry = registryField
.apply { isAccessible = true }.get(pdc) as CraftPersistentDataTypeRegistry .apply { isAccessible = true }.get(pdc) as CraftPersistentDataTypeRegistry
} }

View File

@@ -1,2 +1,2 @@
version = 6.71.4 version = 6.71.5
kotlin.incremental.useClasspathSnapshot=false kotlin.incremental.useClasspathSnapshot=false