Ejemplo n.º 1
0
  public static void setPerk(Player p, Perk name) {
    if (ownsPerk(p, name)) {
      perk.put(p, name);
      setPerkArrow(p);

      savePerk(p);

      if (name == Perk.SPEED) {
        ItemsAndInventories.ClassSelection.get(p)
            .setItem(
                35,
                Items.createItem(
                    Speed.getType(),
                    1,
                    0,
                    "§a§lSpeed",
                    new ArrayList<String>(Arrays.asList("§2Click to change"))));
      } else if (name == Perk.MARATHON) {
        ItemsAndInventories.ClassSelection.get(p)
            .setItem(
                35,
                Items.createItem(
                    Marathon.getType(),
                    1,
                    0,
                    "§a§lMarathon",
                    new ArrayList<String>(Arrays.asList("§2Click to change"))));
      } else if (name == Perk.SCAVENGER) {
        ItemsAndInventories.ClassSelection.get(p)
            .setItem(
                35,
                Items.createItem(
                    Scavenger.getType(),
                    1,
                    0,
                    "§a§lScavenger",
                    new ArrayList<String>(Arrays.asList("§2Click to change"))));
      } else if (name == Perk.HARDLINE) {
        ItemsAndInventories.ClassSelection.get(p)
            .setItem(
                35,
                Items.createItem(
                    Hardline.getType(),
                    1,
                    0,
                    "§a§lHardline",
                    new ArrayList<String>(Arrays.asList("§2Click to change"))));
      } else if (name == Perk.NO_PERK) {
        ItemsAndInventories.ClassSelection.get(p).setItem(35, ItemsAndInventories.none);
      }
    }
  }
Ejemplo n.º 2
0
  @SuppressWarnings("deprecation")
  public static void onPlayerKillPlayer(Player killer) {
    if (getPerk(killer) == Perk.SCAVENGER) {
      if (Main.PlayingPlayers.contains(killer)) {
        if (killer.getInventory().getItem(19) != null) {
          ItemStack ammoPrimary = killer.getInventory().getItem(19);
          int Primary25 = ammoPrimary.getAmount() / 4;
          if (Primary25 <= 0) return;
          killer
              .getInventory()
              .addItem(
                  Items.createItem(
                      ammoPrimary.getType(),
                      Primary25,
                      ammoPrimary.getData().getData(),
                      ammoPrimary.getItemMeta().getDisplayName()));
        }

        if (killer.getInventory().getItem(25) != null) {
          ItemStack ammoSecondary = killer.getInventory().getItem(25);
          int Secondary25 = ammoSecondary.getAmount() / 4;
          if (Secondary25 <= 0) return;
          killer
              .getInventory()
              .addItem(
                  Items.createItem(
                      ammoSecondary.getType(),
                      Secondary25,
                      ammoSecondary.getData().getData(),
                      ammoSecondary.getItemMeta().getDisplayName()));
        }

        if (killer.getInventory().getItem(8) != null) {
          ItemStack ammoFFA = killer.getInventory().getItem(8);
          int FFA25 = ammoFFA.getAmount() / 4;
          if (FFA25 <= 0) return;
          killer
              .getInventory()
              .addItem(
                  Items.createItem(
                      ammoFFA.getType(),
                      FFA25,
                      ammoFFA.getData().getData(),
                      ammoFFA.getItemMeta().getDisplayName()));
        }
      }
    }
  }
Ejemplo n.º 3
0
public class PerkAPI {
  public static HashMap<Player, Perk> perk = new HashMap<Player, Perk>();
  public static HashMap<Player, List<Perk>> ownedPerks = new HashMap<Player, List<Perk>>();

  /* Speed: Bread
   * Marathon: Carrot
   * Scavenger: Apple
   * Hardline: Egg
   * Down Arrow: Water Bucket
   */

  public static ItemStack downArrow =
      Items.createItem(Material.WATER_BUCKET, 1, 0, "§6§lCurrent Perk");
  public static ItemStack noPerk = Items.createItem(Material.EMERALD, 1, 0, "§4§lNo Perk");

