Added AdvancedChests support.

This commit is contained in:
Fernando Pettinelli 2021-09-30 01:31:15 -03:00
parent 8527e1395e
commit 0263da253d
4 changed files with 95 additions and 7 deletions

17
pom.xml
View File

@ -90,6 +90,10 @@
<id>public</id> <id>public</id>
<url>https://repo.songoda.com/repository/public/</url> <url>https://repo.songoda.com/repository/public/</url>
</repository> </repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
@ -101,6 +105,7 @@
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>skyblock</artifactId> <artifactId>skyblock</artifactId>
<version>2.2.13</version> <version>2.2.13</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
@ -108,12 +113,6 @@
<version>LATEST</version> <version>LATEST</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>fabledskyblock</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>EpicFarming</artifactId> <artifactId>EpicFarming</artifactId>
@ -137,5 +136,11 @@
<version>3.5.1</version> <version>3.5.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.DeadSilenceIV</groupId>
<artifactId>AdvancedChestsAPI</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -75,6 +75,7 @@ public class EpicHoppers extends SongodaPlugin {
private DataManager dataManager; private DataManager dataManager;
private boolean epicfarming = false; private boolean epicfarming = false;
private boolean advancedchests = false;
public static EpicHoppers getInstance() { public static EpicHoppers getInstance() {
return INSTANCE; return INSTANCE;
@ -148,6 +149,7 @@ public class EpicHoppers extends SongodaPlugin {
// Check for epicfarming // Check for epicfarming
if (pluginManager.isPluginEnabled("EpicFarming")) epicfarming = true; if (pluginManager.isPluginEnabled("EpicFarming")) epicfarming = true;
if (pluginManager.isPluginEnabled("AdvancedChests")) advancedchests = true;
// Start auto save // Start auto save
int saveInterval = Settings.AUTOSAVE.getInt() * 60 * 20; int saveInterval = Settings.AUTOSAVE.getInt() * 60 * 20;
@ -302,4 +304,8 @@ public class EpicHoppers extends SongodaPlugin {
public boolean isEpicFarming() { public boolean isEpicFarming() {
return epicfarming; return epicfarming;
} }
public boolean isAdvancedChests() {
return advancedchests;
}
} }

View File

@ -162,6 +162,29 @@ public class HopTask extends BukkitRunnable {
} else { } else {
item.setAmount(item.getAmount() - 1); item.setAmount(item.getAmount() - 1);
hopperCache.dirty = hopperCache.cacheChanged[i] = true; hopperCache.dirty = hopperCache.cacheChanged[i] = true;
}
break;
}
}
}
}
if (plugin.isAdvancedChests()) {
us.lynuxcraft.deadsilenceiv.advancedchests.chest.AdvancedChest chest = us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI.getChestManager().getAdvancedChest(pointingLocation);
if (chest != null) {
for (int i = 0; i < 5; i++) {
final ItemStack item = hopperCache.cachedInventory[i];
if (item == null) {
continue;
}
if (us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI.hasSpaceForItem(chest, item)) {
us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI.addItemToChest(chest, item);
if (item.getAmount() == 1) {
hopperCache.removeItem(i);
} else {
item.setAmount(item.getAmount() - 1);
hopperCache.dirty = hopperCache.cacheChanged[i] = true;
} }
break; break;
} }
@ -365,6 +388,14 @@ public class HopTask extends BukkitRunnable {
continue; continue;
} }
if (plugin.isAdvancedChests()) {
us.lynuxcraft.deadsilenceiv.advancedchests.chest.AdvancedChest chest = us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI.getChestManager().getAdvancedChest(targetBlock.getLocation());
if (chest != null) {
addToAdvancedChest(hopper, hopperCache, chest, filterCache, maxToMove, blockedMaterials);
return;
}
}
// Is this a storage container? // Is this a storage container?
StorageContainerCache.Cache targetCache = StorageContainerCache.getCachedInventory(targetBlock); StorageContainerCache.Cache targetCache = StorageContainerCache.getCachedInventory(targetBlock);
if (targetCache == null) { if (targetCache == null) {
@ -393,6 +424,52 @@ public class HopTask extends BukkitRunnable {
} }
} }
private boolean addToAdvancedChest(com.songoda.epichoppers.hopper.Hopper hopper,
StorageContainerCache.Cache hopperCache,
us.lynuxcraft.deadsilenceiv.advancedchests.chest.AdvancedChest chest,
StorageContainerCache.Cache filterCache,
int maxToMove, Collection<Material> blockedMaterials) {
for (int i = 0; i < 5; i++) {
// Get potential item to move.
ItemStack item = hopperCache.cachedInventory[i];
// Can we check this item?
if ( // Ignore this one if the slot is empty
item == null
// Don't try to move items that we've added this round
|| (hopperCache.cacheChanged[i] && item.getAmount() - hopperCache.cacheAdded[i] < maxToMove)
// skip if blocked or voidlisted
|| blockedMaterials.contains(item.getType())
|| hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> Methods.isSimilarMaterial(itemStack, item)))
continue;
// Create item that will be moved.
ItemStack itemToMove = item.clone();
itemToMove.setAmount(Math.min(item.getAmount(), maxToMove));
// Process whitelist and blacklist.
boolean blocked = (!hopper.getFilter().getWhiteList().isEmpty() && hopper.getFilter().getWhiteList().stream().noneMatch(itemStack -> itemStack.isSimilar(item))
|| hopper.getFilter().getBlackList().stream().anyMatch(itemStack -> itemStack.isSimilar(item)));
// If blocked check to see if a movement can be made
if (blocked) {
if (filterCache != null && filterCache.addItem(itemToMove)) {
hopperCache.removeItems(itemToMove);
return true;
}
// can't move into a filter chest, so keep looking for something else to move
continue;
}
// Add item to container and return on success.
if (us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI.addItemToChest(chest, itemToMove)) {
hopperCache.removeItems(itemToMove);
return true;
}
}
return false;
}
private boolean tryPush(com.songoda.epichoppers.hopper.Hopper hopper, private boolean tryPush(com.songoda.epichoppers.hopper.Hopper hopper,
StorageContainerCache.Cache hopperCache, StorageContainerCache.Cache hopperCache,
StorageContainerCache.Cache targetCache, StorageContainerCache.Cache targetCache,

View File

@ -1,7 +1,7 @@
name: EpicHoppers name: EpicHoppers
description: EpicHoppers description: EpicHoppers
main: com.songoda.epichoppers.EpicHoppers main: com.songoda.epichoppers.EpicHoppers
softdepend: [FabledSkyBlock, LiquidTanks, UltimateStacker, WildStacker, Reserve, Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault, EpicFarming] softdepend: [FabledSkyBlock, LiquidTanks, UltimateStacker, WildStacker, Reserve, Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault, EpicFarming, AdvancedChests]
version: maven-version-number version: maven-version-number
author: Songoda author: Songoda
api-version: 1.13 api-version: 1.13