diff --git a/src/main/java/org/maxgamer/quickshop/Economy/Economy_Vault.java b/src/main/java/org/maxgamer/quickshop/Economy/Economy_Vault.java index 618111e46..d727823d3 100644 --- a/src/main/java/org/maxgamer/quickshop/Economy/Economy_Vault.java +++ b/src/main/java/org/maxgamer/quickshop/Economy/Economy_Vault.java @@ -15,6 +15,7 @@ import org.jetbrains.annotations.Nullable; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Util.Util; +import java.util.Objects; import java.util.UUID; public class Economy_Vault implements EconomyCore, Listener { @@ -114,7 +115,7 @@ public class Economy_Vault implements EconomyCore, Listener { return "Error"; } try { - String formatedBalance = this.vault.format(balance); + String formatedBalance = Objects.requireNonNull(this.vault).format(balance); if (formatedBalance == null)//Stupid Ecosystem { return formatInternal(balance); @@ -133,7 +134,7 @@ public class Economy_Vault implements EconomyCore, Listener { } OfflinePlayer p = Bukkit.getOfflinePlayer(name); try { - return this.vault.depositPlayer(p, amount).transactionSuccess(); + return Objects.requireNonNull(this.vault).depositPlayer(p, amount).transactionSuccess(); } catch (Throwable t) { plugin.getSentryErrorReporter().ignoreThrow(); t.printStackTrace(); @@ -155,7 +156,7 @@ public class Economy_Vault implements EconomyCore, Listener { return false; } } - return this.vault.withdrawPlayer(p, amount).transactionSuccess(); + return Objects.requireNonNull(this.vault).withdrawPlayer(p, amount).transactionSuccess(); } catch (Throwable t) { plugin.getSentryErrorReporter().ignoreThrow(); t.printStackTrace(); @@ -173,7 +174,7 @@ public class Economy_Vault implements EconomyCore, Listener { OfflinePlayer pFrom = Bukkit.getOfflinePlayer(from); OfflinePlayer pTo = Bukkit.getOfflinePlayer(to); try { - if (this.vault.getBalance(pFrom) >= amount) { + if (Objects.requireNonNull(this.vault).getBalance(pFrom) >= amount) { if (this.vault.withdrawPlayer(pFrom, amount).transactionSuccess()) { if (!this.vault.depositPlayer(pTo, amount).transactionSuccess()) { this.vault.depositPlayer(pFrom, amount); @@ -206,7 +207,7 @@ public class Economy_Vault implements EconomyCore, Listener { } try { - return this.vault.getBalance(offlinePlayer); + return Objects.requireNonNull(this.vault).getBalance(offlinePlayer); } catch (Throwable t) { plugin.getSentryErrorReporter().ignoreThrow(); t.printStackTrace(); diff --git a/src/main/java/org/maxgamer/quickshop/Metrics.java b/src/main/java/org/maxgamer/quickshop/Metrics.java index 63b738450..83ecaea16 100644 --- a/src/main/java/org/maxgamer/quickshop/Metrics.java +++ b/src/main/java/org/maxgamer/quickshop/Metrics.java @@ -11,7 +11,6 @@ import org.json.simple.JSONObject; import javax.net.ssl.HttpsURLConnection; import java.io.*; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.nio.charset.StandardCharsets; @@ -216,7 +215,7 @@ public class Metrics { for (RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) { try { pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider())); - } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { + } catch (Exception ignored) { } } } catch (NoSuchFieldException ignored) { diff --git a/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/com/sk89q/worldedit/util/net/HttpRequest.java b/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/com/sk89q/worldedit/util/net/HttpRequest.java index 871b05a3b..624e1c898 100644 --- a/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/com/sk89q/worldedit/util/net/HttpRequest.java +++ b/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/com/sk89q/worldedit/util/net/HttpRequest.java @@ -198,9 +198,8 @@ public class HttpRequest implements Closeable { * * @return the buffered response * @throws java.io.IOException on I/O error - * @throws InterruptedException on interruption */ - public BufferedResponse returnContent() throws IOException, InterruptedException { + public BufferedResponse returnContent() throws IOException { if (inputStream == null) { throw new IllegalArgumentException("No input stream available"); } @@ -223,9 +222,8 @@ public class HttpRequest implements Closeable { * @param file the file * @return this object * @throws java.io.IOException on I/O error - * @throws InterruptedException on interruption */ - public HttpRequest saveContent(File file) throws IOException, InterruptedException { + public HttpRequest saveContent(File file) throws IOException { try (Closer closer = Closer.create()) { FileOutputStream fos = closer.register(new FileOutputStream(file)); @@ -243,9 +241,8 @@ public class HttpRequest implements Closeable { * @param out the output stream * @return this object * @throws java.io.IOException on I/O error - * @throws InterruptedException on interruption */ - public HttpRequest saveContent(OutputStream out) throws IOException, InterruptedException { + public HttpRequest saveContent(OutputStream out) throws IOException { BufferedInputStream bis; try { @@ -276,7 +273,7 @@ public class HttpRequest implements Closeable { } @Override - public void close() throws IOException { + public void close() { if (conn != null) conn.disconnect(); } @@ -400,7 +397,7 @@ public class HttpRequest implements Closeable { /** * Used to buffer the response in memory. */ - public class BufferedResponse { + public static class BufferedResponse { private final byte[] data; private BufferedResponse(byte[] data) { @@ -433,9 +430,8 @@ public class HttpRequest implements Closeable { * @param file the file * @return this object * @throws java.io.IOException on I/O error - * @throws InterruptedException on interruption */ - public BufferedResponse saveContent(File file) throws IOException, InterruptedException { + public BufferedResponse saveContent(File file) throws IOException { try (Closer closer = Closer.create()) { file.getParentFile().mkdirs(); @@ -454,9 +450,8 @@ public class HttpRequest implements Closeable { * @param out the output stream * @return this object * @throws java.io.IOException on I/O error - * @throws InterruptedException on interruption */ - public BufferedResponse saveContent(OutputStream out) throws IOException, InterruptedException { + public BufferedResponse saveContent(OutputStream out) throws IOException { out.write(data); return this; diff --git a/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/com/sk89q/worldedit/util/paste/EngineHubPaster.java b/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/com/sk89q/worldedit/util/paste/EngineHubPaster.java index 2c38e8f29..b9f9077ec 100644 --- a/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/com/sk89q/worldedit/util/paste/EngineHubPaster.java +++ b/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/com/sk89q/worldedit/util/paste/EngineHubPaster.java @@ -47,7 +47,7 @@ public class EngineHubPaster { } @Override - public URL call() throws IOException, InterruptedException { + public URL call() throws IOException { HttpRequest.Form form = HttpRequest.Form.create(); form.add("content", content); form.add("from", "enginehub"); diff --git a/src/main/java/org/maxgamer/quickshop/Permission/LuckPermsProvider.java b/src/main/java/org/maxgamer/quickshop/Permission/LuckPermsProvider.java index c65c0e016..71d437303 100644 --- a/src/main/java/org/maxgamer/quickshop/Permission/LuckPermsProvider.java +++ b/src/main/java/org/maxgamer/quickshop/Permission/LuckPermsProvider.java @@ -10,6 +10,8 @@ import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.maxgamer.quickshop.Util.Util; +import java.util.Objects; + @Getter @Deprecated public class LuckPermsProvider implements PermissionProvider { @@ -32,8 +34,8 @@ public class LuckPermsProvider implements PermissionProvider { public boolean hasPermission(@NotNull CommandSender sender, @NotNull String permission) { if (sender instanceof OfflinePlayer) { try { - return api.getUser(((OfflinePlayer) sender).getUniqueId()).hasPermission(api.buildNode(permission).build()).asBoolean(); - } catch (NullPointerException npe) { + return Objects.requireNonNull(Objects.requireNonNull(api.getUser(((OfflinePlayer) sender).getUniqueId()))).hasPermission(api.buildNode(permission).build()).asBoolean(); + } catch (Exception npe) { Util.debugLog("Failed to get user " + sender.getName() + " 's LuckPerms permission infomation, return failed."); return false; } diff --git a/src/main/java/org/maxgamer/quickshop/Permission/PermissionManager.java b/src/main/java/org/maxgamer/quickshop/Permission/PermissionManager.java index fa54955c1..290a8ade9 100644 --- a/src/main/java/org/maxgamer/quickshop/Permission/PermissionManager.java +++ b/src/main/java/org/maxgamer/quickshop/Permission/PermissionManager.java @@ -28,7 +28,6 @@ public class PermissionManager { // try { // switch (providerType) { // case BUKKIT: - //noinspection DuplicateBranchesInSwitch provider = new BukkitPermsProvider(); // break; // case VAULT: diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java index f633b10aa..856036222 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java @@ -19,6 +19,8 @@ import org.maxgamer.quickshop.Event.ShopDisplayItemSpawnEvent; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Util.Util; +import java.util.Objects; + @ToString public class ArmorStandDisplayItem implements DisplayItem { @@ -219,9 +221,9 @@ public class ArmorStandDisplayItem implements DisplayItem { private void setPoseForArmorStand() { if (this.originalItemStack.getType().isBlock()) { - this.armorStand.setRightArmPose(new EulerAngle(-0.2, 0, 0)); + Objects.requireNonNull(this.armorStand).setRightArmPose(new EulerAngle(-0.2, 0, 0)); } else { - this.armorStand.setRightArmPose(new EulerAngle(-89.5, 0, 0)); + Objects.requireNonNull(this.armorStand).setRightArmPose(new EulerAngle(-89.5, 0, 0)); } } @@ -243,12 +245,12 @@ public class ArmorStandDisplayItem implements DisplayItem { @Override public void fixDisplayMoved() { - for (Entity entity : this.shop.getLocation().getWorld().getEntities()) { + for (Entity entity : Objects.requireNonNull(this.shop.getLocation().getWorld()).getEntities()) { if (!(entity instanceof ArmorStand)) { continue; } ArmorStand eArmorStand = (ArmorStand) entity; - if (eArmorStand.getUniqueId().equals(this.armorStand.getUniqueId())) { + if (eArmorStand.getUniqueId().equals(Objects.requireNonNull(this.armorStand).getUniqueId())) { Util.debugLog("Fixing moved ArmorStand displayItem " + eArmorStand.getUniqueId() + " at " + eArmorStand .getLocation()); eArmorStand.teleport(getDisplayLocation()); diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index d4a304b4e..cb429d415 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -123,7 +123,7 @@ public class ContainerShop implements Shop { while (remains > 0) { int stackSize = Math.min(remains, item.getMaxStackSize()); item.setAmount(stackSize); - inv.addItem(item); + Objects.requireNonNull(inv).addItem(item); remains -= stackSize; } this.setSignText(); @@ -214,7 +214,7 @@ public class ContainerShop implements Shop { int x = this.getLocation().getBlockX(); int y = this.getLocation().getBlockY(); int z = this.getLocation().getBlockZ(); - String world = this.getLocation().getWorld().getName(); + String world = Objects.requireNonNull(this.getLocation().getWorld()).getName(); int unlimited = this.isUnlimited() ? 1 : 0; try { plugin.getDatabaseHelper().updateShop(ShopModerator.serialize(this.moderator.clone()), this @@ -230,7 +230,7 @@ public class ContainerShop implements Shop { */ @Override public short getDurability() { - return (short) ((Damageable) this.item.getItemMeta()).getDamage(); + return (short) ((Damageable) Objects.requireNonNull(this.item.getItemMeta())).getDamage(); } /** @@ -311,7 +311,7 @@ public class ContainerShop implements Shop { // We can modify this, it is a copy. item.setAmount(stackSize); // Add the items to the players inventory - chestInv.addItem(item); + Objects.requireNonNull(chestInv).addItem(item); amount1 -= stackSize; } } @@ -362,7 +362,7 @@ public class ContainerShop implements Shop { int x = this.getLocation().getBlockX(); int y = this.getLocation().getBlockY(); int z = this.getLocation().getBlockZ(); - String world = this.getLocation().getWorld().getName(); + String world = Objects.requireNonNull(this.getLocation().getWorld()).getName(); // Refund if necessary if (plugin.getConfig().getBoolean("shop.refund")) { plugin.getEconomy().deposit(this.getOwner(), plugin.getConfig().getDouble("shop.cost")); @@ -440,7 +440,7 @@ public class ContainerShop implements Shop { while (remains > 0) { int stackSize = Math.min(remains, item.getMaxStackSize()); item.setAmount(stackSize); - inv.removeItem(item); + Objects.requireNonNull(inv).removeItem(item); remains -= stackSize; } this.setSignText(); @@ -504,7 +504,7 @@ public class ContainerShop implements Shop { amount -= stackSize; } } else { - ItemStack[] chestContents = this.getInventory().getContents(); + ItemStack[] chestContents = Objects.requireNonNull(this.getInventory()).getContents(); for (int i = 0; amount > 0 && i < chestContents.length; i++) { // Can't clone it here, it could be null ItemStack item = chestContents[i]; @@ -562,7 +562,7 @@ public class ContainerShop implements Shop { * @return The enchantments the shop has on its items. */ public @NotNull Map getEnchants() { - return this.item.getItemMeta().getEnchants(); + return Objects.requireNonNull(this.item.getItemMeta()).getEnchants(); } /** @@ -572,8 +572,8 @@ public class ContainerShop implements Shop { try { if (location.getBlock().getState().getType() == Material.ENDER_CHEST && plugin.getOpenInvPlugin() != null) { OpenInv openInv = ((OpenInv) plugin.getOpenInvPlugin()); - return openInv.getSpecialEnderChest(openInv.loadPlayer(Bukkit.getOfflinePlayer(this.moderator.getOwner() - )), Bukkit.getOfflinePlayer((this.moderator.getOwner())).isOnline()).getBukkitInventory(); + return openInv.getSpecialEnderChest(Objects.requireNonNull(openInv.loadPlayer(Bukkit.getOfflinePlayer(this.moderator.getOwner() + ))), Bukkit.getOfflinePlayer((this.moderator.getOwner())).isOnline()).getBukkitInventory(); } } catch (Exception e) { Util.debugLog(e.getMessage()); @@ -847,7 +847,7 @@ public class ContainerShop implements Shop { } this.isLoaded = true; - plugin.getShopManager().getLoadedShops().add(this); + Objects.requireNonNull(plugin.getShopManager().getLoadedShops()).add(this); checkContainer(); @@ -880,7 +880,7 @@ public class ContainerShop implements Shop { } update(); this.isLoaded = false; - plugin.getShopManager().getLoadedShops().remove(this); + Objects.requireNonNull(plugin.getShopManager().getLoadedShops()).remove(this); ShopUnloadEvent shopUnloadEvent = new ShopUnloadEvent(this); Bukkit.getPluginManager().callEvent(shopUnloadEvent); } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java index 8d16409b5..a653c33e4 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java @@ -13,6 +13,7 @@ import org.maxgamer.quickshop.Util.Util; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * @author Netherfoam A display item, that spawns a block above the chest and @@ -46,12 +47,12 @@ public interface DisplayItem { // return true; // } // } - if (!iMeta.hasLore()) { + if (!Objects.requireNonNull(iMeta).hasLore()) { return false; } List lores = iMeta.getLore(); Gson gson = new Gson(); - for (String lore : lores) { + for (String lore : Objects.requireNonNull(lores)) { try { if (!lore.startsWith("{")) { continue; @@ -98,7 +99,7 @@ public interface DisplayItem { } List lores = iMeta.getLore(); Gson gson = new Gson(); - for (String lore : lores) { + for (String lore : Objects.requireNonNull(lores)) { try { if (!lore.startsWith("{")) { continue; @@ -132,15 +133,15 @@ public interface DisplayItem { itemStack.setAmount(1); ItemMeta iMeta = itemStack.getItemMeta(); if (QuickShop.instance.getConfig().getBoolean("shop.display-item-use-name")) { - if (iMeta.hasDisplayName()) { + if (Objects.requireNonNull(iMeta).hasDisplayName()) { iMeta.setDisplayName(iMeta.getDisplayName()); } else { iMeta.setDisplayName(Util.getItemStackName(itemStack)); } } else { - iMeta.setDisplayName(null); + Objects.requireNonNull(iMeta).setDisplayName(null); } - java.util.List lore = new ArrayList(); + java.util.List lore = new ArrayList<>(); Gson gson = new Gson(); ShopProtectionFlag shopProtectionFlag = createShopProtectionFlag(itemStack,shop); String protectFlag = gson.toJson(shopProtectionFlag); diff --git a/src/main/java/org/maxgamer/quickshop/Shop/InventoryPreview.java b/src/main/java/org/maxgamer/quickshop/Shop/InventoryPreview.java index 1908e2486..1986465c4 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/InventoryPreview.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/InventoryPreview.java @@ -17,6 +17,7 @@ import org.maxgamer.quickshop.Util.Util; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * A class to create a GUI item preview quickly @@ -29,11 +30,11 @@ public class InventoryPreview implements Listener { if (stack == null) { return false; } - if (!stack.hasItemMeta() || !stack.getItemMeta().hasLore()) { + if (!stack.hasItemMeta() || !Objects.requireNonNull(stack.getItemMeta()).hasLore()) { return false; } List lores = stack.getItemMeta().getLore(); - for (String string : lores) { + for (String string : Objects.requireNonNull(lores)) { if ("QuickShop GUI preview item".equals(string)) { return true; } @@ -55,10 +56,10 @@ public class InventoryPreview implements Listener { public InventoryPreview(@NotNull ItemStack itemStack, @NotNull Player player) { this.itemStack = itemStack.clone(); this.player = player; - if (this.itemStack.getItemMeta().hasLore()) { + if (Objects.requireNonNull(this.itemStack.getItemMeta()).hasLore()) { ItemMeta itemMeta = this.itemStack.getItemMeta(); List lores = itemMeta.getLore(); - lores.add("QuickShop GUI preview item"); + Objects.requireNonNull(lores).add("QuickShop GUI preview item"); itemMeta.setLore(lores); this.itemStack.setItemMeta(itemMeta); } else { diff --git a/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java b/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java index aad7a8c24..97072b402 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java @@ -9,10 +9,7 @@ import org.bukkit.potion.PotionData; import org.jetbrains.annotations.Nullable; import org.maxgamer.quickshop.QuickShop; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * A util allow quickshop check item matches easy and quick. @@ -23,7 +20,7 @@ public class ItemMatcher { public ItemMatcher(QuickShop plugin) { this.plugin = plugin; - itemMetaMatcher = new ItemMetaMatcher(plugin.getConfig().getConfigurationSection("matcher.item")); + itemMetaMatcher = new ItemMetaMatcher(Objects.requireNonNull(plugin.getConfig().getConfigurationSection("matcher.item"))); } /** @@ -124,8 +121,8 @@ class ItemMetaMatcher { if (!meta2.hasAttributeModifiers()) { return false; } - Set set1 = meta1.getAttributeModifiers().keySet(); - Set set2 = meta2.getAttributeModifiers().keySet(); + Set set1 = Objects.requireNonNull(meta1.getAttributeModifiers()).keySet(); + Set set2 = Objects.requireNonNull(meta2.getAttributeModifiers()).keySet(); for (Attribute att : set1) { if (!set2.contains(att)) { return false; @@ -244,7 +241,7 @@ class ItemMetaMatcher { } List lores1 = meta1.getLore(); List lores2 = meta2.getLore(); - return Arrays.deepEquals(lores1.toArray(), lores2.toArray()); + return Arrays.deepEquals(Objects.requireNonNull(lores1).toArray(), Objects.requireNonNull(lores2).toArray()); } boolean matches(ItemStack requireStack, ItemStack givenStack) { @@ -341,7 +338,7 @@ class ItemMetaMatcher { if (!potion2.hasColor()) { return false; } else { - if (!potion1.getColor().equals(potion2.getColor())) { + if (!Objects.requireNonNull(potion1.getColor()).equals(potion2.getColor())) { return false; } } diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 1d85b3e29..b712b61c1 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -106,7 +106,6 @@ public class Util { if (!isShoppables(b.getType())) { return false; } - //noinspection RedundantIfStatement if (isBlacklistWorld(b.getWorld())) { return false; } diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/DisplayWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/DisplayWatcher.java index 25c5a4862..00d5dd58b 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/DisplayWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/DisplayWatcher.java @@ -7,6 +7,7 @@ import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Shop.Shop; import java.util.ArrayList; +import java.util.Objects; class DisplayRunnable implements Runnable { @Override @@ -55,7 +56,7 @@ public class DisplayWatcher { // if (!Util.isLoaded(shop.getLocation())) { // continue; // } - pendingCheckDisplay.addAll(plugin.getShopManager().getLoadedShops()); + pendingCheckDisplay.addAll(Objects.requireNonNull(plugin.getShopManager().getLoadedShops())); //} Bukkit.getScheduler().runTask(plugin, new DisplayRunnable()); }