2014-04-04 22:03:18 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2013-02-24 20:16:12 +00:00
|
|
|
package com.sk89q.worldedit.forge;
|
|
|
|
|
2014-04-06 19:07:10 +00:00
|
|
|
import com.sk89q.util.StringUtil;
|
2014-04-06 22:06:38 +00:00
|
|
|
import com.sk89q.worldedit.Vector;
|
|
|
|
import com.sk89q.worldedit.WorldVector;
|
2014-04-28 06:34:39 +00:00
|
|
|
import com.sk89q.worldedit.entity.BaseEntity;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
|
2014-04-06 19:07:10 +00:00
|
|
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
2014-04-06 22:06:38 +00:00
|
|
|
import com.sk89q.worldedit.internal.LocalWorldAdapter;
|
2014-04-06 19:07:10 +00:00
|
|
|
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
2014-07-28 03:44:05 +00:00
|
|
|
import com.sk89q.worldedit.session.SessionKey;
|
2014-04-27 02:48:21 +00:00
|
|
|
import com.sk89q.worldedit.util.Location;
|
2014-10-12 19:27:51 +00:00
|
|
|
|
2013-02-25 06:22:05 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2014-10-12 19:27:51 +00:00
|
|
|
import net.minecraft.item.Item;
|
2013-02-25 06:22:05 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-10-12 19:27:51 +00:00
|
|
|
import net.minecraft.network.play.server.S3FPacketCustomPayload;
|
|
|
|
import net.minecraft.util.ChatComponentText;
|
2013-02-25 06:22:05 +00:00
|
|
|
|
2014-07-16 02:47:47 +00:00
|
|
|
import javax.annotation.Nullable;
|
2014-10-12 19:27:51 +00:00
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
import java.util.UUID;
|
2014-07-16 02:47:47 +00:00
|
|
|
|
|
|
|
public class ForgePlayer extends AbstractPlayerActor {
|
|
|
|
|
2014-11-15 02:23:43 +00:00
|
|
|
private final ForgePlatform platform;
|
|
|
|
private final EntityPlayerMP player;
|
2013-02-24 20:16:12 +00:00
|
|
|
|
2014-11-15 02:23:43 +00:00
|
|
|
protected ForgePlayer(ForgePlatform platform, EntityPlayerMP player) {
|
|
|
|
this.platform = platform;
|
2013-02-24 20:16:12 +00:00
|
|
|
this.player = player;
|
2014-07-28 03:44:05 +00:00
|
|
|
ThreadSafeCache.getInstance().getOnlineIds().add(getUniqueId());
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
|
|
|
public UUID getUniqueId() {
|
|
|
|
return player.getUniqueID();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public int getItemInHand() {
|
|
|
|
ItemStack is = this.player.getCurrentEquippedItem();
|
2014-10-12 19:27:51 +00:00
|
|
|
return is == null ? 0 : Item.getIdFromItem(is.getItem());
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public String getName() {
|
2014-10-12 19:27:51 +00:00
|
|
|
return this.player.getCommandSenderName();
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-04-28 06:34:39 +00:00
|
|
|
@Override
|
|
|
|
public BaseEntity getState() {
|
|
|
|
throw new UnsupportedOperationException("Cannot create a state from this object");
|
|
|
|
}
|
|
|
|
|
2014-04-27 02:48:21 +00:00
|
|
|
@Override
|
|
|
|
public Location getLocation() {
|
|
|
|
Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
|
2014-07-10 22:49:34 +00:00
|
|
|
return new Location(
|
|
|
|
ForgeWorldEdit.inst.getWorld(this.player.worldObj),
|
|
|
|
position,
|
2014-07-16 03:10:14 +00:00
|
|
|
this.player.cameraYaw,
|
|
|
|
this.player.cameraPitch);
|
2014-04-27 02:48:21 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public WorldVector getPosition() {
|
2014-06-26 23:56:40 +00:00
|
|
|
return new WorldVector(LocalWorldAdapter.adapt(ForgeWorldEdit.inst.getWorld(this.player.worldObj)), this.player.posX, this.player.posY, this.player.posZ);
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2014-04-06 22:06:38 +00:00
|
|
|
public com.sk89q.worldedit.world.World getWorld() {
|
2014-04-06 19:07:10 +00:00
|
|
|
return ForgeWorldEdit.inst.getWorld(this.player.worldObj);
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public double getPitch() {
|
2013-09-29 13:30:06 +00:00
|
|
|
return this.player.rotationPitch;
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public double getYaw() {
|
2013-09-29 13:30:06 +00:00
|
|
|
return this.player.rotationYaw;
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public void giveItem(int type, int amt) {
|
2014-10-12 19:27:51 +00:00
|
|
|
this.player.inventory.addItemStackToInventory(new ItemStack(Item.getItemById(type), amt, 0));
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public void dispatchCUIEvent(CUIEvent event) {
|
|
|
|
String[] params = event.getParameters();
|
|
|
|
String send = event.getTypeId();
|
|
|
|
if (params.length > 0) {
|
|
|
|
send = send + "|" + StringUtil.joinString(params, "|");
|
|
|
|
}
|
2014-10-12 19:27:51 +00:00
|
|
|
S3FPacketCustomPayload packet = new S3FPacketCustomPayload(ForgeWorldEdit.CUI_PLUGIN_CHANNEL, send.getBytes(WECUIPacketHandler.UTF_8_CHARSET));
|
|
|
|
this.player.playerNetServerHandler.sendPacket(packet);
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public void printRaw(String msg) {
|
2013-08-13 01:26:17 +00:00
|
|
|
for (String part : msg.split("\n")) {
|
2014-10-12 19:27:51 +00:00
|
|
|
this.player.addChatMessage(new ChatComponentText(part));
|
2013-08-13 01:26:17 +00:00
|
|
|
}
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public void printDebug(String msg) {
|
2013-08-13 01:26:17 +00:00
|
|
|
for (String part : msg.split("\n")) {
|
2014-10-12 19:27:51 +00:00
|
|
|
this.player.addChatMessage(new ChatComponentText("\u00a77" + part));
|
2013-08-13 01:26:17 +00:00
|
|
|
}
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public void print(String msg) {
|
2013-08-13 01:26:17 +00:00
|
|
|
for (String part : msg.split("\n")) {
|
2014-10-12 19:27:51 +00:00
|
|
|
this.player.addChatMessage(new ChatComponentText("\u00a7d" + part));
|
2013-08-13 01:26:17 +00:00
|
|
|
}
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public void printError(String msg) {
|
2013-08-13 01:26:17 +00:00
|
|
|
for (String part : msg.split("\n")) {
|
2014-10-12 19:27:51 +00:00
|
|
|
this.player.addChatMessage(new ChatComponentText("\u00a7c" + part));
|
2013-08-13 01:26:17 +00:00
|
|
|
}
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public void setPosition(Vector pos, float pitch, float yaw) {
|
|
|
|
this.player.playerNetServerHandler.setPlayerLocation(pos.getX(), pos.getY(), pos.getZ(), pitch, yaw);
|
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public String[] getGroups() {
|
|
|
|
return new String[]{}; // WorldEditMod.inst.getPermissionsResolver().getGroups(this.player.username);
|
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public BlockBag getInventoryBlockBag() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
2013-02-24 20:16:12 +00:00
|
|
|
public boolean hasPermission(String perm) {
|
2014-11-15 02:23:43 +00:00
|
|
|
return ForgeUtil.hasPermission(platform, this.player, perm);
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
2014-07-16 02:47:47 +00:00
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public <T> T getFacet(Class<? extends T> cls) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
|
|
|
public SessionKey getSessionKey() {
|
2014-10-12 19:27:51 +00:00
|
|
|
return new SessionKeyImpl(player.getUniqueID(), player.getCommandSenderName());
|
2014-07-28 03:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
// We can't directly check if the player is online because
|
|
|
|
// the list of players is not thread safe
|
|
|
|
return ThreadSafeCache.getInstance().getOnlineIds().contains(uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPersistent() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|