F Perm GUI (#1045)
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
package com.massivecraft.factions.struct;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.zcore.fperms.Permissable;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public enum Relation implements Permissable {
|
||||
@@ -21,11 +29,6 @@ public enum Relation implements Permissable {
|
||||
this.nicename = nicename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.nicename;
|
||||
}
|
||||
|
||||
public static Relation fromString(String s) {
|
||||
// Because Java 6 doesn't allow String switches :(
|
||||
if (s.equalsIgnoreCase(MEMBER.nicename)) {
|
||||
@@ -41,6 +44,11 @@ public enum Relation implements Permissable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.nicename;
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
try {
|
||||
return TL.valueOf("RELATION_" + name() + "_SINGULAR").toString();
|
||||
@@ -184,4 +192,42 @@ public enum Relation implements Permissable {
|
||||
return Conf.econCostNeutral;
|
||||
}
|
||||
}
|
||||
|
||||
// Utility method to build items for F Perm GUI
|
||||
@Override
|
||||
public ItemStack buildItem() {
|
||||
final ConfigurationSection RELATION_CONFIG = P.p.getConfig().getConfigurationSection("fperm-gui.relation");
|
||||
|
||||
String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", ""));
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
Material material = Material.matchMaterial(RELATION_CONFIG.getString("materials." + name().toLowerCase()));
|
||||
if (material == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
|
||||
for (String loreLine : RELATION_CONFIG.getStringList("placeholder-item.lore")) {
|
||||
lore.add(replacePlaceholders(loreLine));
|
||||
}
|
||||
|
||||
itemMeta.setDisplayName(displayName);
|
||||
itemMeta.setLore(lore);
|
||||
item.setItemMeta(itemMeta);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public String replacePlaceholders(String string) {
|
||||
string = ChatColor.translateAlternateColorCodes('&', string);
|
||||
|
||||
String permissableName = nicename.substring(0, 1).toUpperCase() + nicename.substring(1);
|
||||
|
||||
string = string.replace("{relation-color}", getColor().toString());
|
||||
string = string.replace("{relation}", permissableName);
|
||||
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user