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;
|
|
|
|
|
|
|
|
import org.bukkit.*;
|
2011-01-18 05:05:05 +00:00
|
|
|
import org.bukkit.block.Block;
|
2011-01-16 17:39:11 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2011-01-01 02:36:25 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
|
|
|
import com.sk89q.worldedit.bags.BlockBag;
|
2011-01-18 05:05:05 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BlockType;
|
2011-01-01 02:36:25 +00:00
|
|
|
|
2011-01-03 20:05:41 +00:00
|
|
|
public class BukkitPlayer extends LocalPlayer {
|
2011-01-01 02:36:25 +00:00
|
|
|
private Player player;
|
2011-01-16 21:19:29 +00:00
|
|
|
private WorldEditPlugin plugin;
|
2011-01-01 02:36:25 +00:00
|
|
|
|
2011-01-16 21:19:29 +00:00
|
|
|
public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
|
2011-01-03 20:05:41 +00:00
|
|
|
super(server);
|
2011-01-16 21:19:29 +00:00
|
|
|
this.plugin = plugin;
|
2011-01-01 02:36:25 +00:00
|
|
|
this.player = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-01-03 20:05:41 +00:00
|
|
|
public WorldVector getBlockTrace(int range) {
|
2011-01-18 05:05:05 +00:00
|
|
|
TargetBlock tb = new TargetBlock(player, range, 0.2);
|
|
|
|
Block block = tb.getTargetBlock();
|
|
|
|
if (block == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return new WorldVector(getWorld(), block.getX(), block.getY(), block.getZ());
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-01-03 20:05:41 +00:00
|
|
|
public WorldVector getSolidBlockTrace(int range) {
|
2011-01-18 05:05:05 +00:00
|
|
|
TargetBlock tb = new TargetBlock(player, range, 0.2);
|
|
|
|
tb.reset();
|
|
|
|
while (tb.getNextBlock() != null
|
|
|
|
&& BlockType.canPassThrough(tb.getCurrentBlock().getTypeId()));
|
|
|
|
Block block = tb.getCurrentBlock();
|
|
|
|
if (block == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return new WorldVector(getWorld(), block.getX(), block.getY(), block.getZ());
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemInHand() {
|
2011-01-09 19:43:47 +00:00
|
|
|
ItemStack itemStack = player.getItemInHand();
|
2011-01-16 17:39:11 +00:00
|
|
|
return itemStack != null ? itemStack.getTypeId() : 0;
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return player.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-01-03 20:05:41 +00:00
|
|
|
public WorldVector getPosition() {
|
2011-01-01 02:36:25 +00:00
|
|
|
Location loc = player.getLocation();
|
2011-01-03 20:05:41 +00:00
|
|
|
return new WorldVector(new BukkitWorld(loc.getWorld()),
|
|
|
|
loc.getX(), loc.getY(), loc.getZ());
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getPitch() {
|
|
|
|
return player.getLocation().getPitch();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getYaw() {
|
|
|
|
return player.getLocation().getYaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void giveItem(int type, int amt) {
|
2011-01-08 21:03:18 +00:00
|
|
|
player.getWorld().dropItem(player.getLocation(), new ItemStack(type, amt));
|
2011-01-18 05:05:05 +00:00
|
|
|
// TODO: Make this actually give the item
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean passThroughForwardWall(int range) {
|
2011-01-18 05:05:05 +00:00
|
|
|
boolean foundNext = false;
|
|
|
|
int searchDist = 0;
|
|
|
|
TargetBlock hitBlox = new TargetBlock(player, range, 0.2);
|
|
|
|
LocalWorld world = getPosition().getWorld();
|
|
|
|
Block block;
|
|
|
|
while ((block = hitBlox.getNextBlock()) != null) {
|
|
|
|
searchDist++;
|
|
|
|
if (searchDist > 20) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (BlockType.canPassThrough(block.getTypeId())) {
|
|
|
|
if (foundNext) {
|
|
|
|
Vector v = new Vector(block.getX(), block.getY() - 1, block.getZ());
|
|
|
|
if (BlockType.canPassThrough(world.getBlockType(v))) {
|
|
|
|
setPosition(v.add(0.5, 0, 0.5));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foundNext = true;
|
|
|
|
}
|
|
|
|
}
|
2011-01-01 02:36:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void printRaw(String msg) {
|
|
|
|
player.sendMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void print(String msg) {
|
2011-01-08 21:07:50 +00:00
|
|
|
player.sendMessage("\u00A7d" + msg);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void printError(String msg) {
|
2011-01-08 21:07:50 +00:00
|
|
|
player.sendMessage("\u00A7c" + msg);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPosition(Vector pos, float pitch, float yaw) {
|
2011-01-08 21:03:18 +00:00
|
|
|
player.teleportTo(new Location(player.getWorld(), pos.getX(), pos.getY(),
|
|
|
|
pos.getZ(), yaw, pitch));
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String[] getGroups() {
|
2011-01-16 21:19:29 +00:00
|
|
|
return plugin.getGroups(player);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockBag getInventoryBlockBag() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPermission(String perm) {
|
2011-01-16 21:19:29 +00:00
|
|
|
return plugin.hasPermission(player, "/" + perm);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
2011-01-03 20:05:41 +00:00
|
|
|
@Override
|
|
|
|
public LocalWorld getWorld() {
|
2011-01-04 20:21:35 +00:00
|
|
|
return new BukkitWorld(player.getWorld());
|
2011-01-03 20:05:41 +00:00
|
|
|
}
|
|
|
|
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|