Skip to content

Commit 922536d

Browse files
committed
fix: /qs supercreate can't bypass the protection checks
1 parent 6f589ba commit 922536d

File tree

7 files changed

+52
-21
lines changed

7 files changed

+52
-21
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is Info.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+
120
package org.maxgamer.quickshop.api.shop;
221

322
import org.bukkit.Location;
@@ -40,4 +59,11 @@ public interface Info {
4059
*/
4160
boolean hasChanged(@NotNull Shop shop);
4261

62+
/**
63+
* Check if this Info marked as skip protection checks
64+
*
65+
* @return Bypassed Protection Checks
66+
*/
67+
boolean isBypassed();
68+
4369
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public interface ShopManager {
156156

157157
void handleChat(@NotNull Player p, @NotNull String msg);
158158

159-
void handleChat(@NotNull Player p, @NotNull String msg, boolean bypassProtectionChecks);
159+
// void handleChat(@NotNull Player p, @NotNull String msg, boolean bypassProtectionChecks);
160160

161161
/**
162162
* Load shop method for loading shop into mapping, so getShops method will can find it. It also

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
148148

149149
// Send creation menu.
150150
plugin.getShopManager().getActions().put(sender.getUniqueId(),
151-
new SimpleInfo(b.getLocation(), ShopAction.CREATE, item, b.getRelative(sender.getFacing().getOppositeFace())));
151+
new SimpleInfo(b.getLocation(), ShopAction.CREATE, item, b.getRelative(sender.getFacing().getOppositeFace()), false));
152152
plugin.getShopManager().handleChat(sender, price);
153153
return;
154154
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
5858
continue;
5959
}
6060

61-
if (cmdArg.length >= 1) {
62-
plugin.getShopManager().handleChat(sender, cmdArg[0], true);
63-
return;
64-
}
61+
// if (cmdArg.length >= 1) {
62+
// plugin.getShopManager().handleChat(sender, cmdArg[0], true);
63+
// return;
64+
// }
6565
// Send creation menu.
66-
final SimpleInfo info = new SimpleInfo(b.getLocation(), ShopAction.CREATE, sender.getInventory().getItemInMainHand(), b.getRelative(sender.getFacing().getOppositeFace()));
66+
final SimpleInfo info = new SimpleInfo(b.getLocation(), ShopAction.CREATE, sender.getInventory().getItemInMainHand(), b.getRelative(sender.getFacing().getOppositeFace()), true);
6767

6868
plugin.getShopManager().getActions().put(sender.getUniqueId(), info);
6969
plugin.text().of(sender, "how-much-to-trade-for", MsgUtil.convertItemStackToTranslateText(info.getItem().getType()), Integer.toString(plugin.isAllowStack() && QuickShop.getPermissionManager().hasPermission(sender, "quickshop.create.stacks") ? item.getAmount() : 1)).send();

src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private void postTrade(PlayerInteractEvent e) {
234234
}
235235
// Add the new action
236236
Map<UUID, Info> actions = plugin.getShopManager().getActions();
237-
Info info = new SimpleInfo(shop.getLocation(), ShopAction.BUY, null, null, shop);
237+
Info info = new SimpleInfo(shop.getLocation(), ShopAction.BUY, null, null, shop, false);
238238
actions.put(p.getUniqueId(), info);
239239
}
240240
// Handles creating shops
@@ -287,7 +287,7 @@ else if (e.useInteractedBlock() == Event.Result.ALLOW
287287
last = n;
288288
}
289289
// Send creation menu.
290-
final SimpleInfo info = new SimpleInfo(b.getLocation(), ShopAction.CREATE, e.getItem(), last);
290+
final SimpleInfo info = new SimpleInfo(b.getLocation(), ShopAction.CREATE, e.getItem(), last, false);
291291

292292
plugin.getShopManager().getActions().put(p.getUniqueId(), info);
293293
plugin.text().of(p, "how-much-to-trade-for", MsgUtil.convertItemStackToTranslateText(Objects.requireNonNull(e.getItem()).getType()), Integer.toString(plugin.isAllowStack() && QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.stacks") ? item.getAmount() : 1)).send();

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class SimpleInfo implements Info {
3939
private final Block last;
4040
private final Location loc;
4141
private final boolean dirty;
42+
private final boolean bypass;
4243
private ShopAction action;
4344
private ItemStack item;
4445
private Shop shop;
@@ -47,25 +48,30 @@ public SimpleInfo(
4748
@NotNull Location loc,
4849
@NotNull ShopAction action,
4950
@Nullable ItemStack item,
50-
@Nullable Block last) {
51+
@Nullable Block last,
52+
boolean bypass) {
5153
this.loc = loc;
5254
this.action = action;
5355
this.last = last;
56+
this.bypass = bypass;
5457
if (item != null) {
5558
this.item = item.clone();
5659
}
5760
this.dirty = true;
5861
}
5962

63+
6064
public SimpleInfo(
6165
@NotNull Location loc,
6266
@NotNull ShopAction action,
6367
@Nullable ItemStack item,
6468
@Nullable Block last,
65-
@Nullable Shop shop) {
69+
@Nullable Shop shop,
70+
boolean bypass) {
6671
this.loc = loc;
6772
this.action = action;
6873
this.last = last;
74+
this.bypass = bypass;
6975
if (item != null) {
7076
this.item = item.clone();
7177
}
@@ -148,4 +154,9 @@ public boolean hasChanged(@NotNull Shop shop) {
148154
return !this.shop.matches(shop.getItem());
149155
}
150156

157+
@Override
158+
public boolean isBypassed() {
159+
return bypass;
160+
}
161+
151162
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,6 @@ public Shop getShopFromRuntimeRandomUniqueId(
515515

516516
@Override
517517
public void handleChat(@NotNull Player p, @NotNull String msg) {
518-
handleChat(p, msg, false);
519-
}
520-
521-
@Override
522-
public void handleChat(@NotNull Player p, @NotNull String msg, boolean bypassProtectionChecks) {
523518
if (!plugin.getShopManager().getActions().containsKey(p.getUniqueId())) {
524519
return;
525520
}
@@ -544,7 +539,7 @@ public void handleChat(@NotNull Player p, @NotNull String msg, boolean bypassPro
544539
return;
545540
}
546541
if (info.getAction() == ShopAction.CREATE) {
547-
actionCreate(p, info, finalMessage, bypassProtectionChecks);
542+
actionCreate(p, info, finalMessage);
548543
}
549544
if (info.getAction() == ShopAction.BUY) {
550545
actionTrade(p, info, finalMessage);
@@ -844,8 +839,7 @@ public double getTax(@NotNull Shop shop, @NotNull UUID p) {
844839
return taxEvent.getTax();
845840
}
846841

847-
public void actionCreate(@NotNull Player p, Info info, @NotNull String message,
848-
boolean bypassProtectionChecks) {
842+
public void actionCreate(@NotNull Player p, Info info, @NotNull String message) {
849843
Util.ensureThread(false);
850844
if (plugin.getEconomy() == null) {
851845
MsgUtil.sendDirectMessage(p, "Error: Economy system not loaded, type /qs main command to get details.");
@@ -859,7 +853,7 @@ public void actionCreate(@NotNull Player p, Info info, @NotNull String message,
859853
// Checking the shop can be created
860854
Util.debugLog("Calling for protection check...");
861855
// Fix openInv compatible issue
862-
if (!bypassProtectionChecks) {
856+
if (!info.isBypassed()) {
863857
Result result = plugin.getPermissionChecker().canBuild(p, info.getLocation());
864858
if (!result.isSuccess()) {
865859
plugin.text().of(p, "3rd-plugin-build-check-failed", result.getMessage()).send();
@@ -979,7 +973,7 @@ public void actionCreate(@NotNull Player p, Info info, @NotNull String message,
979973
null,
980974
false,
981975
null);
982-
if (!bypassProtectionChecks) {
976+
if (!info.isBypassed()) {
983977
Result result = ((SimpleIntegrationManager) plugin.getIntegrationHelper()).callIntegrationsCanCreate(p, info.getLocation());
984978
if (!result.isSuccess()) {
985979
plugin.text().of(p, "integrations-check-failed-create", result.getMessage()).send();

0 commit comments

Comments
 (0)