/
GiveCommand.kt
61 lines (51 loc) · 2 KB
/
GiveCommand.kt
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
61
/*
* LiquidBounce Hacked Client
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
* https://github.com/CCBlueX/LiquidBounce/
*/
package net.ccbluex.liquidbounce.features.command.commands
import net.ccbluex.liquidbounce.features.command.Command
import net.ccbluex.liquidbounce.utils.PacketUtils.sendPacket
import net.ccbluex.liquidbounce.utils.inventory.ItemUtils
import net.ccbluex.liquidbounce.utils.misc.StringUtils
import net.minecraft.item.Item
import net.minecraft.network.play.client.C10PacketCreativeInventoryAction
class GiveCommand : Command("give", "item", "i", "get") {
/**
* Execute commands with provided [args]
*/
override fun execute(args: Array<String>) {
val thePlayer = mc.thePlayer ?: return
if (mc.playerController.isNotCreative) {
chat("§c§lError: §3You need to be in creative mode.")
return
}
if (args.size > 1) {
val itemStack = ItemUtils.createItem(StringUtils.toCompleteString(args, 1))
if (itemStack == null) {
chatSyntaxError()
return
}
val emptySlot = thePlayer.inventory.firstEmptyStack
if (emptySlot != -1) {
sendPacket(C10PacketCreativeInventoryAction(emptySlot, itemStack))
chat("§7Given [§8${itemStack.displayName}§7] * §8${itemStack.stackSize}§7 to §8${mc.session.username}§7.")
} else
chat("Your inventory is full.")
return
}
chatSyntax("give <item> [amount] [data] [datatag]")
}
override fun tabComplete(args: Array<String>): List<String> {
if (args.isEmpty())
return emptyList()
return when (args.size) {
1 -> {
return Item.itemRegistry.keys
.map { it.resourcePath.lowercase() }
.filter { it.startsWith(args[0], true) }
}
else -> emptyList()
}
}
}