Skip to content

Commit cf30ecd

Browse files
committed
Merge branch 'release/3.3.2'
2 parents 7d5e736 + 58a74d2 commit cf30ecd

26 files changed

Lines changed: 356 additions & 70 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ target
4949
target-api
5050
*.java~
5151
*.kts~
52+
.claude
53+
CLAUDE.md
54+
gradle.properties

API/src/main/java/fr/maxlego08/shop/api/event/ShopAction.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ public class ShopAction {
88
private final ItemStack itemStack;
99
private final ItemButton itemButton;
1010
private double price;
11+
private int totalAmount;
1112

1213
public ShopAction(ItemStack itemStack, ItemButton itemButton, double price) {
1314
this.itemStack = itemStack;
1415
this.itemButton = itemButton;
1516
this.price = price;
17+
this.totalAmount = itemStack.getAmount();
1618
}
1719

1820
public ItemStack getItemStack() {
@@ -30,4 +32,16 @@ public double getPrice() {
3032
public void setPrice(double price) {
3133
this.price = price;
3234
}
35+
36+
public int getTotalAmount() {
37+
return totalAmount;
38+
}
39+
40+
public void setTotalAmount(int totalAmount) {
41+
this.totalAmount = totalAmount;
42+
}
43+
44+
public void addAmount(int amount) {
45+
this.totalAmount += amount;
46+
}
3347
}

API/src/main/java/fr/maxlego08/shop/api/limit/LimiterManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public interface LimiterManager {
99

1010
Collection<Limit> getLimits();
1111

12+
Collection<Limit> getLimits(LimitType limitType);
13+
1214
void create(Limit limit);
1315

1416
Optional<Limit> getLimit(LimitType limitType, String material);

build.gradle.kts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "fr.maxlego08.shop"
10-
version = "3.3.1"
10+
version = "3.3.2"
1111

1212
extra.set("targetFolder", file("target/"))
1313
extra.set("apiFolder", file("target-api/"))
@@ -47,6 +47,7 @@ allprojects {
4747

4848
tasks.compileJava {
4949
options.encoding = "UTF-8"
50+
options.release = 21
5051
}
5152

5253
tasks.javadoc {
@@ -58,7 +59,7 @@ allprojects {
5859
dependencies {
5960
compileOnly("org.spigotmc:spigot-api:1.21.5-R0.1-SNAPSHOT")
6061
compileOnly("me.clip:placeholderapi:2.11.6")
61-
compileOnly("fr.maxlego08.menu:zmenu-api:1.1.0.0")
62+
compileOnly("fr.maxlego08.menu:zmenu-api:1.1.0.8")
6263

6364
}
6465
}
@@ -88,10 +89,6 @@ tasks {
8889
dependsOn(shadowJar)
8990
}
9091

91-
compileJava {
92-
options.release = 21
93-
}
94-
9592
processResources {
9693
from("resources")
9794
filesMatching("plugin.yml") {

changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44

55
# Unreleased
66

7+
# 3.3.2
8+
9+
- **Added**: Reset limit commands (#22)
10+
- `/zshoplugin resetlimit` - Main reset commands menu
11+
- `/zshoplugin resetlimit player <player> <material>` - Reset a player's limit for an item
12+
- `/zshoplugin resetlimit server <material>` - Reset the server limit for an item
13+
- `/zshoplugin resetlimit all` - Reset all limits
14+
- **Fixed**: `%buyPrice%` and `%sellPrice%` placeholders now display the total price in confirmation button lore (#18)
15+
- **Fixed**: Item overflow when selling
16+
- **Fixed**: Amount calculation when selling
17+
- **Fixed**: ItemStack size issue
18+
- **Updated**: zMenu to version 1.1.0.8
19+
720
# 3.3.1
821

922
- Fix button load event

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/java/fr/maxlego08/shop/ZShopManager.java

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -392,21 +392,21 @@ public void sellAllContent(Player player, org.bukkit.inventory.Inventory invento
392392
List<Pair<ItemStack, ItemButton>> buttons = this.itemButtons.stream().map(button -> {
393393
ItemStack itemStack = button.getItemStack().build(player, false);
394394
return new Pair<>(itemStack, button);
395-
}).collect(Collectors.toList());
395+
}).toList();
396396

397397
/* SCAN ITEMS */
398398
for (int slot = 0; slot != inventory.getContents().length; slot++) {
399399
ItemStack itemStack = inventory.getContents()[slot];
400400
if (itemStack == null) continue;
401401

402402
Optional<ItemButton> optional = buttons.stream().filter(e -> e.first.isSimilar(itemStack)).map(e -> e.second).findFirst();
403-
if (!optional.isPresent()) continue;
403+
if (optional.isEmpty()) continue;
404404

405405
ItemButton itemButton = optional.get();
406406
if (!itemButton.canSell()) continue;
407407

408408
double price = itemButton.getSellPrice(player, itemStack.getAmount());
409-
ShopAction shopAction = new ShopAction(itemStack, itemButton, price);
409+
ShopAction shopAction = new ShopAction(itemStack.clone(), itemButton, price);
410410
shopActions.add(shopAction);
411411
}
412412

@@ -424,6 +424,8 @@ public void sellAllContent(Player player, org.bukkit.inventory.Inventory invento
424424
ItemButton button = action.getItemButton();
425425
ItemStack itemStack = action.getItemStack();
426426

427+
int requestedAmount = itemStack.getAmount();
428+
int actualSellAmount = requestedAmount; // Amount that will actually be sold
427429
int newServerLimitAmount = 0;
428430
int newPlayerLimitAmount = 0;
429431
String material = button.getItemStack().getMaterial();
@@ -435,20 +437,41 @@ public void sellAllContent(Player player, org.bukkit.inventory.Inventory invento
435437
/* SERVER LIMIT */
436438
if (optionalServer.isPresent()) {
437439
Limit serverSellLimit = optionalServer.get();
438-
newServerLimitAmount = serverSellLimit.getAmount() + itemStack.getAmount();
439-
if (newServerLimitAmount > serverSellLimit.getLimit()) return;
440+
int currentServerAmount = serverSellLimit.getAmount();
441+
int maxCanSell = serverSellLimit.getLimit() - currentServerAmount;
442+
443+
if (maxCanSell <= 0) {
444+
action.setTotalAmount(0);
445+
return;
446+
}
447+
actualSellAmount = Math.min(actualSellAmount, maxCanSell);
448+
newServerLimitAmount = currentServerAmount + actualSellAmount;
440449
}
441450
/* END SERVER LIMIT */
442451

443452
/* PLAYER LIMIT */
444453
if (optionalPlayer.isPresent()) {
445454
Limit playerSellLimit = optionalPlayer.get();
446455
Optional<PlayerLimit> optional = limiterManager.getLimit(player);
447-
newPlayerLimitAmount = optional.map(e -> e.getSellAmount(material)).orElse(0) + itemStack.getAmount();
448-
if (newPlayerLimitAmount > playerSellLimit.getLimit()) return;
456+
int currentPlayerAmount = optional.map(e -> e.getSellAmount(material)).orElse(0);
457+
int maxCanSell = playerSellLimit.getLimit() - currentPlayerAmount;
458+
459+
if (maxCanSell <= 0) {
460+
action.setTotalAmount(0);
461+
return;
462+
}
463+
actualSellAmount = Math.min(actualSellAmount, maxCanSell);
464+
newPlayerLimitAmount = currentPlayerAmount + actualSellAmount;
449465
}
450466
/* END PLAYER LIMIT */
451467

468+
if (actualSellAmount != requestedAmount) {
469+
itemStack.setAmount(actualSellAmount);
470+
double actualPrice = button.getSellPrice(player, actualSellAmount);
471+
action.setPrice(actualPrice);
472+
}
473+
action.setTotalAmount(actualSellAmount);
474+
452475
/* UPDATE LIMIT VALUES */
453476
if (optionalServer.isPresent()) optionalServer.get().setAmount(newServerLimitAmount);
454477
if (newPlayerLimitAmount > 0)
@@ -457,8 +480,7 @@ public void sellAllContent(Player player, org.bukkit.inventory.Inventory invento
457480

458481
/* REMOVE ITEMS AND UPDATE MONEY */
459482
prices.put(button.getEconomy(), prices.getOrDefault(button.getEconomy(), 0.0) + action.getPrice());
460-
// inventory.remove(itemStack);
461-
InventoryUtils.removeItem(inventory, itemStack, itemStack.getAmount());
483+
InventoryUtils.removeItem(inventory, itemStack, actualSellAmount);
462484
});
463485

464486
if (prices.isEmpty()) {
@@ -469,23 +491,25 @@ public void sellAllContent(Player player, org.bukkit.inventory.Inventory invento
469491
List<ShopAction> fixedShopActions = new ArrayList<>();
470492

471493
shopActions.forEach(action -> {
494+
if (action.getTotalAmount() == 0) return;
495+
472496
Optional<ShopAction> optional = fixedShopActions.stream().filter(e -> e.getItemStack().isSimilar(action.getItemStack())).findFirst();
473497
if (optional.isPresent()) {
474498
ShopAction currentAction = optional.get();
475499
currentAction.setPrice(currentAction.getPrice() + action.getPrice());
476-
currentAction.getItemStack().setAmount(currentAction.getItemStack().getAmount() + action.getItemStack().getAmount());
500+
currentAction.addAmount(action.getTotalAmount());
477501
} else fixedShopActions.add(action);
478502
});
479503

480504
var translationManager = this.plugin.getTranslationManager();
481505

482-
String results = toList(fixedShopActions.stream().map(action -> getMessage(Message.SELL_ALL_INFO, "%amount%", action.getItemStack().getAmount(), "%item%", translationManager.translateItemStack(action.getItemStack()), "%price%", action.getItemButton().getEconomy().format(transformPrice(action.getPrice()), action.getPrice()))).collect(Collectors.toList()), Message.SELL_ALL_COLOR_SEPARATOR.msg(), Message.SELL_ALL_COLOR_INFO.msg());
506+
String results = toList(fixedShopActions.stream().map(action -> getMessage(Message.SELL_ALL_INFO, "%amount%", action.getTotalAmount(), "%item%", translationManager.translateItemStack(action.getItemStack()), "%price%", action.getItemButton().getEconomy().format(transformPrice(action.getPrice()), action.getPrice()))).collect(Collectors.toList()), Message.SELL_ALL_COLOR_SEPARATOR.msg(), Message.SELL_ALL_COLOR_INFO.msg());
483507
if (results == null) {
484508
Logger.info("Error with results on sellall !");
485509
player.sendMessage("§cError with results on sellall !");
486510
}
487511

488-
String resultsReason = toList(fixedShopActions.stream().map(action -> getMessage(Config.depositAllLine, "%amount%", action.getItemStack().getAmount(), "%item%", translationManager.translateItemStack(action.getItemStack()), "%price%", action.getItemButton().getEconomy().format(transformPrice(action.getPrice()), action.getPrice()))).collect(Collectors.toList()), "", "");
512+
String resultsReason = toList(fixedShopActions.stream().map(action -> getMessage(Config.depositAllLine, "%amount%", action.getTotalAmount(), "%item%", translationManager.translateItemStack(action.getItemStack()), "%price%", action.getItemButton().getEconomy().format(transformPrice(action.getPrice()), action.getPrice()))).collect(Collectors.toList()), "", "");
489513
prices.forEach((economy, price) -> economy.depositMoney(player, price, Config.depositAllReason.replace("%items%", resultsReason == null ? "" : resultsReason)));
490514

491515
message(this.plugin, player, Message.SELL_ALL_MESSAGE, "%items%", results == null ? "ERROR" : results);
@@ -510,7 +534,7 @@ public void sellAllContent(Player player, org.bukkit.inventory.Inventory invento
510534
public void sellHand(Player player, int amount) {
511535

512536
ItemStack itemInHand = player.getItemInHand(); // Use old method for 1.8 support
513-
if (itemInHand == null || itemInHand.getType().equals(Material.AIR)) {
537+
if (itemInHand.getType().equals(Material.AIR)) {
514538
message(this.plugin, player, Message.SELL_HAND_AIR);
515539
return;
516540
}

src/main/java/fr/maxlego08/shop/buttons/ConfirmationButton.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,57 @@
66
import fr.maxlego08.menu.api.utils.Placeholders;
77
import fr.maxlego08.shop.ShopPlugin;
88
import fr.maxlego08.shop.api.PlayerCache;
9+
import fr.maxlego08.shop.api.buttons.ItemButton;
910
import fr.maxlego08.shop.api.buttons.ShowItemButton;
1011
import fr.maxlego08.shop.save.ConfirmAction;
1112
import org.bukkit.entity.Player;
13+
import org.bukkit.inventory.ItemStack;
14+
import org.bukkit.inventory.meta.ItemMeta;
15+
import org.bukkit.plugin.Plugin;
1216

1317
import java.util.List;
18+
import java.util.stream.Collectors;
1419

15-
public class ConfirmationButton extends Button {
20+
public abstract class ConfirmationButton extends Button {
1621

22+
protected ShopPlugin plugin;
1723
private Inventory inventory;
1824

25+
public ConfirmationButton(Plugin plugin) {
26+
this.plugin = (ShopPlugin) plugin;
27+
}
28+
29+
@Override
30+
public ItemStack getCustomItemStack(Player player, Placeholders placeholders) {
31+
ItemStack itemStack = super.getCustomItemStack(player, placeholders);
32+
33+
PlayerCache playerCache = this.plugin.getShopManager().getCache(player);
34+
ItemButton itemButton = playerCache.getItemButton();
35+
if (itemButton == null) return itemStack;
36+
37+
int amount = playerCache.getAmount();
38+
String sellPrice = itemButton.getSellPriceFormat(player, amount);
39+
String buyPrice = itemButton.getBuyPriceFormat(player, amount);
40+
41+
ItemMeta itemMeta = itemStack.getItemMeta();
42+
if (itemMeta != null && itemMeta.hasLore()) {
43+
List<String> lore = itemMeta.getLore();
44+
if (lore != null) {
45+
List<String> newLore = lore.stream().map(line -> {
46+
line = line.replace("%sellPrice%", sellPrice);
47+
line = line.replace("%buyPrice%", buyPrice);
48+
return line;
49+
}).collect(Collectors.toList());
50+
itemMeta.setLore(newLore);
51+
itemStack.setItemMeta(itemMeta);
52+
}
53+
}
54+
55+
return itemStack;
56+
}
57+
1958
protected void action(Player player, InventoryEngine inventory, ConfirmAction confirmAction, ShopPlugin plugin, PlayerCache cache) {
59+
var placeholders = new Placeholders();
2060
switch (confirmAction) {
2161
case CLOSE:
2262
player.closeInventory();
@@ -32,7 +72,7 @@ protected void action(Player player, InventoryEngine inventory, ConfirmAction co
3272
break;
3373
case RESET_AMOUNT:
3474
cache.setItemAmount(1);
35-
inventory.getButtons().stream().filter(button -> button instanceof ShowItemButton).forEach(inventory::buildButton);
75+
inventory.getButtons().stream().filter(button -> button instanceof ShowItemButton).forEach(b -> inventory.buildButton(b, placeholders));
3676
break;
3777
}
3878
}
@@ -42,7 +82,7 @@ public void onInventoryOpen(Player player, InventoryEngine inventory, Placeholde
4282
super.onInventoryOpen(player, inventory, placeholders);
4383
List<Inventory> oldInventories = inventory.getOldInventories();
4484
if (!oldInventories.isEmpty()) {
45-
this.inventory = oldInventories.get(oldInventories.size() - 1);
85+
this.inventory = oldInventories.getLast();
4686
}
4787
}
4888
}

src/main/java/fr/maxlego08/shop/buttons/ZAddButton.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import fr.maxlego08.shop.placeholder.Placeholder;
1010
import org.bukkit.entity.Player;
1111
import org.bukkit.event.inventory.InventoryClickEvent;
12+
import org.jetbrains.annotations.NotNull;
1213

1314
public class ZAddButton extends AddButton {
1415

@@ -36,13 +37,13 @@ public int parseInt(Player player) {
3637
}
3738

3839
@Override
39-
public void onClick(Player player, InventoryClickEvent event, InventoryEngine inventory, int slot, Placeholders placeholders) {
40+
public void onClick(@NotNull Player player, @NotNull InventoryClickEvent event, @NotNull InventoryEngine inventory, int slot, @NotNull Placeholders placeholders) {
4041
super.onClick(player, event, inventory, slot, placeholders);
4142

4243
int amount = parseInt(player);
4344
PlayerCache cache = this.plugin.getShopManager().getCache(player);
4445
cache.setItemAmount(Math.min(cache.getAmount() + amount, cache.getItemButton().getMaxStack()));
4546

46-
inventory.getButtons().stream().filter(button -> button instanceof ShowItemButton).forEach(inventory::buildButton);
47+
inventory.getButtons().stream().filter(button -> button instanceof ShowItemButton || button instanceof ConfirmationButton).forEach(b -> inventory.buildButton(b, placeholders));
4748
}
4849
}

src/main/java/fr/maxlego08/shop/buttons/ZBuyMore.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import fr.maxlego08.shop.api.buttons.ItemButton;
88
import org.bukkit.entity.Player;
99
import org.bukkit.event.inventory.InventoryClickEvent;
10+
import org.jetbrains.annotations.NotNull;
1011

1112
public class ZBuyMore extends BuyMore {
1213

@@ -19,7 +20,7 @@ public ZBuyMore(ShopPlugin plugin, int stack) {
1920
}
2021

2122
@Override
22-
public void onClick(Player player, InventoryClickEvent event, InventoryEngine inventory, int slot, Placeholders placeholders) {
23+
public void onClick(@NotNull Player player, @NotNull InventoryClickEvent event, @NotNull InventoryEngine inventory, int slot, @NotNull Placeholders placeholders) {
2324
super.onClick(player, event, inventory, slot, placeholders);
2425

2526
ItemButton itemButton = this.plugin.getShopManager().getCache(player).getItemButton();

0 commit comments

Comments
 (0)