Search in sources :

Example 1 with IntegerRange

use of net.dzikoysk.funnyguilds.util.IntegerRange in project FunnyGuilds by FunnyGuilds.

the class PluginConfig method reload.

public void reload() {
    this.dateFormat = new SimpleDateFormat(Messages.getInstance().dateFormat);
    try {
        this.nameRegex = GuildRegex.valueOf(this.nameRegex_.toUpperCase());
    } catch (Exception e) {
        this.nameRegex = GuildRegex.LETTERS;
        FunnyLogger.exception(new IllegalArgumentException("\"" + this.nameRegex_ + "\" is not a valid regex option!"));
    }
    try {
        this.tagRegex = GuildRegex.valueOf(this.tagRegex_.toUpperCase());
    } catch (Exception e) {
        this.tagRegex = GuildRegex.LETTERS;
        FunnyLogger.exception(new IllegalArgumentException("\"" + this.tagRegex_ + "\" is not a valid regex option!"));
    }
    this.createItems = loadItemStackList(this.items_);
    this.createItemsVip = loadItemStackList(this.itemsVip_);
    this.guiItems = loadGUI(this.guiItems_);
    if (!useCommonGUI) {
        this.guiItemsVip = loadGUI(this.guiItemsVip_);
    }
    this.guiItemsTitle = StringUtils.colored(this.guiItemsTitle_);
    this.guiItemsVipTitle = StringUtils.colored(this.guiItemsVipTitle_);
    this.guiItemsLore = StringUtils.colored(this.guiItemsLore_);
    try {
        this.createEntityType = EntityType.valueOf(this.createType.toUpperCase().replace(" ", "_"));
    } catch (Exception e) {
        this.createMaterialData = Parser.parseMaterialData(this.createType, true);
    }
    if (this.createMaterialData != null && this.createMaterialData.getItemType() == Material.DRAGON_EGG) {
        this.eventPhysics = true;
    }
    if (this.enlargeEnable) {
        this.enlargeItems = this.loadItemStackList(this.enlargeItems_);
    } else {
        this.enlargeSize = 0;
        this.enlargeItems = null;
    }
    if (this.buggedBlocksTimer < 0L) {
        FunnyLogger.exception(new IllegalArgumentException("The field named \"bugged-blocks-timer\" can not be less than zero!"));
        // default value
        this.buggedBlocksTimer = 20L;
    }
    try {
        this.rankSystem = RankSystem.valueOf(this.rankSystem_.toUpperCase());
    } catch (Exception e) {
        this.rankSystem = RankSystem.ELO;
        FunnyLogger.exception(new IllegalArgumentException("\"" + this.rankSystem_ + "\" is not a valid rank system!"));
    }
    if (this.rankSystem == RankSystem.ELO) {
        Map<IntegerRange, Integer> parsedData = new HashMap<>();
        for (Entry<IntegerRange, String> entry : Parser.parseIntegerRange(this.eloConstants_, false).entrySet()) {
            try {
                parsedData.put(entry.getKey(), Integer.parseInt(entry.getValue()));
            } catch (NumberFormatException e) {
                FunnyLogger.parser("\"" + entry.getValue() + "\" is not a valid elo constant!");
            }
        }
        this.eloConstants = parsedData;
    }
    HashMap<Material, Double> map = new HashMap<>();
    for (Map.Entry<String, Double> entry : this.explodeMaterials_.entrySet()) {
        Material material = Parser.parseMaterial(entry.getKey(), true);
        if (material == null || material == Material.AIR) {
            continue;
        }
        double chance = entry.getValue();
        if (chance == 0) {
            continue;
        }
        map.put(material, chance);
    }
    DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
    LocalTime startTime = LocalTime.parse(guildTNTProtectionStartTime_, timeFormatter);
    LocalTime endTime = LocalTime.parse(guildTNTProtectionEndTime_, timeFormatter);
    this.guildTNTProtectionStartTime = LocalDateTime.of(LocalDate.now(), startTime);
    this.guildTNTProtectionEndTime = LocalDateTime.of(LocalDate.now(), endTime);
    if (this.guildTNTProtectionEndTime.isBefore(guildTNTProtectionStartTime)) {
        this.guildTNTProtectionEndTime = this.guildTNTProtectionEndTime.plusDays(1);
    }
    this.explodeMaterials = map;
    this.translatedMaterials = new HashMap<>();
    for (String materialName : translatedMaterials_.keySet()) {
        Material material = Material.matchMaterial(materialName.toUpperCase());
        if (material == null) {
            continue;
        }
        translatedMaterials.put(material, translatedMaterials_.get(materialName));
    }
    for (String s : this.regionEnterNotificationStyle_) {
        this.regionEnterNotificationStyle.add(NotificationStyle.valueOf(s.toUpperCase()));
    }
    if (this.notificationTitleFadeIn <= 0) {
        FunnyLogger.exception(new IllegalArgumentException("The field named \"notification-title-fade-in\" can not be less than or equal to zero!"));
        this.notificationTitleFadeIn = 10;
    }
    if (this.notificationTitleStay <= 0) {
        FunnyLogger.exception(new IllegalArgumentException("The field named \"notification-title-stay\" can not be less than or equal to zero!"));
        this.notificationTitleStay = 10;
    }
    if (this.notificationTitleFadeOut <= 0) {
        FunnyLogger.exception(new IllegalArgumentException("The field named \"notification-title-fade-out\" can not be less than or equal to zero!"));
        this.notificationTitleFadeOut = 10;
    }
    this.rankResetItems = loadItemStackList(this.rankResetItems_);
    this.warProtection = Parser.parseTime(this.warProtection_);
    this.warWait = Parser.parseTime(this.warWait_);
    this.validityStart = Parser.parseTime(this.validityStart_);
    this.validityTime = Parser.parseTime(this.validityTime_);
    this.validityWhen = Parser.parseTime(this.validityWhen_);
    this.validityItems = this.loadItemStackList(this.validityItems_);
    this.joinItems = this.loadItemStackList(this.joinItems_);
    this.baseItems = this.loadItemStackList(this.baseItems_);
    this.prefixOur = StringUtils.colored(this.prefixOur_);
    this.prefixAllies = StringUtils.colored(this.prefixAllies_);
    this.prefixOther = StringUtils.colored(this.prefixOther_);
    this.ptopOnline = StringUtils.colored(this.ptopOnline_);
    this.ptopOffline = StringUtils.colored(this.ptopOffline_);
    this.dummySuffix = StringUtils.colored(this.dummySuffix_);
    this.chatPosition = StringUtils.colored(this.chatPosition_);
    this.chatGuild = StringUtils.colored(this.chatGuild_);
    this.chatRank = StringUtils.colored(this.chatRank_);
    this.chatPoints = StringUtils.colored(this.chatPoints_);
    this.pointsFormat = Parser.parseIntegerRange(this.pointsFormat_, true);
    this.pingFormat = Parser.parseIntegerRange(this.pingFormat_, true);
    this.ptopPoints = StringUtils.colored(this.ptopPoints_);
    this.gtopPoints = StringUtils.colored(this.gtopPoints_);
    this.chatPrivDesign = StringUtils.colored(this.chatPrivDesign_);
    this.chatAllyDesign = StringUtils.colored(this.chatAllyDesign_);
    this.chatGlobalDesign = StringUtils.colored(this.chatGlobalDesign_);
    if (this.pasteSchematicOnCreation) {
        if (this.guildSchematicFileName == null || this.guildSchematicFileName.isEmpty()) {
            FunnyLogger.exception(new IllegalArgumentException("The field named \"guild-schematic-file-name\" is empty, but field \"paste-schematic-on-creation\" is set to true!"));
            this.pasteSchematicOnCreation = false;
        } else {
            this.guildSchematicFile = new File(FunnyGuilds.getInstance().getDataFolder(), this.guildSchematicFileName);
            if (!this.guildSchematicFile.exists()) {
                FunnyLogger.exception(new IllegalArgumentException("File with given name in field \"guild-schematic-file-name\" does not exist!"));
                this.pasteSchematicOnCreation = false;
            }
        }
    }
}
Also used : IntegerRange(net.dzikoysk.funnyguilds.util.IntegerRange) LocalTime(java.time.LocalTime) HashMap(java.util.HashMap) Material(org.bukkit.Material) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DateTimeFormatter(java.time.format.DateTimeFormatter) File(java.io.File)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 SimpleDateFormat (java.text.SimpleDateFormat)1 LocalTime (java.time.LocalTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IntegerRange (net.dzikoysk.funnyguilds.util.IntegerRange)1 Material (org.bukkit.Material)1