[Tutorial] Fixing Fence Eating Glitch!

Discussion in 'Resources' started by BeefyPlays, Mar 18, 2014.

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

    BeefyPlays

    -=[Intro]=-
    Some people wanted to fix the fence glitch so here is a patch. Now, I don't know if there are other tutorials about this but if there are please do not say I copied. This method was made by me 100%. So there is not need to call me a copier because I came up with this.

    -=[How]=-
    So what we will be doing is when a player right clicks a fence we will check for the item and if it is a fence. Then we will cancel the event. By now you most likely will know how to do it, if not please keep reading and I have how to do it below!

    -=[Tutorial]=-
    First we would want to make the event!

    Code:
    @EventHandler
    public void FenceGlitchFail(PlayerInteractEvent event) {
    Next we would want to get the clicked block, players and checking if the clicked block is nothing
    Code:
    @EventHandler
    public void FenceGlitchFail(PlayerInteractEvent event) {
    if(event.getClickedBlock() == null) return;
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    So far we are almost done! Thank you for reading this tutorial up to this far! Next what we want to do is check if the block is really a fence.


    Code:
    @EventHandler
    public void FenceGlitchFail(PlayerInteractEvent event) {
    if(event.getClickedBlock() == null) return;
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();

    if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if (block.getType() == Material.FENCE) {
    Finally we want to cancel the event.

    Code:
    @EventHandler
    public void FenceGlitchFail(PlayerInteractEvent event) {
    if(event.getClickedBlock() == null) return;
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();

    if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if (block.getType() == Material.FENCE) {
    event.setCancelled(true);
    -=[EXTRA]=-
    Here is something extra I came up with! Use it if you want. Now as you know, No one can place anything on top of a fence. Now, this first thing I came up with was checking if the player has permission. If he does, the event will not cancel.

    Method 1
    Code:
    @EventHandler
    public void FenceGlitchFail(PlayerInteractEvent event) {
    if(event.getClickedBlock() == null) return;
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();

    if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if (block.getType() == Material.FENCE) {
    event.setCancelled(true);

    } else if(player.hasPermission("fence.use")) {
    event.setCancelled(false);
    Method 2
    The second method I came up with was to cancel the event for only certain items.
    Code:
    @EventHandler
    public void FenceGlitchFail(PlayerInteractEvent event) {
    if(event.getClickedBlock() == null) return;
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    ItemStack item = event.getItem();

    if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if (block.getType() == Material.FENCE) {
    if(item.getType() == Material.DIAMOND_SWORD) {
    event.setCancelled(true);
    Method 2 Extra
    If you would like to do this will more than one item but the same event please do this.
    Code:
    @EventHandler
    public void FenceGlitchFail(PlayerInteractEvent event) {
    if(event.getClickedBlock() == null) return;
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    ItemStack item = event.getItem();

    if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if (block.getType() == Material.FENCE) {
    if(item.getType() == Material.DIAMOND_SWORD) {
    event.setCancelled(true);

    } else if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if (block.getType() == Material.FENCE) {
    if(item.getType() == Material.BOW) {
    event.setCancelled(true);
    -=[END]=-
    Thank you for reading this! If you see any errors please tell me and I will fix it. I just wanted to help some people out who had this problem!

    Want help with a plugin? Contact:
    ItsBeefyPlays

     
  2. Offline

    Jombi

    Do you know what code tags are?
     
    Goblom likes this.
  3. Offline

    97WaterPolo

    What is this glitch? :confused:
     
  4. Offline

    RawCode

    why hardcoded constants, especially diamondsword?
     
  5. Offline

    SoThatsIt

    so hard to read :| use code tags and make the font size of the titles bigger, bolded or both.
     
  6. Offline

    TeamJesus

    i smell a copy and paste in action!
     
Thread Status:
Not open for further replies.

Share This Page