Storage and Reading In

Discussion in 'Resources' started by hoovergg, Oct 27, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    hoovergg

    A few questions....
    How can you store data so that it doesn't delete when the server shuts down?
    And how can you read in from the keyboard?
    Do you use a regular scanner or what?
     
  2. Offline

    Windwaker

    This is not the place for questions, you're looking for Plugin Development. It will save you some time in the future. :)

    But to save you some trouble...
    There are many ways to store data to disk but perhaps the easiest was is with Java's ObjectInputStream and load with ObjectInputStream. However, storing objects will make anything saved illegible. If you want to make the data available to the user in the file you store it to it might just be best to use bukkit's FileConfiguration. I made a tutorial on this matter for people who are looking to get the basics down.

    Good Luck :)
     
  3. Offline

    oyasunadev

    you mean "ObjectOutputStream and load with ObjectInputStream."
     
  4. Offline

    Windwaker

  5. Offline

    oyasunadev

    How did you create that picture in your signature?
     
  6. Offline

    Windwaker

    xenmod.com
     
    DomovoiButler likes this.
  7. Offline

    hoovergg

    Thanks, that was helpful, but what about reading in from the keyboard?
     
  8. Offline

    oyasunadev

    You mean reading the console input?
     
  9. Offline

    hoovergg

    When a player types in something:
    ie:
    /s georgia 5

    I understand how to read the command /s
    but how can i read in the georgia and the 5
     
  10. Offline

    DomovoiButler

    args[] ...
    onCommand(CommandSender sender, Command cmd, String label, String[] args)
    @sender the one who send the command
    @CMD command passed
    @Label the typed command
    @args the arguments after the command args[0] as the first argument
    /<label> <args...>
     
  11. Offline

    hoovergg

    Okay, but elaborate on the last part.....
     
  12. Offline

    DomovoiButler

    u only need to save the /<command> on your plugin.yml
    example a player typed
    /tp me player2
    then on your onCommand use
    if(label.equalsIgnoreCase("tp")) right?
    then after that do

    if(args.length==2){
    if(args[0].equalsIgnoreCase("me")){
    (Player) sender.teleport((Player) args[1].location)
    }
    }
    that means if the number of strings after the typed command(in here, after /tp) is equals to 2...then the command sender will be teleported to player2 location

    args is the parameters you put after the command.
    on your example...
    args[0] = "georgia";
    args[1] = "5";
     
  13. Offline

    thehutch

    With that method you would get an error because you cannt directll cast a string into a player instead you have to use this:
    Code:
    try {
        getServer().getPlayer(StringNameOfPlayerInHere)
    } catch (Exception ex) {
          cs.sendMessage("Invalid player");
    }
    
     
  14. Offline

    hoovergg

    Okay thats helpful but can you:
    Int num1 = args[1];
     
  15. Offline

    thehutch

    Integer.parseInt(args[1]);
     
  16. Offline

    DomovoiButler

    i thought it was Integer.valueOf(args[1])
    im not trying to make a workable code there...im just giving an example
     
  17. Offline

    thehutch

    Well not to be rude but giving code which wont work at all isnt really helpful :)
     
  18. Offline

    DomovoiButler

    lol...dude...it was just an example...and the question his asking is for only the parameters after the send command...xD...and nothing else
     
Thread Status:
Not open for further replies.

Share This Page