Code cleanup

Former-commit-id: cca1c3dc1449049fa9e416b03b30cbac3e21f438
Former-commit-id: 42ebe78012b208971120659cf8cb00f2fe5cc47c
This commit is contained in:
Ghost_chu committed 2019-12-12 15:18:27 +08:00
1 parent 17f24acbd1
commit f2c606c811
13 files changed
+57 -60

No files matched your search

@@ -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();
@@ -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) {
@@ -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;
@@ -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");
@@ -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;
}
@@ -28,7 +28,6 @@ public class PermissionManager {
// try {
// switch (providerType) {
// case BUKKIT:
//noinspection DuplicateBranchesInSwitch
provider = new BukkitPermsProvider();
// break;
// case VAULT:
@@ -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());
@@ -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<Enchantment, Integer> 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);
}
@@ -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<String> 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<String> 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<String> lore = new ArrayList<String>();
java.util.List<String> lore = new ArrayList<>();
Gson gson = new Gson();
ShopProtectionFlag shopProtectionFlag = createShopProtectionFlag(itemStack,shop);
String protectFlag = gson.toJson(shopProtectionFlag);
@@ -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<String> 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<String> 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 {
@@ -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<Attribute> set1 = meta1.getAttributeModifiers().keySet();
Set<Attribute> set2 = meta2.getAttributeModifiers().keySet();
Set<Attribute> set1 = Objects.requireNonNull(meta1.getAttributeModifiers()).keySet();
Set<Attribute> set2 = Objects.requireNonNull(meta2.getAttributeModifiers()).keySet();
for (Attribute att : set1) {
if (!set2.contains(att)) {
return false;
@@ -244,7 +241,7 @@ class ItemMetaMatcher {
}
List<String> lores1 = meta1.getLore();
List<String> 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;
}
}
@@ -106,7 +106,6 @@ public class Util {
if (!isShoppables(b.getType())) {
return false;
}
//noinspection RedundantIfStatement
if (isBlacklistWorld(b.getWorld())) {
return false;
}
@@ -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());
}