  public static ItemStack ownsSpeed =
      Items.createItem(
          Material.BREAD,
          1,
          0,
          "§e§l§nSpeed",
          new ArrayList<String>(
              Arrays.asList(
                  "",
                  "§f§lCosts: §2§l" + getCost(Perk.SPEED) + " Credits",
                  "§f§lPurchased: §a§lTrue",
                  "§7When using this perk, you",
                  "§7will have an extra speed",
                  "§7boost during the game")));
  public static ItemStack ownsMarathon =
      Items.createItem(
          Material.CARROT_ITEM,
          1,
          0,
          "§e§l§nMarathon",
          new ArrayList<String>(
              Arrays.asList(
                  "",
                  "§f§lCosts: §2§l" + getCost(Perk.MARATHON) + " Credits",
                  "§f§lPurchased: §a§lTrue",
                  "§7When using this perk, you",
                  "§7will have unlimited hunger",
                  "§7meaning you can run forever")));
  public static ItemStack ownsScavenger =
      Items.createItem(
          Material.APPLE,
          1,
          0,
          "§e§l§nScavenger",
          new ArrayList<String>(
              Arrays.asList(
                  "",
                  "§f§lCosts: §2§l" + getCost(Perk.SCAVENGER) + " Credits",
                  "§f§lPurchased: §a§lTrue",
                  "§7When using this perk, you",
                  "§7will receive 25% of your ammo",
                  "§7back after you kill someone")));
  public static ItemStack ownsHardline =
      Items.createItem(
          Material.EGG,
          1,
          0,
          "§e§l§nHardline",
          new ArrayList<String>(
              Arrays.asList(
                  "",
                  "§f§lCosts: §2§l" + getCost(Perk.HARDLINE) + " Credits",
                  "§f§lPurchased: §a§lTrue",
                  "§7When using this perk, you",
                  "§7will get killstreak powerups",
                  "§7by having one less kill than",
                  "§7the usual amount. This means",
                  "§7you will only have to get 4",
                  "§7kills to get extra ammo")));

  public static ItemStack Speed =
      Items.createItem(
          Material.BREAD,
          1,
          0,
          "§e§l§nSpeed",
          new ArrayList<String>(
              Arrays.asList(
                  "",
                  "§f§lCosts: §4§l" + getCost(Perk.SPEED) + " Credits",
                  "§f§lPurchased: §c§lFalse",
                  "§5» Click to purchase",
                  "§7When using this perk, you",
                  "§7will have an extra speed",
                  "§7boost during the game")));
  public static ItemStack Marathon =
      Items.createItem(
          Material.CARROT_ITEM,
          1,
          0,
          "§e§l§nMarathon",
          new ArrayList<String>(
              Arrays.asList(
                  "",
                  "§f§lCosts: §4§l" + getCost(Perk.MARATHON) + " Credits",
                  "§f§lPurchased: §c§lFalse",
                  "§5» Click to purchase",
                  "§7When using this perk, you",
                  "§7will have unlimited hunger",
                  "§7meaning you can run forever")));
  public static ItemStack Scavenger =
      Items.createItem(
          Material.APPLE,
          1,
          0,
          "§e§l§nScavenger",
          new ArrayList<String>(
              Arrays.asList(
                  "",
                  "§f§lCosts: §4§l" + getCost(Perk.SCAVENGER) + " Credits",
                  "§f§lPurchased: §c§lFalse",
                  "§5» Click to purchase",
                  "§7When using this perk, you",
                  "§7will receive 25% of your ammo",
                  "§7back after you kill someone")));
  public static ItemStack Hardline =
      Items.createItem(
          Material.EGG,
          1,
          0,
          "§e§l§nHardline",
          new ArrayList<String>(
              Arrays.asList(
                  "",
                  "§f§lCosts: §4§l" + getCost(Perk.HARDLINE) + " Credits",
                  "§f§lPurchased: §c§lFalse",
                  "§5» Click to purchase",
                  "§7When using this perk, you",
                  "§7will get killstreak powerups",
                  "§7by having one less kill than",
                  "§7the usual amount. This means",
                  "§7you will only have to get 4",
                  "§7kills to get extra ammo")));

  public static void setPerk(Player p, Perk name) {
    if (ownsPerk(p, name)) {
      perk.put(p, name);
      setPerkArrow(p);

      savePerk(p);

      if (name == Perk.SPEED) {
        ItemsAndInventories.ClassSelection.get(p)
            .setItem(
                35,
                Items.createItem(
                    Speed.getType(),
                    1,
                    0,
                    "§a§lSpeed",
                    new ArrayList<String>(Arrays.asList("§2Click to change"))));
      } else if (name == Perk.MARATHON) {
        ItemsAndInventories.ClassSelection.get(p)
            .setItem(
                35,
                Items.createItem(
                    Marathon.getType(),
                    1,
                    0,
                    "§a§lMarathon",
                    new ArrayList<String>(Arrays.asList("§2Click to change"))));
      } else if (name == Perk.SCAVENGER) {
        ItemsAndInventories.ClassSelection.get(p)
            .setItem(
                35,
                Items.createItem(
                    Scavenger.getType(),
                    1,
                    0,
                    "§a§lScavenger",
                    new ArrayList<String>(Arrays.asList("§2Click to change"))));
      } else if (name == Perk.HARDLINE) {
        ItemsAndInventories.ClassSelection.get(p)
            .setItem(
                35,
                Items.createItem(
                    Hardline.getType(),
                    1,
                    0,
                    "§a§lHardline",
                    new ArrayList<String>(Arrays.asList("§2Click to change"))));
      } else if (name == Perk.NO_PERK) {
        ItemsAndInventories.ClassSelection.get(p).setItem(35, ItemsAndInventories.none);
      }
    }
  }

