mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 15:16:45 +01:00
Merge pull request #3300 from EasyMFnE/master
Add automatic Alchemy potion colorization and custom color config
This commit is contained in:
commit
eb4960f307
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -166,6 +167,14 @@ public class PotionConfig extends ConfigLoader {
|
||||
}
|
||||
}
|
||||
|
||||
Color color = null;
|
||||
if (potion_section.contains("Color")) {
|
||||
color = Color.fromRGB(potion_section.getInt("Color"));
|
||||
}
|
||||
else {
|
||||
color = this.generateColor(effects);
|
||||
}
|
||||
|
||||
Map<ItemStack, String> children = new HashMap<ItemStack, String>();
|
||||
if (potion_section.contains("Children")) {
|
||||
for (String child : potion_section.getConfigurationSection("Children").getKeys(false)) {
|
||||
@ -179,7 +188,7 @@ public class PotionConfig extends ConfigLoader {
|
||||
}
|
||||
}
|
||||
|
||||
return new AlchemyPotion(material, data, name, lore, effects, children);
|
||||
return new AlchemyPotion(material, data, name, lore, effects, color, children);
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().warning("Failed to load Alchemy potion: " + potion_section.getName());
|
||||
@ -251,4 +260,36 @@ public class PotionConfig extends ConfigLoader {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Color generateColor(List<PotionEffect> effects) {
|
||||
if (effects != null && !effects.isEmpty()) {
|
||||
List<Color> colors = new ArrayList<Color>();
|
||||
for (PotionEffect effect : effects) {
|
||||
if (effect.getType().getColor() != null) {
|
||||
colors.add(effect.getType().getColor());
|
||||
}
|
||||
}
|
||||
if (!colors.isEmpty()) {
|
||||
if (colors.size() > 1) {
|
||||
return calculateAverageColor(colors);
|
||||
}
|
||||
return colors.get(0);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Color calculateAverageColor(List<Color> colors) {
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
int blue = 0;
|
||||
for (Color color : colors) {
|
||||
red += color.getRed();
|
||||
green += color.getGreen();
|
||||
blue += color.getBlue();
|
||||
}
|
||||
Color color = Color.fromRGB(red/colors.size(), green/colors.size(), blue/colors.size());
|
||||
return color;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
@ -19,15 +20,17 @@ public class AlchemyPotion {
|
||||
private String name;
|
||||
private List<String> lore;
|
||||
private List<PotionEffect> effects;
|
||||
private Color color;
|
||||
private Map<ItemStack, String> children;
|
||||
|
||||
public AlchemyPotion(Material material, PotionData data, String name, List<String> lore, List<PotionEffect> effects, Map<ItemStack, String> children) {
|
||||
public AlchemyPotion(Material material, PotionData data, String name, List<String> lore, List<PotionEffect> effects, Color color, Map<ItemStack, String> children) {
|
||||
this.material = material;
|
||||
this.data = data;
|
||||
this.lore = lore;
|
||||
this.name = name;
|
||||
this.effects = effects;
|
||||
this.children = children;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@ -53,6 +56,10 @@ public class AlchemyPotion {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getColor() != null) {
|
||||
meta.setColor(this.getColor());
|
||||
}
|
||||
|
||||
potion.setItemMeta(meta);
|
||||
return potion;
|
||||
}
|
||||
@ -97,6 +104,14 @@ public class AlchemyPotion {
|
||||
this.effects = effects;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Map<ItemStack, String> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ Concoctions:
|
||||
# Name: <name> Custom display name for this potion (optional)
|
||||
# Material: <material> Material for this potion, defaults to POTION
|
||||
# Data: <data_value> Data value for this potion (if this is not present it will read from identifier)
|
||||
# Color: <color> Custom color for the potion in RGB integer (e.g. 0xFF000, optional)
|
||||
# Lore: ["lore1","lore2"...] Custom lore for this potion (section is optional)
|
||||
# Children: The potential children of this potion (section is optional)
|
||||
# <INGREDIENT>: <NEW_IDENTIFIER> The ingredient used, and resultant potion's identifier
|
||||
|
Loading…
Reference in New Issue
Block a user