mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-09-06 15:58:20 +00:00
- so certain people can look at the diff and complain about my sloppy code :( Signed-off-by: Jesse Boyd <jessepaleg@gmail.com>
244 lines
7.2 KiB
Java
244 lines
7.2 KiB
Java
/*
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
* Copyright (C) WorldEdit team and contributors
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
* under the terms of the GNU Lesser 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 Lesser General Public License
|
|
* for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package com.sk89q.worldedit.bukkit;
|
|
|
|
import com.sk89q.util.StringUtil;
|
|
import com.sk89q.worldedit.Vector;
|
|
import com.sk89q.worldedit.WorldEditException;
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
import com.sk89q.worldedit.world.block.BlockState;
|
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
|
import com.sk89q.worldedit.entity.BaseEntity;
|
|
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
|
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
|
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
|
import com.sk89q.worldedit.session.SessionKey;
|
|
import com.sk89q.worldedit.util.HandSide;
|
|
import com.sk89q.worldedit.world.World;
|
|
import com.sk89q.worldedit.world.gamemode.GameMode;
|
|
import com.sk89q.worldedit.world.gamemode.GameModes;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import java.util.UUID;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
public class BukkitPlayer extends AbstractPlayerActor {
|
|
|
|
private Player player;
|
|
private WorldEditPlugin plugin;
|
|
|
|
public BukkitPlayer(WorldEditPlugin plugin, Player player) {
|
|
this.plugin = plugin;
|
|
this.player = player;
|
|
}
|
|
|
|
@Override
|
|
public UUID getUniqueId() {
|
|
return player.getUniqueId();
|
|
}
|
|
|
|
@Override
|
|
public BaseItemStack getItemInHand(HandSide handSide) {
|
|
ItemStack itemStack = handSide == HandSide.MAIN_HAND
|
|
? player.getInventory().getItemInMainHand()
|
|
: player.getInventory().getItemInOffHand();
|
|
return BukkitAdapter.adapt(itemStack);
|
|
}
|
|
|
|
@Override
|
|
public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException {
|
|
ItemStack itemStack = handSide == HandSide.MAIN_HAND
|
|
? player.getInventory().getItemInMainHand()
|
|
: player.getInventory().getItemInOffHand();
|
|
return new BaseBlock(BukkitAdapter.asBlockState(itemStack));
|
|
}
|
|
|
|
@Override
|
|
public String getName() {
|
|
return player.getName();
|
|
}
|
|
|
|
@Override
|
|
public void giveItem(BaseItemStack itemStack) {
|
|
player.getInventory().addItem(BukkitAdapter.adapt(itemStack));
|
|
}
|
|
|
|
@Override
|
|
public void printRaw(String msg) {
|
|
for (String part : msg.split("\n")) {
|
|
player.sendMessage(part);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void print(String msg) {
|
|
for (String part : msg.split("\n")) {
|
|
player.sendMessage("\u00A7d" + part);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void printDebug(String msg) {
|
|
for (String part : msg.split("\n")) {
|
|
player.sendMessage("\u00A77" + part);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void printError(String msg) {
|
|
for (String part : msg.split("\n")) {
|
|
player.sendMessage("\u00A7c" + part);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void setPosition(Vector pos, float pitch, float yaw) {
|
|
player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(),
|
|
pos.getZ(), yaw, pitch));
|
|
}
|
|
|
|
@Override
|
|
public String[] getGroups() {
|
|
return plugin.getPermissionsResolver().getGroups(player);
|
|
}
|
|
|
|
@Override
|
|
public BlockBag getInventoryBlockBag() {
|
|
return new BukkitPlayerBlockBag(player);
|
|
}
|
|
|
|
@Override
|
|
public GameMode getGameMode() {
|
|
return GameModes.get(player.getGameMode().name().toLowerCase());
|
|
}
|
|
|
|
@Override
|
|
public void setGameMode(GameMode gameMode) {
|
|
player.setGameMode(org.bukkit.GameMode.valueOf(gameMode.getId().toUpperCase()));
|
|
}
|
|
|
|
@Override
|
|
public boolean hasPermission(String perm) {
|
|
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
|
|
|| plugin.getPermissionsResolver().hasPermission(
|
|
player.getWorld().getName(), player, perm);
|
|
}
|
|
|
|
@Override
|
|
public World getWorld() {
|
|
return BukkitAdapter.adapt(player.getWorld());
|
|
}
|
|
|
|
@Override
|
|
public void dispatchCUIEvent(CUIEvent event) {
|
|
String[] params = event.getParameters();
|
|
String send = event.getTypeId();
|
|
if (params.length > 0) {
|
|
send = send + "|" + StringUtil.joinString(params, "|");
|
|
}
|
|
player.sendPluginMessage(plugin, WorldEditPlugin.getCuiPluginChannel(), send.getBytes(CUIChannelListener.UTF_8_CHARSET));
|
|
}
|
|
|
|
public Player getPlayer() {
|
|
return player;
|
|
}
|
|
|
|
@Override
|
|
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
|
|
if (alwaysGlass || !player.getAllowFlight()) {
|
|
super.floatAt(x, y, z, alwaysGlass);
|
|
return;
|
|
}
|
|
|
|
setPosition(new Vector(x + 0.5, y, z + 0.5));
|
|
player.setFlying(true);
|
|
}
|
|
|
|
@Override
|
|
public BaseEntity getState() {
|
|
throw new UnsupportedOperationException("Cannot create a state from this object");
|
|
}
|
|
|
|
@Override
|
|
public com.sk89q.worldedit.util.Location getLocation() {
|
|
Location nativeLocation = player.getLocation();
|
|
Vector position = BukkitAdapter.asVector(nativeLocation);
|
|
return new com.sk89q.worldedit.util.Location(
|
|
getWorld(),
|
|
position,
|
|
nativeLocation.getYaw(),
|
|
nativeLocation.getPitch());
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public <T> T getFacet(Class<? extends T> cls) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public SessionKey getSessionKey() {
|
|
return new SessionKeyImpl(this.player.getUniqueId(), player.getName());
|
|
}
|
|
|
|
private static class SessionKeyImpl implements SessionKey {
|
|
// If not static, this will leak a reference
|
|
|
|
private final UUID uuid;
|
|
private final String name;
|
|
|
|
private SessionKeyImpl(UUID uuid, String name) {
|
|
this.uuid = uuid;
|
|
this.name = name;
|
|
}
|
|
|
|
@Override
|
|
public UUID getUniqueId() {
|
|
return uuid;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
@Override
|
|
public boolean isActive() {
|
|
// This is a thread safe call on CraftBukkit because it uses a
|
|
// CopyOnWrite list for the list of players, but the Bukkit
|
|
// specification doesn't require thread safety (though the
|
|
// spec is extremely incomplete)
|
|
return Bukkit.getServer().getPlayer(uuid) != null;
|
|
}
|
|
|
|
@Override
|
|
public boolean isPersistent() {
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
}
|