Skip to content

Commit

Permalink
refactored ternary operators
Browse files Browse the repository at this point in the history
  • Loading branch information
iTwins committed Aug 20, 2023
1 parent 7da1af0 commit 1315e5a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;

Expand Down Expand Up @@ -236,13 +237,13 @@ public void scan(@Nonnull Player p, @Nonnull Block block, int page) {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,21 @@ public static void awaitInput(@Nonnull Player p, @Nonnull Consumer<String> callb
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";
}

}

0 comments on commit 1315e5a

Please sign in to comment.