2011-01-01 02:36:25 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 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;
|
|
|
|
|
2011-01-16 17:39:11 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2011-03-27 18:12:35 +00:00
|
|
|
import org.bukkit.event.block.Action;
|
2011-01-26 18:52:53 +00:00
|
|
|
import org.bukkit.event.player.PlayerAnimationEvent;
|
|
|
|
import org.bukkit.event.player.PlayerAnimationType;
|
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-01-01 02:36:25 +00:00
|
|
|
import org.bukkit.event.player.PlayerListener;
|
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-02-25 01:14:03 +00:00
|
|
|
import com.sk89q.worldedit.WorldVector;
|
|
|
|
import com.sk89q.worldedit.blocks.BlockID;
|
2011-01-01 02:36:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles all events thrown in relation to a Player
|
|
|
|
*/
|
|
|
|
public class WorldEditPlayerListener extends PlayerListener {
|
|
|
|
/**
|
|
|
|
* Plugin.
|
|
|
|
*/
|
|
|
|
private WorldEditPlugin plugin;
|
|
|
|
|
2011-01-26 18:52:53 +00:00
|
|
|
/**
|
|
|
|
* Called when a player plays an animation, such as an arm swing
|
|
|
|
*
|
|
|
|
* @param event Relevant event details
|
|
|
|
*/
|
|
|
|
|
2011-01-01 02:36:25 +00:00
|
|
|
/**
|
|
|
|
* Construct the object;
|
|
|
|
*
|
|
|
|
* @param plugin
|
|
|
|
*/
|
|
|
|
public WorldEditPlayerListener(WorldEditPlugin plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a player leaves a server
|
|
|
|
*
|
|
|
|
* @param event Relevant event details
|
|
|
|
*/
|
2011-02-18 23:31:09 +00:00
|
|
|
@Override
|
2011-04-01 23:18:40 +00:00
|
|
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
2011-05-02 00:37:05 +00:00
|
|
|
plugin.getWorldEdit().markExpire(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
|
|
|
|
*/
|
2011-02-18 23:31:09 +00:00
|
|
|
@Override
|
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-04-01 23:18:40 +00:00
|
|
|
if (plugin.getWorldEdit().handleCommand(wrapPlayer(event.getPlayer()), split)) {
|
2011-01-08 21:11:03 +00:00
|
|
|
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
|
|
|
|
*/
|
2011-02-18 23:31:09 +00:00
|
|
|
@Override
|
2011-03-27 18:12:35 +00:00
|
|
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
2011-07-23 15:51:31 +00:00
|
|
|
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
|
2011-03-27 18:12:35 +00:00
|
|
|
LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld());
|
|
|
|
WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(),
|
|
|
|
event.getClickedBlock().getY(), event.getClickedBlock().getZ());
|
|
|
|
LocalPlayer player = wrapPlayer(event.getPlayer());
|
2011-07-23 15:51:31 +00:00
|
|
|
|
|
|
|
if (!(event.getAction() == Action.LEFT_CLICK_BLOCK && plugin.getWorldEdit().handleBlockLeftClick(player, pos))) {
|
2011-07-23 15:54:38 +00:00
|
|
|
plugin.getWorldEdit().handleArmSwing(player);
|
2011-07-23 15:51:31 +00:00
|
|
|
}
|
|
|
|
event.setCancelled(true);
|
2011-03-27 18:12:35 +00:00
|
|
|
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
|
|
|
LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld());
|
|
|
|
WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(),
|
|
|
|
event.getClickedBlock().getY(), event.getClickedBlock().getZ());
|
|
|
|
LocalPlayer player = wrapPlayer(event.getPlayer());
|
|
|
|
|
2011-04-01 23:18:40 +00:00
|
|
|
if (plugin.getWorldEdit().handleBlockRightClick(player, pos)) {
|
2011-03-27 18:12:35 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:18:40 +00:00
|
|
|
if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) {
|
2011-03-27 18:12:35 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
} else if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
2011-04-01 23:18:40 +00:00
|
|
|
if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) {
|
2011-03-27 18:12:35 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2011-01-19 10:27:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-03 20:05:41 +00:00
|
|
|
private BukkitPlayer wrapPlayer(Player player) {
|
2011-04-01 23:18:40 +00:00
|
|
|
return new BukkitPlayer(plugin, plugin.getServerInterface(), player);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
}
|