AntiFlySwitch 1.0

Disable fly when switching world

  1. Galaxias
    Well um, this is awkward... I was working om somebody's server and decided to clean up the plugins. I found this odd plugin called 'AntiFlySwitch' and asked the owner what it did. Apparently, I made it for him a while ago and when a user switches the world, fly will automatically be disabled for that player.

    If you don't want it switched for a specific player/group, you can add the permission 'antiflyswitch.op'. This will prevent AntiFlySwitch from working for a specific player.

    The message that will be sent to a player when their fly is disabled is customizable. Here's the code of the plugin...

    Main.class

    Code (Text):

    package nl.galaxias.AntiFlySwitch;

    import org.bukkit.Bukkit;
    import org.bukkit.Server;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.FileConfigurationOptions;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main
      extends JavaPlugin
    {
      private static Plugin plugin;
      FileConfiguration config = getConfig();
     
      public void onEnable()
      {
        plugin = this;
       
        registerEvents(this, new Listener[] { new PlayerChangedWorldListener() });
       
        this.config.addDefault("general.message", "&cFly &9is &agedeactiveerd");
       
        this.config.options().copyDefaults(true);
        saveConfig();
      }
     
      public void onDisable()
      {
        plugin = null;
      }
     
      public static void registerEvents(Plugin plugin, Listener... listeners)
      {
        for (Listener listener : listeners) {
          Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
        }
      }
     
      public static Plugin getPlugin()
      {
        return plugin;
      }
    }
     
    PlayerChangedWorldListener.class

    Code (Text):

    package nl.galaxias.AntiFlySwitch;

    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerChangedWorldEvent;
    import org.bukkit.plugin.Plugin;

    public class PlayerChangedWorldListener
      implements Listener
    {
      @EventHandler
      public void onWorldChange(PlayerChangedWorldEvent event)
      {
        Player player = event.getPlayer();
        if (!player.hasPermission("antiflyswitch.op"))
        {
          player.setAllowFlight(false);
         
          player.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.getPlugin().getConfig().getString("general.message")));
        }
      }
    }
     
    Ye, it's a pretty basic plugin :)