2011-01-01 02:36:25 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit
|
2012-01-23 05:11:54 +00:00
|
|
|
* Copyright (C) 2012 sk89q <http://www.sk89q.com>
|
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/>.
|
2012-01-18 04:35:34 +00:00
|
|
|
*/
|
2012-01-23 05:11:54 +00:00
|
|
|
|
|
|
|
// $Id$
|
|
|
|
|
2011-01-01 02:36:25 +00:00
|
|
|
package com.sk89q.worldedit.bukkit;
|
|
|
|
|
2011-12-25 06:34:53 +00:00
|
|
|
import com.sk89q.util.StringUtil;
|
2011-11-16 15:54:05 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2011-11-13 14:13:59 +00:00
|
|
|
import org.bukkit.block.Block;
|
2012-01-18 04:35:34 +00:00
|
|
|
import org.bukkit.event.Event.Result;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
2011-12-25 04:46:35 +00:00
|
|
|
import org.bukkit.event.block.Action;
|
2011-04-01 23:18:40 +00:00
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
2011-03-27 18:12:35 +00:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
2011-04-01 23:18:40 +00:00
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
2011-02-25 01:14:03 +00:00
|
|
|
import com.sk89q.worldedit.LocalPlayer;
|
2011-03-27 18:12:35 +00:00
|
|
|
import com.sk89q.worldedit.LocalWorld;
|
2011-11-13 14:13:59 +00:00
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
2011-02-25 01:14:03 +00:00
|
|
|
import com.sk89q.worldedit.WorldVector;
|
2011-01-01 02:36:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles all events thrown in relation to a Player
|
|
|
|
*/
|
2012-01-18 04:35:34 +00:00
|
|
|
public class WorldEditListener implements Listener {
|
2012-03-21 00:53:15 +00:00
|
|
|
|
2011-01-01 02:36:25 +00:00
|
|
|
private WorldEditPlugin plugin;
|
2012-01-01 04:16:39 +00:00
|
|
|
private boolean ignoreLeftClickAir = false;
|
2011-11-13 14:13:59 +00:00
|
|
|
|
2011-01-26 18:52:53 +00:00
|
|
|
/**
|
|
|
|
* Called when a player plays an animation, such as an arm swing
|
2012-03-21 00:53:15 +00:00
|
|
|
*
|
2011-01-26 18:52:53 +00:00
|
|
|
* @param event Relevant event details
|
|
|
|
*/
|
2011-11-13 14:13:59 +00:00
|
|
|
|
2011-01-01 02:36:25 +00:00
|
|
|
/**
|
|
|
|
* Construct the object;
|
2012-03-21 00:53:15 +00:00
|
|
|
*
|
2011-01-01 02:36:25 +00:00
|
|
|
* @param plugin
|
|
|
|
*/
|
2012-01-18 04:35:34 +00:00
|
|
|
public WorldEditListener(WorldEditPlugin plugin) {
|
2011-01-01 02:36:25 +00:00
|
|
|
this.plugin = plugin;
|
2012-01-18 04:35:34 +00:00
|
|
|
}
|
2011-08-21 21:05:03 +00:00
|
|
|
|
2011-01-01 02:36:25 +00:00
|
|
|
/**
|
|
|
|
* Called when a player leaves a server
|
|
|
|
*
|
|
|
|
* @param event Relevant event details
|
|
|
|
*/
|
2012-01-19 23:21:18 +00:00
|
|
|
@EventHandler
|
2011-04-01 23:18:40 +00:00
|
|
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
2011-12-06 15:45:07 +00:00
|
|
|
plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer()));
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a player attempts to use a command
|
|
|
|
*
|
|
|
|
* @param event Relevant event details
|
|
|
|
*/
|
2012-03-21 00:53:15 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2011-04-01 23:18:40 +00:00
|
|
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
2011-01-16 21:19:29 +00:00
|
|
|
String[] split = event.getMessage().split(" ");
|
2011-11-13 14:13:59 +00:00
|
|
|
|
2011-12-25 06:34:53 +00:00
|
|
|
if (split.length > 0) {
|
|
|
|
split = plugin.getWorldEdit().commandDetection(split);
|
2012-01-06 16:39:20 +00:00
|
|
|
split[0] = "/" + split[0];
|
2011-01-08 21:11:03 +00:00
|
|
|
}
|
2012-03-21 00:53:15 +00:00
|
|
|
|
2012-02-11 21:59:42 +00:00
|
|
|
final String newMessage = StringUtil.joinString(split, " ");
|
|
|
|
|
|
|
|
if (!newMessage.equals(event.getMessage())) {
|
|
|
|
event.setMessage(newMessage);
|
|
|
|
plugin.getServer().getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
if (event.getMessage().length() > 0) {
|
2012-03-21 00:53:15 +00:00
|
|
|
plugin.getServer().dispatchCommand(event.getPlayer(),
|
2012-02-11 21:59:42 +00:00
|
|
|
event.getMessage().substring(1));
|
|
|
|
}
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2011-01-03 20:05:41 +00:00
|
|
|
}
|
2011-03-27 18:12:35 +00:00
|
|
|
|
2011-01-19 10:27:12 +00:00
|
|
|
/**
|
2011-03-27 18:12:35 +00:00
|
|
|
* Called when a player interacts
|
|
|
|
*
|
2011-01-19 10:27:12 +00:00
|
|
|
* @param event Relevant event details
|
|
|
|
*/
|
2012-01-19 23:21:18 +00:00
|
|
|
@EventHandler
|
2011-03-27 18:12:35 +00:00
|
|
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
2012-01-18 04:35:34 +00:00
|
|
|
if (event.useItemInHand() == Result.DENY) {
|
2011-12-06 15:45:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-21 00:53:15 +00:00
|
|
|
|
2011-12-06 15:45:07 +00:00
|
|
|
final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
|
2011-11-13 14:13:59 +00:00
|
|
|
final LocalWorld world = player.getWorld();
|
|
|
|
final WorldEdit we = plugin.getWorldEdit();
|
|
|
|
|
2011-12-25 04:46:35 +00:00
|
|
|
Action action = event.getAction();
|
|
|
|
if (action == Action.LEFT_CLICK_BLOCK) {
|
2011-11-13 14:13:59 +00:00
|
|
|
final Block clickedBlock = event.getClickedBlock();
|
|
|
|
final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
|
|
|
|
clickedBlock.getY(), clickedBlock.getZ());
|
2011-08-17 01:39:07 +00:00
|
|
|
|
2011-11-13 14:13:59 +00:00
|
|
|
if (we.handleBlockLeftClick(player, pos)) {
|
2011-08-17 01:39:07 +00:00
|
|
|
event.setCancelled(true);
|
2011-08-06 14:22:02 +00:00
|
|
|
}
|
|
|
|
|
2011-11-13 14:13:59 +00:00
|
|
|
if (we.handleArmSwing(player)) {
|
2011-07-23 16:34:28 +00:00
|
|
|
event.setCancelled(true);
|
2011-08-06 14:22:02 +00:00
|
|
|
}
|
2011-11-16 15:54:05 +00:00
|
|
|
|
|
|
|
if (!ignoreLeftClickAir) {
|
2011-11-23 01:29:48 +00:00
|
|
|
final int taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
ignoreLeftClickAir = false;
|
|
|
|
}
|
|
|
|
}, 2);
|
2011-11-16 15:54:05 +00:00
|
|
|
|
|
|
|
if (taskId != -1) {
|
|
|
|
ignoreLeftClickAir = true;
|
|
|
|
}
|
|
|
|
}
|
2011-12-25 04:46:35 +00:00
|
|
|
} else if (action == Action.LEFT_CLICK_AIR) {
|
2011-11-16 15:54:05 +00:00
|
|
|
if (ignoreLeftClickAir) {
|
2011-12-25 04:46:35 +00:00
|
|
|
return;
|
2011-11-16 15:54:05 +00:00
|
|
|
}
|
|
|
|
|
2011-11-13 14:13:59 +00:00
|
|
|
if (we.handleArmSwing(player)) {
|
2011-07-23 16:34:28 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2011-11-16 15:54:05 +00:00
|
|
|
|
2011-11-13 14:13:59 +00:00
|
|
|
|
2011-12-25 04:46:35 +00:00
|
|
|
} else if (action == Action.RIGHT_CLICK_BLOCK) {
|
2011-11-13 14:13:59 +00:00
|
|
|
final Block clickedBlock = event.getClickedBlock();
|
|
|
|
final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
|
|
|
|
clickedBlock.getY(), clickedBlock.getZ());
|
|
|
|
|
|
|
|
if (we.handleBlockRightClick(player, pos)) {
|
2011-03-27 18:12:35 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2011-08-06 14:22:02 +00:00
|
|
|
|
2011-11-13 14:13:59 +00:00
|
|
|
if (we.handleRightClick(player)) {
|
2011-03-27 18:12:35 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2011-12-25 04:46:35 +00:00
|
|
|
} else if (action == Action.RIGHT_CLICK_AIR) {
|
2011-11-13 14:13:59 +00:00
|
|
|
if (we.handleRightClick(player)) {
|
2011-07-23 16:34:28 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2011-01-19 10:27:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|