Validate command names on Bukkit and Nukkit

This commit is contained in:
Minecrell 2018-07-24 15:42:22 +02:00
parent c7169d6ad0
commit 6ef1128cd8
2 changed files with 14 additions and 0 deletions

View File

@ -53,6 +53,13 @@ class BukkitPlugin : PlatformPlugin<BukkitPluginDescription>("Bukkit", "plugin.y
val main = description.main ?: throw InvalidPluginDescriptionException("Main class is not defined")
if (main.isEmpty()) throw InvalidPluginDescriptionException("Main class cannot be empty")
if (main.startsWith("org.bukkit.")) throw InvalidPluginDescriptionException("Main may not be within the org.bukkit namespace")
for (command in description.commands) {
if (command.name.contains(':')) throw InvalidPluginDescriptionException("Command '${command.name}' cannot contain ':'")
command.aliases?.forEach { alias ->
if (alias.contains(':')) throw InvalidPluginDescriptionException("Alias '$alias' of '${command.name}' cannot contain ':'")
}
}
}
}

View File

@ -48,6 +48,13 @@ class NukkitPlugin : PlatformPlugin<NukkitPluginDescription>("Nukkit", "nukkit.y
if (main.startsWith("cn.nukkit.")) throw InvalidPluginDescriptionException("Main class cannot be within cn.nukkit. package")
if (description.api?.isEmpty() != false) throw InvalidPluginDescriptionException("Nukkit API version is not set")
for (command in description.commands) {
if (command.name.contains(':')) throw InvalidPluginDescriptionException("Command '${command.name}' cannot contain ':'")
command.aliases?.forEach { alias ->
if (alias.contains(':')) throw InvalidPluginDescriptionException("Alias '$alias' of '${command.name}' cannot contain ':'")
}
}
}
}