Solved A few questions

Discussion in 'Plugin Development' started by rob1998@, Jun 20, 2013.

Thread Status:
Not open for further replies.
  1. Hi,

    I'm working on a few plugins and I have a few questions

    1. How can I get the Playername with the prefix (assigned with essentials chat) for broadcasting?
    2. How can I make a new file (data.yml) and write/read from it?
    3. How can I convert a string to a md5 string?
    4. How can I repeat a task*?
    5. How to give someone 2 healing potions?
    6. Look here


    Please help me

    task* = Pay a player
     
  2. Offline

    caseif

    1. Player.getDisplayName()
    2. Get an instance of a File, create a new YamlConfiguration, load the File into the YamlConfiguration with YamlConfiguration.load(File), then modify it and save it in the same way.
    3. Haven't done that before, but a Google search should turn up the answer.
    4. Actually, these could all probably be solved with Google searches. Try searching for "bukkit repeating task."
    5. Come on, really? Google is your friend.
    6. Check out the GroupManager JavaDocs (I'd link to them, but you seem to need practice with Google searches).
     
  3. Offline

    chasechocolate

    1. player.getDisplayName();

    2.
    Code:java
    1. File dataFile = new File(this.getDataFolder(), "data.yml");
    2. FileConfiguration dataConfig = null;
    3.  
    4. //In onEnable():
    5. if(!(dataFile.exists())){
    6. dataFile.createNewFile(); //Surround with try and catch
    7. }
    8.  
    9. //Still in onEnable():
    10. dataConfig = YamlConfiguration.loadConfiguration(dataFile);


    4.
    Code:java
    1. new BukkitRunnable(){
    2. @Override
    3. public void run(){
    4. //Pay player
    5. }
    6. }.runTaskTimer(<plugin instance>, <initial delay>, <delay>); //Delays are in ticks, which can be found by multiplying seconds by 20


    5.
    Code:java
    1. ItemStack healing = new Potion(PotionType.INSTANT_HEAL, <level>).toItemStack(2);
    2.  
    3. player.getInventory().addItem(healing);


    6. I think this can be achieved by using Vault.
     
  4. Offline

    ProtoTempus

    2. From here (There are a couple options)
    Code:java
    1. public String MD5(String md5) {
    2. try {
    3. java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
    4. byte[] array = md.digest(md5.getBytes());
    5. for (int i = 0; i < array.length; ++i) {
    6. sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
    7. }
    8. return sb.toString();
    9. } catch (java.security.NoSuchAlgorithmException e) {
    10. }
    11. return null;
    12. }[/i]

    Give that a try?
    Plop it in your class and:
    Code:java
    1. String toBeMd5 = "test";
    2. String outputMd5 = MD5(toBeMd5);
     
  5. thanks that worked!

    So to add something to the data.yml file I can use something like this: dataConfig.set("rules", "there are no rules!"); ?
    If that's right question 1,2,3,4 and 5 are solved...
    But I already googled for 6 but I don't understand the given examples...

    How can I save the data.yml file?
    because every time I reload the server it clears data.yml

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  6. Offline

    wizzinangel

    rob1998@
    Code:java
    1.  
    2. dataConfig.save(dataFile);
    3.  


    this will save your file
     
  7. I solved question 6, I forgot the return true; statement...
     
Thread Status:
Not open for further replies.

Share This Page