Get player eye trace

Discussion in 'Plugin Development' started by Clavus, Jan 10, 2013.

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

    Clavus

    I want to double check whether a player can actually hit the block that gets passed in a PlayerInteractEvent. Sometimes the players on my server use the lag between breaking a block and the server cancelling the block break event, to interact with blocks behind the one they broke (in this case, to circumvent Factions protection). By double checking if there are no solid blocks between their eye position and the block they hit, I could prevent that from happening.

    Now I just wonder how to do this. It looks like the BlockIterator is a way of performing a raytrace, but what would be an accurate way to determine if a player can actually hit something using that?
     
  2. Offline

    stirante

    Try getTargetBlock on Player. If it's not the same block as it is in PlayerInteractEvent then cancel event.
     
  3. Offline

    Clavus

    That looks pretty good. There's one thing: I'm trying to avoid false positives at all costs; I don't want the event to be cancelled if the player is clearly able to hit a block from his point of view. getTargetBlock seems to take a set of transparent blocks as argument? Would it mean that if I leave that null, things like signs and ladders would block the trace? That'd be bad since you can clearly hit the blocks around them.

    EDIT: seems they do. So I guess I could build a set of transparent blocks by looping through the materials and adding everything that isn't solid.
     
  4. Offline

    fireblast709

    leaving it null should only ignore AIR blocks
     
  5. Offline

    netherfoam

    https://github.com/netherfoam/Chest...src/com/gmail/igotburnt/ChestFix/Checker.java

    I did the same thing you're trying to do. The result is here: dev.bukkit.org/server-mods/ChestFix/ if you want it, less you want to write it yourself. its by default just for chests and containers, but you can protect any block you want with it.

    Some other guy tried to do this but had a lot of flaws in it :/ There's sometimes an issue with say Iron Bars and Glass Panes where collision boxes are weird in my version though.
     
Thread Status:
Not open for further replies.

Share This Page