diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/ErrorReport.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/ErrorReport.java index 930c7fe48..edaf225ce 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/ErrorReport.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/ErrorReport.java @@ -8,6 +8,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.function.Function; import java.util.logging.Level; @@ -41,7 +42,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun; public class ErrorReport { private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm", Locale.ROOT); - private static int count; + private static final AtomicInteger count = new AtomicInteger(0); private SlimefunAddon addon; private T throwable; @@ -124,12 +125,12 @@ public class ErrorReport { * @return The amount of {@link ErrorReport ErrorReports} created. */ public static int count() { - return count; + return count.get(); } private void print(@Nonnull Consumer printer) { this.file = getNewFile(); - count++; + count.incrementAndGet(); try (PrintStream stream = new PrintStream(file, StandardCharsets.UTF_8.name())) { stream.println(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index ac30d55ff..db3043ab1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -404,6 +404,8 @@ public final class PlayerProfile { * @return Whether the {@link PlayerProfile} was already loaded */ public static boolean request(@Nonnull OfflinePlayer p) { + Validate.notNull(p, "Cannot request a Profile for null"); + if (!SlimefunPlugin.getRegistry().getPlayerProfiles().containsKey(p.getUniqueId())) { // Should probably prevent multiple requests for the same profile in the future Bukkit.getScheduler().runTaskAsynchronously(SlimefunPlugin.instance(), () -> { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java index 5201b10e9..c0a40bf01 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java @@ -5,6 +5,7 @@ import java.util.Set; import java.util.stream.Stream; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -24,16 +25,19 @@ class PlaceholderAPIHook extends PlaceholderExpansion { this.author = plugin.getDescription().getAuthors().toString(); } + @Nonnull @Override public String getIdentifier() { return "slimefun"; } + @Nonnull @Override public String getVersion() { return version; } + @Nonnull @Override public String getAuthor() { return author; @@ -49,9 +53,18 @@ class PlaceholderAPIHook extends PlaceholderExpansion { return true; } + private boolean isPlaceholder(@Nullable OfflinePlayer p, boolean requiresProfile, @Nonnull String params, @Nonnull String placeholder) { + if (requiresProfile) { + return p != null && placeholder.equals(params) && PlayerProfile.request(p); + } + else { + return placeholder.equals(params); + } + } + @Override - public String onRequest(OfflinePlayer p, String params) { - if (params.equals("researches_total_xp_levels_spent") && PlayerProfile.request(p)) { + public String onRequest(@Nullable OfflinePlayer p, @Nonnull String params) { + if (isPlaceholder(p, true, params, "researches_total_xp_levels_spent")) { Optional profile = PlayerProfile.find(p); if (profile.isPresent()) { @@ -60,7 +73,7 @@ class PlaceholderAPIHook extends PlaceholderExpansion { } } - if (params.equals("researches_total_researches_unlocked") && PlayerProfile.request(p)) { + if (isPlaceholder(p, true, params, "researches_total_researches_unlocked")) { Optional profile = PlayerProfile.find(p); if (profile.isPresent()) { @@ -69,11 +82,11 @@ class PlaceholderAPIHook extends PlaceholderExpansion { } } - if (params.equals("researches_total_researches")) { + if (isPlaceholder(p, false, params, "researches_total_researches")) { return String.valueOf(SlimefunPlugin.getRegistry().getResearches().size()); } - if (params.equals("researches_percentage_researches_unlocked") && PlayerProfile.request(p)) { + if (isPlaceholder(p, true, params, "researches_percentage_researches_unlocked")) { Optional profile = PlayerProfile.find(p); if (profile.isPresent()) { @@ -82,7 +95,7 @@ class PlaceholderAPIHook extends PlaceholderExpansion { } } - if (params.equals("researches_title") && PlayerProfile.request(p)) { + if (isPlaceholder(p, true, params, "researches_title")) { Optional profile = PlayerProfile.find(p); if (profile.isPresent()) { @@ -90,20 +103,17 @@ class PlaceholderAPIHook extends PlaceholderExpansion { } } - if (params.equals("gps_complexity")) { + if (isPlaceholder(p, false, params, "gps_complexity") && p != null) { return String.valueOf(SlimefunPlugin.getGPSNetwork().getNetworkComplexity(p.getUniqueId())); } - if (params.equals("timings_lag")) { + if (isPlaceholder(p, false, params, "timings_lag")) { return SlimefunPlugin.getProfiler().getTime(); } - if (params.equals("language")) { - if (!(p instanceof Player)) { - return "Unknown"; - } - - return SlimefunPlugin.getLocalization().getLanguage((Player) p).getName((Player) p); + if (isPlaceholder(p, false, params, "language") && p instanceof Player) { + Player player = (Player) p; + return SlimefunPlugin.getLocalization().getLanguage(player).getName(player); } return null; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java b/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java index 916e4780c..feb7253df 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/SlimefunItemStack.java @@ -33,7 +33,7 @@ import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -public class SlimefunItemStack extends CustomItem { +public class SlimefunItemStack extends CustomItem implements Cloneable { private String id; private ImmutableItemMeta immutableMeta; @@ -243,16 +243,6 @@ public class SlimefunItemStack extends CustomItem { locked = true; } - @Override - public ItemStack clone() { - return new SlimefunItemStack(id, this); - } - - @Override - public String toString() { - return "SlimefunItemStack (" + id + (getAmount() > 1 ? (" x " + getAmount()) : "") + ')'; - } - @Nonnull public Optional getSkullTexture() { return Optional.ofNullable(texture); @@ -292,4 +282,26 @@ public class SlimefunItemStack extends CustomItem { throw new IllegalArgumentException("The provided texture for Item \"" + id + "\" does not seem to be a valid texture String!"); } } + + @Override + public ItemStack clone() { + return new SlimefunItemStack(id, this); + } + + @Override + public String toString() { + return "SlimefunItemStack (" + id + (getAmount() > 1 ? (" x " + getAmount()) : "") + ')'; + } + + @Override + public final boolean equals(Object obj) { + // We don't want people to override this, it should use the super method + return super.equals(obj); + } + + @Override + public final int hashCode() { + // We don't want people to override this, it should use the super method + return super.hashCode(); + } }