88import org .bukkit .plugin .Plugin ;
99import org .bukkit .plugin .RegisteredListener ;
1010
11- import java .lang .reflect .Constructor ;
1211import java .lang .reflect .InvocationTargetException ;
1312import java .util .HashMap ;
1413
@@ -19,7 +18,7 @@ public class MenuManager {
1918
2019 //each player will be assigned their own PlayerMenuUtility object
2120 private static final HashMap <Player , PlayerMenuUtility > playerMenuUtilityMap = new HashMap <>();
22- private static Class <? extends PlayerMenuUtility > pmuClass ;
21+ // private static Class<? extends PlayerMenuUtility> pmuClass;
2322 private static boolean isSetup = false ;
2423 //private static Class<? extends Menu>[] menus;
2524
@@ -51,24 +50,22 @@ private static void registerMenuListener(Server server, Plugin plugin) {
5150
5251 }
5352
54- private static void registerPlayerMenuUtility (Class <? extends PlayerMenuUtility > playerMenuUtilityClass ) {
55-
56- MenuManager .pmuClass = playerMenuUtilityClass ;
57-
58- }
53+ // private static void registerPlayerMenuUtility(Class<? extends PlayerMenuUtility> playerMenuUtilityClass) {
54+ //
55+ // MenuManager.pmuClass = playerMenuUtilityClass;
56+ //
57+ // }
5958
6059 /**
6160 * @param server The instance of your server. Provide by calling getServer()
6261 * @param plugin The instance of the plugin using this API. Can provide in plugin class by passing this keyword
63- * @param playerMenuUtilityClass The class reference of your concrete defined PlayerMenuUtility subclass of AbstractPlayerMenuUtility
6462 */
65- public static void setup (Server server , Plugin plugin , Class <? extends PlayerMenuUtility > playerMenuUtilityClass ) {
63+ public static void setup (Server server , Plugin plugin ) {
6664
6765 System .out .println ("MENU MANAGER HAS BEEN SETUP" );
6866
6967 registerMenuListener (server , plugin );
70- registerPlayerMenuUtility (playerMenuUtilityClass );
71-
68+ //registerPlayerMenuUtility(playerMenuUtilityClass);
7269 isSetup = true ;
7370
7471 }
@@ -79,23 +76,27 @@ public static void setup(Server server, Plugin plugin, Class<? extends PlayerMen
7976 * @throws MenuManagerNotSetupException Thrown if the setup() method has not been called and used properly
8077 */
8178 public static void openMenu (Class <? extends Menu > menuClass , Player player ) throws MenuManagerException , MenuManagerNotSetupException {
82- openMenu (menuClass , getPlayerMenuUtility (player ));
83- }
84-
85- /**
86- * @param menuClass The class reference of the Menu you want to open for a player
87- * @param abstractPlayerMenuUtility Usually used to pass in a custom PlayerMenuUtility, for data transfer
88- */
89- public static void openMenu (Class <? extends Menu > menuClass , PlayerMenuUtility abstractPlayerMenuUtility ) throws MenuManagerException {
90-
9179 try {
92- menuClass .getConstructor (PlayerMenuUtility .class ).newInstance (abstractPlayerMenuUtility ).open ();
80+ menuClass .getConstructor (PlayerMenuUtility .class ).newInstance (getPlayerMenuUtility ( player ) ).open ();
9381 } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e ) {
9482 throw new MenuManagerException ();
9583 }
96-
9784 }
9885
86+ // /**
87+ // * @param menuClass The class reference of the Menu you want to open for a player
88+ // * @param abstractPlayerMenuUtility Usually used to pass in a custom PlayerMenuUtility, for data transfer
89+ // */
90+ // public static void openMenu(Class<? extends Menu> menuClass, PlayerMenuUtility pmc) throws MenuManagerException {
91+ //
92+ // try {
93+ // menuClass.getConstructor(PlayerMenuUtility.class).newInstance(pmc).open();
94+ // } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
95+ // throw new MenuManagerException();
96+ // }
97+ //
98+ // }
99+
99100 public static PlayerMenuUtility getPlayerMenuUtility (Player p ) throws MenuManagerException , MenuManagerNotSetupException {
100101
101102 if (!isSetup ){
@@ -105,16 +106,9 @@ public static PlayerMenuUtility getPlayerMenuUtility(Player p) throws MenuManage
105106 PlayerMenuUtility playerMenuUtility ;
106107 if (!(playerMenuUtilityMap .containsKey (p ))) { //See if the player has a pmu "saved" for them
107108
108- //Construct PMU using reflection
109- Constructor <? extends PlayerMenuUtility > constructor ;
110- try {
111- constructor = pmuClass .getConstructor (Player .class );
112-
113- playerMenuUtility = constructor .newInstance (p );
114- playerMenuUtilityMap .put (p , playerMenuUtility );
115- } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e ) {
116- throw new MenuManagerException ();
117- }
109+ //Construct PMU
110+ playerMenuUtility = new PlayerMenuUtility (p );
111+ playerMenuUtilityMap .put (p , playerMenuUtility );
118112
119113 return playerMenuUtility ;
120114 } else {
@@ -123,31 +117,31 @@ public static PlayerMenuUtility getPlayerMenuUtility(Player p) throws MenuManage
123117 }
124118
125119
126- /**
127- * @param p The player to get the custom PlayerMenuUtility from
128- * @param t The class reference of your custom PlayerMenuUtility
129- * @param <T> The custom PlayerMenuUtility Type
130- * @return The PlayerMenuUtility for that player
131- */
132- public static <T > T getPlayerMenuUtility (Player p , Class <T > t ) throws MenuManagerException {
133-
134- PlayerMenuUtility playerMenuUtility ;
135- if (!(playerMenuUtilityMap .containsKey (p ))) { //See if the player has a PMU "saved" for them
136-
137- try {
138- //Construct PMU using reflection
139- Constructor <? extends PlayerMenuUtility > constructor = pmuClass .getConstructor (Player .class );
140-
141- playerMenuUtility = constructor .newInstance (p );
142- playerMenuUtilityMap .put (p , playerMenuUtility );
143- } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e ) {
144- throw new MenuManagerException ();
145- }
146-
147- return t .cast (playerMenuUtility );
148- } else {
149- return t .cast (playerMenuUtilityMap .get (p )); //Return the object by using the provided player
150- }
151-
152- }
120+ // /**
121+ // * @param p The player to get the custom PlayerMenuUtility from
122+ // * @param t The class reference of your custom PlayerMenuUtility
123+ // * @param <T> The custom PlayerMenuUtility Type
124+ // * @return The PlayerMenuUtility for that player
125+ // */
126+ // public static <T> T getPlayerMenuUtility(Player p, Class<T> t) throws MenuManagerException {
127+ //
128+ // PlayerMenuUtility playerMenuUtility;
129+ // if (!(playerMenuUtilityMap.containsKey(p))) { //See if the player has a PMU "saved" for them
130+ //
131+ // try{
132+ // //Construct PMU using reflection
133+ // Constructor<? extends PlayerMenuUtility> constructor = pmuClass.getConstructor(Player.class);
134+ //
135+ // playerMenuUtility = constructor.newInstance(p);
136+ // playerMenuUtilityMap.put(p, playerMenuUtility);
137+ // } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
138+ // throw new MenuManagerException();
139+ // }
140+ //
141+ // return t.cast(playerMenuUtility);
142+ // } else {
143+ // return t.cast(playerMenuUtilityMap.get(p)); //Return the object by using the provided player
144+ // }
145+ //
146+ // }
153147}
0 commit comments