benedict.zhang.addon.roleplaying.model.SpellConfiguration.java Source code

Java tutorial

Introduction

Here is the source code for benedict.zhang.addon.roleplaying.model.SpellConfiguration.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package benedict.zhang.addon.roleplaying.model;

import benedict.zhang.addon.roleplaying.core.datatype.SpellCast;
import benedict.zhang.addon.roleplaying.core.datatype.SpellCooldown;
import benedict.zhang.addon.roleplaying.core.datatype.UnitAura;
import benedict.zhang.addon.roleplaying.core.factory.RolePlayingConfigurationFactory;
import java.lang.reflect.InvocationTargetException;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import org.apache.commons.beanutils.BeanUtils;
import org.h2.util.StringUtils;

/**
 *
 * @author bzhang097
 */
public class SpellConfiguration {

    private String id;

    private SimpleStringProperty spellName;

    private SimpleBooleanProperty spellCastAvailable;
    private SimpleStringProperty spellCastLockTimeGlobal;
    private SimpleStringProperty spellCastLockTimeSelf;
    private SimpleStringProperty spellCastSoundName;

    private SimpleBooleanProperty spellCooldownAvailable;
    private SimpleStringProperty spellCooldownLockTimeGlobal;
    private SimpleStringProperty spellCooldownLockTimeSelf;
    private SimpleStringProperty spellCooldownReminderBefore;
    private SimpleStringProperty spellCooldownSoundName;

    private SimpleBooleanProperty unitAuraAvailable;
    private SimpleStringProperty unitAuraLockTimeGlobal;
    private SimpleStringProperty unitAuraLockTimeSelf;
    private SimpleStringProperty unitAuraSoundName;

    private RolePlayingConfiguration roleplayingConfig;

