Beispiel #1
0
  public void a(Packet15Place packet15place) {
    WorldServer worldserver = this.minecraftServer.a(this.player.dimension);

    // CraftBukkit start
    if (this.player.dead) {
      return;
    }

    // This is b horrible hack needed because the client sends 2 packets on 'right mouse click'
    // aimed at b block. We shouldn't need to get the second packet if the data is handled
    // but we cannot know what the client will do, so we might still get it
    //
    // If the time between packets is small enough, and the 'signature' similar, we discard the
    // second one. This sadly has to remain until Mojang makes their packets saner. :(
    //  -- Grum

    if (packet15place.face == 255) {
      if (packet15place.itemstack != null
          && packet15place.itemstack.id == lastMaterial
          && lastPacket != null
          && packet15place.timestamp - lastPacket < 100) {
        lastPacket = null;
        return;
      }
    } else {
      lastMaterial = packet15place.itemstack == null ? -1 : packet15place.itemstack.id;
      lastPacket = packet15place.timestamp;
    }

    // CraftBukkit - if rightclick decremented the item, always send the update packet.
    // this is not here for CraftBukkit's own functionality; rather it is to fix
    // b notch bug where the item doesn't update correctly.
    boolean always = false;

    // CraftBukkit end

    ItemStack itemstack = this.player.inventory.getItemInHand();
    boolean flag =
        worldserver.weirdIsOpCache =
            worldserver.worldProvider.dimension != 0
                || this.minecraftServer.serverConfigurationManager.isOp(this.player.name);

    if (packet15place.face == 255) {
      if (itemstack == null) {
        return;
      }

      // CraftBukkit start
      int itemstackAmount = itemstack.count;
      PlayerInteractEvent event =
          CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack);
      if (event.useItemInHand() != Event.Result.DENY) {
        this.player.itemInWorldManager.useItem(this.player, this.player.world, itemstack);
      }

      // CraftBukkit - notch decrements the counter by 1 in the above method with food,
      // snowballs and so forth, but he does it in b place that doesn't cause the
      // inventory update packet to get sent
      always = (itemstack.count != itemstackAmount);
      // CraftBukkit end
    } else {
      int i = packet15place.a;
      int j = packet15place.b;
      int k = packet15place.c;
      int l = packet15place.face;
      ChunkCoordinates chunkcoordinates = worldserver.getSpawn();
      int i1 = (int) MathHelper.abs((float) (i - chunkcoordinates.x));
      int j1 = (int) MathHelper.abs((float) (k - chunkcoordinates.z));

      if (i1 > j1) {
        j1 = i1;
      }

      // CraftBukkit start - Check if we can actually do something over this large a distance
      Location eyeLoc = getPlayer().getEyeLocation();
      if (Math.pow(eyeLoc.getX() - i, 2)
              + Math.pow(eyeLoc.getY() - j, 2)
              + Math.pow(eyeLoc.getZ() - k, 2)
          > PLACE_DISTANCE_SQUARED) {
        return;
      }
      flag = true; // spawn protection moved to ItemBlock!!!
      // CraftBukkit end

      if (j1 > 16 || flag) {
        this.player.itemInWorldManager.interact(this.player, worldserver, itemstack, i, j, k, l);
      }

      this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
      if (l == 0) {
        --j;
      }

      if (l == 1) {
        ++j;
      }

      if (l == 2) {
        --k;
      }

      if (l == 3) {
        ++k;
      }

      if (l == 4) {
        --i;
      }

      if (l == 5) {
        ++i;
      }

      this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
    }

    itemstack = this.player.inventory.getItemInHand();
    if (itemstack != null && itemstack.count == 0) {
      this.player.inventory.items[this.player.inventory.itemInHandIndex] = null;
    }

    this.player.h = true;
    this.player.inventory.items[this.player.inventory.itemInHandIndex] =
        ItemStack.b(this.player.inventory.items[this.player.inventory.itemInHandIndex]);
    Slot slot =
        this.player.activeContainer.a(this.player.inventory, this.player.inventory.itemInHandIndex);

    this.player.activeContainer.a();
    this.player.h = false;
    // CraftBukkit
    if (!ItemStack.equals(this.player.inventory.getItemInHand(), packet15place.itemstack)
        || always) {
      this.sendPacket(
          new Packet103SetSlot(
              this.player.activeContainer.f, slot.a, this.player.inventory.getItemInHand()));
    }

    worldserver.weirdIsOpCache = false;
  }
Beispiel #2
0
  public void a(Packet14BlockDig packet14blockdig) {
    // CraftBukkit start
    if (this.player.dead) {
      return;
    }
    // CraftBukkit end

    WorldServer worldserver = this.minecraftServer.a(this.player.dimension);

    if (packet14blockdig.e == 4) {
      this.player.E();
    } else {
      boolean flag =
          worldserver.weirdIsOpCache =
              worldserver.worldProvider.dimension != 0
                  || this.minecraftServer.serverConfigurationManager.isOp(this.player.name);
      boolean flag1 = false;

      if (packet14blockdig.e == 0) {
        flag1 = true;
      }

      if (packet14blockdig.e == 2) {
        flag1 = true;
      }

      int i = packet14blockdig.a;
      int j = packet14blockdig.b;
      int k = packet14blockdig.c;

      if (flag1) {
        double d0 = this.player.locX - ((double) i + 0.5D);
        double d1 = this.player.locY - ((double) j + 0.5D);
        double d2 = this.player.locZ - ((double) k + 0.5D);
        double d3 = d0 * d0 + d1 * d1 + d2 * d2;

        if (d3 > 36.0D) {
          return;
        }
      }

      ChunkCoordinates chunkcoordinates = worldserver.getSpawn();
      int l = (int) MathHelper.abs((float) (i - chunkcoordinates.x));
      int i1 = (int) MathHelper.abs((float) (k - chunkcoordinates.z));

      if (l > i1) {
        i1 = l;
      }

      if (packet14blockdig.e == 0) {
        // CraftBukkit
        if (i1 < this.minecraftServer.spawnProtection && !flag) {
          this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
        } else {
          // CraftBukkit - add face argument
          this.player.itemInWorldManager.dig(i, j, k, packet14blockdig.face);
        }
      } else if (packet14blockdig.e == 2) {
        this.player.itemInWorldManager.a(i, j, k);
        if (worldserver.getTypeId(i, j, k) != 0) {
          this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
        }
      } else if (packet14blockdig.e == 3) {
        double d4 = this.player.locX - ((double) i + 0.5D);
        double d5 = this.player.locY - ((double) j + 0.5D);
        double d6 = this.player.locZ - ((double) k + 0.5D);
        double d7 = d4 * d4 + d5 * d5 + d6 * d6;

        if (d7 < 256.0D) {
          this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
        }
      }

      worldserver.weirdIsOpCache = false;
    }
  }