Per world multipliers

Discussion in 'Spigot Plugin Development' started by Vidsify, May 22, 2015.

  1. Hey Guys,

    I had a suggestion to add a feature to my plugin where server owners can chose what world and how much of a multiplier players would get depending on what world they were in on that server.

    At the minute the multiplier section looks like this:
    Code (Text):
    Multiplier: 2.0
    EnablePermMultiplier: false
    DaysToEnable:
    - Monday
    - tuesday
    - wed
    - thursday
    - frida
    - sat
    - SundAy
    So instead of it looking like that it would look like:
    Code (Text):
    Multiplier: 2.0
    EnablePermMultiplier: false
    EnablePerWorldMultiplier: <true/false>
    WorldsToEnable:
    - World1
    Multiplier: 4.0
    - World2
    Multiplier: 2.5
    DaysToEnable:
    - Monday
    - tuesday
    - wed
    - thursday
    - frida
    - sat
    - SundAy
    So this to work the PermMultipier would have to be disabled and the Multiplier.

    I ask how to do this as I have never dealt with Per World things before and was wondering how to do it.

    GitHub: https://github.com/Vidsify/DoubleYourExperience

    Thanks in advance and I hope I made sense :)
     
  2. Create a string list in your config.yml with corresponding sections
    Code (Text):

    enabledWorlds:
      - world
      - world_nether
      - world_end
    #################
    world:
      multiplier: 1.0
    world_nether:
      multiplier: 2.0
    world_end:
      multiplier: 3.0
     
    Get the enabled worlds within your code
    Code (Text):

    List<String> worlds = config.getStringList("enabledWorld");

    for (String worldName : worlds) {
    double multiplier = config.getDouble(wolrdName + ".multiplier");
    }
     
     
  3. @BlahBerrys OK so i've added the strings to my config.yml
    Code (Text):
    EnablePermMultiplier: false
    EnabledWorlds:
    - world
    - world_nether
    - world_the_end
    #################
    world:
      multiplier: 1.0
    world_nether:
      multiplier: 2.0
    world_the_end:
      multiplier: 3.0
    I have created a new permission called WORLD (doubleurexp.world.<name>) in Perms.java. So how would I use that within the PlayerExpLisener class with the code you stated above?
     
  4. Okay so listen to the PlayerExpLisener or whatever that may be - I'm assuming it's a method listening for when a player gets EXP yes?
    So listen to that event, get the world the player is in, if that world's name is in "EnabledWorlds" in your config, get the multiplier for that world, multiply the EXP the player received and update their exp accordingly!
     
  5. @BlahBerrys Yes the PlayerExpLisner is the listening method.

    I'm confused on what this means:
    Code (Text):
    double multiplier = config.getDouble(wolrdName + ".multiplier");
     
  6. It gets a double from the config!
     
  7. Wow how could I be so blind lol