Add support for delegating permissions to Sponge.

When Sponge is not installed, behaviour is as before.
Closes #331
This commit is contained in:
zml 2015-06-29 12:57:01 -07:00 committed by Kenzie Togami
parent 0d5c115e4d
commit aa3a2d4764
4 changed files with 29 additions and 3 deletions

View File

@ -55,6 +55,7 @@
<allow pkg="org.apache.logging.log4j"/> <allow pkg="org.apache.logging.log4j"/>
<allow pkg="org.lwjgl"/> <allow pkg="org.lwjgl"/>
<allow pkg="io.netty.buffer"/> <allow pkg="io.netty.buffer"/>
<allow pkg="org.spongepowered.api" />
</subpackage> </subpackage>
</subpackage> </subpackage>
</import-control> </import-control>

View File

@ -15,9 +15,14 @@ apply plugin: 'forge'
dependencies { dependencies {
compile project(':worldedit-core') compile project(':worldedit-core')
compile 'org.spongepowered:spongeapi:2.1-SNAPSHOT'
testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0-rc1' testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0-rc1'
} }
repositories {
maven { url ="https://repo.spongepowered.org/maven" }
}
minecraft { minecraft {
ext.forgeVersion = "11.14.0.1281" ext.forgeVersion = "11.14.0.1281"
version = "1.8-$forgeVersion-1.8" version = "1.8-$forgeVersion-1.8"

View File

@ -23,6 +23,7 @@ import net.minecraft.command.ICommand;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.WorldSettings.GameType; import net.minecraft.world.WorldSettings.GameType;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
import org.spongepowered.api.entity.player.Player;
public interface ForgePermissionsProvider { public interface ForgePermissionsProvider {
@ -49,4 +50,17 @@ public interface ForgePermissionsProvider {
@Override @Override
public void registerPermission(ICommand command, String permission) {} 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) {
}
}
} }

View File

@ -36,6 +36,7 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CommandEvent; import net.minecraftforge.event.CommandEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance; 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. * 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 class ForgeWorldEdit {
public static Logger logger; public static Logger logger;
@ -116,7 +117,12 @@ public class ForgeWorldEdit {
this.platform = new ForgePlatform(this); this.platform = new ForgePlatform(this);
WorldEdit.getInstance().getPlatformManager().register(platform); 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 @EventHandler