@Override public void run()
{
for (Entity e : getWorld().getEntitiesByClasses(Item.class))
{
Item item = (Item) e;
UUID uuid = item.getUniqueId();
Location prev = itemLocations.get(uuid);
Location curr = e.getLocation();
Location stop = lastStoppedLocation.get(uuid);
if (prev == null) continue;
boolean pass = TeleportationUtil.isBlockPassable(curr.getBlock());
// if the item is moving upwards and is currently in a passable
double ydelta = curr.getY() - prev.getY();
if (ydelta > YDELTA_THRESHOLD && !pass && !elevatedItem.containsKey(uuid))
elevatedItem.put(uuid, false);
double dy = stop == null ? 0.0 : curr.getY() - stop.getY();
if (elevatedItem.containsKey(uuid) && dy >= DISTANCE_THRESHOLD)
elevatedItem.put(uuid, true);
if (ydelta < 0.001)
{
// record the last location it was stopped at
lastStoppedLocation.put(uuid, curr);
boolean atrest = !TeleportationUtil.isBlockPassable(curr.getBlock().getRelative(0, -1, 0));
if (elevatedItem.containsKey(uuid) && elevatedItem.get(uuid) && atrest)
{
// if the item didn't elevate high enough, don't worry about it
if (dy < DISTANCE_THRESHOLD) { elevatedItem.remove(uuid); continue; }
setLastNotificationLocation(curr);
String coords = LocationUtil.toBlockCoords(curr);
String msg = ChatColor.DARK_GRAY + String.format(
"Possible Item Elevator @ (%s) [y%+d] %s", coords, Math.round(dy),
new BlockData(item.getItemStack()).getDisplayName());
for (Player ref : getReferees()) ref.sendMessage(msg);
AutoReferee.log(msg);
}
}