Solved Anti EnderChest

Discussion in 'Plugin Development' started by thomasb454, Dec 5, 2013.

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

    thomasb454

    Hello, I'm making a so called "Anti EnderChest" plugin for my server, so I've got the placement and use of an enderchest blocked unless a player has a permission, I'm attmpeintg to do the same, but with crafting - which doesn't seem to work.

    Code:java
    1. public void onInventoryClick(InventoryClickEvent event) {
    2. Player player = ((Player) event).getPlayer();
    3. if ((event.getCurrentItem().getType() == Material.ENDER_CHEST)) {
    4. if(!(player.hasPermission("vp.craft.enderchest"))) {
    5. event.setCancelled(true);
    6. ((Player)event.getWhoClicked()).sendMessage(ChatColor.RED + "You cannot craft an EnderChest");
    7. }
    8. }
    9. }
    10.  

    -note- the mode may be messy wrote the last night when I was quite tired.
    Also, will the above code when fixed stop shift-click crafting as well?
     
  2. Offline

    Wingzzz

    To prevent crafting use CraftItemEvent

    Code:java
    1. public void onCraft(CraftItemEvent event) {
    2. Player player = (Player) event.getWhoClicked();
    3. if(event.getRecipe().getResult().getType() == Material.ENDER_CHEST) {
    4. if(!(player.hasPermission("vp.craft.enderchest"))) {
    5. event.setCancelled(true);
    6. }
    7. }
    8. }

    Written without an IDE- should work unless I got some methods the event contains wrong
     
  3. Offline

    thomasb454


    This didn't work, it allows me to craft an Enderchest just fine.

    -this isn't a bump-

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  4. Offline

    thomas15v

    make sure your aren't OP or have * or vp.craft.enderchest permission.

    Also i would suggest this.
    Code:java
    1. @EventHandler(priority = EventPriority.LOWEST)
    2. void PlayerInteractEvent(PlayerInteractEvent event){
    3. if (event.getAction() == Action.RIGHT_CLICK_BLOCK ){
    4. if (event.getClickedBlock().getType() == Material.ENDER_CHEST){
    5. if(!(event.getPlayer().hasPermission("vp.use.enderchest")))
    6. event.setCancelled(true);
    7. }
    8. }
    9. }
     
  5. Offline

    thomasb454


    I used an alt account with no permissions to test it.
    I already have working code that blocks interaction with an enderchest unless you have permission.
     
  6. Offline

    Aperx

    Add the

    @EventHandler if you haven't already
     
    thomas15v likes this.
  7. Offline

    thomasb454


    Wow, this is what I forgot. I had it on all my other events #noob


    Done that. :D



    Will go test now.

    -Edit-

    Works fine after adding the "@EventHandler" annotation.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page