[1.11.2] Replace item in PlayerInventory

Discussion in 'Plugin Help/Development/Requests' started by RyFax, Apr 8, 2017.

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

    RyFax

    Hello, sorry for my bad english because im french.
    I have a problem, when I click on the Magma_cream it's doesent worked.
    This is the code:

    Code:
    package Plugins.Minecraft.PluginsManageur;
    
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    
    public class ShowPlayers implements Listener {
    
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onClick(PlayerInteractEvent e) {
            if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_BLOCK){
                if(e.getMaterial() == Material.MAGMA_CREAM){
                    Player p = e.getPlayer();
                    p.getInventory().setItemInHand(new ItemStack(Material.SLIME_BALL, 1));
                    p.updateInventory();
                }else if(e.getMaterial() == Material.SLIME_BALL){
                    Player p = e.getPlayer();
                    p.getInventory().setItemInHand(new ItemStack(Material.MAGMA_CREAM, 1));
                    p.updateInventory();
                }
            }
        }
    }
    
    thanks a lot, bye :D
     
  2. Offline

    yPedx

    @RyFax
    Change your event to;
    Code:
    @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
    That'll help a bit :p
     
  3. Offline

    RyFax

    Thank you :D but some errors at
    Code:
    if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_BLOCK){
                if(e.getMaterial() == Material.MAGMA_CREAM){
     
  4. Offline

    DerpySasuke

    I'm having the same problem but InventoryClickEvent doesn't work. Cuz you're not clicking it after opening your inventory.
     
  5. Offline

    yPedx

    @RyFax
    Wait a second, are you trying to catch when the player interacts with the Item (right clicking or left clicking) when he holds it? I'm sorry if I told you to do the wrong thing here >.<

    Also, could you post the errors?
     
Thread Status:
Not open for further replies.

Share This Page