Need Help with Packets!

Discussion in 'Plugin Development' started by Archgames, Jan 2, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Archgames

    The code does nothing?
    Code:java
    1. @EventHandler
    2. public void compassClick(PlayerInteractEvent e) {
    3. Player player = e.getPlayer();
    4.  
    5. inv.setItem(0, Quake);
    6.  
    7. if (player.getInventory().getItemInHand().getType() == Material.COMPASS) {
    8. if (e.getAction() == Action.RIGHT_CLICK_AIR
    9. || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    10. Location loc = player.getLocation();
    11. player.playSound(loc, Sound.ITEM_PICKUP, 1, 1);
    12. player.sendMessage("Games:");
    13. IChatBaseComponent chatcomp = ChatSerializer
    14. .a("{\"text\":\" §6QuakeCraft - \",\"extra\":[{\"text\":\"§6Join Now\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/quake\"}}]}");
    15. PacketPlayOutChat packet = new PacketPlayOutChat(chatcomp, true);
    16. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    17. }
    18. }
    19. }
     
  2. Offline

    podpage

    Archgames

    I think this should work
    Code:java
    1. @EventHandler
    2. public void compassClick(PlayerInteractEvent e) {
    3. if(e.getItem().getType() == Material.COMPASS) {
    4. if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5. e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.ITEM_PICKUP, 1, 1);
    6. e.getPlayer().sendMessage("Games:");
    7. IChatBaseComponent chatcomp = ChatSerializer.a("{\"text\":\" §6QuakeCraft - \",\"extra\":[{\"text\":\"§6Join Now\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/quake\"}}]}");
    8. PacketPlayOutChat packet = new PacketPlayOutChat(chatcomp, true);
    9. ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(packet);
    10. }
    11. }
    12. }
     
  3. Offline

    Stealth2800

    Did you register the listener?
     
  4. Offline

    Archgames

    Stealth2800
    Yes, I did register the listener. I think the problem comes from here
    Code:java
    1. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);

    Pretty sure that you have to change playerConnection, becuase I think playerConnection is when player join but how might i always send it no matter what?
     
  5. Offline

    Archgames

Thread Status:
Not open for further replies.

Share This Page