Clarify comment

This commit is contained in:
filoghost 2021-05-05 11:15:52 +02:00
parent 9f7e2915c1
commit fe626053e6

View File

@ -23,21 +23,21 @@ public class DefaultHolographicDisplaysAPIProvider extends HolographicDisplaysAP
private final NMSManager nmsManager; private final NMSManager nmsManager;
private final PlaceholderRegistry placeholderRegistry; private final PlaceholderRegistry placeholderRegistry;
// Avoid creating a new instance every time a plugin requires it // Optimization: avoid creating a new instance every time a plugin requires it, in case it never stores a reference
private final Map<Plugin, HolographicDisplaysAPI> apiCache; private final Map<Plugin, HolographicDisplaysAPI> apiInstanceCache;
public DefaultHolographicDisplaysAPIProvider(APIHologramManager apiHologramManager, NMSManager nmsManager, PlaceholderRegistry placeholderRegistry) { public DefaultHolographicDisplaysAPIProvider(APIHologramManager apiHologramManager, NMSManager nmsManager, PlaceholderRegistry placeholderRegistry) {
this.apiHologramManager = apiHologramManager; this.apiHologramManager = apiHologramManager;
this.nmsManager = nmsManager; this.nmsManager = nmsManager;
this.placeholderRegistry = placeholderRegistry; this.placeholderRegistry = placeholderRegistry;
this.apiCache = new WeakHashMap<>(); this.apiInstanceCache = new WeakHashMap<>();
} }
@Override @Override
public HolographicDisplaysAPI getHolographicDisplaysAPI(Plugin plugin) { public HolographicDisplaysAPI getHolographicDisplaysAPI(Plugin plugin) {
Preconditions.notNull(plugin, "plugin"); Preconditions.notNull(plugin, "plugin");
return apiCache.computeIfAbsent(plugin, pluginKey -> return apiInstanceCache.computeIfAbsent(plugin, pluginKey ->
new DefaultHolographicDisplaysAPI(pluginKey, apiHologramManager, placeholderRegistry)); new DefaultHolographicDisplaysAPI(pluginKey, apiHologramManager, placeholderRegistry));
} }