2011-01-01 02:36:25 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
2012-01-05 21:38:23 +00:00
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
|
2011-01-01 02:36:25 +00:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
import java.io.File;
|
2011-09-29 02:05:22 +00:00
|
|
|
import java.io.FileNotFoundException;
|
2011-01-17 10:52:57 +00:00
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2013-01-19 23:33:23 +00:00
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.jar.JarEntry;
|
2011-09-29 02:05:22 +00:00
|
|
|
import java.util.jar.JarFile;
|
2012-12-27 16:45:37 +00:00
|
|
|
import java.util.logging.Handler;
|
2011-09-29 02:05:22 +00:00
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
2013-01-18 02:49:34 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2011-03-12 08:28:19 +00:00
|
|
|
import org.bukkit.World;
|
2011-01-30 04:38:41 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
2011-01-16 21:19:29 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2011-01-01 02:36:25 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2012-12-27 16:45:37 +00:00
|
|
|
|
|
|
|
import com.sk89q.util.yaml.YAMLProcessor;
|
|
|
|
import com.sk89q.wepif.PermissionsResolverManager;
|
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.IncompleteRegionException;
|
|
|
|
import com.sk89q.worldedit.LocalPlayer;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.ServerInterface;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditOperation;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
2012-12-27 16:45:37 +00:00
|
|
|
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
|
|
|
|
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
|
|
|
|
import com.sk89q.worldedit.bukkit.selections.Selection;
|
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
|
|
|
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
|
|
|
import com.sk89q.worldedit.regions.Region;
|
|
|
|
import com.sk89q.worldedit.regions.RegionSelector;
|
2011-01-01 02:36:25 +00:00
|
|
|
|
2011-01-08 21:03:18 +00:00
|
|
|
/**
|
|
|
|
* Plugin for Bukkit.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-02-22 06:28:23 +00:00
|
|
|
* @author sk89q
|
2011-01-08 21:03:18 +00:00
|
|
|
*/
|
2011-01-01 02:36:25 +00:00
|
|
|
public class WorldEditPlugin extends JavaPlugin {
|
2012-03-28 05:52:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the CUI's plugin channel registration
|
|
|
|
*/
|
|
|
|
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
|
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* The server interface that all server-related API goes through.
|
|
|
|
*/
|
2011-12-25 06:34:53 +00:00
|
|
|
private BukkitServerInterface server;
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Main WorldEdit instance.
|
|
|
|
*/
|
2011-04-01 23:18:40 +00:00
|
|
|
private WorldEdit controller;
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Deprecated API.
|
|
|
|
*/
|
2011-04-01 23:18:40 +00:00
|
|
|
private WorldEditAPI api;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Holds the configuration for WorldEdit.
|
|
|
|
*/
|
2011-02-20 01:54:47 +00:00
|
|
|
private BukkitConfiguration config;
|
2011-01-01 02:36:25 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Called on plugin enable.
|
|
|
|
*/
|
2012-12-27 16:45:37 +00:00
|
|
|
@Override
|
2011-02-20 01:54:47 +00:00
|
|
|
public void onEnable() {
|
2011-11-02 16:10:07 +00:00
|
|
|
final String pluginYmlVersion = getDescription().getVersion();
|
|
|
|
final String manifestVersion = WorldEdit.getVersion();
|
|
|
|
|
|
|
|
if (!manifestVersion.equalsIgnoreCase(pluginYmlVersion)) {
|
|
|
|
WorldEdit.setVersion(manifestVersion + " (" + pluginYmlVersion + ")");
|
|
|
|
}
|
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
// Make the data folders that WorldEdit uses
|
2011-02-20 01:54:47 +00:00
|
|
|
getDataFolder().mkdirs();
|
2013-01-19 23:33:23 +00:00
|
|
|
File targetDir = new File(getDataFolder() + File.separator + "nmsblocks");
|
|
|
|
targetDir.mkdir();
|
|
|
|
copyNmsBlockClasses(targetDir);
|
2011-01-17 10:52:57 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
// Create the default configuration file
|
2011-01-17 10:52:57 +00:00
|
|
|
createDefaultConfiguration("config.yml");
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
// Set up configuration and such, including the permissions
|
|
|
|
// resolver
|
2012-03-28 18:03:59 +00:00
|
|
|
config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this);
|
2011-12-04 17:56:35 +00:00
|
|
|
PermissionsResolverManager.initialize(this);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
// Load the configuration
|
2012-03-02 05:32:33 +00:00
|
|
|
config.load();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
// Setup interfaces
|
2011-02-19 09:22:28 +00:00
|
|
|
server = new BukkitServerInterface(this, getServer());
|
2011-01-26 18:53:26 +00:00
|
|
|
controller = new WorldEdit(server, config);
|
2013-06-22 03:54:28 +00:00
|
|
|
WorldEdit.logger.setParent(Bukkit.getLogger());
|
2011-01-16 17:39:11 +00:00
|
|
|
api = new WorldEditAPI(this);
|
2012-03-28 05:52:48 +00:00
|
|
|
getServer().getMessenger().registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this));
|
|
|
|
getServer().getMessenger().registerOutgoingPluginChannel(this, CUI_PLUGIN_CHANNEL);
|
2011-02-22 06:28:23 +00:00
|
|
|
// Now we can register events!
|
2012-01-18 04:35:34 +00:00
|
|
|
getServer().getPluginManager().registerEvents(new WorldEditListener(this), this);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2013-06-22 03:54:28 +00:00
|
|
|
getServer().getScheduler().runTaskTimerAsynchronously(this,
|
2011-05-02 00:37:05 +00:00
|
|
|
new SessionTimer(controller, getServer()), 120, 120);
|
2013-01-19 23:33:23 +00:00
|
|
|
}
|
2013-01-18 02:49:34 +00:00
|
|
|
|
2013-01-19 23:33:23 +00:00
|
|
|
private void copyNmsBlockClasses(File target) {
|
|
|
|
try {
|
|
|
|
JarFile jar = new JarFile(getFile());
|
2013-06-22 03:54:28 +00:00
|
|
|
@SuppressWarnings("rawtypes")
|
2013-01-19 23:33:23 +00:00
|
|
|
Enumeration entries = jar.entries();
|
|
|
|
while (entries.hasMoreElements()) {
|
|
|
|
JarEntry jarEntry = (JarEntry) entries.nextElement();
|
|
|
|
if (!jarEntry.getName().startsWith("nmsblocks") || jarEntry.isDirectory()) continue;
|
|
|
|
|
|
|
|
File file = new File(target + File.separator + jarEntry.getName().replace("nmsblocks", ""));
|
|
|
|
if (file.exists()) continue;
|
|
|
|
|
|
|
|
InputStream is = jar.getInputStream(jarEntry);
|
|
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
|
|
|
|
|
|
fos = new FileOutputStream(file);
|
|
|
|
byte[] buf = new byte[8192];
|
|
|
|
int length = 0;
|
|
|
|
while ((length = is.read(buf)) > 0) {
|
|
|
|
fos.write(buf, 0, length);
|
|
|
|
}
|
|
|
|
fos.close();
|
|
|
|
is.close();
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {}
|
2011-01-01 03:28:28 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Called on plugin disable.
|
|
|
|
*/
|
2012-12-27 16:45:37 +00:00
|
|
|
@Override
|
2011-01-01 02:36:25 +00:00
|
|
|
public void onDisable() {
|
2011-05-31 03:58:32 +00:00
|
|
|
controller.clearSessions();
|
2012-12-27 16:45:37 +00:00
|
|
|
for (Handler h : controller.commandLogger.getHandlers()) {
|
|
|
|
h.close();
|
|
|
|
}
|
2011-05-08 04:57:08 +00:00
|
|
|
config.unload();
|
2011-12-25 06:34:53 +00:00
|
|
|
server.unregisterCommands();
|
2011-08-07 15:57:32 +00:00
|
|
|
this.getServer().getScheduler().cancelTasks(this);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Loads and reloads all configuration.
|
|
|
|
*/
|
|
|
|
protected void loadConfiguration() {
|
2011-05-08 05:40:20 +00:00
|
|
|
config.unload();
|
2011-02-22 06:28:23 +00:00
|
|
|
config.load();
|
2011-12-04 17:56:35 +00:00
|
|
|
getPermissionsResolver().load();
|
2011-02-22 06:28:23 +00:00
|
|
|
}
|
2011-01-01 02:36:25 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Create a default configuration file from the .jar.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-02-22 06:28:23 +00:00
|
|
|
* @param name
|
|
|
|
*/
|
|
|
|
protected void createDefaultConfiguration(String name) {
|
2011-01-17 10:52:57 +00:00
|
|
|
File actual = new File(getDataFolder(), name);
|
|
|
|
if (!actual.exists()) {
|
|
|
|
InputStream input =
|
2011-09-29 02:05:22 +00:00
|
|
|
null;
|
|
|
|
try {
|
|
|
|
JarFile file = new JarFile(getFile());
|
2011-10-02 08:27:52 +00:00
|
|
|
ZipEntry copy = file.getEntry("defaults/" + name);
|
2011-09-29 02:05:22 +00:00
|
|
|
if (copy == null) throw new FileNotFoundException();
|
|
|
|
input = file.getInputStream(copy);
|
|
|
|
} catch (IOException e) {
|
2012-03-28 18:03:59 +00:00
|
|
|
getLogger().severe("Unable to read default configuration: " + name);
|
2011-09-29 02:05:22 +00:00
|
|
|
}
|
2011-01-17 10:52:57 +00:00
|
|
|
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);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2012-03-28 18:03:59 +00:00
|
|
|
getLogger().info("Default configuration file written: " + name);
|
2011-01-17 10:52:57 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
try {
|
2011-11-23 01:29:48 +00:00
|
|
|
if (input != null) {
|
2011-01-17 10:52:57 +00:00
|
|
|
input.close();
|
2011-11-23 01:29:48 +00:00
|
|
|
}
|
2011-01-17 10:52:57 +00:00
|
|
|
} catch (IOException e) {}
|
|
|
|
|
|
|
|
try {
|
2011-11-23 01:29:48 +00:00
|
|
|
if (output != null) {
|
2011-01-17 10:52:57 +00:00
|
|
|
output.close();
|
2011-11-23 01:29:48 +00:00
|
|
|
}
|
2011-01-17 10:52:57 +00:00
|
|
|
} catch (IOException e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 04:38:41 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Called on WorldEdit command.
|
|
|
|
*/
|
2011-02-18 23:31:09 +00:00
|
|
|
@Override
|
2011-12-15 12:26:59 +00:00
|
|
|
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd,
|
2011-01-30 04:38:41 +00:00
|
|
|
String commandLabel, String[] args) {
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
// Add the command to the array because the underlying command handling
|
|
|
|
// code of WorldEdit expects it
|
2011-01-22 02:24:38 +00:00
|
|
|
String[] split = new String[args.length + 1];
|
|
|
|
System.arraycopy(args, 0, split, 1, args.length);
|
|
|
|
split[0] = "/" + cmd.getName();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-12-15 12:26:59 +00:00
|
|
|
controller.handleCommand(wrapCommandSender(sender), split);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-23 00:34:46 +00:00
|
|
|
return true;
|
2011-01-22 02:24:38 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:12:15 +00:00
|
|
|
/**
|
|
|
|
* Gets the session for the player.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-02-19 05:12:15 +00:00
|
|
|
* @param player
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public LocalSession getSession(Player player) {
|
|
|
|
return controller.getSession(wrapPlayer(player));
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:12:15 +00:00
|
|
|
/**
|
|
|
|
* Gets the session for the player.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-02-19 05:12:15 +00:00
|
|
|
* @param player
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public EditSession createEditSession(Player player) {
|
|
|
|
LocalPlayer wePlayer = wrapPlayer(player);
|
|
|
|
LocalSession session = controller.getSession(wePlayer);
|
|
|
|
BlockBag blockBag = session.getBlockBag(wePlayer);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2012-10-18 10:34:09 +00:00
|
|
|
EditSession editSession = controller.getEditSessionFactory()
|
2012-11-13 10:07:08 +00:00
|
|
|
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer);
|
2011-02-19 05:12:15 +00:00
|
|
|
editSession.enableQueue();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:12:15 +00:00
|
|
|
return editSession;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:12:15 +00:00
|
|
|
/**
|
|
|
|
* Remember an edit session.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-02-19 05:12:15 +00:00
|
|
|
* @param player
|
|
|
|
* @param editSession
|
|
|
|
*/
|
|
|
|
public void remember(Player player, EditSession editSession) {
|
|
|
|
LocalPlayer wePlayer = wrapPlayer(player);
|
|
|
|
LocalSession session = controller.getSession(wePlayer);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:12:15 +00:00
|
|
|
session.remember(editSession);
|
|
|
|
editSession.flushQueue();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:12:15 +00:00
|
|
|
controller.flushBlockBag(wePlayer, editSession);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:12:15 +00:00
|
|
|
/**
|
|
|
|
* Wrap an operation into an EditSession.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-02-19 05:12:15 +00:00
|
|
|
* @param player
|
|
|
|
* @param op
|
|
|
|
* @throws Throwable
|
|
|
|
*/
|
|
|
|
public void perform(Player player, WorldEditOperation op)
|
|
|
|
throws Throwable {
|
|
|
|
LocalPlayer wePlayer = wrapPlayer(player);
|
|
|
|
LocalSession session = controller.getSession(wePlayer);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 05:12:15 +00:00
|
|
|
EditSession editSession = createEditSession(player);
|
|
|
|
try {
|
|
|
|
op.run(session, wePlayer, editSession);
|
|
|
|
} finally {
|
|
|
|
remember(player, editSession);
|
|
|
|
}
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Get the API.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-02-22 06:28:23 +00:00
|
|
|
* @return
|
|
|
|
*/
|
2011-02-19 05:12:15 +00:00
|
|
|
@Deprecated
|
|
|
|
public WorldEditAPI getAPI() {
|
|
|
|
return api;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Returns the configuration used by WorldEdit.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-02-22 06:28:23 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public BukkitConfiguration getLocalConfiguration() {
|
|
|
|
return config;
|
2011-01-16 21:19:29 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Get the permissions resolver in use.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-02-22 06:28:23 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public PermissionsResolverManager getPermissionsResolver() {
|
2011-12-04 17:56:35 +00:00
|
|
|
return PermissionsResolverManager.getInstance();
|
2011-01-16 21:19:29 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 06:28:23 +00:00
|
|
|
/**
|
|
|
|
* Used to wrap a Bukkit Player as a LocalPlayer.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-02-22 06:28:23 +00:00
|
|
|
* @param player
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public BukkitPlayer wrapPlayer(Player player) {
|
2011-01-22 02:24:38 +00:00
|
|
|
return new BukkitPlayer(this, this.server, player);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-12-15 11:02:00 +00:00
|
|
|
public LocalPlayer wrapCommandSender(CommandSender sender) {
|
|
|
|
if (sender instanceof Player) {
|
|
|
|
return wrapPlayer((Player) sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new BukkitCommandSender(this, this.server, sender);
|
|
|
|
}
|
2012-03-02 05:32:33 +00:00
|
|
|
|
2011-04-01 23:18:40 +00:00
|
|
|
/**
|
|
|
|
* Get the server interface.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-04-01 23:18:40 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public ServerInterface getServerInterface() {
|
|
|
|
return server;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-04-01 23:18:40 +00:00
|
|
|
/**
|
|
|
|
* Get WorldEdit.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-04-01 23:18:40 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public WorldEdit getWorldEdit() {
|
|
|
|
return controller;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-03-12 08:28:19 +00:00
|
|
|
/**
|
|
|
|
* Gets the region selection for the player.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-03-12 08:28:19 +00:00
|
|
|
* @param player
|
|
|
|
* @return the selection or null if there was none
|
|
|
|
*/
|
|
|
|
public Selection getSelection(Player player) {
|
2011-04-03 18:03:57 +00:00
|
|
|
if (player == null) {
|
|
|
|
throw new IllegalArgumentException("Null player not allowed");
|
|
|
|
}
|
|
|
|
if (!player.isOnline()) {
|
|
|
|
throw new IllegalArgumentException("Offline player not allowed");
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-03-12 08:28:19 +00:00
|
|
|
LocalSession session = controller.getSession(wrapPlayer(player));
|
2011-12-13 03:20:31 +00:00
|
|
|
RegionSelector selector = session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()));
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-03-12 08:28:19 +00:00
|
|
|
try {
|
|
|
|
Region region = selector.getRegion();
|
|
|
|
World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-03-12 08:28:19 +00:00
|
|
|
if (region instanceof CuboidRegion) {
|
2011-11-23 01:29:48 +00:00
|
|
|
return new CuboidSelection(world, selector, (CuboidRegion) region);
|
2011-03-12 08:28:19 +00:00
|
|
|
} else if (region instanceof Polygonal2DRegion) {
|
2011-11-23 01:29:48 +00:00
|
|
|
return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region);
|
2011-03-12 08:28:19 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (IncompleteRegionException e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-04-03 18:03:57 +00:00
|
|
|
/**
|
|
|
|
* Sets the region selection for a player.
|
2012-03-02 05:32:33 +00:00
|
|
|
*
|
2011-04-03 18:03:57 +00:00
|
|
|
* @param player
|
|
|
|
* @param selection
|
|
|
|
*/
|
|
|
|
public void setSelection(Player player, Selection selection) {
|
|
|
|
if (player == null) {
|
|
|
|
throw new IllegalArgumentException("Null player not allowed");
|
|
|
|
}
|
|
|
|
if (!player.isOnline()) {
|
|
|
|
throw new IllegalArgumentException("Offline player not allowed");
|
|
|
|
}
|
|
|
|
if (selection == null) {
|
|
|
|
throw new IllegalArgumentException("Null selection not allowed");
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
|
|
|
LocalSession session = controller.getSession(wrapPlayer(player));
|
2011-04-03 18:03:57 +00:00
|
|
|
RegionSelector sel = selection.getRegionSelector();
|
2011-12-15 14:44:04 +00:00
|
|
|
session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
|
2011-04-03 18:03:57 +00:00
|
|
|
session.dispatchCUISelection(wrapPlayer(player));
|
|
|
|
}
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|