geforkt von Mirrors/FastAsyncWorldEdit
Add a com.sk89q.worldedit.bukkit.WorldEditPlugin.getSelection(Player player) method to return the user's current selection utilizing native Bukkit types.
Dieser Commit ist enthalten in:
Ursprung
5e536ad302
Commit
3b29403a9b
@ -232,6 +232,15 @@ public class LocalSession {
|
|||||||
return selector.getRegion();
|
return selector.getRegion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the selection world.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public LocalWorld getSelectionWorld() {
|
||||||
|
return selectionWorld;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the clipboard.
|
* Gets the clipboard.
|
||||||
*
|
*
|
||||||
|
@ -24,6 +24,7 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -37,7 +38,8 @@ import com.sk89q.bukkit.migration.PermissionsResolverManager;
|
|||||||
import com.sk89q.bukkit.migration.PermissionsResolverServerListener;
|
import com.sk89q.bukkit.migration.PermissionsResolverServerListener;
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
import com.sk89q.worldedit.bags.BlockBag;
|
import com.sk89q.worldedit.bags.BlockBag;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.bukkit.selections.*;
|
||||||
|
import com.sk89q.worldedit.regions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin for Bukkit.
|
* Plugin for Bukkit.
|
||||||
@ -246,19 +248,6 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
return controller.getSession(wrapPlayer(player));
|
return controller.getSession(wrapPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the region selection for the player.
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* @return
|
|
||||||
* @throws IncompleteRegionException
|
|
||||||
*/
|
|
||||||
public Region getPlayerSelection(Player player)
|
|
||||||
throws IncompleteRegionException {
|
|
||||||
return controller.getSession(wrapPlayer(player))
|
|
||||||
.getSelection(new BukkitWorld(player.getWorld()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the session for the player.
|
* Gets the session for the player.
|
||||||
*
|
*
|
||||||
@ -351,4 +340,30 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
public BukkitPlayer wrapPlayer(Player player) {
|
public BukkitPlayer wrapPlayer(Player player) {
|
||||||
return new BukkitPlayer(this, this.server, player);
|
return new BukkitPlayer(this, this.server, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the region selection for the player.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @return the selection or null if there was none
|
||||||
|
*/
|
||||||
|
public Selection getSelection(Player player) {
|
||||||
|
LocalSession session = controller.getSession(wrapPlayer(player));
|
||||||
|
RegionSelector selector = session.getRegionSelector();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Region region = selector.getRegion();
|
||||||
|
World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();
|
||||||
|
|
||||||
|
if (region instanceof CuboidRegion) {
|
||||||
|
return new CuboidSelection(world, (CuboidRegion)region);
|
||||||
|
} else if (region instanceof Polygonal2DRegion) {
|
||||||
|
return new Polygonal2DSelection(world, (Polygonal2DRegion)region);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (IncompleteRegionException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
34
src/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java
Normale Datei
34
src/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java
Normale Datei
@ -0,0 +1,34 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.bukkit.selections;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
import com.sk89q.worldedit.regions.*;
|
||||||
|
|
||||||
|
public class CuboidSelection extends RegionSelection {
|
||||||
|
|
||||||
|
protected CuboidRegion cuboid;
|
||||||
|
|
||||||
|
public CuboidSelection(World world, CuboidRegion region) {
|
||||||
|
super(world, region);
|
||||||
|
this.world = world;
|
||||||
|
this.cuboid = region;
|
||||||
|
}
|
||||||
|
}
|
34
src/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java
Normale Datei
34
src/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java
Normale Datei
@ -0,0 +1,34 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.bukkit.selections;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
import com.sk89q.worldedit.regions.*;
|
||||||
|
|
||||||
|
public class Polygonal2DSelection extends RegionSelection {
|
||||||
|
|
||||||
|
protected Polygonal2DRegion poly2d;
|
||||||
|
|
||||||
|
public Polygonal2DSelection(World world, Polygonal2DRegion region) {
|
||||||
|
super(world, region);
|
||||||
|
this.world = world;
|
||||||
|
this.poly2d = region;
|
||||||
|
}
|
||||||
|
}
|
82
src/com/sk89q/worldedit/bukkit/selections/RegionSelection.java
Normale Datei
82
src/com/sk89q/worldedit/bukkit/selections/RegionSelection.java
Normale Datei
@ -0,0 +1,82 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.bukkit.selections;
|
||||||
|
|
||||||
|
import static com.sk89q.worldedit.bukkit.BukkitUtil.toLocation;
|
||||||
|
import static com.sk89q.worldedit.bukkit.BukkitUtil.toVector;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
|
|
||||||
|
public abstract class RegionSelection implements Selection {
|
||||||
|
|
||||||
|
protected World world;
|
||||||
|
protected Region region;
|
||||||
|
|
||||||
|
public RegionSelection(World world, Region region) {
|
||||||
|
this.world = world;
|
||||||
|
this.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getMinimumPoint() {
|
||||||
|
return toLocation(world, region.getMinimumPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getMaximumPoint() {
|
||||||
|
return toLocation(world, region.getMaximumPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public World getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getArea() {
|
||||||
|
return region.getArea();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidth() {
|
||||||
|
return region.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHeight() {
|
||||||
|
return region.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLength() {
|
||||||
|
return region.getLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Location pt) {
|
||||||
|
if (!pt.getWorld().equals(world)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return region.contains(toVector(pt));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
82
src/com/sk89q/worldedit/bukkit/selections/Selection.java
Normale Datei
82
src/com/sk89q/worldedit/bukkit/selections/Selection.java
Normale Datei
@ -0,0 +1,82 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.bukkit.selections;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
public interface Selection {
|
||||||
|
/**
|
||||||
|
* Get the lower point of a region.
|
||||||
|
*
|
||||||
|
* @return min. point
|
||||||
|
*/
|
||||||
|
public Location getMinimumPoint();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the upper point of a region.
|
||||||
|
*
|
||||||
|
* @return max. point
|
||||||
|
*/
|
||||||
|
public Location getMaximumPoint();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the world.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public World getWorld();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of blocks in the region.
|
||||||
|
*
|
||||||
|
* @return number of blocks
|
||||||
|
*/
|
||||||
|
public int getArea();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get X-size.
|
||||||
|
*
|
||||||
|
* @return width
|
||||||
|
*/
|
||||||
|
public int getWidth();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Y-size.
|
||||||
|
*
|
||||||
|
* @return height
|
||||||
|
*/
|
||||||
|
public int getHeight();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Z-size.
|
||||||
|
*
|
||||||
|
* @return length
|
||||||
|
*/
|
||||||
|
public int getLength();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true based on whether the region contains the point,
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean contains(Location pt);
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren