[Forge] Cleaned up the code somewhat.

This commit is contained in:
sk89q 2014-04-06 12:07:10 -07:00
parent cb7508f481
commit b6ee2c570a
12 changed files with 430 additions and 708 deletions

View File

@ -25,7 +25,7 @@ import com.sk89q.worldedit.util.PropertiesConfiguration;
public class ForgeConfiguration extends PropertiesConfiguration { public class ForgeConfiguration extends PropertiesConfiguration {
public ForgeConfiguration(WorldEditMod mod) { public ForgeConfiguration(ForgeWorldEdit mod) {
super(new File(mod.getWorkingDir() + File.separator + "worldedit.properties")); super(new File(mod.getWorkingDir() + File.separator + "worldedit.properties"));
} }
@ -35,6 +35,6 @@ public class ForgeConfiguration extends PropertiesConfiguration {
} }
public File getWorkingDirectory() { public File getWorkingDirectory() {
return WorldEditMod.inst.getWorkingDir(); return ForgeWorldEdit.inst.getWorkingDir();
} }
} }

View File

@ -39,12 +39,12 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class ForgeServerInterface extends ServerInterface { class ForgePlatform extends ServerInterface {
private final WorldEditMod mod; private final ForgeWorldEdit mod;
private final MinecraftServer server; private final MinecraftServer server;
private final ForgeBiomeTypes biomes; private final ForgeBiomeTypes biomes;
public ForgeServerInterface(WorldEditMod mod) { public ForgePlatform(ForgeWorldEdit mod) {
this.mod = mod; this.mod = mod;
this.server = FMLCommonHandler.instance().getMinecraftServerInstance(); this.server = FMLCommonHandler.instance().getMinecraftServerInstance();
this.biomes = new ForgeBiomeTypes(); this.biomes = new ForgeBiomeTypes();

View File

@ -19,24 +19,20 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.ChatMessageComponent;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
public class ForgePlayer extends LocalPlayer { public class ForgePlayer extends LocalPlayer {
private EntityPlayerMP player; private EntityPlayerMP player;
protected ForgePlayer(EntityPlayerMP player) { protected ForgePlayer(EntityPlayerMP player) {
super(WorldEditMod.inst.getServerInterface()); super((ServerInterface) ForgeWorldEdit.inst.getPlatform());
this.player = player; this.player = player;
} }
@ -50,11 +46,11 @@ public class ForgePlayer extends LocalPlayer {
} }
public WorldVector getPosition() { public WorldVector getPosition() {
return new WorldVector(WorldEditMod.inst.getWorld(this.player.worldObj), this.player.posX, this.player.posY, this.player.posZ); return new WorldVector(ForgeWorldEdit.inst.getWorld(this.player.worldObj), this.player.posX, this.player.posY, this.player.posZ);
} }
public LocalWorld getWorld() { public LocalWorld getWorld() {
return WorldEditMod.inst.getWorld(this.player.worldObj); return ForgeWorldEdit.inst.getWorld(this.player.worldObj);
} }
public double getPitch() { public double getPitch() {
@ -75,7 +71,7 @@ public class ForgePlayer extends LocalPlayer {
if (params.length > 0) { if (params.length > 0) {
send = send + "|" + StringUtil.joinString(params, "|"); send = send + "|" + StringUtil.joinString(params, "|");
} }
Packet250CustomPayload packet = new Packet250CustomPayload(WorldEditMod.CUI_PLUGIN_CHANNEL, send.getBytes(WECUIPacketHandler.UTF_8_CHARSET)); Packet250CustomPayload packet = new Packet250CustomPayload(ForgeWorldEdit.CUI_PLUGIN_CHANNEL, send.getBytes(WECUIPacketHandler.UTF_8_CHARSET));
this.player.playerNetServerHandler.sendPacketToPlayer(packet); this.player.playerNetServerHandler.sendPacketToPlayer(packet);
} }

View File

@ -52,7 +52,7 @@ import java.util.Set;
public class ForgeWorld extends LocalWorld { public class ForgeWorld extends LocalWorld {
private WeakReference<World> world; private WeakReference<World> world;
public ForgeWorld(World world) { ForgeWorld(World world) {
this.world = new WeakReference<World>(world); this.world = new WeakReference<World>(world);
} }

View File

@ -0,0 +1,270 @@
/*
* 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.google.common.io.ByteStreams;
import com.google.common.io.Closer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformRejectionException;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.network.NetworkMod;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CommandEvent;
import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
import static net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
/**
* The Forge implementation of WorldEdit.
*/
@Mod(modid = "WorldEdit", name = "WorldEdit", version = "%VERSION%")
@NetworkMod(channels="WECUI", packetHandler=WECUIPacketHandler.class)
public class ForgeWorldEdit {
private static final Logger logger = Logger.getLogger(ForgeWorldEdit.class.getCanonicalName());
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
@Instance("WorldEdit")
public static ForgeWorldEdit inst;
private ForgePlatform platform;
private ForgeConfiguration config;
private File workingDir;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
// Redirect all loggers under com.sk89q to FML's logger
Logger.getLogger("com.sk89q").setParent(FMLLog.getLogger());
// Setup working directory
workingDir = new File(event.getModConfigurationDirectory() + File.separator + "worldedit");
workingDir.mkdir();
// Create default configuration
createDefaultConfiguration(event.getSourceFile(), "worldedit.properties");
config = new ForgeConfiguration(this);
config.load();
}
@EventHandler
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
logger.info("WorldEdit for Forge (version " + getInternalVersion() + ") is loaded");
}
@EventHandler
public void serverStarting(FMLServerStartingEvent event) {
if (this.platform != null) {
logger.warning("FMLServerStartingEvent occurred when FMLServerStoppingEvent hasn't");
WorldEdit.getInstance().getPlatformManager().unregister(platform);
}
this.platform = new ForgePlatform(this);
try {
WorldEdit.getInstance().getPlatformManager().register(platform);
} catch (PlatformRejectionException e) {
throw new RuntimeException("Failed to register with WorldEdit", e);
}
}
@EventHandler
public void serverStopping(FMLServerStoppingEvent event) {
WorldEdit.getInstance().getPlatformManager().unregister(platform);
}
@ForgeSubscribe
public void onCommandEvent(CommandEvent event) {
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());
WorldEdit.getInstance().handleCommand(wrap((EntityPlayerMP) event.sender), split);
}
}
@ForgeSubscribe
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.useItem == Result.DENY || event.entity.worldObj.isRemote) return;
WorldEdit we = WorldEdit.getInstance();
ForgePlayer player = wrap((EntityPlayerMP) event.entityPlayer);
ForgeWorld world = getWorld(event.entityPlayer.worldObj);
Action action = event.action;
switch (action) {
case LEFT_CLICK_BLOCK: {
WorldVector pos = new WorldVector(world, event.x, event.y, event.z);
if (we.handleBlockLeftClick(player, pos)) {
event.setCanceled(true);
}
if (we.handleArmSwing(player)) {
event.setCanceled(true);
}
}
case RIGHT_CLICK_BLOCK: {
WorldVector pos = new WorldVector(world, event.x, event.y, event.z);
if (we.handleBlockRightClick(player, pos)) {
event.setCanceled(true);
}
if (we.handleRightClick(player)) {
event.setCanceled(true);
}
}
case RIGHT_CLICK_AIR: {
if (we.handleRightClick(player)) {
event.setCanceled(true);
}
}
}
}
/**
* Get the configuration.
*
* @return the Forge configuration
*/
ForgeConfiguration getConfig() {
return this.config;
}
/**
* Get the WorldEdit proxy for the given player.
*
* @param player the player
* @return the WorldEdit player
*/
public ForgePlayer wrap(EntityPlayerMP player) {
checkNotNull(player);
return new ForgePlayer(player);
}
/**
* Get the session for a player.
*
* @param player the player
* @return the session
*/
public LocalSession getSession(EntityPlayerMP player) {
checkNotNull(player);
return WorldEdit.getInstance().getSessionManager().get(wrap(player));
}
/**
* Get the WorldEdit proxy for the given world.
*
* @param world the world
* @return the WorldEdit world
*/
public ForgeWorld getWorld(World world) {
checkNotNull(world);
return new ForgeWorld(world);
}
/**
* Get the WorldEdit proxy for the platform.
*
* @return the WorldEdit platform
*/
public Platform getPlatform() {
return this.platform;
}
/**
* Get the working directory where WorldEdit's files are stored.
*
* @return the working directory
*/
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.WARNING, "Failed to extract defaults", e);
} finally {
try {
closer.close();
} catch (IOException ignored) {
}
}
}
/**
* Get the version of the WorldEdit-for-Forge implementation.
*
* @return a version string
*/
String getInternalVersion() {
return ForgeWorldEdit.class.getAnnotation(Mod.class).version();
}
}

