Materials in Configs

Status
This thread has been locked.

Hoppys

Supreme
Feedback score
0
Posts
725
Reactions
250
Resources
0
Hello, i'm interested in knowing how to make it so i can edit an item that will spawn once they right click a Piston via config. this is what i have as a rough idea.. as you'll see is, i have the "items" which they will be able to list as many items as they can with an amount that they put in the config.

Code:
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_AIR)) return;
       
        if (!(e.getItem().getType() == Material.PISTON_BASE)) return;
       
        Inventory inv = p.getInventory();
       
        p.sendMessage(prefix + ChatColor.GOLD + "You have recieved your rewards");
        Material material = Material.getMaterial(getConfig().getString("items"));
        inv.addItem(new ItemStack(Material..getConfig().getString("items")));
       
        inv.removeItem(new ItemStack(Material.PISTON_BASE, 1));
       

}
}
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Kek123

Feedback score
1
Posts
61
Reactions
34
Resources
0
You will need to convert the String to a Material

Code:
String materialString = getConfig().getString("Path");


Material material = Material.valueOf(materialString);

ItemStack item = new ItemStack(material, 1);

Add the necessary checks to make sure the String is actually a Material in case you make a mistake in the config, and voila!
 

Hoppys

Supreme
Feedback score
0
Posts
725
Reactions
250
Resources
0
You will need to convert the String to a Material

Code:
String materialString = getConfig().getString("Path");


Material material = Material.valueOf(materialString);

ItemStack item = new ItemStack(material, 1);

Add the necessary checks to make sure the String is actually a Material in case you make a mistake in the config, and voila!
Thanks! :D
 
Status
This thread has been locked.
Top