Solved WorldChangeEvent

Discussion in 'Spigot Plugin Development' started by Sunique, Jun 13, 2016.

  1. How can I enable flying on certain worlds? I have this
    Code (Text):
        public void FlightEnabledOnPrison(PlayerChangedWorldEvent e){
            final Player p = (Player) e.getPlayer();
                p.sendMessage("Flight enabled.");
            }else if(!p.getWorld().getName().equals("Prison")||!p.getWorld().getName().equals("Prison-1")){
                p.sendMessage("Flight disabled.");
  2. use while loop if world is equals to prison then
    another for loop for online players then let them fly
  3. That else if is redundant. Just use an else statement.
    • Agree Agree x 2
  4. Do you mean a for loop? What would be the point in using a while loop.

    What isn't working for your original code?
  5. know the difference between while and for loop then
  6. Since this is a toggle I will show you a trick.
    Code (Text):

    if (condition) {
        p.setAllowFlight( !p.getAllowFlight() );
        p.setFlying( !p.isFlying() );
    This will work as a switch, if the value is false it will set it to true and vice versa.
    • Like Like x 1
  7. I already figured it out but even if I did this they would join in the hub and it would set them to flying ;-; but I just did a timer and wait 1L and then it does the code.