#Want to clear all sniffer locations.

1 messages · Page 1 of 1 (latest)

languid cloak
#

So I was wondering if there is a way to add all sniffer discovered locations and wipe them clean.

I have only managed to get the newer ones to cleared and not the old ones.

    @EventHandler(priority = EventPriority.MONITOR)
    public void onSnifferDiscoveredItem(EntityDropItemEvent e) {
        if (e instanceof Sniffer sniffer) {
            if (e.isCancelled()) return;
            Location location = sniffer.getLocation();
            Block bLocation = sniffer.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
            sniffer.removeExploredLocation((Location) bLocation);
        }
    }
prime jetty
languid cloak
#

Never looked at MemoryKey before. Will it clear everytime it drops an item even the older memory?

prime jetty
#

afaik yeah

#

Unsure how their explored locations are stored, or how many for that matter. Though I'd imagine just setting the memory key value to null should remove any and all stored positions

#

I suppose alternatively,

sniffer.getExploredLocations().forEach(sniffer::removeExploredLocation);```
languid cloak
#

I may go for the 2nd one as it may give the best behavior, but if it doesnt work, then maybe i will go for MemoryKey

languid cloak
#

Tested and the event isn't firing for some reason @prime jetty :/

#

threw in debug type code just to see if it will work

languid cloak
#

Maybe it goes off of another event I am unfamiliar with or its a bug

prime jetty
#

It fires, though you're checking if e instanceof Sniffer which probably isn't what you want

#

e.getEntity() instanceof Sniffer

#

This is why we name things by their full name PES2_BlushCoffee event.getEntity() instanceof Sniffer

#

Also, @EventHandler has an ignoreCancelled boolean you can use.

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onSnifferDiscoveredItem(EntityDropItemEvent event) {
        if (event.getEntity() instanceof Sniffer sniffer) {
            sniffer.getExploredLocations().forEach(sniffer::removeExploredLocation);
        }
    }```
languid cloak
#

that may be why

#

plus I think I will keep the cancelled stuff incase its cancelled

#

but then again, I do want to purge em regardless, so I guess I will keep it

prime jetty
#

Just a quick trick instead of having to do if (e.isCancelled()) return;

languid cloak
#

Alright. I changed it up a bit to what I want them to do for now:

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onSnifferDiscoveredItem(EntityDropItemEvent e) {
        if (e.getEntity() instanceof Sniffer sniffer) {
            
            // Debug
            Bukkit.getLogger().warning("Sniffer " + sniffer.getEntityId() + " found " + e.getItemDrop().getName() + ".");
            
            sniffer.getExploredLocations().forEach(sniffer::removeExploredLocation); // Should Purge them
            
            sniffer.findPossibleDigLocation(); // Totally not trying to overwork them ;D

            // Debug to see if it can dig or not.
            if (sniffer.canDig()) {
                Bukkit.getLogger().warning("Sniffer " + sniffer.getEntityId() + " Found a possible dig site.");
            } else {
                Bukkit.getLogger().warning("Sniffer " + sniffer.getEntityId() + " Couldn't find a possible dig site.");
            }
        }
    }
#

yep. its working now

#
[01:30:39 WARN]: Sniffer 201 found Pitcher Pod.
[01:30:39 WARN]: Sniffer 201 Found a possible dig site.