View File

@ -35,7 +35,7 @@ public class WECUIPacketHandler implements IPacketHandler {
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
if (player instanceof EntityPlayerMP) { if (player instanceof EntityPlayerMP) {
LocalSession session = WorldEditMod.inst.getSession((EntityPlayerMP) player); LocalSession session = ForgeWorldEdit.inst.getSession((EntityPlayerMP) player);
if (session.hasCUISupport()) { if (session.hasCUISupport()) {
return; return;

View File

@ -1,81 +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 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 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());
WorldEditMod.inst.getWorldEdit().handleCommand(WorldEditMod.inst.wrapPlayer((EntityPlayerMP) event.sender), split);
}
}
@ForgeSubscribe
public void onPlayerInteract(PlayerInteractEvent event) {
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);
WorldEdit we = WorldEditMod.inst.getWorldEdit();
PlayerInteractEvent.Action action = event.action;
if (action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
WorldVector pos = new WorldVector(world, event.x, event.y, event.z);
if (we.handleBlockLeftClick(player, pos)) {
event.setCanceled(true);
}
if (we.handleArmSwing(player)) {
event.setCanceled(true);
}
} else if (action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
WorldVector pos = new WorldVector(world, event.x, event.y, event.z);
if (we.handleBlockRightClick(player, pos)) {
event.setCanceled(true);
}
if (we.handleRightClick(player))
event.setCanceled(true);
} else if ((action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR) && (we.handleRightClick(player))) {
event.setCanceled(true);
}
}
}

