use of org.bukkit.inventory.meta.ItemMeta in project RedProtect by FabioZumbi12.
the class RPGui method onInventoryClick.
@EventHandler(priority = EventPriority.LOWEST)
void onInventoryClick(InventoryClickEvent event) {
if (event.isCancelled() || !(event.getInventory().getHolder() instanceof Player) || !event.getInventory().getTitle().equals(this.name)) {
return;
}
if (this.edit) {
return;
}
if (event.getInventory().getTitle() != null && event.getInventory().getTitle().equals(this.name)) {
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
if (item != null && !item.equals(RPConfig.getGuiSeparator()) && !item.getType().equals(Material.AIR) && event.getRawSlot() >= 0 && event.getRawSlot() <= this.size - 1) {
ItemMeta itemMeta = item.getItemMeta();
String flag = itemMeta.getLore().get(1).replace("§0", "");
if (RPConfig.getBool("flags-configuration.change-flag-delay.enable")) {
if (RPConfig.getStringList("flags-configuration.change-flag-delay.flags").contains(flag)) {
if (!RedProtect.get().changeWait.contains(this.region.getName() + flag)) {
applyFlag(flag, itemMeta, event);
RPUtil.startFlagChanger(this.region.getName(), flag, player);
} else {
RPLang.sendMessage(player, RPLang.get("gui.needwait.tochange").replace("{seconds}", RPConfig.getString("flags-configuration.change-flag-delay.seconds")));
}
} else {
applyFlag(flag, itemMeta, event);
}
} else {
applyFlag(flag, itemMeta, event);
}
}
}
}
use of org.bukkit.inventory.meta.ItemMeta in project RedProtect by FabioZumbi12.
the class RPConfig method getGuiSeparator.
public static ItemStack getGuiSeparator() {
ItemStack separator = new ItemStack(Material.getMaterial(GuiItems.getString("gui-separator.material")), 1, (short) GuiItems.getInt("gui-separator.data"));
ItemMeta meta = separator.getItemMeta();
meta.setDisplayName(getGuiString("separator"));
meta.setLore(Arrays.asList("", getGuiString("separator")));
separator.setItemMeta(meta);
return separator;
}
use of org.bukkit.inventory.meta.ItemMeta in project FireAPI by FireBlade-Serv.
the class FriendsActionInventoryGUI method getBorderItem.
public ItemStack getBorderItem() {
ItemStack i = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) ((this.friends.size() != 0) ? 4 : 14));
ItemMeta m = i.getItemMeta();
m.setDisplayName((this.friends.size() != 0) ? "§eVous avez §6" + this.getFriends().size() + " §eamis" : "§cVous n'avez aucun ami :'(");
i.setItemMeta(m);
return i;
}
use of org.bukkit.inventory.meta.ItemMeta in project NoCheatPlus by NoCheatPlus.
the class BridgeMisc method getFireworksPower.
/**
* Get the power for a firework(s) item (stack).
*
* @param item
* @return The power. Should be between 0 and 127 including edges, in case
* of valid items, according to javadocs (Spigot MC 1.11.2). In case
* the item is null or can't be judged, -1 is returned.
*/
public static int getFireworksPower(final ItemStack item) {
if (item == null || item.getType() != FIREWORK) {
return 0;
}
final ItemMeta meta = item.getItemMeta();
if (!(meta instanceof FireworkMeta)) {
// INDIRECT: With elytra, this already exists.
return 0;
}
final FireworkMeta fwMeta = (FireworkMeta) meta;
return fwMeta.getPower();
}
use of org.bukkit.inventory.meta.ItemMeta in project UltimateChat by FabioZumbi12.
the class UCMessages method formatTags.
@SuppressWarnings("deprecation")
public static String formatTags(String tag, String text, Object cmdSender, Object receiver, String msg, UCChannel ch) {
if (receiver instanceof CommandSender && tag.equals("message")) {
text = text.replace("{message}", mention(cmdSender, (CommandSender) receiver, msg));
if (UChat.get().getUCConfig().getBoolean("general.item-hand.enable")) {
text = text.replace(UChat.get().getUCConfig().getString("general.item-hand.placeholder"), formatTags("", ChatColor.translateAlternateColorCodes('&', UChat.get().getUCConfig().getString("general.item-hand.format")), cmdSender, receiver, msg, ch));
}
} else {
text = text.replace("{message}", msg);
}
if (tag.equals("message") && !UChat.get().getUCConfig().getBoolean("general.enable-tags-on-messages")) {
return text;
}
text = text.replace("{ch-color}", ch.getColor()).replace("{ch-name}", ch.getName()).replace("{ch-alias}", ch.getAlias());
if (UChat.get().getUCConfig().getBoolean("jedis.enable") && ch.useJedis()) {
text = text.replace("{jedis-id}", UChat.get().getUCConfig().getString("jedis.server-id"));
}
if (ch.isBungee()) {
text = text.replace("{bungee-id}", UChat.get().getUCConfig().getString("bungee.server-id"));
}
if (cmdSender instanceof CommandSender) {
text = text.replace("{playername}", ((CommandSender) cmdSender).getName());
if (receiver instanceof CommandSender)
text = text.replace("{receivername}", ((CommandSender) receiver).getName());
if (receiver instanceof String)
text = text.replace("{receivername}", (String) receiver);
} else {
text = text.replace("{playername}", (String) cmdSender).replace("{receivername}", (String) receiver);
}
for (String repl : registeredReplacers.keySet()) {
if (registeredReplacers.get(repl).equals(repl)) {
text = text.replace(repl, "");
continue;
}
text = text.replace(repl, registeredReplacers.get(repl));
}
StringBuilder def = new StringBuilder();
for (int i = 0; i < defFormat.length; i++) {
text = text.replace("{default-format-" + i + "}", defFormat[i]);
def.append(" ").append(defFormat[i]);
}
if (def.length() > 0) {
text = text.replace("{default-format-full}", def.substring(1));
}
if (text.contains("{time-now}")) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
text = text.replace("{time-now}", sdf.format(cal.getTime()));
}
if (cmdSender instanceof Player) {
Player sender = (Player) cmdSender;
if (text.contains("{world}")) {
String world = UChat.get().getUCConfig().getString("general.world-names." + sender.getWorld().getName());
text = text.replace("{world}", world != null ? world : sender.getWorld().getName());
}
text = text.replace("{nickname}", sender.getDisplayName());
// replace item hand
text = text.replace(UChat.get().getUCConfig().getString("general.item-hand.placeholder"), ChatColor.translateAlternateColorCodes('&', UChat.get().getUCConfig().getString("general.item-hand.format")));
if (text.contains("{hand-") && !sender.getItemInHand().getType().equals(Material.AIR)) {
ItemStack item = sender.getItemInHand();
text = text.replace("{hand-durability}", String.valueOf(item.getDurability()));
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (UCUtil.getBukkitVersion() >= 1112 && meta.hasLocalizedName()) {
text = text.replace("{hand-name}", item.getItemMeta().getLocalizedName());
} else if (meta.hasDisplayName()) {
text = text.replace("{hand-name}", item.getItemMeta().getDisplayName());
} else {
text = text.replace("{hand-name}", UCUtil.capitalize(item.getType().toString()));
}
if (meta.hasLore()) {
StringBuilder lorestr = new StringBuilder();
for (String lore : meta.getLore()) {
lorestr.append("\n ").append(lore);
}
if (lorestr.length() >= 2) {
text = text.replace("{hand-lore}", lorestr.toString().substring(0, lorestr.length() - 1));
}
}
if (meta.hasEnchants()) {
StringBuilder str = new StringBuilder();
for (Entry<Enchantment, Integer> enchant : meta.getEnchants().entrySet()) {
str.append("\n ").append(enchant.getKey().getName()).append(": ").append(enchant.getValue());
}
if (str.length() >= 2) {
text = text.replace("{hand-enchants}", str.toString().substring(0, str.length() - 1));
}
}
}
text = text.replace("{hand-amount}", String.valueOf(item.getAmount()));
text = text.replace("{hand-name}", UCUtil.capitalize(item.getType().toString()));
text = text.replace("{hand-type}", UCUtil.capitalize(item.getType().toString()));
} else {
text = text.replace("{hand-name}", UChat.get().getLang().get("chat.emptyslot"));
text = text.replace("{hand-type}", "Air");
}
if (UChat.get().getVaultChat() != null && (text.contains("-prefix") || text.contains("-suffix"))) {
text = text.replace("{group-suffix}", UCVaultCache.getVaultChat(sender).getPlayerSuffix()).replace("{group-prefix}", UCVaultCache.getVaultChat(sender).getPlayerPrefix());
String[] pgs = UCVaultCache.getVaultPerms(sender).getPlayerGroups();
if (pgs.length > 0) {
text = text.replace("{player-groups-prefixes}", UCVaultCache.getVaultChat(sender).getGroupPrefixes()).replace("{player-groups-suffixes}", UCVaultCache.getVaultChat(sender).getGroupSuffixes());
}
}
if (UChat.get().getVaultEco() != null && text.contains("{balance}")) {
text = text.replace("{balance}", "" + UChat.get().getVaultEco().getBalance(sender, sender.getWorld().getName()));
}
if (UChat.get().getVaultPerms() != null && (text.contains("-group}") || text.contains("-groups}"))) {
String[] pgs = UCVaultCache.getVaultPerms(sender).getPlayerGroups();
if (pgs.length > 0) {
StringBuilder groups = new StringBuilder();
for (String g : pgs) {
groups.append(g).append(",");
}
text = text.replace("{player-groups}", groups.toString().substring(0, groups.length() - 1));
}
String primGroup = UCVaultCache.getVaultPerms(sender).getPrimaryGroup();
String group = UChat.get().getUCConfig().getString("general.group-names." + primGroup);
text = text.replace("{prim-group}", group == null ? primGroup : group);
}
if (text.contains("{clan-") && UChat.SClans) {
ClanPlayer cp = UChat.sc.getClanManager().getClanPlayer(sender.getUniqueId());
SettingsManager scm = UChat.sc.getSettingsManager();
if (cp != null) {
String fulltag = scm.getTagBracketColor() + scm.getTagBracketLeft() + scm.getTagDefaultColor() + cp.getClan().getColorTag() + scm.getTagBracketColor() + scm.getTagBracketRight() + scm.getTagSeparatorColor() + scm.getTagSeparator();
text = text.replace("{clan-tag}", cp.getTag()).replace("{clan-fulltag}", fulltag).replace("{clan-name}", checkEmpty(cp.getClan().getName())).replace("{clan-kdr}", "" + cp.getKDR()).replace("{clan-rank}", checkEmpty(cp.getRank())).replace("{clan-totalkdr}", "" + cp.getClan().getTotalKDR()).replace("{clan-deaths}", "" + cp.getDeaths()).replace("{clan-isleader}", "" + cp.isLeader()).replace("{clan-totalkdr}", "" + cp.getClan().getTotalKDR()).replace("{clan-ctag}", cp.getClan().getColorTag());
}
}
if (UChat.Factions) {
text = UCFactionsHook.formatFac(text, sender, receiver);
}
if (text.contains("{marry-")) {
if (UChat.MarryReloded && sender.hasMetadata("marriedTo")) {
String partner = sender.getMetadata("marriedTo").get(0).asString();
String prefix = UChat.mapi.getBukkitConfig("config.yml").getString("chat.status-format");
UChat.mapi.getMPlayer(sender.getUniqueId()).getGender().getChatPrefix();
prefix = prefix.replace("{icon:male}", "♂").replace("{icon:female}", "♀").replace("{icon:genderless}", "⚤").replace("{icon:heart}", "❤");
String gender = UChat.mapi.getMPlayer(sender.getUniqueId()).getGender().getChatPrefix();
gender = gender.replace("{icon:male}", "♂").replace("{icon:female}", "♀").replace("{icon:genderless}", "⚤").replace("{icon:heart}", "❤");
text = text.replace("{marry-partner}", partner).replace("{marry-prefix}", prefix).replace("{marry-suffix}", gender);
}
if (UChat.MarryMaster) {
if (UChat.mm.HasPartner(sender)) {
text = text.replace("{marry-partner}", UChat.mm.DB.GetPartner(sender)).replace("{marry-prefix}", UChat.mm.config.GetPrefix().replace("<heart>", ChatColor.RED + "❤" + ChatColor.WHITE)).replace("{marry-suffix}", UChat.mm.config.GetSuffix().replace("<heart>", ChatColor.RED + "❤" + ChatColor.WHITE));
}
}
}
if (UChat.PlaceHolderAPI) {
if (receiver instanceof Player && UChat.get().isRelation()) {
while (text.contains("%rel_")) {
text = PlaceholderAPI.setRelationalPlaceholders(sender, (Player) receiver, text);
}
}
text = PlaceholderAPI.setPlaceholders(sender, text);
if (tag.equals("message")) {
text = composeColor(sender, text);
}
}
}
if (cmdSender instanceof CommandSender) {
text = text.replace("{nickname}", UChat.get().getUCConfig().getString("general.console-tag").replace("{console}", ((CommandSender) cmdSender).getName()));
} else {
text = text.replace("{nickname}", UChat.get().getUCConfig().getString("general.console-tag").replace("{console}", (String) cmdSender));
}
// colorize tags (not message)
if (!tag.equals("message")) {
text = ChatColor.translateAlternateColorCodes('&', text);
}
// remove blank items
text = text.replaceAll("\\{.*\\}", "");
// remove remain PlaceholderAPI
if (UChat.get().getUCConfig().getBoolean("general.remove-unnused-placeholderapi")) {
text = text.replaceAll("\\%.*\\%", "");
}
if (!tag.equals("message")) {
for (String rpl : UChat.get().getUCConfig().getStringList("general.remove-from-chat")) {
text = text.replace(ChatColor.translateAlternateColorCodes('&', rpl), "");
}
}
if (text.equals(" ") || text.equals(" ")) {
text = "";
}
return text;
}
Aggregations