| 1 | /*
|
| 2 | * This file is part of Hawk Anticheat.
|
| 3 | * Copyright (C) 2018 Hawk Development Team
|
| 4 | *
|
| 5 | * This program is free software: you can redistribute it and/or modify
|
| 6 | * it under the terms of the GNU General Public License as published by
|
| 7 | * the Free Software Foundation, either version 3 of the License, or
|
| 8 | * (at your option) any later version.
|
| 9 | *
|
| 10 | * This program is distributed in the hope that it will be useful,
|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 | * GNU General Public License for more details.
|
| 14 | *
|
| 15 | * You should have received a copy of the GNU General Public License
|
| 16 | * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
| 17 | */
|
| 18 |
|
| 19 | package me.islandscout.hawk;
|
| 20 |
|
| 21 | import me.islandscout.hawk.check.Check;
|
| 22 | import me.islandscout.hawk.util.*;
|
| 23 | import me.islandscout.hawk.wrap.block.WrappedBlock;
|
| 24 | import me.islandscout.hawk.wrap.entity.MetaData;
|
| 25 | import me.islandscout.hawk.wrap.entity.WrappedEntity;
|
| 26 | import me.islandscout.hawk.wrap.entity.human.WrappedEntityHuman;
|
| 27 | import org.bukkit.*;
|
| 28 | import org.bukkit.block.Block;
|
| 29 | import org.bukkit.entity.Entity;
|
| 30 | import org.bukkit.entity.Player;
|
| 31 | import org.bukkit.event.player.PlayerTeleportEvent;
|
| 32 | import org.bukkit.inventory.ItemStack;
|
| 33 | import org.bukkit.util.Vector;
|
| 34 |
|
| 35 | import java.util.*;
|
| 36 | import java.util.concurrent.ConcurrentHashMap;
|
| 37 | import java.util.concurrent.CopyOnWriteArrayList;
|
| 38 |
|
| 39 | /**
|
| 40 | * Represents a client. Provides essential and additional tools
|
| 41 | * to analyze players during packet interception. Recommended
|
| 42 | * to use this rather than Bukkit's implementation.
|
| 43 | *
|
| 44 | * Fields here should be faithful to the client they represent
|
| 45 | * as much as possible, regardless of any modifications that the
|
| 46 | * anti-cheat makes to the incoming packets. Caution: that means
|
| 47 | * some of these fields can be spoofed!
|
| 48 | */
|
| 49 | public class HawkPlayer {
|
| 50 |
|
| 51 | //Represents a queue of commands sent from server to client. Simulates latency as it is ticked.
|
| 52 | //Can be used to simulate commands that the client doesn't show any clear acknowledgement for,
|
| 53 | //such as inventory window opening/closing.
|
| 54 | private final List<Pair<Runnable, Long>> simulatedCmds;
|
| 55 |
|
| 56 | private final UUID uuid;
|
| 57 | private final Map<Check, Double> vl;
|
| 58 | private boolean digging;
|
| 59 | private boolean receiveNotifications;
|
| 60 | private boolean online;
|
| 61 | private final Player p;
|
| 62 | private long lastTeleportAcceptTick;
|
| 63 | private final Hawk hawk;
|
| 64 |
|
| 65 | //Be careful when playing with these fields.
|
| 66 | //World is not sync'd to position, yaw, nor pitch.
|
| 67 | //private World world; //updated by server
|
| 68 | private Vector position; //updated by server and client
|
| 69 | private Vector positionRaw; //updated by client
|
| 70 | private Location altSetbackLoc; //updated by server
|
| 71 | private float yaw; //updated by server and client
|
| 72 | private float pitch; //updated by server and client
|
| 73 |
|
| 74 | private Vector predictedPosition; //ticked by client
|
| 75 | private Vector previousPredictedPosition;
|
| 76 | private Vector predictedVelocity;
|
| 77 | private Vector previousPredictedVelocity;
|
| 78 |
|
| 79 | private Map<Location, List<AABB>> trackedBlockCollisions; //Private. Used to update ignoredBlockCollisions.
|
| 80 | private Set<Location> ignoredBlockCollisions; //is accessible via getter
|
| 81 |
|
| 82 | private Vector velocity;
|
| 83 | private Vector previousVelocity;
|
| 84 | private float deltaYaw;
|
| 85 | private float deltaPitch;
|
| 86 | private boolean onGround;
|
| 87 | private boolean prevTickOnGround;
|
| 88 | private boolean onGroundReally;
|
| 89 | private boolean sentPosUpdate;
|
| 90 | private boolean liquidExit;
|
| 91 | private float friction;
|
| 92 | private int ping;
|
| 93 | private short pingJitter;
|
| 94 | private long lastMoveTime;
|
| 95 | private long currentTick;
|
| 96 | private boolean sneaking;
|
| 97 | private boolean sprinting;
|
| 98 | private boolean blocking;
|
| 99 | private boolean pullingBow;
|
| 100 | private boolean consumingItem;
|
| 101 | private byte inventoryOpen; //0 for closed; 1 for own inventory; 2 for any other inventory. Updated by server & client
|
| 102 | private boolean inWater;
|
| 103 | private boolean inLava;
|
| 104 | private boolean swimming;
|
| 105 | private boolean inVehicle; //updated by server
|
| 106 | private boolean allowedToFly; //updated by server
|
| 107 | private boolean flying; //updated by server and client
|
| 108 | private boolean inCreative; //updated by server
|
| 109 | private long itemUseTick;
|
| 110 | private long lastAttackedPlayerTick;
|
| 111 | private long lastEntityInteractTick;
|
| 112 | private long lastInLiquidToggleTick;
|
| 113 | private long lastSlotSwitchTick;
|
| 114 | private long lastMoveTick;
|
| 115 | private long hitSlowdownTick;
|
| 116 | private long lastVelocityAcceptTick;
|
| 117 | private long lastLandTick;
|
| 118 | private ItemStack itemUsedForAttack;
|
| 119 | private double maxY;
|
| 120 | private double jumpedHeight;
|
| 121 | private long flyPendingTime;
|
| 122 | private int heldItemSlot;
|
| 123 | private int itemConsumeTicks;
|
| 124 | private final Map<Location, ClientBlock> clientBlocks;
|
| 125 | private final List<Pair<Vector, Long>> pendingVelocities;
|
| 126 | private final List<Pair<Location, Long>> pendingTeleports;
|
| 127 | private final Set<Direction> boxSidesTouchingBlocks;
|
| 128 | private Vector waterFlowForce;
|
| 129 | private List<Pair<MetaData, Long>> metaDataUpdates;
|
| 130 | private Set<Entity> entitiesInteractedInThisTick;
|
| 131 | private List<Double> lastPings;
|
| 132 | private int clientVersion;
|
| 133 |
|
| 134 | HawkPlayer(Player p, Hawk hawk) {
|
| 135 | this.uuid = p.getUniqueId();
|
| 136 | vl = new ConcurrentHashMap<>();
|
| 137 | receiveNotifications = true;
|
| 138 | this.p = p;
|
| 139 | Location defaultLocation = p.getLocation();
|
| 140 | this.position = defaultLocation.toVector();
|
| 141 | this.positionRaw = defaultLocation.toVector();
|
| 142 | altSetbackLoc = defaultLocation;
|
| 143 | this.yaw = defaultLocation.getYaw();
|
| 144 | this.pitch = defaultLocation.getPitch();
|
| 145 | this.velocity = new Vector();
|
| 146 | this.previousVelocity = new Vector();
|
| 147 | this.predictedPosition = defaultLocation.toVector();
|
| 148 | this.previousPredictedPosition = defaultLocation.toVector();
|
| 149 | this.predictedVelocity = new Vector();
|
| 150 | this.onGround = ((Entity) p).isOnGround();
|
| 151 | this.hawk = hawk;
|
| 152 | this.ping = ServerUtils.getPing(p);
|
| 153 | this.heldItemSlot = p.getInventory().getHeldItemSlot();
|
| 154 | clientBlocks = new ConcurrentHashMap<>();
|
| 155 | pendingVelocities = new CopyOnWriteArrayList<>();
|
| 156 | pendingTeleports = new CopyOnWriteArrayList<>();
|
| 157 | boxSidesTouchingBlocks = new HashSet<>();
|
| 158 | this.waterFlowForce = new Vector();
|
| 159 | trackedBlockCollisions = new HashMap<>();
|
| 160 | ignoredBlockCollisions = new HashSet<>();
|
| 161 | simulatedCmds = new CopyOnWriteArrayList<>();
|
| 162 | metaDataUpdates = new CopyOnWriteArrayList<>();
|
| 163 | entitiesInteractedInThisTick = new HashSet<>();
|
| 164 | lastPings = new CopyOnWriteArrayList<>();
|
| 165 | clientVersion = ServerUtils.getProtocolVersion(p) == 47 ? 8 : 7;
|
| 166 |
|
| 167 | //do this a little later since these values are a little slow
|
| 168 | Bukkit.getScheduler().scheduleSyncDelayedTask(hawk, new Runnable() {
|
| 169 | @Override
|
| 170 | public void run() {
|
| 171 | allowedToFly = p.getAllowFlight();
|
| 172 | flying = p.isFlying();
|
| 173 | inCreative = p.getGameMode() == GameMode.CREATIVE;
|
| 174 | }
|
| 175 | });
|
| 176 |
|
| 177 | }
|
| 178 |
|
| 179 | public void tick() {
|
| 180 | this.currentTick++;
|
| 181 | manageClientBlocks();
|
| 182 | executeTasks();
|
| 183 | cleanUpOldMetaDataUpdates();
|
| 184 | cleanUpOldPendingTeleports();
|
| 185 | entitiesInteractedInThisTick.clear();
|
| 186 | predictNextPosition();
|
| 187 | if(consumingItem)
|
| 188 | itemConsumeTicks++;
|
| 189 | }
|
| 190 |
|
| 191 | public int getVL(Check check) {
|
| 192 | return (int) (double) vl.getOrDefault(check, 0D);
|
| 193 | }
|
| 194 |
|
| 195 | public Map<Check, Double> getVLs() {
|
| 196 | return vl;
|
| 197 | }
|
| 198 |
|
| 199 | public void setVL(Check check, double vl) {
|
| 200 | this.vl.put(check, vl);
|
| 201 | }
|
| 202 |
|
| 203 | public void incrementVL(Check check) {
|
| 204 | this.vl.put(check, vl.getOrDefault(check, 0D) + 1D);
|
| 205 | }
|
| 206 |
|
| 207 | public void addVL(Check check, double amnt) {
|
| 208 | this.vl.put(check, vl.getOrDefault(check, 0D) + amnt);
|
| 209 | }
|
| 210 |
|
| 211 | public void multiplyVL(Check check, double factor) {
|
| 212 | vl.put(check, vl.getOrDefault(check, 0D) * factor);
|
| 213 | }
|
| 214 |
|
| 215 | public UUID getUuid() {
|
| 216 | return uuid;
|
| 217 | }
|
| 218 |
|
| 219 | public boolean isDigging() {
|
| 220 | return digging && p.getGameMode() != GameMode.CREATIVE;
|
| 221 | }
|
| 222 |
|
| 223 | //this should really not be public
|
| 224 | public void setDigging(boolean digging) {
|
| 225 | this.digging = digging;
|
| 226 | }
|
| 227 |
|
| 228 | public boolean getReceiveNotificationsPreference() {
|
| 229 | return receiveNotifications;
|
| 230 | }
|
| 231 |
|
| 232 | public void setReceiveNotificationsPreference(boolean status) {
|
| 233 | receiveNotifications = status;
|
| 234 | }
|
| 235 |
|
| 236 | public boolean isOnline() {
|
| 237 | return online;
|
| 238 | }
|
| 239 |
|
| 240 | public void setOnline(boolean online) {
|
| 241 | this.online = online;
|
| 242 | }
|
| 243 |
|
| 244 | public boolean isTeleporting() {
|
| 245 | return !getPendingTeleports().isEmpty();
|
| 246 | }
|
| 247 |
|
| 248 | public long getLastTeleportAcceptTick() {
|
| 249 | return lastTeleportAcceptTick;
|
| 250 | }
|
| 251 |
|
| 252 | public void setLastTeleportAcceptTick(long lastTeleportAcceptTick) {
|
| 253 | this.lastTeleportAcceptTick = lastTeleportAcceptTick;
|
| 254 | }
|
| 255 |
|
| 256 | public boolean isOnGround() {
|
| 257 | return onGround;
|
| 258 | }
|
| 259 |
|
| 260 | //this should really not be public
|
| 261 | public void setOnGround(boolean onGround) {
|
| 262 | this.prevTickOnGround = this.onGround;
|
| 263 | this.onGround = onGround;
|
| 264 | }
|
| 265 |
|
| 266 | //why do I need to make this???
|
| 267 | public boolean wasOnGround() {
|
| 268 | return prevTickOnGround;
|
| 269 | }
|
| 270 |
|
| 271 | public boolean isOnGroundReally() {
|
| 272 | return onGroundReally;
|
| 273 | }
|
| 274 |
|
| 275 | public void setOnGroundReally(boolean onGroundReally) {
|
| 276 | this.onGroundReally = onGroundReally;
|
| 277 | }
|
| 278 |
|
| 279 | public int getPing() {
|
| 280 | return ping;
|
| 281 | }
|
| 282 |
|
| 283 | public void setPing(int ping) {
|
| 284 | this.ping = ping;
|
| 285 | this.lastPings.add((double)ping);
|
| 286 | if(lastPings.size() > 10) {
|
| 287 | lastPings.remove(0);
|
| 288 | }
|
| 289 | pingJitter = (short)MathPlus.range(lastPings);
|
| 290 | }
|
| 291 |
|
| 292 | public short getPingJitter() {
|
| 293 | return pingJitter;
|
| 294 | }
|
| 295 |
|
| 296 | public long getLastMoveTime() {
|
| 297 | return lastMoveTime;
|
| 298 | }
|
| 299 |
|
| 300 | public void setLastMoveTime(long lastMoveTime) {
|
| 301 | this.lastMoveTime = lastMoveTime;
|
| 302 | }
|
| 303 |
|
| 304 | public World getWorld() {
|
| 305 | return p.getWorld();
|
| 306 | }
|
| 307 |
|
| 308 | //currently doesn't support when in vehicle
|
| 309 | public Vector getPosition() {
|
| 310 | return position;
|
| 311 | }
|
| 312 |
|
| 313 | //the player's position since the last flying packet; completely untouched
|
| 314 | public Vector getPositionRaw() {
|
| 315 | return positionRaw;
|
| 316 | }
|
| 317 |
|
| 318 | //currently doesn't support when in vehicle
|
| 319 | public Vector getHeadPosition() {
|
| 320 | Vector add = new Vector(0, 0, 0);
|
| 321 | add.setY(isSneaking() ? 1.54 : 1.62);
|
| 322 | return position.clone().add(add);
|
| 323 | }
|
| 324 |
|
| 325 | public Vector getPositionCloned() {
|
| 326 | return position.clone();
|
| 327 | }
|
| 328 |
|
| 329 | //Returns the current predicted position of the HawkPlayer, assuming no user input.
|
| 330 | public Vector getPositionPredicted() {
|
| 331 | return predictedPosition;
|
| 332 | }
|
| 333 |
|
| 334 | public Vector getPreviousPositionPredicted() {
|
| 335 | return previousPredictedPosition;
|
| 336 | }
|
| 337 |
|
| 338 | public void updatePositionYawPitch(Vector position, float yaw, float pitch, boolean isPosUpdate) {
|
| 339 | this.previousVelocity = this.velocity;
|
| 340 | this.velocity = new Vector(
|
| 341 | position.getX() - this.position.getX(),
|
| 342 | position.getY() - this.position.getY(),
|
| 343 | position.getZ() - this.position.getZ());
|
| 344 | this.deltaYaw = yaw - this.yaw;
|
| 345 | this.deltaPitch = pitch - this.pitch;
|
| 346 |
|
| 347 | this.position = position;
|
| 348 | this.yaw = yaw;
|
| 349 | this.pitch = pitch;
|
| 350 | if(isPosUpdate) {
|
| 351 | predictedPosition = position.clone();
|
| 352 | if(hasSentPosUpdate())
|
| 353 | predictedVelocity = velocity.clone();
|
| 354 | }
|
| 355 | }
|
| 356 |
|
| 357 | public void setPositionRaw(Vector positionRaw) {
|
| 358 | this.positionRaw = positionRaw;
|
| 359 | }
|
| 360 |
|
| 361 | public float getYaw() {
|
| 362 | return yaw;
|
| 363 | }
|
| 364 |
|
| 365 | public void setYaw(float yaw) {
|
| 366 | this.yaw = yaw;
|
| 367 | }
|
| 368 |
|
| 369 | public float getPitch() {
|
| 370 | return pitch;
|
| 371 | }
|
| 372 |
|
| 373 | public void setPitch(float pitch) {
|
| 374 | this.pitch = pitch;
|
| 375 | }
|
| 376 |
|
| 377 | public void setVelocity(Vector velocity) {
|
| 378 | this.velocity = velocity;
|
| 379 | }
|
| 380 |
|
| 381 | public Vector getVelocity() {
|
| 382 | return velocity;
|
| 383 | }
|
| 384 |
|
| 385 | public Vector getVelocityPredicted() {
|
| 386 | return predictedVelocity;
|
| 387 | }
|
| 388 |
|
| 389 | public Vector getPreviousVelocity() {
|
| 390 | return previousVelocity;
|
| 391 | }
|
| 392 |
|
| 393 | public Vector getPreviousPredictedVelocity() {
|
| 394 | return previousPredictedVelocity;
|
| 395 | }
|
| 396 |
|
| 397 | public float getDeltaYaw() {
|
| 398 | return deltaYaw;
|
| 399 | }
|
| 400 |
|
| 401 | public float getDeltaPitch() {
|
| 402 | return deltaPitch;
|
| 403 | }
|
| 404 |
|
| 405 | public long getCurrentTick() {
|
| 406 | return currentTick;
|
| 407 | }
|
| 408 |
|
| 409 | public boolean isSneaking() {
|
| 410 | return sneaking;
|
| 411 | }
|
| 412 |
|
| 413 | public void setSneaking(boolean sneaking) {
|
| 414 | this.sneaking = sneaking;
|
| 415 | }
|
| 416 |
|
| 417 | public boolean isSprinting() {
|
| 418 | return sprinting;
|
| 419 | }
|
| 420 |
|
| 421 | public void setSprinting(boolean sprinting) {
|
| 422 | this.sprinting = sprinting;
|
| 423 | }
|
| 424 |
|
| 425 | public boolean isBlocking() {
|
| 426 | return blocking;
|
| 427 | }
|
| 428 |
|
| 429 | public void setBlocking(boolean blocking) {
|
| 430 | this.blocking = blocking;
|
| 431 | if(blocking)
|
| 432 | itemUseTick = currentTick;
|
| 433 | }
|
| 434 |
|
| 435 | public boolean isPullingBow() {
|
| 436 | return pullingBow;
|
| 437 | }
|
| 438 |
|
| 439 | public void setPullingBow(boolean pullingBow) {
|
| 440 | this.pullingBow = pullingBow;
|
| 441 | if(pullingBow)
|
| 442 | itemUseTick = currentTick;
|
| 443 | }
|
| 444 |
|
| 445 | public byte hasInventoryOpen() {
|
| 446 | return inventoryOpen;
|
| 447 | }
|
| 448 |
|
| 449 | public void setInventoryOpen(byte status) {
|
| 450 | this.inventoryOpen = status;
|
| 451 | }
|
| 452 |
|
| 453 | public double getFallDistance() {
|
| 454 | return maxY - position.getY();
|
| 455 | }
|
| 456 |
|
| 457 | public int getHeldItemSlot() {
|
| 458 | return heldItemSlot;
|
| 459 | }
|
| 460 |
|
| 461 | public void setHeldItemSlot(int heldItemSlot) {
|
| 462 | this.heldItemSlot = heldItemSlot;
|
| 463 | }
|
| 464 |
|
| 465 | public boolean isConsumingItem() {
|
| 466 | return consumingItem;
|
| 467 | }
|
| 468 |
|
| 469 | public void setConsumingItem(boolean consumingItem) {
|
| 470 | this.consumingItem = consumingItem;
|
| 471 | if(consumingItem)
|
| 472 | itemUseTick = currentTick;
|
| 473 | else
|
| 474 | itemConsumeTicks = 0;
|
| 475 | }
|
| 476 |
|
| 477 | public boolean isInWater() {
|
| 478 | return inWater;
|
| 479 | }
|
| 480 |
|
| 481 | public void setInWater(boolean inWater) {
|
| 482 | if(this.inWater != inWater) {
|
| 483 | lastInLiquidToggleTick = currentTick;
|
| 484 | this.inWater = inWater;
|
| 485 | }
|
| 486 | }
|
| 487 |
|
| 488 | public boolean isInLava() {
|
| 489 | return inLava;
|
| 490 | }
|
| 491 |
|
| 492 | public void setInLava(boolean inLava) {
|
| 493 | this.inLava = inLava;
|
| 494 | }
|
| 495 |
|
| 496 | @Deprecated
|
| 497 | public boolean isFlyingClientside() {
|
| 498 | return (p.getAllowFlight() && hasFlyPending()) || p.isFlying();
|
| 499 | }
|
| 500 |
|
| 501 | public long getLastItemUseTick() {
|
| 502 | return itemUseTick;
|
| 503 | }
|
| 504 |
|
| 505 | public long getLastAttackedPlayerTick() {
|
| 506 | return lastAttackedPlayerTick;
|
| 507 | }
|
| 508 |
|
| 509 | public void updateLastAttackedPlayerTick() {
|
| 510 | this.lastAttackedPlayerTick = currentTick;
|
| 511 | }
|
| 512 |
|
| 513 | public long getLastEntityInteractTick() {
|
| 514 | return lastEntityInteractTick;
|
| 515 | }
|
| 516 |
|
| 517 | public void updateLastEntityInteractTick() {
|
| 518 | this.lastEntityInteractTick = currentTick;
|
| 519 | }
|
| 520 |
|
| 521 | public long getLastInLiquidToggleTick() {
|
| 522 | return lastInLiquidToggleTick;
|
| 523 | }
|
| 524 |
|
| 525 | public long getLastSlotSwitchTick() {
|
| 526 | return lastSlotSwitchTick;
|
| 527 | }
|
| 528 |
|
| 529 | public void updateLastSlotSwitchTick() {
|
| 530 | this.lastSlotSwitchTick = currentTick;
|
| 531 | }
|
| 532 |
|
| 533 | public long getHitSlowdownTick() {
|
| 534 | return hitSlowdownTick;
|
| 535 | }
|
| 536 |
|
| 537 | public void updateHitSlowdownTick() {
|
| 538 | this.hitSlowdownTick = currentTick;
|
| 539 | }
|
| 540 |
|
| 541 | public long getLastVelocityAcceptTick() {
|
| 542 | return lastVelocityAcceptTick;
|
| 543 | }
|
| 544 |
|
| 545 | public void updateLastVelocityAcceptTick() {
|
| 546 | this.lastVelocityAcceptTick = currentTick;
|
| 547 | }
|
| 548 |
|
| 549 | public boolean hasHitSlowdown() {
|
| 550 | return hitSlowdownTick == currentTick;
|
| 551 | }
|
| 552 |
|
| 553 | public boolean isSwimming() {
|
| 554 | return swimming;
|
| 555 | }
|
| 556 |
|
| 557 | public void setSwimming(boolean swimming) {
|
| 558 | this.swimming = swimming;
|
| 559 | }
|
| 560 |
|
| 561 | public ItemStack getItemUsedForAttack() {
|
| 562 | return itemUsedForAttack;
|
| 563 | }
|
| 564 |
|
| 565 | public void updateItemUsedForAttack() {
|
| 566 | this.itemUsedForAttack = getHeldItem();
|
| 567 | }
|
| 568 |
|
| 569 | public ItemStack getHeldItem() {
|
| 570 | return p.getInventory().getItem(heldItemSlot);
|
| 571 | }
|
| 572 |
|
| 573 | //call this before updating whether on ground or not
|
| 574 | public void updateFallDistance(Location loc) {
|
| 575 | if (onGround)
|
| 576 | maxY = loc.getY();
|
| 577 | else
|
| 578 | maxY = Math.max(loc.getY(), maxY);
|
| 579 |
|
| 580 | }
|
| 581 |
|
| 582 | public double getTotalAscensionSinceGround() {
|
| 583 | return jumpedHeight;
|
| 584 | }
|
| 585 |
|
| 586 | //call this before updating whether on ground or not
|
| 587 | public void updateTotalAscensionSinceGround(double y1, double y2) {
|
| 588 | if (onGround) {
|
| 589 | jumpedHeight = 0;
|
| 590 | return;
|
| 591 | }
|
| 592 | double deltaY = y2 - y1;
|
| 593 | if(deltaY > 0)
|
| 594 | jumpedHeight += deltaY;
|
| 595 | }
|
| 596 |
|
| 597 | public boolean hasFlyPending() {
|
| 598 | return System.currentTimeMillis() - flyPendingTime <= 100;
|
| 599 | }
|
| 600 |
|
| 601 | public void setFlyPendingTime(long time) {
|
| 602 | flyPendingTime = time;
|
| 603 | }
|
| 604 |
|
| 605 | public Player getPlayer() {
|
| 606 | return p;
|
| 607 | }
|
| 608 |
|
| 609 | public Map<Location, ClientBlock> getClientBlocks() {
|
| 610 | return clientBlocks;
|
| 611 | }
|
| 612 |
|
| 613 | public void addClientBlock(Location loc, ClientBlock pBlock) {
|
| 614 | if (clientBlocks.size() >= ClientBlock.MAX_PER_PLAYER)
|
| 615 | return;
|
| 616 | clientBlocks.put(loc, pBlock);
|
| 617 | }
|
| 618 |
|
| 619 | private void manageClientBlocks() {
|
| 620 | for (Location loc : clientBlocks.keySet()) {
|
| 621 | ClientBlock clientBlock = clientBlocks.get(loc);
|
| 622 | if (currentTick - clientBlock.getInitTick() > ClientBlock.CLIENTTICKS_UNTIL_EXPIRE) {
|
| 623 | clientBlocks.remove(loc);
|
| 624 | }
|
| 625 | }
|
| 626 | }
|
| 627 |
|
| 628 | //TODO shrink this code
|
| 629 | //TODO TEST BEFORE RELEASING 2001
|
| 630 | private void predictNextPosition() {
|
| 631 | Vector move = predictedVelocity.clone();
|
| 632 | previousPredictedPosition = predictedPosition.clone();
|
| 633 | previousPredictedVelocity = predictedVelocity.clone();
|
| 634 |
|
| 635 | World world = getWorld();
|
| 636 |
|
| 637 | Block blockAtPos = ServerUtils.getBlockAsync(predictedPosition.toLocation(getWorld()));
|
| 638 | boolean onClimbable = blockAtPos != null && (blockAtPos.getType() == Material.LADDER || blockAtPos.getType() == Material.VINE);
|
| 639 |
|
| 640 | Set<Material> oldTouchedMats = WrappedEntity.getWrappedEntity(p).getCollisionBox(predictedPosition).getMaterials(getWorld());
|
| 641 |
|
| 642 | //compute new predicted motion values
|
| 643 | double pdX = move.getX() * getFriction();
|
| 644 | double pdY = move.getY() * 0.98;
|
| 645 | double pdZ = move.getZ() * getFriction();
|
| 646 |
|
| 647 | if(!isFlying())
|
| 648 | pdY += -0.0784;
|
| 649 |
|
| 650 | if(oldTouchedMats.contains(Material.WEB)) {
|
| 651 | pdX *= 0.25;
|
| 652 | pdY *= 0.05;
|
| 653 | pdZ *= 0.25;
|
| 654 | }
|
| 655 |
|
| 656 | if(Math.abs(pdX) < 0.005) {
|
| 657 | pdX = 0;
|
| 658 | }
|
| 659 | if(Math.abs(pdY) < 0.005 || (onClimbable && sneaking)) {
|
| 660 | pdY = 0;
|
| 661 | }
|
| 662 | if(Math.abs(pdZ) < 0.005) {
|
| 663 | pdZ = 0;
|
| 664 | }
|
| 665 |
|
| 666 | move.setX(pdX);
|
| 667 | move.setY(pdY);
|
| 668 | move.setZ(pdZ);
|
| 669 |
|
| 670 | AABB box = WrappedEntity.getWrappedEntity(p).getCollisionBox(predictedPosition);
|
| 671 | AABB preBox = box.clone();
|
| 672 | preBox.expand(-0.0001, -0.0001, -0.0001);
|
| 673 | List<AABB> collidedBlocksBefore = preBox.getBlockAABBs(world, getClientVersion(), Material.WEB);
|
| 674 |
|
| 675 | boolean collidedVertically = false;
|
| 676 |
|
| 677 | //clipping order: X, Z, Y
|
| 678 | //X
|
| 679 | box.expand(-0.00000001, -0.00000001, -0.00000001);
|
| 680 | boolean positive = pdX > 0;
|
| 681 | box.translate(new Vector(pdX, 0, 0));
|
| 682 | List<AABB> collidedBlocks = box.getBlockAABBs(world, getClientVersion(), Material.WEB);
|
| 683 | collidedBlocks.removeAll(collidedBlocksBefore);
|
| 684 |
|
| 685 | double highestPoint = positive ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
|
| 686 | for(AABB aabb : collidedBlocks) {
|
| 687 | double point = positive ? aabb.getMin().getX() : aabb.getMax().getX();
|
| 688 | if(positive && point < highestPoint)
|
| 689 | highestPoint = point;
|
| 690 | else if(!positive && point > highestPoint)
|
| 691 | highestPoint = point;
|
| 692 | }
|
| 693 | if(Double.isFinite(highestPoint)) {
|
| 694 | double invPenetrationDist = positive ? highestPoint - box.getMax().getX() - 0.00000001 : highestPoint - box.getMin().getX() + 0.00000001;
|
| 695 | box.translate(new Vector(invPenetrationDist, 0, 0));
|
| 696 | pdX += invPenetrationDist;
|
| 697 | }
|
| 698 |
|
| 699 | //Z
|
| 700 | positive = pdZ > 0;
|
| 701 | box.translate(new Vector(0, 0, pdZ));
|
| 702 | collidedBlocks = box.getBlockAABBs(world, getClientVersion(), Material.WEB);
|
| 703 | collidedBlocks.removeAll(collidedBlocksBefore);
|
| 704 |
|
| 705 | highestPoint = positive ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
|
| 706 | for(AABB aabb : collidedBlocks) {
|
| 707 | double point = positive ? aabb.getMin().getZ() : aabb.getMax().getZ();
|
| 708 | if(positive && point < highestPoint)
|
| 709 | highestPoint = point;
|
| 710 | else if(!positive && point > highestPoint)
|
| 711 | highestPoint = point;
|
| 712 | }
|
| 713 | if(Double.isFinite(highestPoint)) {
|
| 714 | double invPenetrationDist = positive ? highestPoint - box.getMax().getZ() - 0.00000001 : highestPoint - box.getMin().getZ() + 0.00000001;
|
| 715 | box.translate(new Vector(0, 0, invPenetrationDist));
|
| 716 | pdZ += invPenetrationDist;
|
| 717 | }
|
| 718 |
|
| 719 | //Y
|
| 720 | positive = pdY > 0;
|
| 721 | box.translate(new Vector(0, pdY, 0));
|
| 722 | collidedBlocks = box.getBlockAABBs(world, getClientVersion(), Material.WEB);
|
| 723 | collidedBlocks.removeAll(collidedBlocksBefore);
|
| 724 |
|
| 725 | highestPoint = positive ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
|
| 726 | for(AABB aabb : collidedBlocks) {
|
| 727 | double point = positive ? aabb.getMin().getY() : aabb.getMax().getY();
|
| 728 | if(positive && point < highestPoint)
|
| 729 | highestPoint = point;
|
| 730 | else if(!positive && point > highestPoint)
|
| 731 | highestPoint = point;
|
| 732 | }
|
| 733 | if(Double.isFinite(highestPoint)) {
|
| 734 | double invPenetrationDist = positive ? highestPoint - box.getMax().getY() - 0.00000001 : highestPoint - box.getMin().getY() + 0.00000001;
|
| 735 | box.translate(new Vector(0, invPenetrationDist, 0));
|
| 736 | pdY += invPenetrationDist;
|
| 737 | collidedVertically = true;
|
| 738 | }
|
| 739 |
|
| 740 | //crude way of handling sneaking
|
| 741 | boolean sneakHalt;
|
| 742 | if(sneaking) {
|
| 743 | Vector min = predictedPosition.clone().add(new Vector(-0.3, -0.001, -0.3));
|
| 744 | Vector max = predictedPosition.clone().add(new Vector(0.3, 0, 0.3));
|
| 745 | AABB feet = new AABB(min, max);
|
| 746 | boolean wasOnGround = feet.getBlockAABBs(world, clientVersion, Material.WEB).size() > 0;
|
| 747 |
|
| 748 | feet.translate(new Vector(pdX, pdY, pdZ));
|
| 749 | boolean isOnGround = feet.getBlockAABBs(world, clientVersion, Material.WEB).size() > 0;
|
| 750 |
|
| 751 | if(wasOnGround && !isOnGround) {
|
| 752 | //use max.getY() to save a clone()
|
| 753 | Vector check = new Vector(pdX, max.getY() - 1, pdZ);
|
| 754 | Block checkBlock = ServerUtils.getBlockAsync(check.toLocation(world));
|
| 755 | if(checkBlock == null) {
|
| 756 | sneakHalt = true;
|
| 757 | }
|
| 758 | else {
|
| 759 | sneakHalt = true;
|
| 760 | for(AABB aabb : WrappedBlock.getWrappedBlock(checkBlock, clientVersion).getCollisionBoxes()) {
|
| 761 | if(aabb.containsPoint(check)) {
|
| 762 | sneakHalt = false;
|
| 763 | break;
|
| 764 | }
|
| 765 | }
|
| 766 | }
|
| 767 | }
|
| 768 | else {
|
| 769 | sneakHalt = false;
|
| 770 | }
|
| 771 | }
|
| 772 | else {
|
| 773 | sneakHalt = false;
|
| 774 | }
|
| 775 | if(sneakHalt) {
|
| 776 | predictedVelocity = new Vector(0, 0, 0);
|
| 777 | return;
|
| 778 | }
|
| 779 |
|
| 780 | //move predicted position
|
| 781 | Vector clippedVel = new Vector(MathPlus.round(pdX, 10), MathPlus.round(pdY, 10), MathPlus.round(pdZ, 10));
|
| 782 | predictedPosition.add(clippedVel);
|
| 783 |
|
| 784 | //AABB a = AABB.playerCollisionBox.clone();
|
| 785 | //a.translate(predictedPosition);
|
| 786 | //a.highlight(hawk, getWorld(), 0.299);
|
| 787 |
|
| 788 | Set<Material> newTouchedMats = WrappedEntity.getWrappedEntity(p).getCollisionBox(predictedPosition).getMaterials(getWorld());
|
| 789 | if(newTouchedMats.contains(Material.WEB)) {
|
| 790 | predictedVelocity = new Vector();
|
| 791 | } else if(collidedVertically) {
|
| 792 | Block b = ServerUtils.getBlockAsync(predictedPosition.clone().add(new Vector(0, -0.2, 0)).toLocation(getWorld()));
|
| 793 | if(Hawk.getServerVersion() == 8 && !isSneaking() && b != null && b.getType() == Material.SLIME_BLOCK && move.getY() < 0) {
|
| 794 | predictedVelocity.setY(-move.getY());
|
| 795 | } else {
|
| 796 | predictedVelocity = clippedVel; //touched ground
|
| 797 | }
|
| 798 | }
|
| 799 | else {
|
| 800 | predictedVelocity = clippedVel; //air
|
| 801 | }
|
| 802 | }
|
| 803 |
|
| 804 | //Handles block AABB updates and teleportations to assist collision-based checks
|
| 805 | public void updateIgnoredBlockCollisions(Vector to, Vector from, boolean teleported) {
|
| 806 | final double expand = -0.0001; //TODO perhaps make this equal to NMS's margin to prevent bypasses via /sethome abuse?
|
| 807 | AABB bbox = WrappedEntity.getWrappedEntity(p).getCollisionBox(to);
|
| 808 | bbox.expand(expand, expand, expand);
|
| 809 |
|
| 810 | //handle teleportation INTO a block
|
| 811 | if(teleported) {
|
| 812 | AABB lastbbox = WrappedEntity.getWrappedEntity(p).getCollisionBox(from);
|
| 813 | lastbbox.expand(expand, expand, expand);
|
| 814 |
|
| 815 | //add new entries
|
| 816 | Set<Location> addIgnored = new HashSet<>();
|
| 817 | for(Block b : bbox.getBlocks(getWorld())) {
|
| 818 | for(AABB aabb : WrappedBlock.getWrappedBlock(b, getClientVersion()).getCollisionBoxes()) {
|
| 819 | if(aabb.isColliding(bbox) && !aabb.isColliding(lastbbox)) { //Must enter an AABB. This patches a Phase bypass.
|
| 820 | addIgnored.add(b.getLocation());
|
| 821 | break;
|
| 822 | }
|
| 823 | }
|
| 824 | }
|
| 825 |
|
| 826 | //remove old entries
|
| 827 | Set<Location> removeIgnored = new HashSet<>();
|
| 828 | for(Location loc : ignoredBlockCollisions) {
|
| 829 | Block b = ServerUtils.getBlockAsync(loc);
|
| 830 | if(b == null) {
|
| 831 | removeIgnored.add(loc);
|
| 832 | continue;
|
| 833 | }
|
| 834 |
|
| 835 | boolean colliding = false;
|
| 836 | for(AABB aabb : WrappedBlock.getWrappedBlock(b, getClientVersion()).getCollisionBoxes()) {
|
| 837 | if(aabb.isColliding(bbox)) {
|
| 838 | colliding = true;
|
| 839 | break;
|
| 840 | }
|
| 841 | }
|
| 842 |
|
| 843 | if(!colliding) {
|
| 844 | removeIgnored.add(loc);
|
| 845 | }
|
| 846 | }
|
| 847 |
|
| 848 | ignoredBlockCollisions.removeAll(removeIgnored);
|
| 849 | ignoredBlockCollisions.addAll(addIgnored);
|
| 850 | }
|
| 851 |
|
| 852 | //handle AABB updates within player bounds
|
| 853 | //TODO Phase false when player moves out of block
|
| 854 | //TODO to fix concurrency issues with checks such as Phase, have these blocks/AABBs in this method copied and stored in a shared list in MoveEvent so that Phase can compare using the same block data
|
| 855 | else {
|
| 856 | Map<Location, List<AABB>> blocksInBBNew = new HashMap<>();
|
| 857 | for(Block b : bbox.getBlocks(getWorld())) {
|
| 858 | Location loc = b.getLocation();
|
| 859 | List<AABB> aabbs = Arrays.asList(WrappedBlock.getWrappedBlock(b, getClientVersion()).getCollisionBoxes());
|
| 860 | blocksInBBNew.put(loc, aabbs);
|
| 861 | }
|
| 862 |
|
| 863 | Map<Location, List<AABB>> blocksInBBOld = trackedBlockCollisions;
|
| 864 | Set<Location> ignored = new HashSet<>();
|
| 865 | for(Location entry : blocksInBBNew.keySet()) {
|
| 866 | if (blocksInBBOld.containsKey(entry) && !blocksInBBOld.get(entry).equals(blocksInBBNew.get(entry))) {
|
| 867 | for(AABB aabb : blocksInBBNew.get(entry)) {
|
| 868 | if(aabb.isColliding(bbox)) {
|
| 869 | ignored.add(entry);
|
| 870 | break;
|
| 871 | }
|
| 872 | }
|
| 873 | }
|
| 874 | }
|
| 875 |
|
| 876 | trackedBlockCollisions = blocksInBBNew;
|
| 877 | Set<Location> ignoredOld = ignoredBlockCollisions;
|
| 878 | for(Location loc : ignoredOld) {
|
| 879 | Block b = ServerUtils.getBlockAsync(loc);
|
| 880 | if(b == null)
|
| 881 | continue;
|
| 882 | for(AABB aabb : WrappedBlock.getWrappedBlock(b, getClientVersion()).getCollisionBoxes()) {
|
| 883 | if(aabb.isColliding(bbox)) {
|
| 884 | ignored.add(loc);
|
| 885 | break;
|
| 886 | }
|
| 887 | }
|
| 888 | }
|
| 889 | ignoredBlockCollisions = ignored;
|
| 890 | }
|
| 891 | }
|
| 892 |
|
| 893 | //Get locations of blocks that had their AABB updated within the player's AABB
|
| 894 | public Set<Location> getIgnoredBlockCollisions() {
|
| 895 | return ignoredBlockCollisions;
|
| 896 | }
|
| 897 |
|
| 898 | public Set<Direction> getBoxSidesTouchingBlocks() {
|
| 899 | return boxSidesTouchingBlocks;
|
| 900 | }
|
| 901 |
|
| 902 | public Vector getWaterFlowForce() {
|
| 903 | return waterFlowForce;
|
| 904 | }
|
| 905 |
|
| 906 | public void setWaterFlowForce(Vector waterFlowForce) {
|
| 907 | this.waterFlowForce = waterFlowForce;
|
| 908 | }
|
| 909 |
|
| 910 | public long getLastMoveTick() {
|
| 911 | return lastMoveTick;
|
| 912 | }
|
| 913 |
|
| 914 | public long getClientTicksSinceLastMove() {
|
| 915 | return getCurrentTick() - lastMoveTick;
|
| 916 | }
|
| 917 |
|
| 918 | public void setHasMoved() {
|
| 919 | this.lastMoveTick = getCurrentTick();
|
| 920 | }
|
| 921 |
|
| 922 | public long getLastLandTick() {
|
| 923 | return lastLandTick;
|
| 924 | }
|
| 925 |
|
| 926 | public void updateLastLandTick() {
|
| 927 | this.lastLandTick = currentTick;
|
| 928 | }
|
| 929 |
|
| 930 | public List<Pair<Vector, Long>> getPendingVelocities() {
|
| 931 | return pendingVelocities;
|
| 932 | }
|
| 933 |
|
| 934 | public float getFriction() {
|
| 935 | return friction;
|
| 936 | }
|
| 937 |
|
| 938 | public void setFriction(float friction) {
|
| 939 | this.friction = friction;
|
| 940 | }
|
| 941 |
|
| 942 | //DO NOT USE THIS IN CHECKS. USE MoveEvent#isLiquidExit()
|
| 943 | public boolean isExitingLiquidTemp() {
|
| 944 | return liquidExit;
|
| 945 | }
|
| 946 |
|
| 947 | public void setLiquidExit(boolean liquidExit) {
|
| 948 | this.liquidExit = liquidExit;
|
| 949 | }
|
| 950 |
|
| 951 | //safely kill the connection
|
| 952 | public void kickPlayer(String reason) {
|
| 953 | online = false;
|
| 954 | Bukkit.getScheduler().scheduleSyncDelayedTask(hawk, () -> p.kickPlayer(reason), 0L);
|
| 955 | }
|
| 956 |
|
| 957 | //safely force player to release item (bow, consumable, or sword blocking)
|
| 958 | public void releaseItem() {
|
| 959 | Bukkit.getScheduler().scheduleSyncDelayedTask(hawk, () -> ((WrappedEntityHuman)WrappedEntity.getWrappedEntity(p)).releaseItem());
|
| 960 | sendSimulatedAction(() -> {
|
| 961 | setBlocking(false);
|
| 962 | setPullingBow(false);
|
| 963 | setConsumingItem(false);
|
| 964 | });
|
| 965 | }
|
| 966 |
|
| 967 | public void addPendingTeleport(Location loc) {
|
| 968 | pendingTeleports.add(new Pair<>(loc, currentTick));
|
| 969 | if(pendingTeleports.size() > 200) {
|
| 970 | pendingTeleports.remove(0);
|
| 971 | }
|
| 972 | }
|
| 973 |
|
| 974 | private void cleanUpOldPendingTeleports() {
|
| 975 | if(pendingTeleports.size() == 0)
|
| 976 | return;
|
| 977 | while(pendingTeleports.size() > 0 && currentTick - pendingTeleports.get(0).getValue() > (ping + 2000) / 50) {
|
| 978 | pendingTeleports.remove(0);
|
| 979 | }
|
| 980 | }
|
| 981 |
|
| 982 | public List<Pair<Location, Long>> getPendingTeleports() {
|
| 983 | return pendingTeleports;
|
| 984 | }
|
| 985 |
|
| 986 | //This method simulates the reaction of the client by a server packet.
|
| 987 | //This is accomplished by simulating latency.
|
| 988 | //This can be used to simulate sprint-update or inventory-open packets
|
| 989 | public void sendSimulatedAction(Runnable action) {
|
| 990 | simulatedCmds.add(new Pair<>(action, System.currentTimeMillis()));
|
| 991 | }
|
| 992 |
|
| 993 | private void executeTasks() {
|
| 994 | if(simulatedCmds.size() == 0)
|
| 995 | return;
|
| 996 | int ping = ServerUtils.getPing(p);
|
| 997 | long currTime = System.currentTimeMillis();
|
| 998 | while(simulatedCmds.size() > 0 && currTime - simulatedCmds.get(0).getValue() >= ping) {
|
| 999 | simulatedCmds.get(0).getKey().run();
|
| 1000 | simulatedCmds.remove(0);
|
| 1001 | }
|
| 1002 | }
|
| 1003 |
|
| 1004 | public void addMetaDataUpdate(MetaData metaData) {
|
| 1005 | metaDataUpdates.add(new Pair<>(metaData, System.currentTimeMillis()));
|
| 1006 | //in case something happens, let's not hog memory...
|
| 1007 | if(metaDataUpdates.size() > 200) {
|
| 1008 | metaDataUpdates.remove(0);
|
| 1009 | }
|
| 1010 | }
|
| 1011 |
|
| 1012 | public List<Pair<MetaData, Long>> getMetaDataUpdates() {
|
| 1013 | return metaDataUpdates;
|
| 1014 | }
|
| 1015 |
|
| 1016 | private void cleanUpOldMetaDataUpdates() {
|
| 1017 | if(metaDataUpdates.size() == 0)
|
| 1018 | return;
|
| 1019 | long currTime = System.currentTimeMillis();
|
| 1020 | while(metaDataUpdates.size() > 0 && currTime - metaDataUpdates.get(0).getValue() > ping + 2000) {
|
| 1021 | metaDataUpdates.remove(0);
|
| 1022 | }
|
| 1023 | }
|
| 1024 |
|
| 1025 | public Set<Entity> getEntitiesInteractedInThisTick() {
|
| 1026 | return entitiesInteractedInThisTick;
|
| 1027 | }
|
| 1028 |
|
| 1029 | public void addEntityToEntitiesInteractedInThisTick(Entity entity) {
|
| 1030 | entitiesInteractedInThisTick.add(entity);
|
| 1031 | }
|
| 1032 |
|
| 1033 | public AABB getCollisionBox() {
|
| 1034 | return WrappedEntity.getWrappedEntity(p).getCollisionBox(position);
|
| 1035 | }
|
| 1036 |
|
| 1037 | public AABB getHitBox() {
|
| 1038 | return WrappedEntity.getWrappedEntity(p).getHitbox(position);
|
| 1039 | }
|
| 1040 |
|
| 1041 | public int getClientVersion() {
|
| 1042 | return clientVersion;
|
| 1043 | }
|
| 1044 |
|
| 1045 | public void setClientVersion(int protocolVersion) {
|
| 1046 | clientVersion = protocolVersion == 47 ? 8 : 7;
|
| 1047 | }
|
| 1048 |
|
| 1049 | public boolean isInVehicle() {
|
| 1050 | return inVehicle;
|
| 1051 | }
|
| 1052 |
|
| 1053 | public void setInVehicle(boolean inVehicle) {
|
| 1054 | this.inVehicle = inVehicle;
|
| 1055 | }
|
| 1056 |
|
| 1057 | public int getItemConsumeTicks() {
|
| 1058 | return itemConsumeTicks;
|
| 1059 | }
|
| 1060 |
|
| 1061 | //Dedicated method for approximating whether a player is consuming or charging bow.
|
| 1062 | //Factors in meta-data updates sent from server. Damn it, Mojang. >:(
|
| 1063 | public boolean isConsumingOrPullingBowMetadataIncluded() {
|
| 1064 | boolean consumingOrBow = isConsumingItem() || isPullingBow();
|
| 1065 | long currTime = System.currentTimeMillis();
|
| 1066 | int ping = ServerUtils.getPing(p) + 100;
|
| 1067 | for(Pair<MetaData, Long> metaDataPair : getMetaDataUpdates()) {
|
| 1068 | //Ideally it would be +/-50ms leniency, but let's do +/-100ms just because of network jitter.
|
| 1069 | if(Math.abs(metaDataPair.getValue() + ping - currTime) < 100) {
|
| 1070 | MetaData metaData = metaDataPair.getKey();
|
| 1071 | if(metaData.getType() == MetaData.Type.USE_ITEM && !metaData.getValue()) {
|
| 1072 | consumingOrBow = false;
|
| 1073 | break;
|
| 1074 | }
|
| 1075 | }
|
| 1076 | }
|
| 1077 | return consumingOrBow;
|
| 1078 | }
|
| 1079 |
|
| 1080 | public boolean isAllowedToFly() {
|
| 1081 | return allowedToFly;
|
| 1082 | }
|
| 1083 |
|
| 1084 | public void setAllowedToFly(boolean allowedToFly) {
|
| 1085 | this.allowedToFly = allowedToFly;
|
| 1086 | }
|
| 1087 |
|
| 1088 | public boolean isFlying() {
|
| 1089 | return flying;
|
| 1090 | }
|
| 1091 |
|
| 1092 | public void setFlying(boolean flying) {
|
| 1093 | if(!isAllowedToFly() && flying)
|
| 1094 | return;
|
| 1095 | this.flying = flying;
|
| 1096 | }
|
| 1097 |
|
| 1098 | public boolean isInCreative() {
|
| 1099 | return inCreative;
|
| 1100 | }
|
| 1101 |
|
| 1102 | public void setInCreative(boolean inCreative) {
|
| 1103 | this.inCreative = inCreative;
|
| 1104 | }
|
| 1105 |
|
| 1106 | public boolean hasSentPosUpdate() {
|
| 1107 | return sentPosUpdate;
|
| 1108 | }
|
| 1109 |
|
| 1110 | public void setSentPosUpdate(boolean hasSentPosUpdate) {
|
| 1111 | this.sentPosUpdate = hasSentPosUpdate;
|
| 1112 | }
|
| 1113 |
|
| 1114 | public Location getAltSetbackLoc() {
|
| 1115 | return altSetbackLoc;
|
| 1116 | }
|
| 1117 |
|
| 1118 | public void setAltSetbackLoc(Location altSetbackLoc) {
|
| 1119 | this.altSetbackLoc = altSetbackLoc;
|
| 1120 | }
|
| 1121 | }
|