Skip to content

Commit e6fe7e6

Browse files
committed
4.1.3
1 parent cbc35b7 commit e6fe7e6

7 files changed

Lines changed: 64 additions & 41 deletions

File tree

docs/me/kodysimpson/simpapi/menu/AbstractPlayerMenuUtility.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ <h2 title="Class AbstractPlayerMenuUtility" class="title">Class AbstractPlayerMe
101101
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a></li>
102102
<li>
103103
<ul class="inheritance">
104-
<li>me.kodysimpson.simpapi.menu.AbstractPlayerMenuUtility</li>
104+
<li>me.kodysimpson.simpapi.menu.PlayerMenuUtility</li>
105105
</ul>
106106
</li>
107107
</ul>

docs/me/kodysimpson/simpapi/menu/class-use/AbstractPlayerMenuUtility.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
</a></div>
7272
<!-- ========= END OF TOP NAVBAR ========= -->
7373
<div class="header">
74-
<h2 title="Uses of Class me.kodysimpson.simpapi.menu.AbstractPlayerMenuUtility" class="title">Uses of Class<br>me.kodysimpson.simpapi.menu.AbstractPlayerMenuUtility</h2>
74+
<h2 title="Uses of Class me.kodysimpson.simpapi.menu.PlayerMenuUtility" class="title">Uses of Class<br>me.kodysimpson.simpapi.menu.AbstractPlayerMenuUtility</h2>
7575
</div>
7676
<div class="classUseContainer">
7777
<ul class="blockList">

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.kodysimpson</groupId>
88
<artifactId>SimpAPI</artifactId>
9-
<version>4.1.2</version>
9+
<version>4.1.3</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimpAPI</name>