View File

@ -1,184 +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.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.PlatformRejectionException;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
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.network.NetworkMod;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import java.io.*;
import java.util.jar.JarFile;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
@Mod(modid = "WorldEdit", name = "WorldEdit", version = "%VERSION%")
@NetworkMod(channels="WECUI", packetHandler=WECUIPacketHandler.class)
public class WorldEditMod {
@Instance("WorldEdit")
public static WorldEditMod inst;
protected static Logger logger;
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
private ForgeServerInterface server;
private WorldEdit controller;
private ForgeConfiguration config;
private File workingDir;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
logger = Logger.getLogger(getClass().getAnnotation(Mod.class).modid());
logger.setParent(FMLLog.getLogger());
Logger.getLogger("com.sk89q").setParent(FMLLog.getLogger());
String modVersion = getInternalVersion();
String manifestVersion = WorldEdit.getVersion();
if (!manifestVersion.equalsIgnoreCase(modVersion) && !modVersion.equals("%VERSION%")) {
WorldEdit.setVersion(manifestVersion + " (" + modVersion + ")");
}
this.workingDir = new File(event.getModConfigurationDirectory() + File.separator + "WorldEdit");
this.workingDir.mkdir();
createDefaultConfiguration(event.getSourceFile(), "worldedit.properties");
config = new ForgeConfiguration(this);
config.load();
// PermissionsResolverManager.initialize(this, this.workingDir);
}
@EventHandler
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new WorldEditForgeListener());
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
logger.info("WorldEdit " + WorldEdit.getVersion() + " Loaded");
}
@EventHandler
public void serverStarting(FMLServerStartingEvent event) {
this.server = new ForgeServerInterface(this);
this.controller = WorldEdit.getInstance();
try {
controller.getPlatformManager().register(server);
} catch (PlatformRejectionException e) {
throw new RuntimeException("Failed to register with WorldEdit", e);
}
}
public ForgeConfiguration getConfig() {
return this.config;
}
/*public PermissionsResolverManager getPermissionsResolver() {
return PermissionsResolverManager.getInstance();
}*/
public LocalSession getSession(EntityPlayerMP player) {
return this.controller.getSession(wrapPlayer(player));
}
public LocalWorld getWorld(World world) {
return new ForgeWorld(world);
}
public ForgePlayer wrapPlayer(EntityPlayerMP player) {
return new ForgePlayer(player);
}
public WorldEdit getWorldEdit() {
return this.controller;
}
public ServerInterface getServerInterface() {
return this.server;
}
public File getWorkingDir() {
return this.workingDir;
}
private void createDefaultConfiguration(File jar, String name) {
File actual = new File(getWorkingDir(), name);
if (!actual.exists()) {
InputStream input = null;
JarFile file = null;
try {
file = new JarFile(jar);
ZipEntry copy = file.getEntry("defaults/" + name);
if (copy == null)
throw new FileNotFoundException();
input = file.getInputStream(copy);
} catch (IOException e) {
logger.severe("Unable to read default configuration: " + name);
} finally {
try {
file.close();
} catch (Exception e) {}
}
if (input != null) {
FileOutputStream output = null;
try {
output = new FileOutputStream(actual);
byte[] buf = new byte[8192];
int length = 0;
while ((length = input.read(buf)) > 0) {
output.write(buf, 0, length);
}
logger.info("Default configuration file written: " + name);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (input != null)
input.close();
} catch (IOException e) {
}
try {
if (output != null)
output.close();
} catch (IOException e) {
}
}
}
}
}
String getInternalVersion() {
return WorldEditMod.class.getAnnotation(Mod.class).version();
}
}

