What is wrong with getting the world name from config?

Discussion in 'Plugin Development' started by adde, Aug 24, 2012.

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

    adde

    Hello, I am trying to make a plugin where you disable some stuff in a specified world, that you can configure in the config, BUT it doesn't get the world, it disables it in EVERY world. Here is my code:

    Code:java
    1.  
    2. @EventHandler
    3. public void onPearlThrow(PlayerInteractEvent event){
    4. if (event.getItem() != null && event.getItem().getType() == Material.ENDER_PEARL){
    5. if(event.getPlayer().getServer().getWorld(getConfig().getString("WorldNames")) != null){
    6. if(event.getPlayer().hasPermission("pearlman.throw")){
    7.  
    8. }else{
    9. event.getPlayer().sendMessage(ChatColor.DARK_RED + getConfig().getString("DenyMessage"));
    10. event.setCancelled(true);
    11. }
    12. }
    13. }
    14.  
    15. }
    16.  

    The else works, like that DenyMessage thing, I can configure that, but not the world name, at WorldNames.

    I really need to finish this in like any minute! Please help me!

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

    Giant

    How many worlds does worldnames contain? Also I would suggest validating the other way round, so that would be:
    getConfig().getString("WorlNames").contains(event.getPlayer().getWorld().getName());
     
    adde likes this.
  3. Offline

    adde

    As default, it is World, World2, Does that matter?

    Ok, thx it works now with your method! :D Will try if it works with more then one world.

    Edit: works if I seperate with a ,

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

    Giant

    Kind of, as you get it as a single string, it means that getWorld() is going to exact match it to that. So getWorld() is currently trying to find a world with the name "World, World2". I would also still suggest matching it the other way round, as in seeing if the players name is on the allowed list, see my example in my previous post for that! :)

    Edit:
    Glad to hear you've fixed it so far! :)
     
  5. Offline

    adde

    http://forums.bukkit.org/threads/ad...pearls-in-configurable-worlds-cb-1-3-2.95766/
     
Thread Status:
Not open for further replies.

Share This Page