World config

Discussion in 'Plugin Development' started by ProMCKingz, Nov 14, 2014.

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

    ProMCKingz

    Hey there,
    I wanted to know how I could make a section in the config, where the "world" selected by the user would be the only place in which the plugin would function. I currently have the following, however it does not work:
    Code:java
    1. if(p.getWorld() == JavaPlugin.getPlugin(Main.class).getConfig().get("World"))

    Config.yml
    PHP:
    Worldworld
    I have no errors otherwise.
     
  2. Offline

    Shaggy67

    I usually do this by putting permissions on the plugin, and then use PermissionsEX to manage which world allows that specific permission.

    In your case though, doesn't p.getWorld() return a World class, where getConfig().get("World") returns a String (I'm guessing the name of the world)?

    Would this work:

    if(p.getWorld().getName().equalsIgnoreCase(getConfig.get("World")))
     
  3. Offline

    ProMCKingz

    Shaggy67
    That is what i tried

    Shaggy67
    Do you mean this?
    Code:java
    1. if(p.getWorld().getName().equalsIgnoreCase(JavaPlugin.getPlugin(Main.class).getConfig().get("World").toString()))


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

    Googlelover1234

    ProMCKingz
    I'm pretty sure this has already been answered, but you just go into the config and get the world name, check if it's the same as the players' world, and continue.
     
  5. Offline

    ProMCKingz

    Googlelover1234
    Thanks, but we know that,
    Its jsut the method you use to implement that into the code.
     
  6. Offline

    Gnat008

    ProMCKingz
    I would try to see if the World that the player is in is equal to the World on the server that is in the config:
    Code:
    // EXAMPLE CODE! DO NOT COPY AND PASTE DIRECTLY
    if (p.getWorld().equals(plugin.getServer.getWorld(plugin.getConfig().getString("World")))) {
        // Code here
    }
    Also, why are you using the JavaPlugin method to get your main Class? Just pass it in to your other Class's constructor.
     
  7. Offline

    Googlelover1234

    Pretty much what he did. I was just trying not to spoonfeed :p
     
  8. Offline

    Gnat008

  9. Offline

    Googlelover1234

    Gnat008
    Sorry, I wasn't very clear on what I meant. I meant "pretty much what he did" as in "pretty much what Gnat008 did". I was talking to the OP, sorry to mislead you.
     
  10. Offline

    Gnat008

Thread Status:
Not open for further replies.

Share This Page