@Override
  public void a(Packet108ButtonClick packet) {
    if (this.player.activeContainer instanceof ContainerEnchantTable)
      if (this.player.activeContainer.windowId == packet.a
          && this.player.activeContainer.c(this.player)) {
        // Store our pre-event values
        CraftPlayer player = (CraftPlayer) this.player.getBukkitEntity();
        Inventory inventory = getActiveInventory();
        ContainerEnchantTable table = (ContainerEnchantTable) this.player.activeContainer;
        ItemStack initial = table.a.getItem(0).cloneItemStack();
        int level = this.player.expLevel;

        if (table.a(this.player, packet.b)) {
          ItemStack after = ((ContainerEnchantTable) this.player.activeContainer).a.getItem(0);
          int afterLevel = this.player.expLevel;

          SpoutCraftItemStack before = SpoutCraftItemStack.fromItemStack(initial);
          SpoutCraftItemStack result = SpoutCraftItemStack.fromItemStack(after);
          InventoryEnchantEvent event =
              new InventoryEnchantEvent(player, inventory, before, result, level, afterLevel);
          Bukkit.getServer().getPluginManager().callEvent(event);

          if (event.isCancelled()) {
            player.setLevel(level);
            table.a.setItem(0, initial);
          } else {
            player.setLevel(event.getLevelAfter());
            table.a.setItem(0, SpoutCraftItemStack.createNMSItemStack(event.getResult()));
          }
        }
        this.player.activeContainer.a();
      } else super.a(packet);
  }
  // Called from the main thread only
  private void syncedSendPacket(Packet packet, MCCraftPacket[] packetWrappers) {
    int packetId = -1;
    try {
      packetId = packet.b();
    } catch (Exception e) {
      return;
    }

    try {
      if (!PacketListeners.canSend(getPlayer(), packet, packetWrappers, packetId)) {
        return;
      } else {
        if (packet instanceof Packet51MapChunk) {
          Packet51MapChunk chunk = (Packet51MapChunk) packet;
          if (chunk.buffer == null) {
            ChunkCompressionThread.sendPacket(player, packet);
            return;
          }
        }
        super.sendPacket(packet);
      }
    } catch (NullPointerException npe) {
      if (packet != null) {
        throw new RuntimeException(
            "Null pointer exception thrown when trying to process packet of type "
                + packet.getClass().getName(),
            npe);
      } else {
        throw npe;
      }
    }
  }
  @Override
  public void a(Packet101CloseWindow packet) {
    Inventory inventory = getActiveInventory();

    InventoryCloseEvent event =
        new InventoryCloseEvent(
            (Player) this.player.getBukkitEntity(),
            inventory,
            getDefaultInventory(),
            activeLocation);
    Bukkit.getServer().getPluginManager().callEvent(event);

    if (event.isCancelled()) {
      IInventory inv = ((CraftInventory) event.getInventory()).getInventory();
      if (inventory instanceof TileEntityFurnace) {
        this.player.a((TileEntityFurnace) inventory);
      } else if (inventory instanceof TileEntityDispenser) {
        this.player.a((TileEntityDispenser) inventory);
      } else if (inventory instanceof InventoryCraftResult
          && this.player.activeContainer instanceof ContainerWorkbench) {
        sendPacket(new Packet100OpenWindow(packet.a, 1, "Crafting", 9));
        this.player.syncInventory();
      } else if (inventory instanceof InventoryCraftResult) {
        // There is no way to force a player's own inventory back open.
      } else {
        this.player.a(inv);
      }
    } else {
      activeInventory = false;
      activeLocation = null;
      super.a(packet);
    }
  }
 @Override
 public void a(Packet10Flying packet) {
   manageChunkQueue(true);
   SpoutPlayer player = SpoutManager.getPlayer(this.getPlayer());
   boolean old = ((CraftServer) Bukkit.getServer()).getHandle().server.allowFlight;
   ((CraftServer) Bukkit.getServer()).getHandle().server.allowFlight = player.canFly();
   super.a(packet);
   ((CraftServer) Bukkit.getServer()).getHandle().server.allowFlight = old;
 }
  @Override
  public void disconnect(String kick) {

    processingKick.set(
        true); // If any packets are sent while this flag is true, it will flush the sync queue

    super.disconnect(kick);
    if (this.disconnected) syncFlushPacketQueue(new MCCraftPacket[256]);

    processingKick.set(false);
  }
 public void flushUnloadQueue() {
   synchronized (unloadQueue) {
     Iterator<ChunkCoordIntPair> i = unloadQueue.iterator();
     while (i.hasNext()) {
       ChunkCoordIntPair coord = i.next();
       if (activeChunks.remove(coord)) {
         super.sendPacket(new Packet50PreChunk(coord.x, coord.z, false));
       }
       i.remove();
     }
   }
 }
 @Override
 public void a(Packet14BlockDig packet) {
   SpoutCraftPlayer player = (SpoutCraftPlayer) SpoutCraftPlayer.getPlayer(getPlayer());
   boolean inAir = false;
   if (player.canFly() && !player.getHandle().onGround) {
     inAir = true;
     player.getHandle().onGround = true;
   }
   super.a(packet);
   if (inAir) {
     player.getHandle().onGround = false;
   }
 }
 @Override
 public void a(Packet18ArmAnimation packet) {
   if (packet.a == -42) {
     SpoutCraftPlayer player = (SpoutCraftPlayer) SpoutCraftPlayer.getPlayer(getPlayer());
     player.setBuildVersion(1); // Don't know yet, just set above zero
     try {
       Spout.getInstance().playerListener.manager.onSpoutcraftEnable((SpoutPlayer) getPlayer());
     } catch (Exception e) {
       e.printStackTrace();
     }
   } else {
     super.a(packet);
   }
 }
 @Override
 public void a(Packet3Chat packet) {
   String chat = packet.message;
   if (chat.trim().isEmpty()) {
     return;
   }
   if (!allowReload && chat.equalsIgnoreCase("/reload")) {
     allowReload = true;
     SpoutCraftPlayer player = (SpoutCraftPlayer) SpoutCraftPlayer.getPlayer(getPlayer());
     if (!player.isSpoutCraftEnabled()) {
       player.sendMessage(ChatColor.RED + "Spout does not support the /reload command.");
       player.sendMessage(ChatColor.RED + "Unexpected behavior may occur.");
       player.sendMessage(ChatColor.RED + "We recommend using /stop and restarting.");
       player.sendMessage(ChatColor.RED + "Or you can use /spout reload to reload the config.");
       player.sendMessage(
           ChatColor.RED + "If you want to use /reload anyway, use the command again.");
     } else {
       Label warning =
           new DecayingLabel(
               200,
               ChatColor.RED
                   + "Spout does not support the /reload command."
                   + "\n"
                   + ChatColor.RED
                   + "Unexpected behavior may occur."
                   + "\n"
                   + ChatColor.RED
                   + "We recommend using /stop and restarting."
                   + " \n"
                   + ChatColor.RED
                   + "Or you can use /spout reload to reload the config."
                   + "\n"
                   + ChatColor.RED
                   + "If you want to use /reload anyway, use the command again.");
       warning.setX(100).setY(100).setPriority(RenderPriority.Lowest);
       player.getMainScreen().attachWidget(Spout.getInstance(), warning);
     }
     return;
   }
   super.a(packet);
 }
Esempio n. 10
0
 @Override
 public void a() {
   syncFlushPacketQueue();
   super.a();
 }
Esempio n. 11
0
 public CanaryNetServerHandler getServerHandler() {
   return a.getCanaryServerHandler();
 }