APIProviderBasic(LiteAPI[] apis) { this.apis = apis; for (LiteAPI api : this.apis) { this.apiMap.put(api.getIdentifier(), api); } }
/* (non-Javadoc) * @see com.mumfrey.liteloader.api.manager.APIProvider#isAPIAvailable(java.lang.String, int) */ @Override public boolean isAPIAvailable(String identifier, int minRevision) { LiteAPI api = this.apiMap.get(identifier); if (api == null) return false; return api.getRevision() >= minRevision; }
/* (non-Javadoc) * @see com.mumfrey.liteloader.api.manager.APIProvider#getPacketTransformers() */ @Override public List<String> getPacketTransformers() { List<String> packetTransformers = new ArrayList<String>(); for (LiteAPI api : this.apis) { String[] apiTransformers = api.getPacketTransformers(); if (apiTransformers != null) { packetTransformers.addAll(Arrays.asList(apiTransformers)); } } return packetTransformers; }
/* (non-Javadoc) * @see com.mumfrey.liteloader.api.manager.APIProvider#getRequiredDownstreamTransformers() */ @Override public List<String> getRequiredDownstreamTransformers() { List<String> requiredDownstreamTransformers = new ArrayList<String>(); for (LiteAPI api : this.apis) { String[] apiTransformers = api.getRequiredDownstreamTransformers(); if (apiTransformers != null) { requiredDownstreamTransformers.addAll(Arrays.asList(apiTransformers)); } } return requiredDownstreamTransformers; }
/* (non-Javadoc) * @see com.mumfrey.liteloader.api.manager.APIProvider#getAPI(java.lang.Class) */ @SuppressWarnings("unchecked") @Override public <T extends LiteAPI> T getAPI(Class<T> apiClass) { try { for (LiteAPI api : this.apis) { if (apiClass.isAssignableFrom(api.getClass())) return (T) api; } } catch (NullPointerException ex1) { } catch (ClassCastException ex2) { } return null; }
/* (non-Javadoc) * @see com.mumfrey.liteloader.api.manager.APIAdapter#getCoreProviders() */ @Override public List<CoreProvider> getCoreProviders() { if (this.coreProviders == null) { List<CoreProvider> coreProviders = new ArrayList<CoreProvider>(); for (LiteAPI api : this.apis) { List<CoreProvider> apiCoreProviders = api.getCoreProviders(); if (apiCoreProviders != null) { coreProviders.addAll(apiCoreProviders); } } this.coreProviders = Collections.unmodifiableList(coreProviders); } return this.coreProviders; }
/* (non-Javadoc) * @see com.mumfrey.liteloader.api.manager.APIProvider#getObservers(com.mumfrey.liteloader.api.LiteAPI) */ @Override public List<? extends Observer> getObservers(LiteAPI api) { if (!this.observers.containsKey(api)) { List<Observer> apiObservers = api.getObservers(); this.observers.put( api, Collections.unmodifiableList( apiObservers != null ? apiObservers : new ArrayList<Observer>())); } return this.observers.get(api); }