Plex-FAWE/src/forge/java/com/sk89q/worldedit/forge/ForgePlayer.java

117 lines
4.1 KiB
Java
Raw Normal View History

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;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.util.ChatMessageComponent;
2013-02-24 20:16:12 +00:00
public class ForgePlayer extends LocalPlayer {
private EntityPlayerMP player;
protected ForgePlayer(EntityPlayerMP player) {
2014-04-06 19:07:10 +00:00
super((ServerInterface) ForgeWorldEdit.inst.getPlatform());
2013-02-24 20:16:12 +00:00
this.player = player;
}
public int getItemInHand() {
ItemStack is = this.player.getCurrentEquippedItem();
return is == null ? 0 : is.itemID;
}
public String getName() {
return this.player.username;
}
public WorldVector getPosition() {
2014-04-06 19:07:10 +00:00
return new WorldVector(ForgeWorldEdit.inst.getWorld(this.player.worldObj), this.player.posX, this.player.posY, this.player.posZ);
2013-02-24 20:16:12 +00:00
}
public LocalWorld getWorld() {
2014-04-06 19:07:10 +00:00
return ForgeWorldEdit.inst.getWorld(this.player.worldObj);
2013-02-24 20:16:12 +00:00
}
public double getPitch() {
return this.player.rotationPitch;
2013-02-24 20:16:12 +00:00
}
public double getYaw() {
return this.player.rotationYaw;
2013-02-24 20:16:12 +00:00
}
public void giveItem(int type, int amt) {
this.player.inventory.addItemStackToInventory(new ItemStack(type, amt, 0));
}
public void dispatchCUIEvent(CUIEvent event) {
String[] params = event.getParameters();
String send = event.getTypeId();
if (params.length > 0) {
send = send + "|" + StringUtil.joinString(params, "|");
}
2014-04-06 19:07:10 +00:00
Packet250CustomPayload packet = new Packet250CustomPayload(ForgeWorldEdit.CUI_PLUGIN_CHANNEL, send.getBytes(WECUIPacketHandler.UTF_8_CHARSET));
2013-02-24 20:16:12 +00:00
this.player.playerNetServerHandler.sendPacketToPlayer(packet);
}
public void printRaw(String msg) {
for (String part : msg.split("\n")) {
this.player.sendChatToPlayer(ChatMessageComponent.createFromText(part));
}
2013-02-24 20:16:12 +00:00
}
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
this.player.sendChatToPlayer(ChatMessageComponent.createFromText("\u00a77" + part));
}
2013-02-24 20:16:12 +00:00
}
public void print(String msg) {
for (String part : msg.split("\n")) {
this.player.sendChatToPlayer(ChatMessageComponent.createFromText("\u00a7d" + part));
}
2013-02-24 20:16:12 +00:00
}
public void printError(String msg) {
for (String part : msg.split("\n")) {
this.player.sendChatToPlayer(ChatMessageComponent.createFromText("\u00a7c" + part));
}
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);
}
public String[] getGroups() {
return new String[]{}; // WorldEditMod.inst.getPermissionsResolver().getGroups(this.player.username);
}
public BlockBag getInventoryBlockBag() {
return null;
}
public boolean hasPermission(String perm) {
return ForgeUtil.hasPermission(this.player, perm);
}
}