コード例 #1
0
  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;
  }
コード例 #2
0
  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]");
    }
  }