Integer stamp = Utils.getUnixTimestamp(0L);
if (!Utils.checkCommandSpam(sendingPlayer, "kits-give")) {
// check if we can use the kit in question
FileConfiguration f = CommandsEX.getConf();
ConfigurationSection kitConfigGroups = f.getConfigurationSection("kits");
if (kitConfigGroups != null){
Set<String> kitGroups = kitConfigGroups.getKeys(false);
for (String group : kitGroups) {
if (group.equals("*") || Permissions.checkPermEx(sendingPlayer, "cex.kits." + group)) {
ConfigurationSection kits = f.getConfigurationSection("kits." + group);
Set<String> kitNames = kits.getKeys(false);
for (String kit : kitNames) {
if (kit.equalsIgnoreCase(args[0])) {
if (f.getBoolean("kits." + group + "." + kit + ".onetime", false) && usedOneTimeKits.containsKey(pName)) {
// a one-time kit that was used by this player already
oneTimeKitWarning = true;
} else if ((f.getInt("kits." + group + "." + kit + ".cooldown", 0) > 0) && !Permissions.checkPermEx(player, "cex.kits.cooldown.bypass") && kitCooldowns.containsKey(pName) && ((stamp - kitCooldowns.get(pName)) < f.getInt("kits." + group + "." + kit + ".cooldown"))) {
// kit on a cooldown
cooldownWarning = true;
} else {
// one-time kit?
if (f.getBoolean("kits." + group + "." + kit + ".onetime", false)) {
// store one-time usage into database - if this returns error, the record already exists, so we just return a warning
if (CommandsEX.sqlEnabled) {
SQLManager.omitErrorLogs = true;
if (!SQLManager.query("INSERT INTO "+ SQLManager.prefix +"kits_usage VALUES (?, ?)", pName, kit)) {
oneTimeKitWarning = true;
} else {
usedOneTimeKits.put(pName, kit);
}
SQLManager.omitErrorLogs = false;
}
}
// cooldown kit?
if (f.getInt("kits." + group + "." + kit + ".cooldown", 0) > 0) {
kitCooldowns.put(pName, Utils.getUnixTimestamp(0L));
}
// if we don't have a one-time kit warning from database, give items to the player
if (!oneTimeKitWarning) {
// load all items for this player's reward
ConfigurationSection configGroups = f.getConfigurationSection("kits." + group + "." + kit);
Set<String> s = configGroups.getKeys(false);
// remove onetime and cooldown keys
s.remove("onetime");
s.remove("cooldown");
s.remove("onjoin");