Skip to content

Commit

Permalink
Added new config variable for how to display hoveritems
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven65 committed Jul 19, 2020
1 parent 437fcd4 commit e579324
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/xyz/mackan/Slabbo/GUI/ShopCreationGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ public void onInventoryClick(final InventoryClickEvent e) {
}


ItemUtil.dropShopItem(slabLocation, shopItem);
ItemUtil.dropShopItem(slabLocation, shopItem, quantity);
} else {
ItemUtil.dropShopItem(slabLocation, shopItem);
ItemUtil.dropShopItem(slabLocation, shopItem, quantity);
}

p.playSound(this.slabLocation, SlabboSound.MODIFY_SUCCESS.sound, SoundCategory.BLOCKS, 1, 1);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/xyz/mackan/Slabbo/commands/SlabboCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void onReload (Player player) {
String key = shopEntry.getKey();
Shop shop = shopEntry.getValue();

ItemUtil.dropShopItem(shop.location, shop.item);
ItemUtil.dropShopItem(shop.location, shop.item, shop.quantity);

Slabbo.shopUtil.put(key, shop);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public void onImportShops(Player player, String type, String file) {
}

for (Shop shop : result.shops) {
ItemUtil.dropShopItem(shop.location, shop.item);
ItemUtil.dropShopItem(shop.location, shop.item, shop.quantity);

Slabbo.shopUtil.put(shop.getLocationString(), shop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,16 @@ public void run () {

@EventHandler
public void onInventoryDrag (InventoryDragEvent e) {
Block chestBlock = e.getInventory().getLocation().getBlock(); // TODO check this
Inventory inv = e.getInventory();

if (inv == null) return;

Location invLocation = inv.getLocation();

if (invLocation == null) return;


Block chestBlock = invLocation.getBlock(); // TODO check this

if (chestBlock == null) return;

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/xyz/mackan/Slabbo/utils/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import xyz.mackan.Slabbo.Slabbo;
import xyz.mackan.Slabbo.types.AttributeKey;

import java.util.Collection;
Expand Down Expand Up @@ -39,15 +40,24 @@ public static double getSlabYOffset (Location location) {
}
}

public static void dropShopItem (Location location, ItemStack item) {
public static void dropShopItem (Location location, ItemStack item, int quantity) {
Location dropLocation = location.clone();

dropLocation.add(0.5, getSlabYOffset(location), 0.5);

ItemStack clonedItem = item.clone();
ItemMeta meta = clonedItem.getItemMeta();

clonedItem.setAmount(64);
String displayType = Slabbo.getInstance().getConfig().getString("itemdisplay", "quantity");

if (displayType.equalsIgnoreCase("quantity")) {
if (quantity < 1) quantity = 1;
if (quantity > 64) quantity = 64;

clonedItem.setAmount(quantity);
} else {
clonedItem.setAmount(64);
}

meta.getPersistentDataContainer().set(AttributeKey.NO_PICKUP.getKey(), PersistentDataType.INTEGER, 1);
meta.getPersistentDataContainer().set(AttributeKey.NO_DESPAWN.getKey(), PersistentDataType.INTEGER, 1);
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ chestlinks: # Linking chests
enabled: true
savetime: 5

checkupdates: true
itemdisplay: quantity # Quantity (The amount the shop sells) / Full (A full stack (64 items))

checkupdates: true

0 comments on commit e579324

Please sign in to comment.