src/main/java/me/kodysimpson/simpapi/menu/AbstractPlayerMenuUtility.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/main/java/me/kodysimpson/simpapi/menu/Menu.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
public abstract class Menu implements InventoryHolder {
2020

2121
//Protected values that can be accessed in the menus
22-
protected AbstractPlayerMenuUtility pmu;
22+
protected PlayerMenuUtility pmu;
2323
protected Inventory inventory;
2424
protected ItemStack FILLER_GLASS = makeItem(Material.GRAY_STAINED_GLASS_PANE, " ");
2525

2626
//Constructor for Menu. Pass in a PlayerMenuUtility so that
2727
// we have information on who's menu this is and
2828
// what info is to be transferred
29-
public Menu(AbstractPlayerMenuUtility pmu) {
29+
public Menu(PlayerMenuUtility pmu) {
3030
this.pmu = pmu;
3131
}
3232

@@ -64,6 +64,9 @@ public void open() {
6464
return inventory;
6565
}
6666

67+
/**
68+
* This will fill all of the empty slots with "filler glass"
69+
*/
6770
//Helpful utility method to fill all remaining slots with "filler glass"
6871
public void setFillerGlass(){
6972
for (int i = 0; i < getSlots(); i++) {
@@ -86,7 +89,7 @@ public ItemStack makeItem(Material material, String displayName, String... lore)
8689
return item;
8790
}
8891

89-
public <T> T PMUCaster(AbstractPlayerMenuUtility abstractPlayerMenuUtility, Class<T> t) {
92+
public <T> T PMUCaster(PlayerMenuUtility abstractPlayerMenuUtility, Class<T> t) {
9093
return t.cast(abstractPlayerMenuUtility);
9194
}
9295

src/main/java/me/kodysimpson/simpapi/menu/MenuManager.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
public class MenuManager {
1919

2020
//each player will be assigned their own PlayerMenuUtility object
21-
private static final HashMap<Player, AbstractPlayerMenuUtility> playerMenuUtilityMap = new HashMap<>();
22-
private static Class<? extends AbstractPlayerMenuUtility> pmuClass;
21+
private static final HashMap<Player, PlayerMenuUtility> playerMenuUtilityMap = new HashMap<>();
22+
private static Class<? extends PlayerMenuUtility> pmuClass;
2323
private static boolean isSetup = false;
2424
//private static Class<? extends Menu>[] menus;
2525

@@ -51,7 +51,7 @@ private static void registerMenuListener(Server server, Plugin plugin) {
5151

5252
}
5353

54-
private static void registerPlayerMenuUtility(Class<? extends AbstractPlayerMenuUtility> playerMenuUtilityClass) {
54+
private static void registerPlayerMenuUtility(Class<? extends PlayerMenuUtility> playerMenuUtilityClass) {
5555

5656
MenuManager.pmuClass = playerMenuUtilityClass;
5757

@@ -62,7 +62,7 @@ private static void registerPlayerMenuUtility(Class<? extends AbstractPlayerMenu
6262
* @param plugin The instance of the plugin using this API. Can provide in plugin class by passing this keyword
6363
* @param playerMenuUtilityClass The class reference of your concrete defined PlayerMenuUtility subclass of AbstractPlayerMenuUtility
6464
*/
65-
public static void setup(Server server, Plugin plugin, Class<? extends AbstractPlayerMenuUtility> playerMenuUtilityClass) {
65+
public static void setup(Server server, Plugin plugin, Class<? extends PlayerMenuUtility> playerMenuUtilityClass) {
6666

6767
System.out.println("MENU MANAGER HAS BEEN SETUP");
6868

@@ -86,27 +86,27 @@ public static void openMenu(Class<? extends Menu> menuClass, Player player) thro
8686
* @param menuClass The class reference of the Menu you want to open for a player
8787
* @param abstractPlayerMenuUtility Usually used to pass in a custom PlayerMenuUtility, for data transfer
8888
*/
89-
public static void openMenu(Class<? extends Menu> menuClass, AbstractPlayerMenuUtility abstractPlayerMenuUtility) throws MenuManagerException {
89+
public static void openMenu(Class<? extends Menu> menuClass, PlayerMenuUtility abstractPlayerMenuUtility) throws MenuManagerException {
9090

9191
try {
92-
menuClass.getConstructor(AbstractPlayerMenuUtility.class).newInstance(abstractPlayerMenuUtility).open();
92+
menuClass.getConstructor(PlayerMenuUtility.class).newInstance(abstractPlayerMenuUtility).open();
9393
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
9494
throw new MenuManagerException();
9595
}
9696

9797
}
9898

99-
public static AbstractPlayerMenuUtility getPlayerMenuUtility(Player p) throws MenuManagerException, MenuManagerNotSetupException {
99+
public static PlayerMenuUtility getPlayerMenuUtility(Player p) throws MenuManagerException, MenuManagerNotSetupException {
100100

101101
if (!isSetup){
102102
throw new MenuManagerNotSetupException();
103103
}
104104

105-
AbstractPlayerMenuUtility playerMenuUtility;
105+
PlayerMenuUtility playerMenuUtility;
106106
if (!(playerMenuUtilityMap.containsKey(p))) { //See if the player has a pmu "saved" for them
107107

108108
//Construct PMU using reflection
109-
Constructor<? extends AbstractPlayerMenuUtility> constructor;
109+
Constructor<? extends PlayerMenuUtility> constructor;
110110
try {
111111
constructor = pmuClass.getConstructor(Player.class);
112112

@@ -131,12 +131,12 @@ public static AbstractPlayerMenuUtility getPlayerMenuUtility(Player p) throws Me
131131
*/
132132
public static <T> T getPlayerMenuUtility(Player p, Class<T> t) throws MenuManagerException {
133133

134-
AbstractPlayerMenuUtility playerMenuUtility;
134+
PlayerMenuUtility playerMenuUtility;
135135
if (!(playerMenuUtilityMap.containsKey(p))) { //See if the player has a PMU "saved" for them
136136

137137
try{
138138
//Construct PMU using reflection
139-
Constructor<? extends AbstractPlayerMenuUtility> constructor = pmuClass.getConstructor(Player.class);
139+
Constructor<? extends PlayerMenuUtility> constructor = pmuClass.getConstructor(Player.class);
140140

141141
playerMenuUtility = constructor.newInstance(p);
142142
playerMenuUtilityMap.put(p, playerMenuUtility);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package me.kodysimpson.simpapi.menu;
2+
3+
/*
4+
Companion class to all menus. This is needed to pass information across the entire
5+
menu system no matter how many inventories are opened or closed.
6+
7+
Each player has one of these objects, and only one.
8+
*/
9+
10+
import org.bukkit.entity.Player;
11+
12+
import java.util.HashMap;
13+
14+
public class PlayerMenuUtility {
15+
16+
private final Player owner;
17+
private final HashMap<String, Object> dataMap = new HashMap<>();
18+
19+
public PlayerMenuUtility(Player p) {
20+
this.owner = p;
21+
}
22+
23+
public Player getOwner() {
24+
return owner;
25+
}
26+
27+
/**
28+
* @param identifier A key to store the data by
29+
* @param data The data itself to be stored
30+
*/
31+
public void setData(String identifier, Object data){
32+
this.dataMap.put(identifier, data);
33+
}
34+
35+
/**
36+
* @param identifier The key for the data stored in the PMC
37+
* @return The retrieved value or null if not found
38+
*/
39+
public Object getData(String identifier){
40+
return this.dataMap.get(identifier);
41+
}
42+
43+
}
44+

0 commit comments

Comments
 (0)