Convert Spigot API arguments to floats?

Fl
5

As indicated in the title I have a problem with the Spigot API or Java. I'm still pretty new in the scene and could not find anything. For those who only code Java but do not know the Spigot API: This is for Minecraft. But I will explain it later.

Umzwar I would like to create a command with which my airspeed changes to the specified value when I enter the command "/ speed [value]". I would like to achieve this by means of a method that can be found in the following post:

So, now my problem is that in line 19 a float is expected instead of the string "args". In Minecraft I give a "/ speed 8" for example, the 8 would be a float. That means that the string args is defined as "8" at this moment. I'd like to know how to change the line, or if I need to define a variable, and if so, which one, that will transform that string into a float or something. So that in the end, practically a float I enter in minecraft in this line.

I hope my concern is not confused and understandable. If that does not work as desired, how could I do it? Should I make a switch statement with Cases 1-10 and Default? If so, how exactly would that look like (I 'm not familiar with loops other than If - Else / If - else if - else)? Or maybe a for loop? Also, I would not be sure how that should look like.

Ro

First of all a tip: first learn Java properly before you do something with it…

String str = "12";
float number = Float.parseFloat (str);

So you get a float from a string

String strs [] = {"Text1", "Text2", "Text3"};
String element1 = strs [0];

and so you get elements from a string array

How do you apply that to your problem? Can you find out for yourself… Is not difficult

Fl

Thank you very much! Your answer helped me. I changed it now () and it seems to work. Your tip, to learn Java properly first - of course, is important. Thank you for calling that to me again. How did you learn it? It will take a while until I have Java in school. Html and css, for example, I learned by book and that worked great. Youtube tutorials I do not like so much to be honest, u.A. Since I have not found any Java series that explains all this well. In addition, it is difficult to summarize each element of Java in a tutorial series on Youtube. Therefore - how did you learn it? If with Youtube tutorials, can you recommend me some?

Ro

I learned Java more or less than I used it (learned C ++ before, are very similar in syntax)

I've already learned C ++ as I said before, but now a coworker wants to start a Youtube channel and I think he can explain very well, so let me say hello to you: https://www.youtube.com/...w/featured

if not a book I think not wrong you just have to look for reviews

Of course you have such a tutorial series can only teach you the basics everything else you have to find out more or less yourself (eg via Google) but once you know the basics should not be a problem.

Bu

Html and css, for example, I learned by book and that worked great.

Also to Java there are books. Even as http://openbook.rheinwerk-verlag.de/javainsel/ variant.

I advise against YouTube tutorials.

Fr

Please note, however, what happens if you still give a letter or a mix of numbers and letters. Also, the Flyspeed has a certain range, if you enter too high a number you also get an error.

Give it a try.