LWC - Check if item is inside a chest

Discussion in 'Plugin Development' started by EnZiGuRi, Aug 2, 2017.

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

    EnZiGuRi

    Hello,

    Im working on a plugin that limits the storing of ShulkerBoxes. Iam having trouble checking if Shulkerboxes are inside a chest before make it private with LWC plugin. Its my first time integrating a plugin with another one, so its a mess to me making that "if" between another plugin actions.

    This is a example how i find if chest is locked and block item storing inside it.

    Code:
    LWC lwc = com.griefcraft.lwc.LWC.getInstance();
    Protection isProtected;
    isProtected = lwc.findProtection(chest);
    So, what i want is: The player type "/cprivate" (or other lock commands). When he click on the chest to lock it, it will check if a specific item is inside. If it is, my plugin blocks the action that inserts the chest on database.

    Thank you.
     
    Last edited: Aug 7, 2017
  2. Offline

    EnZiGuRi

    Do someone knows if it is possible?
     
  3. Offline

    PenguinOwl

    I really don't know if this is possible, but another alternative is to write a plugin that blocks the storing of shulker boxes altogether.
     
  4. Offline

    EnZiGuRi

    Thanks for the reply, i want it to allow to be stored on regular chests, but not enderchest and LWC protected chests...

    Atm iam already blocking enderchests and lwc protected ones.. but players can store them before doing /lock with lwc. it is safe to "record" all lwc commands on my plugin? It makes no sense on my head..
     
  5. Offline

    PenguinOwl

    When a player runs a command, it sets off all onCommand methods from all plugins, including LWC. I would just use a check that prevents you from placing signs on chest with shulkerboxes and vice versa
     
  6. Online

    timtower Administrator Administrator Moderator

    @PenguinOwl It only sets off the onCommand where the command is registered. Not all onCommands.
     
  7. Offline

    EnZiGuRi

  8. Offline

    PenguinOwl

    Correct me if I'm wrong, be if a player runs a command and the plugin has an onCommand in their main class, it doesn't need to be registered and will run regardless of the command, thus the compareIgnoreCase

    EDIT: nvm, was thinking about event, not plugin.yml
     
  9. Offline

    EntityID

    Code:
            Block b = (...);
            if (((Chest) b.getState()).getBlockInventory().contains(Material.DIAMOND)) {
               //...
            }
    I think this will check if a block contains a specified ItemStack or Material. Just make sure the block is a chest first.
     
  10. Offline

    PenguinOwl

    Just going to point out, you are making an unsafe cast. Here's a better way to do it:
    Code:
            Block b = (...);
            if (b.getType == Material.CHEST) {
            if (((Chest) b.getState()).getBlockInventory().contains(Material.DIAMOND)) {
               //...
            }
            }
     
Thread Status:
Not open for further replies.

Share This Page