Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 928 lines 30 kB view raw
1package net.minecraft.server; 2 3import java.util.Iterator; 4import java.util.List; 5 6import org.bukkit.craftbukkit.TrigMath; 7import org.bukkit.craftbukkit.entity.CraftItem; 8import org.bukkit.entity.Player; 9import org.bukkit.entity.Projectile; 10import org.bukkit.event.entity.EntityDamageByEntityEvent; 11import org.bukkit.event.entity.EntityDamageEvent; 12import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; 13import org.bukkit.event.entity.EntityTargetEvent; 14import org.bukkit.event.player.PlayerBedEnterEvent; 15import org.bukkit.event.player.PlayerBedLeaveEvent; 16import org.bukkit.event.player.PlayerDropItemEvent; 17 18import com.legacyminecraft.poseidon.PoseidonConfig; 19 20import me.devcody.uberbukkit.math.Vec3i; 21import uk.betacraft.uberbukkit.Uberbukkit; 22 23public abstract class EntityHuman extends EntityLiving { 24 25 public InventoryPlayer inventory = new InventoryPlayer(this); 26 public Container defaultContainer; 27 public Container activeContainer; 28 public byte l = 0; 29 public int m = 0; 30 public float n; 31 public float o; 32 public boolean p = false; 33 public int q = 0; 34 public String name; 35 public int dimension; 36 public double t; 37 public double u; 38 public double v; 39 public double w; 40 public double x; 41 public double y; 42 // CraftBukkit start 43 public boolean sleeping; 44 public boolean fauxSleeping; 45 public String spawnWorld = ""; 46 // CraftBukkit end 47 public ChunkCoordinates A; 48 public int sleepTicks; // CraftBukkit - private -> public 49 public float B; 50 public float C; 51 public ChunkCoordinates b; 52 private ChunkCoordinates c; 53 public int D = 20; 54 protected boolean E = false; 55 public float F; 56 private int d = 0; 57 public EntityFish hookedFish = null; 58 59 public EntityHuman(World world) { 60 super(world); 61 this.defaultContainer = new ContainerPlayer(this.inventory, !world.isStatic); 62 this.activeContainer = this.defaultContainer; 63 this.height = 1.62F; 64 ChunkCoordinates chunkcoordinates = world.getSpawn(); 65 66 this.setPositionRotation((double) chunkcoordinates.x + 0.5D, (double) (chunkcoordinates.y + 1), (double) chunkcoordinates.z + 0.5D, 0.0F, 0.0F); 67 this.health = 20; 68 this.U = "humanoid"; 69 this.T = 180.0F; 70 this.maxFireTicks = 20; 71 this.texture = "/mob/char.png"; 72 } 73 74 protected void b() { 75 super.b(); 76 this.datawatcher.a(16, Byte.valueOf((byte) 0)); 77 } 78 79 public void m_() { 80 if (this.isSleeping()) { 81 ++this.sleepTicks; 82 if (this.sleepTicks > 100) { 83 this.sleepTicks = 100; 84 } 85 86 if (!this.world.isStatic) { 87 if (!this.o()) { 88 this.a(true, true, false); 89 } else if (this.world.d()) { 90 this.a(false, true, true); 91 } 92 } 93 } else if (this.sleepTicks > 0) { 94 ++this.sleepTicks; 95 if (this.sleepTicks >= 110) { 96 this.sleepTicks = 0; 97 } 98 } 99 100 super.m_(); 101 if (!this.world.isStatic && this.activeContainer != null && !this.activeContainer.b(this)) { 102 this.y(); 103 this.activeContainer = this.defaultContainer; 104 } 105 106 this.t = this.w; 107 this.u = this.x; 108 this.v = this.y; 109 double d0 = this.locX - this.w; 110 double d1 = this.locY - this.x; 111 double d2 = this.locZ - this.y; 112 double d3 = 10.0D; 113 114 if (d0 > d3) { 115 this.t = this.w = this.locX; 116 } 117 118 if (d2 > d3) { 119 this.v = this.y = this.locZ; 120 } 121 122 if (d1 > d3) { 123 this.u = this.x = this.locY; 124 } 125 126 if (d0 < -d3) { 127 this.t = this.w = this.locX; 128 } 129 130 if (d2 < -d3) { 131 this.v = this.y = this.locZ; 132 } 133 134 if (d1 < -d3) { 135 this.u = this.x = this.locY; 136 } 137 138 this.w += d0 * 0.25D; 139 this.y += d2 * 0.25D; 140 this.x += d1 * 0.25D; 141 this.a(StatisticList.k, 1); 142 if (this.vehicle == null) { 143 this.c = null; 144 } 145 } 146 147 protected boolean D() { 148 return this.health <= 0 || this.isSleeping(); 149 } 150 151 protected void y() { 152 this.activeContainer = this.defaultContainer; 153 } 154 155 public void E() { 156 double d0 = this.locX; 157 double d1 = this.locY; 158 double d2 = this.locZ; 159 160 super.E(); 161 this.n = this.o; 162 this.o = 0.0F; 163 this.i(this.locX - d0, this.locY - d1, this.locZ - d2); 164 } 165 166 protected void c_() { 167 if (this.p) { 168 ++this.q; 169 if (this.q >= 8) { 170 this.q = 0; 171 this.p = false; 172 } 173 } else { 174 this.q = 0; 175 } 176 177 this.aa = (float) this.q / 8.0F; 178 } 179 180 public void v() { 181 // CraftBukkit - spawnMonsters -> allowMonsters 182 if (!this.world.allowMonsters && this.health < 20 && this.ticksLived % 20 * 12 == 0) { 183 this.b(1, RegainReason.REGEN); 184 } 185 186 this.inventory.f(); 187 this.n = this.o; 188 super.v(); 189 float f = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ); 190 // CraftBukkit - Math -> TrigMath 191 float f1 = (float) TrigMath.atan(-this.motY * 0.20000000298023224D) * 15.0F; 192 193 if (f > 0.1F) { 194 f = 0.1F; 195 } 196 197 if (!this.onGround || this.health <= 0) { 198 f = 0.0F; 199 } 200 201 if (this.onGround || this.health <= 0) { 202 f1 = 0.0F; 203 } 204 205 this.o += (f - this.o) * 0.4F; 206 this.aj += (f1 - this.aj) * 0.8F; 207 if (this.health > 0) { 208 List list = this.world.b((Entity) this, this.boundingBox.b(1.0D, 0.0D, 1.0D)); 209 210 if (list != null) { 211 for (int i = 0; i < list.size(); ++i) { 212 Entity entity = (Entity) list.get(i); 213 214 if (!entity.dead) { 215 this.i(entity); 216 } 217 } 218 } 219 } 220 } 221 222 private void i(Entity entity) { 223 entity.b(this); 224 } 225 226 public void die(Entity entity) { 227 super.die(entity); 228 this.b(0.2F, 0.2F); 229 this.setPosition(this.locX, this.locY, this.locZ); 230 this.motY = 0.10000000149011612D; 231 if (this.name.equals("Notch")) { 232 this.a(new ItemStack(Item.APPLE, 1), true); 233 } 234 235 this.inventory.h(); 236 if (entity != null) { 237 this.motX = (double) (-MathHelper.cos((this.af + this.yaw) * 3.1415927F / 180.0F) * 0.1F); 238 this.motZ = (double) (-MathHelper.sin((this.af + this.yaw) * 3.1415927F / 180.0F) * 0.1F); 239 } else { 240 this.motX = this.motZ = 0.0D; 241 } 242 243 this.height = 0.1F; 244 this.a(StatisticList.y, 1); 245 } 246 247 public void c(Entity entity, int i) { 248 this.m += i; 249 if (entity instanceof EntityHuman) { 250 this.a(StatisticList.A, 1); 251 } else { 252 this.a(StatisticList.z, 1); 253 } 254 } 255 256 public void F() { 257 this.a(this.inventory.splitStack(this.inventory.itemInHandIndex, 1), false); 258 } 259 260 public void b(ItemStack itemstack) { 261 this.a(itemstack, false); 262 } 263 264 public void a(ItemStack itemstack, boolean flag) { 265 if (itemstack != null) { 266 EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY - 0.30000001192092896D + (double) this.t(), this.locZ, itemstack); 267 268 entityitem.pickupDelay = 40; 269 float f = 0.1F; 270 float f1; 271 272 if (flag) { 273 f1 = this.random.nextFloat() * 0.5F; 274 float f2 = this.random.nextFloat() * 3.1415927F * 2.0F; 275 276 entityitem.motX = (double) (-MathHelper.sin(f2) * f1); 277 entityitem.motZ = (double) (MathHelper.cos(f2) * f1); 278 entityitem.motY = 0.20000000298023224D; 279 } else { 280 f = 0.3F; 281 entityitem.motX = (double) (-MathHelper.sin(this.yaw / 180.0F * 3.1415927F) * MathHelper.cos(this.pitch / 180.0F * 3.1415927F) * f); 282 entityitem.motZ = (double) (MathHelper.cos(this.yaw / 180.0F * 3.1415927F) * MathHelper.cos(this.pitch / 180.0F * 3.1415927F) * f); 283 entityitem.motY = (double) (-MathHelper.sin(this.pitch / 180.0F * 3.1415927F) * f + 0.1F); 284 f = 0.02F; 285 f1 = this.random.nextFloat() * 3.1415927F * 2.0F; 286 f *= this.random.nextFloat(); 287 entityitem.motX += Math.cos((double) f1) * (double) f; 288 entityitem.motY += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); 289 entityitem.motZ += Math.sin((double) f1) * (double) f; 290 } 291 292 // CraftBukkit start 293 Player player = (Player) this.getBukkitEntity(); 294 CraftItem drop = new CraftItem(this.world.getServer(), entityitem); 295 296 PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop); 297 this.world.getServer().getPluginManager().callEvent(event); 298 299 if (event.isCancelled()) { 300 player.getInventory().addItem(drop.getItemStack()); 301 return; 302 } 303 // CraftBukkit end 304 305 this.a(entityitem); 306 this.a(StatisticList.v, 1); 307 } 308 } 309 310 protected void a(EntityItem entityitem) { 311 this.world.addEntity(entityitem); 312 } 313 314 public float a(Block block) { 315 float f = this.inventory.a(block); 316 317 if (this.a(Material.WATER)) { 318 f /= 5.0F; 319 } 320 321 if (!this.onGround) { 322 f /= 5.0F; 323 } 324 325 return f; 326 } 327 328 public boolean b(Block block) { 329 return this.inventory.b(block); 330 } 331 332 public void a(NBTTagCompound nbttagcompound) { 333 super.a(nbttagcompound); 334 NBTTagList nbttaglist = nbttagcompound.l("Inventory"); 335 336 this.inventory.b(nbttaglist); 337 this.dimension = nbttagcompound.e("Dimension"); 338 this.sleeping = nbttagcompound.m("Sleeping"); 339 this.sleepTicks = nbttagcompound.d("SleepTimer"); 340 if (this.sleeping) { 341 this.A = new ChunkCoordinates(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)); 342 this.a(true, true, false); 343 } 344 345 // CraftBukkit start 346 this.spawnWorld = nbttagcompound.getString("SpawnWorld"); 347 if (this.spawnWorld == "") { 348 this.spawnWorld = this.world.getServer().getWorlds().get(0).getName(); 349 } 350 // CraftBukkit end 351 352 if (nbttagcompound.hasKey("SpawnX") && nbttagcompound.hasKey("SpawnY") && nbttagcompound.hasKey("SpawnZ")) { 353 this.b = new ChunkCoordinates(nbttagcompound.e("SpawnX"), nbttagcompound.e("SpawnY"), nbttagcompound.e("SpawnZ")); 354 } 355 } 356 357 public void b(NBTTagCompound nbttagcompound) { 358 super.b(nbttagcompound); 359 nbttagcompound.a("Inventory", (NBTBase) this.inventory.a(new NBTTagList())); 360 nbttagcompound.a("Dimension", this.dimension); 361 nbttagcompound.a("Sleeping", this.sleeping); 362 nbttagcompound.a("SleepTimer", (short) this.sleepTicks); 363 if (this.b != null) { 364 nbttagcompound.a("SpawnX", this.b.x); 365 nbttagcompound.a("SpawnY", this.b.y); 366 nbttagcompound.a("SpawnZ", this.b.z); 367 nbttagcompound.setString("SpawnWorld", this.spawnWorld); // CraftBukkit 368 } 369 } 370 371 public void a(IInventory iinventory) { 372 } 373 374 public void a(IInventory iinventory, Vec3i position) { 375 } 376 377 public void b(int i, int j, int k) { 378 } 379 380 public void receive(Entity entity, int i) { 381 } 382 383 public float t() { 384 return 0.12F; 385 } 386 387 protected void s() { 388 this.height = 1.62F; 389 } 390 391 public boolean damageEntity(Entity entity, int i) { 392 this.ay = 0; 393 if (this.health <= 0) { 394 return false; 395 } else { 396 if (this.isSleeping() && !this.world.isStatic) { 397 this.a(true, true, false); 398 } 399 400 if (entity instanceof EntityMonster || entity instanceof EntityArrow) { 401 if (this.world.spawnMonsters == 0) { 402 i = 0; 403 } 404 405 if (this.world.spawnMonsters == 1) { 406 i = i / 3 + 1; 407 } 408 409 if (this.world.spawnMonsters == 3) { 410 i = i * 3 / 2; 411 } 412 } 413 414 if (i == 0) { 415 return false; 416 } else { 417 Object object = entity; 418 419 if (entity instanceof EntityArrow && ((EntityArrow) entity).shooter != null) { 420 object = ((EntityArrow) entity).shooter; 421 } 422 423 if (object instanceof EntityLiving) { 424 // CraftBukkit start - this is here instead of EntityMonster because EntityLiving(s) that aren't monsters 425 // also damage the player in this way. For example, EntitySlime. 426 427 // We handle projectiles in their individual classes! 428 if (!(entity.getBukkitEntity() instanceof Projectile)) { 429 org.bukkit.entity.Entity damager = ((Entity) object).getBukkitEntity(); 430 org.bukkit.entity.Entity damagee = this.getBukkitEntity(); 431 432 EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, i); 433 this.world.getServer().getPluginManager().callEvent(event); 434 435 if (event.isCancelled() || event.getDamage() == 0) { 436 return false; 437 } 438 439 i = event.getDamage(); 440 } 441 // CraftBukkit end 442 443 this.a((EntityLiving) object, false); 444 } 445 446 this.a(StatisticList.x, i); 447 return super.damageEntity(entity, i); 448 } 449 } 450 } 451 452 protected boolean j_() { 453 return false; 454 } 455 456 protected void a(EntityLiving entityliving, boolean flag) { 457 if (!(entityliving instanceof EntityCreeper) && !(entityliving instanceof EntityGhast)) { 458 if (entityliving instanceof EntityWolf) { 459 EntityWolf entitywolf = (EntityWolf) entityliving; 460 461 if (entitywolf.isTamed() && this.name.equals(entitywolf.getOwnerName())) { 462 return; 463 } 464 } 465 466 if (!(entityliving instanceof EntityHuman) || this.j_()) { 467 List list = this.world.a(EntityWolf.class, AxisAlignedBB.b(this.locX, this.locY, this.locZ, this.locX + 1.0D, this.locY + 1.0D, this.locZ + 1.0D).b(16.0D, 4.0D, 16.0D)); 468 Iterator iterator = list.iterator(); 469 470 while (iterator.hasNext()) { 471 Entity entity = (Entity) iterator.next(); 472 EntityWolf entitywolf1 = (EntityWolf) entity; 473 474 if (entitywolf1.isTamed() && entitywolf1.F() == null && this.name.equals(entitywolf1.getOwnerName()) && (!flag || !entitywolf1.isSitting())) { 475 // CraftBukkit start 476 org.bukkit.entity.Entity bukkitTarget = entity == null ? null : entityliving.getBukkitEntity(); 477 478 EntityTargetEvent event; 479 if (flag) { 480 event = new EntityTargetEvent(entitywolf1.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET); 481 } else { 482 event = new EntityTargetEvent(entitywolf1.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER); 483 } 484 this.world.getServer().getPluginManager().callEvent(event); 485 486 if (event.isCancelled()) { 487 continue; 488 } 489 // CraftBukkit end 490 491 entitywolf1.setSitting(false); 492 entitywolf1.setTarget(entityliving); 493 } 494 } 495 } 496 } 497 } 498 499 protected void c(int i) { 500 int j = 25 - this.inventory.g(); 501 int k = i * j + this.d; 502 503 this.inventory.c(i); 504 i = k / 25; 505 this.d = k % 25; 506 super.c(i); 507 } 508 509 public void a(TileEntityFurnace tileentityfurnace) { 510 } 511 512 public void a(TileEntityDispenser tileentitydispenser) { 513 } 514 515 public void a(TileEntitySign tileentitysign) { 516 } 517 518 public void c(Entity entity) { 519 if (!entity.a(this)) { 520 ItemStack itemstack = this.G(); 521 522 if (itemstack != null && entity instanceof EntityLiving) { 523 itemstack.a((EntityLiving) entity); 524 // CraftBukkit - bypass infinite items; <= 0 -> == 0 525 if (itemstack.count == 0) { 526 itemstack.a(this); 527 this.H(); 528 } 529 } 530 } 531 } 532 533 public ItemStack G() { 534 return this.inventory.getItemInHand(); 535 } 536 537 public void H() { 538 this.inventory.setItem(this.inventory.itemInHandIndex, (ItemStack) null); 539 } 540 541 public double I() { 542 return (double) (this.height - 0.5F); 543 } 544 545 public void w() { 546 this.q = -1; 547 this.p = true; 548 } 549 550 public void d(Entity entity) { 551 int i = this.inventory.a(entity); 552 553 if (i > 0) { 554 if (Uberbukkit.getTargetPVN() >= 11) { 555 if (this.motY < 0.0D) { 556 ++i; 557 } 558 } 559 // CraftBukkit start - Don't call the event when the entity is human since it will be called with damageEntity 560 if (entity instanceof EntityLiving && !(entity instanceof EntityHuman)) { 561 org.bukkit.entity.Entity damager = this.getBukkitEntity(); 562 org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity(); 563 564 EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, i); 565 this.world.getServer().getPluginManager().callEvent(event); 566 567 if (event.isCancelled() || event.getDamage() == 0) { 568 return; 569 } 570 571 i = event.getDamage(); 572 } 573 // CraftBukkit end 574 575 // CraftBukkit start - Return when the damage fails so that the item will not lose durability 576 double d0 = entity.motX; 577 double d1 = entity.motY; 578 double d2 = entity.motZ; 579 580 if (!entity.damageEntity(this, i)) { 581 return; 582 } 583 584 if (entity instanceof EntityPlayer && entity.velocityChanged && PoseidonConfig.getInstance().getBoolean("settings.player-knockback-fix.enabled", true)) { 585 boolean cancelled = false; 586 org.bukkit.entity.Player player = (org.bukkit.entity.Player) entity.getBukkitEntity(); 587 org.bukkit.util.Vector velocity = new org.bukkit.util.Vector(d0, d1, d2); 588 589 org.bukkit.event.player.PlayerVelocityEvent event = new org.bukkit.event.player.PlayerVelocityEvent(player, velocity.clone()); 590 this.world.getServer().getPluginManager().callEvent(event); 591 592 if (event.isCancelled()) { 593 cancelled = true; 594 } else if (!velocity.equals(event.getVelocity())) { 595 player.setVelocity(velocity); 596 } 597 598 if (!cancelled) { 599 ((EntityPlayer) entity).netServerHandler.sendPacket(new Packet28EntityVelocity(entity)); 600 entity.velocityChanged = false; 601 entity.motX = d0; 602 entity.motY = d1; 603 entity.motZ = d2; 604 } 605 } 606 607 // CraftBukkit end 608 609 ItemStack itemstack = this.G(); 610 611 if (itemstack != null && entity instanceof EntityLiving) { 612 itemstack.a((EntityLiving) entity, this); 613 // CraftBukkit - bypass infinite items; <= 0 -> == 0 614 if (itemstack.count == 0) { 615 itemstack.a(this); 616 this.H(); 617 } 618 } 619 620 if (entity instanceof EntityLiving) { 621 if (entity.T()) { 622 this.a((EntityLiving) entity, true); 623 } 624 625 this.a(StatisticList.w, i); 626 } 627 } 628 } 629 630 public void a(ItemStack itemstack) { 631 } 632 633 public void die() { 634 super.die(); 635 this.defaultContainer.a(this); 636 if (this.activeContainer != null) { 637 this.activeContainer.a(this); 638 } 639 } 640 641 public boolean K() { 642 return !this.sleeping && super.K(); 643 } 644 645 public EnumBedError a(int i, int j, int k) { 646 if (!this.world.isStatic) { 647 if (this.isSleeping() || !this.T()) { 648 return EnumBedError.OTHER_PROBLEM; 649 } 650 651 if (this.world.worldProvider.c) { 652 return EnumBedError.NOT_POSSIBLE_HERE; 653 } 654 655 if (this.world.d()) { 656 return EnumBedError.NOT_POSSIBLE_NOW; 657 } 658 659 if (Math.abs(this.locX - (double) i) > 3.0D || Math.abs(this.locY - (double) j) > 2.0D || Math.abs(this.locZ - (double) k) > 3.0D) { 660 return EnumBedError.TOO_FAR_AWAY; 661 } 662 } 663 664 // CraftBukkit start 665 if (this.getBukkitEntity() instanceof Player) { 666 Player player = (Player) this.getBukkitEntity(); 667 org.bukkit.block.Block bed = this.world.getWorld().getBlockAt(i, j, k); 668 669 PlayerBedEnterEvent event = new PlayerBedEnterEvent(player, bed); 670 this.world.getServer().getPluginManager().callEvent(event); 671 672 if (event.isCancelled()) { 673 return EnumBedError.OTHER_PROBLEM; 674 } 675 } 676 // CraftBukkit end 677 678 this.b(0.2F, 0.2F); 679 this.height = 0.2F; 680 if (this.world.isLoaded(i, j, k)) { 681 int l = this.world.getData(i, j, k); 682 int i1 = BlockBed.c(l); 683 float f = 0.5F; 684 float f1 = 0.5F; 685 686 switch (i1) { 687 case 0: 688 f1 = 0.9F; 689 break; 690 691 case 1: 692 f = 0.1F; 693 break; 694 695 case 2: 696 f1 = 0.1F; 697 break; 698 699 case 3: 700 f = 0.9F; 701 } 702 703 this.e(i1); 704 this.setPosition((double) ((float) i + f), (double) ((float) j + 0.9375F), (double) ((float) k + f1)); 705 } else { 706 this.setPosition((double) ((float) i + 0.5F), (double) ((float) j + 0.9375F), (double) ((float) k + 0.5F)); 707 } 708 709 this.sleeping = true; 710 this.sleepTicks = 0; 711 this.A = new ChunkCoordinates(i, j, k); 712 this.motX = this.motZ = this.motY = 0.0D; 713 if (!this.world.isStatic) { 714 this.world.everyoneSleeping(); 715 } 716 717 return EnumBedError.OK; 718 } 719 720 private void e(int i) { 721 this.B = 0.0F; 722 this.C = 0.0F; 723 switch (i) { 724 case 0: 725 this.C = -1.8F; 726 break; 727 728 case 1: 729 this.B = 1.8F; 730 break; 731 732 case 2: 733 this.C = 1.8F; 734 break; 735 736 case 3: 737 this.B = -1.8F; 738 } 739 } 740 741 public void a(boolean flag, boolean flag1, boolean flag2) { 742 this.b(0.6F, 1.8F); 743 this.s(); 744 ChunkCoordinates chunkcoordinates = this.A; 745 ChunkCoordinates chunkcoordinates1 = this.A; 746 747 if (chunkcoordinates != null && this.world.getTypeId(chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z) == Block.BED.id) { 748 BlockBed.a(this.world, chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z, false); 749 chunkcoordinates1 = BlockBed.f(this.world, chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z, 0); 750 if (chunkcoordinates1 == null) { 751 chunkcoordinates1 = new ChunkCoordinates(chunkcoordinates.x, chunkcoordinates.y + 1, chunkcoordinates.z); 752 } 753 754 this.setPosition((double) ((float) chunkcoordinates1.x + 0.5F), (double) ((float) chunkcoordinates1.y + this.height + 0.1F), (double) ((float) chunkcoordinates1.z + 0.5F)); 755 } 756 757 this.sleeping = false; 758 if (!this.world.isStatic && flag1) { 759 this.world.everyoneSleeping(); 760 } 761 762 // CraftBukkit start 763 if (this.getBukkitEntity() instanceof Player) { 764 Player player = (Player) this.getBukkitEntity(); 765 766 org.bukkit.block.Block bed; 767 if (chunkcoordinates != null) { 768 bed = this.world.getWorld().getBlockAt(chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z); 769 } else { 770 bed = this.world.getWorld().getBlockAt(player.getLocation()); 771 } 772 773 PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed); 774 this.world.getServer().getPluginManager().callEvent(event); 775 } 776 // CraftBukkit end 777 778 if (flag) { 779 this.sleepTicks = 0; 780 } else { 781 this.sleepTicks = 100; 782 } 783 784 if (flag2 && PoseidonConfig.getInstance().getBoolean("version.mechanics.beds_set_spawnpoint", true)) { 785 this.a(this.A); 786 } 787 } 788 789 private boolean o() { 790 return this.world.getTypeId(this.A.x, this.A.y, this.A.z) == Block.BED.id; 791 } 792 793 public static ChunkCoordinates getBed(World world, ChunkCoordinates chunkcoordinates) { 794 IChunkProvider ichunkprovider = world.o(); 795 796 ichunkprovider.getChunkAt(chunkcoordinates.x - 3 >> 4, chunkcoordinates.z - 3 >> 4); 797 ichunkprovider.getChunkAt(chunkcoordinates.x + 3 >> 4, chunkcoordinates.z - 3 >> 4); 798 ichunkprovider.getChunkAt(chunkcoordinates.x - 3 >> 4, chunkcoordinates.z + 3 >> 4); 799 ichunkprovider.getChunkAt(chunkcoordinates.x + 3 >> 4, chunkcoordinates.z + 3 >> 4); 800 if (world.getTypeId(chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z) != Block.BED.id) { 801 return null; 802 } else { 803 ChunkCoordinates chunkcoordinates1 = BlockBed.f(world, chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z, 0); 804 805 return chunkcoordinates1; 806 } 807 } 808 809 public boolean isSleeping() { 810 return this.sleeping; 811 } 812 813 public boolean isDeeplySleeping() { 814 return this.sleeping && this.sleepTicks >= 100; 815 } 816 817 public void a(String s) { 818 } 819 820 public ChunkCoordinates getBed() { 821 return this.b; 822 } 823 824 public void a(ChunkCoordinates chunkcoordinates) { 825 if (chunkcoordinates != null) { 826 this.b = new ChunkCoordinates(chunkcoordinates); 827 this.spawnWorld = this.world.worldData.name; // CraftBukkit 828 } else { 829 this.b = null; 830 } 831 } 832 833 public void a(Statistic statistic) { 834 this.a(statistic, 1); 835 } 836 837 public void a(Statistic statistic, int i) { 838 } 839 840 protected void O() { 841 super.O(); 842 this.a(StatisticList.u, 1); 843 } 844 845 public void a(float f, float f1) { 846 double d0 = this.locX; 847 double d1 = this.locY; 848 double d2 = this.locZ; 849 850 super.a(f, f1); 851 this.h(this.locX - d0, this.locY - d1, this.locZ - d2); 852 } 853 854 private void h(double d0, double d1, double d2) { 855 if (this.vehicle == null) { 856 int i; 857 858 if (this.a(Material.WATER)) { 859 i = Math.round(MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); 860 if (i > 0) { 861 this.a(StatisticList.q, i); 862 } 863 } else if (this.ad()) { 864 i = Math.round(MathHelper.a(d0 * d0 + d2 * d2) * 100.0F); 865 if (i > 0) { 866 this.a(StatisticList.m, i); 867 } 868 } else if (this.p()) { 869 if (d1 > 0.0D) { 870 this.a(StatisticList.o, (int) Math.round(d1 * 100.0D)); 871 } 872 } else if (this.onGround) { 873 i = Math.round(MathHelper.a(d0 * d0 + d2 * d2) * 100.0F); 874 if (i > 0) { 875 this.a(StatisticList.l, i); 876 } 877 } else { 878 i = Math.round(MathHelper.a(d0 * d0 + d2 * d2) * 100.0F); 879 if (i > 25) { 880 this.a(StatisticList.p, i); 881 } 882 } 883 } 884 } 885 886 private void i(double d0, double d1, double d2) { 887 if (this.vehicle != null) { 888 int i = Math.round(MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); 889 890 if (i > 0) { 891 if (this.vehicle instanceof EntityMinecart) { 892 this.a(StatisticList.r, i); 893 if (this.c == null) { 894 this.c = new ChunkCoordinates(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)); 895 } else if (this.c.a(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)) >= 1000.0D) { 896 this.a(AchievementList.q, 1); 897 } 898 } else if (this.vehicle instanceof EntityBoat) { 899 this.a(StatisticList.s, i); 900 } else if (this.vehicle instanceof EntityPig) { 901 this.a(StatisticList.t, i); 902 } 903 } 904 } 905 } 906 907 protected void a(float f) { 908 if (f >= 2.0F) { 909 this.a(StatisticList.n, (int) Math.round((double) f * 100.0D)); 910 } 911 912 super.a(f); 913 } 914 915 public void a(EntityLiving entityliving) { 916 if (entityliving instanceof EntityMonster) { 917 this.a((Statistic) AchievementList.s); 918 } 919 } 920 921 public void P() { 922 if (this.D > 0) { 923 this.D = 10; 924 } else { 925 this.E = true; 926 } 927 } 928}