Check if a player is looking at another player

Status
This thread has been locked.

Capri

Well-Known Gangster
Supreme
Feedback score
6
Posts
133
Reactions
63
Resources
0
I'm creating a staff plugin, and i'm currently doing the staff items, but checking if the staff member is looking at the player when he clicks the item is holding me up. Any help would be greatly appreciated!
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Capri

Well-Known Gangster
Supreme
Feedback score
6
Posts
133
Reactions
63
Resources
0
Are you talking about if the staff member is physically clicking on them, or looking at them from a distance?

If you are talking about physically clicking on them use a PlayerInteractEntityEvent and check what item they are holding.

Yes I'm talking about physically clicking on them. I will try this and report back. thanks for the advice!
 

SmilyFTW

Feedback score
0
Posts
33
Reactions
11
Resources
0
Code:
    @EventHandler
    public void ItemUseAtPlayer (PlayerInteractEntityEvent e) {
        Player clicked = (Player) e.getRightClicked();
        Player p = e.getPlayer();
        Utils utils = new Utils();
       
        if (Main.getInstance().list.contains(p.getUniqueId().toString()) && p.hasPermission("staffassist.mode")) {
            if (p.getItemInHand().getType().equals(Material.BOOK) && p.getItemInHand().getItemMeta().getDisplayName().contains("Inspector")) {
            Inventory targetinv = Bukkit.createInventory(null, 54, "§a" + clicked.getName() + "'s Info");
           
               ItemStack[] items = clicked.getInventory().getContents();
               ItemStack[] armor = clicked.getInventory().getArmorContents();
               
               utils.reverse(armor);
               for (int i = 0; i < items.length; i++) {
                 targetinv.setItem(i, items[i]);
               }
               for (int i = 0; i <= armor.length - 1; i++)
               {
                 if (i == 3) {
                   targetinv.setItem(39 + i, clicked.getItemInHand());
                 }
                 targetinv.setItem(38 + i, armor[i]);
               }

Here is how I did it in a old project.
 
Last edited:

Killstreak702

Premium
Feedback score
1
Posts
227
Reactions
105
Resources
0
Use PlayerInteractEntityEvent. Fired whenever a player right clicks/interacts with an Entity. Just make sure you're checking if the interacted Entity is an instanceof Player and you should be good
 
Status
This thread has been locked.
Top