Development Assistance How can I delay PlayerInteractEvent?

Discussion in 'Plugin Help/Development/Requests' started by AdvanceNoob, Oct 19, 2015.

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

    AdvanceNoob

    Hey everyone,

    I am currently building a lock picking plugin for 1.7.10 right now on my Tekkit server and I want to incorporate mods into it. I'm not entirely sure how to add the modded chests and doors so I figured maybe I could just delay the PlayerInteractEvent for a few seconds and if the player successfully pick locks then pass e.setCancelled(false); else, e.setCancelled(true);

    Code:
    new BukkitRunnable() {
         
        @Override
        public void run() {
            if(pickLock(player)){
                e.setCancelled(false);
                player.playSound(modLoc, Sound.SUCCESSFUL_HIT, 1, 1);
                player.sendMessage(ChatColor.DARK_PURPLE + "[FactionPickLock]: " + ChatColor.GOLD + ChatColor.BOLD + "Ahh haa!");
                picklocking = false;
                pickers.remove(player.getName());
            }else{
                e.setCancelled(true);
                player.getInventory().removeItem(pick);
                player.updateInventory();
                player.sendMessage(ChatColor.DARK_PURPLE + "[FactionPickLock]: " + ChatColor.RED + ChatColor.ITALIC + "Pick broke..");
                player.playSound(modLoc, Sound.ITEM_BREAK, 1, 1);
                picklocking = false;
                pickers.remove(player.getName());
            }
        }
    }.runTaskLater(FactionPickLock.plugin, time);
    
    as show on line 7 or 13, but of course I have two problems.. One of which the player has already interacted with the object so the chest/door would already open and two, lines 13 and 7 the events are non-local so I cant declare them.

    Any ideas?
     
  2. Offline

    pie_flavor

    @AdvanceNoob The event problems are simple, just make it final in the method argument.
     
  3. Offline

    AdvanceNoob

    True but when added to the timer it still opens the chest/door.
     
  4. Offline

    MisterErwin

    @AdvanceNoob Afaik you can't cancel events afterwards.

    Try to cancel the event. And after a period time (via your scheduler) use Player#openInventory with the BlockInventory of the chest.

    You archive the chest inventory by Block#getState().
    The "vanilla" chest "state" is a class named "Chest" and implements ContainerBlock and InventoryHolder.
    Both have the method getInventory().

    I'm not sure if mods implement these, but give it a shot ;)
     
  5. Offline

    AdvanceNoob


    That's how the plugin opens vanilla chests and doors using states and inventory. Sadly it doesn't work for the mods and I have no idea how to get that to work or even the path I should take to learn more about.
     
  6. Offline

    MisterErwin

    @AdvanceNoob Well, I guessed that forge would use some vanilla interfaces (like the ContainerBlock one).
    The other way this could be possible would be by using forges events. But then you would have to make a (server) mod ;)
     
  7. Offline

    AdvanceNoob

    Yeah I would prefer not having to make it a mod.
     
  8. Offline

    pie_flavor

    @AdvanceNoob Cancel the event, then call another one later?
     
  9. Offline

    AdvanceNoob

    How would I call a event to interact with a specific block or object as if the player was right clicking it?
     
  10. Offline

    Scorpionvssub

    @AdvanceNoob via a Action.getrightclick something like that then check if the right clicked block its state is a chest, when done correctly do e.setcancelled(true); then run a timer that opens either the chest or a gui interface

    but thats using java way i.r. plugins not really mods, mods i believe arent supported here anyway
     
  11. Offline

    AdvanceNoob

    Yeah I got the vanilla portion working already its just getting the plugin to work with the mods.
     
  12. Offline

    pie_flavor

    @Scorpionvssub i cannot help but notice that you read virtually none of the posts
    @AdvanceNoob Events have constructors. Make one, that acts like the event that already happened, then run it via the PluginManager.
     
Thread Status:
Not open for further replies.

Share This Page