Problem with PlayerInteractEvent

Discussion in 'Plugin Development' started by Kicksy, Jun 25, 2018.

Thread Status:
Not open for further replies.
  1. I can move all items why?
    I also use other listeners like InventoryClickEvent or PlayerJoinEvent they work as they should. But InventoryInteractEvent and InventoryDragEvent do not work.
    I use the 1.12.2 Spigot version.
    InventoryInteractEvent (open)

    Code:
    package me.Kicksy.Auwahl;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    public class Listeners  implements Listener {
        private main plugin;
    
    
        public Listeners(main main) {
            this.plugin = main;
        }
    
        @EventHandler
        public void onInteraact(InventoryInteractEvent e) {
            e.setCancelled(true);
    
        }
    
    }
    


    onEnable (open)

    Code:
    @Override
        public void onEnable() {
    
            gruppen = new Gruppen(this);
            buch = new Buch(this);
            if(!buch.customFile.exists()) {
                 try {
                    buch.customFile.createNewFile();
                } catch (Exception e) {    
                }
             }
            if(!gruppen.gruppenFile.exists()) {
                 try {
                    gruppen.gruppenFile.createNewFile();
                } catch (Exception e) {
                }
             }
        
             for(int i =0; i < pex.getPermissionsManager().getGroupNames().size(); i++) {
                     if(gruppen.gruppenConfig.get("Gruppen." + pex.getPermissionsManager().getGroupNames().toArray()[i]) == null) {
            
                         gruppen.gruppenConfig.set("Gruppen." + pex.getPermissionsManager().getGroupNames().toArray()[i] + ".visible", "true");
                        // gruppen.gruppenConfig.set("Gruppen." + pex.getPermissionsManager().getGroupNames().toArray()[i] + ".name", i);
                         gruppen.gruppenConfig.set("Gruppen." + pex.getPermissionsManager().getGroupNames().toArray()[i] + ".item", "1");
                         gruppen.gruppenConfig.set("Gruppen." + pex.getPermissionsManager().getGroupNames().toArray()[i] + ".slot", "0");
                     }
                     gruppen.saveCustomYml(gruppen.gruppenConfig, gruppen.gruppenFile);
                 }
         
            Bukkit.broadcastMessage(prefix  + "Das Plugin wurde geladen.");
             Bukkit.getPluginManager().registerEvents(new Auswahl(this), this); 
             Bukkit.getPluginManager().registerEvents(new Listeners(this), this); 
             registerCommands();
         
        
            
        }
     
    Last edited: Jun 25, 2018
  2. Offline

    Zombie_Striker

    @Kicksy
    PlayerInteractEvent is called when a player left or right clicks anywhere in the world. To get when a player clicks an inventory, use InventoryClickEvent.
     
  3. @Zombie_Striker
    Ohh, I mean InventoryInteractEvent.

    I have the problem that when I shift click a book into a custom inventory, a new inventory opens which should only happen if that item is in that custom inventory.

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

    CommonSenze

    @Kicksy
    On your InventoryClickEvent or InteractEvent they should have a way to tell what part of the inventory the player is clicking. Either the top or the bottom. Now I never used 1.12 because I'm a old 2013 soup pvper so I stay in the 1.7.10 to 1.8.8 category. However, you should have a way to do this in either ClickEvent or InteractEvent:
    Code:java
    1. if (e.getWhoClicked().getInventory() == e.getClickedInventory());

    It should most definitely be in Click Event because that's what I use but, again, I'm on 1.8.8 spigot so I wouldn't know if they changed it.
     
  5. Offline

    Zombie_Striker

    @CommonSenze
    You should click the link below. Even if you like pre-1.9-PVP, there should be no reason to stay on outdated versions.

    LINK

    @Kicksy
    You can do what CommonSenze posted only if you are using Spigot, as bukkit by itself does not have the getClickedInventory method. On the off chance you still use the craftbukkit server version, you can check if the inventory is not the player's inventory.
     
  6. Offline

    CommonSenze

    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page