From aa3a2d4764ff22ab408b4b6edf606f544d8b250f Mon Sep 17 00:00:00 2001 From: zml Date: Mon, 29 Jun 2015 12:57:01 -0700 Subject: [PATCH] Add support for delegating permissions to Sponge. When Sponge is not installed, behaviour is as before. Closes #331 --- config/checkstyle/import-control.xml | 1 + worldedit-forge/build.gradle | 7 ++++++- .../worldedit/forge/ForgePermissionsProvider.java | 14 ++++++++++++++ .../com/sk89q/worldedit/forge/ForgeWorldEdit.java | 10 ++++++++-- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml index ab87b642b..3e4233471 100644 --- a/config/checkstyle/import-control.xml +++ b/config/checkstyle/import-control.xml @@ -55,6 +55,7 @@ + diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index 563ceeea4..331008ad4 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -15,9 +15,14 @@ apply plugin: 'forge' dependencies { compile project(':worldedit-core') + compile 'org.spongepowered:spongeapi:2.1-SNAPSHOT' testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0-rc1' } +repositories { + maven { url ="https://repo.spongepowered.org/maven" } +} + minecraft { ext.forgeVersion = "11.14.0.1281" version = "1.8-$forgeVersion-1.8" @@ -31,7 +36,7 @@ project.archivesBaseName = "${project.archivesBaseName}-mc${minecraft.version}" processResources { from (sourceSets.main.resources.srcDirs) { expand 'version': project.version, - 'mcVersion': project.minecraft.version, + 'mcVersion': project.minecraft.version, 'forgeVersion': project.minecraft.forgeVersion, 'internalVersion': project.internalVersion include 'mcmod.info' diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePermissionsProvider.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePermissionsProvider.java index ffd8de06b..aa5dd5c2d 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePermissionsProvider.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePermissionsProvider.java @@ -23,6 +23,7 @@ import net.minecraft.command.ICommand; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.world.WorldSettings.GameType; import net.minecraftforge.fml.common.FMLCommonHandler; +import org.spongepowered.api.entity.player.Player; public interface ForgePermissionsProvider { @@ -49,4 +50,17 @@ public interface ForgePermissionsProvider { @Override public void registerPermission(ICommand command, String permission) {} } + + public static class SpongePermissionsProvider implements ForgePermissionsProvider { + + @Override + public boolean hasPermission(EntityPlayerMP player, String permission) { + return ((Player) player).hasPermission(permission); + } + + @Override + public void registerPermission(ICommand command, String permission) { + + } + } } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java index f7f4c6ea5..017ade171 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java @@ -36,6 +36,7 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.CommandEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; @@ -60,7 +61,7 @@ import static net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; /** * The Forge implementation of WorldEdit. */ -@Mod(modid = ForgeWorldEdit.MOD_ID, name = "WorldEdit", version = "%VERSION%", acceptableRemoteVersions = "*") +@Mod(modid = ForgeWorldEdit.MOD_ID, name = "WorldEdit", version = "%VERSION%", acceptableRemoteVersions = "*", dependencies = "after:Sponge") public class ForgeWorldEdit { public static Logger logger; @@ -116,7 +117,12 @@ public class ForgeWorldEdit { this.platform = new ForgePlatform(this); WorldEdit.getInstance().getPlatformManager().register(platform); - this.provider = new ForgePermissionsProvider.VanillaPermissionsProvider(platform); + + if (Loader.isModLoaded("Sponge")) { + this.provider = new ForgePermissionsProvider.SpongePermissionsProvider(); + } else { + this.provider = new ForgePermissionsProvider.VanillaPermissionsProvider(platform); + } } @EventHandler