mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-25 18:27:36 +01:00
Small simplification
This commit is contained in:
parent
017b0a2346
commit
39e51328cc
@ -17,26 +17,20 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class DefaultHolographicDisplaysAPIProvider extends HolographicDisplaysAPIProvider {
|
||||
|
||||
private final Map<Plugin, HolographicDisplaysAPI> apiCache;
|
||||
private final Function<Plugin, HolographicDisplaysAPI> apiFactory;
|
||||
private final APIHologramManager apiHologramManager;
|
||||
private final PlaceholderRegistry placeholderRegistry;
|
||||
|
||||
public DefaultHolographicDisplaysAPIProvider(APIHologramManager apiHologramManager, PlaceholderRegistry placeholderRegistry) {
|
||||
this.apiCache = new WeakHashMap<>();
|
||||
this.apiFactory = plugin -> new DefaultHolographicDisplaysAPI(plugin, apiHologramManager, placeholderRegistry);
|
||||
this.apiHologramManager = apiHologramManager;
|
||||
this.placeholderRegistry = placeholderRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HolographicDisplaysAPI getHolographicDisplaysAPI(Plugin plugin) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
|
||||
// Optimization: avoid creating a new instance every time a plugin requests it, in case it never stores a reference
|
||||
return apiCache.computeIfAbsent(plugin, apiFactory);
|
||||
return new DefaultHolographicDisplaysAPI(plugin, apiHologramManager, placeholderRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user