1919
2020package org .maxgamer .quickshop .command .subcommand ;
2121
22+ import org .bukkit .command .CommandSender ;
2223import org .bukkit .entity .Player ;
2324import org .jetbrains .annotations .NotNull ;
2425import 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 ();
0 commit comments