How would I go about detecting a right click on a packet?

Discussion in 'Plugin Development' started by baighxansgaming, Jun 25, 2017.

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

    baighxansgaming

    Code:
    public class BlockMain extends JavaPlugin implements Listener {
    
        private EntityPlayer npc;
    
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
            Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "Tutorial Enabled!");
    
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
    
            MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
            npc = new EntityPlayer(nmsServer, nmsWorld, new GameProfile(UUID.fromString("0b5da481-4083-4341-9b19-a0495f3e31f4"), ChatColor.GREEN + "Shop"), new PlayerInteractManager(nmsWorld));
        }
    
        public void onDisable() {
            Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.RED + "Tutorial Disabled!");
        }
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            npc.setLocation(-39.5, 77, 311.5, 0, 0);
            PlayerConnection connection = ((CraftPlayer) e.getPlayer()).getHandle().playerConnection;
            connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
            connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
        }
    }
    I've tried playerinteractentityevent but that didn't work and I can't find anything else, any suggestions?
     
  2. Offline

    YoloSanta

  3. Offline

    baighxansgaming

  4. Offline

    YoloSanta

    My bad it was morning at the time Here you go
    Code:java
    1. @EventHandler
    2. public void ballFiring(PlayerInteractEvent e){
    3. Player p = e.getPlayer();
    4. if (!(e.getAction() == Action.RIGHT_CLICK_AIR))return;
     
  5. Offline

    baighxansgaming

    @YoloSanta It doesn't trigger when I click the player entity.
    It only triggers when I right click a block.
     
  6. Offline

    Zombie_Striker

    @baighxansgaming
    Interacting with entities is different than just general interactions. Use PlayerInteractAtEntityEvent for right clicking on entities.

    @YoloSant
    Please do not spoonfeed. Just tell them the events and what to check for.
     
  7. Offline

    baighxansgaming

  8. Offline

    Zombie_Striker

  9. Offline

    baighxansgaming

    @Zombie_Striker I updated to 1.12 to try your idea, but it didn't work.
    https://hastebin.com/donexezuwa.java

    I believe it's because it's a packet of an entity sent to a player so it's client side not server side so it's not a real entity, but I'm not sure though.
     
  10. Offline

    Zombie_Striker

    @baighxansgaming
    Yes, that is the case. Since it is not a real player (it's just packets sent to the player), bukkit does not detect anything regarding that entity. In order to listen for right clicking on packet-entities, you would need to use ProtocolLib.
     
  11. Offline

    baighxansgaming

    @Zombie_Striker Do you know what the event would be called on ProtocolLib?
     
  12. Offline

    Zombie_Striker

  13. Offline

    InstanceofDeath

    Otherwise you could inject in the PacketPlayIn Connection and search for a Packet named "PacketPlayInUseEntity" which gives you the EnumPlayerAction action ATTACK, INTERACT, INTERACT_AT and int a, which represents the EntityID
     
    Last edited: Jun 26, 2017
  14. Offline

    Zombie_Striker

    @InstanceofDeath
    Packet injection requires knowledge in NMS, and makes the plugin version dependent. I would not recommend it in this situation.
     
  15. Offline

    InstanceofDeath

    well you are right, but when you don't like ProtcolLib. I mean its not THAT hard. Create a versionfetcher, and boom done. And rlly I don't think that the minecraft classes are "that" complicated
     
  16. Offline

    Zombie_Striker

    @InstanceofDeath
    I honestly don't know why so many people are against protocol lib, or for that matter any API. There's no reason to re-invent the wheel by creating your own injector, when you have PL that does that for you and allows you to only need three or four lines to do so.
    If you use utils (in which case, why not use PL if you're willing to use someone else's code), then yes, it is not that hard. But, in that case, you're just bloating your own code so you don't have to use a separate jar (and even then, there are utilities that can automatically download PL if your clients don't want to).
    *Laughs in obfuscation*
     
    timtower likes this.
  17. Offline

    InstanceofDeath

    well injecting needs 12 lines. and yes I went a step with saying nms classes are not that hard
     
Thread Status:
Not open for further replies.

Share This Page