gt:             String msg = getServerOfflineFormat();
context: /*
   * Copyright 2012 frdfsnlght <frdfsnlght@gmail.com>.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package com.frdfsnlght.transporter;
  
  import com.frdfsnlght.transporter.api.TypeMap;
  import com.frdfsnlght.inquisitor.Inquisitor;
  import com.frdfsnlght.inquisitor.api.API;
  import com.frdfsnlght.transporter.api.ReservationException;
  import java.util.Arrays;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  import org.bukkit.Location;
  import org.bukkit.World;
  import org.bukkit.entity.Player;
  import org.bukkit.plugin.Plugin;
  
  /**
   *
   * @author frdfsnlght <frdfsnlght@gmail.com>
   */
  public final class Realm {
  
      private static final Set<String> OPTIONS = new HashSet<String>();
  
      private static final Options options;
  
      static {
          OPTIONS.add("name");
          OPTIONS.add("defaultServer");
          OPTIONS.add("defaultWorld");
          OPTIONS.add("defaultGate");
          OPTIONS.add("respawn");
          OPTIONS.add("respawnGate");
          OPTIONS.add("serverOfflineFormat");
          OPTIONS.add("restoreWhenServerOffline");
          OPTIONS.add("restoreWhenServerOfflineFormat");
          OPTIONS.add("kickWhenServerOffline");
          OPTIONS.add("kickWhenServerOfflineFormat");
  
          options = new Options(Realm.class, OPTIONS, "trp.realm", new OptionsListener() {
              @Override
              public void onOptionSet(Context ctx, String name, String value) {
                  ctx.send("realm option '%s' set to '%s'", name, value);
              }
              @Override
              public String getOptionPermission(Context ctx, String name) {
                  return name;
              }
          });
      }
  
      private static boolean started = false;
      private static Set<String> redirectedPlayers = new HashSet<String>();
      private static Set<String> respawningPlayers = new HashSet<String>();
      private static API inquisitor = null;
  
      public static boolean isStarted() {
          return started;
      }
  
      // called from main thread
      public static void start(Context ctx) {
          if (! getEnabled()) return;
          try {
              if (getName() == null)
                  throw new RealmException("name is not set");
  
              redirectedPlayers.clear();
  
              started = true;
              ctx.send("realm support started");
  
              for (Server server : Servers.getAll())
                  if (server.isConnected()) server.sendRefreshData();
  
          } catch (RealmException e) {
              ctx.warn("realm support cannot be started: %s", e.getMessage());
          }
      }
  
      // called from main thread
      public static void stop(Context ctx) {
          if (! started) return;
          inquisitor = null;
          started = false;
          respawningPlayers.clear();
          ctx.send("realm support stopped");
      }
  
      public static void onConfigLoad(Context ctx) {}
  
      public static void onConfigSave() {}
  
      // Player events
  
      public static void onTeleport(Player player, Location toLocation) {
          if (! started) return;
          if (redirectedPlayers.contains(player.getName())) return;
          if (! respawningPlayers.remove(player.getName())) return;
          Utils.debug("realm respawn '%s'", player.getName());
          if (! getRespawn()) return;
          GateImpl respawnGate = getRespawnGateImpl();
          if (respawnGate != null)
              sendPlayerToGate(player, respawnGate);
          else {
              if (! inquisitorAvailable()) return;
              com.frdfsnlght.inquisitor.api.Location bedLocation = inquisitor.getPlayerBedLocation(player.getName());
              if (bedLocation == null) return;
              sendPlayerToBed(player, bedLocation.getServer(), bedLocation.getWorld(), bedLocation.getCoords());
          }
      }
  
      public static boolean onJoin(Player player) {
          if (! started) return false;
          Utils.debug("realm join '%s'", player.getName());
          redirectedPlayers.remove(player.getName());
          if (! inquisitorAvailable()) return false;
          com.frdfsnlght.inquisitor.api.Location lastLocation = inquisitor.getPlayerLastLocation(player.getName());
          if (lastLocation != null) {
              if (! lastLocation.getServer().equals(Global.plugin.getServer().getServerName())) {
                  if (sendPlayerToServer(player, lastLocation.getServer()))
                      return true;
              }
          } else {
              GateImpl defaultGate = getDefaultGateImpl();
              if (defaultGate != null) {
                  if (sendPlayerToGate(player, defaultGate))
                      return true;
              }
              String toServer = getDefaultServer();
              if (toServer != null) {
                  if (! toServer.equals(Global.plugin.getServer().getServerName())) {
                      if (sendPlayerToServer(player, toServer))
                          return true;
                  }
              }
              String toWorld = getDefaultWorld();
              if (toWorld != null) {
                  if (! toWorld.equals(player.getWorld().getName())) {
                      if (sendPlayerToWorld(player, toWorld))
                          return true;
                  }
              }
          }
          return false;
      }
  
      public static void onRespawn(Player player) {
          if (! started) return;
          respawningPlayers.add(player.getName());
      }
  
  
      // End Player events
  
      private static boolean inquisitorAvailable() {
          if (inquisitor != null) return true;
          Plugin p = Global.plugin.getServer().getPluginManager().getPlugin("Inquisitor");
          if (p == null) {
              Utils.warning("Inquisitor plugin is not installed!");
              return false;
          }
          Utils.info("Inquisitor plugin found");
          if (! p.isEnabled()) {
              Utils.warning("Inquisitor plugin is not enabled!");
              return false;
          }
          inquisitor = ((Inquisitor)p).getAPI();
          if (! inquisitor.isPlayerStatsStarted()) {
              inquisitor = null;
              Utils.warning("Inquisitor player stats is not started!");
              return false;
          }
          Utils.info("Inquisitor plugin is ready to go");
          return true;
      }
  
      // toServer is either the name of a configured server, or the name of a connected remote server
      private static boolean sendPlayerToServer(Player player, String toServer) {
          Server server = Servers.findByRemoteName(toServer);
          if (server == null) {
              server = Servers.find(toServer);
              /*
              if (server == null) {
                  Utils.warning("Unknown realm server '%s' for player '%s'", toServer, player.getName());
                  return false;
              }
              */
          }
          if ((server == null) || (! server.isConnected())) {
              Utils.warning("Unknown or offline realm server '%s' for player '%s'", toServer, player.getName());
  
              if (getRestoreWhenServerOffline()) {
                  Map<String,Object> playerData = inquisitor.getPlayerStats(player.getName());
                  if (playerData == null)
                      Utils.warning("Realm player stats for '%s' not found", player.getName());
                  else {
                      TypeMap data = new TypeMap(playerData);
                      Players.restore(player, data);
                      Utils.debug("restored '%s' from realm data", player.getName());
                      String msg = getRestoreWhenServerOfflineFormat();
                      if (msg != null)
                          msg = msg.replace("%server%", toServer);
                       Chat.colorize(msg);
                       if ((msg != null) && (! msg.isEmpty()))
                          player.sendMessage(msg);
                      return false;
                  }
              }
              if (getKickWhenServerOffline()) {
                  String msg = getKickWhenServerOfflineFormat();
                  msg = msg.replace("%server%", toServer);
                  inquisitor.ignorePlayerJoin(player.getName());
                  Utils.schedulePlayerKick(player, msg);
                  return true;
              }
  
  