Exemplo n.º 1
0
 @Override
 public void onPacketReceiving(PacketEvent event) {
   // TODO
   if (getPlugin().sendDebug) System.out.println("[HUB] Packet received: " + event.getPacketID());
   String playername = event.getPlayer().getName().toLowerCase();
   if (getPlugin().playerServerMap.containsKey(playername)) {
     if (getPlugin().sendDebug)
       System.out.println(
           "[HUB] Passed On: "
               + playername
               + " ---> "
               + getPlugin().playerServerMap.get(playername));
     event.setCancelled(true);
     // TODO Pass onto server
     // sendToServer(Player p, getPlugin().playerServerMap.get(playername));
   }
 }
Exemplo n.º 2
0
  @Override
  public void onPacketSending(PacketEvent event) {

    if (!event.isCancelled() && event.getPacketID() == Packets.Server.NAMED_ENTITY_SPAWN) {

      PacketContainer packet = event.getPacket();
      StructureModifier<String> text = packet.getSpecificModifier(String.class);

      try {
        String tag = text.read(0);
        Player observer = event.getPlayer();
        Entity watched = packet.getEntityModifier(observer.getWorld()).read(0);

        if (watched instanceof Player) {
          ReceiveNameTagEvent nameTagEvent =
              new ReceiveNameTagEvent(event.getPlayer(), (Player) watched, tag);
          pluginManager.callEvent(nameTagEvent);

          if (nameTagEvent.isModified()) {
            // Trim excess
            tag = nameTagEvent.getTrimmedTag();

            // Uh, ok.
            if (tag == null) tag = "";
            text.write(0, tag);
          }

        } else {
          // Might as well notify about this
          logger.log(
              Level.WARNING,
              "Cannot find entity id " + packet.getSpecificModifier(int.class).read(0));
        }

      } catch (FieldAccessException e) {
        logger.log(Level.SEVERE, "Cannot read field.", e);
      }
    }
  }