Minecraft Java Plugin: I can take one item from my inventory (inv) and not the other one. How does it work?

Th
- in Plugins
6

So I want to make an inventory that opens with / elite. It should have 2 items in it. As a "Non Op" player you can only take Item1. And as an operator you can take both items. My problem is that I'm not lying down. Would be great if you take the time and you look at it and help me.

Mfg Colin

I work with Java 8,

Minecraft Bukkit 1.12.2,

on

Windows 10 (64bit).

package cmd;
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.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta;

public class cmdsget implements CommandExecutor, Listener {// INVENTORY CREATED FOR COMMANDEXECUTOR AND LISTENER Inventory inv = Bukkit.createInventory (null, 27, "Elite Chest");

// LISTENER
@EventHandler
public void on (InventoryClickEvents) {

Player t = (Player) e.getWhoClicked ();

// ITEM1 IS CREATED
ItemStack user = new ItemStack (Material.DIRT);
ItemMeta usermeta = user.getItemMeta ();
usermeta.setDisplayName ("§§lUser Terminal");
user.setItemMeta (usermeta);

// ITEM2 IS CREATED
ItemStack admin = new ItemStack (Material.COMMAND);
ItemMeta adminmeta = admin.getItemMeta ();
adminmeta.setDisplayName ("§§ladmin Terminal");
admin.setItemMeta (adminmeta);

// QUESTION WHETHER THE COMMAND BLOCK IS TAKEN
if (e.getCurrentItem (). GetType (). Equals (Material.COMMAND)) {

if (t.hasPermission ("op *") || (t.hasPermission ("Default" {// QUERY ON PLAYER RIGHTS
// THE PLAYER HAS THE RIGHT (OP)
e.setCancelled (false); } else {// THE PLAYER DOES NOT HAVE THE RIGHT (NON OP) e.setCancelled (true); t.sendMessage ("§4§The admin terminal is not accessible to users."); }}}

// COMMANDEXECUTOR: ALL LISTENER THINGS SHOULD BE NARROWLY AWAY. THAT SHOULD NOT HAPPEN.

public boolean onCommand (CommandSender sender, Command cmd, String label, String [] args) {
// DETERMINE PLAYER TRANSMITTER
Player p = (player) transmitter;
// SAFETY QUESTION
if (sender instanceof Player) {
// QUESTION WHAT IS BEHIND / ELITE
if (args.length == 0) {
// PLAYERS SHOULD NOW SEE AN INVENTORY WHERE ITEM1 AND ITEM2 ARE IN. // ITEM2 CAN ONLY TAKE ONE OP PLAYER. // DESPITE ITEM1 AND ITEM2 SHOULD BE DISPLAYED. P.openInventory (inv);

// ANSWER TO ARGS LENGTH == 0
} else {
p.sendMessage ("§4Es / elite.");
}

// SENDER INSTANCEOF PLAYER ANSWER WHEN THE TRANSMITTER IS NO PLAYER
} else {
System.out.println ("§4Please enter command in chat!");
}
return false;

Th

Small note:

I do not know why these "& nbsp" are there.

They are not in the plugin!

g colin

Dr

What exactly do you want from us now?

Th

I want yes, but

When I do the ItemStack in CommandExecutor

public boolean onCommand (CommandSender sender, Command cmd, String label, String [] args) {

//The code

} // WITH COMMANDEXECUTOR I MAKE MY PILLARS {}

is ok in the beginning, but if I need the InventoryClickEvent to make it impossible for the player to take it

event.setCancelled (true);

it will be critical again. In order to use the InventoryClickEvent, I actually need the listener. So the stuff that's done in CommandExecutor ({}) (the ItemStacks and the placing of the items) will be unknown and will not appear in the inventory (inv).

Dr

You can also make the ItemStacks at any time…

Or what exactly is the problem?

Th

I can only make the ItemStacks for the CommandExecutor or the Listener. I can't do that for both. If I use the "EventHandler" or "public boolean onCommand (CommandSender sender, Command cmd, String label, String [] args) {" Then everything is red marked.

Dr

I can show you how to do that. Do you have discord or something similar?