mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-22 10:15:43 +01:00
Fix for chunk loading.
This commit is contained in:
parent
9f394c21ce
commit
424e406f7c
@ -1,5 +1,6 @@
|
||||
package com.songoda.epichoppers.api.hopper;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -18,7 +19,7 @@ public interface Filter {
|
||||
|
||||
void setVoidList(List<ItemStack> voidList);
|
||||
|
||||
Block getEndPoint();
|
||||
Location getEndPoint();
|
||||
|
||||
void setEndPoint(Block endPoint);
|
||||
void setEndPoint(Location endPoint);
|
||||
}
|
||||
|
@ -109,9 +109,9 @@ public interface Hopper {
|
||||
*/
|
||||
void setTeleportTrigger(TeleportTrigger teleportTrigger);
|
||||
|
||||
List<Block> getLinkedBlocks();
|
||||
List<Location> getLinkedBlocks();
|
||||
|
||||
void addLinkedBlock(Block block);
|
||||
void addLinkedBlock(Location block);
|
||||
|
||||
void clearLinkedBlocks();
|
||||
|
||||
|
@ -151,15 +151,15 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
if (storage.containsGroup("sync")) {
|
||||
for (StorageRow row : storage.getRowsByGroup("sync")) {
|
||||
Location location = Serialize.getInstance().unserializeLocation(row.getKey());
|
||||
if (location == null || location.getBlock() == null) return;
|
||||
if (location == null) return;
|
||||
|
||||
int level = row.get("level").asInt();
|
||||
|
||||
List<String> blockLoc = row.get("block").asStringList();
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
List<Location> blocks = new ArrayList<>();
|
||||
if (blockLoc != null) {
|
||||
for (String string : blockLoc) {
|
||||
blocks.add(Arconix.pl().getApi().serialize().unserializeLocation(string).getBlock());
|
||||
blocks.add(Arconix.pl().getApi().serialize().unserializeLocation(string));
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
Material autoCrafting = Material.valueOf(row.get("autocrafting").asString() == null ? "AIR" : row.get("autocrafting").asString());
|
||||
|
||||
String blackLoc = row.get("black").asString();
|
||||
Block black = blackLoc == null ? null : Arconix.pl().getApi().serialize().unserializeLocation(blackLoc).getBlock();
|
||||
Location black = blackLoc == null ? null : Arconix.pl().getApi().serialize().unserializeLocation(blackLoc);
|
||||
|
||||
EFilter filter = new EFilter();
|
||||
|
||||
@ -319,7 +319,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
new StorageItem("whitelist", hopper.getFilter().getWhiteList()),
|
||||
new StorageItem("blacklist", hopper.getFilter().getBlackList()),
|
||||
new StorageItem("void", hopper.getFilter().getVoidList()),
|
||||
new StorageItem("black", hopper.getFilter().getEndPoint() == null ? null : Arconix.pl().getApi().serialize().serializeLocation(hopper.getFilter().getEndPoint().getLocation())));
|
||||
new StorageItem("black", hopper.getFilter().getEndPoint() == null ? null : Arconix.pl().getApi().serialize().serializeLocation(hopper.getFilter().getEndPoint())));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -30,7 +30,6 @@ public class HopHandler {
|
||||
try {
|
||||
this.instance = instance;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
hopperCleaner();
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::hopperRunner, 0, instance.getConfig().getLong("Main.Amount of Ticks Between Hops"));
|
||||
}, 40L);
|
||||
} catch (Exception e) {
|
||||
@ -38,48 +37,27 @@ public class HopHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void hopperCleaner() {
|
||||
try {
|
||||
ConfigurationSection data = instance.getConfig().createSection("data");
|
||||
if (!data.contains("sync")) return;
|
||||
for (String key : data.getConfigurationSection("sync").getKeys(false)) {
|
||||
if (Arconix.pl().getApi().serialize().unserializeLocation(key).getWorld() == null) continue;
|
||||
Block block = Arconix.pl().getApi().serialize().unserializeLocation(key).getBlock();
|
||||
if (block != null && block.getState() instanceof Hopper) continue;
|
||||
data.getConfigurationSection("sync").set(key, null);
|
||||
instance.getLogger().info("EpicHoppers Removing non-hopper entry: " + key);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void hopperRunner() {
|
||||
try {
|
||||
main:
|
||||
for (com.songoda.epichoppers.api.hopper.Hopper hopper : new HashMap<>(instance.getHopperManager().getHoppers()).values()) {
|
||||
|
||||
Location location = hopper.getLocation();
|
||||
|
||||
int x = location.getBlockX() >> 4;
|
||||
int z = location.getBlockZ() >> 4;
|
||||
|
||||
try {
|
||||
if (!location.getWorld().isChunkLoaded(x, z)) {
|
||||
if (!location.getWorld().isChunkLoaded(x, z))
|
||||
continue;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
continue;
|
||||
}
|
||||
Block block = location.getBlock();
|
||||
|
||||
if (block.isBlockPowered() || block.isBlockIndirectlyPowered()) continue;
|
||||
Block block = location.getBlock();
|
||||
|
||||
if (block == null || block.getType() != Material.HOPPER) {
|
||||
instance.getHopperManager().removeHopper(location);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (block.isBlockPowered() || block.isBlockIndirectlyPowered()) continue;
|
||||
|
||||
Hopper hopperBlock = hopper.getHopper();
|
||||
|
||||
List<Material> blockedMaterials = new ArrayList<>();
|
||||
@ -98,38 +76,33 @@ public class HopHandler {
|
||||
|
||||
if (hopper.getLinkedBlocks() == null || hopper.getLinkedBlocks().isEmpty()) continue;
|
||||
|
||||
for (Block destBlock : hopper.getLinkedBlocks()) {
|
||||
Location dest = destBlock.getLocation();
|
||||
if (dest == null) continue;
|
||||
for (Location destinationLocation : hopper.getLinkedBlocks()) {
|
||||
if (destinationLocation == null) continue;
|
||||
|
||||
int destx = location.getBlockX() >> 4;
|
||||
int destz = location.getBlockZ() >> 4;
|
||||
if (!dest.getWorld().isChunkLoaded(destx, destz)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block b2 = dest.getBlock();
|
||||
if (!(b2.getState() instanceof InventoryHolder)) {
|
||||
if (!destinationLocation.getWorld().isChunkLoaded(destx, destz))
|
||||
continue;
|
||||
|
||||
Block destinationBlock = destinationLocation.getBlock();
|
||||
if (!(destinationBlock.getState() instanceof InventoryHolder)) {
|
||||
hopper.clearLinkedBlocks();
|
||||
continue;
|
||||
}
|
||||
|
||||
//InventoryHolder inventoryHolder = (InventoryHolder) b2.getState();
|
||||
//TODO add some restrictions here if needed
|
||||
|
||||
BoostData boostData = instance.getBoostManager().getBoost(hopper.getPlacedBy());
|
||||
|
||||
int amt = hopper.getLevel().getAmount() * (boostData == null ? 1 : boostData.getMultiplier());
|
||||
int amount = hopper.getLevel().getAmount() * (boostData == null ? 1 : boostData.getMultiplier());
|
||||
|
||||
List<ItemStack> whiteList = hopper.getFilter().getWhiteList();
|
||||
|
||||
List<ItemStack> blackList = hopper.getFilter().getBlackList();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ItemStack it;
|
||||
ItemStack item;
|
||||
if (is[i] != null) {
|
||||
it = is[i].clone();
|
||||
it.setAmount(1);
|
||||
item = is[i].clone();
|
||||
item.setAmount(1);
|
||||
}
|
||||
if (hopper.getLocation().getBlock().isBlockPowered()
|
||||
|| is[i] != null && blockedMaterials.contains(is[i].getType())) {
|
||||
@ -137,24 +110,24 @@ public class HopHandler {
|
||||
if (i >= 5) continue;
|
||||
}
|
||||
|
||||
int finalI = i;
|
||||
int finalIncrement = i;
|
||||
if (is[i] != null
|
||||
&& !whiteList.isEmpty()
|
||||
&& whiteList.stream().noneMatch(itemStack -> itemStack.isSimilar(is[finalI]))) {
|
||||
doBlacklist(hopperBlock, hopper, is[i].clone(), is, amt, i);
|
||||
continue main;
|
||||
} else {
|
||||
if (is[i] != null && blackList.stream().noneMatch(itemStack -> itemStack.isSimilar(is[finalI]))) {
|
||||
if (addItem(hopperBlock, hopper, b2, is[i], is, amt, i)) {
|
||||
block.getState().update();
|
||||
&& whiteList.stream().noneMatch(itemStack -> itemStack.isSimilar(is[finalIncrement]))) {
|
||||
doBlacklist(hopperBlock, hopper, is[i].clone(), is, amount, i);
|
||||
continue main;
|
||||
}
|
||||
} else {
|
||||
if (is[i] != null && blackList.stream().anyMatch(itemStack -> itemStack.isSimilar(is[finalI]))) {
|
||||
doBlacklist(hopperBlock, hopper, is[i].clone(), is, amt, i);
|
||||
|
||||
if (is[i] != null && blackList.stream().noneMatch(itemStack -> itemStack.isSimilar(is[finalIncrement]))) {
|
||||
if (addItem(hopperBlock, hopper, destinationBlock, is[i], is, amount, i)) {
|
||||
//block.getState().update();
|
||||
continue main;
|
||||
}
|
||||
}
|
||||
|
||||
if (is[i] != null && blackList.stream().anyMatch(itemStack -> itemStack.isSimilar(is[finalIncrement]))) {
|
||||
doBlacklist(hopperBlock, hopper, is[i].clone(), is, amount, i);
|
||||
continue main;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,16 +140,17 @@ public class HopHandler {
|
||||
|
||||
private void doBlacklist(Hopper hopperBlock, com.songoda.epichoppers.api.hopper.Hopper hopper, ItemStack item, ItemStack[] isS, int amt, int place) {
|
||||
try {
|
||||
Location loc = hopperBlock.getLocation();
|
||||
Block block = loc.getBlock();
|
||||
Location location = hopperBlock.getLocation();
|
||||
Block block = location.getBlock();
|
||||
if (hopper.getFilter().getEndPoint() != null
|
||||
&& block != null && block.getState() instanceof Hopper) {
|
||||
Location dest = hopper.getFilter().getEndPoint().getLocation();
|
||||
int destx = loc.getBlockX() >> 4;
|
||||
int destz = loc.getBlockZ() >> 4;
|
||||
if (!dest.getWorld().isChunkLoaded(destx, destz)) {
|
||||
Location dest = hopper.getFilter().getEndPoint();
|
||||
int destx = location.getBlockX() >> 4;
|
||||
int destz = location.getBlockZ() >> 4;
|
||||
|
||||
if (!dest.getWorld().isChunkLoaded(destx, destz))
|
||||
return;
|
||||
}
|
||||
|
||||
Block b2 = dest.getBlock();
|
||||
|
||||
if (!(b2.getState() instanceof InventoryHolder)) {
|
||||
@ -185,7 +159,7 @@ public class HopHandler {
|
||||
}
|
||||
|
||||
addItem(hopperBlock, hopper, b2, item, isS, amt, place);
|
||||
block.getState().update();
|
||||
//block.getState().update();
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -72,7 +72,15 @@ public class TeleportHandler {
|
||||
while (instance.getHopperManager().isHopper(next.getLocation()) && instance.getHopperManager().getHopper(next.getLocation()).getLinkedBlocks() != null && num != 15) {
|
||||
Hopper nextHopper = instance.getHopperManager().getHopper(next);
|
||||
if (nextHopper.getLinkedBlocks() != null && !nextHopper.getLinkedBlocks().isEmpty()) {
|
||||
next = nextHopper.getLinkedBlocks().get(0);
|
||||
Location location = nextHopper.getLinkedBlocks().get(0);
|
||||
|
||||
int x = location.getBlockX() >> 4;
|
||||
int z = location.getBlockZ() >> 4;
|
||||
|
||||
if (!location.getWorld().isChunkLoaded(x, z))
|
||||
continue;
|
||||
|
||||
next = location.getBlock();
|
||||
}
|
||||
|
||||
if (!next.getType().equals(Material.HOPPER)) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epichoppers.hopper;
|
||||
|
||||
import com.songoda.epichoppers.api.hopper.Filter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -13,7 +14,7 @@ public class EFilter implements Filter {
|
||||
private List<ItemStack> blackList = new ArrayList<>();
|
||||
private List<ItemStack> voidList = new ArrayList<>();
|
||||
|
||||
private Block endPoint;
|
||||
private Location endPoint;
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getWhiteList() {
|
||||
@ -49,12 +50,12 @@ public class EFilter implements Filter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getEndPoint() {
|
||||
public Location getEndPoint() {
|
||||
return endPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEndPoint(Block endPoint) {
|
||||
public void setEndPoint(Location endPoint) {
|
||||
this.endPoint = endPoint;
|
||||
}
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ public class EHopper implements Hopper {
|
||||
private Level level;
|
||||
private UUID lastPlayer;
|
||||
private UUID placedBy;
|
||||
private List<Block> linkedBlocks;
|
||||
private List<Location> linkedBlocks;
|
||||
private Filter filter;
|
||||
private TeleportTrigger teleportTrigger;
|
||||
private Material autoCrafting;
|
||||
private org.bukkit.block.Hopper hopper;
|
||||
|
||||
public EHopper(Location location, Level level, UUID lastPlayer, UUID placedBy, List<Block> linkedBlocks, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) {
|
||||
public EHopper(Location location, Level level, UUID lastPlayer, UUID placedBy, List<Location> linkedBlocks, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) {
|
||||
this.location = location;
|
||||
this.level = level;
|
||||
this.linkedBlocks = linkedBlocks;
|
||||
@ -51,11 +51,18 @@ public class EHopper implements Hopper {
|
||||
this.placedBy = placedBy;
|
||||
this.teleportTrigger = teleportTrigger;
|
||||
this.autoCrafting = autoCrafting;
|
||||
|
||||
int x = location.getBlockX() >> 4;
|
||||
int z = location.getBlockZ() >> 4;
|
||||
|
||||
if (!location.getWorld().isChunkLoaded(x, z))
|
||||
return;
|
||||
|
||||
this.reloadHopper();
|
||||
this.syncName();
|
||||
}
|
||||
|
||||
public EHopper(Block block, Level level, UUID lastPlayer, UUID placedBy, List<Block> linkedBlocks, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) {
|
||||
public EHopper(Block block, Level level, UUID lastPlayer, UUID placedBy, List<Location> linkedBlocks, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) {
|
||||
this(block.getLocation(), level, lastPlayer, placedBy, linkedBlocks, filter, teleportTrigger, autoCrafting);
|
||||
}
|
||||
|
||||
@ -556,9 +563,9 @@ public class EHopper implements Hopper {
|
||||
}
|
||||
|
||||
if (!filtered)
|
||||
this.linkedBlocks.add(toLink);
|
||||
this.linkedBlocks.add(toLink.getLocation());
|
||||
else
|
||||
this.filter.setEndPoint(toLink);
|
||||
this.filter.setEndPoint(toLink.getLocation());
|
||||
this.lastPlayer = player.getUniqueId();
|
||||
|
||||
if (level.getLinkAmount() > 1) {
|
||||
@ -637,12 +644,12 @@ public class EHopper implements Hopper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Block> getLinkedBlocks() {
|
||||
public List<Location> getLinkedBlocks() {
|
||||
return Collections.unmodifiableList(linkedBlocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLinkedBlock(Block block) {
|
||||
public void addLinkedBlock(Location block) {
|
||||
linkedBlocks.add(block);
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,6 @@ public class BlockListeners implements Listener {
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
try {
|
||||
Player player = e.getPlayer();
|
||||
if (e.getBlock().getType().equals(Material.ENDER_CHEST)) {
|
||||
//instance.getDataFile().getConfig().set("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(e.getBlock()), player.getUniqueId().toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getBlock().getType() != Material.HOPPER) return;
|
||||
|
||||
@ -103,10 +99,6 @@ public class BlockListeners implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
try {
|
||||
if (event.getBlock().getType().equals(Material.ENDER_CHEST)) {
|
||||
//instance.getDataFile().getConfig().set("data.enderTracker." + Arconix.pl().getApi().serialize().serializeLocation(event.getBlock()), null);
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class HopperListeners implements Listener {
|
||||
Hopper hopper = instance.getHopperManager().getHopper(source.getLocation());
|
||||
if (hopper.getLinkedBlocks() == null || hopper.getLinkedBlocks().isEmpty()) {
|
||||
hopper.clearLinkedBlocks();
|
||||
hopper.addLinkedBlock(event.getDestination().getLocation().getBlock());
|
||||
hopper.addLinkedBlock(event.getDestination().getLocation());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
} catch (Exception ee) {
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epichoppers.storage;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epichoppers.utils.Serializers;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -33,10 +34,10 @@ public class StorageItem {
|
||||
this.object = object.toString();
|
||||
}
|
||||
|
||||
public StorageItem(String key, boolean type, List<Block> blocks) {
|
||||
public StorageItem(String key, boolean type, List<Location> blocks) {
|
||||
StringBuilder object = new StringBuilder();
|
||||
for (Block block : blocks) {
|
||||
object.append(Arconix.pl().getApi().serialize().serializeLocation(block));
|
||||
for (Location location : blocks) {
|
||||
object.append(Arconix.pl().getApi().serialize().serializeLocation(location));
|
||||
object.append(";;");
|
||||
}
|
||||
this.key = key;
|
||||
|
Loading…
Reference in New Issue
Block a user