public void onClick(ItemClickEvent e) {
String name = e.getClicked().getItemMeta().getDisplayName();
int = -1;
try {
i = Integer.parseInt(name);
} catch (NumberFormatException x) {}
if (i > -1) // do stuff
}
So like this?:Java:public void onClick(ItemClickEvent e) { String name = e.getClicked().getItemMeta().getDisplayName(); int = -1; try { i = Integer.parseInt(name); } catch (NumberFormatException x) {} if (i > -1) // do stuff }
public void onClick(ItemClickEvent e) {
String name = e.getClicked().getItemMeta().getDisplayName();
int = -1;
try {
i = Integer.parseInt(name);
} catch (NumberFormatException x) {}
if (i > -1) // do stuff
p.sendMessage("You have recieved " + x + "!");
}
I'm basically making a tiny note plugin, which gives them the value of the note + removes it from their inv, could you give a small example?I have absolutely no idea what you're trying to do.
The code I gave you will get an integer from the clicked item's name.
What are you trying to tell the player they received? x is the exception that's thrown if there item's name isn't a number... You're not even using it in the correct scope.
You can either use "name" or "i", but why would you need to even get an integer from the name if you're just going to send the player a string?
You might as well keep it as a string, and just send them the item's displayname.
Where would I put this though? Does the "i" variable carry the value?I'm sorry, I still have no idea what you're trying to do.
If you want to remove an item:
inv.remove(item);
The i variable holds an integer value of the item's name.
It's -1 if the item's name is not an integer.
public class WithdrawEvent implements Listener {
Main plugin;
public WithdrawEvent(Main instance) {
this.plugin = instance;
}
@SuppressWarnings("static-access")
@EventHandler
public void onClick(PlayerInteractEvent e) {
if(e.getItem().getType() == Material.GOLD_NUGGET){
if(e.getAction() == Action.RIGHT_CLICK_AIR | e.getAction() == Action.RIGHT_CLICK_BLOCK){
Player p = e.getPlayer();
p.sendMessage(plugin.color("&6awdawd"));
String name = e.getItem().getItemMeta().getDisplayName();
ItemStack item = e.getItem();
int i = -1;
try {
i = Integer.parseInt(name);
} catch (NumberFormatException x) {}
if (i > -1){
plugin.econ.depositPlayer(p, i);
p.sendMessage(plugin.color("&6You have recieved " + i + "!"));
p.getInventory().remove(item);
}
}
}
}
}
public class WithdrawMain implements CommandExecutor{
Main plugin;
public WithdrawMain(Main instance) {
this.plugin = instance;
}
@Override
public boolean onCommand(CommandSender s, Command c, String l, String[] args) {
Player p = (Player) s;
if(c.getName().equalsIgnoreCase("withdraw")){
if(p.hasPermission("fable.admin.withdraw")){
if(args.length == 1){
ItemStack nuggetWithdraw = new ItemStack(Material.GOLD_NUGGET);
nuggetWithdraw.addUnsafeEnchantment(Enchantment.DURABILITY, 5);
ItemMeta nuggetWithdrawMeta = nuggetWithdraw.getItemMeta();
nuggetWithdrawMeta.setDisplayName(plugin.color("&bNugget &f" + args[0]));
nuggetWithdraw.setItemMeta(nuggetWithdrawMeta);
p.getInventory().addItem(nuggetWithdraw);
} else {
p.sendMessage("Incorrect arguments!");
}
} else{
p.sendMessage("No permission!");
}
}
return false;
}
}
