Merge pull request #309 from luacs1998/master

Add temporary permissions API for the Forge mod.
Dieser Commit ist enthalten in:
sk89q 2014-12-11 20:06:23 -08:00
Commit 0151f9a038
7 geänderte Dateien mit 162 neuen und 94 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,77 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.util.command.CommandMapping;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
public class CommandWrapper extends CommandBase {
private CommandMapping command;
protected CommandWrapper(CommandMapping command) {
this.command = command;
}
@Override
public String getCommandName() {
return command.getPrimaryAlias();
}
@Override
public List<String> getCommandAliases() {
return Arrays.asList(command.getAllAliases());
}
@Override
public void processCommand(ICommandSender var1, String[] var2) {}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
return "/" + command.getPrimaryAlias() + " " + command.getDescription().getUsage();
}
@Override
public int getRequiredPermissionLevel() {
return 0;
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
return true;
}
@Override
public int compareTo(@Nullable
Object o) {
if (o == null) {
return 0;
} else if (o instanceof ICommand) {
return super.compareTo((ICommand) o);
} else {
return 0;
}
}
}

Datei anzeigen

@ -0,0 +1,52 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.forge;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.command.ICommand;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.WorldSettings.GameType;
public interface ForgePermissionsProvider {
public boolean hasPermission(EntityPlayerMP player, String permission);
public void registerPermission(ICommand command, String permission);
public static class VanillaPermissionsProvider implements ForgePermissionsProvider {
private ForgePlatform platform;
public VanillaPermissionsProvider(ForgePlatform platform) {
this.platform = platform;
}
@Override
public boolean hasPermission(EntityPlayerMP player, String permission) {
ForgeConfiguration configuration = platform.getConfiguration();
return configuration.cheatMode ||
FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152596_g(player.getGameProfile()) ||
(configuration.creativeEnable && player.theItemInWorldManager.getGameType() == GameType.CREATIVE);
}
@Override
public void registerPermission(ICommand command, String permission) {}
}
}

Datei anzeigen

@ -151,47 +151,14 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
ServerCommandManager mcMan = (ServerCommandManager) server.getCommandManager();
for (final CommandMapping command : dispatcher.getCommands()) {
final Description description = command.getDescription();
mcMan.registerCommand(new CommandBase() {
@Override
public String getCommandName() {
return command.getPrimaryAlias();
CommandWrapper wrapper = new CommandWrapper(command);
mcMan.registerCommand(wrapper);
ForgeWorldEdit.inst.getPermissionsProvider().registerPermission(wrapper, command.getDescription().getPermissions().get(0));
if (command.getDescription().getPermissions().size() > 1) {
for (int i = 1; i < command.getDescription().getPermissions().size(); i++) {
ForgeWorldEdit.inst.getPermissionsProvider().registerPermission(null, command.getDescription().getPermissions().get(i));
}
@Override
public List<String> getCommandAliases() {
return Arrays.asList(command.getAllAliases());
}
@Override
public void processCommand(ICommandSender var1, String[] var2) {}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
return "/" + command.getPrimaryAlias() + " " + description.getUsage();
}
@Override
public int getRequiredPermissionLevel() {
return 0;
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
return true;
}
@Override
public int compareTo(@Nullable Object o) {
if (o == null) {
return 0;
} else if (o instanceof ICommand) {
return super.compareTo((ICommand) o);
} else {
return 0;
}
}
});
}
}
}

Datei anzeigen

@ -163,7 +163,7 @@ public class ForgePlayer extends AbstractPlayerActor {
@Override
public boolean hasPermission(String perm) {
return ForgeUtil.hasPermission(platform, this.player, perm);
return ForgeWorldEdit.inst.getPermissionsProvider().hasPermission(player, perm);
}
@Nullable

Datei anzeigen

@ -1,52 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.blocks.BaseItemStack;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.WorldSettings.GameType;
import java.util.Map;
public final class ForgeUtil {
private ForgeUtil() {
}
public static boolean hasPermission(ForgePlatform platform, EntityPlayerMP player, String perm) {
// TODO fix WEPIF
ForgeConfiguration configuration = platform.getConfiguration();
return configuration.cheatMode ||
FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152596_g(player.getGameProfile()) ||
(configuration.creativeEnable && player.theItemInWorldManager.getGameType() == GameType.CREATIVE);
}
public static ItemStack toForgeItemStack(BaseItemStack item) {
ItemStack ret = new ItemStack(Item.getItemById(item.getType()), item.getAmount(), item.getData());
for (Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
ret.addEnchantment(net.minecraft.enchantment.Enchantment.enchantmentsList[((Integer) entry.getKey())], (Integer) entry.getValue());
}
return ret;
}
}

Datei anzeigen

@ -208,7 +208,7 @@ public class ForgeWorld extends AbstractWorld {
return;
}
EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeUtil.toForgeItemStack(item));
EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeWorldEdit.toForgeItemStack(item));
entity.delayBeforeCanPickup = 10;
getWorld().spawnEntityInWorld(entity);
}

Datei anzeigen

@ -23,6 +23,7 @@ import com.google.common.base.Joiner;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.internal.LocalWorldAdapter;
@ -40,6 +41,8 @@ import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CommandEvent;
@ -47,6 +50,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
import static net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
@ -61,6 +65,8 @@ public class ForgeWorldEdit {
public static final String MOD_ID = "worldedit";
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
private ForgePermissionsProvider provider;
@Instance(MOD_ID)
public static ForgeWorldEdit inst;
@ -107,6 +113,7 @@ public class ForgeWorldEdit {
this.platform = new ForgePlatform(this);
WorldEdit.getInstance().getPlatformManager().register(platform);
this.provider = new ForgePermissionsProvider.VanillaPermissionsProvider(platform);
}
@EventHandler
@ -184,6 +191,15 @@ public class ForgeWorldEdit {
}
}
public static ItemStack toForgeItemStack(BaseItemStack item) {
ItemStack ret = new ItemStack(Item.getItemById(item.getType()), item.getAmount(), item.getData());
for (Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
ret.addEnchantment(net.minecraft.enchantment.Enchantment.enchantmentsList[((Integer) entry.getKey())], (Integer) entry.getValue());
}
return ret;
}
/**
* Get the configuration.
*
@ -253,4 +269,12 @@ public class ForgeWorldEdit {
return ForgeWorldEdit.class.getAnnotation(Mod.class).version();
}
public void setPermissionsProvider(ForgePermissionsProvider provider) {
this.provider = provider;
}
public ForgePermissionsProvider getPermissionsProvider() {
return provider;
}
}