mirror of
https://github.com/kiranhart/Auction-House.git
synced 2024-11-22 05:25:11 +01:00
extract some bundle stuff into its own util class
Took 24 minutes
This commit is contained in:
parent
4990d28ae3
commit
13652e485f
@ -19,4 +19,6 @@
|
||||
package ca.tweetzy.auctionhouse.ahv3.api;
|
||||
|
||||
public interface AuctionHouseAPI {
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Auction House
|
||||
* Copyright 2022 Kiran Hart
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ca.tweetzy.auctionhouse.ahv3.model;
|
||||
|
||||
import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
||||
import ca.tweetzy.core.compatibility.XMaterial;
|
||||
import ca.tweetzy.flight.comp.NBTEditor;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
public final class BundleUtil {
|
||||
|
||||
public boolean isBundledItem(@NonNull final ItemStack itemStack) {
|
||||
return itemStack.getType() != XMaterial.AIR.parseMaterial() && NBTEditor.contains(itemStack, "AuctionBundleItem");
|
||||
}
|
||||
|
||||
public List<ItemStack> extractBundleItems(@NonNull final ItemStack itemStack) {
|
||||
final List<ItemStack> items = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < NBTEditor.getInt(itemStack, "AuctionBundleItem"); i++) {
|
||||
items.add(AuctionAPI.getInstance().deserializeItem(NBTEditor.getByteArray(itemStack, "AuctionBundleItem-" + i)));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@
|
||||
package ca.tweetzy.auctionhouse.listeners;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
||||
import ca.tweetzy.auctionhouse.ahv3.model.BundleUtil;
|
||||
import ca.tweetzy.auctionhouse.api.UpdateChecker;
|
||||
import ca.tweetzy.auctionhouse.api.hook.PlaceholderAPIHook;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
|
||||
@ -52,7 +52,6 @@ import org.bukkit.inventory.CraftingInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -149,14 +148,10 @@ public class PlayerListeners implements Listener {
|
||||
if (heldItem == null || (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK))
|
||||
return;
|
||||
if (heldItem.getType() == XMaterial.AIR.parseMaterial()) return;
|
||||
if (!NBTEditor.contains(heldItem, "AuctionBundleItem")) return;
|
||||
if (!BundleUtil.isBundledItem(heldItem)) return;
|
||||
e.setCancelled(true);
|
||||
|
||||
final List<ItemStack> items = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < NBTEditor.getInt(heldItem, "AuctionBundleItem"); i++) {
|
||||
items.add(AuctionAPI.getInstance().deserializeItem(NBTEditor.getByteArray(heldItem, "AuctionBundleItem-" + i)));
|
||||
}
|
||||
final List<ItemStack> items = BundleUtil.extractBundleItems(heldItem);
|
||||
|
||||
if (heldItem.getAmount() >= 2) {
|
||||
heldItem.setAmount(heldItem.getAmount() - 1);
|
||||
|
Loading…
Reference in New Issue
Block a user