mirror of
https://e.coding.net/circlecloud/Soulbound.git
synced 2024-11-21 01:39:10 +00:00
fix ActionItem Null Error...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
e82831db0d
commit
6f7cd753c3
@ -15,141 +15,136 @@ import com.me.tft_02.soulbound.datatypes.ActionType;
|
||||
import com.me.tft_02.soulbound.datatypes.SoulbindItem;
|
||||
|
||||
public class ItemsConfig extends ConfigLoader {
|
||||
private static ItemsConfig instance;
|
||||
private static ItemsConfig instance;
|
||||
|
||||
private List<SoulbindItem> soulbindOnCraft = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnOpenChest = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnPickupItem = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnDrop = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnRespawn = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnKit = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnCraft = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnOpenChest = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnPickupItem = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnDrop = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnRespawn = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnKit = new ArrayList<SoulbindItem>();
|
||||
|
||||
public ItemsConfig() {
|
||||
super("items.yml");
|
||||
loadKeys();
|
||||
}
|
||||
public ItemsConfig() {
|
||||
super("items.yml");
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
public static ItemsConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ItemsConfig();
|
||||
}
|
||||
public static ItemsConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ItemsConfig();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void loadKeys() {
|
||||
ConfigurationSection configurationSection = config.getConfigurationSection("Items");
|
||||
protected void loadKeys() {
|
||||
ConfigurationSection configurationSection = config.getConfigurationSection("Items");
|
||||
|
||||
if (configurationSection == null) {
|
||||
return;
|
||||
}
|
||||
if (configurationSection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> itemConfigSet = configurationSection.getKeys(false);
|
||||
Set<String> itemConfigSet = configurationSection.getKeys(false);
|
||||
|
||||
for (String itemName : itemConfigSet) {
|
||||
String[] itemInfo = itemName.split("[|]");
|
||||
for (String itemName : itemConfigSet) {
|
||||
String[] itemInfo = itemName.split("[|]");
|
||||
|
||||
Material itemMaterial = Material.matchMaterial(itemInfo[0]);
|
||||
Material itemMaterial = Material.matchMaterial(itemInfo[0]);
|
||||
|
||||
if (itemMaterial == null) {
|
||||
plugin.getLogger().warning("Invalid material name. This item will be skipped. - " + itemInfo[0]);
|
||||
continue;
|
||||
}
|
||||
if (itemMaterial == null) {
|
||||
plugin.getLogger().warning(
|
||||
"Invalid material name. This item will be skipped. - " + itemInfo[0]);
|
||||
continue;
|
||||
}
|
||||
|
||||
byte itemData = (itemInfo.length == 2) ? Byte.valueOf(itemInfo[1]) : 0;
|
||||
MaterialData itemMaterialData = new MaterialData(itemMaterial, itemData);
|
||||
byte itemData = (itemInfo.length == 2) ? Byte.valueOf(itemInfo[1]) : 0;
|
||||
MaterialData itemMaterialData = new MaterialData(itemMaterial, itemData);
|
||||
|
||||
List<String> lore = new ArrayList<String>();
|
||||
if (config.contains("Items." + itemName + ".Lore")) {
|
||||
List<String> lore = new ArrayList<String>();
|
||||
if (config.contains("Items." + itemName + ".Lore")) {
|
||||
|
||||
for (String loreEntry : config.getStringList("Items." + itemName + ".Lore")) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', loreEntry));
|
||||
}
|
||||
}
|
||||
for (String loreEntry : config.getStringList("Items." + itemName + ".Lore")) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', loreEntry));
|
||||
}
|
||||
}
|
||||
|
||||
String name = null;
|
||||
if (config.contains("Items." + itemName + ".Name")) {
|
||||
name = ChatColor.translateAlternateColorCodes('&', config.getString("Items." + itemName + ".Name"));
|
||||
}
|
||||
String name = null;
|
||||
if (config.contains("Items." + itemName + ".Name")) {
|
||||
name = ChatColor.translateAlternateColorCodes('&',
|
||||
config.getString("Items." + itemName + ".Name"));
|
||||
}
|
||||
|
||||
SoulbindItem soulbindItem = new SoulbindItem(itemMaterialData, name, lore);
|
||||
SoulbindItem soulbindItem = new SoulbindItem(itemMaterialData, name, lore);
|
||||
|
||||
List<String> actions = config.getStringList("Items." + itemName + ".Actions");
|
||||
List<String> actions = config.getStringList("Items." + itemName + ".Actions");
|
||||
|
||||
for (ActionType actionType : ActionType.values()) {
|
||||
if (actions.contains(actionType.toString())) {
|
||||
addSoulbindItem(actionType, soulbindItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ActionType actionType : ActionType.values()) {
|
||||
if (actions.contains(actionType.toString())) {
|
||||
addSoulbindItem(actionType, soulbindItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addSoulbindItem(ActionType actionType, SoulbindItem soulbindItem) {
|
||||
switch (actionType) {
|
||||
case CRAFT:
|
||||
soulbindOnCraft.add(soulbindItem);
|
||||
return;
|
||||
case OPEN_CHEST:
|
||||
soulbindOnOpenChest.add(soulbindItem);
|
||||
return;
|
||||
case PICKUP_ITEM:
|
||||
soulbindOnPickupItem.add(soulbindItem);
|
||||
return;
|
||||
case DROP_ITEM:
|
||||
soulbindOnDrop.add(soulbindItem);
|
||||
return;
|
||||
case RESPAWN:
|
||||
soulbindOnRespawn.add(soulbindItem);
|
||||
return;
|
||||
case KIT:
|
||||
soulbindOnKit.add(soulbindItem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
private void addSoulbindItem(ActionType actionType, SoulbindItem soulbindItem) {
|
||||
switch (actionType) {
|
||||
case CRAFT:
|
||||
soulbindOnCraft.add(soulbindItem);
|
||||
return;
|
||||
case OPEN_CHEST:
|
||||
soulbindOnOpenChest.add(soulbindItem);
|
||||
return;
|
||||
case PICKUP_ITEM:
|
||||
soulbindOnPickupItem.add(soulbindItem);
|
||||
return;
|
||||
case DROP_ITEM:
|
||||
soulbindOnDrop.add(soulbindItem);
|
||||
return;
|
||||
case RESPAWN:
|
||||
soulbindOnRespawn.add(soulbindItem);
|
||||
return;
|
||||
case KIT:
|
||||
soulbindOnKit.add(soulbindItem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public List<SoulbindItem> getSoulbindItems(ActionType actionType) {
|
||||
switch (actionType) {
|
||||
case CRAFT:
|
||||
return soulbindOnCraft;
|
||||
case OPEN_CHEST:
|
||||
return soulbindOnOpenChest;
|
||||
case PICKUP_ITEM:
|
||||
return soulbindOnPickupItem;
|
||||
case DROP_ITEM:
|
||||
return soulbindOnDrop;
|
||||
case RESPAWN:
|
||||
return soulbindOnRespawn;
|
||||
case KIT:
|
||||
return soulbindOnKit;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public List<SoulbindItem> getSoulbindItems(ActionType actionType) {
|
||||
switch (actionType) {
|
||||
case CRAFT:
|
||||
return soulbindOnCraft;
|
||||
case OPEN_CHEST:
|
||||
return soulbindOnOpenChest;
|
||||
case PICKUP_ITEM:
|
||||
return soulbindOnPickupItem;
|
||||
case DROP_ITEM:
|
||||
return soulbindOnDrop;
|
||||
case RESPAWN:
|
||||
return soulbindOnRespawn;
|
||||
case KIT:
|
||||
return soulbindOnKit;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isActionItem(ItemStack itemStack, ActionType actionType) {
|
||||
for (SoulbindItem soulbindItem : getSoulbindItems(actionType)) {
|
||||
if (itemStack.getData().equals(soulbindItem.getMaterialData())) {
|
||||
if (itemStack.hasItemMeta()) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if (soulbindItem.getName() != null) {
|
||||
if (!itemMeta.getDisplayName().contains(soulbindItem.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (soulbindItem.getLore() != null && !soulbindItem.getLore().isEmpty()) {
|
||||
if (itemMeta.hasLore() || !itemMeta.getLore().containsAll(soulbindItem.getLore())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public boolean isActionItem(ItemStack itemStack, ActionType actionType) {
|
||||
for (SoulbindItem soulbindItem : getSoulbindItems(actionType)) {
|
||||
if (itemStack.getData().equals(soulbindItem.getMaterialData())) {
|
||||
if (itemStack.hasItemMeta()) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (soulbindItem.getName() != null) {
|
||||
if (itemMeta.getDisplayName().contains(soulbindItem.getName()))
|
||||
if (soulbindItem.getLore() != null && !soulbindItem.getLore().isEmpty())
|
||||
if (itemMeta.hasLore()
|
||||
&& itemMeta.getLore().containsAll(soulbindItem.getLore()))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user