Getting the item in hand from a list

Status
This thread has been locked.

M4T14SG4M3R

PapuHost Game Hosting CEO
Premium
Feedback score
0
Posts
278
Reactions
77
Resources
0
I started to change from Skript to Java to increase my server performance so i basically want to check if the player has a certain item from a list, for example if the player has a stone, a diamond block or a glass block in the hand but i don't know how to do it
Code
Code:
if (player.getPlayer().getItemInHand().getType().equals(Material.WOOD)){
Actions goes here
}
 
Last edited:
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

M4T14SG4M3R

PapuHost Game Hosting CEO
Premium
Feedback score
0
Posts
278
Reactions
77
Resources
0
This is pretty basic, maybe you should learn more Java before you start working on plugins. Also why are you using
Code:
player.getPlayer()
?
Code:
final Player player = event.getPlayer();
 

M4T14SG4M3R

PapuHost Game Hosting CEO
Premium
Feedback score
0
Posts
278
Reactions
77
Resources
0
Code:
event.getPlayer().getPlayer()
???

Also are you sure you didn't use a decompiler?
As i said i'm new and i'm just trying to do the thing i said in the thread by using bukkit code examples
upload_2017-11-5_17-56-12.png

upload_2017-11-5_17-57-17.png

I searched on bukkit forums and google, and please if you will not help me don't reply to the thread. Thanks.
 

Attachments

  • upload_2017-11-5_17-56-12.png
    upload_2017-11-5_17-56-12.png
    35.4 KB · Views: 77
  • upload_2017-11-5_17-57-17.png
    upload_2017-11-5_17-57-17.png
    133 KB · Views: 80

Kuzni

If you signed up after 2016 don't diss me thx
Supreme
Feedback score
12
Posts
1,688
Reactions
950
Resources
0
Code:
final Player player = event.getPlayer();
Code:
event.getPlayer().getPlayer()
???

Also are you sure you didn't use a decompiler?

I'll explain it a tad softer, He's asking why you are getting player twice.

You've assigned it so when you type "player", eclipse or whatever will recognise it as event.getPlayer()

now you've written code thats "player.getPlayer();

So essentially, you're doing event.getPlayer().getPlayer();
 

M4T14SG4M3R

PapuHost Game Hosting CEO
Premium
Feedback score
0
Posts
278
Reactions
77
Resources
0
I'll explain it a tad softer, He's asking why you are getting player twice.

You've assigned it so when you type "player", eclipse or whatever will recognise it as event.getPlayer()

now you've written code thats "player.getPlayer();

So essentially, you're doing event.getPlayer().getPlayer();
Fixed that, please if you know how to do that tell me an example
 

M4T14SG4M3R

PapuHost Game Hosting CEO
Premium
Feedback score
0
Posts
278
Reactions
77
Resources
0
This.


I can spoon feed you right now but that doesn't help you in the future. I really recommend learning some Java. Also maybe show us all the code?
I think showing all the code will help nothing to do a basic thing as you say to get the item from a list
 

Spoch

Developer & Game seller
Supreme
Feedback score
13
Posts
269
Reactions
112
Resources
0
Something along the lines of:
Code:
//(Your player object)
Player player = yourplayer

//Create a list and add the Material value STONE
List<Material> list  = new ArrayList<Material>();
list.add(Material.STONE);

//Check if the list contains the type (Material) of players itemInHand
if (list.contains(player.getItemInHand().getType())) {
    //Do your stuff here
}

Like others have stated above you don't need to append the extra getPlayer() as you already have the Player object, there is also no getPlayer() method in the Player interface.
 
Last edited:

M4T14SG4M3R

PapuHost Game Hosting CEO
Premium
Feedback score
0
Posts
278
Reactions
77
Resources
0
Something along the lines of:
Code:
//(Your player object)
Player player = yourplayer

//Create a list and add the Material value STONE
List<Material> list  = new ArrayList<Material>();
list.add(Material.STONE);

//Check if the list contains the type (Material) of players itemInHand
if (list.contains(player.getItemInHand().getType())) {
    //Do your stuff here
}
Thanks so much!
 
Status
This thread has been locked.
Top