Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/yourname/sellplugin/SellPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class SellPlugin extends JavaPlugin {
public void onEnable() {
saveDefaultConfig();
configManager = new ConfigManager(this);
configManager.generateExampleConfig();

priceManager = new PriceManager(this);
priceManager.loadPrices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ private ItemStack resolveItemStack(String itemKey) {
return item;
}
Material mat = Material.matchMaterial(itemKey);
return new ItemStack(mat != null ? mat : Material.BARRIER);
if (mat == null || !mat.isItem()) return new ItemStack(Material.BARRIER);
return new ItemStack(mat);
}

// ── Item clicked ─────────────────────────────────────────────────────────
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/yourname/sellplugin/gui/GUIListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void onClick(InventoryClickEvent e) {
e.setCancelled(true);
String catId = shopGUI.getCategoryAtSlot(slot);
if (catId != null) {
new CategoryItemsGUI(plugin, player, catId, 0).open(player);
new CategoryProgressGUI(plugin, player, catId).open(player);
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.yourname.sellplugin.gui.ShopMainGUI;
import com.yourname.sellplugin.gui.TopSellGUI;
import com.yourname.sellplugin.util.NumberFormatter;
import org.bukkit.GameMode;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
Expand Down Expand Up @@ -46,14 +47,16 @@ public void register() {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
packetListener = new PacketAdapter(plugin, ListenerPriority.NORMAL,
PacketType.Play.Server.SET_SLOT,
PacketType.Play.Server.SET_CURSOR_ITEM,
PacketType.Play.Server.WINDOW_ITEMS) {

@Override
public void onPacketSending(PacketEvent event) {
if (!WorthPacketListener.this.plugin.getConfigManager().isWorthEnabled()) return;
if (!shouldDecorate(event.getPlayer())) return;

if (event.getPacketType() == PacketType.Play.Server.SET_SLOT) {
if (event.getPacketType() == PacketType.Play.Server.SET_SLOT
|| event.getPacketType() == PacketType.Play.Server.SET_CURSOR_ITEM) {
if (event.getPacket().getItemModifier().size() <= 0) return;
ItemStack item = event.getPacket().getItemModifier().read(0);
ItemStack updated = addWorthLore(event.getPlayer(), item);
Expand Down Expand Up @@ -111,6 +114,8 @@ private ItemStack addWorthLore(Player player, ItemStack original) {
}

private boolean shouldDecorate(Player player) {
if (player.getGameMode() == GameMode.CREATIVE) return false;

Inventory topInventory = player.getOpenInventory().getTopInventory();
InventoryHolder holder = topInventory.getHolder();

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/yourname/sellplugin/manager/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,23 @@ public List<String> getIconLore(String key, List<String> defaultLore) {
public void reload() {
plugin.reloadConfig();
plugin.getPriceManager().loadPrices();
generateExampleConfig();
}

/**
* Generates an example-config.yml in the plugin data folder that always
* reflects the latest defaults shipped inside the JAR.
*/
public void generateExampleConfig() {
try {
java.io.InputStream in = plugin.getResource("config.yml");
if (in == null) return;
java.io.File target = new java.io.File(plugin.getDataFolder(), "example-config.yml");
java.nio.file.Files.copy(in, target.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
in.close();
} catch (java.io.IOException e) {
plugin.getLogger().warning("Could not generate example-config.yml: " + e.getMessage());
}
}

// ---- Helpers ----------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,11 @@ public void sendSellNotification(Player player, double amount, int itemCount) {
// Shulker box helpers
// ---------------------------------------------------------------

/** Returns true if the item is any colour of shulker box. */
/** Returns true if the item is any colour of shulker box (including the non-dyed SHULKER_BOX). */
public static boolean isShulkerBox(ItemStack item) {
return item != null && item.getType().name().endsWith("_SHULKER_BOX");
if (item == null) return false;
String name = item.getType().name();
return name.equals("SHULKER_BOX") || name.endsWith("_SHULKER_BOX");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/price.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ armortools:
FLINT_AND_STEEL: 6
ROCKET: 6
LEAD: 5
POWDER_SNOW: 5
POWDER_SNOW_BUCKET: 5
SHEARS: 4
SPYGLASS: 50
COMPASS: 10.0
Expand Down
Loading