1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45:51 +00:00

Undid formatting

This commit is contained in:
Sfiguz7 2021-09-22 21:38:35 +02:00
parent aa456901e4
commit e32b6ff064

View File

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