/
SpoutPlayer.java
161 lines (137 loc) · 4.59 KB
/
SpoutPlayer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
*
* 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/>.
*/
// $Id$
package com.sk89q.worldedit.spout;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.cui.CUIEvent;
import org.spout.api.Client;
import org.spout.api.chat.style.ChatStyle;
import org.spout.api.component.impl.TransformComponent;
import org.spout.api.geo.discrete.Point;
import org.spout.api.inventory.ItemStack;
import org.spout.api.entity.Player;
import org.spout.vanilla.api.inventory.Slot;
import org.spout.vanilla.plugin.component.inventory.PlayerInventory;
import org.spout.vanilla.plugin.component.living.neutral.Human;
import org.spout.vanilla.api.material.VanillaMaterial;
import org.spout.vanilla.plugin.material.VanillaMaterials;
public class SpoutPlayer extends LocalPlayer {
private Player player;
@SuppressWarnings("unused")
private WorldEditPlugin plugin;
public SpoutPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
super(server);
this.plugin = plugin;
this.player = player;
}
@Override
public int getItemInHand() {
if (player.has(Human.class)) {
Slot slot = player.get(PlayerInventory.class).getQuickbar().getSelectedSlot();
if (slot.get() == null) {
return 0;
}
return ((VanillaMaterial) slot.get().getMaterial()).getMinecraftId();
} else {
return 0;
}
}
@Override
public String getName() {
return player.getName();
}
@Override
public WorldVector getPosition() {
Point loc = player.getTransform().getPosition();
return new WorldVector(SpoutUtil.getLocalWorld(loc.getWorld()),
loc.getX(), loc.getY(), loc.getZ());
}
@Override
public double getPitch() {
return player.getTransform().getPitch();
}
@Override
public double getYaw() {
return player.getTransform().getYaw();
}
@Override
public void giveItem(int type, int amt) {
if (player.has(Human.class)) {
player.get(PlayerInventory.class).add(new ItemStack(VanillaMaterials.getMaterial((short) type), amt));
}
}
@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(ChatStyle.PINK, part);
}
}
@Override
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage(ChatStyle.GRAY, part);
}
}
@Override
public void printError(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage(ChatStyle.RED, part);
}
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
TransformComponent component = player.getTransform();
player.teleport(SpoutUtil.toPoint(player.getWorld(), pos));
component.setPitch(pitch);
component.setYaw(yaw);
}
@Override
public String[] getGroups() {
return player.getGroups();
}
@Override
public BlockBag getInventoryBlockBag() {
return new SpoutPlayerBlockBag(player);
}
@Override
public boolean hasPermission(String perm) {
return player.hasPermission(perm);
}
@Override
public LocalWorld getWorld() {
return SpoutUtil.getLocalWorld(player.getWorld());
}
@Override
public void dispatchCUIEvent(CUIEvent event) {
player.getSession().send(player.getSession().getEngine() instanceof Client, new WorldEditCUIMessage(event));
}
public Player getPlayer() {
return player;
}
}