#ChatScanner class | get an input from the chat (Like Java's Scanner class)

1 messages · Page 1 of 1 (latest)

narrow portal
#

That is the minecraft version of the java's Scanner class.

REQUIRES A BETA VERSION OF SERVER MODULE.

It gets what the players write in chat waiting for the result to be something before continuing.

Changelog v1.0

  • created ChatInput class
  • created nextLine() for strings
  • created nextFloat() for numbers
  • created nextBool() for booleans
  • created close() to close the input stream

Usage Example:

// creating the input scanner for player
const input = new ChatInput(player);

// use async to wait for the result to continue
(async () => {

    //getting the values 

    player.sendMessage("<question> Type something:")
    const string = await input.nextLine();

    player.sendMessage("<question> Type a number:")
    const float = await input.nextFloat();

    player.sendMessage("<question> Type yes or no:")
    const bool = await input.nextBool()

    //closing the input

    input.close()

    // sending the result 

    player.sendMessage("<result data> RESULT:")
    player.sendMessage("<result data> text: " + string)
    player.sendMessage("<result data> number: " + float)
    player.sendMessage("<result data> bool: " + bool)
})();
narrow portal
#

Update 1.1
That is the minecraft version of the java's Scanner class.

REQUIRES A BETA VERSION OF SERVER MODULE.

It gets what the players write in chat waiting for the result to be something before continuing.

Changelog v1.1

  • changed name to ChatScanner.
  • created listen() to listen again if closed.
  • changed nextLine() to next() to use an unique method.
  • removed nextFloat() .
  • removed nextBool() .
    Usage Example:
// creating a new ChatScanner instance
const input = new ChatScanner(player)

// async arrow function, needs await
(async () =>{
    
    //asking the player his name
    player.sendMessage("type your name.")
    const name = await input.next()
    input.close()

    //asking the player his surname
    player.sendMessage("type your surname.")
    input.listen()
    const surname = await input.next()
    input.close

    //sending the result
    player.sendMessage("name: " + name +  ", surname: " + surname)

})()