    public SpellConfiguration() {
        this.spellName = new SimpleStringProperty("");
        this.spellCastAvailable = new SimpleBooleanProperty(false);
        this.spellCooldownAvailable = new SimpleBooleanProperty(false);
        this.unitAuraAvailable = new SimpleBooleanProperty(false);
        this.spellCastLockTimeGlobal = new SimpleStringProperty("3");
        this.spellCastLockTimeSelf = new SimpleStringProperty("3");
        this.spellCastSoundName = new SimpleStringProperty("Not Selected");
        this.spellCooldownLockTimeGlobal = new SimpleStringProperty("3");
        this.spellCooldownLockTimeSelf = new SimpleStringProperty("3");
        this.spellCooldownReminderBefore = new SimpleStringProperty("5");
        this.spellCooldownSoundName = new SimpleStringProperty("Not Selected");
        this.unitAuraLockTimeGlobal = new SimpleStringProperty("3");
        this.unitAuraLockTimeSelf = new SimpleStringProperty("3");
        this.unitAuraSoundName = new SimpleStringProperty("Not Selected");
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Boolean getSpellCastAvailable() {
        return spellCastAvailable.get();
    }

    public String getSpellCastLockTimeGlobal() {
        return spellCastLockTimeGlobal.get();
    }

    public String getSpellCastLockTimeSelf() {
        return spellCastLockTimeSelf.get();
    }

    public Boolean getSpellCooldownAvailable() {
        return spellCooldownAvailable.get();
    }

    public String getSpellCooldownLockTimeGlobal() {
        return spellCooldownLockTimeGlobal.get();
    }

    public String getSpellCooldownLockTimeSelf() {
        return spellCooldownLockTimeSelf.get();
    }

    public String getSpellCooldownReminderBefore() {
        return spellCooldownReminderBefore.get();
    }

    public Boolean getUnitAuraAvailable() {
        return unitAuraAvailable.get();
    }

    public String getUnitAuraLockTimeGlobal() {
        return unitAuraLockTimeGlobal.get();
    }

    public String getUnitAuraLockTimeSelf() {
        return unitAuraLockTimeSelf.get();
    }

    public void setSpellCastAvailable(Boolean spellCastAvailable) {
        this.spellCastAvailable.set(spellCastAvailable);
    }

    public void setSpellCastLockTimeGlobal(String spellCastLockTimeGlobal) {
        this.spellCastLockTimeGlobal.set(spellCastLockTimeGlobal);
    }

    public void setSpellCastLockTimeSelf(String spellCastLockTimeSelf) {
        this.spellCastLockTimeSelf.set(spellCastLockTimeSelf);
    }

    public void setSpellCooldownAvailable(Boolean spellCooldownAvailable) {
        this.spellCooldownAvailable.set(spellCooldownAvailable);
    }

    public void setSpellCooldownLockTimeGlobal(String spellCooldownLockTimeGlobal) {
        this.spellCooldownLockTimeGlobal.set(spellCooldownLockTimeGlobal);
    }

    public void setSpellCooldownLockTimeSelf(String spellCooldownLockTimeSelf) {
        this.spellCooldownLockTimeSelf.set(spellCooldownLockTimeSelf);
    }

    public void setSpellCooldownReminderBefore(String spellCooldownReminderBefore) {
        this.spellCooldownReminderBefore.set(spellCooldownReminderBefore);
    }

    public void setUnitAuraAvailable(Boolean unitAuraAvailable) {
        this.unitAuraAvailable.set(unitAuraAvailable);
    }

    public void setUnitAuraLockTimeGlobal(String unitAuraLockTimeGlobal) {
        this.unitAuraLockTimeGlobal.set(unitAuraLockTimeGlobal);
    }

    public void setUnitAuraLockTimeSelf(String unitAuraLockTimeSelf) {
        this.unitAuraLockTimeSelf.set(unitAuraLockTimeSelf);
    }

    public String getSpellName() {
        return spellName.get();
    }

    public void setSpellName(String spellName) {
        this.spellName.set(spellName);
    }

    public String getSpellCastSoundName() {
        return spellCastSoundName.get();
    }

    public void setSpellCastSoundName(String spellCastSoundName) {
        if (StringUtils.isNullOrEmpty(spellCastSoundName)) {
            this.spellCastSoundName.set("Not Selected");
            return;
        }
        this.spellCastSoundName.set(spellCastSoundName);
    }

    public String getSpellCooldownSoundName() {
        return spellCooldownSoundName.get();
    }

    public void setSpellCooldownSoundName(String spellCooldownSoundName) {
        if (StringUtils.isNullOrEmpty(spellCooldownSoundName)) {
            this.spellCooldownSoundName.set("Not Selected");
            return;
        }
        this.spellCooldownSoundName.set(spellCooldownSoundName);
    }

    public String getUnitAuraSoundName() {
        return unitAuraSoundName.get();
    }

    public void setUnitAuraSoundName(String unitAuraSoundName) {
        if (StringUtils.isNullOrEmpty(unitAuraSoundName)) {
            this.unitAuraSoundName.set("Not Selected");
            return;
        }
        this.unitAuraSoundName.set(unitAuraSoundName);
    }

    public SimpleStringProperty SpellName() {
        return spellName;
    }

    public SimpleBooleanProperty SpellCastAvailable() {
        return spellCastAvailable;
    }

    public SimpleStringProperty SpellCastLockTimeGlobal() {
        return spellCastLockTimeGlobal;
    }

    public SimpleStringProperty SpellCastLockTimeSelf() {
        return spellCastLockTimeSelf;
    }

    public SimpleStringProperty SpellCastSoundName() {
        return spellCastSoundName;
    }

    public SimpleBooleanProperty SpellCooldownAvailable() {
        return spellCooldownAvailable;
    }

    public SimpleStringProperty SpellCooldownLockTimeGlobal() {
        return spellCooldownLockTimeGlobal;
    }

    public SimpleStringProperty SpellCooldownLockTimeSelf() {
        return spellCooldownLockTimeSelf;
    }

    public SimpleStringProperty SpellCooldownReminderBefore() {
        return spellCooldownReminderBefore;
    }

    public SimpleStringProperty SpellCooldownSoundName() {
        return spellCooldownSoundName;
    }

    public SimpleBooleanProperty UnitAuraAvailable() {
        return unitAuraAvailable;
    }

    public SimpleStringProperty UnitAuraLockTimeGlobal() {
        return unitAuraLockTimeGlobal;
    }

    public SimpleStringProperty UnitAuraLockTimeSelf() {
        return unitAuraLockTimeSelf;
    }

    public SimpleStringProperty UnitAuraSoundName() {
        return unitAuraSoundName;
    }

    public benedict.zhang.addon.roleplaying.core.datatype.SpellConfiguration toSpellConfiguration() {
        benedict.zhang.addon.roleplaying.core.datatype.SpellConfiguration spellConfiguration = RolePlayingConfigurationFactory
                .getInstance().getSpellConfiguration();

        spellConfiguration.setSpellName(this.getSpellName());

        SpellCast spellCast = spellConfiguration.getSpellCast();
        spellCast.setAvailable(this.getSpellCastAvailable() ? "true" : "false");
        spellCast.setLockTimeGlobal(this.getSpellCastLockTimeGlobal());
        spellCast.setLockTimeSelf(this.getSpellCastLockTimeSelf());
        String soundName = this.getSpellCastSoundName().equals("Not Selected") ? "" : this.getSpellCastSoundName();
        spellCast.setSoundName(soundName);

        SpellCooldown spellCooldown = spellConfiguration.getSpellCooldown();
        spellCooldown.setAvailable(this.getSpellCooldownAvailable() ? "true" : "false");
        spellCooldown.setLockTimeSelf(this.getSpellCooldownLockTimeSelf());
        spellCooldown.setLockTimeGlobal(this.getSpellCooldownLockTimeGlobal());
        spellCooldown.setReminderBefore(this.getSpellCooldownReminderBefore());
        soundName = this.getSpellCooldownSoundName().equals("Not Selected") ? "" : this.getSpellCooldownSoundName();
        spellCooldown.setSoundName(soundName);

        UnitAura unitAura = spellConfiguration.getUnitAura();
        unitAura.setAvailable(this.getUnitAuraAvailable() ? "true" : "false");
        unitAura.setLockTimeGlobal(this.getUnitAuraLockTimeGlobal());
        unitAura.setLockTimeSelf(this.getUnitAuraLockTimeSelf());
        soundName = this.getUnitAuraSoundName().equals("Not Selected") ? "" : this.getUnitAuraSoundName();
        unitAura.setSoundName(soundName);
        return spellConfiguration;
    }

    @Override
    public String toString() {
        return this.getSpellName();
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof SpellConfiguration) {
            if (((SpellConfiguration) o).getSpellName().equals(this.getSpellName())) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 89 * hash + Objects.hashCode(this.spellName);
        return hash;
    }

    public SpellConfiguration create() {
        SpellConfiguration spellConfig = new SpellConfiguration();
        try {
            long start = System.currentTimeMillis();
            BeanUtils.copyProperties(spellConfig, this);
            System.out.println(System.currentTimeMillis() - start);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(SpellConfiguration.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
            Logger.getLogger(SpellConfiguration.class.getName()).log(Level.SEVERE, null, ex);
        }
        return spellConfig;
    }

    public RolePlayingConfiguration getRoleplayingConfig() {
        return roleplayingConfig;
    }

    public void setRoleplayingConfig(RolePlayingConfiguration roleplayingConfig) {
        this.roleplayingConfig = roleplayingConfig;
    }

    public void copySpellConfiguration(SpellConfiguration spellConfig) {
        try {
            BeanUtils.copyProperties(this, spellConfig);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(SpellConfiguration.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
            Logger.getLogger(SpellConfiguration.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}