1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

refactored ternary operators

This commit is contained in:
iTwins 2023-08-20 03:42:30 +02:00
parent 7da1af0383
commit 1315e5a8c9
2 changed files with 21 additions and 3 deletions

View File

@ -28,6 +28,7 @@ import io.github.thebusybiscuit.slimefun4.api.events.GEOResourceGenerationEvent;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOMiner;
import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOScanner;
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
@ -236,13 +237,13 @@ public class ResourceManager {
for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) {
GEOResource resource = resources.get(i);
OptionalInt optional = getSupplies(resource, block.getWorld(), x, z);
int supplies = optional.isPresent() ? optional.getAsInt() : generate(resource, block.getWorld(), x, block.getY(), z);
String suffix = Slimefun.getLocalization().getResourceString(p, supplies == 1 ? "tooltips.unit" : "tooltips.units");
int supplies = optional.orElse(generate(resource, block.getWorld(), x, block.getY(), z));
String suffix = Slimefun.getLocalization().getResourceString(p, ChatUtils.checkPlurality("tooltips.unit", supplies));
ItemStack item = new CustomItemStack(resource.getItem(), "&f" + resource.getName(p), "&8\u21E8 &e" + supplies + ' ' + suffix);
if (supplies > 1) {
item.setAmount(supplies > item.getMaxStackSize() ? item.getMaxStackSize() : supplies);
item.setAmount(Math.min(supplies, item.getMaxStackSize()));
}
menu.addItem(index, item, ChestMenuUtils.getEmptyClickHandler());

View File

@ -80,4 +80,21 @@ public final class ChatUtils {
return builder.toString();
}
/**
* This method adds an s to a string if the supplied integer is not 1.
*
* @param string
* The string to potentially pluralize
* @param count
* The amount of things
* @return
* <code>string</code> if <code>count</code> is 1 else <code>string + "s"</code>
*/
public static @Nonnull String checkPlurality(@Nonnull String string, int count) {
if (count == 1) {
return string;
}
return string + "s";
}
}