View File

@ -1,64 +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.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.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.RegionSelector;
public class CuboidSelection extends RegionSelection {
protected CuboidRegion cuboid;
public CuboidSelection(World world, Location pt1, Location pt2) {
this(world, pt1 == null ? null : pt1.getPosition(), pt2 == null ? null : pt2.getPosition());
}
public CuboidSelection(World world, Vector pt1, Vector pt2) {
super(world);
if (pt1 == null) {
throw new IllegalArgumentException("Null point 1 not permitted");
}
if (pt2 == null) {
throw new IllegalArgumentException("Null point 2 not permitted");
}
CuboidRegionSelector sel = new CuboidRegionSelector(WorldEditMod.inst.getWorld(world));
sel.selectPrimary(pt1);
sel.selectSecondary(pt2);
this.cuboid = sel.getIncompleteRegion();
setRegionSelector(sel);
setRegion(this.cuboid);
}
public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) {
super(world, sel, region);
this.cuboid = region;
}
}

View File

@ -1,59 +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.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.selector.Polygonal2DRegionSelector;
import com.sk89q.worldedit.regions.RegionSelector;
public class Polygonal2DSelection extends RegionSelection {
protected Polygonal2DRegion poly2d;
public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) {
super(world, sel, region);
this.poly2d = region;
}
public Polygonal2DSelection(World world, List points, int minY, int maxY) {
super(world);
LocalWorld lWorld = WorldEditMod.inst.getWorld(world);
minY = Math.min(Math.max(0, minY), world.getActualHeight());
maxY = Math.min(Math.max(0, maxY), world.getActualHeight());
Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector(lWorld, points, minY, maxY);
this.poly2d = sel.getIncompleteRegion();
setRegionSelector(sel);
setRegion(this.poly2d);
}
public List getNativePoints() {
return Collections.unmodifiableList(this.poly2d.getPoints());
}
}

View File

@ -1,106 +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.selections;
import java.lang.ref.WeakReference;
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;
public abstract class RegionSelection implements Selection {
private WeakReference<World> world;
private RegionSelector selector;
private Region region;
public RegionSelection(World world) {
this.world = new WeakReference<World>(world);
}
public RegionSelection(World world, RegionSelector selector, Region region) {
this(world);
this.region = region;
this.selector = selector;
}
protected Region getRegion() {
return this.region;
}
protected void setRegion(Region region) {
this.region = region;
}
public RegionSelector getRegionSelector() {
return this.selector;
}
protected void setRegionSelector(RegionSelector selector) {
this.selector = selector;
}
public Location getMinimumPoint() {
return new Location(WorldEditMod.inst.getWorld(this.world.get()), this.region.getMinimumPoint());
}
public Vector getNativeMinimumPoint() {
return this.region.getMinimumPoint();
}
public Location getMaximumPoint() {
return new Location(WorldEditMod.inst.getWorld(this.world.get()), this.region.getMaximumPoint());
}
public Vector getNativeMaximumPoint() {
return this.region.getMaximumPoint();
}
public World getWorld() {
return this.world.get();
}
public int getArea() {
return this.region.getArea();
}
public int getWidth() {
return this.region.getWidth();
}
public int getHeight() {
return this.region.getHeight();
}
public int getLength() {
return this.region.getLength();
}
public boolean contains(Location pt) {
if (!pt.getWorld().equals(this.world.get())) {
return false;
}
return this.region.contains(new Vector(pt.getPosition()));
}
}

View File

@ -1,50 +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.selections;
import net.minecraft.world.World;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.RegionSelector;
public abstract interface Selection {
public abstract Location getMinimumPoint();
public abstract Vector getNativeMinimumPoint();
public abstract Location getMaximumPoint();
public abstract Vector getNativeMaximumPoint();
public abstract RegionSelector getRegionSelector();
public abstract World getWorld();
public abstract int getArea();
public abstract int getWidth();
public abstract int getHeight();
public abstract int getLength();
public abstract boolean contains(Location paramLocation);
}