Skip to content

Commit d013f55

Browse files
Feature - Inventory Module (#193)
* Inventory module implementation * Add inventory to meta.json * Add callout * Fix commands format * Add glint & saturation example integration * Add unclickable to each item * Update inventory code example * Add inventory module overview * docs: Add disabled by default callout --------- Co-authored-by: TrentinTheKid <[email protected]>
1 parent 5bfef74 commit d013f55

File tree

14 files changed

+888
-0
lines changed

14 files changed

+888
-0
lines changed

bukkit-example/src/main/java/com/lunarclient/apollo/example/ApolloExamplePlugin.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@
5858
import com.lunarclient.apollo.example.common.commands.module.CombatCommand;
5959
import com.lunarclient.apollo.example.common.commands.module.CooldownCommand;
6060
import com.lunarclient.apollo.example.common.commands.module.EntityCommand;
61+
import com.lunarclient.apollo.example.common.commands.module.GlintCommand;
6162
import com.lunarclient.apollo.example.common.commands.module.GlowCommand;
6263
import com.lunarclient.apollo.example.common.commands.module.HologramCommand;
64+
import com.lunarclient.apollo.example.common.commands.module.InventoryCommand;
6365
import com.lunarclient.apollo.example.common.commands.module.LimbCommand;
6466
import com.lunarclient.apollo.example.common.commands.module.ModSettingsCommand;
6567
import com.lunarclient.apollo.example.common.commands.module.NametagCommand;
6668
import com.lunarclient.apollo.example.common.commands.module.NickHiderCommand;
6769
import com.lunarclient.apollo.example.common.commands.module.NotificationCommand;
6870
import com.lunarclient.apollo.example.common.commands.module.RichPresenceCommand;
71+
import com.lunarclient.apollo.example.common.commands.module.SaturationCommand;
6972
import com.lunarclient.apollo.example.common.commands.module.ServerRuleCommand;
7073
import com.lunarclient.apollo.example.common.commands.module.StaffModCommand;
7174
import com.lunarclient.apollo.example.common.commands.module.StopwatchCommand;
@@ -84,14 +87,17 @@
8487
import com.lunarclient.apollo.example.common.modules.impl.CombatExample;
8588
import com.lunarclient.apollo.example.common.modules.impl.CooldownExample;
8689
import com.lunarclient.apollo.example.common.modules.impl.EntityExample;
90+
import com.lunarclient.apollo.example.common.modules.impl.GlintExample;
8791
import com.lunarclient.apollo.example.common.modules.impl.GlowExample;
8892
import com.lunarclient.apollo.example.common.modules.impl.HologramExample;
93+
import com.lunarclient.apollo.example.common.modules.impl.InventoryExample;
8994
import com.lunarclient.apollo.example.common.modules.impl.LimbExample;
9095
import com.lunarclient.apollo.example.common.modules.impl.ModSettingsExample;
9196
import com.lunarclient.apollo.example.common.modules.impl.NametagExample;
9297
import com.lunarclient.apollo.example.common.modules.impl.NickHiderExample;
9398
import com.lunarclient.apollo.example.common.modules.impl.NotificationExample;
9499
import com.lunarclient.apollo.example.common.modules.impl.RichPresenceExample;
100+
import com.lunarclient.apollo.example.common.modules.impl.SaturationExample;
95101
import com.lunarclient.apollo.example.common.modules.impl.ServerRuleExample;
96102
import com.lunarclient.apollo.example.common.modules.impl.StaffModExample;
97103
import com.lunarclient.apollo.example.common.modules.impl.StopwatchExample;
@@ -177,14 +183,17 @@ public class ApolloExamplePlugin extends JavaPlugin {
177183
private CombatExample combatExample;
178184
private CooldownExample cooldownExample;
179185
private EntityExample entityExample;
186+
private GlintExample glintExample;
180187
private GlowExample glowExample;
181188
private HologramExample hologramExample;
189+
private InventoryExample inventoryExample;
182190
private LimbExample limbExample;
183191
private ModSettingsExample modSettingsExample;
184192
private NametagExample nametagExample;
185193
private NickHiderExample nickHiderExample;
186194
private NotificationExample notificationExample;
187195
private RichPresenceExample richPresenceExample;
196+
private SaturationExample saturationExample;
188197
private ServerRuleExample serverRuleExample;
189198
private StaffModExample staffModExample;
190199
private StopwatchExample stopwatchExample;
@@ -222,14 +231,17 @@ private void registerCommands() {
222231
this.getCommand("combat").setExecutor(new CombatCommand());
223232
this.getCommand("cooldown").setExecutor(new CooldownCommand());
224233
this.getCommand("entity").setExecutor(new EntityCommand());
234+
this.getCommand("glint").setExecutor(new GlintCommand());
225235
this.getCommand("glow").setExecutor(new GlowCommand());
226236
this.getCommand("hologram").setExecutor(new HologramCommand());
237+
this.getCommand("inventory").setExecutor(new InventoryCommand());
227238
this.getCommand("limb").setExecutor(new LimbCommand());
228239
this.getCommand("modsettings").setExecutor(new ModSettingsCommand());
229240
this.getCommand("nametag").setExecutor(new NametagCommand());
230241
this.getCommand("nickhider").setExecutor(new NickHiderCommand());
231242
this.getCommand("notification").setExecutor(new NotificationCommand());
232243
this.getCommand("richpresence").setExecutor(new RichPresenceCommand());
244+
this.getCommand("saturation").setExecutor(new SaturationCommand());
233245
this.getCommand("serverrule").setExecutor(new ServerRuleCommand());
234246
this.getCommand("staffmod").setExecutor(new StaffModCommand());
235247
this.getCommand("stopwatch").setExecutor(new StopwatchCommand());
@@ -267,6 +279,10 @@ public void changeImplementationType(ApolloExampleType type) {
267279
private void registerModuleExamples() {
268280
this.spamPacketDebug = new SpamPacketDebug();
269281

282+
this.glintExample = new GlintExample();
283+
this.inventoryExample = new InventoryExample();
284+
this.saturationExample = new SaturationExample();
285+
270286
switch (TYPE) {
271287
case API: {
272288
this.beamExample = new BeamApiExample();
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.common;
25+
26+
import net.minecraft.server.v1_8_R3.NBTTagCompound;
27+
import org.bukkit.Material;
28+
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
29+
import org.bukkit.inventory.ItemStack;
30+
import org.bukkit.inventory.meta.ItemMeta;
31+
32+
public final class ItemUtil {
33+
34+
public static ItemStack itemWithName(Material material, String name) {
35+
ItemStack item = new ItemStack(material);
36+
37+
ItemMeta itemMeta = item.getItemMeta();
38+
itemMeta.setDisplayName(name);
39+
40+
item.setItemMeta(itemMeta);
41+
return item;
42+
}
43+
44+
public static ItemStack addTag(ItemStack item, String key, Object value) {
45+
net.minecraft.server.v1_8_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
46+
NBTTagCompound tag = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
47+
48+
NBTTagCompound lunarTag = tag.getCompound("lunar");
49+
if (lunarTag == null) {
50+
lunarTag = new NBTTagCompound();
51+
}
52+
53+
if (value instanceof Integer) {
54+
lunarTag.setInt(key, (Integer) value);
55+
} else if (value instanceof Double) {
56+
lunarTag.setDouble(key, (Double) value);
57+
} else if (value instanceof Float) {
58+
lunarTag.setFloat(key, (Float) value);
59+
} else if (value instanceof Boolean) {
60+
lunarTag.setBoolean(key, (Boolean) value);
61+
} else if (value instanceof String) {
62+
lunarTag.setString(key, (String) value);
63+
}
64+
65+
tag.set("lunar", lunarTag);
66+
nmsItem.setTag(tag);
67+
68+
return CraftItemStack.asBukkitCopy(nmsItem);
69+
}
70+
71+
private ItemUtil() {
72+
}
73+
74+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.common.commands.module;
25+
26+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
27+
import com.lunarclient.apollo.example.common.modules.impl.GlintExample;
28+
import org.bukkit.command.Command;
29+
import org.bukkit.command.CommandExecutor;
30+
import org.bukkit.command.CommandSender;
31+
import org.bukkit.entity.Player;
32+
import org.jetbrains.annotations.NotNull;
33+
34+
public class GlintCommand implements CommandExecutor {
35+
36+
@Override
37+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
38+
if (!(sender instanceof Player)) {
39+
sender.sendMessage("Player only!");
40+
return true;
41+
}
42+
43+
Player player = (Player) sender;
44+
GlintExample glintExample = ApolloExamplePlugin.getPlugin().getGlintExample();
45+
46+
if (glintExample.glintModuleExample(player)) {
47+
player.sendMessage("Giving items...");
48+
} else {
49+
player.sendMessage("Displaying menu...");
50+
}
51+
52+
return true;
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.common.commands.module;
25+
26+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
27+
import com.lunarclient.apollo.example.common.modules.impl.InventoryExample;
28+
import org.bukkit.command.Command;
29+
import org.bukkit.command.CommandExecutor;
30+
import org.bukkit.command.CommandSender;
31+
import org.bukkit.entity.Player;
32+
import org.jetbrains.annotations.NotNull;
33+
34+
public class InventoryCommand implements CommandExecutor {
35+
36+
@Override
37+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
38+
if (!(sender instanceof Player)) {
39+
sender.sendMessage("Player only!");
40+
return true;
41+
}
42+
43+
Player player = (Player) sender;
44+
InventoryExample inventoryExample = ApolloExamplePlugin.getPlugin().getInventoryExample();
45+
46+
if (inventoryExample.inventoryModuleExample(player)) {
47+
player.sendMessage("Giving items...");
48+
} else {
49+
player.sendMessage("Displaying menu...");
50+
}
51+
52+
return true;
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.common.commands.module;
25+
26+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
27+
import com.lunarclient.apollo.example.common.modules.impl.SaturationExample;
28+
import org.bukkit.command.Command;
29+
import org.bukkit.command.CommandExecutor;
30+
import org.bukkit.command.CommandSender;
31+
import org.bukkit.entity.Player;
32+
import org.jetbrains.annotations.NotNull;
33+
34+
public class SaturationCommand implements CommandExecutor {
35+
36+
@Override
37+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
38+
if (!(sender instanceof Player)) {
39+
sender.sendMessage("Player only!");
40+
return true;
41+
}
42+
43+
Player player = (Player) sender;
44+
SaturationExample saturationExample = ApolloExamplePlugin.getPlugin().getSaturationExample();
45+
46+
if (saturationExample.saturationModuleExample(player)) {
47+
player.sendMessage("Giving items...");
48+
} else {
49+
player.sendMessage("Displaying menu...");
50+
}
51+
52+
return true;
53+
}
54+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.common.modules.impl;
25+
26+
import com.lunarclient.apollo.example.common.ItemUtil;
27+
import org.bukkit.Bukkit;
28+
import org.bukkit.Material;
29+
import org.bukkit.entity.Player;
30+
import org.bukkit.inventory.Inventory;
31+
import org.bukkit.inventory.ItemStack;
32+
33+
public class GlintExample extends NMSExample {
34+
35+
public boolean glintModuleExample(Player player) {
36+
if (this.isOneEight()) {
37+
this.glintModuleNMSExample(player);
38+
return false;
39+
} else {
40+
this.glintModuleCommandExample(player);
41+
return true;
42+
}
43+
}
44+
45+
public void glintModuleCommandExample(Player player) {
46+
player.performCommand("summon item ~ ~1 ~ {Item:{id:\"minecraft:diamond_helmet\",Count:1b,tag:{lunar:{glint:\"#FF5733\"}}}}");
47+
player.performCommand("summon item ~ ~1 ~ {Item:{id:\"minecraft:diamond_helmet\",Count:1b,tag:{lunar:{glint:\"#33FF57\"}}}}");
48+
player.performCommand("summon item ~ ~1 ~ {Item:{id:\"minecraft:diamond_helmet\",Count:1b,tag:{lunar:{glint:\"#3357FF\"}}}}");
49+
player.performCommand("summon item ~ ~1 ~ {Item:{id:\"minecraft:diamond_helmet\",Count:1b,tag:{lunar:{glint:\"#FFD700\"}}}}");
50+
player.performCommand("summon item ~ ~1 ~ {Item:{id:\"minecraft:diamond_helmet\",Count:1b,tag:{lunar:{glint:\"-16711936\"}}}}");
51+
}
52+
53+
public void glintModuleNMSExample(Player player) {
54+
Inventory inventory = Bukkit.createInventory(player, 5 * 9);
55+
56+
inventory.setItem(11, ItemUtil.addTag(new ItemStack(Material.DIAMOND_HELMET), "glint", "#FF5733"));
57+
inventory.setItem(14, ItemUtil.addTag(new ItemStack(Material.DIAMOND_HELMET), "glint", "#33FF57"));
58+
inventory.setItem(17, ItemUtil.addTag(new ItemStack(Material.DIAMOND_HELMET), "glint", "#3357FF"));
59+
inventory.setItem(29, ItemUtil.addTag(new ItemStack(Material.DIAMOND_HELMET), "glint", "#FFD700"));
60+
inventory.setItem(33, ItemUtil.addTag(new ItemStack(Material.DIAMOND_HELMET), "glint", -16711936));
61+
62+
player.openInventory(inventory);
63+
}
64+
65+
}

0 commit comments

Comments
 (0)