mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-25 20:16:13 +01:00
Added custom head setting to the gui shop, #152
- Fix NullPointerException, https://www.spigotmc.org/threads/jobs-reborn.50989/page-227#post-3221066
This commit is contained in:
parent
11af61064c
commit
9e7eb97b12
@ -31,12 +31,10 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
|
||||
import com.gamingmesh.jobs.resources.jfep.Parser;
|
||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||
import com.gamingmesh.jobs.container.CurrencyLimit;
|
||||
import com.gamingmesh.jobs.container.CurrencyType;
|
||||
import com.gamingmesh.jobs.container.LocaleReader;
|
||||
@ -933,15 +931,12 @@ public class GeneralConfigManager {
|
||||
c.getW().addComment("JobsTop.AmountToShow", "Defines amount of players to be shown in one page for /jobs top & /jobs gtop");
|
||||
JobsTopAmount = c.get("JobsTop.AmountToShow", 15);
|
||||
|
||||
CMIMaterial tmat = CMIMaterial.get(c.get("JobsGUI.BackButton.Material", "JACK_O_LANTERN"));
|
||||
CMIMaterial tmat = null;
|
||||
tmat = CMIMaterial.get(c.get("JobsGUI.BackButton.Material", "JACK_O_LANTERN"));
|
||||
guiBackButton = tmat == null ? CMIMaterial.JACK_O_LANTERN.newItemStack() : tmat.newItemStack();
|
||||
|
||||
tmat = CMIMaterial.get(c.get("JobsGUI.Filler.Material", "STAINED_GLASS_PANE"));
|
||||
|
||||
guiFiller = tmat == null ? CMIMaterial.GREEN_STAINED_GLASS_PANE.newItemStack() : tmat.newItemStack();
|
||||
ItemMeta meta = guiFiller.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.RED + "");
|
||||
guiFiller.setItemMeta(meta);
|
||||
|
||||
// c.getW().addComment("Schedule.Boost.Enable", "Do you want to enable scheduler for global boost");
|
||||
// useGlobalBoostScheduler = c.get("Schedule.Boost.Enable", false);
|
||||
|
@ -10,6 +10,7 @@ import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -18,6 +19,7 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
|
||||
@ -289,8 +291,7 @@ public class ShopManager {
|
||||
if (prog != null && prog.getLevel() < one.getValue())
|
||||
levelColor = ChatColor.DARK_RED.toString();
|
||||
|
||||
Lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobsList", "%jobsname%", jobColor + one.getKey(), "%level%", levelColor + one
|
||||
.getValue()));
|
||||
Lore.add(Jobs.getLanguage().getMessage("command.shop.info.reqJobsList", "%jobsname%", jobColor + one.getKey(), "%level%", levelColor + one.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -300,18 +301,41 @@ public class ShopManager {
|
||||
}
|
||||
|
||||
meta.setLore(Lore);
|
||||
|
||||
if (item.getCustomHead() != null) {
|
||||
GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack();
|
||||
|
||||
SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta();
|
||||
// Fix skull meta
|
||||
skullMeta.setDisplayName(item.getIconName());
|
||||
skullMeta.setLore(Lore);
|
||||
|
||||
if (item.getCustomHeadOwner())
|
||||
skullMeta.setOwner(Jobs.getPlayerManager().getJobsPlayer(player).getUserName());
|
||||
else {
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(item.getCustomHead());
|
||||
skullMeta.setOwner(offPlayer.getName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
GUIitem.setItemMeta(skullMeta);
|
||||
} else
|
||||
GUIitem.setItemMeta(meta);
|
||||
|
||||
GuiInv.setItem(i, GUIitem);
|
||||
}
|
||||
|
||||
ItemStack Item = new ItemStack(Material.ARROW);
|
||||
|
||||
ItemMeta meta = Item.getItemMeta();
|
||||
int pervSlot = getPrevButtonSlot(GuiSize, page);
|
||||
if (pervSlot != -1) {
|
||||
int prevSlot = getPrevButtonSlot(GuiSize, page);
|
||||
if (prevSlot != -1) {
|
||||
meta.setDisplayName(Jobs.getLanguage().getMessage("command.help.output.prevPage"));
|
||||
Item.setItemMeta(meta);
|
||||
GuiInv.setItem(pervSlot, Item);
|
||||
GuiInv.setItem(prevSlot, Item);
|
||||
}
|
||||
|
||||
int nextSlot = getnextButtonSlot(GuiSize, page);
|
||||
@ -356,6 +380,12 @@ public class ShopManager {
|
||||
int IconId = NameSection.getInt("Icon.Id");
|
||||
ShopItem Sitem = new ShopItem(category, price, IconId);
|
||||
|
||||
if (NameSection.isString("Icon.CustomHead.PlayerName"))
|
||||
Sitem.setCustomHead(NameSection.getString("Icon.CustomHead.PlayerName"));
|
||||
|
||||
if (NameSection.isBoolean("Icon.CustomHead.UseCurrentPlayer"))
|
||||
Sitem.setCustomHeadOwner(NameSection.getBoolean("Icon.CustomHead.UseCurrentPlayer"));
|
||||
|
||||
if (NameSection.isInt("Icon.Data"))
|
||||
Sitem.setIconData(NameSection.getInt("Icon.Data"));
|
||||
|
||||
@ -367,7 +397,7 @@ public class ShopManager {
|
||||
|
||||
if (NameSection.isList("Icon.Lore")) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (NameSection.getStringList("Icon.Lore") != null && !NameSection.getStringList("Icon.Lore").isEmpty())
|
||||
if (!NameSection.getStringList("Icon.Lore").isEmpty())
|
||||
for (String eachLine : NameSection.getStringList("Icon.Lore")) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', eachLine));
|
||||
}
|
||||
@ -379,7 +409,8 @@ public class ShopManager {
|
||||
}
|
||||
|
||||
if (NameSection.isList("RequiredPermission"))
|
||||
Sitem.setRequiredPerm(NameSection.getStringList("RequiredPermission"));
|
||||
if (!NameSection.getStringList("RequiredPermission").isEmpty())
|
||||
Sitem.setRequiredPerm(NameSection.getStringList("RequiredPermission"));
|
||||
|
||||
if (NameSection.isInt("RequiredTotalLevels"))
|
||||
Sitem.setRequiredTotalLevels(NameSection.getInt("RequiredTotalLevels"));
|
||||
@ -404,7 +435,7 @@ public class ShopManager {
|
||||
|
||||
if (NameSection.isList("PerformCommands")) {
|
||||
List<String> cmd = new ArrayList<>();
|
||||
if (NameSection.getStringList("PerformCommands") != null && !NameSection.getStringList("PerformCommands").isEmpty())
|
||||
if (!NameSection.getStringList("PerformCommands").isEmpty())
|
||||
for (String eachLine : NameSection.getStringList("PerformCommands")) {
|
||||
cmd.add(ChatColor.translateAlternateColorCodes('&', eachLine));
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ public class ShopItem {
|
||||
|
||||
private List<JobItems> items = new ArrayList<>();
|
||||
|
||||
private String PlayerName;
|
||||
private boolean useCurrentPlayer = false;
|
||||
|
||||
public ShopItem(String NodeName, double price, int IconId) {
|
||||
this.NodeName = NodeName;
|
||||
this.price = price;
|
||||
@ -142,4 +145,20 @@ public class ShopItem {
|
||||
public void setRequiredTotalLevels(int RequiredTotalLevels) {
|
||||
this.RequiredTotalLevels = RequiredTotalLevels;
|
||||
}
|
||||
|
||||
public String getCustomHead() {
|
||||
return PlayerName;
|
||||
}
|
||||
|
||||
public void setCustomHead(String PlayerName) {
|
||||
this.PlayerName = PlayerName;
|
||||
}
|
||||
|
||||
public boolean getCustomHeadOwner() {
|
||||
return useCurrentPlayer;
|
||||
}
|
||||
|
||||
public void setCustomHeadOwner(boolean useCurrentPlayer) {
|
||||
this.useCurrentPlayer = useCurrentPlayer;
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,13 @@ Items:
|
||||
- "&6Efficiency V"
|
||||
- "&6Unbreaking III"
|
||||
- "&eAnd one tasty apple!"
|
||||
# (Optional - default: false) Hides icon if player dont have permission to get this item
|
||||
# (Optional - default: false) Hides icon if player don't have permission to get this item
|
||||
HideWithoutPermission: true
|
||||
# (Optional) When you want to use Player Head material with skin then use this
|
||||
#CustomHead:
|
||||
# PlayerName: playerName
|
||||
# Using the current player (if have job) who opened the gui. The PlayerName string is ignoring if this exist.
|
||||
# UseCurrentPlayer: true
|
||||
# (Optional) List of permissions required to buy this item
|
||||
RequiredPermission:
|
||||
- jobs.item.pickaxe
|
||||
@ -27,9 +32,9 @@ Items:
|
||||
- Woodcutter-10
|
||||
# (Optional) Total level from all jobs player currently in
|
||||
RequiredTotalLevels: 100
|
||||
# (Optional) Performs comands on item purchase
|
||||
# (Optional) Performs commands on item purchase
|
||||
# use 'msg ' at start of command to send nice message to player
|
||||
# all other commands will be performed normaly as they would be executed from console
|
||||
# all other commands will be performed normally as they would be executed from console
|
||||
# use [player] variable to include buyers name
|
||||
PerformCommands:
|
||||
- "msg &eThanks for buying this super pick axe!"
|
||||
|
Loading…
Reference in New Issue
Block a user