Guest User

Untitled

a guest
Sep 26th, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.List;
  3. import java.util.Map.Entry;
  4.  
  5. import net.minecraft.src.Item;
  6. import net.minecraft.src.ItemStack;
  7.  
  8. /**
  9.  *
  10.  * @author Duke605
  11.  *
  12.  */
  13. public class InformationAPI{
  14.  
  15.     private static HashMap<String, IInformationAPI> modArray = new HashMap<String, IInformationAPI>();
  16.    
  17.     /**
  18.      * Registers a class for information API method call
  19.      *
  20.      * @param modClass the class you wish to register
  21.      */
  22.     public static void register(IInformationAPI modClass){
  23.         if (modClass != null && !modArray.containsKey(modClass.getClass().getSimpleName()))
  24.             modArray.put(modClass.getClass().getSimpleName(), modClass);
  25.         else if (modClass == null)
  26.             System.out.println("You cannot register NULL.");
  27.         else if (modArray.containsKey(modClass.getClass().getSimpleName()))
  28.             System.err.println(modClass.getClass().getSimpleName() + " is already registered.");
  29.         else
  30.             System.err.println("An impossiable error occured!");
  31.     }
  32.    
  33.     /**
  34.      * Unregisters a class for information API method call
  35.      *
  36.      * @param modClass the class you wish to unregister
  37.      */
  38.     public static void unregister(IInformationAPI modClass){
  39.         modArray.remove(modClass.getClass().getSimpleName());
  40.     }
  41.    
  42.     /**
  43.      * Called by GuiContainer, calls all addInformation method from all classes in modArray
  44.      *
  45.      * @param itemstack The item stack
  46.      * @param item Done for convince. Equivalent of "itemstack.getItem()"
  47.      * @param list The information list
  48.      */
  49.     public static void addInfo(ItemStack itemstack, Item item, List list){
  50.         for (Entry<String, IInformationAPI> i: modArray.entrySet()){
  51.             i.getValue().addInformation(itemstack, item, list);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment