[Forge] Add creative use mode and cheat mode and fix config overwrite.

This commit is contained in:
sk89q 2014-11-14 18:23:43 -08:00
parent 3bee2d4c02
commit 052addbc05
7 changed files with 45 additions and 50 deletions

View File

@ -224,7 +224,7 @@ public void handleCommand(CommandEvent event) {
try {
dispatcher.call(Joiner.on(" ").join(split), locals, new String[0]);
} catch (CommandPermissionsException e) {
actor.printError("You don't have permission to do this.");
actor.printError("You are not permitted to do that. Are you in the right mode?");
} catch (InvalidUsageException e) {
if (e.isFullHelpSuggested()) {
actor.printRaw(ColorCodeBuilder.asColorCodes(new CommandUsageBox(e.getCommand(), e.getCommandUsed("/", ""), locals)));

View File

@ -79,6 +79,8 @@ public void load() {
}
}
loadExtra();
profile = getBool("profile", profile);
disallowedBlocks = getIntSet("disallowed-blocks", defaultDisallowedBlocks);
defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit);
@ -137,6 +139,12 @@ public void load() {
}
}
/**
* Called to load extra configuration.
*/
protected void loadExtra() {
}
/**
* Get a string value.
*

View File

@ -25,10 +25,19 @@
public class ForgeConfiguration extends PropertiesConfiguration {
public boolean creativeEnable = false;
public boolean cheatMode = false;
public ForgeConfiguration(ForgeWorldEdit mod) {
super(new File(mod.getWorkingDir() + File.separator + "worldedit.properties"));
}
@Override
protected void loadExtra() {
creativeEnable = getBool("use-in-creative", false);
cheatMode = getBool("cheat-mode", false);
}
@Override
public File getWorkingDirectory() {
return ForgeWorldEdit.inst.getWorkingDir();

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.AbstractPlatform;
import com.sk89q.worldedit.extension.platform.Actor;
@ -126,7 +125,7 @@ public Player matchPlayer(Player player) {
return player;
} else {
EntityPlayerMP entity = server.getConfigurationManager().func_152612_a(player.getName());
return entity != null ? new ForgePlayer(entity) : null;
return entity != null ? new ForgePlayer(this, entity) : null;
}
}
@ -172,6 +171,16 @@ 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) {
@ -193,7 +202,7 @@ public void registerGameHooks() {
}
@Override
public LocalConfiguration getConfiguration() {
public ForgeConfiguration getConfiguration() {
return mod.getConfig();
}
@ -231,7 +240,7 @@ public Collection<Actor> getConnectedUsers() {
for (String name : scm.getAllUsernames()) {
EntityPlayerMP entity = scm.func_152612_a(name);
if (entity != null) {
users.add(new ForgePlayer(entity));
users.add(new ForgePlayer(this, entity));
}
}
return users;

View File

@ -42,9 +42,11 @@
public class ForgePlayer extends AbstractPlayerActor {
private EntityPlayerMP player;
private final ForgePlatform platform;
private final EntityPlayerMP player;
protected ForgePlayer(EntityPlayerMP player) {
protected ForgePlayer(ForgePlatform platform, EntityPlayerMP player) {
this.platform = platform;
this.player = player;
ThreadSafeCache.getInstance().getOnlineIds().add(getUniqueId());
}
@ -161,7 +163,7 @@ public BlockBag getInventoryBlockBag() {
@Override
public boolean hasPermission(String perm) {
return ForgeUtil.hasPermission(this.player, perm);
return ForgeUtil.hasPermission(platform, this.player, perm);
}
@Nullable

View File

@ -24,6 +24,7 @@
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;
@ -32,9 +33,12 @@ public final class ForgeUtil {
private ForgeUtil() {
}
public static boolean hasPermission(EntityPlayerMP player, String perm) {
public static boolean hasPermission(ForgePlatform platform, EntityPlayerMP player, String perm) {
// TODO fix WEPIF
return FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152596_g(player.getGameProfile());
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) {

View File

@ -28,7 +28,6 @@
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.internal.LocalWorldAdapter;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
@ -46,14 +45,14 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CommandEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
import static net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
@ -81,9 +80,6 @@ public void preInit(FMLPreInitializationEvent event) {
workingDir = new File(event.getModConfigurationDirectory() + File.separator + "worldedit");
workingDir.mkdir();
// Create default configuration
createDefaultConfiguration(event.getSourceFile(), "worldedit.properties");
config = new ForgeConfiguration(this);
config.load();
@ -206,7 +202,7 @@ ForgeConfiguration getConfig() {
*/
public ForgePlayer wrap(EntityPlayerMP player) {
checkNotNull(player);
return new ForgePlayer(player);
return new ForgePlayer(platform, player);
}
/**
@ -249,39 +245,6 @@ public File getWorkingDir() {
return this.workingDir;
}
/**
* Create the default configuration.
*
* @param jar the jar
* @param name the name
*/
private void createDefaultConfiguration(File jar, String name) {
checkNotNull(jar);
checkNotNull(name);
String path = "/defaults/" + name;
File targetFile = new File(getWorkingDir(), name);
Closer closer = Closer.create();
try {
@Nullable InputStream inputStream = getClass().getResourceAsStream(path);
if (inputStream == null) {
throw new IOException("Failed to get resource '" + path + "' from .class");
}
closer.register(inputStream);
FileOutputStream outputStream = new FileOutputStream(targetFile);
ByteStreams.copy(inputStream, outputStream);
logger.info("Default configuration file written: " + name);
} catch (IOException e) {
logger.log(Level.WARN, "Failed to extract defaults", e);
} finally {
try {
closer.close();
} catch (IOException ignored) {
}
}
}
/**
* Get the version of the WorldEdit-for-Forge implementation.
*