Cast EntityPlayerMP to Player

I trying to cast EntityPlayerMP to Player, using Pixelmon event, but show this error:
Libs:
Sponge: 7.4.0
Forge: forge-1.12.2-14.23.5.2860

package pkbr.battlepass.listeners;

import com.pixelmonmod.pixelmon.api.enums.ReceiveType;
import com.pixelmonmod.pixelmon.api.events.PixelmonReceivedEvent;
import com.pixelmonmod.pixelmon.api.pokemon.Pokemon;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import pkbr.battlepass.Main;
import pkbr.battlepass.utils.PlayerData;

public class PokemonCapture {
  @SubscribeEvent
  public void onPokemonReceived(final PixelmonReceivedEvent e) {
    if (e.receiveType == ReceiveType.PokeBall) {
      final PlayerData playerData = Main.getPlayerCache().get((Player) e.player); //the error its here
      final Pokemon pokemon = e.pokemon;

      if (pokemon.isShiny()) {
        playerData.setExp(playerData.getExp() + 100.0);
      } else if (pokemon.isLegendary()) {
        playerData.setExp(playerData.getExp() + 700.0);
      }
    }
  }
}

So 2 problem. The first one is you say “it shows this problem” yet all i see is code. Is this a Intellij (or whatever your ide is) error?

The second is you have package and imports in your code, so my guess is you copied and pasted the whole code. However im not seeing a import for player. Do you have a player class in your package that its using instead?

I fixed that, thx

1 Like