use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class RequirementManager method load.
public void load() {
FileConfiguration config = plugin.getConfig();
this.globalRequirements = new HashSet<>();
for (ModifierType type : ModifierType.values()) {
List<String> list = config.getStringList("requirement." + type.name().toLowerCase(Locale.ENGLISH) + ".global");
for (String text : list) {
String[] splitText = text.split(" ");
Optional<XMaterial> potentialMaterial = XMaterial.matchXMaterial(splitText[0].toUpperCase());
if (potentialMaterial.isPresent()) {
XMaterial material = potentialMaterial.get();
Map<Skill, Integer> requirements = new HashMap<>();
for (int i = 1; i < splitText.length; i++) {
String requirementText = splitText[i];
try {
Skill skill = plugin.getSkillRegistry().getSkill(requirementText.split(":")[0]);
if (skill != null) {
int level = Integer.parseInt(requirementText.split(":")[1]);
requirements.put(skill, level);
}
} catch (Exception e) {
Bukkit.getLogger().warning("[AureliumSkills] Error parsing global skill " + type.name().toLowerCase(Locale.ENGLISH) + " requirement skill level pair with text " + requirementText);
}
}
GlobalRequirement globalRequirement = new GlobalRequirement(type, material, requirements);
globalRequirements.add(globalRequirement);
} else {
Bukkit.getLogger().warning("[AureliumSkills] Error parsing global skill " + type.name().toLowerCase(Locale.ENGLISH) + " requirement material with text " + splitText[0]);
}
}
}
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class Requirements method getRequirements.
public Map<Skill, Integer> getRequirements(ModifierType type, ItemStack item) {
if (isNBTDisabled())
return new HashMap<>();
NBTItem nbtItem = new NBTItem(item);
Map<Skill, Integer> requirements = new HashMap<>();
NBTCompound compound = ItemUtils.getRequirementsTypeCompound(nbtItem, type);
for (String key : compound.getKeys()) {
try {
Skill skill = plugin.getSkillRegistry().getSkill(key);
if (skill != null) {
Integer value = compound.getInteger(key);
requirements.put(skill, value);
}
} catch (Exception ignored) {
}
}
return requirements;
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class SkillItem method load.
@Override
public void load(ConfigurationSection config) {
try {
pos = SlotPos.of(config.getInt("row"), config.getInt("column"));
// Load base items
for (String materialInput : config.getStringList("material")) {
String[] splitInput = materialInput.split(" ", 2);
Skill skill = Skills.valueOf(splitInput[0]);
baseItems.put(skill, MenuLoader.parseItem(splitInput[1]));
}
displayName = TextUtil.replace(Objects.requireNonNull(config.getString("display_name")), "&", "§");
// Load lore
List<String> lore = new ArrayList<>();
Map<Integer, Set<String>> lorePlaceholders = new HashMap<>();
int lineNum = 0;
for (String line : config.getStringList("lore")) {
Set<String> linePlaceholders = new HashSet<>();
lore.add(TextUtil.replace(line, "&", "§"));
// Find lore placeholders
for (String placeholder : definedPlaceholders) {
if (line.contains("{" + placeholder + "}")) {
linePlaceholders.add(placeholder);
}
}
lorePlaceholders.put(lineNum, linePlaceholders);
lineNum++;
}
this.lore = lore;
this.lorePlaceholders = lorePlaceholders;
} catch (Exception e) {
e.printStackTrace();
Bukkit.getLogger().warning("[AureliumSkills] Error parsing item " + itemType.toString() + ", check error above for details!");
}
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class SourceManager method loadSources.
public void loadSources() {
long start = System.currentTimeMillis();
// Create file
File file = new File(plugin.getDataFolder(), "sources_config.yml");
if (!file.exists()) {
plugin.saveResource("sources_config.yml", false);
}
// Load FileConfigurations
FileConfiguration config = updateFile(file, YamlConfiguration.loadConfiguration(file));
// Load sources
int sourcesLoaded = 0;
for (Source source : plugin.getSourceRegistry().values()) {
String path = source.getPath();
// Add if exists
if (config.contains("sources." + path)) {
sources.put(source, config.getDouble("sources." + path));
sourcesLoaded++;
} else // Otherwise add default value and write to config
{
Bukkit.getLogger().warning("[AureliumSkills] sources_config.yml is missing source of path sources." + path + ", value has been set to 0");
sources.put(source, 0.0);
}
}
// Load tags
int tagsLoaded = 0;
for (SourceTag tag : SourceTag.values()) {
String path = tag.getPath();
if (config.contains("tags." + path)) {
List<String> sourceStringList = config.getStringList("tags." + path);
List<Source> sourcesList = new ArrayList<>();
for (String sourceString : sourceStringList) {
if (sourceString.equals("*")) {
// Add all sources in that skill if use * syntax
sourcesList.addAll(Arrays.asList(plugin.getSourceRegistry().values(tag.getSkill())));
} else if (sourceString.startsWith("!")) {
// Remove source if starts with !
Source source = plugin.getSourceRegistry().valueOf(sourceString.substring(1));
if (source != null) {
sourcesList.remove(source);
}
} else {
// Add source
Source source = plugin.getSourceRegistry().valueOf(sourceString);
if (source != null) {
sourcesList.add(source);
}
}
}
tags.put(tag, sourcesList);
tagsLoaded++;
} else {
plugin.getLogger().warning("sources_config.yml is missing tag of path tags." + path + ", tag will be empty");
tags.put(tag, new ArrayList<>());
}
}
// Load custom blocks
customBlocks = new HashMap<>();
customBlockSet = new HashSet<>();
Skill[] customBlockSkills = new Skill[] { Skills.FARMING, Skills.FORAGING, Skills.MINING, Skills.EXCAVATION };
for (Skill skill : customBlockSkills) {
ConfigurationSection section = config.getConfigurationSection("sources." + skill.toString().toLowerCase(Locale.ENGLISH) + ".custom");
if (section != null) {
Map<XMaterial, Double> blockMap = new HashMap<>();
for (String key : section.getKeys(false)) {
double value = section.getDouble(key);
Optional<XMaterial> optionalMaterial = XMaterial.matchXMaterial(key.toUpperCase());
if (optionalMaterial.isPresent()) {
XMaterial material = optionalMaterial.get();
blockMap.put(material, value);
customBlockSet.add(material);
sourcesLoaded++;
} else {
Bukkit.getLogger().warning("[AureliumSkills] Custom block " + key + " is not a valid block!");
}
}
customBlocks.put(skill, blockMap);
}
}
// Load custom mobs
customMobs = new HashMap<>();
customMobSet = new HashSet<>();
Skill[] customMobSkills = new Skill[] { Skills.FIGHTING, Skills.ARCHERY };
for (Skill skill : customMobSkills) {
ConfigurationSection section = config.getConfigurationSection("sources." + skill.toString().toLowerCase(Locale.ENGLISH) + ".custom");
if (section != null) {
Map<String, Double> mobMap = new HashMap<>();
for (String key : section.getKeys(false)) {
double value = section.getDouble(key);
mobMap.put(key, value);
customMobSet.add(key);
sourcesLoaded++;
}
customMobs.put(skill, mobMap);
}
}
Bukkit.getLogger().info("[AureliumSkills] Loaded " + sourcesLoaded + " sources and " + tagsLoaded + " tags in " + (System.currentTimeMillis() - start) + "ms");
}
use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.
the class ArcheryLeveler method onEntityDamage.
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDamage(EntityDamageByEntityEvent event) {
// Damage based listener
if (OptionL.isEnabled(Skills.ARCHERY)) {
if (event.isCancelled())
return;
if (!OptionL.getBoolean(Option.ARCHERY_DAMAGE_BASED))
return;
if (event.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) event.getDamager();
Skill skill = Skills.ARCHERY;
if (projectile instanceof ThrownPotion) {
if (OptionL.getBoolean(Option.ALCHEMY_GIVE_XP_ON_POTION_COMBAT)) {
// Reward alchemy if potion used
skill = Skills.ALCHEMY;
} else {
return;
}
}
if (projectile.getShooter() instanceof Player) {
Player player = (Player) projectile.getShooter();
if (event.getEntity() instanceof LivingEntity) {
LivingEntity entity = (LivingEntity) event.getEntity();
if (blockXpGainLocation(entity.getLocation(), player))
return;
EntityType type = entity.getType();
if (blockXpGainPlayer(player))
return;
if (entity.equals(player))
return;
double health = entity.getHealth();
double damage = Math.min(health, event.getFinalDamage());
// Apply spawner multiplier
if (entity.hasMetadata("aureliumskills_spawner_mob")) {
double spawnerMultiplier = OptionL.getDouble(Option.ARCHERY_SPAWNER_MULTIPLIER);
damage *= spawnerMultiplier;
}
try {
plugin.getLeveler().addXp(player, skill, damage * getXp(player, ArcherySource.valueOf(type.toString())));
} catch (IllegalArgumentException e) {
if (type.toString().equals("PIG_ZOMBIE")) {
plugin.getLeveler().addXp(player, skill, damage * getXp(player, ArcherySource.ZOMBIFIED_PIGLIN));
}
}
}
}
}
}
}
Aggregations