Use SpongeGradle plugin with Eclipse

Hi!

I don’t understand how I’ve to use gradle with Eclipse in order to be able to use the Sponge API. It is said that it is recommended to use the SpongeGradle plugin. But I don’t know how to use this with my IDE (Eclipse) and I don’t find any video or blog using it… Can somebody show me how to use this?

Thanks a lot :stuck_out_tongue: (I’m not familiar with Gradle)

EDIT: I was using Maven but I got this error

static interface method invocations are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable static interface method invocations)

using maven. The code of the class is:.

package io.github.AlexandreGerault.BattleRoyal.commands.structure;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Optional;
import java.util.zip.GZIPOutputStream;

import org.spongepowered.api.command.CommandCallable;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandElement;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.data.persistence.DataFormats;
import org.spongepowered.api.data.persistence.DataTranslators;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.ArchetypeVolume;
import org.spongepowered.api.world.schematic.BlockPaletteTypes;
import org.spongepowered.api.world.schematic.Schematic;

import com.flowpowered.math.vector.Vector3i;

import io.github.AlexandreGerault.BattleRoyal.BRP.BattleRoyal;
import io.github.AlexandreGerault.BattleRoyal.BRP.PlayerData;

public class SaveStructureCommand implements CommandCallable {
	
	private BattleRoyal plugin;
	private final Optional<Text> desc = Optional.of(Text.of("Saves the selected area to a structure file").toText());
    private final Optional<Text> help = Optional.of(Text.of("Saves the selected area to a structure file").toText());
    private final Text usage = Text.of("structure save <structure_name>");

    public SaveStructureCommand(BattleRoyal plugin_) {
    	this.plugin = plugin_;
    }
    
	@Override
	public CommandResult process(CommandSource source, String arguments) throws CommandException {
		if (!(source instanceof Player)) {
			source.sendMessage(Text.of(TextColors.RED, "The sender must be a player"));
			return CommandResult.success();
		}
		
		Player player = (Player) source;
		PlayerData playerData = plugin.getPlayerData(player);
		CommandElement structureName = GenericArguments.firstParsing(GenericArguments.string(Text.of("structure name")));
		String name = structureName.toString();
		
		if (playerData.getPos1() == null || playerData.getPos2() == null) {
			player.sendMessage(Text.of(TextColors.RED, "Error, you must have selected two corners with golden hoe"));
			return CommandResult.success();
		}
		
		Vector3i min = playerData.getPos1().min(playerData.getPos2());
        Vector3i max = playerData.getPos1().max(playerData.getPos2());

        // Defines the volume we will be copying, using the min
        // and max values gotten from the interact events.
        ArchetypeVolume volume = player.getWorld().createArchetypeVolume(min, max, player.getLocation().getPosition().toInt());
		
        Schematic schematic = Schematic.builder()
                .volume(volume)
                .metaValue(Schematic.METADATA_AUTHOR, player.getName())
                .metaValue(Schematic.METADATA_NAME, name)
                .paletteType(BlockPaletteTypes.LOCAL)
                .build();
        
        DataContainer schematicData = DataTranslators.SCHEMATIC.translate(schematic);
        
        File outputFile = new File(plugin.config(), name + ".schematic");
        
        try {
            DataFormats.NBT.writeTo(new GZIPOutputStream(new FileOutputStream(outputFile)), schematicData);
            player.sendMessage(Text.of(TextColors.GREEN, "Saved structure to " + outputFile.getAbsolutePath()));
        } catch (Exception e) {
            e.printStackTrace();
            player.sendMessage(Text.of(TextColors.DARK_RED, "Error saving structure: " + e.getMessage()));
            return CommandResult.success();
        }
        
		return null;
	}

	@Override
	public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition)
			throws CommandException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean testPermission(CommandSource source) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Optional<Text> getShortDescription(CommandSource source) {
		// TODO Auto-generated method stub
		return this.desc;
	}

	@Override
	public Optional<Text> getHelp(CommandSource source) {
		// TODO Auto-generated method stub
		return this.help;
	}

	@Override
	public Text getUsage(CommandSource source) {
		// TODO Auto-generated method stub
		return this.usage;
	}

}

Hi it’s me again but I decided to create a new account (old e-mail, new username etc… the previous one was too old and I don’t like MrAlexan14’s name anymore)

Indeed the solution is obvious… Just write these lines as mentioned in the doc to the build.gradle file…

plugins {
    id 'java-library'
    id 'org.spongepowered.plugin' version '0.9.0'
}

It has to be at the very beginning of the file if I understood well. Here is my complete file:

plugins {
    id 'java-library'
    id 'org.spongepowered.plugin' version '0.9.0'
}

group = 'io.github.AlexandreGerault.BattleRoyal' // TODO
version = '1.0-SNAPSHOT'
description = 'A battle royal plugin'

dependencies {
    api 'org.apache.commons:commons-math3:3.6.1'
    implementation 'com.google.guava:guava:23.0'
    testImplementation 'junit:junit:4.12'
    compile 'org.spongepowered:spongeapi:7.1.0'
}

repositories {
    jcenter()
}