Skip to content

Commit 03971d2

Browse files
Add include-offlineplayer-for-command option
1 parent 0191c9a commit 03971d2

File tree

12 files changed

+33
-19
lines changed

12 files changed

+33
-19
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ public class QuickShop extends JavaPlugin implements QuickShopAPI {
296296
@Getter
297297
private boolean allowStack;
298298
@Getter
299+
private boolean includeOfflinePlayer;
300+
@Getter
299301
private EnvironmentChecker environmentChecker;
300302
@Getter
301303
@Nullable
@@ -569,7 +571,7 @@ public boolean loadEcon() {
569571
if (Util.isUUID(taxAccount)) {
570572
tax = PlayerFinder.findOfflinePlayerByUUID(UUID.fromString(taxAccount));
571573
} else {
572-
tax = PlayerFinder.findOfflinePlayerByUUID(PlayerFinder.findUUIDByName(Objects.requireNonNull(taxAccount), true));
574+
tax = PlayerFinder.findOfflinePlayerByUUID(PlayerFinder.findUUIDByName(Objects.requireNonNull(taxAccount), true, true));
573575
}
574576
Economy_Vault vault = (Economy_Vault) economy;
575577
if (vault.isValid()) {
@@ -672,6 +674,7 @@ public void reloadConfiguration() {
672674
this.priceChangeRequiresFee = this.getConfig().getBoolean("shop.price-change-requires-fee");
673675
this.displayItemCheckTicks = this.getConfig().getInt("shop.display-items-check-ticks");
674676
this.allowStack = this.getConfig().getBoolean("shop.allow-stacks");
677+
this.includeOfflinePlayer = this.getConfig().getBoolean("include-offlineplayer-for-command");
675678
this.currency = this.getConfig().getString("currency");
676679
this.loggingLocation = this.getConfig().getInt("logging.location");
677680
if (StringUtils.isEmpty(this.currency)) {
@@ -2220,6 +2223,10 @@ private void updateConfig(int selectedVersion) throws IOException {
22202223
getConfig().set("database.mysql-connect-options", new ArrayList<>(Arrays.asList("autoReconnect=true", "useUnicode=true", "characterEncoding=utf8")));
22212224
getConfig().set("config-version", ++selectedVersion);
22222225
}
2226+
if (selectedVersion == 161) {
2227+
getConfig().set("include-offlineplayer-for-command", false);
2228+
getConfig().set("config-version", ++selectedVersion);
2229+
}
22232230
if (getConfig().isSet("shop.shop")) {
22242231
getConfig().set("shop.shop", null);
22252232
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void onCommand(@NotNull CommandSender sender, @NotNull String commandLabe
4848
if (cmdArg.length == 1) {
4949
//copy it first
5050
List<Shop> tempList = new ArrayList<>(plugin.getShopManager().getAllShops());
51-
PlayerFinder.PlayerProfile shopOwner = PlayerFinder.findPlayerProfileByName(cmdArg[0], false);
51+
PlayerFinder.PlayerProfile shopOwner = PlayerFinder.findPlayerProfileByName(cmdArg[0], false, plugin.isIncludeOfflinePlayer());
5252
if (shopOwner == null) {
5353
plugin.text().of(sender, "unknown-player").send();
5454
return;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
5757
continue;
5858
}
5959

60-
final PlayerFinder.PlayerProfile newShopOwnerProfile = PlayerFinder.findPlayerProfileByName(cmdArg[0], false);
60+
final PlayerFinder.PlayerProfile newShopOwnerProfile = PlayerFinder.findPlayerProfileByName(cmdArg[0], false, plugin.isIncludeOfflinePlayer());
6161
if (newShopOwnerProfile == null) {
6262
plugin.text().of(sender, "unknown-player").send();
6363
return;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
8484
return;
8585
}
8686
case 2:
87-
final PlayerFinder.PlayerProfile profile = PlayerFinder.findPlayerProfileByName(cmdArg[1], false);
87+
final PlayerFinder.PlayerProfile profile = PlayerFinder.findPlayerProfileByName(cmdArg[1], false, plugin.isIncludeOfflinePlayer());
8888
if (profile == null) {
8989
plugin.text().of(sender, "unknown-player").send();
9090
return;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
5454
if (Util.isUUID(cmdArg[0])) {
5555
shop.setTaxAccount(UUID.fromString(cmdArg[0]));
5656
} else {
57-
UUID uuid = PlayerFinder.findUUIDByName(cmdArg[0], false);
57+
UUID uuid = PlayerFinder.findUUIDByName(cmdArg[0], false, plugin.isIncludeOfflinePlayer());
5858
if (uuid == null) {
5959
plugin.text().of(sender, "unknown-player").send();
6060
return;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public SubCommand_Transfer(QuickShop plugin) {
4444
@Override
4545
public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
4646
if (cmdArg.length == 1) {
47-
final PlayerFinder.PlayerProfile targetPlayer = PlayerFinder.findPlayerProfileByName(cmdArg[0], false);
47+
final PlayerFinder.PlayerProfile targetPlayer = PlayerFinder.findPlayerProfileByName(cmdArg[0], false, plugin.isIncludeOfflinePlayer());
4848
if (targetPlayer == null) {
4949
plugin.text().of(sender, "unknown-player").send();
5050
return;
@@ -67,7 +67,7 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
6767
return;
6868
}
6969

70-
final PlayerFinder.PlayerProfile fromPlayer = PlayerFinder.findPlayerProfileByName(cmdArg[0], false);
70+
final PlayerFinder.PlayerProfile fromPlayer = PlayerFinder.findPlayerProfileByName(cmdArg[0], false, plugin.isIncludeOfflinePlayer());
7171
if (fromPlayer == null) {
7272
plugin.text().of(sender, "unknown-player").send();
7373
return;
@@ -77,7 +77,7 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
7777
fromPlayerName = "null";
7878
}
7979
//FIXME: Update this when drop 1.15 supports
80-
final PlayerFinder.PlayerProfile targetPlayer = PlayerFinder.findPlayerProfileByName(cmdArg[1], false);
80+
final PlayerFinder.PlayerProfile targetPlayer = PlayerFinder.findPlayerProfileByName(cmdArg[1], false, plugin.isIncludeOfflinePlayer());
8181
if (targetPlayer == null) {
8282
plugin.text().of(sender, "unknown-player").send();
8383
return;

src/main/java/org/maxgamer/quickshop/shop/ShopLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public class ShopDatabaseInfo {
491491
shopModerator = SimpleShopModerator.deserialize(moderatorJson);
492492
} catch (JsonSyntaxException ex) {
493493
Util.debugLog("Updating old shop data... for " + moderatorJson);
494-
moderatorJson = PlayerFinder.findUUIDByName(moderatorJson, true).toString();
494+
moderatorJson = PlayerFinder.findUUIDByName(moderatorJson, true, true).toString();
495495
shopModerator = new SimpleShopModerator(UUID.fromString(moderatorJson)); // New one
496496
needUpdate.set(true);
497497
}

src/main/java/org/maxgamer/quickshop/shop/SimpleShopManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private void init() {
142142
if (Util.isUUID(taxAccount)) {
143143
this.cacheTaxAccount = new Trader(taxAccount, PlayerFinder.findOfflinePlayerByUUID(UUID.fromString(taxAccount)));
144144
} else {
145-
this.cacheTaxAccount = PlayerFinder.findPlayerProfileByName(taxAccount, true).getTrader();
145+
this.cacheTaxAccount = PlayerFinder.findPlayerProfileByName(taxAccount, true, true).getTrader();
146146
}
147147
} else {
148148
// disable tax account
@@ -157,7 +157,7 @@ private void init() {
157157
if (Util.isUUID(uAccount)) {
158158
cacheUnlimitedShopAccount = new Trader(uAccount, PlayerFinder.findOfflinePlayerByUUID(UUID.fromString(uAccount)));
159159
} else {
160-
cacheUnlimitedShopAccount = PlayerFinder.findPlayerProfileByName(uAccount, true).getTrader();
160+
cacheUnlimitedShopAccount = PlayerFinder.findPlayerProfileByName(uAccount, true, true).getTrader();
161161
}
162162
}
163163
this.priceLimiter = new SimplePriceLimiter(

src/main/java/org/maxgamer/quickshop/util/MsgUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public static void loadTransactionMessages() {
365365
if (Util.isUUID(owner)) {
366366
ownerUUID = UUID.fromString(owner);
367367
} else {
368-
ownerUUID = PlayerFinder.findUUIDByName(owner, true);
368+
ownerUUID = PlayerFinder.findUUIDByName(owner, true, true);
369369
}
370370
String message = rs.getString("message");
371371
List<ShopTransactionMessageContainer> msgs = OUTGOING_MESSAGES.computeIfAbsent(ownerUUID, k -> new LinkedList<>());

src/main/java/org/maxgamer/quickshop/util/PlayerFinder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public static void doLargeOfflineCachingWork(QuickShop quickShop, OfflinePlayer[
136136
* @param forceWebRequest whether to use web request, may result blocking server thread
137137
* @return the uuid of this player name, null when [forceWebRequest] is false
138138
*/
139-
public static PlayerProfile findPlayerProfileByName(String name, boolean forceWebRequest) {
140-
UUID uuid = findUUIDByName(name, forceWebRequest);
139+
public static PlayerProfile findPlayerProfileByName(String name, boolean forceWebRequest, boolean checkOfflinePlayer) {
140+
UUID uuid = findUUIDByName(name, forceWebRequest, checkOfflinePlayer);
141141
if (uuid != null) {
142142
return new PlayerProfile(findNameByUUID(uuid), uuid);
143143
} else {
@@ -159,10 +159,11 @@ private static void puttingToCache(String realPlayerName, UUID uuid) {
159159
*
160160
* @param name the player name, case ignored
161161
* @param includingBlockingWebReq whether to use web request, may result blocking server thread
162+
* @param checkOfflinePlayer whether to check offline player, beware that should be a large cost for some times
162163
* @return the uuid of this player name, null when [includingBlockingWebReq] is false
163164
*/
164165
@Nullable
165-
public static UUID findUUIDByName(String name, boolean includingBlockingWebReq) {
166+
public static UUID findUUIDByName(String name, boolean includingBlockingWebReq, boolean checkOfflinePlayer) {
166167

167168
UUID uuid = name2UUIDCache.getIfPresent(name.toLowerCase(Locale.ROOT));
168169

@@ -177,7 +178,7 @@ public static UUID findUUIDByName(String name, boolean includingBlockingWebReq)
177178
//Online
178179
PlayerProfile profile = findProfileByName(name, server.getOnlinePlayers(), false);
179180
//Offline
180-
if (!useOfflineStash && profile == null) {
181+
if (!useOfflineStash && checkOfflinePlayer && profile == null) {
181182
profile = findProfileByName(name, Arrays.asList(server.getOfflinePlayers()), true);
182183
}
183184
//Blocking web request/querying user cache

0 commit comments

Comments
 (0)