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-01-26 18:52:53 +00:00
|
|
|
import org.bukkit.event.player.PlayerAnimationEvent;
|
|
|
|
import org.bukkit.event.player.PlayerAnimationType;
|
2011-01-01 02:36:25 +00:00
|
|
|
import org.bukkit.event.player.PlayerChatEvent;
|
|
|
|
import org.bukkit.event.player.PlayerEvent;
|
2011-01-19 10:27:12 +00:00
|
|
|
import org.bukkit.event.player.PlayerItemEvent;
|
2011-01-01 02:36:25 +00:00
|
|
|
import org.bukkit.event.player.PlayerListener;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
public void onPlayerAnimation(PlayerAnimationEvent event) {
|
|
|
|
if (event.getAnimationType() == PlayerAnimationType.ARM_SWING) {
|
|
|
|
plugin.controller.handleArmSwing(wrapPlayer(event.getPlayer()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public void onPlayerQuit(PlayerEvent event) {
|
2011-01-03 20:05:41 +00:00
|
|
|
plugin.controller.handleDisconnect(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
|
|
|
|
*/
|
|
|
|
public void onPlayerCommand(PlayerChatEvent event) {
|
2011-01-16 21:19:29 +00:00
|
|
|
String[] split = event.getMessage().split(" ");
|
|
|
|
|
|
|
|
if (plugin.controller.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-01-19 10:27:12 +00:00
|
|
|
/**
|
|
|
|
* Called when a player uses an item
|
|
|
|
*
|
|
|
|
* @param event Relevant event details
|
|
|
|
*/
|
|
|
|
public void onPlayerItem(PlayerItemEvent event) {
|
2011-01-26 18:52:53 +00:00
|
|
|
if (plugin.controller.handleRightClick(wrapPlayer(event.getPlayer()))) {
|
2011-01-19 10:27:12 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-03 20:05:41 +00:00
|
|
|
private BukkitPlayer wrapPlayer(Player player) {
|
2011-01-16 21:19:29 +00:00
|
|
|
return new BukkitPlayer(plugin, plugin.server, player);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
}
|