gt:         for (String key : vars.keySet()) {
context: /*  
   *  ReActions, Minecraft bukkit plugin
   *  (c)2012-2017, fromgate, fromgate@gmail.com
   *  http://dev.bukkit.org/server-mods/reactions/
   *    
   *  This file is part of ReActions.
   *  
   *  ReActions is free software: you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation, either version 3 of the License, or
   *  (at your option) any later version.
   *
   *  ReActions is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with ReActions.  If not, see <http://www.gnorg/licenses/>.
   * 
   */
  
  package me.fromgate.reactions.util;
  
  import me.fromgate.reactions.ReActions;
  import me.fromgate.reactions.event.EventManager;
  import me.fromgate.reactions.util.message.M;
  import org.bukkit.command.CommandSender;
  import org.bukkit.configuration.file.YamlConfiguration;
  import org.bukkit.entity.Player;
  import org.bukkit.plugin.java.JavaPlugin;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  import java.util.TreeMap;
  import java.util.UUID;
  import java.util.regex.Pattern;
  
  public class Variables {
  
      private static Map<String, String> vars = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
      private static Map<String, String> tempvars = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
  
      private final static Pattern VARP = Pattern.compile("(?i).*%varp?:\\S+%.*");
      private final static Pattern FLOAT_0 = Pattern.compile("^[0-9]+\\.0$");
      private final static Pattern NUMBER = Pattern.compile("-?[0-9]+(.[0-9]+)?");
  
      private static String varId(Player player, String var) {
          return (player == null ? "general." + var : player.getName() + "." + var);
      }
  
      private static String varId(String player, String var) {
          return (player.isEmpty() ? "general." + var : player + "." + var);
      }
  
      public static void setVar(String player, String var, String value) {
          String prevVal = Variables.getVar(player, var, "");
          vars.put(varId(player, var), value);
          if (!Cfg.playerSelfVarFile) save();
          else save(player);
          EventManager.raiseVariableEvent(var, player, value, prevVal);
      }
  
      public static void setVar(Player player, String var, String value) {
          String prevVal = Variables.getVar(player, var, "");
          vars.put(varId(player, var), value);
          if (!Cfg.playerSelfVarFile) save();
          else save(player.getName());
          EventManager.raiseVariableEvent(var, player == null ? "" : player.getName(), value, prevVal);
      }
  
      public static void clearVar(Player player, String var) {
          String prevVal = Variables.getVar(player, var, "");
          String id = varId(player, var);
          if (vars.containsKey(id)) vars.remove(id);
          if (!Cfg.playerSelfVarFile) save();
          else save(player.getName());
          EventManager.raiseVariableEvent(var, player == null ? "" : player.getName(), "", prevVal);
      }
  
      public static boolean clearVar(String player, String var) {
          String prevVal = Variables.getVar(player, var, "");
          String id = varId(player, var);
          if (!vars.containsKey(id)) return false;
          vars.remove(id);
          if (!Cfg.playerSelfVarFile) save();
          else save(player);
          EventManager.raiseVariableEvent(var, player, "", prevVal);
          return true;
      }
  
  
      public static String getVar(String player, String var, String defvar) {
          String id = varId(player, var);
          if (vars.containsKey(id)) return vars.get(id);
          return defvar;
      }
  
      public static String getVar(Player player, String var, String defvar) {
          String id = varId(player, var);
          if (vars.containsKey(id)) return vars.get(id);
          return defvar;
      }
  
      public static boolean cmpVar(String playerName, String var, String cmpvalue) {
          String id = varId(playerName, var);
          if (!vars.containsKey(id)) return false;
          String value = getVar(playerName, var, "");
          if (isNumber(cmpvalue, value)) return (Double.parseDouble(cmpvalue) == Double.parseDouble(value));
          return value.equalsIgnoreCase(cmpvalue);
      }
  
      public static boolean cmpGreaterVar(String playerName, String var, String cmpvalue) {
          String id = varId(playerName, var);
          if (!vars.containsKey(id)) return false;
          if (!isNumber(vars.get(id), cmpvalue)) return false;
          return Double.parseDouble(vars.get(id)) > Double.parseDouble(cmpvalue);
      }
  
      public static boolean cmpLowerVar(String playerName, String var, String cmpvalue) {
          String id = varId(playerName, var);
          if (!vars.containsKey(id)) return false;
          if (!isNumber(vars.get(id), cmpvalue)) return false;
          return Double.parseDouble(vars.get(id)) < Double.parseDouble(cmpvalue);
      }
  
      public static boolean existVar(String playerName, String var) {
          return (vars.containsKey(varId(playerName, var)));
      }
  
      public static boolean incVar(Player player, String var) {
          return incVar(player, var, 1);
      }
  
      public static boolean incVar(String player, String var) {
          return incVar(player, var, 1);
      }
  
      public static boolean decVar(Player player, String var) {
          return incVar(player, var, -1);
      }
  
      public static boolean decVar(String player, String var) {
          return incVar(player, var, -1);
      }
  
      public static boolean incVar(Player player, String var, double addValue) {
          return incVar(player == null ? "" : player.getName(), var, addValue);
      }
  
      public static boolean incVar(String player, String var, double addValue) {
          String id = varId(player, var);
          if (!vars.containsKey(id)) setVar(player, var, "0");
          String valueStr = vars.get(id);
          if (!isNumber(valueStr)) return false;
          setVar(player, var, String.valueOf(Double.parseDouble(valueStr) + addValue));
          return true;
      }
  
  
      public static boolean decVar(String player, String var, double decValue) {
          return incVar(player, var, decValue * (-1));
      }
  
      public static boolean decVar(Player player, String var, double decValue) {
          return incVar(player, var, decValue * (-1));
      }
  
      public static boolean mergeVar(Player player, String var, String stringToMerge, boolean spaceDivider) {
          String space = spaceDivider ? " " : "";
          String id = varId(player, var);
          if (!vars.containsKey(id)) setVar(player, var, "");
          setVar(player, var, getVar(player, var, "") + space + stringToMerge);
          return false;
      }
  
  
      public static void save() {
          try {
              YamlConfiguration cfg = new YamlConfiguration();
              File f = new File(ReActions.instance.getDataFolder() + File.separator + "variables.yml");
              if (f.exists()) f.delete();
              f.createNewFile();
              for (String key : vars.keySet())
                  cfg.set(key, vars.get(key));
              cfg.save(f);
          } catch (Exception ignored) {
          }
      }
  
      public static void save(String player) {
          if (Cfg.playerAsynchSaveSelfVarFile) saveAsynch(player);
          else savePlayer(player);
      }
  
      public static void savePlayer(String player) {
          try {
              YamlConfiguration cfg = new YamlConfiguration();
              String varDir = ReActions.instance.getDataFolder() + File.separator + "variables";
              File dir = new File(varDir);
              if (!dir.exists() && !dir.mkdirs()) return;
              saveGeneral();
              if (player == null || player.isEmpty()) return;
              UUID id = Util.getUUID(player);
              if (id == null) return;
              File f = new File(varDir + File.separator + id.toString() + ".yml");
              if (f.exists()) f.delete();
              f.createNewFile();
              for (String key : vars.keySet()) {
                  if (key.contains(player)) cfg.set(key, vars.get(key));
              }
              cfg.save(f);
              removePlayerVars(player);
          } catch (Exception ignored) {
          }
      }
  
      public static void saveAsynch(String player) {
          JavaPlugin pluginInstance = ReActions.instance;
          pluginInstance.getServer().getScheduler().runTaskAsynchronously(pluginInstance, () -> savePlayer(player));
      }
  
      private static void saveGeneral() {
          try {
              YamlConfiguration cfg = new YamlConfiguration();
              String varDir = ReActions.instance.getDataFolder() + File.separator + "variables";
              File f = new File(varDir + File.separator + "general.yml");
              if (f.exists()) f.delete();
              f.createNewFile();
              for (String key : vars.keySet()) {
                  if (key.contains("general")) cfg.set(key, vars.get(key));
              }
              cfg.save(f);
          } catch (Exception ignored) {
          }
      }
  
      public static void load() {
          vars.clear();
          try {
              YamlConfiguration cfg = new YamlConfiguration();
              File f = new File(ReActions.instance.getDataFolder() + File.separator + "variables.yml");
              if (!f.exists()) return;
              cfg.load(f);
              for (String key : cfg.getKeys(true)) {
                  if (!key.contains(".")) continue;
                  vars.put(key, cfg.getString(key));
              }
              if (!Cfg.playerSelfVarFile) {
                  loadVars();
                  File dir = new File(ReActions.instance.getDataFolder() + File.separator + "variables");
                  if (!dir.exists() || !dir.isDirectory()) return;
                  String[] files = dir.list();
                  for (String file : files) {
                      File fl = new File(dir, file);
                      fl.delete();
                  }
                  dir.delete();
              }
          } catch (Exception ignored) {
          }
      }
  
      public static void loadVars() {
          if (Cfg.playerSelfVarFile) load();
          try {
              YamlConfiguration cfg = new YamlConfiguration();
              File dir = new File(ReActions.instance.getDataFolder() + File.separator + "variables");
              if (!dir.exists()) return;
              for (File f : dir.listFiles()) {
                  if (!f.isDirectory()) {
                      String fstr = f.getName();
                      if (fstr.endsWith(".yml")) {
                          cfg.load(f);
                          for (String key : cfg.getKeys(true)) {
                              if (!key.contains(".")) continue;
                              vars.put(key, cfg.getString(key));
                          }
                      }
                  }
              }
          } catch (Exception ignored) {
          }
      }
  
      private static void removePlayerVars(String player) {
          try {
              Map<String, String> vars_tmp = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
              YamlConfiguration cfg = new YamlConfiguration();
              String fileName = ReActions.instance.getDataFolder() + File.separator + "variables.yml";
              File f = new File(fileName);
              if (!f.exists()) return;
              cfg.load(f);
              for (String key : cfg.getKeys(true)) {
                  if (!key.contains(".")) continue;
                  if (key.contains(player) || key.contains("general")) continue;
                  vars_tmp.put(key, cfg.getString(key));
              }
  
              YamlConfiguration cfg2 = new YamlConfiguration();
              if (f.delete() && f.createNewFile()) {
                  for (String key : vars_tmp.keySet())
                      cfg2.set(key, vars_tmp.get(key));
                  cfg2.save(f);
                  vars_tmp.clear();
              }
          } catch (Exception ignored) {
          }
      }
  
  
      public static String replacePlaceholders(Player player, String str) {
          if (!VARP.matcher(str).matches()) return str;
  
          String newStr = str;
  