Skip to content

Commit b487daa

Browse files
[Transfer] Check limit when transferring shop and bump version
1 parent 2305105 commit b487daa

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<artifactId>QuickShop</artifactId>
2626

2727
<properties>
28-
<pluginver>5.1.2.1</pluginver>
28+
<pluginver>5.1.2.2</pluginver>
2929
<package>org.maxgamer.quickshop</package>
3030
<developer>Ghost-chu</developer>
3131
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

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

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

2020
package org.maxgamer.quickshop.command.subcommand;
2121

22+
import org.bukkit.command.CommandSender;
2223
import org.bukkit.entity.Player;
2324
import org.jetbrains.annotations.NotNull;
2425
import org.jetbrains.annotations.Nullable;
@@ -55,6 +56,16 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
5556
}
5657
final UUID targetPlayerUUID = targetPlayer.getUuid();
5758
List<Shop> shopList = plugin.getShopManager().getPlayerAllShops(sender.getUniqueId());
59+
if (plugin.isLimit()) {
60+
final Player player = plugin.getServer().getPlayer(targetPlayerUUID);
61+
if (player == null) {
62+
plugin.text().of(sender, "unknown-player").send();
63+
return;
64+
}
65+
if (!checkAndSendLimitMessage(player, sender, shopList.size())) {
66+
return;
67+
}
68+
}
5869
for (Shop shop : shopList) {
5970
if (!shop.isBuying()) {
6071
shop.setOwner(targetPlayerUUID);
@@ -88,6 +99,16 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
8899
}
89100
final UUID targetPlayerUUID = targetPlayer.getUuid();
90101
List<Shop> shopList = plugin.getShopManager().getPlayerAllShops(fromPlayer.getUuid());
102+
if (plugin.isLimit()) {
103+
final Player player = plugin.getServer().getPlayer(targetPlayerUUID);
104+
if (player == null) {
105+
plugin.text().of(sender, "unknown-player").send();
106+
return;
107+
}
108+
if (!checkAndSendLimitMessage(player, sender, shopList.size())) {
109+
return;
110+
}
111+
}
91112
for (Shop shop : shopList) {
92113
shop.setOwner(targetPlayerUUID);
93114
}
@@ -98,6 +119,27 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
98119
}
99120
}
100121

122+
private boolean checkAndSendLimitMessage(Player checkingPlayer, CommandSender commandSender, int increment) {
123+
if (plugin.isLimit()) {
124+
int owned = 0;
125+
if (plugin.getConfig().getBoolean("limits.old-algorithm")) {
126+
owned = plugin.getShopManager().getPlayerAllShops(checkingPlayer.getUniqueId()).size();
127+
} else {
128+
for (final Shop shop : plugin.getShopManager().getPlayerAllShops(checkingPlayer.getUniqueId())) {
129+
if (!shop.isUnlimited()) {
130+
owned++;
131+
}
132+
}
133+
}
134+
int max = plugin.getShopLimit(checkingPlayer);
135+
if (owned + increment <= max) {
136+
plugin.text().of(commandSender, "reached-maximum-other-can-hold", String.valueOf(owned), String.valueOf(max)).send();
137+
return false;
138+
}
139+
}
140+
return true;
141+
}
142+
101143
@Override
102144
public @Nullable List<String> onTabComplete(@NotNull Player sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
103145
return cmdArg.length <= 2 ? Util.getPlayerList() : Collections.emptyList();

src/main/resources/lang/messages.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"unknown-owner": "Unknown",
7171
"owner-bypass-check": "&eBypassed all checks. Trade successful! (You are now the shop owner!)",
7272
"reached-maximum-can-create": "&cYou already created a maximum of {0}/{1} shops!",
73+
"reached-maximum-other-can-hold": "&cTarget player has reached the maximum of {0}/{1} shops!",
7374
"restricted-prices": "&cRestricted price for {0}: Min {1}, max {2}",
7475
"no-enough-money-to-keep-shops": "&cYou didn't have enough money to keep your shops! All shops have been removed...",
7576
"nothing-to-flush": "&aYou have no new shop messages.",

0 commit comments

Comments
 (0)