-
-
Notifications
You must be signed in to change notification settings - Fork 824
/
Player.java
332 lines (294 loc) · 9.84 KB
/
Player.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*
* 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 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 <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.entity;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.gamemode.GameMode;
import javax.annotation.Nullable;
/**
* Represents a player.
*/
public interface Player extends Entity, Actor {
/**
* Return the world that the player is on.
*
* @return the world
*/
World getWorld();
/**
* Returns true if the entity is holding a pick axe.
*
* @return whether a pick axe is held
*/
boolean isHoldingPickAxe();
/**
* Get the player's cardinal direction (N, W, NW, etc.) with an offset. May return null.
* @param yawOffset offset that is added to the player's yaw before determining the cardinal direction
*
* @return the direction
*/
Direction getCardinalDirection(int yawOffset);
/**
* Get the item that the player is holding.
*
* @return the item the player is holding
*/
BaseItemStack getItemInHand(HandSide handSide);
/**
* Get the Block that the player is holding.
*
* @return the item id of the item the player is holding
*/
BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException;
/**
* Gives the player an item.
*
* @param itemStack The item to give
*/
void giveItem(BaseItemStack itemStack);
/**
* Get this actor's block bag.
*
* @return the actor's block bag
*/
BlockBag getInventoryBlockBag();
/**
* Return this actor's game mode.
*
* @return the game mode
*/
GameMode getGameMode();
/**
* Sets the player to the given game mode.
*
* @param gameMode The game mode
*/
void setGameMode(GameMode gameMode);
/**
* Find a position for the actor to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
* a series of two free blocks. The actor will be teleported to
* that free position.
*
* @param searchPos search position
*/
void findFreePosition(Location searchPos);
/**
* Set the actor on the ground.
*
* @param searchPos The location to start searching from
*/
void setOnGround(Location searchPos);
/**
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
* a series of two free blocks. The player will be teleported to
* that free position.
*/
void findFreePosition();
/**
* Go up one level to the next free space above.
*
* @return true if a spot was found
*/
boolean ascendLevel();
/**
* Go up one level to the next free space above.
*
* @return true if a spot was found
*/
boolean descendLevel();
/**
* Ascend to the ceiling above.
*
* @param clearance How many blocks to leave above the player's head
* @return whether the player was moved
*/
boolean ascendToCeiling(int clearance);
/**
* Ascend to the ceiling above.
*
* @param clearance How many blocks to leave above the player's head
* @param alwaysGlass Always put glass under the player
* @return whether the player was moved
*/
boolean ascendToCeiling(int clearance, boolean alwaysGlass);
/**
* Just go up.
*
* @param distance How far up to teleport
* @return whether the player was moved
*/
boolean ascendUpwards(int distance);
/**
* Just go up.
*
* @param distance How far up to teleport
* @param alwaysGlass Always put glass under the player
* @return whether the player was moved
*/
boolean ascendUpwards(int distance, boolean alwaysGlass);
/**
* Make the player float in the given blocks.
*
* @param x The X coordinate of the block to float in
* @param y The Y coordinate of the block to float in
* @param z The Z coordinate of the block to float in
*/
void floatAt(int x, int y, int z, boolean alwaysGlass);
/**
* Get the point of the block that is being stood in.
*
* @return point
* @deprecated Use Locatable#getBlockLocation
*/
@Deprecated
default Location getBlockIn() {
return getBlockLocation();
}
/**
* Get the point of the block that is being stood upon.
*
* @return point
*/
Location getBlockOn();
/**
* Get the point of the block being looked at. May return null.
* Will return the farthest away air block if useLastBlock is true and no other block is found.
*
* @param range how far to checks for blocks
* @param useLastBlock try to return the last valid air block found
* @return point
*/
Location getBlockTrace(int range, boolean useLastBlock);
/**
* Get the point of the block being looked at. May return null.
* Will return the farthest away block before matching the stop mask if useLastBlock is true and no other block is found.
*
* @param range how far to checks for blocks
* @param useLastBlock try to return the last valid block not matching the stop mask found
* @param stopMask the mask used to determine when to stop tracing
* @return point
*/
Location getBlockTrace(int range, boolean useLastBlock, @Nullable Mask stopMask);
/**
* Get the face that the player is looking at.
*
* @param range the range
* @param useLastBlock try to return the last valid air block found
* @return a face
*/
Location getBlockTraceFace(int range, boolean useLastBlock);
/**
* Get the face that the player is looking at.
*
* @param range the range
* @param useLastBlock try to return the last valid block not matching the stop mask found
* @param stopMask the mask used to determine when to stop tracing
* @return a face
*/
Location getBlockTraceFace(int range, boolean useLastBlock, @Nullable Mask stopMask);
/**
* Get the point of the block being looked at. May return null.
*
* @param range How far to checks for blocks
* @return point
*/
Location getBlockTrace(int range);
/**
* Get the point of the block being looked at. May return null.
*
* @param range How far to checks for blocks
* @return point
*/
Location getSolidBlockTrace(int range);
/**
* Get the player's cardinal direction (N, W, NW, etc.). May return null.
*
* @return the direction
*/
Direction getCardinalDirection();
/**
* Pass through the wall that you are looking at.
*
* @param range How far to checks for blocks
* @return whether the player was pass through
*/
boolean passThroughForwardWall(int range);
/**
* Move the player.
*
* @param pos where to move them
* @param pitch the pitch (up/down) of the player's view in degrees
* @param yaw the yaw (left/right) of the player's view in degrees
* @deprecated This method may fail without indication. Use {@link #trySetPosition(Vector3, float, float)} instead
*/
@Deprecated
default void setPosition(Vector3 pos, float pitch, float yaw) {
trySetPosition(pos, pitch, yaw);
}
/**
* Attempt to move the player.
*
* <p>
* This action may fail, due to other mods cancelling the move.
* If so, this method will return {@code false}.
* </p>
*
* @param pos where to move them
* @param pitch the pitch (up/down) of the player's view in degrees
* @param yaw the yaw (left/right) of the player's view in degrees
* @return if the move was able to occur
* @apiNote This must be overridden by new subclasses. See {@link NonAbstractForCompatibility}
* for details
*/
@NonAbstractForCompatibility(
delegateName = "setPosition",
delegateParams = { Vector3.class, float.class, float.class }
)
default boolean trySetPosition(Vector3 pos, float pitch, float yaw) {
DeprecationUtil.checkDelegatingOverride(getClass());
setPosition(pos, pitch, yaw);
return true;
}
/**
* Sends a fake block to the client.
*
* <p>
* This block isn't real.
* </p>
*
* @param pos The position of the block
* @param block The block to send, null to reset
*/
<B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, @Nullable B block);
}