Making Plugins Perworld

Discussion in 'Plugin Development' started by LordVakar, Feb 9, 2014.

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

    LordVakar

    How would I accomplish making my plugin only work in one specific world?
    Like I have this:
    Code:
        for (World world : getServer().getWorlds()) {
            world.setGameRuleValue("naturalRegeneration", "false");
        }
    and I want the gamerule to be only in a specific world.
    I also have schedulers and Bukkit.broadcastMessage. How would I make the schedulers run only in a specific world and the message to broadcast in that specific world?
    I also have various other code that I want run in a specific world.
     
  2. Offline

    Gater12

    LordVakar
    You can have a list of world names and compare it to the Worlds...
    Code:java
    1. for(World world : getServer().getWorlds()){
    2. if(!world.getName().equalsIgnoreCase(String worldName)){
    3. /* Continue the loop, because the world name is not what you want it to be... */
    4. continue;
    5. }
    6. /* The world name is what you want and now you execute the code for that one world... */
    7. }
     
  3. Offline

    LordVakar

    Gater12
    So if I checked the world name and broadcasted a message, wouldn't it broadcast throughout all the worlds still?
    Idk, I'll try it.

    EDIT:
    Gater12
    Do I create a string named world name that is equal to the worldname I want?
     
  4. Offline

    Gater12

    LordVakar It would broadcast to all the worlds.... You would need to loop through all the Players online the server, get the world name and then if the name equals to what you want, then send them the message.
     
  5. Offline

    LordVakar

    Gater12

    (So Do I create a string named world name that is equal to the worldname I want in code you gave me)
    So I don't use broadcastMessage anymore, but I should use player.sendMessage, but loop through it if they are in a specific world?
    How about schedulers and events?
     
  6. Offline

    Gater12

    LordVakar You can have a global variable of the name of the world name. Yes you'd want to use player.sendMessage() to the players who are in the world. What about schedulers and events?
    Example:
    Code:java
    1. String worldName = "AWHOLENEWWOOOOORLD";
    2. /* Loop through all the players */
    3. for(Player p : Bukkit.getOnlinePlayers()){
    4. /* Returns true if the the players world name is equalsIgnoreCase worldName */
    5. if(p.getWorld().getName().equalsIgnoreCase(worldName)){
    6. /* Send them the message */
    7. p.sendMessage(String message);
    8. }
    9. }
     
  7. Offline

    LordVakar

    Gater12

    Well, how do you make schedulers and events apply to only one world?
    Or scoreboards?
     
  8. Offline

    Gater12

    LordVakar For scoreboards, you can check if the player is in the world you want, then show them the scoreboard. For events, entities would probably be involved (So ServerListPingEvent is thrown out the window obviously), so you would get the world of the entity -> If it's not in the world return; Otherwise, it'll execute the code because it's the world you want.

    Still have to ponder about schedulers... What are you doing in them?
     
  9. Offline

    LordVakar

    Gater12


    I have a scheduler that is executed on playerjoinevent that runs every 40 ticks.
    The scheduler updates the player's health on a scoreboard I have.

    I also have another scheduler that is executed on command that runs every 20 mins and broadcasts a message.
     
  10. Offline

    AoH_Ruthless

    LordVakar
    When the player joins, before even executing a scheduler, check if their world is equal to the wrld you want. If not, return.
     
Thread Status:
Not open for further replies.

Share This Page