mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Prevents B717
This commit is contained in:
parent
20d7b809b8
commit
cdeb16825a
@ -705,16 +705,26 @@ public class MMOItems extends LuminePlugin {
|
||||
return m.newBuilder().build();
|
||||
}
|
||||
|
||||
@Nullable public Type getType(@Nullable NBTItem nbtitem) {
|
||||
if (nbtitem == null || !nbtitem.hasType()) { return null; }
|
||||
|
||||
/**
|
||||
* @param nbtItem The NBTItem you are testing
|
||||
* @return The MMOItem Type of this item, if it is a MMOItem
|
||||
*/
|
||||
@Nullable public Type getType(@Nullable NBTItem nbtItem) {
|
||||
if (nbtItem == null || !nbtItem.hasType()) { return null; }
|
||||
|
||||
// Try that one instead
|
||||
return getType(nbtitem.getType());
|
||||
return getType(nbtItem.getType());
|
||||
}
|
||||
@Nullable public String getID(@Nullable NBTItem nbtitem) {
|
||||
if (nbtitem == null || !nbtitem.hasType()) { return null; }
|
||||
|
||||
ItemTag type = ItemTag.getTagAtPath("MMOITEMS_ITEM_ID", nbtitem, SupportedNBTTagValues.STRING);
|
||||
/**
|
||||
* @param nbtItem The NBTItem you are testing
|
||||
* @return The MMOItem ID of this item, if it is a MMOItem
|
||||
*/
|
||||
@Nullable public String getID(@Nullable NBTItem nbtItem) {
|
||||
if (nbtItem == null || !nbtItem.hasType()) { return null; }
|
||||
|
||||
ItemTag type = ItemTag.getTagAtPath("MMOITEMS_ITEM_ID", nbtItem, SupportedNBTTagValues.STRING);
|
||||
if (type == null) { return null; }
|
||||
return (String) type.getValue();
|
||||
}
|
||||
@ -765,5 +775,31 @@ public class MMOItems extends LuminePlugin {
|
||||
* @author Gunging
|
||||
*/
|
||||
@NotNull public static ConsoleCommandSender getConsole() { return plugin.getServer().getConsoleSender(); }
|
||||
|
||||
/**
|
||||
* @param item The item stack you are testing.
|
||||
* @param type MMOItem Type you are expecting {@link Type#getId()}
|
||||
* @param id MMOItem ID you are expecting
|
||||
*
|
||||
* @return If the given item is the desired MMOItem
|
||||
*/
|
||||
public static boolean isMMOItem(@Nullable ItemStack item, @NotNull String type, @NotNull String id) {
|
||||
if (item == null) { return false; }
|
||||
|
||||
// Make it into an NBT Item
|
||||
NBTItem asNBT = NBTItem.get(item);
|
||||
|
||||
// ID Matches?
|
||||
String itemID = MMOItems.plugin.getID(asNBT);
|
||||
|
||||
// Not a MMOItem
|
||||
if (itemID == null) { return false; }
|
||||
|
||||
// ID matches?
|
||||
if (!itemID.equals(id)) { return false; }
|
||||
|
||||
// If the type matches too, we are set.
|
||||
return asNBT.getType().equals(type);
|
||||
}
|
||||
//endregion
|
||||
}
|
@ -150,7 +150,15 @@ public class MMOItemBuilder {
|
||||
|
||||
// Merge
|
||||
if (modifierData == null) { modifierData = data; }
|
||||
else { ((Mergeable) modifierData).merge(data); }
|
||||
else {
|
||||
try {
|
||||
((Mergeable) modifierData).merge(data);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
|
||||
MMOItems.print(null, "Could not merge $f{2}$b modifier data into $f{3}$b of $e{4}$b when generating $r{0} {1}$b. ", "Item Generation", mmoitem.getType().toString(), mmoitem.getId(), data.getClass().getSimpleName(), modifierData.getClass().getSimpleName(), stat.getId());
|
||||
modifierData = data;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user