diff --git a/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_About.java b/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_About.java index 591b7729c..b6ade2d57 100644 --- a/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_About.java +++ b/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_About.java @@ -42,7 +42,7 @@ public class SubCommand_About implements CommandProcesser { public void onCommand( @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) { sender.sendMessage( - ChatColor.AQUA + "QuickShop " + ChatColor.YELLOW + QuickShop.instance.getFork()); + ChatColor.AQUA + "QuickShop " + ChatColor.YELLOW + QuickShop.getFork()); sender.sendMessage( ChatColor.AQUA + "Ver " diff --git a/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java b/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java index b2b0fc1e1..5a9892a68 100644 --- a/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java +++ b/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java @@ -125,47 +125,50 @@ public class DatabaseHelper { * @return Create failed or successed. * @throws SQLException If the connection is invalid */ - private boolean createMessagesTable() throws SQLException { - Statement st = db.getConnection().createStatement(); - String createTable = "CREATE TABLE " + QuickShop.instance.getDbPrefix() - + "messages (owner VARCHAR(255) NOT NULL, message TEXT(25) NOT NULL, time BIGINT(32) NOT NULL );"; - if (plugin.getDatabase().getCore() instanceof MySQLCore) { - createTable = "CREATE TABLE " + QuickShop.instance.getDbPrefix() - + "messages (owner VARCHAR(255) NOT NULL, message TEXT(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL , time BIGINT(32) NOT NULL );"; - } - return st.execute(createTable); - } - - public void createShop(@NotNull String owner, double price, @NotNull ItemStack item, int unlimited, int shopType, @NotNull String world, int x, int y, int z) { + private void createMessagesTable() throws SQLException { plugin.getDatabaseManager().add(() -> { try { - removeShop(x, y, z, world); //First purge old exist shop before create new shop. - String sqlString = "INSERT INTO " + QuickShop.instance - .getDbPrefix() + "shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; - //QuickShop.instance.getDB().execute(q, owner, price, Util.serialize(item), x, y, z, world, unlimited, shopType); - PreparedStatement ps = db.getConnection().prepareStatement(sqlString); - ps.setString(1, owner); - ps.setDouble(2, price); - ps.setString(3, Util.serialize(item)); - ps.setInt(4, x); - ps.setInt(5, y); - ps.setInt(6, z); - ps.setString(7, world); - ps.setInt(8, unlimited); - ps.setInt(9, shopType); - ps.execute(); + Statement st = db.getConnection().createStatement(); + String createTable = "CREATE TABLE " + QuickShop.instance.getDbPrefix() + + "messages (owner VARCHAR(255) NOT NULL, message TEXT(25) NOT NULL, time BIGINT(32) NOT NULL );"; + if (plugin.getDatabase().getCore() instanceof MySQLCore) { + createTable = "CREATE TABLE " + QuickShop.instance.getDbPrefix() + + "messages (owner VARCHAR(255) NOT NULL, message TEXT(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL , time BIGINT(32) NOT NULL );"; + } + st.execute(createTable); } catch (SQLException e) { e.printStackTrace(); } }); } + public boolean createShop(@NotNull String owner, double price, @NotNull ItemStack item, int unlimited, int shopType, @NotNull String world, int x, int y, int z) { + try { + removeShop(x, y, z, world); //First purge old exist shop before create new shop. + String sqlString = "INSERT INTO " + QuickShop.instance + .getDbPrefix() + "shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; + //QuickShop.instance.getDB().execute(q, owner, price, Util.serialize(item), x, y, z, world, unlimited, shopType); + PreparedStatement ps = db.getConnection().prepareStatement(sqlString); + ps.setString(1, owner); + ps.setDouble(2, price); + ps.setString(3, Util.serialize(item)); + ps.setInt(4, x); + ps.setInt(5, y); + ps.setInt(6, z); + ps.setString(7, world); + ps.setInt(8, unlimited); + ps.setInt(9, shopType); + return ps.execute(); + } catch (SQLException e) { + e.printStackTrace(); + return false; + } + } + /** * Creates the database table 'shops'. - * - * @throws SQLException If the connection is invalid. */ - private void createShopsTable() throws SQLException { + private void createShopsTable() { plugin.getDatabaseManager().add(() -> { try { Statement st = db.getConnection().createStatement(); @@ -178,22 +181,29 @@ public class DatabaseHelper { }); } - public boolean removeShop(int x, int y, int z, @NotNull String worldName) throws SQLException { + public void removeShop(int x, int y, int z, @NotNull String worldName) throws SQLException { // db.getConnection().createStatement() // .executeUpdate("DELETE FROM " + QuickShop.instance.getDbPrefix() + "shops WHERE x = " + x + " AND y = " + y // + " AND z = " + z + " AND world = \"" + worldName + "\"" // + (db.getCore() instanceof MySQLCore ? " LIMIT 1" : "")); - String sqlString = "DELETE FROM " + QuickShop.instance - .getDbPrefix() + "shops WHERE x = ? AND y = ? AND z = ? AND world = ?" + (db.getCore() instanceof MySQLCore ? - " LIMIT 1" : - ""); + plugin.getDatabaseManager().add(() -> { + try { + String sqlString = "DELETE FROM " + QuickShop.instance + .getDbPrefix() + "shops WHERE x = ? AND y = ? AND z = ? AND world = ?" + (db.getCore() instanceof MySQLCore ? + " LIMIT 1" : + ""); - PreparedStatement ps = db.getConnection().prepareStatement(sqlString); - ps.setInt(1, x); - ps.setInt(2, y); - ps.setInt(3, z); - ps.setString(4, worldName); - return ps.execute(); + PreparedStatement ps = db.getConnection().prepareStatement(sqlString); + ps.setInt(1, x); + ps.setInt(2, y); + ps.setInt(3, z); + ps.setString(4, worldName); + ps.execute(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + ); } public ResultSet selectAllMessages() throws SQLException { @@ -225,8 +235,7 @@ public class DatabaseHelper { }); } - public void updateOwner2UUID(@NotNull String ownerUUID, int x, int y, int z, @NotNull String worldName) - throws SQLException { + public void updateOwner2UUID(@NotNull String ownerUUID, int x, int y, int z, @NotNull String worldName) { //QuickShop.instance.getDB().getConnection().createStatement() // .executeUpdate("UPDATE " + QuickShop.instance.getDbPrefix() + "shops SET owner = \"" + ownerUUID.toString() // + "\" WHERE x = " + x + " AND y = " + y + " AND z = " + z diff --git a/src/main/java/org/maxgamer/quickshop/Database/DatabaseManager.java b/src/main/java/org/maxgamer/quickshop/Database/DatabaseManager.java index 460be97cd..abb01267a 100644 --- a/src/main/java/org/maxgamer/quickshop/Database/DatabaseManager.java +++ b/src/main/java/org/maxgamer/quickshop/Database/DatabaseManager.java @@ -32,17 +32,26 @@ import org.maxgamer.quickshop.Util.Timer; import org.maxgamer.quickshop.Util.Util; import org.maxgamer.quickshop.Util.WarningSender; -/** Queued database manager. Use queue to solve run SQL make server lagg issue. */ +/** + * Queued database manager. Use queue to solve run SQL make server lagg issue. + */ public class DatabaseManager { private final Queue sqlQueue = new LinkedBlockingQueue<>(); - @NotNull private final Database database; + @NotNull + private final Database database; - @NotNull private final QuickShop plugin; - @NotNull private final WarningSender warningSender; - @Nullable private BukkitTask task; - private boolean useQueue; + @NotNull + private final QuickShop plugin; + + @NotNull + private final WarningSender warningSender; + + @Nullable + private BukkitTask task; + + private final boolean useQueue; /** * Queued database manager. Use queue to solve run SQL make server lagg issue. diff --git a/src/main/java/org/maxgamer/quickshop/Economy/EconomyType.java b/src/main/java/org/maxgamer/quickshop/Economy/EconomyType.java index 09238e161..94b610c86 100644 --- a/src/main/java/org/maxgamer/quickshop/Economy/EconomyType.java +++ b/src/main/java/org/maxgamer/quickshop/Economy/EconomyType.java @@ -32,7 +32,7 @@ public enum EconomyType { RESERVE(1), MIXED(2); - private int id; + private final int id; EconomyType(int id) { this.id = id; diff --git a/src/main/java/org/maxgamer/quickshop/Economy/Economy_Mixed.java b/src/main/java/org/maxgamer/quickshop/Economy/Economy_Mixed.java index 28bdb0887..c2991d5d4 100644 --- a/src/main/java/org/maxgamer/quickshop/Economy/Economy_Mixed.java +++ b/src/main/java/org/maxgamer/quickshop/Economy/Economy_Mixed.java @@ -26,7 +26,7 @@ import org.maxgamer.quickshop.Util.MsgUtil; import org.maxgamer.quickshop.Util.Util; public class Economy_Mixed implements EconomyCore { - EconomyCore core; + final EconomyCore core; public Economy_Mixed() { core = new Economy_Vault(); diff --git a/src/main/java/org/maxgamer/quickshop/Event/ProtectionCheckStatus.java b/src/main/java/org/maxgamer/quickshop/Event/ProtectionCheckStatus.java index 5b2f6589f..e735b9858 100644 --- a/src/main/java/org/maxgamer/quickshop/Event/ProtectionCheckStatus.java +++ b/src/main/java/org/maxgamer/quickshop/Event/ProtectionCheckStatus.java @@ -23,7 +23,7 @@ public enum ProtectionCheckStatus { BEGIN(0), END(1); - int statusCode; + final int statusCode; ProtectionCheckStatus(int statusCode) { this.statusCode = statusCode; diff --git a/src/main/java/org/maxgamer/quickshop/Language.java b/src/main/java/org/maxgamer/quickshop/Language.java index 7105e7971..ec9d2bf87 100644 --- a/src/main/java/org/maxgamer/quickshop/Language.java +++ b/src/main/java/org/maxgamer/quickshop/Language.java @@ -28,7 +28,7 @@ import org.maxgamer.quickshop.Util.Copied; import org.maxgamer.quickshop.Util.Util; public class Language { - private QuickShop plugin; + private final QuickShop plugin; // private List languages = new ArrayList<>(); Language(QuickShop plugin) { diff --git a/src/main/java/org/maxgamer/quickshop/Listeners/DisplayProtectionListener.java b/src/main/java/org/maxgamer/quickshop/Listeners/DisplayProtectionListener.java index 5a5a65a54..db3e11475 100644 --- a/src/main/java/org/maxgamer/quickshop/Listeners/DisplayProtectionListener.java +++ b/src/main/java/org/maxgamer/quickshop/Listeners/DisplayProtectionListener.java @@ -35,21 +35,8 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityInteractEvent; -import org.bukkit.event.entity.EntityPickupItemEvent; -import org.bukkit.event.entity.EntityPortalEvent; -import org.bukkit.event.entity.ItemDespawnEvent; -import org.bukkit.event.inventory.BrewingStandFuelEvent; -import org.bukkit.event.inventory.CraftItemEvent; -import org.bukkit.event.inventory.FurnaceBurnEvent; -import org.bukkit.event.inventory.FurnaceSmeltEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCreativeEvent; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.inventory.InventoryOpenEvent; -import org.bukkit.event.inventory.InventoryPickupItemEvent; +import org.bukkit.event.entity.*; +import org.bukkit.event.inventory.*; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerFishEvent; @@ -67,8 +54,9 @@ import org.maxgamer.quickshop.Util.Util; @SuppressWarnings("DuplicatedCode") public class DisplayProtectionListener implements Listener { - private QuickShop plugin; - private boolean useEnhanceProtection; + private final QuickShop plugin; + + private final boolean useEnhanceProtection; public DisplayProtectionListener(QuickShop plugin) { this.plugin = plugin; diff --git a/src/main/java/org/maxgamer/quickshop/Listeners/ShopProtectionListener.java b/src/main/java/org/maxgamer/quickshop/Listeners/ShopProtectionListener.java index df8303394..602cdc5e5 100644 --- a/src/main/java/org/maxgamer/quickshop/Listeners/ShopProtectionListener.java +++ b/src/main/java/org/maxgamer/quickshop/Listeners/ShopProtectionListener.java @@ -205,7 +205,7 @@ public class ShopProtectionListener implements Listener { MsgUtil.sendGlobalAlert("[DisplayGuard] Defened a item steal action at" + location); } } - private boolean sendProtectionAlert = QuickShop.instance.getConfig().getBoolean("send-shop-protection-alert",false); + private final boolean sendProtectionAlert = QuickShop.instance.getConfig().getBoolean("send-shop-protection-alert", false); // Protect Entity pickup shop @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/de/Keyle/MyPet/api/util/Colorizer.java b/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/de/Keyle/MyPet/api/util/Colorizer.java index f3039434e..1f5db0935 100644 --- a/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/de/Keyle/MyPet/api/util/Colorizer.java +++ b/src/main/java/org/maxgamer/quickshop/NonQuickShopStuffs/de/Keyle/MyPet/api/util/Colorizer.java @@ -26,7 +26,7 @@ import org.bukkit.ChatColor; public class Colorizer { - private static Map colorCodes = new HashMap<>(); + private static final Map colorCodes = new HashMap<>(); static { for (ChatColor color : ChatColor.values()) { diff --git a/src/main/java/org/maxgamer/quickshop/Permission/PermissionProviderType.java b/src/main/java/org/maxgamer/quickshop/Permission/PermissionProviderType.java index e3a27e56d..3b80bba2b 100644 --- a/src/main/java/org/maxgamer/quickshop/Permission/PermissionProviderType.java +++ b/src/main/java/org/maxgamer/quickshop/Permission/PermissionProviderType.java @@ -22,7 +22,7 @@ package org.maxgamer.quickshop.Permission; public enum PermissionProviderType { // BUKKIT(0), VAULT(1), LUCKPERMS(2), PERMISSIONEX(3), GROUPMANAGER(4); BUKKIT(0); - int id; + final int id; PermissionProviderType(int id) { this.id = id; diff --git a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/FactionsUUID/FactionsUUIDIntegration.java b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/FactionsUUID/FactionsUUIDIntegration.java index cc7aab6ef..559d3220c 100644 --- a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/FactionsUUID/FactionsUUIDIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/FactionsUUID/FactionsUUIDIntegration.java @@ -35,24 +35,41 @@ import org.maxgamer.quickshop.QuickShop; @IntegrationStage(loadStage = IntegrateStage.onEnableAfter) public class FactionsUUIDIntegration implements IntegratedPlugin { - private List createFlags; - private List tradeFlags; - private boolean createRequireOpen; - private boolean createRequireNormal; - private boolean createRequireWilderness; - private boolean createRequirePeaceful; - private boolean createRequirePermanent; - private boolean createRequireSafeZone; - private boolean createRequireOwn; - private boolean createRequireWarZone; - private boolean tradeRequireOpen; - private boolean tradeRequireNormal; - private boolean tradeRequireWilderness; - private boolean tradeRequirePeaceful; - private boolean tradeRequirePermanent; - private boolean tradeRequireSafeZone; - private boolean tradeRequireOwn; - private boolean tradeRequireWarZone; + private final List createFlags; + + private final List tradeFlags; + + private final boolean createRequireOpen; + + private final boolean createRequireNormal; + + private final boolean createRequireWilderness; + + private final boolean createRequirePeaceful; + + private final boolean createRequirePermanent; + + private final boolean createRequireSafeZone; + + private final boolean createRequireOwn; + + private final boolean createRequireWarZone; + + private final boolean tradeRequireOpen; + + private final boolean tradeRequireNormal; + + private final boolean tradeRequireWilderness; + + private final boolean tradeRequirePeaceful; + + private final boolean tradeRequirePermanent; + + private final boolean tradeRequireSafeZone; + + private final boolean tradeRequireOwn; + + private final boolean tradeRequireWarZone; public FactionsUUIDIntegration(QuickShop plugin) { this.createFlags = plugin.getConfig().getStringList("integration.factions.create.flags"); diff --git a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/PlotSquared/PlotSquaredIntegration.java b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/PlotSquared/PlotSquaredIntegration.java index ae0a4ee34..c85dd404e 100644 --- a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/PlotSquared/PlotSquaredIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/PlotSquared/PlotSquaredIntegration.java @@ -36,8 +36,10 @@ import org.maxgamer.quickshop.Util.Util; @IntegrationStage(loadStage = IntegrateStage.onEnableAfter) public class PlotSquaredIntegration implements IntegratedPlugin { private BooleanFlag createFlag; + private BooleanFlag tradeFlag; - private QuickShop plugin; + + private final QuickShop plugin; public PlotSquaredIntegration(QuickShop plugin) { this.plugin = plugin; diff --git a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/Residence/ResidenceIntegration.java b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/Residence/ResidenceIntegration.java index bcff69f8e..10f772ebc 100644 --- a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/Residence/ResidenceIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/Residence/ResidenceIntegration.java @@ -35,8 +35,9 @@ import org.maxgamer.quickshop.QuickShop; @SuppressWarnings("DuplicatedCode") @IntegrationStage(loadStage = IntegrateStage.onEnableAfter) public class ResidenceIntegration implements IntegratedPlugin { - List createLimits; - List tradeLimits; + final List createLimits; + + final List tradeLimits; public ResidenceIntegration(QuickShop plugin) { this.createLimits = plugin.getConfig().getStringList("integration.residence.create"); diff --git a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/Towny/TownyIntegration.java b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/Towny/TownyIntegration.java index f03e4cd7f..265f79981 100644 --- a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/Towny/TownyIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/Towny/TownyIntegration.java @@ -32,8 +32,9 @@ import org.maxgamer.quickshop.QuickShop; @SuppressWarnings("DuplicatedCode") @IntegrationStage(loadStage = IntegrateStage.onEnableAfter) public class TownyIntegration implements IntegratedPlugin { - private List createFlags; - private List tradeFlags; + private final List createFlags; + + private final List tradeFlags; public TownyIntegration(QuickShop plugin) { createFlags = diff --git a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/WorldGuard/WorldGuardIntegration.java b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/WorldGuard/WorldGuardIntegration.java index 8987aedf5..20bff8d6c 100644 --- a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/WorldGuard/WorldGuardIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/WorldGuard/WorldGuardIntegration.java @@ -43,11 +43,15 @@ import org.maxgamer.quickshop.Util.Util; @SuppressWarnings("DuplicatedCode") @IntegrationStage(loadStage = IntegrateStage.onLoadAfter) public class WorldGuardIntegration implements IntegratedPlugin { - private List createFlags; - private List tradeFlags; - private StateFlag createFlag = new StateFlag("quickshop-create", false); - private StateFlag tradeFlag = new StateFlag("quickshop-trade", true); - private QuickShop plugin; + private final List createFlags; + + private final List tradeFlags; + + private final StateFlag createFlag = new StateFlag("quickshop-create", false); + + private final StateFlag tradeFlag = new StateFlag("quickshop-trade", true); + + private final QuickShop plugin; public WorldGuardIntegration(QuickShop plugin) { this.plugin = plugin; diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 6146d1578..57cf5a80a 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -663,7 +663,6 @@ public class QuickShop extends JavaPlugin { Bukkit.getPluginManager().registerEvents(customInventoryListener, this); Bukkit.getPluginManager().registerEvents(shopProtectListener, this); - ; Bukkit.getPluginManager().registerEvents(internalListener, this); if (isDisplay() && DisplayItem.getNowUsing() != DisplayType.VIRTUALITEM) { diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java index 165a4f583..0bff1838c 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java @@ -33,18 +33,24 @@ import org.maxgamer.quickshop.Util.Util; /** * @author Netherfoam A display item, that spawns a block above the chest and cannot be interacted - * with. + * with. */ public abstract class DisplayItem { private static final Gson gson = new Gson(); - @Nullable protected ItemStack guardedIstack; - protected ItemStack originalItemStack; - protected static QuickShop plugin = QuickShop.instance; - protected Shop shop; + + @Nullable + protected ItemStack guardedIstack; + + protected final ItemStack originalItemStack; + + protected static final QuickShop plugin = QuickShop.instance; + + protected final Shop shop; + private boolean pendingRemoval; - protected DisplayItem(Shop shop){ + protected DisplayItem(Shop shop) { this.shop = shop; this.originalItemStack = new ItemStack(shop.getItem()); this.originalItemStack.setAmount(1); diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItemPersistentDataType.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItemPersistentDataType.java index dcf51caf5..7f5d18bba 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItemPersistentDataType.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItemPersistentDataType.java @@ -30,7 +30,8 @@ import org.maxgamer.quickshop.Util.Util; public class DisplayItemPersistentDataType implements PersistentDataType { static final DisplayItemPersistentDataType INSTANCE = new DisplayItemPersistentDataType(); - private static Gson gson = new Gson(); + + private static final Gson gson = new Gson(); @Override public @NotNull Class getPrimitiveType() { diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayType.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayType.java index 7b21b160d..0a8d42017 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayType.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayType.java @@ -34,7 +34,7 @@ public enum DisplayType { ARMORSTAND(1), VIRTUALITEM(2); - private int id; + private final int id; DisplayType(int id) { this.id = id; diff --git a/src/main/java/org/maxgamer/quickshop/Shop/MatcherWorkMode.java b/src/main/java/org/maxgamer/quickshop/Shop/MatcherWorkMode.java index 2cd09f156..2554588b9 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/MatcherWorkMode.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/MatcherWorkMode.java @@ -26,7 +26,7 @@ public enum MatcherWorkMode { BUKKITMATCHER(1), JAVAMATCHER(2); - private int id; + private final int id; MatcherWorkMode(int id) { this.id = id; diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopLoader.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopLoader.java index 77a22e6d0..8741a94ff 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopLoader.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopLoader.java @@ -39,18 +39,30 @@ import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Util.Timer; import org.maxgamer.quickshop.Util.Util; -/** A class allow plugin load shops fast and simply. */ +/** + * A class allow plugin load shops fast and simply. + */ public class ShopLoader { private final ArrayList loadTimes = new ArrayList<>(); - private Map costCache = new HashMap<>(); + + private final Map costCache = new HashMap<>(); + private int errors; + private int loadAfterChunkLoaded = 0; + private int loadAfterWorldLoaded = 0; - private QuickShop plugin; + + private final QuickShop plugin; + private int totalLoaded = 0; + /* This may contains broken shop, must use null check before load it. */ - @Getter private List shopsInDatabase = new ArrayList<>(); - @Getter private List originShopsInDatabase = new ArrayList<>(); + @Getter + private List shopsInDatabase = new ArrayList<>(); + + @Getter + private List originShopsInDatabase = new ArrayList<>(); /** * The shop load allow plugin load shops fast and simply. diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index 10750b9a1..3ac467adf 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -55,9 +55,9 @@ public class ShopManager { private final Set loadedShops = QuickShop.instance.isEnabledAsyncDisplayDespawn() ? Sets.newConcurrentHashSet() : Sets.newHashSet(); - private HashMap actions = new HashMap<>(); + private final HashMap actions = new HashMap<>(); - private QuickShop plugin; + private final QuickShop plugin; private boolean useFastShopSearchAlgorithm = false; @@ -680,13 +680,11 @@ public class ShopManager { return; } Location loc = shop.getLocation(); - try { - // Write it to the database - plugin.getDatabaseHelper().createShop(ShopModerator.serialize(shop.getModerator()), shop.getPrice(), shop.getItem(), (shop.isUnlimited() ? 1 : 0), shop.getShopType().toID(), Objects.requireNonNull(loc.getWorld()).getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - // Add it to the world + + if (plugin.getDatabaseHelper().createShop(ShopModerator.serialize(shop.getModerator()), shop.getPrice(), shop.getItem(), (shop.isUnlimited() ? 1 : 0), shop.getShopType().toID(), Objects.requireNonNull(loc.getWorld()).getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) { addShop(loc.getWorld().getName(), shop); - } catch (SQLException error) { - plugin.getLogger().warning("SQLException detected, trying to auto fix the database..."); + } else { + plugin.getLogger().warning("Shop create failed, trying to auto fix the database..."); boolean backupSuccess = Util.backupDatabase(); try { if (backupSuccess) { @@ -699,7 +697,6 @@ public class ShopManager { plugin.getLogger().warning("Failed to autofix the database, all changes will revert after a reboot."); error2.printStackTrace(); } - error.printStackTrace(); } // Create sign if (info.getSignBlock() != null && plugin.getConfig().getBoolean("shop.auto-sign")) { @@ -838,10 +835,8 @@ public class ShopManager { // Found some shops in this chunk if (inChunk != null) { shop = inChunk.get(attachedBlock.getLocation()); - if (shop != null) { - // Okay, shop was founded. - return shop; - } + // Okay, shop was founded. + return shop; // Oooops, no any shops matched. } } @@ -1043,7 +1038,7 @@ public class ShopManager { private Iterator shops; - private Iterator>> worlds; + private final Iterator>> worlds; public ShopIterator() { //noinspection unchecked diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopType.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopType.java index e9c5c70f0..62640348e 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopType.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopType.java @@ -26,7 +26,7 @@ public enum ShopType { SELLING(0), BUYING(1); - private int id; + private final int id; ShopType(int id) { this.id = id; diff --git a/src/main/java/org/maxgamer/quickshop/Shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/VirtualDisplayItem.java index 87c639353..1d531c1ec 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/VirtualDisplayItem.java @@ -46,7 +46,7 @@ import org.maxgamer.quickshop.Util.Util; public class VirtualDisplayItem extends DisplayItem { - private static ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); + private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); private volatile boolean isDisplay; @@ -56,7 +56,7 @@ public class VirtualDisplayItem extends DisplayItem { private static final String version = Util.getNMSVersion(); //unique EntityID - private int entityID = counter.decrementAndGet(); + private final int entityID = counter.decrementAndGet(); //packets private PacketContainer fakeItemPacket; @@ -74,9 +74,9 @@ public class VirtualDisplayItem extends DisplayItem { private ShopChunk chunkLocation; //The List which store packet sender - private Set packetSenders = new ConcurrentSkipListSet<>(); + private final Set packetSenders = new ConcurrentSkipListSet<>(); - private Queue asyncPacketSendQueue = new LinkedList<>(); + private final Queue asyncPacketSendQueue = new LinkedList<>(); @Nullable private BukkitTask asyncSendingTask; diff --git a/src/main/java/org/maxgamer/quickshop/Util/FunnyEasterEgg.java b/src/main/java/org/maxgamer/quickshop/Util/FunnyEasterEgg.java index a40559268..039626c3e 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/FunnyEasterEgg.java +++ b/src/main/java/org/maxgamer/quickshop/Util/FunnyEasterEgg.java @@ -233,37 +233,47 @@ class LunarCalendar { /** 农历数据, 1901 ~ 2100 年之间正确 */ static final long[] lunarInfo = new long[] { - 0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, - 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, - 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, - 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, - 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, - 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, - 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, - 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6, - 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, - 0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, - 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, - 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, - 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, - 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, - 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 + 0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, + 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, + 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, + 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, + 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, + 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, + 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, + 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6, + 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, + 0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, + 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, + 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, + 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, + 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, + 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 }; - /** 中文日期格式 */ - static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日"); - private int year; // 农历年 + /** + * 中文日期格式 + */ + static final SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日"); + + private final int year; // 农历年 + // 上面4个值在构造方法中根据传入日期计算所得 - private int month; // 农历月 - private int day; // 农历日 + private final int month; // 农历月 + + private final int day; // 农历日 + private boolean leap; // 农历闰年 - /** 构造一个表示当前日期的农历日历 */ + /** + * 构造一个表示当前日期的农历日历 + */ public LunarCalendar() { this(Calendar.getInstance()); } - /** 构造一个表示指定日期的农历日历 */ + /** + * 构造一个表示指定日期的农历日历 + */ public LunarCalendar(Date date) { this(date2calendar(date)); } @@ -346,37 +356,47 @@ class LunarCalendar { } // ====== 传回农历 y年的总天数 - private static final int yearDays(int y) { + private static int yearDays(int y) { int i, sum = 348; for (i = 0x8000; i > 0x8; i >>= 1) { - if ((lunarInfo[y - 1900] & i) != 0) sum += 1; + if ((lunarInfo[y - 1900] & i) != 0) { + sum += 1; + } } return (sum + leapDays(y)); } // ====== 传回农历 y年闰月的天数 - private static final int leapDays(int y) { + private static int leapDays(int y) { if (leapMonth(y) != 0) { - if ((lunarInfo[y - 1900] & 0x10000) != 0) return 30; - else return 29; - } else return 0; + if ((lunarInfo[y - 1900] & 0x10000) != 0) { + return 30; + } else { + return 29; + } + } else { + return 0; + } } // ====== 传回农历 y年闰哪个月 1-12 , 没闰传回 0 - private static final int leapMonth(int y) { + private static int leapMonth(int y) { return (int) (lunarInfo[y - 1900] & 0xf); } // ====== 传回农历 y年m月的总天数 - private static final int monthDays(int y, int m) { - if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0) return 29; - else return 30; + private static int monthDays(int y, int m) { + if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0) { + return 29; + } else { + return 30; + } } // ====== 传入 月日的offset 传回干支, 0=甲子 - private static final String cyclicalm(int num) { - final String[] Gan = new String[] {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}; - final String[] Zhi = new String[] {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}; + private static String cyclicalm(int num) { + final String[] Gan = new String[]{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}; + final String[] Zhi = new String[]{"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}; return (Gan[num % 10] + Zhi[num % 12]); } diff --git a/src/main/java/org/maxgamer/quickshop/Util/GameLanguage.java b/src/main/java/org/maxgamer/quickshop/Util/GameLanguage.java index 2d73595b9..22ea02e71 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/GameLanguage.java +++ b/src/main/java/org/maxgamer/quickshop/Util/GameLanguage.java @@ -42,7 +42,7 @@ import org.maxgamer.quickshop.Util.MojangAPI.MojangAPI; public class GameLanguage extends Thread { private @Nullable JsonObject lang; - private GameLanguageLoadThread loadThread; + private final GameLanguageLoadThread loadThread; @SneakyThrows public GameLanguage(@NotNull String languageCode) { diff --git a/src/main/java/org/maxgamer/quickshop/Util/Github/GithubAPI.java b/src/main/java/org/maxgamer/quickshop/Util/Github/GithubAPI.java index e423cc16c..60c13e5aa 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Github/GithubAPI.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Github/GithubAPI.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; import org.maxgamer.quickshop.NonQuickShopStuffs.com.sk89q.worldedit.util.net.HttpRequest; public class GithubAPI { - private Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + private final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); @Nullable public ReleaseJsonContainer.AssetsBean getLatestRelease() throws Exception { diff --git a/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java b/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java index 0f6dfa8fb..4364199d1 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java @@ -29,10 +29,13 @@ import org.bukkit.potion.PotionData; import org.jetbrains.annotations.Nullable; import org.maxgamer.quickshop.QuickShop; -/** A util allow quickshop check item matches easy and quick. */ +/** + * A util allow quickshop check item matches easy and quick. + */ public class ItemMatcher { - private ItemMetaMatcher itemMetaMatcher; - private QuickShop plugin; + private final ItemMetaMatcher itemMetaMatcher; + + private final QuickShop plugin; public ItemMatcher(QuickShop plugin) { this.plugin = plugin; @@ -98,21 +101,32 @@ public class ItemMatcher { private boolean typeMatches(ItemStack requireStack, ItemStack givenStack) { return requireStack.getType().equals(givenStack.getType()); } + } class ItemMetaMatcher { - private boolean banner; - private boolean repaircost; - private boolean attributes; - private boolean custommodeldata; - private boolean damage; - private boolean displayname; - private boolean enchs; - private boolean itemflags; - private boolean lores; - private boolean potions; - private boolean book; + private final boolean banner; + + private final boolean repaircost; + + private final boolean attributes; + + private final boolean custommodeldata; + + private final boolean damage; + + private final boolean displayname; + + private final boolean enchs; + + private final boolean itemflags; + + private final boolean lores; + + private final boolean potions; + + private final boolean book; public ItemMetaMatcher(ConfigurationSection itemMatcherConfig) { this.damage = itemMatcherConfig.getBoolean("damage"); diff --git a/src/main/java/org/maxgamer/quickshop/Util/Logger/QuickShopLogger.java b/src/main/java/org/maxgamer/quickshop/Util/Logger/QuickShopLogger.java index ae264f184..0f7f5c288 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Logger/QuickShopLogger.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Logger/QuickShopLogger.java @@ -16,29 +16,8 @@ package org.maxgamer.quickshop.Util.Logger; -import static org.bukkit.ChatColor.AQUA; -import static org.bukkit.ChatColor.BLACK; -import static org.bukkit.ChatColor.BLUE; -import static org.bukkit.ChatColor.BOLD; -import static org.bukkit.ChatColor.DARK_AQUA; -import static org.bukkit.ChatColor.DARK_BLUE; -import static org.bukkit.ChatColor.DARK_GRAY; -import static org.bukkit.ChatColor.DARK_GREEN; -import static org.bukkit.ChatColor.DARK_PURPLE; -import static org.bukkit.ChatColor.DARK_RED; -import static org.bukkit.ChatColor.GOLD; -import static org.bukkit.ChatColor.GRAY; -import static org.bukkit.ChatColor.GREEN; -import static org.bukkit.ChatColor.ITALIC; -import static org.bukkit.ChatColor.LIGHT_PURPLE; -import static org.bukkit.ChatColor.MAGIC; -import static org.bukkit.ChatColor.RED; -import static org.bukkit.ChatColor.RESET; -import static org.bukkit.ChatColor.STRIKETHROUGH; -import static org.bukkit.ChatColor.UNDERLINE; -import static org.bukkit.ChatColor.WHITE; -import static org.bukkit.ChatColor.YELLOW; - +import static org.bukkit.ChatColor.*; +import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Arrays; import java.util.HashMap; @@ -55,9 +34,6 @@ import org.bukkit.ChatColor; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginLogger; import org.jetbrains.annotations.Nullable; -import org.maxgamer.quickshop.NonQuickShopStuffs.de.Keyle.MyPet.api.util.ReflectionUtil; -import org.maxgamer.quickshop.Util.Util; -import com.google.common.collect.Maps; /* * Originally take from Mypet which is a awesome project, extends PluginLogger in order to replace @@ -94,19 +70,24 @@ public class QuickShopLogger extends PluginLogger { } // below are non-static for secret optimization - /** Regex that indicates the case insensitive */ + + /** + * Regex that indicates the case insensitive + */ private String IGNORE_CASE; // private FileHandler debugLogFileHandler = null; private boolean hasAnsi = true; + private boolean hasJline = true; - private boolean useLog4j; + + private final boolean useLog4j; @SneakyThrows public QuickShopLogger(Plugin plugin) { super(plugin); registerStyles(); - + // Logger re-naming String prefix = plugin.getDescription().getPrefix(); String pluginName = (useLog4j = plugin.getConfig().getBoolean("enable-log4j")) ? diff --git a/src/main/java/org/maxgamer/quickshop/Util/MojangAPI/AssetJson.java b/src/main/java/org/maxgamer/quickshop/Util/MojangAPI/AssetJson.java index 26736bd53..a2a96dd2a 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/MojangAPI/AssetJson.java +++ b/src/main/java/org/maxgamer/quickshop/Util/MojangAPI/AssetJson.java @@ -30,7 +30,9 @@ import org.maxgamer.quickshop.Util.Util; public class AssetJson { final String pathTemplate = "minecraft/lang/{0}.json"; - @NotNull String gameAssets; + + @NotNull + final String gameAssets; public AssetJson(@NotNull String json) { this.gameAssets = json; @@ -38,7 +40,7 @@ public class AssetJson { @Nullable public String getLanguageHash(@NotNull String languageCode) { - languageCode = languageCode.replace("-","_").toLowerCase().trim(); + languageCode = languageCode.replace("-", "_").toLowerCase().trim(); JsonObject json = new JsonParser().parse(this.gameAssets).getAsJsonObject(); if (json == null || json.isJsonNull()) { Util.debugLog("Cannot parse the json: " + this.gameAssets); diff --git a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java index f7ecee5a7..d930a2ef7 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java @@ -59,16 +59,25 @@ import org.maxgamer.quickshop.Shop.Shop; @SuppressWarnings("WeakerAccess") public class MsgUtil { - public static String invaildMsg = "Invaild message"; + public static final String invaildMsg = "Invaild message"; + private static YamlConfiguration enchi18n; + private static boolean inited; + private static YamlConfiguration itemi18n; + private static IFile messagei18n; - private static HashMap> player_messages = new HashMap<>(); - private static QuickShop plugin = QuickShop.instance; + + private static final HashMap> player_messages = new HashMap<>(); + + private static final QuickShop plugin = QuickShop.instance; + private static YamlConfiguration potioni18n; - private static DecimalFormat decimalFormat = + + private static final DecimalFormat decimalFormat = new DecimalFormat(Objects.requireNonNull(plugin.getConfig().getString("decimal-format"))); + private static GameLanguage gameLanguage; /** diff --git a/src/main/java/org/maxgamer/quickshop/Util/Paste/Paste.java b/src/main/java/org/maxgamer/quickshop/Util/Paste/Paste.java index b08e130d8..448ccfe05 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Paste/Paste.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Paste/Paste.java @@ -62,7 +62,7 @@ public class Paste { finalReport.append("================================================\n"); finalReport.append("QuickShop:\n"); finalReport.append("\tVersion: ").append(QuickShop.getVersion()).append("\n"); - finalReport.append("\tFork: ").append(plugin.getFork()).append("\n"); + finalReport.append("\tFork: ").append(QuickShop.getFork()).append("\n"); finalReport.append("\tServer ID: ").append(plugin.getServerUniqueID()).append("\n"); finalReport .append("\tOpenInv Hook: ") diff --git a/src/main/java/org/maxgamer/quickshop/Util/PermissionChecker.java b/src/main/java/org/maxgamer/quickshop/Util/PermissionChecker.java index f2b9d2c8b..8e6215434 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/PermissionChecker.java +++ b/src/main/java/org/maxgamer/quickshop/Util/PermissionChecker.java @@ -19,6 +19,7 @@ package org.maxgamer.quickshop.Util; +import java.util.concurrent.atomic.AtomicBoolean; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; @@ -33,11 +34,10 @@ import org.maxgamer.quickshop.Event.ProtectionCheckStatus; import org.maxgamer.quickshop.Event.ShopProtectionCheckEvent; import org.maxgamer.quickshop.QuickShop; -import java.util.concurrent.atomic.AtomicBoolean; - public class PermissionChecker { - private QuickShop plugin; - private boolean usePermissionChecker; + private final QuickShop plugin; + + private final boolean usePermissionChecker; public PermissionChecker(@NotNull QuickShop plugin) { this.plugin = plugin; diff --git a/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java b/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java index 5df0bcb01..9f573b259 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java +++ b/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java @@ -55,31 +55,31 @@ public class SentryErrorReporter { private final ArrayList reported = new ArrayList<>(); - private Context context; + private final Context context; private boolean disable; @Getter private boolean enabled; - private List> ignoredException = new ArrayList<>(); + private final List> ignoredException = new ArrayList<>(); - private QuickShop plugin; + private final QuickShop plugin; /* Pre-init it if it called before the we create it... */ - private SentryClient sentryClient; + private final SentryClient sentryClient; private boolean tempDisable; private String lastPaste; - private IncompatibleChecker checker = new IncompatibleChecker(); + private final IncompatibleChecker checker = new IncompatibleChecker(); public SentryErrorReporter(@NotNull QuickShop plugin) { this.plugin = plugin; // sentryClient = Sentry.init(dsn); Util.debugLog("Loading SentryErrorReporter"); - sentryClient = SentryClientFactory.sentryClient(dsn);; + sentryClient = SentryClientFactory.sentryClient(dsn); context = sentryClient.getContext(); Util.debugLog("Setting basic report data..."); // context.addTag("plugin_version", QuickShop.getVersion()); diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 65c5473f1..59a5e945d 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -59,23 +59,33 @@ import org.maxgamer.quickshop.Watcher.InventoryEditContainer; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; -/** @author MACHENIKE */ +/** + * @author MACHENIKE + */ @SuppressWarnings("WeakerAccess") public class Util { static short tookLongTimeCostTimes; - private static EnumSet blacklist = EnumSet.noneOf(Material.class); - @Getter - private static List debugLogs = Collections.synchronizedList(new LinkedList<>()); + private static final EnumSet blacklist = EnumSet.noneOf(Material.class); + + @Getter + private static List debugLogs = Collections.synchronizedList(new LinkedList<>()); + + private static boolean devMode = false; - private static boolean devMode = false; private static QuickShop plugin; - private static EnumMap> restrictedPrices = + + private static final EnumMap> restrictedPrices = new EnumMap<>(Material.class); + private static Object serverInstance; - private static EnumSet shoppables = EnumSet.noneOf(Material.class); + + private static final EnumSet shoppables = EnumSet.noneOf(Material.class); + private static Field tpsField; + private static List worldBlacklist = new ArrayList<>(); + private static boolean disableDebugLogger = false; /** diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/DisplayDupeRemoverWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/DisplayDupeRemoverWatcher.java index 700ed643d..b449a6ed7 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/DisplayDupeRemoverWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/DisplayDupeRemoverWatcher.java @@ -31,7 +31,7 @@ import org.maxgamer.quickshop.Shop.DisplayItem; */ @Deprecated public class DisplayDupeRemoverWatcher extends BukkitRunnable { - private Queue checkQueue = new LinkedList<>(); + private final Queue checkQueue = new LinkedList<>(); @Override public @Deprecated void run() { diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/LogWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/LogWatcher.java index 6072a8c43..e8fcccff6 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/LogWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/LogWatcher.java @@ -19,11 +19,7 @@ package org.maxgamer.quickshop.Watcher; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; +import java.io.*; import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; @@ -37,8 +33,10 @@ import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Util.Util; public class LogWatcher extends BukkitRunnable { - private Queue logs = new ConcurrentLinkedQueue<>(); + private final Queue logs = new ConcurrentLinkedQueue<>(); + private FileWriter logFileWriter = null; + private PrintWriter pw; public LogWatcher(QuickShop plugin, File log) { diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/OngoingFeeWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/OngoingFeeWatcher.java index 28d7738fc..858c897bb 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/OngoingFeeWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/OngoingFeeWatcher.java @@ -19,6 +19,8 @@ package org.maxgamer.quickshop.Watcher; +import java.util.Objects; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; @@ -27,15 +29,12 @@ 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; - /** * Check the shops after server booted up, make sure shop can correct self-deleted when container * lost. */ public class OngoingFeeWatcher extends BukkitRunnable { - private QuickShop plugin; + private final QuickShop plugin; public OngoingFeeWatcher(@NotNull QuickShop plugin) { this.plugin = plugin; diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/ShopContainerWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/ShopContainerWatcher.java index c056c650e..58115aadc 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/ShopContainerWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/ShopContainerWatcher.java @@ -34,7 +34,7 @@ import org.maxgamer.quickshop.Shop.Shop; // unused, pending to remove public class ShopContainerWatcher extends BukkitRunnable { // private QuickShop plugin; - private Queue checkQueue = new LinkedList<>(); + private final Queue checkQueue = new LinkedList<>(); public ShopContainerWatcher(@NotNull QuickShop plugin) { // this.plugin = plugin; diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/ShopVaildWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/ShopVaildWatcher.java index 2ea5d8ab7..682927963 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/ShopVaildWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/ShopVaildWatcher.java @@ -34,8 +34,9 @@ import org.maxgamer.quickshop.Util.Util; // unused, pending to remove @Deprecated public class ShopVaildWatcher extends BukkitRunnable { - private QuickShop plugin; - private Queue checkQueue = new LinkedList<>(); + private final QuickShop plugin; + + private final Queue checkQueue = new LinkedList<>(); public ShopVaildWatcher(@NotNull QuickShop plugin) { this.plugin = plugin; diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/SignUpdateWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/SignUpdateWatcher.java index ceadc403d..dc88b7232 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/SignUpdateWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/SignUpdateWatcher.java @@ -28,7 +28,7 @@ import org.maxgamer.quickshop.Shop.Shop; public class SignUpdateWatcher extends BukkitRunnable { // private QuickShop plugin; - private Queue signUpdateQueue = new LinkedList<>(); + private final Queue signUpdateQueue = new LinkedList<>(); public SignUpdateWatcher(QuickShop plugin) { // this.plugin = plugin; diff --git a/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java b/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java index 7d9dca78b..3a6f071e0 100644 --- a/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Watcher/UpdateWatcher.java @@ -42,7 +42,7 @@ public class UpdateWatcher implements Listener { private static UpdateInfomation info = null; public static String fixVer(@NotNull String originalVer) { - originalVer = originalVer.replaceAll(QuickShop.instance.getFork(), ""); + originalVer = originalVer.replaceAll(QuickShop.getFork(), ""); originalVer = originalVer.trim(); return originalVer; }