Help Please

Discussion in 'Plugin Development' started by ByNyntex, Jul 20, 2021 at 3:20 AM.

  1. Offline


    Hi I have made an info plugin for YT ranks and it also works. An inventory opens and the requirements are there, but you can take the items out of the inventory. How can I avoid that? here the code:
    package at.nyntex.NyntaniaSystem.Commands;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import at.nyntex.NyntaniaSystem.main.Main;
    import java.util.ArrayList;
    public class ninfo implements CommandExecutor {
        public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) {
            if(s instanceof Player){
                Player p = (Player)s;
                    Inventory inv = Bukkit.createInventory(null, 9, "§5§lInfo");
                    ItemStack i = new ItemStack(Material.DIAMOND);
                    ItemMeta m = i.getItemMeta();
                    m.setDisplayName("§5YT Rang:");
                    ArrayList<String> lore = new ArrayList<>();
                    lore.add(" ");
                    lore.add("§5YT Rang Vorraussetzung:");
                    lore.add("§b mindestens 150 Aos");
                    lore.add("§b mindestens 2000 Kanalaufrufe");
                  ItemStack itemstack = new ItemStack(Material.GOLD_INGOT);
                  ItemMeta itemmeta = itemstack.getItemMeta();
                  itemmeta.setDisplayName("§eP+ Rang:");
                  ArrayList<String> lore2 = new ArrayList<>();
                  lore2.add(" ");
                  lore2.add("§e P+ Rang Vorraussetzungen");
                  lore2.add("§6 mindestens 50 Abos");
                  lore2.add("§6 mindestens 500 Kanalaufrufe");
                  inv.setItem(0, i);
                  inv.setItem(1, itemstack);
                }else {
                    p.sendMessage(Main.getPrefix() + "§cDazu hast du keine Rechte!");
            }else {
                s.sendMessage(Main.getPrefix() + "§cDu musst ein Spieler sein!");
            return false;
    Last edited by a moderator: Jul 20, 2021 at 4:32 AM
  2. Offline


    You need to make an "InventoryClickEvent" and check if the clicked inventory is your desired inventory and if so cancel the event.

    EDIT: Btw. please don't just name your posts something like "Help please" but rather summarize your issue in the title (e.g. "How to prevent taking items from inventories")
    Last edited: Jul 20, 2021 at 7:53 AM
    Chr0mosom3 and KarimAKL like this.

Share This Page