mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-23 02:35:18 +01:00
Added good support for WildStacker and UltimateStacker.
This commit is contained in:
parent
ba36638dff
commit
7d12f8a7dc
5
pom.xml
5
pom.xml
@ -68,6 +68,11 @@
|
||||
<artifactId>songodaupdater</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateStacker</artifactId>
|
||||
<version>1.6.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.arcaniax</groupId>
|
||||
<artifactId>liquidtanks</artifactId>
|
||||
|
@ -5,6 +5,7 @@ import com.songoda.epichoppers.EpicHoppers;
|
||||
import com.songoda.epichoppers.hopper.Hopper;
|
||||
import com.songoda.epichoppers.tasks.HopTask;
|
||||
import com.songoda.epichoppers.utils.ServerVersion;
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -16,10 +17,7 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModuleSuction extends Module {
|
||||
@ -28,8 +26,8 @@ public class ModuleSuction extends Module {
|
||||
|
||||
public static List<UUID> blacklist = new ArrayList<>();
|
||||
|
||||
private boolean wildStacker = Bukkit.getPluginManager().isPluginEnabled("WildStacker");
|
||||
private boolean ultimateStacker = Bukkit.getPluginManager().isPluginEnabled("UltimateStacker");
|
||||
private static boolean wildStacker = Bukkit.getPluginManager().isPluginEnabled("WildStacker");
|
||||
private static boolean ultimateStacker = Bukkit.getPluginManager().isPluginEnabled("UltimateStacker");
|
||||
|
||||
public ModuleSuction(EpicHoppers plugin, int amount) {
|
||||
super(plugin);
|
||||
@ -64,16 +62,11 @@ public class ModuleSuction extends Module {
|
||||
return; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/
|
||||
}
|
||||
|
||||
if (wildStacker)
|
||||
itemStack.setAmount(WildStackerAPI.getItemAmount(item));
|
||||
|
||||
if (ultimateStacker && item.hasMetadata("US_AMT"))
|
||||
itemStack.setAmount(item.getMetadata("US_AMT").get(0).asInt());
|
||||
|
||||
if (!canMove(hopperInventory, itemStack) || blacklist.contains(item.getUniqueId()))
|
||||
return;
|
||||
|
||||
blacklist.add(item.getUniqueId());
|
||||
addItems(item, hopperInventory);
|
||||
|
||||
|
||||
float xx = (float) (0 + (Math.random() * .1));
|
||||
float yy = (float) (0 + (Math.random() * .1));
|
||||
@ -82,14 +75,52 @@ public class ModuleSuction extends Module {
|
||||
if (EpicHoppers.getInstance().isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
item.getLocation().getWorld().spawnParticle(Particle.FLAME, item.getLocation(), 5, xx, yy, zz, 0);
|
||||
|
||||
for (ItemStack is : hopperInventory.addItem(itemStack).values())
|
||||
item.getWorld().dropItemNaturally(item.getLocation(), is);
|
||||
|
||||
HopTask.updateAdjacentComparators(hopper.getLocation());
|
||||
item.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private void addItems(Item item, Inventory inventory) {
|
||||
int amount = getActualItemAmount(item);
|
||||
|
||||
while (amount > 0) {
|
||||
int subtract = Math.min(amount, 64);
|
||||
amount -= subtract;
|
||||
ItemStack newItem = item.getItemStack().clone();
|
||||
newItem.setAmount(subtract);
|
||||
Map<Integer, ItemStack> result = inventory.addItem(newItem);
|
||||
if (result.get(0) != null) {
|
||||
amount += result.get(0).getAmount();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (amount <= 0) {
|
||||
blacklist.add(item.getUniqueId());
|
||||
item.remove();
|
||||
} else
|
||||
updateAmount(item, amount);
|
||||
}
|
||||
|
||||
private int getActualItemAmount(Item item) {
|
||||
if (ultimateStacker) {
|
||||
return Methods.getActualItemAmount(item);
|
||||
} else if (wildStacker)
|
||||
return WildStackerAPI.getItemAmount(item);
|
||||
else
|
||||
return item.getItemStack().getAmount();
|
||||
|
||||
}
|
||||
|
||||
private void updateAmount(Item item, int amount) {
|
||||
if (ultimateStacker)
|
||||
Methods.updateItemAmount(item, amount);
|
||||
else if (wildStacker)
|
||||
WildStackerAPI.getStackedItem(item).setStackAmount(amount, true);
|
||||
else
|
||||
item.getItemStack().setAmount(amount > item.getItemStack().getMaxStackSize()
|
||||
? item.getItemStack().getMaxStackSize() : amount);
|
||||
}
|
||||
|
||||
public static boolean isBlacklisted(UUID uuid) {
|
||||
if (blacklist.contains(uuid))
|
||||
Bukkit.getScheduler().runTaskLater(EpicHoppers.getInstance(),
|
||||
@ -104,7 +135,8 @@ public class ModuleSuction extends Module {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runButtonPress(Player player, Hopper hopper, ClickType type) { }
|
||||
public void runButtonPress(Player player, Hopper hopper, ClickType type) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getBlockedItems(Hopper hopper) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: EpicHoppers
|
||||
description: EpicHoppers
|
||||
main: com.songoda.epichoppers.EpicHoppers
|
||||
softdepend: [LiquidTanks, WildStacker, Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault, EpicFarming]
|
||||
softdepend: [LiquidTanks, UltimateStacker, WildStacker, Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault, EpicFarming]
|
||||
version: maven-version-number
|
||||
author: Songoda
|
||||
api-version: 1.13
|
||||
|
Loading…
Reference in New Issue
Block a user