Cleanup forge code. Make it singleplayer friendly.

This commit is contained in:
Wizjany 2013-02-25 01:22:05 -05:00
parent b2869058a9
commit c2932cc54f
15 changed files with 134 additions and 115 deletions

View File

@ -1,8 +1,9 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.BiomeType;
import net.minecraft.world.biome.BiomeGenBase;
import com.sk89q.worldedit.BiomeType;
public class ForgeBiomeType implements BiomeType {
private BiomeGenBase biome;

View File

@ -1,16 +1,17 @@
package com.sk89q.worldedit.forge;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import net.minecraft.world.biome.BiomeGenBase;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.sk89q.worldedit.BiomeType;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.UnknownBiomeTypeException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import net.minecraft.world.biome.BiomeGenBase;
public class ForgeBiomeTypes implements BiomeTypes {
private static BiMap biomes = HashBiMap.create();

View File

@ -1,8 +1,9 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.util.PropertiesConfiguration;
import java.io.File;
import com.sk89q.worldedit.util.PropertiesConfiguration;
public class ForgeConfiguration extends PropertiesConfiguration {
public ForgeConfiguration(WorldEditMod mod) {

View File

@ -1,7 +1,10 @@
package com.sk89q.worldedit.forge;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet250CustomPayload;
import com.sk89q.util.StringUtil;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
@ -9,12 +12,6 @@ import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.cui.CUIEvent;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetServerHandler;
import net.minecraft.network.packet.Packet250CustomPayload;
public class ForgePlayer extends LocalPlayer {
private EntityPlayerMP player;

View File

@ -1,23 +1,23 @@
package com.sk89q.worldedit.forge;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import cpw.mods.fml.server.FMLServerHandler;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.ServerCommandManager;
import net.minecraft.entity.EntityList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import cpw.mods.fml.common.FMLCommonHandler;
public class ForgeServerInterface extends ServerInterface {
private WorldEditMod mod;
private MinecraftServer server;
@ -25,7 +25,7 @@ public class ForgeServerInterface extends ServerInterface {
public ForgeServerInterface() {
this.mod = WorldEditMod.inst;
this.server = FMLServerHandler.instance().getServer();
this.server = FMLCommonHandler.instance().getMinecraftServerInstance();
this.biomes = new ForgeBiomeTypes();
}
@ -59,7 +59,8 @@ public class ForgeServerInterface extends ServerInterface {
@Override
public void onCommandRegistration(List<Command> commands) {
ServerCommandManager mcMan = (ServerCommandManager) FMLServerHandler.instance().getServer().getCommandManager();
if (server == null) return;
ServerCommandManager mcMan = (ServerCommandManager) server.getCommandManager();
for (Command cmd : commands) {
for (int i = 0; i < cmd.aliases().length; i++) {
final String name = cmd.aliases()[i];

View File

@ -1,19 +1,19 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.blocks.BaseItemStack;
import cpw.mods.fml.server.FMLServerHandler;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import com.sk89q.worldedit.blocks.BaseItemStack;
import cpw.mods.fml.common.FMLCommonHandler;
public class ForgeUtil {
public static boolean hasPermission(EntityPlayerMP player, String perm) {
return FMLServerHandler.instance().getServer().getConfigurationManager().getOps().contains(player.username);
// TODO fix WEPIF
return FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().areCommandsAllowed(player.username);
}
public static ItemStack toForgeItemStack(BaseItemStack item) {

View File

@ -1,29 +1,7 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.BiomeType;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.EntityType;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.blocks.SignBlock;
import com.sk89q.worldedit.blocks.NoteBlock;
import com.sk89q.worldedit.blocks.SkullBlock;
import com.sk89q.worldedit.blocks.DispenserBlock;
import com.sk89q.worldedit.blocks.MobSpawnerBlock;
import com.sk89q.worldedit.blocks.ChestBlock;
import com.sk89q.worldedit.blocks.ContainerBlock;
import com.sk89q.worldedit.blocks.FurnaceBlock;
import com.sk89q.worldedit.foundation.Block;
import com.sk89q.worldedit.regions.Region;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityHanging;
import net.minecraft.entity.EntityLiving;
@ -44,21 +22,32 @@ import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.tileentity.TileEntityNote;
import net.minecraft.tileentity.TileEntitySign;
import net.minecraft.tileentity.TileEntitySkull;
import net.minecraft.util.LongHashMap;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderServer;
import com.sk89q.worldedit.BiomeType;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.EntityType;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.MobSpawnerBlock;
import com.sk89q.worldedit.blocks.NoteBlock;
import com.sk89q.worldedit.blocks.SignBlock;
import com.sk89q.worldedit.blocks.SkullBlock;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.foundation.Block;
import com.sk89q.worldedit.regions.Region;
public class ForgeWorld extends LocalWorld {
// TODO fix world leaks (see net.minecraftforge.common.getIDs()Z;)
private World world;
public ForgeWorld(World world) {
@ -382,9 +371,31 @@ public class ForgeWorld extends LocalWorld {
}
EntityLiving ent = (EntityLiving) obj;
if (((ent instanceof EntityPlayer)) || ((!killAnimals) && ((ent instanceof EntityAnimal))) || ((!killPets) && ((ent instanceof EntityTameable)) && (((EntityTameable) ent).isTamed())) || ((!killGolems) && ((ent instanceof EntityGolem))) || ((!killNPCs) && ((ent instanceof EntityVillager))) || ((!killAmbient) && ((ent instanceof EntityAmbientCreature)))) {
if (ent instanceof EntityPlayer) {
continue;
}
if (!killAnimals && ent instanceof EntityAnimal) {
continue;
}
if (!killPets && ent instanceof EntityTameable && ((EntityTameable) ent).isTamed()) {
continue; // tamed pet
}
if (!killGolems && ent instanceof EntityGolem) {
continue;
}
if (!killNPCs && ent instanceof EntityVillager) {
continue;
}
if (!killAmbient && ent instanceof EntityAmbientCreature) {
continue;
}
if ((radius < 0.0D) || (origin.distanceSq(new Vector(ent.posX, ent.posY, ent.posZ)) <= radiusSq)) {
ent.isDead = true;
num++;

View File

@ -1,18 +1,16 @@
package com.sk89q.worldedit.forge;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.TileEntityBlock;
public class TileEntityBaseBlock extends BaseBlock implements TileEntityBlock {
private TileEntity tile;

View File

@ -1,13 +1,16 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.LocalSession;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
import java.nio.charset.Charset;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import com.sk89q.worldedit.LocalSession;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
public class WECUIPacketHandler implements IPacketHandler {
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");

View File

@ -1,22 +1,23 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector;
import net.minecraft.command.ICommand;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.event.CommandEvent;
import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector;
public class WorldEditForgeListener {
@ForgeSubscribe
public void onCommandEvent(CommandEvent event) {
if (WorldEditMod.inst.getWorldEdit() == null) return;
if ((event.sender instanceof EntityPlayerMP)) {
if (((EntityPlayerMP) event.sender).worldObj.isRemote) return;
String[] split = new String[event.parameters.length + 1];
System.arraycopy(event.parameters, 0, split, 1, event.parameters.length);
split[0] = ("/" + event.command.getCommandName());
@ -27,9 +28,8 @@ public class WorldEditForgeListener {
@ForgeSubscribe
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.useItem == Result.DENY) {
return;
}
if (WorldEditMod.inst.getWorldEdit() == null) return;
if (event.useItem == Result.DENY || event.entity.worldObj.isRemote) return;
LocalPlayer player = WorldEditMod.inst.wrapPlayer((EntityPlayerMP) event.entityPlayer);
LocalWorld world = WorldEditMod.inst.getWorld(event.entityPlayer.worldObj);

View File

@ -1,23 +1,5 @@
package com.sk89q.worldedit.forge;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldEdit;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@ -29,9 +11,25 @@ import java.util.zip.ZipEntry;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.EventBus;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldEdit;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.ServerStarting;
import cpw.mods.fml.common.Mod.ServerStopping;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;
@Mod(modid = "WorldEdit", name = "WorldEdit", version = "5.5.2-forge-alpha1")
public class WorldEditMod {
@ -46,7 +44,6 @@ public class WorldEditMod {
private ForgeConfiguration config;
private File workingDir;
@SideOnly(Side.SERVER)
@Mod.PreInit
public void preInit(FMLPreInitializationEvent event) {
logger = Logger.getLogger(((Mod) getClass().getAnnotation(Mod.class)).modid());
@ -66,23 +63,28 @@ public class WorldEditMod {
// PermissionsResolverManager.initialize(this, this.workingDir);
}
@SideOnly(Side.SERVER)
@Mod.Init
public void init(FMLInitializationEvent event) {
this.server = new ForgeServerInterface();
this.controller = new WorldEdit(this.server, this.config);
NetworkRegistry.instance().registerChannel(new WECUIPacketHandler(), "WECUI");
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
NetworkRegistry.instance().registerChannel(new WECUIPacketHandler(), "WECUI");
} /* else {
WE CUI stuff here?
} */
MinecraftForge.EVENT_BUS.register(new WorldEditForgeListener());
}
@SideOnly(Side.SERVER)
@Mod.PostInit
public void postInit(FMLPostInitializationEvent event) {
logger.info("WorldEdit " + WorldEdit.getVersion() + " Loaded");
}
@ServerStarting
public void serverStarting(FMLServerStartingEvent event) {
this.server = new ForgeServerInterface();
this.controller = new WorldEdit(this.server, this.config);
}
public ForgeConfiguration getConfig() {
return this.config;
}
@ -156,4 +158,4 @@ public class WorldEditMod {
}
}
}
}
}

View File

@ -1,12 +1,13 @@
package com.sk89q.worldedit.forge.selections;
import net.minecraft.world.World;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.forge.WorldEditMod;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.CuboidRegionSelector;
import com.sk89q.worldedit.regions.RegionSelector;
import net.minecraft.world.World;
public class CuboidSelection extends RegionSelection {
protected CuboidRegion cuboid;

View File

@ -1,13 +1,15 @@
package com.sk89q.worldedit.forge.selections;
import java.util.Collections;
import java.util.List;
import net.minecraft.world.World;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.forge.WorldEditMod;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Polygonal2DRegionSelector;
import com.sk89q.worldedit.regions.RegionSelector;
import java.util.Collections;
import java.util.List;
import net.minecraft.world.World;
public class Polygonal2DSelection extends RegionSelection {
protected Polygonal2DRegion poly2d;

View File

@ -1,12 +1,12 @@
package com.sk89q.worldedit.forge.selections;
import com.sk89q.worldedit.LocalWorld;
import net.minecraft.world.World;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.forge.WorldEditMod;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import net.minecraft.world.World;
public abstract class RegionSelection implements Selection {
private World world;

View File

@ -1,9 +1,10 @@
package com.sk89q.worldedit.forge.selections;
import net.minecraft.world.World;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.RegionSelector;
import net.minecraft.world.World;
public abstract interface Selection {
public abstract Location getMinimumPoint();