From 25bf92c7b903e75c3639d61d78406495b898ea83 Mon Sep 17 00:00:00 2001
From: rbluer <665978+rbluer@users.noreply.github.com>
Date: Fri, 15 Mar 2024 04:13:05 -0400
Subject: [PATCH] Prison API: Added a few new functions to work with
ItemStacks.
---
docs/changelog_v3.3.x.md | 4 +
.../prison/spigot/api/PrisonSpigotAPI.java | 156 +++++++++++++++++-
2 files changed, 159 insertions(+), 1 deletion(-)
diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md
index eb1f701d6..1a83c27a7 100644
--- a/docs/changelog_v3.3.x.md
+++ b/docs/changelog_v3.3.x.md
@@ -17,6 +17,10 @@ These change logs represent the work that has been going on within prison.
# 3.3.0-alpha.16c 2024-03-15
+* **Prison API: Added a few new functions to work with ItemStacks.**
+
+
+
* **Players: Shift the function of getting a player object to the Player classes, such as CommandSender.**
This is to simplify the code and to put the functionality in one location.
diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java
index 3cb826a75..58d8d426a 100644
--- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java
+++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/api/PrisonSpigotAPI.java
@@ -51,14 +51,80 @@
*
If you need something special, then please ask on our discord server and we
* can probably provide it for you.
*
+ * @param
*
*/
-public class PrisonSpigotAPI {
+public class PrisonSpigotAPI {
private PrisonMines prisonMineManager;
private boolean mineModuleDisabled = false;
private SellAllUtil sellAll;
+
+ private void junk() {
+
+// SpigotPrison.getInstance().isSellAllEnabled();
+//
+// SpigotPlayer sPlayer = new SpigotPlayer( Player player );
+//
+// sPlayer.getSellAllMulitiplier()
+// sPlayer.getSellAllMultiplierListings()
+// sPlayer.checkAutoSellPermsAutoFeatures()
+// sPlayer.checkAutoSellTogglePerms( sbDebug )
+// sPlayer.isAutoSellEnabled( sbDebug )
+//
+
+ // PrisonSpigotAPI.sellPlayerItems(Player player );
+ }
+
+// private void handleAffectedBlocks(Player p, IWrappedRegion region, List blocksAffected) {
+// double totalDeposit = 0.0;
+// int fortuneLevel = EnchantUtils.getItemFortuneLevel(p.getItemInHand());
+// boolean autoSellPlayerEnabled = this.plugin.isAutoSellModuleEnabled() && plugin.getCore().getAutoSell().getManager().hasAutoSellEnabled(p);
+//
+// TreeMap itemValues = new TreeMap<>();
+// PrisonSpigotAPI pApi = new PrisonSpigotAPI();
+//
+// getItemStackValueTransactions(p, null);
+//
+// for (Block block : blocksAffected) {
+//
+// int amplifier = fortuneLevel;
+// if (FortuneEnchant.isBlockBlacklisted(block)) {
+// amplifier = 1;
+// }
+//
+// String blockNamme = block.getType().name();
+// double value = 0dg;
+//
+// if ( itemValues.containsKey(blockNamme) ) {
+// value = itemValues.get(blockNamme);
+// }
+// else {
+// ItemStack iStk = new ItemStack( block.getType() );
+// if ( iStk != null ) {
+//
+// value = getItemStackValue(p, iStk);
+// if ( value > 0 ) {{
+// itemValues.put(blockNamme, value);
+// }
+// }
+// }
+//
+// if (autoSellPlayerEnabled && value > 0) {
+// totalDeposit += value * amplifier;
+// } else {
+// ItemStack itemToGive = CompMaterial.fromBlock(block).toItem(amplifier);
+// p.getInventory().addItem(itemToGive);
+// }
+//
+// if (this.removeBlocks ) {
+// this.plugin.getCore().getNmsProvider().setBlockInNativeDataPalette(block.getWorld(), block.getX(), block.getY(), block.getZ(), 0, (byte) 0, true);
+// }
+//
+// }
+// this.giveEconomyRewardsToPlayer(p, totalDeposit);
+// }
/**
* This returns all mines that are within prison.
@@ -480,6 +546,94 @@ public SellAllUtil getPrisonSellAll(){
return sellAll;
}
+
+
+ /**
+ *
This will convert a List to Prison's
+ * List so it can be used with the various SellAll
+ * functions.
+ *
+ *
+ * @param blocks
+ * @return
+ */
+ public List getPrisonItemmStacks( List blocks ) {
+ List results = new ArrayList<>();
+ TreeMap map = new TreeMap<>();
+
+ if ( blocks != null ) {
+ for ( Block b : blocks ) {
+ if ( b != null ) {
+ SpigotBlock sBlock = SpigotBlock.getSpigotBlock( b );
+
+ if ( sBlock != null ) {
+
+ String bName = sBlock.getBlockName();
+
+ if ( !map.containsKey( bName ) ) {
+ String[] lore = null;
+ SpigotItemStack sis = new SpigotItemStack( 1, sBlock, lore );
+
+ map.put(bName, sis );
+ }
+ else {
+ map.get(bName).addToAmount( 1 );
+ }
+ }
+
+ }
+ }
+
+ }
+
+ if ( map.size() > 0 ) {
+ for ( SpigotItemStack sItemStack : map.values() ) {
+ results.add( sItemStack );
+ }
+ }
+
+ return results;
+ }
+
+ public List getItemStacks( List blocks ) {
+ List results = new ArrayList<>();
+ TreeMap map = new TreeMap<>();
+
+ if ( blocks != null ) {
+ for ( Block b : blocks ) {
+ if ( b != null ) {
+
+ String bName = b.getType().name();
+
+ if ( bName != null ) {
+
+ if ( !map.containsKey( bName ) ) {
+
+ ItemStack iStk = new ItemStack( b.getType() );
+ map.put(bName, iStk );
+ }
+ else {
+ ItemStack iStk = map.get(bName);
+
+ iStk.setAmount( iStk.getAmount() );
+
+ map.put(bName, iStk);
+ }
+ }
+
+ }
+ }
+
+ }
+
+ if ( map.size() > 0 ) {
+ for ( ItemStack sItemStack : map.values() ) {
+ results.add( sItemStack );
+ }
+ }
+
+ return results;
+ }
/**
* Get the money to give to the Player depending on the SellAll multiplier.