mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-25 01:49:49 -05:00
Code cleanup
Former-commit-id: 10726ad0830d0dc44a52ff66fc4aa3b539f5fb77 Former-commit-id: c6e9b1113f3d0dc605c20d272c3f22a99067777e
This commit is contained in:
1 parent
f2c606c811
commit
bdbcc50494
20 files changed
+74
-46
No files matched your search
@@ -79,7 +79,7 @@ public class SubCommand_Debug implements CommandProcesser {
|
||||
public void printHandlerList(@NotNull CommandSender sender, String event) {
|
||||
try {
|
||||
final Class clazz = Class.forName(event);
|
||||
final Method method = clazz.getMethod("getHandlerList", (Class[]) new Class[0]);
|
||||
final Method method = clazz.getMethod("getHandlerList");
|
||||
final Object[] obj = new Object[0];
|
||||
final HandlerList list = (HandlerList) method.invoke(null, obj);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SubCommand_Price implements CommandProcesser {
|
||||
@@ -131,7 +132,7 @@ public class SubCommand_Price implements CommandProcesser {
|
||||
sender.sendMessage(
|
||||
MsgUtil.getMessage("fee-charged-for-price-change", sender, plugin.getEconomy().format(fee)));
|
||||
try {
|
||||
plugin.getEconomy().deposit(plugin.getServer().getOfflinePlayer(plugin.getConfig().getString("tax-account"))
|
||||
plugin.getEconomy().deposit(plugin.getServer().getOfflinePlayer(Objects.requireNonNull(plugin.getConfig().getString("tax-account")))
|
||||
.getUniqueId(), fee);
|
||||
} catch (Exception e) {
|
||||
e.getMessage();
|
||||
|
||||
@@ -61,7 +61,7 @@ public class SubCommand_SetOwner implements CommandProcesser {
|
||||
shop.setOwner(p.getUniqueId());
|
||||
//shop.setSignText();
|
||||
shop.update();
|
||||
sender.sendMessage(MsgUtil.getMessage("command.new-owner", sender, shopOwner == null ? "" : shopOwner));
|
||||
sender.sendMessage(MsgUtil.getMessage("command.new-owner", sender, shopOwner));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ public class Database {
|
||||
*
|
||||
* @return the database core object, that this database runs on.
|
||||
*/
|
||||
@NotNull
|
||||
public DatabaseCore getCore() {
|
||||
return core;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.maxgamer.quickshop.Database;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
@@ -74,6 +75,7 @@ public class MySQLCore implements DatabaseCore {
|
||||
*
|
||||
* @return The database connection
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
for (int i = 0; i < MAX_CONNECTIONS; i++) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.maxgamer.quickshop.Database;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -9,6 +10,7 @@ import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SQLiteCore implements DatabaseCore {
|
||||
private final File dbFile;
|
||||
@@ -34,7 +36,7 @@ public class SQLiteCore implements DatabaseCore {
|
||||
}
|
||||
synchronized (dbFile) {
|
||||
try {
|
||||
PreparedStatement ps = bs.prepareStatement(getConnection());
|
||||
PreparedStatement ps = bs.prepareStatement(Objects.requireNonNull(getConnection()));
|
||||
ps.execute();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
@@ -60,6 +62,7 @@ public class SQLiteCore implements DatabaseCore {
|
||||
*
|
||||
* @return The database connection
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
//import com.griefcraft.lwc.LWC;
|
||||
@@ -54,8 +55,8 @@ public class PlayerListener implements Listener {
|
||||
block = e.getClickedBlock();
|
||||
}
|
||||
|
||||
if (plugin.getShopManager().getShop(block.getLocation()) != null && (plugin.getShopManager().getShop(block
|
||||
.getLocation()).getOwner().equals(e.getPlayer().getUniqueId()) || e.getPlayer().isOp())) {
|
||||
if (plugin.getShopManager().getShop(Objects.requireNonNull(block).getLocation()) != null && (Objects.requireNonNull(plugin.getShopManager().getShop(block
|
||||
.getLocation())).getOwner().equals(e.getPlayer().getUniqueId()) || e.getPlayer().isOp())) {
|
||||
if (plugin.getConfig().getBoolean("shop.sneak-to-control") && !e.getPlayer().isSneaking()) {
|
||||
return;
|
||||
}
|
||||
@@ -65,8 +66,8 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
MsgUtil.sendControlPanelInfo(e.getPlayer(),
|
||||
plugin.getShopManager().getShop(block.getLocation()));
|
||||
plugin.getShopManager().getShop(block.getLocation()).setSignText();
|
||||
Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())));
|
||||
Objects.requireNonNull(plugin.getShopManager().getShop(block.getLocation())).setSignText();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +222,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
plugin.getShopManager().getActions().put(p.getUniqueId(), info);
|
||||
p.sendMessage(
|
||||
MsgUtil.getMessage("how-much-to-trade-for", p, Util.getItemStackName(e.getItem())));
|
||||
MsgUtil.getMessage("how-much-to-trade-for", p, Util.getItemStackName(Objects.requireNonNull(e.getItem()))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,6 +236,7 @@ public class PlayerListener implements Listener {
|
||||
Inventory inventory = e.getInventory();
|
||||
|
||||
// FIXME: 24/11/2019 inventory cannot be null
|
||||
//noinspection ConstantConditions
|
||||
if (inventory == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,9 +77,6 @@ public class WorldListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onWorldUnload(WorldUnloadEvent e) {
|
||||
// FIXME: 24/11/2019 It's not necessary but ok.
|
||||
if (e.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
// This is a workaround, because I don't get parsed chunk events when a
|
||||
// world unloads, I think...
|
||||
// So manually tell all of these shops they're unloaded.
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -47,6 +48,7 @@ public class Metrics {
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
@Nullable
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
@@ -162,7 +164,7 @@ public class Metrics {
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(Objects.requireNonNull(compressedData).length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
connection.setConnectTimeout(300000);
|
||||
@@ -326,6 +328,7 @@ public class Metrics {
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
@@ -375,6 +378,7 @@ public class Metrics {
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
@@ -423,6 +427,7 @@ public class Metrics {
|
||||
|
||||
protected abstract JSONObject getChartData() throws Exception;
|
||||
|
||||
@Nullable
|
||||
private JSONObject getRequestJsonObject() {
|
||||
JSONObject chart = new JSONObject();
|
||||
chart.put("chartId", chartId);
|
||||
@@ -462,6 +467,7 @@ public class Metrics {
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
@@ -511,6 +517,7 @@ public class Metrics {
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
@@ -556,6 +563,7 @@ public class Metrics {
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
@@ -594,6 +602,7 @@ public class Metrics {
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
@@ -625,6 +634,7 @@ public class Metrics {
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
+2
-2
@@ -206,7 +206,7 @@ public class HttpRequest implements Closeable {
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
int b = 0;
|
||||
int b;
|
||||
while ((b = inputStream.read()) != -1) {
|
||||
bos.write(b);
|
||||
}
|
||||
@@ -260,7 +260,7 @@ public class HttpRequest implements Closeable {
|
||||
bis = new BufferedInputStream(inputStream);
|
||||
|
||||
byte[] data = new byte[READ_BUFFER_SIZE];
|
||||
int len = 0;
|
||||
int len;
|
||||
while ((len = bis.read(data, 0, READ_BUFFER_SIZE)) >= 0) {
|
||||
out.write(data, 0, len);
|
||||
readBytes += len;
|
||||
|
||||
@@ -326,7 +326,7 @@ public class QuickShop extends JavaPlugin {
|
||||
}
|
||||
Util.debugLog("Unloading all shops...");
|
||||
try {
|
||||
this.getShopManager().getLoadedShops().forEach(Shop::onUnload);
|
||||
Objects.requireNonNull(this.getShopManager().getLoadedShops()).forEach(Shop::onUnload);
|
||||
} catch (Throwable th) {
|
||||
//ignore, we didn't care that
|
||||
}
|
||||
@@ -437,7 +437,7 @@ public class QuickShop extends JavaPlugin {
|
||||
if (limitCfg != null) {
|
||||
this.limit = limitCfg.getBoolean("use", false);
|
||||
limitCfg = limitCfg.getConfigurationSection("ranks");
|
||||
for (String key : limitCfg.getKeys(true)) {
|
||||
for (String key : Objects.requireNonNull(limitCfg).getKeys(true)) {
|
||||
limits.put(key, limitCfg.getInt(key));
|
||||
}
|
||||
}
|
||||
@@ -577,7 +577,7 @@ public class QuickShop extends JavaPlugin {
|
||||
try {
|
||||
ConfigurationSection dbCfg = getConfig().getConfigurationSection("database");
|
||||
DatabaseCore dbCore;
|
||||
if (dbCfg.getBoolean("mysql")) {
|
||||
if (Objects.requireNonNull(dbCfg).getBoolean("mysql")) {
|
||||
// MySQL database - Required database be created first.
|
||||
dbPrefix = dbCfg.getString("prefix");
|
||||
if (dbPrefix == null || "none".equals(dbPrefix)) {
|
||||
@@ -589,7 +589,7 @@ public class QuickShop extends JavaPlugin {
|
||||
String port = dbCfg.getString("port");
|
||||
String database = dbCfg.getString("database");
|
||||
boolean useSSL = dbCfg.getBoolean("usessl");
|
||||
dbCore = new MySQLCore(host, user, pass, database, port, useSSL);
|
||||
dbCore = new MySQLCore(Objects.requireNonNull(host), Objects.requireNonNull(user), Objects.requireNonNull(pass), Objects.requireNonNull(database), Objects.requireNonNull(port), useSSL);
|
||||
} else {
|
||||
// SQLite database - Doing this handles file creation
|
||||
dbCore = new SQLiteCore(new File(this.getDataFolder(), "shops.db"));
|
||||
@@ -1080,7 +1080,7 @@ public class QuickShop extends JavaPlugin {
|
||||
File file = new File(getDataFolder(), "example.config.yml");
|
||||
file.delete();
|
||||
try {
|
||||
Files.copy(getResource("config.yml"), file.toPath());
|
||||
Files.copy(Objects.requireNonNull(getResource("config.yml")), file.toPath());
|
||||
} catch (IOException ioe) {
|
||||
getLogger().warning("Error on spawning the example config file: " + ioe.getMessage());
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.maxgamer.quickshop.Shop;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -32,7 +31,6 @@ import java.util.logging.Level;
|
||||
* ChestShop core
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
public class ContainerShop implements Shop {
|
||||
private DisplayItem displayItem;
|
||||
@EqualsAndHashCode.Exclude
|
||||
|
||||
@@ -14,6 +14,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 RealDisplayItem implements DisplayItem {
|
||||
|
||||
@@ -45,7 +47,7 @@ public class RealDisplayItem implements DisplayItem {
|
||||
}
|
||||
//return !this.item.getLocation().equals(getDisplayLocation());
|
||||
/* We give 0.6 block to allow item drop on the chest, not floating on the air. */
|
||||
if (!this.item.getLocation().getWorld().equals(getDisplayLocation().getWorld())) {
|
||||
if (!Objects.requireNonNull(this.item.getLocation().getWorld()).equals(Objects.requireNonNull(getDisplayLocation()).getWorld())) {
|
||||
return true;
|
||||
}
|
||||
return this.item.getLocation().distance(getDisplayLocation()) > 0.6;
|
||||
@@ -69,15 +71,15 @@ public class RealDisplayItem 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 Item)) {
|
||||
continue;
|
||||
}
|
||||
Item eItem = (Item) entity;
|
||||
if (eItem.getUniqueId().equals(this.item.getUniqueId())) {
|
||||
if (eItem.getUniqueId().equals(Objects.requireNonNull(this.item).getUniqueId())) {
|
||||
Util.debugLog("Fixing moved Item displayItem " + eItem.getUniqueId() + " at " + eItem
|
||||
.getLocation());
|
||||
eItem.teleport(getDisplayLocation());
|
||||
eItem.teleport(Objects.requireNonNull(getDisplayLocation()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -175,7 +177,7 @@ public class RealDisplayItem implements DisplayItem {
|
||||
Util.debugLog(trace.getClassName() + "#" + trace.getMethodName() + "#" + trace.getLineNumber());
|
||||
}
|
||||
}
|
||||
if (!Util.isDisplayAllowBlock(getDisplayLocation().getBlock().getType())) {
|
||||
if (!Util.isDisplayAllowBlock(Objects.requireNonNull(getDisplayLocation()).getBlock().getType())) {
|
||||
Util.debugLog("Can't spawn the displayItem because there is not an AIR block above the shopblock.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -131,7 +132,7 @@ public class ShopLoader {
|
||||
|
||||
if(backupedDatabaseInDeleteProcess){
|
||||
plugin.getDatabaseHelper().removeShop(shop.getLocation().getBlockX(), shop
|
||||
.getLocation().getBlockY(), shop.getLocation().getBlockZ(), shop.getLocation().getWorld()
|
||||
.getLocation().getBlockY(), shop.getLocation().getBlockZ(), Objects.requireNonNull(shop.getLocation().getWorld())
|
||||
.getName());
|
||||
}
|
||||
|
||||
@@ -172,6 +173,7 @@ public class ShopLoader {
|
||||
return sum / m.length;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private boolean shopNullCheck(@Nullable Shop shop) {
|
||||
if (shop == null) {
|
||||
Util.debugLog("Shop Object is null");
|
||||
|
||||
@@ -306,7 +306,7 @@ public class ShopManager {
|
||||
|
||||
if (shop.isDoubleShop()) {
|
||||
Shop nextTo = shop.getAttachedShop();
|
||||
if (nextTo.getPrice() > shop.getPrice()) {
|
||||
if (Objects.requireNonNull(nextTo).getPrice() > shop.getPrice()) {
|
||||
// The one next to it must always be a
|
||||
// buying shop.
|
||||
p.sendMessage(MsgUtil.getMessage("buying-more-than-selling", p));
|
||||
@@ -458,7 +458,7 @@ public class ShopManager {
|
||||
// even if the shop is unlimited, the config option pay-unlimited-shop-owners is set to true,
|
||||
// the unlimited shop owner should have enough money.
|
||||
if (plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners")) {
|
||||
amount = Math.min(amount, (int) ownerCanAfford);
|
||||
amount = Math.min(amount, ownerCanAfford);
|
||||
}
|
||||
}
|
||||
if (amount < 1) { // typed 'all' but the auto set amount is 0
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -42,6 +43,7 @@ public abstract class ItemNMS {
|
||||
* @return The json for ItemStack.
|
||||
* @throws Throwable throws
|
||||
*/
|
||||
@Nullable
|
||||
public static String saveJsonfromNMS(@NotNull ItemStack bStack) throws Throwable {
|
||||
if (bStack.getType() == Material.AIR) {
|
||||
return null;
|
||||
|
||||
@@ -213,7 +213,7 @@ public class MsgUtil {
|
||||
String filled = fillArgs(raw, args);
|
||||
if (player != null) {
|
||||
if (plugin.getPlaceHolderAPI() != null && plugin.getPlaceHolderAPI().isEnabled()) {
|
||||
filled = PlaceholderAPI.setPlaceholders((OfflinePlayer) player, filled);
|
||||
filled = PlaceholderAPI.setPlaceholders(player, filled);
|
||||
Util.debugLog("Processed message " + filled + " by PlaceHolderAPI.");
|
||||
}
|
||||
}
|
||||
@@ -503,7 +503,7 @@ public class MsgUtil {
|
||||
}
|
||||
|
||||
public static @NotNull String getSubString(@NotNull String text, @NotNull String left, @NotNull String right) {
|
||||
String result = "";
|
||||
String result;
|
||||
int zLen;
|
||||
if (left.isEmpty()) {
|
||||
zLen = 0;
|
||||
@@ -530,7 +530,7 @@ public class MsgUtil {
|
||||
* @param shop Target shop
|
||||
*/
|
||||
public static void sendControlPanelInfo(@NotNull CommandSender sender, @NotNull Shop shop) {
|
||||
if ((sender instanceof Player && !((Player) sender).isOp()) && !QuickShop.getPermissionManager().hasPermission(sender, "quickshop.use")) {
|
||||
if ((sender instanceof Player && !sender.isOp()) && !QuickShop.getPermissionManager().hasPermission(sender, "quickshop.use")) {
|
||||
return;
|
||||
}
|
||||
if (plugin.getConfig().getBoolean("sneak-to-control")) {
|
||||
|
||||
@@ -238,7 +238,7 @@ public class Util {
|
||||
*/
|
||||
private static boolean equalsBlockStateLocation(@NotNull Location b1, @NotNull Location b2) {
|
||||
return (b1.getBlockX() == b2.getBlockX()) && (b1.getBlockY() == b2.getBlockY()) && (b1.getBlockZ() == b2
|
||||
.getBlockZ()) && (b1.getWorld().getName().equals(b2.getWorld().getName()));
|
||||
.getBlockZ()) && (Objects.requireNonNull(b1.getWorld()).getName().equals(Objects.requireNonNull(b2.getWorld()).getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,6 +287,7 @@ public class Util {
|
||||
* @param b The block which is attached
|
||||
* @return The block the sign is attached to
|
||||
*/
|
||||
@Nullable
|
||||
public static Block getAttached(@NotNull Block b) {
|
||||
if (b.getBlockData() instanceof Directional) {
|
||||
Directional directional = (Directional) b.getBlockData();
|
||||
@@ -309,7 +310,7 @@ public class Util {
|
||||
}
|
||||
|
||||
public static String getItemStackName(@NotNull ItemStack itemStack) {
|
||||
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName()) {
|
||||
if (itemStack.hasItemMeta() && Objects.requireNonNull(itemStack.getItemMeta()).hasDisplayName()) {
|
||||
return itemStack.getItemMeta().getDisplayName();
|
||||
}
|
||||
return MsgUtil.getItemi18n(itemStack.getType().name());
|
||||
@@ -321,6 +322,7 @@ public class Util {
|
||||
* @param itemStack Target ItemStack
|
||||
* @return LocalName or NULL
|
||||
*/
|
||||
@Nullable
|
||||
public static String getLocalizedName(@NotNull ItemStack itemStack) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta == null) {
|
||||
@@ -349,6 +351,7 @@ public class Util {
|
||||
* @param iStack itemstack
|
||||
* @return potion data, readable
|
||||
*/
|
||||
@Nullable
|
||||
public static String getPotiondata(@NotNull ItemStack iStack) {
|
||||
if ((iStack.getType() != Material.POTION) && (iStack.getType() != Material.LINGERING_POTION) && (iStack
|
||||
.getType() != Material.SPLASH_POTION)) {
|
||||
@@ -361,9 +364,9 @@ public class Util {
|
||||
PotionMeta pMeta = (PotionMeta) iStack.getItemMeta();
|
||||
//if (pMeta.getBasePotionData().getType() != null) {
|
||||
if (!(pMeta.getBasePotionData().isUpgraded())) {
|
||||
pEffects.add(ChatColor.BLUE + MsgUtil.getPotioni18n(pMeta.getBasePotionData().getType().getEffectType()));
|
||||
pEffects.add(ChatColor.BLUE + MsgUtil.getPotioni18n(Objects.requireNonNull(pMeta.getBasePotionData().getType().getEffectType())));
|
||||
} else {
|
||||
pEffects.add(ChatColor.BLUE + MsgUtil.getPotioni18n(pMeta.getBasePotionData().getType().getEffectType()) + " II");
|
||||
pEffects.add(ChatColor.BLUE + MsgUtil.getPotioni18n(Objects.requireNonNull(pMeta.getBasePotionData().getType().getEffectType())) + " II");
|
||||
}
|
||||
|
||||
//}
|
||||
@@ -403,6 +406,7 @@ public class Util {
|
||||
* @param b The chest to check.
|
||||
* @return the block which is also a chest and connected to b.
|
||||
*/
|
||||
@Nullable
|
||||
public static Block getSecondHalf(@NotNull Block b) {
|
||||
if (!isDoubleChest(b)) {
|
||||
Util.debugLog("Target block not a DoubleChest, ignored.");
|
||||
@@ -416,11 +420,11 @@ public class Util {
|
||||
InventoryHolder right = doubleChest.getRightSide();
|
||||
Chest leftC = (Chest) left;
|
||||
Chest rightC = (Chest) right;
|
||||
if (equalsBlockStateLocation(oneSideOfChest.getLocation(), rightC.getLocation())) {
|
||||
if (equalsBlockStateLocation(oneSideOfChest.getLocation(), Objects.requireNonNull(rightC).getLocation())) {
|
||||
Util.debugLog("The left side of the chest was found.");
|
||||
return leftC.getBlock();
|
||||
return Objects.requireNonNull(leftC).getBlock();
|
||||
}
|
||||
if (equalsBlockStateLocation(oneSideOfChest.getLocation(), leftC.getLocation())) {
|
||||
if (equalsBlockStateLocation(oneSideOfChest.getLocation(), Objects.requireNonNull(leftC).getLocation())) {
|
||||
Util.debugLog("The right side of the chest was found.");
|
||||
return rightC.getBlock();
|
||||
}
|
||||
@@ -440,6 +444,7 @@ public class Util {
|
||||
* @return the block which is also a chest and connected to b.
|
||||
* @deprecated
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public static Block getSecondHalf_old(@NotNull Block b) {
|
||||
// if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST)
|
||||
@@ -471,7 +476,7 @@ public class Util {
|
||||
Iterator<Shop> iterator = plugin.getShopManager().getShopIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Shop shop = iterator.next();
|
||||
if (shop.getLocation().getWorld().getName().equals(worldName)) {
|
||||
if (Objects.requireNonNull(shop.getLocation().getWorld()).getName().equals(worldName)) {
|
||||
cost++;
|
||||
}
|
||||
}
|
||||
@@ -576,6 +581,7 @@ public class Util {
|
||||
* @param filePath Target file
|
||||
* @return Byte array
|
||||
*/
|
||||
@Nullable
|
||||
public static byte[] inputStream2ByteArray(@NotNull String filePath) {
|
||||
try {
|
||||
InputStream in = new FileInputStream(filePath);
|
||||
@@ -594,6 +600,7 @@ public class Util {
|
||||
* @param inputStream Target stream
|
||||
* @return Byte array
|
||||
*/
|
||||
@Nullable
|
||||
public static byte[] inputStream2ByteArray(@NotNull InputStream inputStream) {
|
||||
try {
|
||||
byte[] data = toByteArray(inputStream);
|
||||
@@ -676,10 +683,10 @@ public class Util {
|
||||
if(!stack.hasItemMeta()){
|
||||
return false;
|
||||
}
|
||||
if(!stack.getItemMeta().hasLore()){
|
||||
if(!Objects.requireNonNull(stack.getItemMeta()).hasLore()){
|
||||
return false;
|
||||
}
|
||||
for (String lore:stack.getItemMeta().getLore()) {
|
||||
for (String lore: Objects.requireNonNull(stack.getItemMeta().getLore())) {
|
||||
if(plugin.getConfig().getStringList("shop.blacklist-lores").contains(lore)){
|
||||
return true;
|
||||
}
|
||||
@@ -1083,7 +1090,7 @@ public class Util {
|
||||
*/
|
||||
public static Material getSignMaterial() {
|
||||
|
||||
Material signMaterial = Material.matchMaterial(plugin.getConfig().getString("shop.sign-material"));
|
||||
Material signMaterial = Material.matchMaterial(Objects.requireNonNull(plugin.getConfig().getString("shop.sign-material")));
|
||||
if (signMaterial != null) {
|
||||
return signMaterial;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.maxgamer.quickshop.Shop.Shop;
|
||||
import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -64,6 +65,6 @@ public class OngoingFeeWatcher extends BukkitRunnable {
|
||||
*/
|
||||
public void removeShop(@NotNull Shop shop) {
|
||||
Bukkit.getScheduler().runTask(plugin, (@NotNull Runnable) shop::delete);
|
||||
MsgUtil.send(shop.getOwner(), MsgUtil.getMessageOfflinePlayer("shop-removed-cause-ongoing-fee", Bukkit.getOfflinePlayer(shop.getOwner()), "World:" + shop.getLocation().getWorld().getName() + " X:" + shop.getLocation().getBlockX() + " Y:" + shop.getLocation().getBlockY() + " Z:" + shop.getLocation().getBlockZ()), shop.isUnlimited());
|
||||
MsgUtil.send(shop.getOwner(), MsgUtil.getMessageOfflinePlayer("shop-removed-cause-ongoing-fee", Bukkit.getOfflinePlayer(shop.getOwner()), "World:" + Objects.requireNonNull(shop.getLocation().getWorld()).getName() + " X:" + shop.getLocation().getBlockX() + " Y:" + shop.getLocation().getBlockY() + " Z:" + shop.getLocation().getBlockZ()), shop.isUnlimited());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user