mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Undid formatting
This commit is contained in:
parent
aa456901e4
commit
e32b6ff064
@ -51,6 +51,7 @@ import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
* @author Walshy
|
||||
* @author Sfiguz7
|
||||
*/
|
||||
public final class SlimefunUtils {
|
||||
|
||||
@ -63,7 +64,8 @@ public final class SlimefunUtils {
|
||||
* This method quickly returns whether an {@link Item} was marked as "no_pickup" by
|
||||
* a Slimefun device.
|
||||
*
|
||||
* @param item The {@link Item} to query
|
||||
* @param item
|
||||
* The {@link Item} to query
|
||||
* @return Whether the {@link Item} is excluded from being picked up
|
||||
*/
|
||||
public static boolean hasNoPickupFlag(@Nonnull Item item) {
|
||||
@ -74,8 +76,10 @@ public final class SlimefunUtils {
|
||||
* This will prevent the given {@link Item} from being picked up.
|
||||
* This is useful for display items which the {@link AncientPedestal} uses.
|
||||
*
|
||||
* @param item The {@link Item} to prevent from being picked up
|
||||
* @param context The context in which this {@link Item} was flagged
|
||||
* @param item
|
||||
* The {@link Item} to prevent from being picked up
|
||||
* @param context
|
||||
* The context in which this {@link Item} was flagged
|
||||
*/
|
||||
public static void markAsNoPickup(@Nonnull Item item, @Nonnull String context) {
|
||||
item.setMetadata(NO_PICKUP_METADATA, new FixedMetadataValue(Slimefun.instance(), context));
|
||||
@ -90,7 +94,8 @@ public final class SlimefunUtils {
|
||||
/**
|
||||
* This method checks whether the given {@link ItemStack} is considered {@link Soulbound}.
|
||||
*
|
||||
* @param item The {@link ItemStack} to check for
|
||||
* @param item
|
||||
* The {@link ItemStack} to check for
|
||||
* @return Whether the given item is soulbound
|
||||
*/
|
||||
public static boolean isSoulbound(@Nullable ItemStack item) {
|
||||
@ -102,9 +107,11 @@ public final class SlimefunUtils {
|
||||
* If the provided item is a {@link SlimefunItem} then this method will also check that the item
|
||||
* is enabled in the provided {@link World}.
|
||||
*
|
||||
* @param item The {@link ItemStack} to check for
|
||||
* @param world The {@link World} to check if the {@link SlimefunItem} is enabled in if applicable.
|
||||
* If {@code null} then this will not do a world check.
|
||||
* @param item
|
||||
* The {@link ItemStack} to check for
|
||||
* @param world
|
||||
* The {@link World} to check if the {@link SlimefunItem} is enabled in if applicable.
|
||||
* If {@code null} then this will not do a world check.
|
||||
* @return Whether the given item is soulbound
|
||||
*/
|
||||
public static boolean isSoulbound(@Nullable ItemStack item, @Nullable World world) {
|
||||
@ -149,8 +156,10 @@ public final class SlimefunUtils {
|
||||
* by {@link #isSoulbound(ItemStack)}.<br>
|
||||
* If false is passed, this property will be removed.
|
||||
*
|
||||
* @param item The {@link ItemStack} you want to add/remove Soulbound from.
|
||||
* @param makeSoulbound If they item should be soulbound.
|
||||
* @param item
|
||||
* The {@link ItemStack} you want to add/remove Soulbound from.
|
||||
* @param makeSoulbound
|
||||
* If they item should be soulbound.
|
||||
* @see #isSoulbound(ItemStack)
|
||||
*/
|
||||
public static void setSoulbound(@Nullable ItemStack item, boolean makeSoulbound) {
|
||||
@ -189,7 +198,8 @@ public final class SlimefunUtils {
|
||||
/**
|
||||
* This method checks whether the given {@link ItemStack} is radioactive.
|
||||
*
|
||||
* @param item The {@link ItemStack} to check
|
||||
* @param item
|
||||
* The {@link ItemStack} to check
|
||||
* @return Whether this {@link ItemStack} is radioactive or not
|
||||
*/
|
||||
public static boolean isRadioactive(@Nullable ItemStack item) {
|
||||
@ -200,11 +210,11 @@ public final class SlimefunUtils {
|
||||
* This method returns an {@link ItemStack} for the given texture.
|
||||
* The result will be a Player Head with this texture.
|
||||
*
|
||||
* @param texture The texture for this head (base64 or hash)
|
||||
* @param texture
|
||||
* The texture for this head (base64 or hash)
|
||||
* @return An {@link ItemStack} with this Head texture
|
||||
*/
|
||||
public static @Nonnull
|
||||
ItemStack getCustomHead(@Nonnull String texture) {
|
||||
public static @Nonnull ItemStack getCustomHead(@Nonnull String texture) {
|
||||
Validate.notNull(texture, "The provided texture is null");
|
||||
|
||||
if (Slimefun.instance() == null) {
|
||||
@ -219,8 +229,7 @@ public final class SlimefunUtils {
|
||||
String base64 = texture;
|
||||
|
||||
if (CommonPatterns.HEXADECIMAL.matcher(texture).matches()) {
|
||||
base64 = Base64.getEncoder().encodeToString(("{\"textures\":{\"SKIN\":{\"url\":\"http://textures" +
|
||||
".minecraft.net/texture/" + texture + "\"}}}").getBytes(StandardCharsets.UTF_8));
|
||||
base64 = Base64.getEncoder().encodeToString(("{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + texture + "\"}}}").getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
PlayerSkin skin = PlayerSkin.fromBase64(base64);
|
||||
@ -254,8 +263,7 @@ public final class SlimefunUtils {
|
||||
return isItemSimilar(item, sfitem, checkLore, true);
|
||||
}
|
||||
|
||||
public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore,
|
||||
boolean checkAmount) {
|
||||
public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount) {
|
||||
if (item == null) {
|
||||
return sfitem == null;
|
||||
} else if (sfitem == null) {
|
||||
@ -268,8 +276,6 @@ public final class SlimefunUtils {
|
||||
return ((SlimefunItemStack) item).getItemId().equals(((SlimefunItemStack) sfitem).getItemId());
|
||||
} else if (item.hasItemMeta()) {
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
boolean checkCustomModelData =
|
||||
Slimefun.getIntegrations().isCustomItem(item) || Slimefun.getIntegrations().isCustomItem(sfitem);
|
||||
|
||||
if (sfitem instanceof SlimefunItemStack) {
|
||||
Optional<String> id = Slimefun.getItemDataService().getItemData(itemMeta);
|
||||
@ -279,9 +285,9 @@ public final class SlimefunUtils {
|
||||
}
|
||||
|
||||
ItemMetaSnapshot meta = ((SlimefunItemStack) sfitem).getItemMetaSnapshot();
|
||||
return equalsItemMeta(itemMeta, meta, checkLore, checkCustomModelData);
|
||||
return equalsItemMeta(itemMeta, meta, checkLore);
|
||||
} else if (sfitem.hasItemMeta()) {
|
||||
return equalsItemMeta(itemMeta, sfitem.getItemMeta(), checkLore, checkCustomModelData);
|
||||
return equalsItemMeta(itemMeta, sfitem.getItemMeta(), checkLore);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -290,8 +296,7 @@ public final class SlimefunUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean equalsItemMeta(@Nonnull ItemMeta itemMeta, @Nonnull ItemMetaSnapshot meta,
|
||||
boolean checkLore, boolean checkCustomModelData) {
|
||||
private static boolean equalsItemMeta(@Nonnull ItemMeta itemMeta, @Nonnull ItemMetaSnapshot meta, boolean checkLore) {
|
||||
Optional<String> displayName = meta.getDisplayName();
|
||||
|
||||
if (itemMeta.hasDisplayName() != displayName.isPresent()) {
|
||||
@ -309,19 +314,15 @@ public final class SlimefunUtils {
|
||||
}
|
||||
|
||||
// Fixes #3133: name and lore are not enough
|
||||
if (checkCustomModelData) {
|
||||
OptionalInt itemCustomModelData = meta.getCustomModelData();
|
||||
if (itemMeta.hasCustomModelData() && itemCustomModelData.isPresent() && itemMeta.getCustomModelData() != itemCustomModelData.getAsInt()) {
|
||||
return false;
|
||||
} else {
|
||||
return itemMeta.hasCustomModelData() == itemCustomModelData.isPresent();
|
||||
}
|
||||
OptionalInt itemCustomModelData = meta.getCustomModelData();
|
||||
if (itemMeta.hasCustomModelData() && itemCustomModelData.isPresent() && itemMeta.getCustomModelData() != itemCustomModelData.getAsInt()) {
|
||||
return false;
|
||||
} else {
|
||||
return itemMeta.hasCustomModelData() == itemCustomModelData.isPresent();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean equalsItemMeta(@Nonnull ItemMeta itemMeta, @Nonnull ItemMeta sfitemMeta, boolean checkLore
|
||||
, boolean checkCustomModelData) {
|
||||
private static boolean equalsItemMeta(@Nonnull ItemMeta itemMeta, @Nonnull ItemMeta sfitemMeta, boolean checkLore) {
|
||||
if (itemMeta.hasDisplayName() != sfitemMeta.hasDisplayName()) {
|
||||
return false;
|
||||
} else if (itemMeta.hasDisplayName() && sfitemMeta.hasDisplayName() && !itemMeta.getDisplayName().equals(sfitemMeta.getDisplayName())) {
|
||||
@ -337,14 +338,12 @@ public final class SlimefunUtils {
|
||||
}
|
||||
|
||||
// Fixes #3133: name and lore are not enough
|
||||
if (checkCustomModelData) {
|
||||
boolean hasItemMetaCustomModelData = itemMeta.hasCustomModelData();
|
||||
boolean hasSfItemMetaCustomModelData = sfitemMeta.hasCustomModelData();
|
||||
if (hasItemMetaCustomModelData && hasSfItemMetaCustomModelData && itemMeta.getCustomModelData() != sfitemMeta.getCustomModelData()) {
|
||||
return false;
|
||||
} else if (hasItemMetaCustomModelData != hasSfItemMetaCustomModelData) {
|
||||
return false;
|
||||
}
|
||||
boolean hasItemMetaCustomModelData = itemMeta.hasCustomModelData();
|
||||
boolean hasSfItemMetaCustomModelData = sfitemMeta.hasCustomModelData();
|
||||
if (hasItemMetaCustomModelData && hasSfItemMetaCustomModelData && itemMeta.getCustomModelData() != sfitemMeta.getCustomModelData()) {
|
||||
return false;
|
||||
} else if (hasItemMetaCustomModelData != hasSfItemMetaCustomModelData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (itemMeta instanceof PotionMeta && sfitemMeta instanceof PotionMeta) {
|
||||
@ -358,8 +357,11 @@ public final class SlimefunUtils {
|
||||
* This checks if the two provided lores are equal.
|
||||
* This method will ignore any lines such as the soulbound one.
|
||||
*
|
||||
* @param lore1 The first lore
|
||||
* @param lore2 The second lore
|
||||
* @param lore1
|
||||
* The first lore
|
||||
* @param lore2
|
||||
* The second lore
|
||||
*
|
||||
* @return Whether the two lores are equal
|
||||
*/
|
||||
public static boolean equalsLore(@Nonnull List<String> lore1, @Nonnull List<String> lore2) {
|
||||
@ -414,9 +416,13 @@ public final class SlimefunUtils {
|
||||
* <p>
|
||||
* If you already have an instance of {@link SlimefunItem}, please use {@link SlimefunItem#canUse(Player, boolean)}.
|
||||
*
|
||||
* @param p The {@link Player}
|
||||
* @param item The {@link ItemStack} to check
|
||||
* @param sendMessage Whether to send a message response to the {@link Player}
|
||||
* @param p
|
||||
* The {@link Player}
|
||||
* @param item
|
||||
* The {@link ItemStack} to check
|
||||
* @param sendMessage
|
||||
* Whether to send a message response to the {@link Player}
|
||||
*
|
||||
* @return Whether the {@link Player} is able to use that item.
|
||||
*/
|
||||
public static boolean canPlayerUseItem(@Nonnull Player p, @Nullable ItemStack item, boolean sendMessage) {
|
||||
@ -436,16 +442,18 @@ public final class SlimefunUtils {
|
||||
* This method automatically calls a {@link SlimefunItemSpawnEvent} to allow
|
||||
* other plugins to catch the item being dropped.
|
||||
*
|
||||
* @param loc The {@link Location} where to drop the item
|
||||
* @param item The {@link ItemStack} to drop
|
||||
* @param reason The {@link ItemSpawnReason} why the item is being dropped
|
||||
* @param addRandomOffset Whether a random offset should be added (see {@link World#dropItemNaturally(Location,
|
||||
* ItemStack)})
|
||||
* @param loc
|
||||
* The {@link Location} where to drop the item
|
||||
* @param item
|
||||
* The {@link ItemStack} to drop
|
||||
* @param reason
|
||||
* The {@link ItemSpawnReason} why the item is being dropped
|
||||
* @param addRandomOffset
|
||||
* Whether a random offset should be added (see {@link World#dropItemNaturally(Location, ItemStack)})
|
||||
* @return The dropped {@link Item} (or null if the {@link SlimefunItemSpawnEvent} was cancelled)
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public static @Nullable
|
||||
Item spawnItem(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset) {
|
||||
public static @Nullable Item spawnItem(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset) {
|
||||
SlimefunItemSpawnEvent event = new SlimefunItemSpawnEvent(loc, item, reason);
|
||||
Slimefun.instance().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user