mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-22 10:15:43 +01:00
fixes
This commit is contained in:
parent
e9c743dc7a
commit
26d3e86313
@ -73,8 +73,8 @@ public class HopHandler {
|
||||
}
|
||||
Block block = location.getBlock();
|
||||
|
||||
|
||||
if (block == null || block.getType() != Material.HOPPER) {
|
||||
instance.getHopperManager().removeHopper(location);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -96,20 +96,20 @@ public class HopHandler {
|
||||
|
||||
if (hopper.getSyncedBlock() == null) continue;
|
||||
Location dest = hopper.getSyncedBlock().getLocation();
|
||||
if (dest == null) {
|
||||
hopper.setSyncedBlock(null);
|
||||
continue;
|
||||
}
|
||||
if (dest == 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 || b2.getType() == Material.ENDER_CHEST)) {
|
||||
hopper.setSyncedBlock(null);
|
||||
continue;
|
||||
}
|
||||
|
||||
//InventoryHolder inventoryHolder = (InventoryHolder) b2.getState();
|
||||
//TODO add some restrictions here if needed
|
||||
|
||||
@ -122,7 +122,7 @@ public class HopHandler {
|
||||
List<ItemStack> blackList = hopper.getFilter().getBlackList();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ItemStack it = null;
|
||||
ItemStack it;
|
||||
if (is[i] != null) {
|
||||
it = is[i].clone();
|
||||
it.setAmount(1);
|
||||
@ -140,6 +140,7 @@ public class HopHandler {
|
||||
doBlacklist(hopperBlock, hopper, is[i].clone(), is, amt, i);
|
||||
} else {
|
||||
if (is[i] != null && blackList.stream().noneMatch(itemStack -> itemStack.isSimilar(is[finalI]))) {
|
||||
|
||||
int im = addItem(hopperBlock, hopper, b2, is[i], is, amt, i);
|
||||
if (im != 10)
|
||||
i = im;
|
||||
|
@ -50,7 +50,7 @@ public class EHopper implements Hopper {
|
||||
this.placedBy = placedBy;
|
||||
this.teleportTrigger = teleportTrigger;
|
||||
this.autoCrafting = autoCrafting;
|
||||
this.hopper = (org.bukkit.block.Hopper) (location.getBlock() != null && location.getBlock().getType() == Material.HOPPER ? location.getBlock().getState() : null);
|
||||
this.reloadHopper();
|
||||
}
|
||||
|
||||
public EHopper(Block block, Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) {
|
||||
@ -523,6 +523,10 @@ public class EHopper implements Hopper {
|
||||
return hopper;
|
||||
}
|
||||
|
||||
public void reloadHopper() {
|
||||
this.hopper = (org.bukkit.block.Hopper) (location.getBlock() != null && location.getBlock().getType() == Material.HOPPER ? location.getBlock().getState() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync(Block toSync, boolean filtered, Player player) {
|
||||
try {
|
||||
|
@ -8,6 +8,7 @@ import com.songoda.epichoppers.player.PlayerData;
|
||||
import com.songoda.epichoppers.player.SyncType;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import com.songoda.epichoppers.utils.Methods;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@ -16,6 +17,8 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -49,6 +52,31 @@ public class InteractListeners implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMoveChunk(PlayerMoveEvent e) {
|
||||
updateHopper(e.getFrom().getChunk(), e.getTo().getChunk());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTeleport(PlayerTeleportEvent e) {
|
||||
updateHopper(e.getFrom().getChunk(), e.getTo().getChunk());
|
||||
}
|
||||
|
||||
private void updateHopper(Chunk from, Chunk to) {
|
||||
if (from == to) return;
|
||||
|
||||
for (Hopper hopper : instance.getHopperManager().getHoppers().values()) {
|
||||
Location location = hopper.getLocation();
|
||||
|
||||
int x = location.getBlockX() >> 4;
|
||||
int z = location.getBlockZ() >> 4;
|
||||
|
||||
if (location.getWorld().getChunkAt(x, z) == to) {
|
||||
((EHopper)hopper).reloadHopper();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockInteract(PlayerInteractEvent e) {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user