Ejemplo n.º 1
0
  public void a(Packet102WindowClick packet102windowclick) {
    // CraftBukkit start
    if (this.player.dead) {
      return;
    }
    // CraftBukkit end

    if (this.player.activeContainer.f == packet102windowclick.a
        && this.player.activeContainer.c(this.player)) {
      ItemStack itemstack =
          this.player.activeContainer.a(
              packet102windowclick.b, packet102windowclick.c, packet102windowclick.f, this.player);

      if (ItemStack.equals(packet102windowclick.e, itemstack)) {
        this.player.netServerHandler.sendPacket(
            new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, true));
        this.player.h = true;
        this.player.activeContainer.a();
        this.player.y();
        this.player.h = false;
      } else {
        this.n.put(
            Integer.valueOf(this.player.activeContainer.f), Short.valueOf(packet102windowclick.d));
        this.player.netServerHandler.sendPacket(
            new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, false));
        this.player.activeContainer.a(this.player, false);
        ArrayList arraylist = new ArrayList();

        for (int i = 0; i < this.player.activeContainer.e.size(); ++i) {
          arraylist.add(((Slot) this.player.activeContainer.e.get(i)).getItem());
        }

        this.player.a(this.player.activeContainer, arraylist);
      }
    }
  }
Ejemplo n.º 2
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;
  }