Solved Nether Gamerule

Discussion in 'Plugin Development' started by fish_boss, Oct 5, 2013.

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

    fish_boss

    I am new to writing plugins and have hit a bit of a bump. I'm writing a plugin and I need to make sure that natural regeneration is off in the nether when/if a player goes there. My plugin is used on a new map every time so I can't just have it set once. So far, I have come up with this:
    @EventHandler
    public void outPortal(EntityPortalExitEvent event){
    if (event.getEntity()instanceof Player){
    Player player=(Player)event.getEntity();
    World world = player.getWorld();
    world.setGameRuleValue("naturalRegeneration", "false");
    this.plugin.getLogger().info("World Updated.");
    }
    }
    which works great, but it does not work the first time a player enters the nether. I have thought about adding a PortalCreateEvent but I was hoping there was a better way to go about ensuring natural regeneration was off in the nether.
     
  2. Offline

    fish_boss

    Well, since I can't remove the post, I'll share what I found out. The EntityPortalExitEvent is called when a player is teleported out of the portal into the other dimension when I thought it was called as a player walked out of the portal in the other dimension. The event was triggering the natural regeneration to be turned off in the overworld the first time someone went through to the nether, and nether regeneration was only turned off once someone traveled back to the overworld from the nether.
     
  3. Offline

    chasechocolate

    Instead of setting it when they exit a portal, just loop through the worlds in the onEnable() and set it there.
     
  4. Offline

    fish_boss

    How can I do that? I ended up using EntityPortalEnterEvent which is activated repeatedly as long as the player in my case is in contact with a portal so I added the conditional.
    @EventHandler
    public void outPortal(EntityPortalEnterEvent event){
    if (event.getEntity()instanceof Player){
    Player player=(Player)event.getEntity();
    World world = player.getWorld();
    if (world.getGameRuleValue("naturalRegeneration")!="false"){
    world.setGameRuleValue("naturalRegeneration", "false");
    this.plugin.getLogger().info("World Updated.");
    }
    }
    }
     
Thread Status:
Not open for further replies.

Share This Page