Is it possible....

Discussion in 'Plugin Development' started by IcyRelic, Jun 19, 2012.

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

    IcyRelic

    my idea is AntiFreecam

    is it possible to check when a player opens a chest and if there is a wall infront of them and the chest cancel the event?
     
  2. Offline

    zachoooo

    Yes it is possible.
     
  3. Offline

    IcyRelic

    how there is no ChestOpen event or anything like that
     
  4. Offline

    zachoooo

    Use the PlayerInteractEvent
     
  5. Offline

    IcyRelic

    ok with that i will do
    Code:
    //stuff to check if they have right clicked
    if (block.getType() == Material.CHEST) {
     
    }
    But how do i find out if there is a wall
     
  6. Offline

    zachoooo

    Get their location using event.getPlayer().getLocation(), then check get the block over at another location and check if its air or not.
     
  7. Offline

    IcyRelic

    But of what locations? what if they are 3 blocks away what about 5?

    I got it to work here is what i did

    Code:
    @EventHandler
        public void ChestOpen(PlayerInteractEvent event){
            Player p = event.getPlayer();
            Action action = event.getAction();
            if (action.equals(Action.RIGHT_CLICK_BLOCK)) {
                if(event.getClickedBlock().getType() == Material.CHEST) {
                    Block b = p.getTargetBlock(null, 200);
                    if(!(b.getType() == Material.CHEST)){
                        p.sendMessage("[" + ChatColor.YELLOW + "AntiFreecam" + ChatColor.WHITE + "] " + ChatColor.RED + "Stop Using Freecam!");
                        event.setCancelled(true);
                    }else{
                        p.sendMessage("No Freecam");
                    }
                   
                }
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  8. Offline

    m1enkrafft_man

    Uh, wouldn't if(event.getClickedBlock().getType() == Material.CHEST) return false, because there's a wall in the way? Just speculating... I haven't tested it.
     
  9. Offline

    desht

    I'm guessing this is to defeat free-cam client side mods which effectively let you look around corners, over walls etc. By validating server-side that the player can really see the chest, you prevent that particular abuse.
     
  10. Offline

    m1enkrafft_man

    I realize that. But if somebody is freecamming, they stop sending movement packets (by saying that they're riding a pig. Kinda funny, all they send are swing arm and look packets), so if they interact with a chest, then the server would believe that they're interacting with the block in front of them, right...? Wait, duh. You can open chests, chests are server sided. Never mind; this works.
     
Thread Status:
Not open for further replies.

Share This Page