mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-23 02:35:18 +01:00
add compatibility with old skyblock
This commit is contained in:
parent
bb0bee2bbf
commit
9d50fd2242
@ -9,9 +9,6 @@ import com.songoda.epichoppers.utils.HopperDirection;
|
|||||||
import com.songoda.epichoppers.utils.Methods;
|
import com.songoda.epichoppers.utils.Methods;
|
||||||
import com.songoda.epichoppers.utils.StorageContainerCache;
|
import com.songoda.epichoppers.utils.StorageContainerCache;
|
||||||
import com.songoda.epichoppers.utils.settings.Setting;
|
import com.songoda.epichoppers.utils.settings.Setting;
|
||||||
import com.songoda.skyblock.SkyBlock;
|
|
||||||
import com.songoda.skyblock.stackable.Stackable;
|
|
||||||
import com.songoda.skyblock.stackable.StackableManager;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -25,6 +22,7 @@ import org.bukkit.entity.minecart.StorageMinecart;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -47,12 +45,20 @@ public class HopTask extends BukkitRunnable {
|
|||||||
|
|
||||||
private final int hopTicks;
|
private final int hopTicks;
|
||||||
private final boolean hasFabledSkyBlock;
|
private final boolean hasFabledSkyBlock;
|
||||||
|
private boolean legacyFabledSkyblock;
|
||||||
|
private final Plugin fabledSkyblockPlugin;
|
||||||
|
|
||||||
public HopTask(EpicHoppers plug) {
|
public HopTask(EpicHoppers plug) {
|
||||||
plugin = plug;
|
plugin = plug;
|
||||||
this.hopTicks = Math.max(1, Setting.HOP_TICKS.getInt() / 2); // Purposeful integer division. Don't go below 1.
|
this.hopTicks = Math.max(1, Setting.HOP_TICKS.getInt() / 2); // Purposeful integer division. Don't go below 1.
|
||||||
this.runTaskTimer(plugin, 0, 2);
|
this.runTaskTimer(plugin, 0, 2);
|
||||||
this.hasFabledSkyBlock = Bukkit.getPluginManager().isPluginEnabled("FabledSkyBlock");
|
if((this.hasFabledSkyBlock = (fabledSkyblockPlugin = Bukkit.getPluginManager().getPlugin("FabledSkyBlock")) != null)) {
|
||||||
|
try {
|
||||||
|
Class.forName("me.goodandevil.skyblock.SkyBlock");
|
||||||
|
legacyFabledSkyblock = true;
|
||||||
|
} catch (ClassNotFoundException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -143,23 +149,53 @@ public class HopTask extends BukkitRunnable {
|
|||||||
|
|
||||||
// Support for FabledSkyBlock stackables.
|
// Support for FabledSkyBlock stackables.
|
||||||
if (this.hasFabledSkyBlock) {
|
if (this.hasFabledSkyBlock) {
|
||||||
StackableManager stackableManager = SkyBlock.getInstance().getStackableManager();
|
if (legacyFabledSkyblock) {
|
||||||
if (stackableManager != null && stackableManager.isStacked(pointingLocation)) {
|
Object stackableManager = fabledSkyblockPlugin.getClass().getMethod("getStackableManager").invoke(fabledSkyblockPlugin);
|
||||||
Stackable stackable = stackableManager.getStack(pointingLocation, pointingLocation.getBlock().getType());
|
boolean isStacked = stackableManager != null && (boolean) stackableManager.getClass().getMethod("isStacked", Location.class).invoke(stackableManager, pointingLocation);
|
||||||
|
if (isStacked) {
|
||||||
|
Material mat = pointingLocation.getBlock().getType();
|
||||||
|
Object stackable = stackableManager.getClass().getMethod("getStack", Location.class, Material.class).invoke(stackableManager, pointingLocation, mat);
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
final ItemStack item = hopperCache.cachedInventory[i];
|
final ItemStack item = hopperCache.cachedInventory[i];
|
||||||
if (item == null) continue;
|
if (item == null) {
|
||||||
|
continue;
|
||||||
if (item.getType() == stackable.getMaterial()) {
|
}
|
||||||
stackable.addOne();
|
|
||||||
if (item.getAmount() == 1) {
|
if (item.getType() == mat) {
|
||||||
hopperCache.removeItem(i);
|
stackable.getClass().getMethod("addOne").invoke(stackable);
|
||||||
} else {
|
if (item.getAmount() == 1) {
|
||||||
item.setAmount(item.getAmount() - 1);
|
hopperCache.removeItem(i);
|
||||||
hopperCache.dirty = hopperCache.cacheChanged[i] = true;
|
} else {
|
||||||
|
item.setAmount(item.getAmount() - 1);
|
||||||
|
hopperCache.dirty = hopperCache.cacheChanged[i] = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
com.songoda.skyblock.stackable.StackableManager stackableManager = ((com.songoda.skyblock.SkyBlock) fabledSkyblockPlugin).getStackableManager();
|
||||||
|
if (stackableManager != null && stackableManager.isStacked(pointingLocation)) {
|
||||||
|
Material mat = pointingLocation.getBlock().getType();
|
||||||
|
com.songoda.skyblock.stackable.Stackable stackable = stackableManager.getStack(pointingLocation, mat);
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
final ItemStack item = hopperCache.cachedInventory[i];
|
||||||
|
if (item == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.getType() == mat) {
|
||||||
|
stackable.addOne();
|
||||||
|
if (item.getAmount() == 1) {
|
||||||
|
hopperCache.removeItem(i);
|
||||||
|
} else {
|
||||||
|
item.setAmount(item.getAmount() - 1);
|
||||||
|
hopperCache.dirty = hopperCache.cacheChanged[i] = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user