use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class Wand method loadProperties.
@Override
public void loadProperties() {
super.loadProperties();
locked = getBoolean("locked", locked);
lockedAllowUpgrades = getBoolean("locked_allow_upgrades", false);
consumeReduction = getFloat("consume_reduction");
cooldownReduction = getFloat("cooldown_reduction");
costReduction = getFloat("cost_reduction");
power = getFloat("power");
ConfigurationSection protectionConfig = getConfigurationSection("protection");
if (protectionConfig == null && hasProperty("protection")) {
migrateProtection("protection", "overall");
migrateProtection("protection_physical", "physical");
migrateProtection("protection_projectiles", "projectile");
migrateProtection("protection_falling", "fall");
migrateProtection("protection_fire", "fire");
migrateProtection("protection_explosions", "explosion");
protectionConfig = getConfigurationSection("protection");
}
if (protectionConfig != null) {
protection = new HashMap<>();
for (String protectionKey : protectionConfig.getKeys(false)) {
protection.put(protectionKey, protectionConfig.getDouble(protectionKey));
}
}
hasId = getBoolean("unique", false);
blockChance = getFloat("block_chance");
blockReflectChance = getFloat("block_reflect_chance");
blockFOV = getFloat("block_fov");
blockMageCooldown = getInt("block_mage_cooldown");
blockCooldown = getInt("block_cooldown");
manaPerDamage = getFloat("mana_per_damage");
spMultiplier = getFloat("sp_multiplier", 1);
String singleClass = getString("class");
if (singleClass != null && !singleClass.isEmpty()) {
mageClassKeys = new ArrayList<>();
mageClassKeys.add(singleClass);
} else {
mageClassKeys = getStringList("classes");
}
// Check for single-use wands
uses = getInt("uses");
hasUses = uses > 0;
// Convert some legacy properties to potion effects
float healthRegeneration = getFloat("health_regeneration", 0);
float hungerRegeneration = getFloat("hunger_regeneration", 0);
float speedIncrease = getFloat("haste", 0);
if (speedIncrease > 0) {
potionEffects.put(PotionEffectType.SPEED, 1);
}
if (healthRegeneration > 0) {
potionEffects.put(PotionEffectType.REGENERATION, 1);
}
if (hungerRegeneration > 0) {
potionEffects.put(PotionEffectType.SATURATION, 1);
}
// This overrides the value loaded in CasterProperties
if (!regenWhileInactive) {
setProperty("mana_timestamp", System.currentTimeMillis());
}
if (hasProperty("effect_color")) {
setEffectColor(getString("effect_color"));
}
id = getString("id");
isUpgrade = getBoolean("upgrade");
quietLevel = getInt("quiet");
effectBubbles = getBoolean("effect_bubbles");
keep = getBoolean("keep");
passive = getBoolean("passive");
indestructible = getBoolean("indestructible");
superPowered = getBoolean("powered");
superProtected = getBoolean("protected");
glow = getBoolean("glow");
undroppable = getBoolean("undroppable");
isHeroes = getBoolean("heroes");
bound = getBoolean("bound");
forceUpgrade = getBoolean("force");
autoOrganize = getBoolean("organize");
autoAlphabetize = getBoolean("alphabetize");
autoFill = getBoolean("fill");
rename = getBoolean("rename");
renameDescription = getBoolean("rename_description");
enchantCount = getInt("enchant_count");
maxEnchantCount = getInt("max_enchant_count");
inventoryRows = getInt("inventory_rows", 5);
if (inventoryRows <= 0)
inventoryRows = 1;
if (hasProperty("effect_particle")) {
effectParticle = ConfigurationUtils.toParticleEffect(getString("effect_particle"));
effectParticleData = 0;
} else {
effectParticle = null;
}
if (hasProperty("effect_sound")) {
effectSound = ConfigurationUtils.toSoundEffect(getString("effect_sound"));
} else {
effectSound = null;
}
activeEffectsOnly = getBoolean("active_effects");
effectParticleData = getFloat("effect_particle_data");
effectParticleCount = getInt("effect_particle_count");
effectParticleRadius = getDouble("effect_particle_radius");
effectParticleOffset = getDouble("effect_particle_offset");
effectParticleInterval = getInt("effect_particle_interval");
effectParticleMinVelocity = getDouble("effect_particle_min_velocity");
effectSoundInterval = getInt("effect_sound_interval");
castLocation = getVector("cast_location");
castInterval = getInt("cast_interval");
castMinVelocity = getDouble("cast_min_velocity");
castVelocityDirection = getVector("cast_velocity_direction");
castSpell = getString("cast_spell");
String castParameterString = getString("cast_parameters", null);
if (castParameterString != null && !castParameterString.isEmpty()) {
castParameters = new MemoryConfiguration();
ConfigurationUtils.addParameters(StringUtils.split(castParameterString, ' '), castParameters);
} else {
castParameters = null;
}
WandMode newMode = parseWandMode(getString("mode"), controller.getDefaultWandMode());
if (newMode != mode) {
if (isInventoryOpen()) {
closeInventory();
}
mode = newMode;
}
brushMode = parseWandMode(getString("brush_mode"), controller.getDefaultBrushMode());
// Backwards compatibility
if (getBoolean("mode_drop", false)) {
dropAction = WandAction.TOGGLE;
swapAction = WandAction.CYCLE_HOTBAR;
rightClickAction = WandAction.NONE;
quickCast = true;
// This is to turn the redundant spell lore off
quickCastDisabled = true;
manualQuickCastDisabled = false;
} else if (mode == WandMode.CAST) {
leftClickAction = WandAction.CAST;
rightClickAction = WandAction.CAST;
swapAction = WandAction.NONE;
dropAction = WandAction.NONE;
} else if (mode == WandMode.CYCLE) {
leftClickAction = WandAction.CAST;
rightClickAction = WandAction.NONE;
swapAction = WandAction.NONE;
dropAction = WandAction.CYCLE;
} else {
leftClickAction = WandAction.NONE;
rightClickAction = WandAction.NONE;
dropAction = WandAction.NONE;
swapAction = WandAction.NONE;
quickCast = false;
quickCastDisabled = false;
manualQuickCastDisabled = false;
}
String quickCastType = getString("quick_cast", getString("mode_cast"));
if (quickCastType != null) {
if (quickCastType.equalsIgnoreCase("true")) {
quickCast = true;
// This is to turn the redundant spell lore off
quickCastDisabled = true;
manualQuickCastDisabled = false;
} else if (quickCastType.equalsIgnoreCase("manual")) {
quickCast = false;
quickCastDisabled = true;
manualQuickCastDisabled = false;
} else if (quickCastType.equalsIgnoreCase("disable")) {
quickCast = false;
quickCastDisabled = true;
manualQuickCastDisabled = true;
} else {
quickCast = false;
quickCastDisabled = false;
manualQuickCastDisabled = false;
}
}
leftClickAction = parseWandAction(getString("left_click"), leftClickAction);
rightClickAction = parseWandAction(getString("right_click"), rightClickAction);
dropAction = parseWandAction(getString("drop"), dropAction);
swapAction = parseWandAction(getString("swap"), swapAction);
owner = getString("owner");
ownerId = getString("owner_id");
template = getString("template");
upgradeTemplate = getString("upgrade_template");
path = getString("path");
activeSpell = getString("active_spell");
if (activeSpell != null && activeSpell.contains("|")) {
SpellKey activeKey = new SpellKey(activeSpell);
activeSpell = activeKey.getBaseKey();
setProperty("active_spell", activeSpell);
}
alternateSpell = getString("alternate_spell");
alternateSpell2 = getString("alternate_spell2");
activeBrush = getString("active_brush", getString("active_material"));
if (hasProperty("hotbar")) {
currentHotbar = getInt("hotbar");
}
if (hasProperty("page")) {
int page = getInt("page");
if (page != openInventoryPage) {
openInventoryPage = page;
}
}
// Default to template names, override with localizations and finally with wand data
wandName = controller.getMessages().get("wand.default_name");
description = "";
// Check for migration information in the template config
ConfigurationSection templateConfig = null;
if (template != null && !template.isEmpty()) {
templateConfig = controller.getWandTemplateConfiguration(template);
if (templateConfig != null) {
wandName = templateConfig.getString("name", wandName);
description = templateConfig.getString("description", description);
int templateUses = templateConfig.getInt("uses");
isSingleUse = templateUses == 1;
hasUses = hasUses || templateUses > 0;
}
wandName = controller.getMessages().get("wands." + template + ".name", wandName);
description = controller.getMessages().get("wands." + template + ".description", description);
}
wandName = getString("name", wandName);
description = getString("description", description);
WandTemplate wandTemplate = getTemplate();
// Add vanilla attributes
InventoryUtils.applyAttributes(item, getConfigurationSection("item_attributes"), getString("item_attribute_slot", getString("attribute_slot")));
// Add unstashable and unmoveable tags
if (getBoolean("unstashable") || (undroppable && Unstashable)) {
InventoryUtils.setMetaBoolean(item, "unstashable", true);
} else {
InventoryUtils.removeMeta(item, "unstashable");
}
if (getBoolean("unmoveable")) {
InventoryUtils.setMetaBoolean(item, "unmoveable", true);
} else {
InventoryUtils.removeMeta(item, "unmoveable");
}
if (undroppable) {
InventoryUtils.setMetaBoolean(item, "undroppable", true);
} else {
InventoryUtils.removeMeta(item, "undroppable");
}
if (keep) {
InventoryUtils.setMetaBoolean(item, "keep", true);
} else {
InventoryUtils.removeMeta(item, "keep");
}
// Add vanilla enchantments
ConfigurationSection enchantments = getConfigurationSection("enchantments");
InventoryUtils.applyEnchantments(item, enchantments);
// Add enchantment glow
if (enchantments == null || enchantments.getKeys(false).isEmpty()) {
if (glow) {
CompatibilityUtils.addGlow(item);
} else {
CompatibilityUtils.removeGlow(item);
}
}
if (hasProperty("icon_inactive")) {
String iconKey = getString("icon_inactive");
if (wandTemplate != null) {
iconKey = wandTemplate.migrateIcon(iconKey);
}
if (iconKey != null) {
inactiveIcon = new MaterialAndData(iconKey);
}
} else {
inactiveIcon = null;
}
if (inactiveIcon != null && (inactiveIcon.getMaterial() == null || inactiveIcon.getMaterial() == Material.AIR)) {
inactiveIcon = null;
}
inactiveIconDelay = getInt("icon_inactive_delay");
randomizeOnActivate = randomizeOnActivate && hasProperty("randomize_icon");
if (randomizeOnActivate) {
String randomizeIcon = getString("randomize_icon");
setIcon(new MaterialAndData(randomizeIcon));
if (item == null) {
controller.getLogger().warning("Invalid randomize_icon in wand '" + template + "' config: " + randomizeIcon);
}
} else if (hasProperty("icon")) {
String iconKey = getString("icon");
if (wandTemplate != null) {
iconKey = wandTemplate.migrateIcon(iconKey);
}
if (iconKey.contains(",")) {
Random r = new Random();
String[] keys = StringUtils.split(iconKey, ',');
iconKey = keys[r.nextInt(keys.length)];
}
// Port old custom wand icons
if (templateConfig != null && iconKey.contains("i.imgur.com")) {
iconKey = templateConfig.getString("icon");
}
setIcon(new MaterialAndData(iconKey));
if (item == null) {
controller.getLogger().warning("Invalid icon in wand '" + template + "' config: " + iconKey);
}
updateIcon();
} else if (isUpgrade) {
setIcon(new MaterialAndData(DefaultUpgradeMaterial));
} else {
setIcon(new MaterialAndData(DefaultWandMaterial));
}
if (hasProperty("upgrade_icon")) {
upgradeIcon = new MaterialAndData(getString("upgrade_icon"));
}
// Check for path-based migration, may update icons
com.elmakers.mine.bukkit.api.wand.WandUpgradePath upgradePath = getPath();
if (upgradePath != null) {
hasSpellProgression = upgradePath.getSpells().size() > 0 || upgradePath.getExtraSpells().size() > 0 || upgradePath.getRequiredSpells().size() > 0;
upgradePath.checkMigration(this);
} else {
hasSpellProgression = false;
}
if (isHeroes) {
hasSpellProgression = true;
}
brushInventory.clear();
spellInventory.clear();
limitSpellsToPath = getBoolean("limit_spells_to_path");
limitBrushesToPath = getBoolean("limit_brushes_to_path");
loadSpells();
// Load spell levels
Object spellLevelsRaw = getObject("spell_levels");
if (spellLevelsRaw != null) {
// Not sure this will ever appear as a Map, but just in case
if (spellLevelsRaw instanceof Map) {
@SuppressWarnings("unchecked") Map<String, Integer> spellLevels = (Map<String, Integer>) spellLevelsRaw;
loadSpellLevels(spellLevels);
} else if (spellLevelsRaw instanceof ConfigurationSection) {
loadSpellLevels(NMSUtils.getMap((ConfigurationSection) spellLevelsRaw));
}
}
checkActiveSpell();
loadBrushes();
Object brushInventoryRaw = getObject("brush_inventory");
if (brushInventoryRaw != null) {
// Not sure this will ever appear as a Map, but just in case
if (brushInventoryRaw instanceof Map) {
@SuppressWarnings("unchecked") Map<String, Integer> brushInventory = (Map<String, Integer>) brushInventoryRaw;
loadBrushInventory(brushInventory);
} else if (brushInventoryRaw instanceof ConfigurationSection) {
loadBrushInventory(NMSUtils.getMap((ConfigurationSection) brushInventoryRaw));
}
}
Object spellInventoryRaw = getObject("spell_inventory");
if (spellInventoryRaw != null) {
// Not sure this will ever appear as a Map, but just in case
if (spellInventoryRaw instanceof Map) {
@SuppressWarnings("unchecked") Map<String, Integer> spellInventory = (Map<String, Integer>) spellInventoryRaw;
loadSpellInventory(spellInventory);
} else if (spellInventoryRaw instanceof ConfigurationSection) {
loadSpellInventory(NMSUtils.getMap((ConfigurationSection) spellInventoryRaw));
}
} else {
// Spells may have contained an inventory from migration or templates with a spell@slot format.
updateSpellInventory();
}
castOverrides = null;
if (hasProperty("overrides")) {
castOverrides = null;
Object overridesGeneric = getObject("overrides");
if (overridesGeneric != null) {
castOverrides = new HashMap<>();
if (overridesGeneric instanceof String) {
String overrides = (String) overridesGeneric;
if (!overrides.isEmpty()) {
// Support YML-List-As-String format
// May not really need this anymore.
overrides = overrides.replaceAll("[\\]\\[]", "");
String[] pairs = StringUtils.split(overrides, ',');
for (String override : pairs) {
parseOverride(override);
}
}
} else if (overridesGeneric instanceof List) {
@SuppressWarnings("unchecked") List<String> overrideList = (List<String>) overridesGeneric;
for (String override : overrideList) {
parseOverride(override);
}
} else if (overridesGeneric instanceof ConfigurationSection) {
ConfigurationSection overridesSection = (ConfigurationSection) overridesGeneric;
Set<String> keys = overridesSection.getKeys(true);
for (String key : keys) {
Object leaf = overridesSection.get(key);
if (!(leaf instanceof ConfigurationSection) && !(leaf instanceof Map)) {
castOverrides.put(key, leaf.toString());
}
}
}
}
}
potionEffects.clear();
if (hasProperty("potion_effects")) {
addPotionEffects(potionEffects, getString("potion_effects", null));
}
// so try to keep defaults as 0/0.0/false.
if (effectSound == null) {
effectSoundInterval = 0;
} else {
effectSoundInterval = (effectSoundInterval == 0) ? 5 : effectSoundInterval;
}
if (effectParticle == null) {
effectParticleInterval = 0;
}
checkActiveMaterial();
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class Wand method updateSlot.
protected boolean updateSlot(int slot, ItemStack item) {
if (item == null || item.getType() == Material.AIR)
return true;
String spellKey = getSpell(item);
if (spellKey != null) {
SpellKey key = new SpellKey(spellKey);
spellInventory.put(key.getBaseKey(), slot);
} else {
String brushKey = getBrush(item);
if (brushKey != null) {
brushInventory.put(brushKey, slot);
} else if (mage != null) {
// Must have been an item inserted directly into player's inventory?
mage.giveItem(item);
return false;
}
}
return true;
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class Wand method removeSpell.
@Override
public boolean removeSpell(String spellName) {
if (!isModifiable())
return false;
if (!super.removeSpell(spellName))
return false;
SpellKey spellKey = new SpellKey(spellName);
saveInventory();
if (activeSpell != null) {
SpellKey activeKey = new SpellKey(activeSpell);
if (spellKey.getBaseKey().equals(activeKey.getBaseKey())) {
setActiveSpell(null);
}
}
clearSlot(spellInventory.get(spellKey.getBaseKey()));
spells.remove(spellKey.getBaseKey());
spellLevels.remove(spellKey.getBaseKey());
spellInventory.remove(spellKey.getBaseKey());
if (activeSpell == null && spells.size() > 0) {
setActiveSpell(spells.iterator().next());
}
checkSpellLevelsAndInventory();
updateInventory();
updateHasInventory();
updateSpellInventory();
saveState();
updateName();
updateLore();
return true;
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class Wand method addItem.
@Override
public boolean addItem(ItemStack item) {
if (isUpgrade)
return false;
if (isModifiable() && isSpell(item) && !isSkill(item)) {
String spell = getSpell(item);
SpellKey spellKey = new SpellKey(spell);
Integer currentLevel = spellLevels.get(spellKey.getBaseKey());
if ((currentLevel == null || currentLevel < spellKey.getLevel()) && addSpell(spell)) {
return true;
}
} else if (isModifiable() && isBrush(item)) {
String materialKey = getBrush(item);
Set<String> materials = getBrushes();
if (!materials.contains(materialKey) && addBrush(materialKey)) {
return true;
}
} else if (isUpgrade(item)) {
Wand wand = controller.getWand(item);
return this.add(wand);
}
if (mage != null && !mage.isAtMaxSkillPoints() && controller.skillPointItemsEnabled()) {
Integer sp = getSP(item);
if (sp != null) {
int amount = (int) Math.floor(mage.getSPMultiplier() * sp * item.getAmount());
mage.addSkillPoints(amount);
return true;
}
}
return false;
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class Wand method forceAddSpell.
@Override
public boolean forceAddSpell(String spellName) {
if (!super.addSpell(spellName)) {
return false;
}
saveInventory();
SpellTemplate template = controller.getSpellTemplate(spellName);
ItemStack spellItem = createSpellIcon(template);
if (spellItem == null) {
return false;
}
SpellKey spellKey = template.getSpellKey();
int level = spellKey.getLevel();
int inventoryCount = inventories.size();
int spellCount = spells.size();
// Look for existing spells for spell upgrades
Integer inventorySlot = spellInventory.get(spellKey.getBaseKey());
SpellTemplate currentSpell = getBaseSpell(spellKey);
clearSlot(inventorySlot);
setSpellLevel(spellKey.getBaseKey(), level);
spells.add(spellKey.getBaseKey());
if (activeSpell == null || activeSpell.isEmpty()) {
setActiveSpell(spellKey.getBaseKey());
}
addToInventory(spellItem, inventorySlot);
checkSpellLevelsAndInventory();
updateInventory();
updateHasInventory();
saveState();
updateLore();
if (mage != null) {
if (spells.size() != spellCount) {
if (spellCount == 0) {
if (leftClickAction == WandAction.CAST) {
String message = getMessage("spell_instructions", "").replace("$wand", getName());
mage.sendMessage(message.replace("$spell", template.getName()));
}
} else if (spellCount == 1) {
String controlKey = getControlKey(WandAction.TOGGLE);
String inventoryMessage = null;
switch(getMode()) {
case INVENTORY:
inventoryMessage = "inventory_instructions";
break;
case CHEST:
inventoryMessage = "chest_instructions";
break;
case SKILLS:
inventoryMessage = "skills_instructions";
break;
case CYCLE:
inventoryMessage = "cycle_instructions";
if (controlKey == null) {
controlKey = getControlKey(WandAction.CYCLE);
}
break;
case CAST:
case NONE:
// Ignore
break;
}
if (controlKey != null && inventoryMessage != null) {
controlKey = controller.getMessages().get("controls." + controlKey);
mage.sendMessage(getMessage(inventoryMessage, "").replace("$wand", getName()).replace("$toggle", controlKey).replace("$cycle", controlKey));
}
}
if (inventoryCount == 1 && inventories.size() > 1) {
mage.sendMessage(getMessage("page_instructions", "").replace("$wand", getName()));
}
}
}
return true;
}
Aggregations