mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-12-27 20:37:34 +01:00
Added support for custom lore colors
This commit is contained in:
parent
ee258d2d31
commit
2a4ce63e33
@ -4,6 +4,7 @@ import com.willfp.ecoenchants.config.YamlConfig;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,4 +18,40 @@ public class Rarity extends YamlConfig {
|
|||||||
public Set<String> getRarities() {
|
public Set<String> getRarities() {
|
||||||
return config.getConfigurationSection("rarities").getKeys(false);
|
return config.getConfigurationSection("rarities").getKeys(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getInt(String path) {
|
||||||
|
return config.getInt(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInt(String path, int def) {
|
||||||
|
return config.getInt(path, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getInts(String path) {
|
||||||
|
return config.getIntegerList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBool(String path) {
|
||||||
|
return config.getBoolean(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Boolean> getBools(String path) {
|
||||||
|
return config.getBooleanList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String path) {
|
||||||
|
return config.getString(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getStrings(String path) {
|
||||||
|
return config.getStringList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDouble(String path) {
|
||||||
|
return config.getDouble(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Double> getDoubles(String path) {
|
||||||
|
return config.getDoubleList(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
|||||||
import com.willfp.ecoenchants.config.ConfigManager;
|
import com.willfp.ecoenchants.config.ConfigManager;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
|
import com.willfp.ecoenchants.enchantments.EnchantmentRarity;
|
||||||
import com.willfp.ecoenchants.enchantments.EnchantmentTarget;
|
import com.willfp.ecoenchants.enchantments.EnchantmentTarget;
|
||||||
import com.willfp.ecoenchants.util.NumberUtils;
|
import com.willfp.ecoenchants.util.NumberUtils;
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang.WordUtils;
|
||||||
@ -202,6 +203,10 @@ public class EnchantDisplay {
|
|||||||
if(isEcoEnchant) {
|
if(isEcoEnchant) {
|
||||||
name = enchantment.getName();
|
name = enchantment.getName();
|
||||||
description = EcoEnchants.getFromEnchantment(enchantment).getDescription();
|
description = EcoEnchants.getFromEnchantment(enchantment).getDescription();
|
||||||
|
EnchantmentRarity rarity = EcoEnchants.getFromEnchantment(enchantment).getRarity();
|
||||||
|
if(rarity.hasCustomColor()) {
|
||||||
|
color = rarity.getCustomColor();
|
||||||
|
}
|
||||||
description.replaceAll(line -> prefix + descriptionColor + line);
|
description.replaceAll(line -> prefix + descriptionColor + line);
|
||||||
if(!EcoEnchants.getFromEnchantment(enchantment).isEnabled()) forRemoval.add(enchantment);
|
if(!EcoEnchants.getFromEnchantment(enchantment).isEnabled()) forRemoval.add(enchantment);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.enchantments;
|
package com.willfp.ecoenchants.enchantments;
|
||||||
|
|
||||||
import com.willfp.ecoenchants.config.ConfigManager;
|
import com.willfp.ecoenchants.config.ConfigManager;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -17,6 +18,7 @@ public class EnchantmentRarity {
|
|||||||
private final int minimumLevel;
|
private final int minimumLevel;
|
||||||
private final double villagerProbability;
|
private final double villagerProbability;
|
||||||
private final double lootProbability;
|
private final double lootProbability;
|
||||||
|
private final String customColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new EnchantmentRarity
|
* Create new EnchantmentRarity
|
||||||
@ -25,8 +27,9 @@ public class EnchantmentRarity {
|
|||||||
* @param minimumLevel The minimum xp level
|
* @param minimumLevel The minimum xp level
|
||||||
* @param villagerProbability The probability of a villager obtaining an enchantment with this rarity
|
* @param villagerProbability The probability of a villager obtaining an enchantment with this rarity
|
||||||
* @param lootProbability The probability of an item in a loot chest having an enchantment with this rarity
|
* @param lootProbability The probability of an item in a loot chest having an enchantment with this rarity
|
||||||
|
* @param customColor The custom display color, or null if not enabled
|
||||||
*/
|
*/
|
||||||
public EnchantmentRarity(String name, double probability, int minimumLevel, double villagerProbability, double lootProbability) {
|
public EnchantmentRarity(String name, double probability, int minimumLevel, double villagerProbability, double lootProbability, String customColor) {
|
||||||
Optional<EnchantmentRarity> matching = rarities.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
Optional<EnchantmentRarity> matching = rarities.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||||
matching.ifPresent(rarities::remove);
|
matching.ifPresent(rarities::remove);
|
||||||
|
|
||||||
@ -35,6 +38,7 @@ public class EnchantmentRarity {
|
|||||||
this.minimumLevel = minimumLevel;
|
this.minimumLevel = minimumLevel;
|
||||||
this.villagerProbability = villagerProbability;
|
this.villagerProbability = villagerProbability;
|
||||||
this.lootProbability = lootProbability;
|
this.lootProbability = lootProbability;
|
||||||
|
this.customColor = customColor;
|
||||||
|
|
||||||
rarities.add(this);
|
rarities.add(this);
|
||||||
}
|
}
|
||||||
@ -47,6 +51,22 @@ public class EnchantmentRarity {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is custom color enabled
|
||||||
|
* @return If has enabled custom color
|
||||||
|
*/
|
||||||
|
public boolean hasCustomColor() {
|
||||||
|
return this.customColor != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get custom color
|
||||||
|
* @return The custom color
|
||||||
|
*/
|
||||||
|
public String getCustomColor() {
|
||||||
|
return this.customColor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the probability of obtaining enchantment with this rarity from an enchanting table
|
* Get the probability of obtaining enchantment with this rarity from an enchanting table
|
||||||
* @return The probability as a percentage
|
* @return The probability as a percentage
|
||||||
@ -97,12 +117,16 @@ public class EnchantmentRarity {
|
|||||||
Set<String> raritiesNames = ConfigManager.getRarity().getRarities();
|
Set<String> raritiesNames = ConfigManager.getRarity().getRarities();
|
||||||
raritiesNames.forEach((rarity) -> {
|
raritiesNames.forEach((rarity) -> {
|
||||||
String name = rarity;
|
String name = rarity;
|
||||||
double probability = ConfigManager.getConfig().getDouble("rarities." + rarity + ".table-probability");
|
double probability = ConfigManager.getRarity().getDouble("rarities." + rarity + ".table-probability");
|
||||||
int minimumLevel = ConfigManager.getConfig().getInt("rarities." + rarity + ".minimum-level");
|
int minimumLevel = ConfigManager.getRarity().getInt("rarities." + rarity + ".minimum-level");
|
||||||
double villagerProbability = ConfigManager.getConfig().getDouble("rarities." + rarity + ".villager-probability");
|
double villagerProbability = ConfigManager.getRarity().getDouble("rarities." + rarity + ".villager-probability");
|
||||||
double lootProbability = ConfigManager.getConfig().getDouble("rarities." + rarity + ".loot-probability");
|
double lootProbability = ConfigManager.getRarity().getDouble("rarities." + rarity + ".loot-probability");
|
||||||
|
String customColor = null;
|
||||||
|
if(ConfigManager.getRarity().getBool("rarities." + rarity + ".custom-color.enabled")) {
|
||||||
|
customColor = ChatColor.translateAlternateColorCodes('&', ConfigManager.getRarity().getString("rarities." + rarity + ".custom-color.color"));
|
||||||
|
}
|
||||||
|
|
||||||
new EnchantmentRarity(name, probability, minimumLevel, villagerProbability, lootProbability);
|
new EnchantmentRarity(name, probability, minimumLevel, villagerProbability, lootProbability, customColor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import com.willfp.ecoenchants.config.ConfigManager;
|
|||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.util.NumberUtils;
|
import com.willfp.ecoenchants.util.NumberUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.enchantments.EnchantmentOffer;
|
import org.bukkit.enchantments.EnchantmentOffer;
|
||||||
@ -38,6 +39,7 @@ public class EnchantingListeners implements Listener {
|
|||||||
Player player = event.getEnchanter();
|
Player player = event.getEnchanter();
|
||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
int cost = event.getExpLevelCost();
|
int cost = event.getExpLevelCost();
|
||||||
|
|
||||||
Map<Enchantment, Integer> toAdd = event.getEnchantsToAdd();
|
Map<Enchantment, Integer> toAdd = event.getEnchantsToAdd();
|
||||||
if (!ConfigManager.getConfig().getBool("enchanting-table.enabled")) {
|
if (!ConfigManager.getConfig().getBool("enchanting-table.enabled")) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
@ -19,7 +19,7 @@ lore:
|
|||||||
use-numbers-above-threshold: 10 #After level 10, enchantments will display as Name Number, eg: Sharpness 25 instead of Sharpness XXV
|
use-numbers-above-threshold: 10 #After level 10, enchantments will display as Name Number, eg: Sharpness 25 instead of Sharpness XXV
|
||||||
|
|
||||||
describe: # Describe enchantments in lore
|
describe: # Describe enchantments in lore
|
||||||
enabled: true
|
enabled: false
|
||||||
before-lines: 5 # Describe before or equal to number of enchantments
|
before-lines: 5 # Describe before or equal to number of enchantments
|
||||||
wrap: 30 # Word wrap after number of characters
|
wrap: 30 # Word wrap after number of characters
|
||||||
|
|
||||||
|
@ -8,38 +8,63 @@ rarities:
|
|||||||
# Villager probability is the chance of a villager having this trade as a percentage. Vanilla default for all enchantments is 2.7%, however you can choose this per-rarity.
|
# Villager probability is the chance of a villager having this trade as a percentage. Vanilla default for all enchantments is 2.7%, however you can choose this per-rarity.
|
||||||
# Loot probability is the chance of an item in a loot chest having this enchantment as a percentage
|
# Loot probability is the chance of an item in a loot chest having this enchantment as a percentage
|
||||||
|
|
||||||
|
# Custom Color is a custom name color for all enchantments of rarity to have
|
||||||
|
# This is disabled by default.
|
||||||
|
# Curses override this, and always display in their specified color.
|
||||||
|
|
||||||
common:
|
common:
|
||||||
table-probability: 30
|
table-probability: 30
|
||||||
minimum-level: 1
|
minimum-level: 1
|
||||||
villager-probability: 10.5
|
villager-probability: 10.5
|
||||||
loot-probability: 12
|
loot-probability: 12
|
||||||
|
custom-color:
|
||||||
|
enabled: false
|
||||||
|
color: "&7"
|
||||||
uncommon:
|
uncommon:
|
||||||
table-probability: 20
|
table-probability: 20
|
||||||
minimum-level: 5
|
minimum-level: 5
|
||||||
villager-probability: 9
|
villager-probability: 9
|
||||||
loot-probability: 16
|
loot-probability: 16
|
||||||
|
custom-color:
|
||||||
|
enabled: false
|
||||||
|
color: "&e"
|
||||||
rare:
|
rare:
|
||||||
table-probability: 20
|
table-probability: 20
|
||||||
minimum-level: 15
|
minimum-level: 15
|
||||||
villager-probability: 7.5
|
villager-probability: 7.5
|
||||||
loot-probability: 18
|
loot-probability: 18
|
||||||
|
custom-color:
|
||||||
|
enabled: false
|
||||||
|
color: "&a"
|
||||||
epic:
|
epic:
|
||||||
table-probability: 10
|
table-probability: 10
|
||||||
minimum-level: 16
|
minimum-level: 16
|
||||||
villager-probability: 6
|
villager-probability: 6
|
||||||
loot-probability: 20
|
loot-probability: 20
|
||||||
|
custom-color:
|
||||||
|
enabled: false
|
||||||
|
color: "&9"
|
||||||
legendary:
|
legendary:
|
||||||
table-probability: 8
|
table-probability: 8
|
||||||
minimum-level: 20
|
minimum-level: 20
|
||||||
villager-probability: 4.5
|
villager-probability: 4.5
|
||||||
loot-probability: 15
|
loot-probability: 15
|
||||||
|
custom-color:
|
||||||
|
enabled: false
|
||||||
|
color: "&6"
|
||||||
special:
|
special:
|
||||||
table-probability: 2
|
table-probability: 2
|
||||||
minimum-level: 30
|
minimum-level: 30
|
||||||
villager-probability: 3
|
villager-probability: 3
|
||||||
loot-probability: 5
|
loot-probability: 5
|
||||||
|
custom-color:
|
||||||
|
enabled: false
|
||||||
|
color: "&d"
|
||||||
veryspecial:
|
veryspecial:
|
||||||
table-probability: 1
|
table-probability: 1
|
||||||
minimum-level: 30
|
minimum-level: 30
|
||||||
villager-probability: 1.5
|
villager-probability: 1.5
|
||||||
loot-probability: 2
|
loot-probability: 2
|
||||||
|
custom-color:
|
||||||
|
enabled: false
|
||||||
|
color: "&5"
|
Loading…
Reference in New Issue
Block a user