<commit_before>package crazypants.enderio.power;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;

import crazypants.enderio.Log;
import crazypants.enderio.power.forge.ForgeAdapter;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class PowerHandlerUtil {

  private static final List<IPowerApiAdapter> providers = new ArrayList<IPowerApiAdapter>();
  
  public static void addAdapter(IPowerApiAdapter adapter) {
    if(adapter != null) {
      providers.add(adapter);
    }
  }
  
  public static void onPostInit(FMLPostInitializationEvent event) {
    MinecraftForge.EVENT_BUS.register(new CapAttacher());
    providers.add(new ForgeAdapter());
    try {
      IPowerApiAdapter o = (IPowerApiAdapter)Class.forName("crazypants.enderio.power.rf.RfAdpater").newInstance();
      providers.add(o);
      Log.info("RF integration loaded");
    } catch(Exception e) {
      Log.warn("RF API not found. RF integration not loaded.");
    }
    try {
      IPowerApiAdapter o = (IPowerApiAdapter)Class.forName("crazypants.enderio.power.tesla.TeslaAdapter").newInstance();
      providers.add(o);
      Log.info("Tesla integration loaded");
    } catch(Exception e) {
      Log.warn("Tesla API not found. Tesla integration not loaded.");
    }
    
  }
  
  public static IPowerInterface getPowerInterface(@Nullable ICapabilityProvider provider, EnumFacing side) {
    IPowerInterface res = null;
    for(IPowerApiAdapter prov : providers) {
      res = prov.getPowerInterface(provider, side);
      if(res != null) {
        return res;
      }
    }
    return res;
  }

  public static IEnergyStorage getCapability(ItemStack stack) {
    return getCapability(stack, null);
  }

  public static IEnergyStorage getCapability(@Nullable ICapabilityProvider provider, EnumFacing side) {
    IEnergyStorage res = null;
    for(IPowerApiAdapter prov : providers) {
      res = prov.getCapability(provider, side);
      if(res != null) {<commit_msg>Fix for possible concurrent mod exception<commit_after>package crazypants.enderio.power;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.annotation.Nullable;

import crazypants.enderio.Log;
import crazypants.enderio.power.forge.ForgeAdapter;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class PowerHandlerUtil {

  private static final List<IPowerApiAdapter> providers = new CopyOnWriteArrayList<IPowerApiAdapter>();
  
  public static void addAdapter(IPowerApiAdapter adapter) {
    if(adapter != null) {
      providers.add(adapter);
    }
  }
  
  public static void onPostInit(FMLPostInitializationEvent event) {
    providers.add(new ForgeAdapter());
    try {
      IPowerApiAdapter o = (IPowerApiAdapter)Class.forName("crazypants.enderio.power.rf.RfAdpater").newInstance();
      providers.add(o);
      Log.info("RF integration loaded");
    } catch(Exception e) {
      Log.warn("RF API not found. RF integration not loaded.");
    }
    try {
      IPowerApiAdapter o = (IPowerApiAdapter)Class.forName("crazypants.enderio.power.tesla.TeslaAdapter").newInstance();
      providers.add(o);
      Log.info("Tesla integration loaded");
    } catch(Exception e) {
      Log.warn("Tesla API not found. Tesla integration not loaded.");
    }
    MinecraftForge.EVENT_BUS.register(new CapAttacher());
  }
  
  public static IPowerInterface getPowerInterface(@Nullable ICapabilityProvider provider, EnumFacing side) {
    IPowerInterface res = null;
    for(IPowerApiAdapter prov : providers) {
      res = prov.getPowerInterface(provider, side);
      if(res != null) {
        return res;
      }
    }
    return res;
  }

  public static IEnergyStorage getCapability(ItemStack stack) {
    return getCapability(stack, null);
  }

  public static IEnergyStorage getCapability(@Nullable ICapabilityProvider provider, EnumFacing side) {
    IEnergyStorage res = null;
    for(IPowerApiAdapter prov : providers) {
      res = prov.getCapability(provider, side);
      if(res != null) {
{'fraction_non_alphanumeric': 0.09916492693110647, 'fraction_numerical': 0.0, 'mean_word_length': 4.311529933481153, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5136679', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1427, 'n_words': 287}