Vinetos

Bukkit NMS | Écoute de Packets (#03) - Listener.java

Nov 11th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import com.comphenix.protocol.PacketType;
  2. import com.comphenix.protocol.events.ListenerPriority;
  3. import com.comphenix.protocol.events.PacketAdapter;
  4. import com.comphenix.protocol.events.PacketEvent;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.entity.Player;
  7.  
  8. /**
  9. * @author VINETOS on 08/11/2015.
  10. */
  11. public class Listener {
  12.  
  13. private static boolean on = false;
  14.  
  15. public static void listenChatPackets(){
  16. if(on)return;
  17. on = true;
  18. Main.getprotocolManager().addPacketListener(new PacketAdapter(Main.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.CHAT) {
  19. @Override
  20. public void onPacketReceiving(PacketEvent e) {
  21. if(e.getPacketType() == PacketType.Play.Client.CHAT){
  22. Player p = e.getPlayer();
  23. String msg = e.getPacket().getStrings().read(0);
  24. Bukkit.broadcastMessage("§c"+p.getName()+" §7a écrit: "+msg);
  25. e.setCancelled(true);
  26. }
  27. }
  28. });
  29.  
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment