mirror of
https://github.com/MassiveCraft/Factions.git
synced 2025-02-22 14:51:32 +01:00
Add Placeholder support to GUI titles... (#6)
* Add Player and Faction placeholders * Add PlaceholderAPI Support
This commit is contained in:
parent
56ad88840f
commit
f9a878246b
@ -1,9 +1,11 @@
|
||||
package com.massivecraft.factions.struct;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.zcore.fperms.Permissable;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import com.massivecraft.factions.zcore.util.TagUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -196,10 +198,10 @@ public enum Relation implements Permissable {
|
||||
|
||||
// Utility method to build items for F Perm GUI
|
||||
@Override
|
||||
public ItemStack buildItem() {
|
||||
public ItemStack buildItem(FPlayer fme) {
|
||||
final ConfigurationSection RELATION_CONFIG = P.p.getConfig().getConfigurationSection("fperm-gui.relation");
|
||||
|
||||
String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", ""));
|
||||
String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", ""), fme);
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
Material material = Material.matchMaterial(RELATION_CONFIG.getString("materials." + name().toLowerCase()));
|
||||
@ -211,7 +213,7 @@ public enum Relation implements Permissable {
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
|
||||
for (String loreLine : RELATION_CONFIG.getStringList("placeholder-item.lore")) {
|
||||
lore.add(replacePlaceholders(loreLine));
|
||||
lore.add(replacePlaceholders(loreLine, fme));
|
||||
}
|
||||
|
||||
itemMeta.setDisplayName(displayName);
|
||||
@ -222,8 +224,10 @@ public enum Relation implements Permissable {
|
||||
return item;
|
||||
}
|
||||
|
||||
public String replacePlaceholders(String string) {
|
||||
public String replacePlaceholders(String string, FPlayer fme) {
|
||||
string = ChatColor.translateAlternateColorCodes('&', string);
|
||||
string = TagUtil.parsePlain(fme, string);
|
||||
string = TagUtil.parsePlain(fme.getFaction(), string);
|
||||
|
||||
String permissableName = nicename.substring(0, 1).toUpperCase() + nicename.substring(1);
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.massivecraft.factions.struct;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.zcore.fperms.Permissable;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import com.massivecraft.factions.zcore.util.TagUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -117,10 +119,10 @@ public enum Role implements Permissable {
|
||||
|
||||
// Utility method to build items for F Perm GUI
|
||||
@Override
|
||||
public ItemStack buildItem() {
|
||||
public ItemStack buildItem(FPlayer fme) {
|
||||
final ConfigurationSection RELATION_CONFIG = P.p.getConfig().getConfigurationSection("fperm-gui.relation");
|
||||
|
||||
String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", ""));
|
||||
String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", ""), fme);
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
Material material = Material.matchMaterial(RELATION_CONFIG.getString("materials." + name().toLowerCase(), "STAINED_CLAY"));
|
||||
@ -132,7 +134,7 @@ public enum Role implements Permissable {
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
|
||||
for (String loreLine : RELATION_CONFIG.getStringList("placeholder-item.lore")) {
|
||||
lore.add(replacePlaceholders(loreLine));
|
||||
lore.add(replacePlaceholders(loreLine, fme));
|
||||
}
|
||||
|
||||
itemMeta.setDisplayName(displayName);
|
||||
@ -143,7 +145,7 @@ public enum Role implements Permissable {
|
||||
return item;
|
||||
}
|
||||
|
||||
public String replacePlaceholders(String string) {
|
||||
public String replacePlaceholders(String string, FPlayer fme) {
|
||||
string = ChatColor.translateAlternateColorCodes('&', string);
|
||||
|
||||
String permissableName = nicename.substring(0, 1).toUpperCase() + nicename.substring(1);
|
||||
|
@ -6,6 +6,7 @@ import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import com.massivecraft.factions.zcore.util.TagUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
@ -57,7 +58,7 @@ public class WarpGUI implements InventoryHolder, FactionGUI {
|
||||
}
|
||||
|
||||
guiSize *= 9;
|
||||
String guiName = ChatColor.translateAlternateColorCodes('&', section.getString("name", "FactionPermissions"));
|
||||
String guiName = parse(section.getString("name", "FactionPermissions"));
|
||||
warpGUI = Bukkit.createInventory(this, guiSize, guiName);
|
||||
|
||||
maxWarps = P.p.getConfig().getInt("max-warps", 5);
|
||||
@ -174,7 +175,7 @@ public class WarpGUI implements InventoryHolder, FactionGUI {
|
||||
}
|
||||
|
||||
private String replacePlaceholers(String string, String warp, Faction faction) {
|
||||
string = ChatColor.translateAlternateColorCodes('&', string);
|
||||
string = parse(string);
|
||||
string = string.replace("{warp}", warp);
|
||||
string = string.replace("{warp-protected}", faction.hasWarpPassword(warp) ? "Enabled" : "Disabled");
|
||||
string = string.replace("{warp-cost}", !P.p.getConfig().getBoolean("warp-cost.enabled", false) ? "Disabled" : Integer.toString(P.p.getConfig().getInt("warp-cost.warp", 5)));
|
||||
@ -239,11 +240,11 @@ public class WarpGUI implements InventoryHolder, FactionGUI {
|
||||
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES);
|
||||
|
||||
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', dummySection.getString("name", " ")));
|
||||
itemMeta.setDisplayName(parse(dummySection.getString("name", " ")));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String loreLine : dummySection.getStringList("lore")) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', loreLine));
|
||||
lore.add(parse(loreLine));
|
||||
}
|
||||
itemMeta.setLore(lore);
|
||||
|
||||
@ -252,4 +253,11 @@ public class WarpGUI implements InventoryHolder, FactionGUI {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private String parse(String string) {
|
||||
string = ChatColor.translateAlternateColorCodes('&', string);
|
||||
string = TagUtil.parsePlain(fme, string);
|
||||
string = TagUtil.parsePlain(fme.getFaction(), string);
|
||||
return TagUtil.parsePlaceholders(fme.getPlayer(), string);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.massivecraft.factions.zcore.fperms;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface Permissable {
|
||||
|
||||
public ItemStack buildItem();
|
||||
public ItemStack buildItem(FPlayer fme);
|
||||
|
||||
public String replacePlaceholders(String string);
|
||||
public String replacePlaceholders(String string, FPlayer fme);
|
||||
|
||||
public String name();
|
||||
|
||||
|
@ -2,6 +2,8 @@ package com.massivecraft.factions.zcore.fperms;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.zcore.util.TagUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -124,7 +126,9 @@ public enum PermissableAction {
|
||||
|
||||
public String replacePlaceholers(String string, FPlayer fme, Permissable permissable) {
|
||||
// Run Permissable placeholders
|
||||
string = permissable.replacePlaceholders(string);
|
||||
string = permissable.replacePlaceholders(string, fme);
|
||||
string = TagUtil.parsePlain(fme, string);
|
||||
string = TagUtil.parsePlain(fme.getFaction(), string);
|
||||
|
||||
String actionName = name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
string = string.replace("{action}", actionName);
|
||||
|
@ -7,6 +7,7 @@ import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.Permissable;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import com.massivecraft.factions.zcore.util.TagUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
@ -57,7 +58,7 @@ public class PermissableActionGUI implements InventoryHolder, FactionGUI {
|
||||
}
|
||||
|
||||
guiSize *= 9;
|
||||
String guiName = ChatColor.translateAlternateColorCodes('&', section.getString("name", "FactionPerms"));
|
||||
String guiName = parse(section.getString("name", "Faction Permissions"));
|
||||
actionGUI = Bukkit.createInventory(this, guiSize, guiName);
|
||||
|
||||
for (String key : section.getConfigurationSection("slots").getKeys(false)) {
|
||||
@ -177,17 +178,17 @@ public class PermissableActionGUI implements InventoryHolder, FactionGUI {
|
||||
|
||||
switch (specialItem) {
|
||||
case RELATION:
|
||||
return permissable.buildItem();
|
||||
return permissable.buildItem(fme);
|
||||
case BACK:
|
||||
ConfigurationSection backButtonConfig = P.p.getConfig().getConfigurationSection("fperm-gui.back-item");
|
||||
|
||||
ItemStack backButton = new ItemStack(Material.matchMaterial(backButtonConfig.getString("material")));
|
||||
ItemMeta backButtonMeta = backButton.getItemMeta();
|
||||
|
||||
backButtonMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', backButtonConfig.getString("name")));
|
||||
backButtonMeta.setDisplayName(parse(backButtonConfig.getString("name", "Back")));
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String loreLine : backButtonConfig.getStringList("lore")) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', loreLine));
|
||||
lore.add(parse(loreLine));
|
||||
}
|
||||
|
||||
backButtonMeta.setLore(lore);
|
||||
@ -267,11 +268,11 @@ public class PermissableActionGUI implements InventoryHolder, FactionGUI {
|
||||
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', dummySection.getString("name", " ")));
|
||||
itemMeta.setDisplayName(parse(dummySection.getString("name", " ")));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String loreLine : dummySection.getStringList("lore")) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', loreLine));
|
||||
lore.add(parse(loreLine));
|
||||
}
|
||||
|
||||
itemMeta.setLore(lore);
|
||||
@ -282,6 +283,13 @@ public class PermissableActionGUI implements InventoryHolder, FactionGUI {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private String parse(String string) {
|
||||
string = ChatColor.translateAlternateColorCodes('&', string);
|
||||
string = TagUtil.parsePlain(fme, string);
|
||||
string = TagUtil.parsePlain(fme.getFaction(), string);
|
||||
return TagUtil.parsePlaceholders(fme.getPlayer(), string);
|
||||
}
|
||||
|
||||
public enum SpecialItem {
|
||||
BACK,
|
||||
RELATION;
|
||||
|
@ -6,6 +6,8 @@ import com.massivecraft.factions.struct.Relation;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.FactionGUI;
|
||||
import com.massivecraft.factions.zcore.fperms.Permissable;
|
||||
import com.massivecraft.factions.zcore.util.TagUtil;
|
||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
@ -109,7 +111,7 @@ public class PermissableRelationGUI implements InventoryHolder, FactionGUI {
|
||||
for (Map.Entry<Integer, Permissable> entry : relationSlots.entrySet()) {
|
||||
Permissable permissable = entry.getValue();
|
||||
|
||||
ItemStack item = permissable.buildItem();
|
||||
ItemStack item = permissable.buildItem(fme);
|
||||
|
||||
if (item == null) {
|
||||
P.p.log(Level.WARNING, "Invalid material for " + permissable.toString().toUpperCase() + " skipping it");
|
||||
@ -185,11 +187,11 @@ public class PermissableRelationGUI implements InventoryHolder, FactionGUI {
|
||||
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', dummySection.getString("name", " ")));
|
||||
itemMeta.setDisplayName(parse(dummySection.getString("name", " ")));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String loreLine : dummySection.getStringList("lore")) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', loreLine));
|
||||
lore.add(parse(loreLine));
|
||||
}
|
||||
itemMeta.setLore(lore);
|
||||
|
||||
@ -200,4 +202,11 @@ public class PermissableRelationGUI implements InventoryHolder, FactionGUI {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private String parse(String string) {
|
||||
string = ChatColor.translateAlternateColorCodes('&', string);
|
||||
string = TagUtil.parsePlain(fme, string);
|
||||
string = TagUtil.parsePlain(fme.getFaction(), string);
|
||||
return TagUtil.parsePlaceholders(fme.getPlayer(), string);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user