1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package io.dico.parcels2.command
import io.dico.dicore.command.CommandBuilder
import io.dico.dicore.command.Validate
import io.dico.dicore.command.annotation.Cmd
import io.dico.dicore.command.annotation.Desc
import io.dico.dicore.command.annotation.RequireParameters
import io.dico.parcels2.Parcel
import io.dico.parcels2.ParcelsPlugin
import org.bukkit.entity.Player
import kotlin.reflect.KMutableProperty
class CommandsParcelOptions(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
@Cmd("inputs")
@Desc("Sets whether players who are not allowed to",
"build here can use levers, buttons,",
"pressure plates, tripwire or redstone ore",
shortVersion = "allows using inputs")
@RequireParameters(0)
fun ParcelScope.cmdInputs(player: Player, enabled: Boolean?): Any? {
return runOptionCommand(player, Parcel::allowInteractInputs, enabled, "using levers, buttons, etc.")
}
@Cmd("inventory")
@Desc("Sets whether players who are not allowed to",
"build here can interact with inventories",
shortVersion = "allows editing inventories")
@RequireParameters(0)
fun ParcelScope.cmdInventory(player: Player, enabled: Boolean?): Any? {
return runOptionCommand(player, Parcel::allowInteractInventory, enabled, "interaction with inventories")
}
private inline val Boolean.enabledWord get() = if (this) "enabled" else "disabled"
private fun ParcelScope.runOptionCommand(player: Player,
property: KMutableProperty<Boolean>,
enabled: Boolean?,
desc: String): Any? {
checkConnected("have their options changed")
val current = property.getter.call(parcel)
if (enabled == null) {
val word = if (current) "" else "not "
return "This parcel does ${word}allow $desc"
}
checkCanManage(player, "change its options")
Validate.isTrue(current != enabled, "That option was already ${enabled.enabledWord}")
property.setter.call(parcel, enabled)
return "That option is now ${enabled.enabledWord}"
}
companion object {
private const val descShort = "changes interaction options for this parcel"
private val desc = arrayOf("Sets whether players who are not allowed to", "build here can interact with certain things.")
fun setGroupDescription(builder: CommandBuilder) {
builder.setGroupDescription(descShort, *desc)
}
}
}
|