-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathVersionWrapper.java
More file actions
159 lines (137 loc) · 5.03 KB
/
VersionWrapper.java
File metadata and controls
159 lines (137 loc) · 5.03 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package net.wesjd.anvilgui.version;
import java.util.function.Function;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
* Wraps versions to be able to easily use different NMS server versions
*
* @author Wesley Smith
* @since 1.0
*/
public interface VersionWrapper {
/**
* Gets the next available NMS container id for the player
*
* @param player The player to get the next container id of
* @param container The container that a new id is being generated for
* @return The next available NMS container id
*/
int getNextContainerId(Player player, AnvilContainerWrapper container);
/**
* Closes the current inventory for the player
*
* @param player The player that needs their current inventory closed
*/
void handleInventoryCloseEvent(Player player);
/**
* Sends PacketPlayOutOpenWindow to the player with the container id and window title
*
* @param player The player to send the packet to
* @param containerId The container id to open
* @param inventoryTitle The title of the inventory to be opened (only works in Minecraft 1.14 and above)
*/
void sendPacketOpenWindow(Player player, int containerId, Object inventoryTitle);
/**
* Sends PacketPlayOutCloseWindow to the player with the container id
*
* @param player The player to send the packet to
* @param containerId The container id to close
*/
void sendPacketCloseWindow(Player player, int containerId);
/**
* Sends PacketPlayOutExperience to the player with the experience level
*
* @param player The player to send the packet to
* @param experienceLevel The experience level to set
*/
void sendPacketExperienceChange(Player player, int experienceLevel);
/**
* Sets the NMS player's active container to the default one
*
* @param player The player to set the active container of
*/
void setActiveContainerDefault(Player player);
/**
* Sets the NMS player's active container to the one supplied
*
* @param player The player to set the active container of
* @param container The container to set as active
*/
void setActiveContainer(Player player, AnvilContainerWrapper container);
/**
* Sets the supplied windowId of the supplied Container
*
* @param container The container to set the windowId of
* @param containerId The new windowId
*/
void setActiveContainerId(AnvilContainerWrapper container, int containerId);
/**
* Adds a slot listener to the supplied container for the player
*
* @param container The container to add the slot listener to
* @param player The player to have as a listener
*/
void addActiveContainerSlotListener(AnvilContainerWrapper container, Player player);
/**
* Creates a new ContainerAnvil
*
* @param player The player to get the container of
* @param title The title of the anvil inventory
* @return The Container instance
*/
AnvilContainerWrapper newContainerAnvil(Player player, Object title);
/**
* Checks if the current Minecraft version actually supports custom titles
*
* @return The current supported state
*/
default boolean isCustomTitleSupported() {
return true;
}
/**
* Creates a new chat component that does not handle the content in any special way
*
* @param content The content to display
* @return Version-specific ChatComponent instance
*/
Object literalChatComponent(String content);
/**
* Creates a new rich chat component from the provided json
*
* @param json The component to parse
* @return Version-specific ChatComponent instance
*/
Object jsonChatComponent(String json);
/**
* Interface implemented by the custom NMS AnvilContainer used to interact with it directly
*/
interface AnvilContainerWrapper {
/**
* Retrieves the raw text that has been entered into the Anvil at the moment
* <br><br>
* This field is marked as public in the Minecraft AnvilContainer only from Minecraft 1.11 and upwards
*
* @return The raw text in the rename field
*/
default String getRenameText() {
return null;
}
/**
* Sets the provided text as the literal hovername of the item in the left input slot
*
* @param text The text to set
*/
default void setRenameText(String text) {}
default void setRenameVisitor(Function<String, ItemStack> renameVisitor) {}
default void setLeftItem(ItemStack item) {}
default void setMiddleItem(ItemStack item) {}
default void setRightItem(ItemStack item) {}
/**
* Gets the {@link Inventory} wrapper of the NMS container
*
* @return The inventory of the NMS container
*/
Inventory getBukkitInventory();
}
}