<commit_before>/*
 * Copyright (c) 2014 <NAME>.
 *
 * All Rights Reserved
 */

package com.skelril.aurora.modifiers;

import com.sk89q.commandbook.CommandBook;
import com.sk89q.commandbook.util.ChatUtil;
import com.sk89q.commandbook.util.InputUtil;
import com.sk89q.minecraft.util.commands.*;
import com.skelril.aurora.util.database.IOUtil;
import com.zachsthings.libcomponents.ComponentInformation;
import com.zachsthings.libcomponents.bukkit.BukkitComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;

@ComponentInformation(friendlyName = "Modifiers", desc = "Commands and saving for the Modifier system.")
public class ModifierComponent extends BukkitComponent implements Listener {

    private final CommandBook inst = CommandBook.inst();
    private final Logger log = CommandBook.logger();
    private final Server server = CommandBook.server();

    private final static int interval = 20 * 60 * 5;
    private static Modifier modifierCenter;

    @Override
    public void enable() {
        load();
        registerCommands(Commands.class);

        //noinspection AccessStaticViaInstance
        inst.registerEvents(this);
    }

    @Override
    public void disable() {
        save();
    }

    public static Modifier getModifierCenter() {
        return modifierCenter;
    }

    public class Commands {
        @Command(aliases = {"modifiers"}, desc = "Modifier Commands")
        @NestedCommand({ModifierCommands.class})
        public void modCommands(CommandContext args, CommandSender sender) throws CommandException {

        }
    }

    public class ModifierCommands {
        @Command(aliases = {"extend"}, desc = "Extend the duration of a modifier",
                usage = "<modifier> <time> [player]",
                flags = "", min = 2, max = 3)
        @CommandPermissions("aurora.modifiers.extend")
        public void extendCmd(CommandContext args, CommandSender sender) throws CommandException {
            ModifierType modifierType;
            try {
                modifierType = ModifierType.valueOf(args.getString(0));
            } catch (IllegalArgumentException ex) {
                throw new CommandException("No modifier by that name could be found!");
            }
            long amount = InputUtil.TimeParser.matchDate(args.getString(1));

            boolean wasOn = modifierCenter.isActive(modifierType);
            modifierCenter.extend(modifierType, amount);
            save();

            String friendlyTime = ChatUtil.getFriendlyTime(System.currentTimeMillis() + modifierCenter.status(modifierType));
            String change = wasOn ? " extended" : " enabled";
            String by = args.argsLength() > 2 ? " by " + args.getString(2) : "";
            Bukkit.broadcastMessage(ChatColor.GOLD + modifierType.fname() + change + by + " till " + friendlyTime + "!");
        }
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        List<String> messages = new ArrayList<>();
        for (ModifierType type : ModifierType.values()) {
            long dur = modifierCenter.status(type);
            if (dur == 0) continue;<commit_msg>Added support for a random modifier extension<commit_after>/*
 * Copyright (c) 2014 <NAME>.
 *
 * All Rights Reserved
 */

package com.skelril.aurora.modifiers;

import com.sk89q.commandbook.CommandBook;
import com.sk89q.commandbook.util.ChatUtil;
import com.sk89q.commandbook.util.InputUtil;
import com.sk89q.minecraft.util.commands.*;
import com.skelril.aurora.util.CollectionUtil;
import com.skelril.aurora.util.database.IOUtil;
import com.zachsthings.libcomponents.ComponentInformation;
import com.zachsthings.libcomponents.bukkit.BukkitComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;

@ComponentInformation(friendlyName = "Modifiers", desc = "Commands and saving for the Modifier system.")
public class ModifierComponent extends BukkitComponent implements Listener {

    private final CommandBook inst = CommandBook.inst();
    private final Logger log = CommandBook.logger();
    private final Server server = CommandBook.server();

    private final static int interval = 20 * 60 * 5;
    private static Modifier modifierCenter;

    @Override
    public void enable() {
        load();
        registerCommands(Commands.class);

        //noinspection AccessStaticViaInstance
        inst.registerEvents(this);
    }

    @Override
    public void disable() {
        save();
    }

    public static Modifier getModifierCenter() {
        return modifierCenter;
    }

    public class Commands {
        @Command(aliases = {"modifiers"}, desc = "Modifier Commands")
        @NestedCommand({ModifierCommands.class})
        public void modCommands(CommandContext args, CommandSender sender) throws CommandException {

        }
    }

    public class ModifierCommands {
        @Command(aliases = {"extend"}, desc = "Extend the duration of a modifier",
                usage = "<modifier> <time> [player]",
                flags = "", min = 2, max = 3)
        @CommandPermissions("aurora.modifiers.extend")
        public void extendCmd(CommandContext args, CommandSender sender) throws CommandException {
            ModifierType modifierType;
            try {
                String modifierStr = args.getString(0);
                if (modifierStr.equalsIgnoreCase("rand")) {
                    modifierType = CollectionUtil.getElement(ModifierType.values());
                } else {
                    modifierType = ModifierType.valueOf(modifierStr);
                }
            } catch (IllegalArgumentException ex) {
                throw new CommandException("No modifier by that name could be found!");
            }
            long amount = InputUtil.TimeParser.matchDate(args.getString(1));

            boolean wasOn = modifierCenter.isActive(modifierType);
            modifierCenter.extend(modifierType, amount);
            save();

            String friendlyTime = ChatUtil.getFriendlyTime(System.currentTimeMillis() + modifierCenter.status(modifierType));
            String change = wasOn ? " extended" : " enabled";
            String by = args.argsLength() > 2 ? " by " + args.getString(2) : "";
            Bukkit.broadcastMessage(ChatColor.GOLD + modifierType.fname() + change + by + " till " + friendlyTime + "!");
        }
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        List<String> messages = new ArrayList<>();
        for (ModifierType type : ModifierType.values()) {
            long dur = modifierCenter.status(type);
            if (dur == 0) continue;
{'fraction_non_alphanumeric': 0.10203802489399535, 'fraction_numerical': 0.006565449322938038, 'mean_word_length': 3.013172338090011, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4823647', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1949, 'n_words': 473}