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;
|
|
|
|
|
2011-12-25 23:36:23 +00:00
|
|
|
import org.bukkit.Location;
|
2011-01-16 17:39:11 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2011-03-12 06:43:02 +00:00
|
|
|
import com.sk89q.util.StringUtil;
|
2011-01-01 02:36:25 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
|
|
|
import com.sk89q.worldedit.bags.BlockBag;
|
2011-03-12 06:43:02 +00:00
|
|
|
import com.sk89q.worldedit.cui.CUIEvent;
|
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-11-23 01:29:48 +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
|
|
|
|
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-12-15 14:44:04 +00:00
|
|
|
return new WorldVector(BukkitUtil.getLocalWorld(loc.getWorld()),
|
2011-01-03 20:05:41 +00:00
|
|
|
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-02-19 04:56:53 +00:00
|
|
|
player.getInventory().addItem(new ItemStack(type, amt));
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void printRaw(String msg) {
|
2011-12-05 09:33:13 +00:00
|
|
|
for (String part : msg.split("\n")) {
|
|
|
|
player.sendMessage(part);
|
|
|
|
}
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void print(String msg) {
|
2011-12-05 09:33:13 +00:00
|
|
|
for (String part : msg.split("\n")) {
|
|
|
|
player.sendMessage("\u00A7d" + part);
|
|
|
|
}
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
2011-02-01 07:51:55 +00:00
|
|
|
@Override
|
|
|
|
public void printDebug(String msg) {
|
2011-12-05 09:33:13 +00:00
|
|
|
for (String part : msg.split("\n")) {
|
|
|
|
player.sendMessage("\u00A77" + part);
|
|
|
|
}
|
2011-02-01 07:51:55 +00:00
|
|
|
}
|
|
|
|
|
2011-01-01 02:36:25 +00:00
|
|
|
@Override
|
|
|
|
public void printError(String msg) {
|
2011-12-05 09:33:13 +00:00
|
|
|
for (String part : msg.split("\n")) {
|
|
|
|
player.sendMessage("\u00A7c" + part);
|
|
|
|
}
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPosition(Vector pos, float pitch, float yaw) {
|
2011-03-27 18:12:35 +00:00
|
|
|
player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(),
|
2011-01-08 21:03:18 +00:00
|
|
|
pos.getZ(), yaw, pitch));
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String[] getGroups() {
|
2011-12-04 17:56:35 +00:00
|
|
|
return plugin.getPermissionsResolver().getGroups(player);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockBag getInventoryBlockBag() {
|
2011-01-18 05:11:39 +00:00
|
|
|
return new BukkitPlayerBlockBag(player);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPermission(String perm) {
|
2011-02-22 06:28:23 +00:00
|
|
|
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
|
2011-06-09 04:16:39 +00:00
|
|
|
|| plugin.getPermissionsResolver().hasPermission(
|
2011-12-04 17:56:35 +00:00
|
|
|
player.getWorld().getName(), player, perm);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
2011-01-03 20:05:41 +00:00
|
|
|
@Override
|
|
|
|
public LocalWorld getWorld() {
|
2011-12-15 14:44:04 +00:00
|
|
|
return BukkitUtil.getLocalWorld(player.getWorld());
|
2011-01-03 20:05:41 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
@Override
|
|
|
|
public void dispatchCUIEvent(CUIEvent event) {
|
|
|
|
String[] params = event.getParameters();
|
2012-03-28 05:52:48 +00:00
|
|
|
String send = event.getTypeId();
|
2011-03-12 06:43:02 +00:00
|
|
|
if (params.length > 0) {
|
2012-03-28 05:52:48 +00:00
|
|
|
send = send + "|" + StringUtil.joinString(params, "|");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plugin.hasPluginChannelCUI(getName())) {
|
|
|
|
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
|
2011-03-12 06:43:02 +00:00
|
|
|
} else {
|
2012-04-07 10:15:42 +00:00
|
|
|
if (plugin.getLocalConfiguration().enableWECUI) {
|
|
|
|
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + send);
|
|
|
|
}
|
2011-03-12 06:43:02 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
@Override
|
|
|
|
public void dispatchCUIHandshake() {
|
2012-04-07 10:15:42 +00:00
|
|
|
if (!plugin.hasPluginChannelCUI(getName()) && plugin.getLocalConfiguration().enableWECUI) {
|
2012-03-28 05:52:48 +00:00
|
|
|
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75");
|
|
|
|
player.sendRawMessage("\u00A74\u00A75\u00A73\u00A74");
|
|
|
|
}
|
2011-03-12 06:43:02 +00:00
|
|
|
}
|
2011-09-05 02:00:32 +00:00
|
|
|
|
|
|
|
public Player getPlayer() {
|
|
|
|
return player;
|
|
|
|
}
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|