Solved How do i make a chest do something on open?

Discussion in 'Plugin Development' started by Chintzi, Nov 16, 2014.

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

    shohouku

    Code:java
    1. Chest YourChest = (Chest)event.getInventory().getHolder();


    Code:java
    1. try
    2. {
    3. Field inventoryField = YourChest.getClass().getDeclaredField("chest");
    4. inventoryField.setAccessible(true);
    5. TileEntityChest chest = ((TileEntityChest) inventoryField.get(YourChest.getBlock().getState()));
    6. chest.a("Your name");
    7. }
    8. catch (Exception e)
    9. {
    10. e.printStackTrace();
    11. }


    Code:java
    1. if(YourChest.getBlockInventory().getTitle().equalsIgnoreCase("Your name")) {
    2. }
     
  2. Offline

    Chintzi

    Didnt work D:
     
  3. Offline

    shohouku


    I re-edited my code.
     
  4. Offline

    Chintzi

    G2g cya tomorrow. Thanks everyone for all your help at least we got the code to make the chest do something now :D

    Code:java
    1. if (event.getClickedBlock() != null) {
    2. if (event.getClickedBlock().getType() == Material.CHEST) {
    3. player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1.0F, 2.0F);
    4. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999, 1));
    5. }
    6. }


    Once again thank you :D [cake]
     
Thread Status:
Not open for further replies.

Share This Page