mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-26 12:16:18 +01:00
Added AdvancedChests support.
This commit is contained in:
parent
8527e1395e
commit
0263da253d
17
pom.xml
17
pom.xml
@ -90,6 +90,10 @@
|
||||
<id>public</id>
|
||||
<url>https://repo.songoda.com/repository/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -101,6 +105,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>skyblock</artifactId>
|
||||
<version>2.2.13</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
@ -108,12 +113,6 @@
|
||||
<version>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>fabledskyblock</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicFarming</artifactId>
|
||||
@ -137,5 +136,11 @@
|
||||
<version>3.5.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.DeadSilenceIV</groupId>
|
||||
<artifactId>AdvancedChestsAPI</artifactId>
|
||||
<version>2.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -75,6 +75,7 @@ public class EpicHoppers extends SongodaPlugin {
|
||||
private DataManager dataManager;
|
||||
|
||||
private boolean epicfarming = false;
|
||||
private boolean advancedchests = false;
|
||||
|
||||
public static EpicHoppers getInstance() {
|
||||
return INSTANCE;
|
||||
@ -148,6 +149,7 @@ public class EpicHoppers extends SongodaPlugin {
|
||||
|
||||
// Check for epicfarming
|
||||
if (pluginManager.isPluginEnabled("EpicFarming")) epicfarming = true;
|
||||
if (pluginManager.isPluginEnabled("AdvancedChests")) advancedchests = true;
|
||||
|
||||
// Start auto save
|
||||
int saveInterval = Settings.AUTOSAVE.getInt() * 60 * 20;
|
||||
@ -302,4 +304,8 @@ public class EpicHoppers extends SongodaPlugin {
|
||||
public boolean isEpicFarming() {
|
||||
return epicfarming;
|
||||
}
|
||||
|
||||
public boolean isAdvancedChests() {
|
||||
return advancedchests;
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +169,29 @@ public class HopTask extends BukkitRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Move items into destination containers
|
||||
pushItemsIntoContainers(hopper, hopperCache, maxToMove, blockedMaterials, hopperDirection);
|
||||
} catch (Exception e) {
|
||||
@ -365,6 +388,14 @@ public class HopTask extends BukkitRunnable {
|
||||
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?
|
||||
StorageContainerCache.Cache targetCache = StorageContainerCache.getCachedInventory(targetBlock);
|
||||
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,
|
||||
StorageContainerCache.Cache hopperCache,
|
||||
StorageContainerCache.Cache targetCache,
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: EpicHoppers
|
||||
description: 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
|
||||
author: Songoda
|
||||
api-version: 1.13
|
||||
|
Loading…
Reference in New Issue
Block a user