a few quick questions

Discussion in 'Plugin Development' started by 1337, Feb 5, 2011.

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

    1337

    i have a few questions.
    if i had one boolean. and each player could have eather true or false and one is true and one is false would they overwrite each other or does each player have there own boolean? or would i have to make loads of booleans?
    how would i make the chat color go the color of a string?
    so if i had a string called chatcolor and it was = to RED would doing this work?
    ChatColor.chatcolor + "my message"
    Thanks for your help
     
  2. Offline

    fullwall

    About the chatcolor - yes, ChatColor.RED + "message" would give a red message. You might have to be more clear about the first issue... Have you thought of using a HashMap of Player-Boolean?
     
  3. Offline

    Plague

    I also use this method, but it puts formatting characters into the console of the server. Or I am doing something wrong ;)

    Also, fullwall is right, the HashMap is the clear way to do this. One boolean would get overwritten and many booleans are of fixed count.
     
  4. Offline

    fullwall

    I think that's a bug XD. There was an update that was supposed to clear formatting characters from the console because it doesn't support colour (yet).
     
  5. Offline

    1337

    sory i wasnt very clear on any of them i ment that i wanted the chatcolor to be equal to the string so for example
    String test = RED;
    Chatcolor.test + "my message"
    ok ill use hashmaps thanks
     
  6. Offline

    Plague

    String test = ChatColor.RED;
    test + "whatever"
     
  7. Offline

    1337

    thanks :) also how would i do this?
    /mob mobname
    how would i be able to tell what mob they named?
     
  8. Offline

    Plague

    I don't know how to spawn them, but there's a few plugins floating around I think.
    I don't think there is a function to get you the mob entity from name, but you could just go though all MobType (that's a string enum, see javadocs) with a for loop and just check it on string equality. Dirty, I know, but should work.
     
  9. Offline

    1337

    i dont want to spawn them but i want to save the mob the named as a string for use later
     
  10. Offline

    Plague

    ? You want to know how to assign a string to a variable or something? The sample plugin uses commands I think so you got everything already there, just store it.
     
  11. Offline

    1337

    thanks how would i do something like this:
    Code:
    public static void read(){
    try {
    BufferedReader br = new BufferedReader(new FileReader("mclsplayer.txt"));
    String curLine;
    
    while ((curLine = br.readLine()) != null){
    StringTokenizer strTok = new StringTokenizer(curLine, ":");
    if (strTok.nextToken().equals(name)){
    String Level = strTok.nextToken();
    level = Integer.parseInt(Level);
    String Nextlvl = strTok.nextToken();
    nextlvl = Integer.parseInt(Nextlvl);
    String Prestige = strTok.nextToken();
    prestige = Integer.parseInt(Prestige);
    // Here you can do whatever you want with the rest of the tokens. Just use strTok.nextToken() to get the rest of the token, split by colons.
    }
    }
    // This catches all the exceptions. You can go more in detail here if you want.
    } catch(Exception e){
    e.printStackTrace();
    System.out.println("error reading the mclsplayer.txt file. does it exist?");}
    }
    public void write(){
    how would i overwrite just the level int for that one player?
    
    }
     
  12. Offline

    retsrif

    To get the mob name, use onPlayerCommand in player listener:

    Code:
    String mobName;
    
    public void onPlayerCommand(PlayerChatEvent event) {
       String[] split = event.getMessage().split(" ");
       if((split[0].equalsIgnoreCase("/mob"))) {
          mobName = split[1];
       }
    }
    
    Though this should work for storing it in a string, it would only be able to hold one mobname at a time, but this is basically it.
     
  13. Offline

    1337

    That worked thanks but how would i do the writing thing i asked earlyer?
     
  14. Offline

    retsrif

    what are you trying to do with the code you asked about earlier?
     
  15. Offline

    1337

    each player has a line in a txt file like this:
    1337:10:500:1
    the first one is player name the next one is there level the one after is the points to the next level and the last one is like there prestige i would like to just change 1337's or anothers player level but not by making a new line for them, i just want tochange his level to his new one how would i do this?
    --- merged: Feb 10, 2011 7:44 PM ---
    bump
     
  16. Offline

    retsrif

    Not sure, I'm a java noob, though i probably would transfer the contents to an array list then transfer them back.
     
  17. Offline

    1337

    i might try that but does anyone know how to do it how i asked?
     
  18. Offline

    Plague

    You mean you want to edit the file and replace player level with his new level?
     
  19. Offline

    Valrix

    Each player is handled individually by the plugin unless you have a HashMap keeping a list.
     
  20. Offline

    1337

    yes
     
  21. Offline

    Plague

    Since you have no fixed width there, it will not be nice solution :)
    For example in my warp plugin I just remove the old line and then append the new one. You can use the same technique, the problem is that removing is done by creating a new, temporary, file. Then copying everything except the one line to change and then adding the new one.
     
  22. Offline

    1337

    i have just looked at how you did it but is there an easyer way to do it?
     
  23. Offline

    Plague

    Well I'm not saying there is not, but I didn't think of any easier way when i coded my plugin, so if you find out, PM me :)
     
Thread Status:
Not open for further replies.

Share This Page