Solved Can someone please help me correct my code.

Discussion in 'Plugin Development' started by A3O2, Oct 25, 2012.

Thread Status:
Not open for further replies.
  1. My code that doesnt work:
    PHP:
        for(World world Bukkit.getServer().getWorlds()){
     
            
    String path1 String.format("Worlds.%s.DD",world.getName());
            
    String path3 String.format("Worlds.%s",world.getName());
        for(
    Player ply Bukkit.getOnlinePlayers()){
     
        
    /**this line its the line needing to be fixed --> */ if(ply.getWorld().getName().equals(path3) && getConfig().getBoolean(path1) == true){
                
    event.setCancelled(true);
                }
     
        }
    }  
     
  2. Offline

    desht

    "doesn't work" is not a valid problem report.

    What are you intending to happen, and what is actually happening? Are you getting an exception?
     
    zack6849 likes this.
  3. this is what im intending on doing:
    PHP:
        @EventHandler
        
    public void BlockDispense(BlockDispenseEvent event){
    for(
    World world Bukkit.getServer().getWorlds()){
     
            
    String path1 String.format("Worlds.%s.DD",world.getName());
            
    String path3 String.format("Worlds.%s",world.getName());
        for(
    Player ply Bukkit.getOnlinePlayers()){
     
        
    /**this line its the line needing to be fixed --> */ if(ply.getWorld().getName().equals(path3) && getConfig().getBoolean(path1) == true){
                
    event.setCancelled(true);
                }
     
        }
    }
    no errors, just nothing happening.
     
  4. Offline

    Michael Rhodes

    Hey, maybe I can help...

    You have the right idea...
    What I would do to help me figure out where is is going wrong is print out some test messages at different places.

    Code:
    @EventHandler
    public void BlockDispense(BlockDispenseEvent event){
     
        String worldName = wrld.getName();   
        String path1 = String.format("Worlds.%s.DD",worldName);
        String path3 = String.format("Worlds.%s",worldName);
     
        // Print this out to test for proper values...
        System.out.println("Path1: "+path1);  System.out.println("Path3: "+path3);
       
    for(Player ply : Bukkit.getOnlinePlayers()){
     
        /**this line its the line needing to be fixed --> */ 
     
    // The problem appears to be that you are comparing the Name of the world the player is in
    // to the formated string "World.<worldname>"  That will always fail.
    if(ply.getWorld().getName().equals(path3) && getConfig().getBoolean(path1) == true){
                event.setCancelled(true);
                }
        }
    }
    }
    
    Let me know more about what you are trying to do here and I can help. Also, I removed the scanning through all worlds, seemed like a waste of code since the only world that matters is the one the event is taking place in.

    Give some more details, and I don't mind looking at it again

    Michael
     
  5. lol it says:
    HTML:
    21:53:54 [INFO] Path1: Worlds.world.DD
    21:53:54 [INFO] Path1: Worlds.world.DD
    21:53:54 [INFO] Path3: Worlds.world
    21:53:54 [INFO] Path1: Worlds.world_the_end.DD
    21:53:54 [INFO] Path3: Worlds.world_the_end
    21:53:54 [INFO] Path1: Worlds.world_nether.DD
    21:53:54 [INFO] Path3: Worlds.world_nether
    
    So basically its getting "World.world" instead of "world"
     
  6. Offline

    LukeSFT

    Then add a test message, where ptint the name of the world where the player is.
     
  7. Offline

    Michael Rhodes

    Do you have Teamspeak A302 ?
     
  8. Offline

    LukeSFT

  9. Offline

    Michael Rhodes

    I was just asking the OP..... He can come on my server and I am willing to help him out.... We'll post the results here for others to see...

    It was just a though...
     
  10. yes i have teamspeak whats ur ts ip? i dont have a mic though.
     
Thread Status:
Not open for further replies.

Share This Page