@@ -18,12 +18,9 @@ public class MenuManager {
1818
1919 //each player will be assigned their own PlayerMenuUtility object
2020 private static final HashMap <Player , PlayerMenuUtility > playerMenuUtilityMap = new HashMap <>();
21- //private static Class<? extends PlayerMenuUtility> pmuClass;
2221 private static boolean isSetup = false ;
23- //private static Class<? extends Menu>[] menus;
2422
2523 private static void registerMenuListener (Server server , Plugin plugin ) {
26-
2724 boolean isAlreadyRegistered = false ;
2825 for (RegisteredListener rl : InventoryClickEvent .getHandlerList ().getRegisteredListeners ()) {
2926 System .out .println (rl .getListener ().getClass ().getSimpleName ());
@@ -33,73 +30,36 @@ private static void registerMenuListener(Server server, Plugin plugin) {
3330 }
3431 }
3532
36- //Dont touch this code -- kody
37- // HandlerList.getHandlerLists().stream()
38- // .forEach(handler -> {
39- //
40- //
41- //
42- // System.out.println(handler.toString());
43- //// System.out.println(Modifier.toString(field.getModifiers()) + " " + field.getName());
44- // });
45-
46- //System.out.println("erwiwjriwer: " + isAlreadyRegistered);
4733 if (!isAlreadyRegistered ) {
4834 server .getPluginManager ().registerEvents (new MenuListener (), plugin );
4935 }
50-
5136 }
5237
53- // private static void registerPlayerMenuUtility(Class<? extends PlayerMenuUtility> playerMenuUtilityClass) {
54- //
55- // MenuManager.pmuClass = playerMenuUtilityClass;
56- //
57- // }
58-
5938 /**
6039 * @param server The instance of your server. Provide by calling getServer()
6140 * @param plugin The instance of the plugin using this API. Can provide in plugin class by passing this keyword
6241 */
6342 public static void setup (Server server , Plugin plugin ) {
64-
6543 System .out .println ("MENU MANAGER HAS BEEN SETUP" );
6644
6745 registerMenuListener (server , plugin );
68- //registerPlayerMenuUtility(playerMenuUtilityClass);
6946 isSetup = true ;
70-
7147 }
7248
7349 /**
7450 * @param menuClass The class reference of the Menu you want to open for a player
7551 * @param player The player to open the menu for
7652 * @throws MenuManagerNotSetupException Thrown if the setup() method has not been called and used properly
7753 */
78- public static void openMenu (Class <? extends Menu > menuClass , Player player ) throws MenuManagerException , MenuManagerNotSetupException {
54+ public static void openMenu (Class <? extends Menu > menuClass , Plugin plugin , Player player ) throws MenuManagerException , MenuManagerNotSetupException {
7955 try {
80- menuClass .getConstructor (PlayerMenuUtility .class ).newInstance (getPlayerMenuUtility (player )).open ();
56+ menuClass .getConstructor (Plugin . class , PlayerMenuUtility .class ).newInstance (plugin , getPlayerMenuUtility (player )).open ();
8157 } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e ) {
82- e .printStackTrace ();
8358 throw new MenuManagerException ();
8459 }
8560 }
8661
87- // /**
88- // * @param menuClass The class reference of the Menu you want to open for a player
89- // * @param abstractPlayerMenuUtility Usually used to pass in a custom PlayerMenuUtility, for data transfer
90- // */
91- // public static void openMenu(Class<? extends Menu> menuClass, PlayerMenuUtility pmc) throws MenuManagerException {
92- //
93- // try {
94- // menuClass.getConstructor(PlayerMenuUtility.class).newInstance(pmc).open();
95- // } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
96- // throw new MenuManagerException();
97- // }
98- //
99- // }
100-
101- public static PlayerMenuUtility getPlayerMenuUtility (Player p ) throws MenuManagerException , MenuManagerNotSetupException {
102-
62+ public static PlayerMenuUtility getPlayerMenuUtility (Player p ) throws MenuManagerNotSetupException {
10363 if (!isSetup ) {
10464 throw new MenuManagerNotSetupException ();
10565 }
@@ -117,32 +77,4 @@ public static PlayerMenuUtility getPlayerMenuUtility(Player p) throws MenuManage
11777 }
11878 }
11979
120-
121- // /**
122- // * @param p The player to get the custom PlayerMenuUtility from
123- // * @param t The class reference of your custom PlayerMenuUtility
124- // * @param <T> The custom PlayerMenuUtility Type
125- // * @return The PlayerMenuUtility for that player
126- // */
127- // public static <T> T getPlayerMenuUtility(Player p, Class<T> t) throws MenuManagerException {
128- //
129- // PlayerMenuUtility playerMenuUtility;
130- // if (!(playerMenuUtilityMap.containsKey(p))) { //See if the player has a PMU "saved" for them
131- //
132- // try{
133- // //Construct PMU using reflection
134- // Constructor<? extends PlayerMenuUtility> constructor = pmuClass.getConstructor(Player.class);
135- //
136- // playerMenuUtility = constructor.newInstance(p);
137- // playerMenuUtilityMap.put(p, playerMenuUtility);
138- // } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
139- // throw new MenuManagerException();
140- // }
141- //
142- // return t.cast(playerMenuUtility);
143- // } else {
144- // return t.cast(playerMenuUtilityMap.get(p)); //Return the object by using the provided player
145- // }
146- //
147- // }
14880}
0 commit comments