Skip to content

Commit 1a74c74

Browse files
committed
cleanup
1 parent f5fe422 commit 1a74c74

File tree

22 files changed

+56
-224
lines changed

22 files changed

+56
-224
lines changed

src/main/java/org/maxgamer/quickshop/BuildInfo.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,18 @@ public class BuildInfo {
4444
private final String pomGroupId;
4545
private final String pomArtifactId;
4646
private final String jobName;
47+
private static final String UNKNOWN = "Unknown";
4748

4849
public BuildInfo(@Nullable InputStream inputStream) {
4950
if (inputStream == null) {
5051
buildId = 0;
51-
buildTag = "Unknown";
52-
buildUrl = "Unknown";
52+
buildTag = UNKNOWN;
53+
buildUrl = UNKNOWN;
5354
gitCommit = "Custom Build";
54-
gitBranch = "Unknown";
55-
pomGroupId = "Unknown";
56-
pomArtifactId = "Unknown";
57-
jobName = "Unknown";
55+
gitBranch = UNKNOWN;
56+
pomGroupId = UNKNOWN;
57+
pomArtifactId = UNKNOWN;
58+
jobName = UNKNOWN;
5859
jobUrl = "https://ci.codemc.io/job/Ghost-chu/job/QuickShop-Reremake/";
5960
return;
6061
}

src/main/java/org/maxgamer/quickshop/QuickShop.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,9 +1976,9 @@ private void updateConfig(int selectedVersion) throws IOException {
19761976
reloadConfiguration();
19771977

19781978
//Delete old example configuration files
1979-
new File(getDataFolder(), "example.config.yml").delete();
1980-
new File(getDataFolder(), "example-configuration.txt").delete();
1981-
new File(getDataFolder(), "example-configuration.yml").delete();
1979+
Files.deleteIfExists(new File(getDataFolder(), "example.config.yml").toPath());
1980+
Files.deleteIfExists(new File(getDataFolder(), "example-configuration.txt").toPath());
1981+
Files.deleteIfExists(new File(getDataFolder(), "example-configuration.yml").toPath());
19821982

19831983
try {
19841984
if (new File(getDataFolder(), "messages.json").exists())

src/main/java/org/maxgamer/quickshop/api/economy/AbstractEconomy.java

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
package org.maxgamer.quickshop.api.economy;
2121

22-
import org.bukkit.OfflinePlayer;
2322
import org.bukkit.World;
24-
import org.bukkit.plugin.Plugin;
2523
import org.jetbrains.annotations.NotNull;
2624
import org.jetbrains.annotations.Nullable;
2725
import org.maxgamer.quickshop.QuickShop;
@@ -80,69 +78,11 @@ public boolean transfer(@NotNull UUID from, @NotNull UUID to, double amount, @No
8078
return false;
8179
}
8280

83-
@Override
84-
public abstract boolean deposit(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency);
85-
86-
@Override
87-
public abstract boolean deposit(@NotNull OfflinePlayer trader, double amount, @NotNull World world, @Nullable String currency);
88-
89-
/**
90-
* Formats the given number... E.g. 50.5 becomes $50.5 Dollars, or 50 Dollars 5 Cents
91-
*
92-
* @param balance The given number
93-
* @return The balance in human readable text.
94-
*/
95-
@Override
96-
public abstract String format(double balance, @NotNull World world, @Nullable String currency);
97-
// return Util.parseColours(core.format(balance, world, currency));
98-
// // Fix color issue from some stupid economy plugin....
99-
//}
100-
101-
@Override
102-
public abstract double getBalance(@NotNull UUID name, @NotNull World world, @Nullable String currency);
103-
104-
@Override
105-
public abstract double getBalance(@NotNull OfflinePlayer player, @NotNull World world, @Nullable String currency);
106-
107-
@Override
108-
public abstract boolean withdraw(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency);
109-
110-
@Override
111-
public abstract boolean withdraw(@NotNull OfflinePlayer trader, double amount, @NotNull World world, @Nullable String currency);
112-
113-
/**
114-
* Gets the currency does exists
115-
*
116-
* @param currency Currency name
117-
* @return exists
118-
*/
119-
@Override
120-
public abstract boolean hasCurrency(@NotNull World world, @NotNull String currency);
121-
122-
/**
123-
* Gets currency supports status
124-
*
125-
* @return true if supports
126-
*/
127-
@Override
128-
public abstract boolean supportCurrency();
129-
130-
/**
131-
* Checks that this economy is valid. Returns false if it is not valid.
132-
*
133-
* @return True if this economy will work, false if it will not.
134-
*/
135-
@Override
136-
public abstract boolean isValid();
137-
13881
@Override
13982
public @NotNull String getName() {
14083
return "BuiltIn-Economy Processor";
14184
}
14285

143-
@Override
144-
public abstract @NotNull Plugin getPlugin();
145-
14686
/**
14787
* Callback for reloading
14888
*

src/main/java/org/maxgamer/quickshop/api/event/AbstractQSEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static HandlerList getHandlerList() {
4545
@NotNull
4646
@Override
4747
public HandlerList getHandlers() {
48-
return HANDLERS;
48+
return getHandlerList();
4949
}
5050

5151
/**

src/main/java/org/maxgamer/quickshop/api/shop/AbstractDisplayItem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.maxgamer.quickshop.QuickShop;
3232
import org.maxgamer.quickshop.shop.ShopProtectionFlag;
3333
import org.maxgamer.quickshop.util.JsonUtil;
34+
import org.maxgamer.quickshop.util.MsgUtil;
3435
import org.maxgamer.quickshop.util.Util;
3536
import org.maxgamer.quickshop.util.reload.ReloadResult;
3637
import org.maxgamer.quickshop.util.reload.ReloadStatus;
@@ -91,7 +92,7 @@ public static boolean checkIsGuardItemStack(@Nullable final ItemStack itemStack)
9192
//noinspection ConstantConditions
9293
for (String lore : iMeta.getLore()) {
9394
try {
94-
if (!lore.startsWith("{")) {
95+
if (!MsgUtil.isJson(lore)) {
9596
continue;
9697
}
9798
ShopProtectionFlag shopProtectionFlag = JsonUtil.getGson().fromJson(lore, ShopProtectionFlag.class);

src/main/java/org/maxgamer/quickshop/chat/platform/minedown/BungeeQuickChat.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ public void sendItemHologramChat(@NotNull Player player, @NotNull String text, @
123123
}
124124

125125
builder.appendLegacy(" ").appendLegacy(plugin.text().of(player, "menu.preview").forLocale());
126-
// builder.event(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(json).create()));
127126
if (QuickShop.getPermissionManager().hasPermission(player, "quickshop.preview")) {
128127
builder.event(new ClickEvent(
129128
ClickEvent.Action.RUN_COMMAND,
@@ -132,7 +131,7 @@ public void sendItemHologramChat(@NotNull Player player, @NotNull String text, @
132131
shop.getRuntimeRandomUniqueId().toString())));
133132
}
134133
return new QuickComponentImpl(builder.create());
135-
} catch (Throwable t) {
134+
} catch (Exception t) {
136135
plugin.getLogger().log(Level.WARNING, "Failed to process chat component", t);
137136
return new QuickComponentImpl(errorComponent);
138137
}
@@ -145,7 +144,7 @@ public void sendItemHologramChat(@NotNull Player player, @NotNull String text, @
145144
String json;
146145
try {
147146
json = ReflectFactory.convertBukkitItemStackToJson(itemStack);
148-
} catch (Throwable throwable) {
147+
} catch (Exception throwable) {
149148
plugin.getLogger().log(Level.SEVERE, "Failed to saving item to json for holochat", throwable);
150149
return new QuickComponentImpl(errorComponent);
151150
}

src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Find.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,10 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
9595
}
9696
}
9797
if (excludeOutOfStock) {
98-
if (shop.isSelling()) {
99-
if (shop.getRemainingStock() == 0) {
100-
continue;
101-
}
102-
} else if (shop.isBuying()) {
103-
if (shop.getRemainingSpace() == 0) {
104-
continue;
105-
}
98+
if (shop.isSelling() && shop.getRemainingStock() == 0) {
99+
continue;
100+
} else if (shop.isBuying() && shop.getRemainingSpace() == 0) {
101+
continue;
106102
}
107103
}
108104
aroundShops.put(shop, distance);

src/main/java/org/maxgamer/quickshop/database/SQLiteCore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ synchronized void close() {
5656

5757

5858
@Override
59-
synchronized protected DatabaseConnection getConnection0() {
59+
protected synchronized DatabaseConnection getConnection0() {
6060
if (this.connection == null) {
6161
return connection = genConnection();
6262
}
@@ -75,7 +75,7 @@ synchronized protected DatabaseConnection getConnection0() {
7575
}
7676

7777
@Nullable
78-
synchronized private DatabaseConnection genConnection() {
78+
private synchronized DatabaseConnection genConnection() {
7979
if (this.dbFile.exists()) {
8080
try {
8181
Class.forName("org.sqlite.JDBC");

src/main/java/org/maxgamer/quickshop/database/SimpleDatabaseHelper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,11 @@ public SimpleWarpedResultSet selectAllMessages() throws SQLException {
294294
@Override
295295
public SimpleWarpedResultSet selectTable(String table) throws SQLException {
296296
DatabaseConnection databaseConnection = manager.getDatabase().getConnection();
297-
Statement st = databaseConnection.get().createStatement();
298-
String sql = "SELECT * FROM " + plugin.getDbPrefix() + table;
299-
ResultSet resultSet = st.executeQuery(sql);
300-
return new SimpleWarpedResultSet(st, resultSet, databaseConnection);
297+
try (Statement st = databaseConnection.get().createStatement()) {
298+
String sql = "SELECT * FROM " + plugin.getDbPrefix() + table;
299+
ResultSet resultSet = st.executeQuery(sql);
300+
return new SimpleWarpedResultSet(st, resultSet, databaseConnection);
301+
}
301302
}
302303

303304
@Override

src/main/java/org/maxgamer/quickshop/economy/Economy_Reserve.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void setup() {
9494
@Override
9595
public boolean deposit(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency) {
9696
try {
97-
return Objects.requireNonNull(reserve).addHoldings(name, new BigDecimal(amount), world.getName(), currency);
97+
return Objects.requireNonNull(reserve).addHoldings(name, BigDecimal.valueOf(amount), world.getName(), currency);
9898
} catch (Exception throwable) {
9999
plugin.getSentryErrorReporter().ignoreThrow();
100100
plugin.getLogger().log(Level.WARNING, errorMsg, throwable);
@@ -118,7 +118,7 @@ public boolean deposit(@NotNull OfflinePlayer trader, double amount, @NotNull Wo
118118
@Override
119119
public String format(double balance, @NotNull World world, @Nullable String currency) {
120120
try {
121-
return Objects.requireNonNull(reserve).format(new BigDecimal(balance), world.getName(), currency);
121+
return Objects.requireNonNull(reserve).format(BigDecimal.valueOf(balance), world.getName(), currency);
122122
} catch (Exception throwable) {
123123
plugin.getSentryErrorReporter().ignoreThrow();
124124
plugin.getLogger().log(Level.WARNING, errorMsg, throwable);
@@ -172,7 +172,7 @@ public double getBalance(@NotNull OfflinePlayer player, @NotNull World world, @N
172172
@Deprecated
173173
public boolean transfer(@NotNull UUID from, @NotNull UUID to, double amount, @NotNull World world, @Nullable String currency) {
174174
try {
175-
return Objects.requireNonNull(reserve).transferHoldings(from, to, new BigDecimal(amount), world.getName(), currency);
175+
return Objects.requireNonNull(reserve).transferHoldings(from, to, BigDecimal.valueOf(amount), world.getName(), currency);
176176
} catch (Exception throwable) {
177177
plugin.getSentryErrorReporter().ignoreThrow();
178178
plugin.getLogger().log(Level.WARNING, errorMsg, throwable);
@@ -190,7 +190,7 @@ public boolean transfer(@NotNull UUID from, @NotNull UUID to, double amount, @No
190190
@Override
191191
public boolean withdraw(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency) {
192192
try {
193-
return Objects.requireNonNull(reserve).removeHoldings(name, new BigDecimal(amount));
193+
return Objects.requireNonNull(reserve).removeHoldings(name, BigDecimal.valueOf(amount));
194194
} catch (Exception throwable) {
195195
plugin.getSentryErrorReporter().ignoreThrow();
196196
plugin.getLogger().log(Level.WARNING, errorMsg, throwable);

0 commit comments

Comments
 (0)