I have programmed a plugin that is supposed to lock someone's inventory slot. But it does not work. How so?
Source Code:
package eu.singlesecurity.inv;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
public class InvSperre extends JavaPlugin {
public void onJoin (PlayerJoinEvents) {
Player p = e.getPlayer ();
if (! (p.hasPermission ("system.invsperre.ignore" {
Inventory pinv = p.getInventory ();
ItemStack lock = new ItemStack (Material.BARRIER);
ItemMeta sperremeta = lock.getItemMeta ();
sperremeta.setDisplayName ("§Athis inventory space is locked, you can buy this inventory space.");
pinv.addItem (lock);
}
}
}
I think you have to spam some events, for example when the player tries to discard the item that you cancel the event if he has no rights.
I had some idea in spigot plugins program
You think so
Forgot @EventHandler…
What exactly is this supposed to bring?
Still does not work!
What does your main class look like?
What exactly do you mean by locking inventory, you just want to prevent the player from picking items from his inventory:
@EventHandler
public void onInventoryClick (InventoryClickEvent e) // Do not know the exact name
{
if (…)
{
e.setcancelled (true);
}
}
Or do you want to replace items? What you do is to put a barrier into the inventory of the player Join the player or probably get an error back when the inventory is full.