Skip to content
This repository was archived by the owner on Nov 10, 2021. It is now read-only.

Commit 55be09b

Browse files
committed
Merge branch 'feature/inventory' into develop
2 parents 8891d18 + 8755d57 commit 55be09b

File tree

6 files changed

+478
-17
lines changed

6 files changed

+478
-17
lines changed

src/main/java/com/froxynetwork/froxyapi/API.java

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
import java.util.List;
55

66
import org.bukkit.Server;
7+
import org.bukkit.entity.Player;
78
import org.bukkit.plugin.java.JavaPlugin;
89
import org.slf4j.Logger;
910

1011
import com.froxynetwork.froxyapi.command.Command;
1112
import com.froxynetwork.froxyapi.command.CommandManager;
13+
import com.froxynetwork.froxyapi.inventory.Inventory;
14+
import com.froxynetwork.froxyapi.inventory.InventoryManager;
15+
import com.froxynetwork.froxyapi.inventory.InventoryProvider;
1216
import com.froxynetwork.froxyapi.language.LanguageManager;
1317
import com.froxynetwork.froxyapi.language.Languages;
1418

@@ -86,7 +90,8 @@ public default Languages getDefaultLanguage() {
8690
* Files name MUST be of this form: "{name}.lang".<br />
8791
* Example: <code>fr_FR.lang or en_US.lang</code>
8892
*
89-
* @param path The directory
93+
* @param path
94+
* The directory
9095
*/
9196
public default void register(File path) {
9297
getLanguageManager().register(path);
@@ -96,21 +101,29 @@ public default void register(File path) {
96101
* Get the default translate of specific message id.<br />
97102
* Same as <code>$(id, getDefaultLanguage(), params)</code>
98103
*
99-
* @param id The id of the message
100-
* @param params The parameters
101-
* @return The message translated by default language, or the id if message id doesn't exist
104+
* @param id
105+
* The id of the message
106+
* @param params
107+
* The parameters
108+
* @return The message translated by default language, or the id if message id
109+
* doesn't exist
102110
*/
103111
public default String $(String id, String... params) {
104112
return getLanguageManager().$(id, params);
105113
}
106114

107115
/**
108-
* Get the translation of specific message id with specific language. If message id not found, return the translation with DEFAULT language
116+
* Get the translation of specific message id with specific language. If message
117+
* id not found, return the translation with DEFAULT language
109118
*
110-
* @param id The id of the message
111-
* @param lang The specific language
112-
* @param params The parameters
113-
* @return The message translated by specific language, or the message translated by default language, or the id if message id doesn't exist
119+
* @param id
120+
* The id of the message
121+
* @param lang
122+
* The specific language
123+
* @param params
124+
* The parameters
125+
* @return The message translated by specific language, or the message
126+
* translated by default language, or the id if message id doesn't exist
114127
*/
115128
public default String $(String id, Languages lang, String... params) {
116129
return getLanguageManager().$(id, lang, params);
@@ -119,22 +132,25 @@ public default void register(File path) {
119132
/**
120133
* Get the translate of specific id with specific language
121134
*
122-
* @param id The id of the message
123-
* @param lang The specific language
124-
* @param params The parameters
125-
* @return The message translated by specific language, or the id if message id doesn't exist
135+
* @param id
136+
* The id of the message
137+
* @param lang
138+
* The specific language
139+
* @param params
140+
* The parameters
141+
* @return The message translated by specific language, or the id if message id
142+
* doesn't exist
126143
*/
127144
public default String $_(String id, Languages lang, String... params) {
128145
return getLanguageManager().$_(id, lang, params);
129146
}
130-
131147

132148
// -----------------------------------------
133149
// | |
134150
// | Command Manager |
135151
// | |
136152
// -----------------------------------------
137-
153+
138154
/**
139155
* @return The CommandManager
140156
*/
@@ -169,8 +185,55 @@ public default List<Command> getCommands() {
169185

170186
// -----------------------------------------
171187
// | |
172-
// | Other |
188+
// | Inventory Manager |
173189
// | |
174190
// -----------------------------------------
175191

192+
/**
193+
* @return The InventoryManager
194+
*/
195+
public InventoryManager getInventoryManager();
196+
197+
/**
198+
* Create an Inventory and open it
199+
*
200+
* @param provider
201+
* The provider
202+
* @param player
203+
* The player
204+
* @return An inventory
205+
*/
206+
public default Inventory openInventory(InventoryProvider provider, Player player) {
207+
return getInventoryManager().openInventory(provider, player);
208+
}
209+
210+
/**
211+
* @param p
212+
* Player to check
213+
*
214+
* @return true if specific Player has an opened inventory
215+
*/
216+
public default boolean hasInventoryOpened(Player p) {
217+
return getInventoryManager().hasInventoryOpened(p);
218+
}
219+
220+
/**
221+
* @param p
222+
* Specific player
223+
* @return The inventory of specific Player. Null if not opened
224+
*/
225+
public default Inventory getInventory(Player p) {
226+
return getInventoryManager().getInventory(p);
227+
}
228+
229+
/**
230+
* Close player's inventory.<br />
231+
* Same as <code>p.closeInventory();</code>
232+
*
233+
* @param p
234+
* The player
235+
*/
236+
public default void closeInventory(Player p) {
237+
getInventoryManager().closeInventory(p);
238+
}
176239
}

src/main/java/com/froxynetwork/froxyapi/Froxy.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
import java.io.File;
44
import java.util.List;
55

6+
import org.bukkit.entity.Player;
67
import org.bukkit.plugin.java.JavaPlugin;
78
import org.slf4j.Logger;
89

910
import com.froxynetwork.froxyapi.command.Command;
1011
import com.froxynetwork.froxyapi.command.CommandManager;
12+
import com.froxynetwork.froxyapi.inventory.Inventory;
13+
import com.froxynetwork.froxyapi.inventory.InventoryManager;
14+
import com.froxynetwork.froxyapi.inventory.InventoryProvider;
1115
import com.froxynetwork.froxyapi.language.LanguageManager;
1216
import com.froxynetwork.froxyapi.language.Languages;
1317

@@ -208,7 +212,57 @@ public static List<Command> getCommands() {
208212

209213
// -----------------------------------------
210214
// | |
211-
// | Other |
215+
// | Inventory Manager |
212216
// | |
213217
// -----------------------------------------
218+
219+
/**
220+
* @return The InventoryManager
221+
*/
222+
public static InventoryManager getInventoryManager() {
223+
return api.getInventoryManager();
224+
}
225+
226+
/**
227+
* Create an Inventory and open it
228+
*
229+
* @param provider
230+
* The provider
231+
* @param player
232+
* The player
233+
* @return An inventory
234+
*/
235+
public static Inventory openInventory(InventoryProvider provider, Player player) {
236+
return api.openInventory(provider, player);
237+
}
238+
239+
/**
240+
* @param p
241+
* Player to check
242+
*
243+
* @return true if specific Player has an opened inventory
244+
*/
245+
public static boolean hasInventoryOpened(Player p) {
246+
return api.hasInventoryOpened(p);
247+
}
248+
249+
/**
250+
* @param p
251+
* Specific player
252+
* @return The inventory of specific Player. Null if not opened
253+
*/
254+
public static Inventory getInventory(Player p) {
255+
return api.getInventory(p);
256+
}
257+
258+
/**
259+
* Close player's inventory.<br />
260+
* Same as <code>p.closeInventory();</code>
261+
*
262+
* @param p
263+
* The player
264+
*/
265+
public static void closeInventory(Player p) {
266+
api.closeInventory(p);
267+
}
214268
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.froxynetwork.froxyapi.inventory;
2+
3+
import java.util.function.Consumer;
4+
5+
import org.bukkit.event.inventory.InventoryClickEvent;
6+
import org.bukkit.inventory.ItemStack;
7+
8+
import lombok.Getter;
9+
10+
/**
11+
* MIT License
12+
*
13+
* Copyright (c) 2019 FroxyNetwork
14+
*
15+
* Permission is hereby granted, free of charge, to any person obtaining a copy
16+
* of this software and associated documentation files (the "Software"), to deal
17+
* in the Software without restriction, including without limitation the rights
18+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+
* copies of the Software, and to permit persons to whom the Software is
20+
* furnished to do so, subject to the following conditions:
21+
*
22+
* The above copyright notice and this permission notice shall be included in
23+
* all copies or substantial portions of the Software.
24+
*
25+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+
* SOFTWARE.
32+
*
33+
* @author 0ddlyoko
34+
*/
35+
/**
36+
* An item that is clickable in the Inventory
37+
*/
38+
public class ClickableItem {
39+
@Getter
40+
private ItemStack item;
41+
private Consumer<InventoryClickEvent> event;
42+
43+
private ClickableItem(ItemStack item, Consumer<InventoryClickEvent> event) {
44+
this.item = item;
45+
this.event = event;
46+
}
47+
48+
public void run(InventoryClickEvent e) {
49+
event.accept(e);
50+
}
51+
52+
public static ClickableItem of(ItemStack is) {
53+
return new ClickableItem(is, e -> {
54+
});
55+
}
56+
57+
public static ClickableItem of(ItemStack is, Consumer<InventoryClickEvent> event) {
58+
return new ClickableItem(is, event);
59+
}
60+
}

0 commit comments

Comments
 (0)