  public static Perk getPerk(Player p) {
    if (perk.get(p) == null) setPerk(p, Perk.NO_PERK);
    return perk.get(p);
  }

  public static void savePerk(Player p) {
    if (!(MySQL.mySQLenabled())) {
      PerksFile.getData().set("Perks.CurrentlyUsing." + p.getUniqueId(), "" + perk.get(p));
      PerksFile.saveData();
      PerksFile.reloadData();
    } else {
      try {
        Connection conn = MySQL.getConnection();
        String INSERT =
            "INSERT INTO CODPerks (uuid, currentperk) VALUES(?, ?) ON DUPLICATE KEY UPDATE currentperk=?";
        PreparedStatement ps = conn.prepareStatement(INSERT);
        ps.setString(1, p.getUniqueId().toString());
        ps.setString(2, "" + perk.get(p));
        ps.setString(3, "" + perk.get(p));

        ps.executeUpdate();

        ps.close();
        conn.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }

  public static void loadPerk(Player p) {
    if (!(MySQL.mySQLenabled())) {
      String name = PerksFile.getData().getString("Perks.CurrentlyUsing." + p.getUniqueId());

      if (name != null) {
        perk.put(p, getPerk(name));
      } else {
        perk.put(p, Perk.NO_PERK);
      }
    } else {
      try {
        Connection conn = MySQL.getConnection();
        PreparedStatement ps = conn.prepareStatement("SELECT uuid,currentperk FROM CODPerks");
        ResultSet result = ps.executeQuery();

        while (result.next()) {
          if (result.getString("uuid").equals(p.getUniqueId().toString())) {
            if ((result.getString("currentperk") == null)
                || (result.getString("currentperk").equals(""))) {
              perk.put(p, Perk.NO_PERK);
            } else {
              perk.put(p, getPerk(result.getString("currentperk")));
            }

            break;
          }
        }

        result.close();
        ps.close();
        conn.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }

  public static Perk getPerk(String name) {
    if (Perk.valueOf(name) != null) {
      return Perk.valueOf(name);
    } else {
      return Perk.NO_PERK;
    }
  }

  public static void loadOwnedPerks(Player p) {
    if (!(MySQL.mySQLenabled())) {
      List<String> perkNames =
          PerksFile.getData().getStringList("Perks.OwnedPerks." + p.getUniqueId());
      ownedPerks.put(p, new ArrayList<Perk>());

      for (int i = 0; i < perkNames.size(); i++) {
        String name = perkNames.get(i);
        if (getPerk(name) == Perk.NO_PERK) continue;

        ownedPerks.get(p).add(getPerk(name));
      }
    } else {
      try {
        Connection conn = MySQL.getConnection();
        PreparedStatement ps = conn.prepareStatement("SELECT uuid,list FROM CODPerks");
        ResultSet rs = ps.executeQuery();

        while (rs.next()) {
          if (rs.getString("uuid").equals(p.getUniqueId().toString())) {
            ArrayList<String> perkNames =
                MySQL.stringToList(MySQL.clobToString(rs.getClob("list")));
            if ((perkNames == null) || (perkNames.isEmpty())) {
              ownedPerks.put(p, new ArrayList<Perk>());
            } else {
              ownedPerks.put(p, new ArrayList<Perk>());

              for (int i = 0; i < perkNames.size(); i++) {
                String name = perkNames.get(i);
                if (getPerk(name) == Perk.NO_PERK) continue;

                ownedPerks.get(p).add(getPerk(name));
              }
            }

            break;
          }
        }

        if (ownedPerks.get(p) == null) {
          ownedPerks.put(p, new ArrayList<Perk>());
        }

        rs.close();
        ps.close();
        conn.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  public static void saveOwnedPerks(Player p) {
    if (!(MySQL.mySQLenabled())) {
      List<String> perkNames = new ArrayList<String>();
      for (Perk perk : ownedPerks.get(p)) {
        perkNames.add("" + perk);
      }

      PerksFile.getData().set("Perks.OwnedPerks." + p.getUniqueId(), perkNames);
      PerksFile.saveData();
      PerksFile.reloadData();
    } else {
      try {
        Connection conn = MySQL.getConnection();
        String INSERT =
            "INSERT INTO CODPerks (uuid, list) VALUES(?, ?) ON DUPLICATE KEY UPDATE list=?";
        PreparedStatement ps = conn.prepareStatement(INSERT);
        ps.setString(1, p.getUniqueId().toString());

        ArrayList<String> perkNames = new ArrayList<String>();
        for (Perk perk : ownedPerks.get(p)) {
          perkNames.add("" + perk);
        }

        Clob clob = MySQL.stringToClob(MySQL.listToString(perkNames), conn);
        ps.setClob(2, clob);
        ps.setClob(3, clob);

        ps.executeUpdate();

        ps.close();
        conn.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  public static boolean ownsPerk(Player p, Perk name) {
    if (name == Perk.NO_PERK) return true;
    loadOwnedPerks(p);
    if (ownedPerks.get(p).contains(name)) return true;
    return false;
  }

  public static boolean isUsingPerk(Player p) {
    if (perk.get(p) != null && perk.get(p) != Perk.NO_PERK) return true;
    return false;
  }

  public static int getCost(Perk perk) {
    if (ThisPlugin.getPlugin().getConfig().get("Perks.Cost." + perk) != null)
      return ThisPlugin.getPlugin().getConfig().getInt("Perks.Cost." + perk);
    return 0;
  }

  @SuppressWarnings("deprecation")
  public static void setPerkArrow(Player p) {
    Inventory inv = ItemsAndInventories.perks.get(p);

    inv.setItem(9, new ItemStack(Material.AIR));
    inv.setItem(11, new ItemStack(Material.AIR));
    inv.setItem(13, new ItemStack(Material.AIR));
    inv.setItem(15, new ItemStack(Material.AIR));
    inv.setItem(17, new ItemStack(Material.AIR));

    if (PerkAPI.isUsingPerk(p)) {
      if (PerkAPI.getPerk(p) == Perk.SPEED) inv.setItem(9, downArrow);
      if (PerkAPI.getPerk(p) == Perk.MARATHON) inv.setItem(11, downArrow);
      if (PerkAPI.getPerk(p) == Perk.SCAVENGER) inv.setItem(15, downArrow);
      if (PerkAPI.getPerk(p) == Perk.HARDLINE) inv.setItem(17, downArrow);
    } else {
      inv.setItem(13, downArrow);
    }

    p.updateInventory();
  }

  public static void unlockPerk(Player p, Perk name) {
    List<Perk> perks = ownedPerks.get(p);
    Inventory inv = ItemsAndInventories.perks.get(p);

    if (name == Perk.SPEED) {
      if (!(perks.contains(Perk.SPEED))) {
        perks.add(Perk.SPEED);
        inv.setItem(18, ownsSpeed);
        saveOwnedPerks(p);
        p.sendMessage(Main.codSignature + "§aSuccessfully purchased §2Speed Perk");

        if (ownsPerk(p, Perk.SPEED)) {
          setPerk(p, name);
        }
      }
    } else if (name == Perk.MARATHON) {
      if (!(perks.contains(Perk.MARATHON))) {
        perks.add(Perk.MARATHON);
        inv.setItem(20, ownsMarathon);
        saveOwnedPerks(p);
        p.sendMessage(Main.codSignature + "§aSuccessfully purchased §2Marathon Perk");

        if (ownsPerk(p, Perk.MARATHON)) {
          setPerk(p, name);
        }
      }
    } else if (name == Perk.SCAVENGER) {
      if (!(perks.contains(Perk.SCAVENGER))) {
        perks.add(Perk.SCAVENGER);
        inv.setItem(24, ownsScavenger);
        saveOwnedPerks(p);
        p.sendMessage(Main.codSignature + "§aSuccessfully purchased §2Scavenger Perk");

        if (ownsPerk(p, Perk.SCAVENGER)) {
          setPerk(p, name);
        }
      }
    } else if (name == Perk.HARDLINE) {
      if (!(perks.contains(Perk.HARDLINE))) {
        perks.add(Perk.HARDLINE);
        inv.setItem(26, ownsHardline);
        saveOwnedPerks(p);
        p.sendMessage(Main.codSignature + "§aSuccessfully purchased §2Hardline Perk");

        if (ownsPerk(p, Perk.HARDLINE)) {
          setPerk(p, name);
        }
      }
    }
  }

  // Events:
  public static void onStartOfMatch() {
    for (Player pp : Main.PlayingPlayers) {
      if (getPerk(pp) == Perk.SPEED) {
        pp.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 180000, 1));
      }
    }
  }

  public static void onRespawn(Player p) {
    if (getPerk(p) == Perk.SPEED) {
      p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 180000, 1));
    }
  }

  @SuppressWarnings("deprecation")
  public static void onPlayerKillPlayer(Player killer) {
    if (getPerk(killer) == Perk.SCAVENGER) {
      if (Main.PlayingPlayers.contains(killer)) {
        if (killer.getInventory().getItem(19) != null) {
          ItemStack ammoPrimary = killer.getInventory().getItem(19);
          int Primary25 = ammoPrimary.getAmount() / 4;
          if (Primary25 <= 0) return;
          killer
              .getInventory()
              .addItem(
                  Items.createItem(
                      ammoPrimary.getType(),
                      Primary25,
                      ammoPrimary.getData().getData(),
                      ammoPrimary.getItemMeta().getDisplayName()));
        }

        if (killer.getInventory().getItem(25) != null) {
          ItemStack ammoSecondary = killer.getInventory().getItem(25);
          int Secondary25 = ammoSecondary.getAmount() / 4;
          if (Secondary25 <= 0) return;
          killer
              .getInventory()
              .addItem(
                  Items.createItem(
                      ammoSecondary.getType(),
                      Secondary25,
                      ammoSecondary.getData().getData(),
                      ammoSecondary.getItemMeta().getDisplayName()));
        }

        if (killer.getInventory().getItem(8) != null) {
          ItemStack ammoFFA = killer.getInventory().getItem(8);
          int FFA25 = ammoFFA.getAmount() / 4;
          if (FFA25 <= 0) return;
          killer
              .getInventory()
              .addItem(
                  Items.createItem(
                      ammoFFA.getType(),
                      FFA25,
                      ammoFFA.getData().getData(),
                      ammoFFA.getItemMeta().getDisplayName()));
        }
      }
    }
  }
}
Ejemplo n.º 4
0
@SuppressWarnings("deprecation")
public class CreateGunCommand {

  public static HashMap<Player, Boolean> gunBuilder = new HashMap<Player, Boolean>();
  public static HashMap<Player, Integer> gunBuilderStep = new HashMap<Player, Integer>();
  public static HashMap<Player, ItemStack> Gun = new HashMap<Player, ItemStack>();
  public static HashMap<Player, ItemStack> Ammo = new HashMap<Player, ItemStack>();
  public static HashMap<Player, String> GName = new HashMap<Player, String>();
  public static HashMap<Player, String> AName = new HashMap<Player, String>();
  public static HashMap<Player, Integer> LevelUnlock = new HashMap<Player, Integer>();
  public static HashMap<Player, Integer> gunCost = new HashMap<Player, Integer>();
  public static HashMap<Player, String> type = new HashMap<Player, String>();
  public static HashMap<Player, ItemStack[]> inventory = new HashMap<Player, ItemStack[]>();
  public static HashMap<Player, GameMode> gamemode = new HashMap<Player, GameMode>();

  public static ItemStack primary =
      Items.createItem(Material.WOOL, 1, 14, "§3» §bClick to set gun to primary §3«");
  public static ItemStack secondary =
      Items.createItem(Material.WOOL, 1, 5, "§e» §6Click to set gun to secondary §e«");
  public static ItemStack confirm =
      Items.createItem(Material.INK_SACK, 1, 10, "§2» §aClick to confirm gun creation §2«");
  public static ItemStack abort =
      Items.createItem(Material.INK_SACK, 1, 5, "§4» §cAbort gun creation §4«");

  public static void createGun(Player p, String[] args) {
    if (args.length == 11) {
      String gunID = args[1];
      String gunData = args[2];
      String gunName = args[3];
      String ammoID = args[4];
      String ammoData = args[5];
      String ammoAmount = args[6];
      String ammoName = args[7];
      String Level = args[8];
      String Cost = args[9];
      String Type = args[10];

      try {
        Integer.parseInt(gunID);
        Integer.parseInt(gunData);
        Integer.parseInt(ammoID);
        Integer.parseInt(ammoData);
        Integer.parseInt(ammoAmount);
        Integer.parseInt(Level);
        Integer.parseInt(Cost);
      } catch (NumberFormatException exception) {
        p.sendMessage(
            Main.codSignature
                + "§cGun Item ID, Gun Data Value, Ammo Item ID, Ammo Data Value, Ammo Amount, Level, and Cost all have to be valid numbers");
        return;
      }

      Guns.loadGuns();

      final String displayName = "§e" + gunName;

      for (int i = 0; i < Guns.guns.size(); i++) {
        if (Guns.guns.get(i).getItemMeta().getDisplayName().equals(displayName)) {
          p.sendMessage(Main.codSignature + "§cThe gun§4 " + gunName + " §calready exists");
          return;
        }
      }

      if (!(Type.equalsIgnoreCase("Primary")) && !(Type.equalsIgnoreCase("Secondary")))
        p.sendMessage(Main.codSignature + "§cInvalid type. Try §ePrimary §cor §eSecondary");

      if (Type.equalsIgnoreCase("Primary")) Type = "Primary";
      if (Type.equalsIgnoreCase("Secondary")) Type = "Secondary";

      ItemStack gun = new ItemStack(Integer.parseInt(gunID));
      ItemMeta gunMeta = gun.getItemMeta();
      gunMeta.setDisplayName(gunName);
      gun.setItemMeta(gunMeta);

      ItemStack ammo = new ItemStack(Integer.parseInt(ammoID), Integer.parseInt(ammoAmount));
      ItemMeta ammoMeta = ammo.getItemMeta();
      ammoMeta.setDisplayName(ammoName);
      ammo.setItemMeta(ammoMeta);

      Guns.saveGun(
          gun,
          Integer.parseInt(gunData),
          ammo,
          Integer.parseInt(ammoData),
          Integer.parseInt(Cost),
          Integer.parseInt(Level),
          Type);

      p.sendMessage(Main.codSignature + "§bGun Created!");
    } else {
      p.sendMessage(
          Main.codSignature
              + "§ePlease type §b/cod creategun §6[Gun Item ID] [Gun Data Value] [Gun Name] [Ammo Item ID] [Ammo Data Value] [Ammo Amount] [Ammo Name] [Level Unlock] [Gun Cost] [§3Primary§6|§3Secondary§6]");
    }
  }

  public static void createAutoGun(final Player p) {
    if (CreateArenaCommand.creatingArena.get(p) == true) {
      p.sendMessage(Main.codSignature + "§cPlease finish creating your arena first");
      return;
    }

    gunBuilder.put(p, true);
    p.sendMessage(
        Main.codSignature
            + "§7You entered gun creator mode. Type §f/cod guncreator§7 to abort creation");
    p.sendMessage("§21. §aPut the gun item in your hand and right-click");

    gunBuilderStep.put(p, 1);

    gamemode.put(p, p.getGameMode());
    p.setGameMode(GameMode.CREATIVE);

    BukkitRunnable br =
        new BukkitRunnable() {
          @Override
          public void run() {
            if (gunBuilder.get(p)) {
              SendCoolMessages.sendOverActionBar(
                  p, "§7You are in gun creator mode. Type §f/cod guncreator§7 to leave");
            }
          }
        };

    br.runTaskTimer(ThisPlugin.getPlugin(), 0L, 30L);
  }

  public static void onInteract(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    if (gunBuilder.get(p) == true) {
      if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (e.getItem() == null || e.getItem().getType() == Material.AIR) return;
        if (gunBuilderStep.get(p) == 1) {
          e.setCancelled(true);
          ItemStack gun =
              new ItemStack(p.getItemInHand().getType(), 1, p.getItemInHand().getData().getData());
          Gun.put(p, gun);
          p.sendMessage(" §f» §8Set gun item to§7 " + gun.getType());
          p.sendMessage("§22. §aPut the ammo in your hand and right-click");
          gunBuilderStep.put(p, 2);
        } else if (gunBuilderStep.get(p) == 2) {
          e.setCancelled(true);
          ItemStack ammo =
              new ItemStack(
                  p.getItemInHand().getType(),
                  p.getItemInHand().getAmount(),
                  p.getItemInHand().getData().getData());
          Ammo.put(p, ammo);
          // if (gamemode.get(p) != null)
          // p.setGameMode(gamemode.get(p));
          p.sendMessage(" §f» §8Set ammo to§7 " + ammo.getType());
          p.sendMessage("§23. §aNow type the name of the gun in the chat");
          gunBuilderStep.put(p, 3);
        } else if (gunBuilderStep.get(p) == 7) {
          e.setCancelled(true);
          if ((e.getItem().getType().equals(Material.WOOL))
              && (e.getItem().getData().getData() == (byte) 14)) {
            type.put(p, "primary");
            p.getInventory().clear();
            p.getInventory().setItem(1, confirm);
            p.getInventory().setItem(7, abort);
            p.getInventory().setHeldItemSlot(4);

            p.sendMessage(" §f» §8Set gun type to §7primary");
            p.sendMessage(
                "§28. §aNow right-click the green dye to confirm gun creation or right-click the purple dye to cancel gun creation");

            p.updateInventory();
            gunBuilderStep.put(p, 8);
          } else if ((e.getItem().getType().equals(Material.WOOL))
              && (e.getItem().getData().getData() == (byte) 5)) {
            type.put(p, "secondary");
            p.getInventory().clear();
            p.getInventory().setItem(1, confirm);
            p.getInventory().setItem(7, abort);
            p.getInventory().setHeldItemSlot(4);

            p.sendMessage(" §f» §8Set gun type to §7secondary");
            p.sendMessage(
                "§28. §aNow right-click the green dye to confirm gun creation or right-click the purple dye to cancel gun creation");

            p.updateInventory();
            gunBuilderStep.put(p, 8);
          }
        } else if (gunBuilderStep.get(p) == 8) {
          e.setCancelled(true);
          if (e.getItem().getType().equals(Material.INK_SACK)
              && (e.getItem().getData().getData() == (byte) 10)) {
            p.sendMessage(" §e» §6Finalizing gun creation...");
            if (!(makeAutoGun(p))) {
              p.sendMessage("§cGun creation failed");
            } else {
              p.sendMessage(" §b» §3Successfully created gun!");
            }
            endGunCreation(p, false);
          } else if (e.getItem().getType().equals(Material.INK_SACK)
              && (e.getItem().getData().getData() == (byte) 5)) {
            endGunCreation(p, true);
          }
        }
      }
    } else {
      return;
    }
  }

  public static boolean makeAutoGun(Player p) {
    if (gunBuilder.get(p) == true) {
      Guns.loadGuns();

      final String displayName = "§e" + GName.get(p);

      for (int i = 0; i < Guns.guns.size(); i++) {
        if (Guns.guns.get(i).getItemMeta().getDisplayName().equals(displayName)) {
          p.sendMessage("§cThe gun§4 " + GName.get(p) + " §calready exists");
          return false;
        }
      }

      String Type = type.get(p);
      int Cost = gunCost.get(p);
      int Level = LevelUnlock.get(p);

      if (!(Type.equalsIgnoreCase("Primary")) && !(Type.equalsIgnoreCase("Secondary")))
        p.sendMessage(Main.codSignature + "§cInvalid type. Try §ePrimary §cor §eSecondary");

      if (Type.equalsIgnoreCase("Primary")) Type = "Primary";
      if (Type.equalsIgnoreCase("Secondary")) Type = "Secondary";

      ItemStack gun = Gun.get(p);
      ItemMeta gunMeta = gun.getItemMeta();
      gunMeta.setDisplayName(GName.get(p));
      gun.setItemMeta(gunMeta);

      ItemStack ammo = Ammo.get(p);
      ItemMeta ammoMeta = ammo.getItemMeta();
      ammoMeta.setDisplayName(AName.get(p));
      ammo.setItemMeta(ammoMeta);

      Guns.saveGun(
          gun,
          (int) Gun.get(p).getData().getData(),
          ammo,
          (int) Ammo.get(p).getData().getData(),
          Cost,
          Level,
          Type);

      return true;
    }

    return false;
  }

  public static void onInventoryClick(InventoryClickEvent e) {
    if (!(e.getWhoClicked() instanceof Player)) return;
    Player p = (Player) e.getWhoClicked();
    if (gunBuilder.get(p) == true) {
      if (gunBuilderStep.get(p) >= 7) {
        e.setCancelled(true);
      }
    }
  }

  public static void endGunCreation(Player p, Boolean abortMessage) {
    if (gunBuilder.get(p) == true) {
      p.getInventory().clear();
      gunBuilder.put(p, false);
      gunBuilderStep.put(p, 0);
      if (inventory.get(p) != null) p.getInventory().setContents(inventory.get(p));
      if (gamemode.get(p) != null) p.setGameMode(gamemode.get(p));
      gamemode.put(p, null);
      inventory.put(p, null);
      p.updateInventory();
      if (abortMessage) p.sendMessage("§cGun creation canceled");
      p.sendMessage(Main.codSignature + "§7You left gun creator");
    }
  }

  public static void onChat(AsyncPlayerChatEvent e) {
    Player p = e.getPlayer();
    if (gunBuilder.get(p) == true) {
      if (gunBuilderStep.get(p) == 3) {
        e.setCancelled(true);
        // String Name = StringUtils.remove(e.getMessage(), ' ');
        GName.put(p, e.getMessage());
        p.sendMessage(" §f» §8Set gun name to§7 " + e.getMessage());
        p.sendMessage("§24. §aNow type the name of the ammo in the chat");
        gunBuilderStep.put(p, 4);
      } else if (gunBuilderStep.get(p) == 4) {
        e.setCancelled(true);
        // String Name = StringUtils.remove(e.getMessage(), ' ');
        AName.put(p, e.getMessage());
        p.sendMessage(" §f» §8Set ammo name to§7 " + e.getMessage());
        p.sendMessage("§25. §aNow type the cost of the gun in the chat");
        gunBuilderStep.put(p, 5);
      } else if (gunBuilderStep.get(p) == 5) {
        e.setCancelled(true);
        Integer cost = 0;
        try {
          String message = StringUtils.remove(e.getMessage(), ' ');
          cost = Integer.parseInt(message);
        } catch (NumberFormatException exeption) {
          p.sendMessage("§cGun cost must be a valid number. Try again");
          return;
        }

        gunCost.put(p, cost);
        p.sendMessage(" §f» §8Set gun cost to§7 " + cost);
        p.sendMessage("§26. §aNow type the level at which the gun will be unlocked in the chat");
        gunBuilderStep.put(p, 6);
      } else if (gunBuilderStep.get(p) == 6) {
        e.setCancelled(true);
        Integer level = 0;
        try {
          String message = StringUtils.remove(e.getMessage(), ' ');
          level = Integer.parseInt(message);
        } catch (NumberFormatException exception) {
          p.sendMessage("§cUnlock level must be a valid number. Try again");
          return;
        }

        LevelUnlock.put(p, level);
        p.sendMessage(" §f» §8Set gun level unlock to §7 " + level);
        p.sendMessage(
            "§27. §aNow right-click the red wool in your inventory to make the gun primary, or right-click the green wool in you inventory to make the gun secondary");
        gunBuilderStep.put(p, 7);

        inventory.put(p, p.getInventory().getContents());
        p.getInventory().clear();
        p.getInventory().setItem(1, primary);
        p.getInventory().setItem(7, secondary);
        p.getInventory().setHeldItemSlot(4);
      }
    }
  }
}
  @SuppressWarnings("deprecation")
  public static void setAvailableGuns(Player p) {
    if ((KitInventory.getKit(p).getItem(1) == null)
        || (KitInventory.getKit(p).getItem(3) == null)) {
      return;
    }

    none = new ItemStack(Material.EMERALD);

    ItemMeta noneMeta = none.getItemMeta();
    noneMeta.setDisplayName("§4None");
    none.setItemMeta(noneMeta);

    ArrayList<String> lore = new ArrayList<String>();

    final ItemStack Primary =
        new ItemStack(
            KitInventory.getKit(p).getItem(1).getType(),
            1,
            KitInventory.getKit(p).getItem(1).getData().getData());

    ItemMeta pMeta = Primary.getItemMeta();
    pMeta.setDisplayName(KitInventory.getKit(p).getItem(1).getItemMeta().getDisplayName());

    final ItemStack Secondary =
        new ItemStack(
            KitInventory.getKit(p).getItem(3).getType(),
            1,
            KitInventory.getKit(p).getItem(3).getData().getData());

    ItemMeta sMeta = Secondary.getItemMeta();
    sMeta.setDisplayName(KitInventory.getKit(p).getItem(3).getItemMeta().getDisplayName());

    String PrimaryName = pMeta.getDisplayName();
    String SecondaryName = sMeta.getDisplayName();

    ItemMeta PMeta = Primary.getItemMeta();
    PMeta.setDisplayName("§7Current Primary:§e " + PrimaryName);
    lore.add("§8Click this item to change");
    lore.add("§8your primary weapon");
    lore.add("");
    PMeta.setLore(lore);
    Primary.setItemMeta(PMeta);

    lore.clear();

    ItemMeta SMeta = Secondary.getItemMeta();
    SMeta.setDisplayName("§7Current Secondary:§e " + SecondaryName);
    lore.add("§8Click this item to change");
    lore.add("§8your secondary weapon");
    SMeta.setLore(lore);
    Secondary.setItemMeta(SMeta);

    PGun.put(p, Primary);
    SGun.put(p, Secondary);

    ClassSelection.get(p).setItem(27, Primary);
    ClassSelection.get(p).setItem(29, Secondary);
    ClassSelection.get(p).setItem(31, none);
    ClassSelection.get(p).setItem(33, none);

    Perk name = PerkAPI.getPerk(p);

    if (name == Perk.NO_PERK) {
      ItemsAndInventories.ClassSelection.get(p).setItem(35, none);
    } else if (name == Perk.SPEED) {
      ItemsAndInventories.ClassSelection.get(p)
          .setItem(
              35,
              Items.createItem(
                  PerkAPI.Speed.getType(),
                  1,
                  0,
                  "§a§lSpeed",
                  new ArrayList<String>(Arrays.asList("§2Click to change"))));
    } else if (name == Perk.MARATHON) {
      ItemsAndInventories.ClassSelection.get(p)
          .setItem(
              35,
              Items.createItem(
                  PerkAPI.Marathon.getType(),
                  1,
                  0,
                  "§a§lMarathon",
                  new ArrayList<String>(Arrays.asList("§2Click to change"))));
    } else if (name == Perk.SCAVENGER) {
      ItemsAndInventories.ClassSelection.get(p)
          .setItem(
              35,
              Items.createItem(
                  PerkAPI.Scavenger.getType(),
                  1,
                  0,
                  "§a§lScavenger",
                  new ArrayList<String>(Arrays.asList("§2Click to change"))));
    } else if (name == Perk.HARDLINE) {
      ItemsAndInventories.ClassSelection.get(p)
          .setItem(
              35,
              Items.createItem(
                  PerkAPI.Hardline.getType(),
                  1,
                  0,
                  "§a§lHardline",
                  new ArrayList<String>(Arrays.asList("§2Click to change"))));
    }
  }