Minor improvements to Sponge implementation

- Use SpongeGradle for setting plugin version from Gradle
- Use Guice to manage configuration
- Use event filter annotation for interact event
- Set plugin description and URL
- Remove some redundant parts in the Gradle config
This commit is contained in:
Minecrell 2016-05-21 12:28:22 +02:00 committed by Wyatt Childers
parent fabd7045e7
commit fd0e400bcc
3 changed files with 31 additions and 51 deletions

View File

@ -1,68 +1,51 @@
apply plugin: 'eclipse'
apply plugin: 'idea'
buildscript {
repositories {
mavenCentral()
maven { url = "http://files.minecraftforge.net/maven" }
maven { url = "http://repo.minecrell.net/snapshots" }
maven { url = "http://repo.minecrell.net/releases" }
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
}
dependencies {
classpath 'net.minecrell:VanillaGradle:2.0.3-SNAPSHOT'
classpath 'net.minecrell:VanillaGradle:2.0.3_1'
classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
}
}
plugins {
id 'org.spongepowered.plugin' version '0.5.2'
}
apply plugin: 'net.minecrell.vanilla.server.library'
dependencies {
compile project(':worldedit-core')
compile 'org.spongepowered:spongeapi:4.1.0-SNAPSHOT'
compile 'ninja.leaping.configurate:configurate-hocon:3.1'
testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0-rc1'
}
repositories {
maven {
name = 'forge'
url = 'http://files.minecraftforge.net/maven'
}
maven {
name = "Sponge"
url = "https://repo.spongepowered.org/maven"
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
sponge {
plugin {
id = 'worldedit'
}
}
minecraft {
version = "1.8.9"
mappings = "stable_22"
runDir = 'run'
replaceIn "com/sk89q/worldedit/sponge/SpongeWorldEdit.java"
replace "%VERSION%", project.version
}
project.archivesBaseName = "${project.archivesBaseName}-mc${minecraft.version}"
processResources {
from (sourceSets.main.resources.srcDirs) {
expand 'version': project.version,
'mcVersion': project.minecraft.version,
'internalVersion': project.internalVersion
}
}
jar {
manifest {
attributes("Class-Path": "truezip.jar WorldEdit/truezip.jar js.jar WorldEdit/js.jar",
"WorldEdit-Version": version,
"FMLAT": "worldedit_at.cfg")
"WorldEdit-Version": version)
}
}

View File

@ -32,15 +32,15 @@ import com.sk89q.worldedit.sponge.config.SpongeConfiguration;
import com.sk89q.worldedit.sponge.nms.NMSHelper;
import com.sk89q.worldedit.sponge.nms.SpongeNMSWorld;
import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.config.ConfigManager;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.InteractBlockEvent;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.event.game.state.*;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.plugin.Plugin;
@ -50,7 +50,6 @@ import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import java.io.File;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@ -59,7 +58,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* The Sponge implementation of WorldEdit.
*/
@Plugin(id = SpongeWorldEdit.MOD_ID, name = "WorldEdit", version = "%VERSION%")
@Plugin(id = SpongeWorldEdit.MOD_ID, name = "WorldEdit",
description = "WorldEdit is an easy-to-use in-game world editor for Minecraft",
url = "http://www.enginehub.org/worldedit")
public class SpongeWorldEdit {
@Inject
@ -83,7 +84,11 @@ public class SpongeWorldEdit {
}
private SpongePlatform platform;
@Inject
private SpongeConfiguration config;
@Inject @ConfigDir(sharedRoot = false)
private File workingDir;
public SpongeWorldEdit() {
@ -92,14 +97,7 @@ public class SpongeWorldEdit {
@Listener
public void preInit(GamePreInitializationEvent event) {
// Setup working directory
ConfigManager service = Sponge.getGame().getConfigManager();
Path path = service.getPluginConfig(this).getDirectory();
workingDir = path.toFile();
workingDir.mkdir();
config = new SpongeConfiguration(service.getPluginConfig(this).getConfig(), logger);
// Load configuration
config.load();
Task.builder().interval(30, TimeUnit.SECONDS).execute(ThreadSafeCache.getInstance()).submit(this);
@ -141,7 +139,7 @@ public class SpongeWorldEdit {
private boolean ignoreLeftClickAir = false;
@Listener
public void onPlayerInteract(InteractBlockEvent event) {
public void onPlayerInteract(InteractBlockEvent event, @Root Player spongePlayer) {
if (platform == null) {
return;
}
@ -149,12 +147,8 @@ public class SpongeWorldEdit {
if (!platform.isHookingEvents()) return; // We have to be told to catch these events
WorldEdit we = WorldEdit.getInstance();
Object rootObj = event.getCause().root();
if (!(rootObj instanceof Player)) {
return;
}
SpongePlayer player = wrapPlayer((Player) rootObj);
SpongePlayer player = wrapPlayer(spongePlayer);
com.sk89q.worldedit.world.World world = player.getWorld();
BlockSnapshot targetBlock = event.getTargetBlock();
@ -297,7 +291,7 @@ public class SpongeWorldEdit {
* @return a version string
*/
String getInternalVersion() {
return SpongeWorldEdit.class.getAnnotation(Plugin.class).version();
return container.getVersion().orElse("Unknown");
}
public void setPermissionsProvider(SpongePermissionsProvider provider) {

View File

@ -19,10 +19,12 @@
package com.sk89q.worldedit.sponge.config;
import com.google.inject.Inject;
import com.sk89q.worldedit.sponge.SpongeWorldEdit;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import org.slf4j.Logger;
import org.spongepowered.api.config.DefaultConfig;
import java.io.File;
import java.io.IOException;
@ -32,7 +34,8 @@ public class SpongeConfiguration extends ConfigurateConfiguration {
public boolean creativeEnable = false;
public boolean cheatMode = false;
public SpongeConfiguration(ConfigurationLoader<CommentedConfigurationNode> config, Logger logger) {
@Inject
public SpongeConfiguration(@DefaultConfig(sharedRoot = false) ConfigurationLoader<CommentedConfigurationNode> config, Logger logger) {
super(config, logger);
}
@ -54,4 +57,4 @@ public class SpongeConfiguration extends ConfigurateConfiguration {
public File getWorkingDirectory() {
return SpongeWorldEdit.inst().getWorkingDir();
}
}
}