[SOLVED]Can't create ItemStack

Hello,
I tried to give to a random player tree diamond but Intellij Idea sayed that I can’t.
Here’s the code and the error :
`
if(src instanceof Player) {
Player p = (Player) src;

Player choosenPlayer = getRandomPlayer(Sponge.getServer());

**_choosenPlayer.getInventory().set(ItemStack.of(ItemTypes.DIAMOND, 3))_**

spongePrivate.getLogger().info("GIVED 3 DIAMOND TO "+ choosenPlayer.getName());

Text textRandom = Text.of("A player is selected.");
for(int i = 0;i < Sponge.getServer().getOnlinePlayers().size() + 1;i++) {
    Player[] playersList = Sponge.getServer().getOnlinePlayers().toArray(new Player[Sponge.getServer().getOnlinePlayers().size()]);
    Player allPlayers = playersList[i];
    allPlayers.sendMessage(textRandom);
}
return CommandResult.success();

}
`
At choosenPlayer.getInventory().set(ItemStack.of(ItemTypes.DIAMOND, 3)) it says : Static interface method invocations are not supported at this language level.
I also tried ItemStack diamond = ItemStack.builder().itemType(ItemTypes.DIAMOND).quantity(3).build(); and it says the same thing.
Can someone help me please ? :slight_smile:
Sorry if there is a wrong spelling :frowning: I’m french.

You’ll need to set your project/module language level to Java 8.

It’s already on Java 8 and I set the project language to maximum level but it didn’t work.

Try adding this to your pom.xml:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
1 Like

Ah it worked ! Thank you so much :slight_smile: