Skip to content

Commit

Permalink
[build] apply max stack size to player inventory when doing addItem
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Jul 12, 2024
1 parent 72cb16d commit 8b2d778
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
### Changes:
- Simplified parsing messages internally with placeholders
### Fixed:
- Apply `MaxStackSize` to the player's inventory when using Player#addItem, so now instead of 99 items popping up in the inventory if giving 99 keys or any items, it'll split 64/35
- Spigot for some odd reason made Player#addItem use the max stack size for the inventories. #hardforkwhen
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

val buildNumber: String? = System.getenv("BUILD_NUMBER")

rootProject.version = if (buildNumber != null) "${libs.versions.minecraft.get()}-$buildNumber" else "3.7.1"
rootProject.version = if (buildNumber != null) "${libs.versions.minecraft.get()}-$buildNumber" else "3.7.2"

val isSnapshot = true

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/badbones69/crazyvouchers/Methods.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.persistence.PersistentDataContainer;
Expand All @@ -38,6 +39,13 @@ public static void removeItem(final ItemStack item, final Player player) {
public static String getPrefix(final String message) {
return MsgUtils.color(config.getProperty(ConfigKeys.command_prefix) + message);
}

public static void addItem(final Player player, final ItemStack... items) {
final Inventory inventory = player.getInventory();

inventory.setMaxStackSize(64);
inventory.addItem(items);
}

public static boolean isInt(final String value) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.badbones69.crazyvouchers.api.builders.types;

import com.badbones69.crazyvouchers.Methods;
import com.badbones69.crazyvouchers.api.InventoryManager;
import com.badbones69.crazyvouchers.api.builders.InventoryBuilder;
import com.badbones69.crazyvouchers.api.enums.PersistentKeys;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void run(InventoryClickEvent event) {
if (voucher != null) {
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1F, 1F);

player.getInventory().addItem(voucher.buildItem());
Methods.addItem(player, voucher.buildItem());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N

for (ItemBuilder itemBuilder : voucherCode.getItems()) {
if (!Methods.isInventoryFull(player)) {
player.getInventory().addItem(itemBuilder.build());
Methods.addItem(player, itemBuilder.build());
} else {
player.getWorld().dropItem(player.getLocation(), itemBuilder.build());
}
Expand Down Expand Up @@ -308,7 +308,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
if (Methods.isInventoryFull(player)) {
player.getWorld().dropItem(player.getLocation(), item);
} else {
player.getInventory().addItem(item);
Methods.addItem(player, item);
player.updateInventory();
}

Expand Down Expand Up @@ -365,7 +365,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
if (Methods.isInventoryFull(player)) {
player.getWorld().dropItem(player.getLocation(), item);
} else {
player.getInventory().addItem(item);
Methods.addItem(player, item);
player.updateInventory();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private void voucherClick(Player player, ItemStack item, Voucher voucher, String

for (ItemBuilder itemStack : voucher.getItems()) {
if (!Methods.isInventoryFull(player)) {
player.getInventory().addItem(itemStack.build());
Methods.addItem(player, itemStack.build());
} else {
player.getWorld().dropItem(player.getLocation(), itemStack.build());
}
Expand Down

0 comments on commit 8b2d778

Please sign in to comment.