[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 final class CommandManager {
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 class PropertiesConfiguration extends LocalConfiguration {
}
}
loadExtra();
profile = getBool("profile", profile);
disallowedBlocks = getIntSet("disallowed-blocks", defaultDisallowedBlocks);
defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit);
@ -137,6 +139,12 @@ public class PropertiesConfiguration extends LocalConfiguration {
}
}
/**
* Called to load extra configuration.
*/
protected void loadExtra() {
}
/**
* Get a string value.
*

View File

@ -25,10 +25,19 @@ import java.io.File;
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 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
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 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
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 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
}
@Override
public LocalConfiguration getConfiguration() {
public ForgeConfiguration getConfiguration() {
return mod.getConfig();
}
@ -231,7 +240,7 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
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 @@ import java.util.UUID;
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 class ForgePlayer extends AbstractPlayerActor {
@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 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;
@ -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.WorldVector;
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.minecraft.world.World;
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 class ForgeWorldEdit {
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 @@ public class ForgeWorldEdit {
*/
public ForgePlayer wrap(EntityPlayerMP player) {
checkNotNull(player);
return new ForgePlayer(player);
return new ForgePlayer(platform, player);
}
/**
@ -249,39 +245,6 @@ public class ForgeWorldEdit {
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.
*