Java is pretty similar to C# actually, so you shouldn't have much trouble
1. To detect user input, you will need to implement the onMessage method in your class that extends Script. Method overriding works the same in Java as it does in C#.
The onMessage method will be called whenever a new message (be it a game message or a player message) appears in your chatbox.
2. To parse the inputted string, you could simply break the message into parts.
Given your example "!58x2", you could first check if the message starts with "!" ( stringMsg.startsWith("!") )
Then you could proceed to split the remainder of the string on the "x" delimiter, and read each value.
To generate a random number, you can use the built in osbot method MethodProvider.random(minValue, maxValue)
3. To let your character write stuff in the chat, you can use the OSBot keyboard API.
example: getKeyboard().typeString("You rolled a " + num);
Note that the getKeyboard method is located in the MethodProvider class, so it may only be used from the Script class, since Script inherits from MethodProvider