Skip to content

Commit 4bb0e18

Browse files
committed
Prevent directly hook into not exists economy system even the configuration marked
1 parent e1919ad commit 4bb0e18

File tree

8 files changed

+78
-16
lines changed

8 files changed

+78
-16
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,15 @@ public static BootError econError() {
6666
"compatible economy plugin installed to get Vault working.");
6767
}
6868

69+
/**
70+
* Call îf economy system failed to load. This checks the failure reason.
71+
*
72+
* @return The error reason.
73+
*/
74+
public static BootError econHandlerMissingError() {
75+
// Check if Vault is installed
76+
return new BootError(QuickShop.getInstance().getLogger(),
77+
"The selected economy handler not installed", "Please check the configuration.");
78+
}
79+
6980
}

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.maxgamer.quickshop.chat.platform.minedown.BungeeQuickChat;
6363
import org.maxgamer.quickshop.command.SimpleCommandManager;
6464
import org.maxgamer.quickshop.database.*;
65+
import org.maxgamer.quickshop.economy.EconomyProviderNotFoundException;
6566
import org.maxgamer.quickshop.economy.Economy_GemsEconomy;
6667
import org.maxgamer.quickshop.economy.Economy_TNE;
6768
import org.maxgamer.quickshop.economy.Economy_Vault;
@@ -497,13 +498,21 @@ public boolean loadEcon() {
497498
return false;
498499
}
499500
economy = ServiceInjector.getEconomy(economy);
501+
if (Objects.equals(this.bootError, BuiltInSolution.econHandlerMissingError()) || Objects.equals(this.bootError, BuiltInSolution.econError())) {
502+
this.bootError = null;
503+
}
500504
} catch (Exception e) {
501-
this.getSentryErrorReporter().ignoreThrow();
502-
getLogger().log(Level.WARNING, "Something going wrong when loading up economy system", e);
503-
getLogger().severe("QuickShop could not hook into a economy/Not found Vault or Reserve!");
504-
getLogger().severe("QuickShop CANNOT start!");
505-
setupBootError(BuiltInSolution.econError(), false);
506-
getLogger().severe("Plugin listeners was disabled, please fix the economy issue.");
505+
if (e instanceof EconomyProviderNotFoundException) {
506+
getLogger().log(Level.WARNING, "Something going wrong when loading up economy system", e);
507+
getLogger().severe("Failed to hook into the Economy Handler that configuration point to!");
508+
getLogger().severe("QuickShop CANNOT start!");
509+
setupBootError(BuiltInSolution.econHandlerMissingError(), false);
510+
} else {
511+
getLogger().log(Level.WARNING, "Something going wrong when loading up economy system", e);
512+
getLogger().severe("QuickShop could not hook into a economy/Not found Vault or Reserve!");
513+
getLogger().severe("QuickShop CANNOT start!");
514+
setupBootError(BuiltInSolution.econError(), false);
515+
}
507516
return false;
508517
}
509518
return true;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is EconomyProviderNotFoundException.java
3+
* Copyright (C) PotatoCraft Studio and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
package org.maxgamer.quickshop.economy;
21+
22+
public class EconomyProviderNotFoundException extends RuntimeException {
23+
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import lombok.ToString;
2525
import me.xanium.gemseconomy.api.GemsEconomyAPI;
2626
import me.xanium.gemseconomy.currency.Currency;
27+
import org.bukkit.Bukkit;
2728
import org.bukkit.OfflinePlayer;
2829
import org.bukkit.World;
2930
import org.bukkit.plugin.Plugin;
@@ -47,7 +48,7 @@ public class Economy_GemsEconomy extends AbstractEconomy {
4748
@Setter
4849
private GemsEconomyAPI api;
4950

50-
public Economy_GemsEconomy(@NotNull QuickShop plugin) {
51+
public Economy_GemsEconomy(@NotNull QuickShop plugin) throws EconomyProviderNotFoundException {
5152
super();
5253
this.plugin = plugin;
5354
this.formatter = new BuiltInEconomyFormatter(plugin);
@@ -61,7 +62,10 @@ private void init() {
6162
this.allowLoan = plugin.getConfiguration().getBoolean("shop.allow-economy-loan");
6263
}
6364

64-
private void setupEconomy() {
65+
private void setupEconomy() throws EconomyProviderNotFoundException {
66+
if (Bukkit.getPluginManager().getPlugin("GemsEconomy") == null) {
67+
throw new EconomyProviderNotFoundException();
68+
}
6569
this.api = new GemsEconomyAPI();
6670
}
6771

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class Economy_Reserve extends AbstractEconomy {
6262
* @deprecated Reserve no-longer active after Minecraft 1.14.
6363
*/
6464
@Deprecated
65-
public Economy_Reserve(@NotNull QuickShop plugin) {
65+
public Economy_Reserve(@NotNull QuickShop plugin) throws EconomyProviderNotFoundException {
6666
this.plugin = plugin;
6767
this.formatter = new BuiltInEconomyFormatter(plugin);
6868
plugin.getReloadManager().register(this);
@@ -71,14 +71,19 @@ public Economy_Reserve(@NotNull QuickShop plugin) {
7171
}
7272

7373
@SuppressWarnings("ConstantConditions")
74-
private void setup() {
74+
private void setup() throws EconomyProviderNotFoundException {
7575
try {
76+
Plugin pl = plugin.getServer().getPluginManager().getPlugin("Reserve");
77+
if (pl == null) {
78+
throw new EconomyProviderNotFoundException();
79+
}
7680
Reserve re = ((Reserve) plugin.getServer().getPluginManager().getPlugin("Reserve"));
7781
if (re.economyProvided()) {
7882
reserve = re.economy();
7983
}
8084
} catch (Exception throwable) {
8185
reserve = null;
86+
plugin.getLogger().log(Level.SEVERE, "Failed to load up Reserve", throwable);
8287
}
8388
}
8489

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class Economy_TNE extends AbstractEconomy {
4949
@Setter
5050
private TNEAPI api;
5151

52-
public Economy_TNE(@NotNull QuickShop plugin) {
52+
public Economy_TNE(@NotNull QuickShop plugin) throws EconomyProviderNotFoundException {
5353
super();
5454
this.plugin = plugin;
5555
plugin.getReloadManager().register(this);
@@ -61,7 +61,12 @@ private void init() {
6161
this.allowLoan = plugin.getConfiguration().getBoolean("shop.allow-economy-loan");
6262
}
6363

64-
private void setupEconomy() {
64+
private void setupEconomy() throws EconomyProviderNotFoundException {
65+
if (Bukkit.getPluginManager().getPlugin("TNE") == null
66+
&& Bukkit.getPluginManager().getPlugin("TNE-Bukkit") == null
67+
&& Bukkit.getPluginManager().getPlugin("TheNewEconomy") == null) {
68+
throw new EconomyProviderNotFoundException();
69+
}
6570
this.api = TNE.instance().api();
6671
}
6772

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class Economy_Vault extends AbstractEconomy implements Listener {
5858
private net.milkbowl.vault.economy.Economy vault;
5959

6060

61-
public Economy_Vault(@NotNull QuickShop plugin) {
61+
public Economy_Vault(@NotNull QuickShop plugin) throws EconomyProviderNotFoundException {
6262
super();
6363
this.plugin = plugin;
6464
this.formatter = new BuiltInEconomyFormatter(plugin);
@@ -71,15 +71,16 @@ private void init() {
7171
this.allowLoan = plugin.getConfiguration().getBoolean("shop.allow-economy-loan");
7272
}
7373

74-
private boolean setupEconomy() {
74+
private boolean setupEconomy() throws EconomyProviderNotFoundException {
7575
if (!Util.isClassAvailable("net.milkbowl.vault.economy.Economy")) {
76-
return false; // QUICKSHOP-YS I can't believe it broken almost a year and nobody found it, my sentry exploded.
76+
throw new EconomyProviderNotFoundException();
7777
}
7878
RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> economyProvider;
7979
try {
8080
economyProvider = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
8181
} catch (Exception e) {
82-
return false;
82+
plugin.getLogger().log(Level.SEVERE, "Failed to getting vault registration", e);
83+
throw new EconomyProviderNotFoundException();
8384
}
8485

8586
if (economyProvider != null) {

src/main/resources/plugin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ softdepend:
6868
- IridiumSkyblock
6969
- FabledSkyblock
7070
- NBTAPI
71+
- TNE
72+
- TNE-Bukkit
73+
- TheNewEconomy
74+
- GemsEconomy
7175

7276
api-version: 1.15
7377

0 commit comments

Comments
 (0)