I'm pretty new to Java (and first question I ask on Stackoverflow, too) and right now I'm struggling about how to pass some variables values defined in a method to another.
I've done multiple searchs about things like global variables, ArrayList, HashMap, etc, but the only thing that seems to be what I'm searching ( Global variables in Java) let me a little more confused about how to proceed.
I've try to use ArrayList for that, but it haven't work - and I don't know if I can use it for what I want to day anyways...
Here's my code:
public static void creationGuilde(String[] args, Player player, String playerName)
{
String nomGuilde = args[2];
String message1 = "Votre nouvelle guilde se nommera " + nomGuilde + ".";
TextComponent confirmer = new TextComponent("Cliquez ici pour confirmer");
TextComponent annuler = new TextComponent("cliquez ici pour annuler");
String message2 = confirmer + "OU" + annuler + ".";
player.sendMessage(message1);
player.sendMessage(message2);
confirmer.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/creationGuildeConfirmer"));
annuler.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/creationGuildeAnnuler"));
}
private void onPreCreationGuildeCommand(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().equals("creationGuildeConfirmer"))
{
String guilde = CommandeGuilde.creationGuilde(nomGuilde);
event.getPlayer().sendMessage("Félicitations! Vous venez de créer la guilde " +guilde); // <-- Here, trying to get the value of 'guilde' in the 'creationGuilde' method...
}
}
What I want to do is from the "onPreCreationGuildeCommand" method, I want to get the 'nomGuilde' value from the "creationGuilde" method to put it on my last sendMessage.
I hope that my question is clear enough. Thanks for helping me on this.