Solved Best way to detect who caused created explosion

Discussion in 'Plugin Development' started by bwfcwalshy, Jul 29, 2016.

Thread Status:
Not open for further replies.
  1. Hey, so I am making an explosion using World#createExplosion when someone breaks a block and can explode then. I need to get the player who broke the block, my idea was to add them to a Map<Location, UUID> and then check the location in BlockExplodeEvent but that seems a little wasteful to add to a map and then remove a millisecond later. I was wondering if anyone had any better solutions to getting the player. Since multiple people could be doing this I can't just make a player variable or anything like that. I will need the UUID and location.
     
  2. Offline

    ArsenArsen

    Set the block to some that can hold data, example a Hopper, and if you do a container like Hopper set its name to players UUID. Or if you use a normal data holder, just read the data from it.

    EDIT or spawn an entity and give it some meta or custom name.
     
  3. Offline

    MarinD99

    Why not just use BlockBreakEvent? It covers everything you need.
     
  4. @ArsenArsen So your suggesting set it to a data-holding-block instead of air then on explode read that? I wonder if the player will render the block change considering it will be from event to event. I would obviously prefer the player not seeing a hopper but a solution is a solution.

    @MarinD99 it does not cover explosions created by World#createExplosion
     
  5. Offline

    ArsenArsen

    Yea. And you can go ahead and filter the packet out if you really need to. Protocollib =p
     
  6. Offline

    MarinD99

    @bwfcwalshy ,

    Code:
    @EventHandler
        public void onBlockBreak(BlockBreakEvent e) {
            Player p = e.getPlayer();
            Block b = e.getBlock();
            Location l = b.getLocation();
            World w = l.getWorld();
            w.createExplosion(l, 1);
            getServer().broadcastMessage(p.getDisplayName() + ChatColor.AQUA + " has broken a block and caused an explosion.");
        }
     
  7. @MarinD99 Again, not helpful, I need the explosion data along with the Player, this is not a solution.

    @ArsenArsen Looking into it now, I can get the inventory of it but issue, you can't actually set the name of it since that is done in creation, I might have to look into doing something else. I might look into what MetaData I can use to see if I can change any of that to resemble the player.

    EDIT: What if I added the players head or an item with a display name of their UUID, then I can just grab the first item and it's display name.
     
    Last edited: Jul 29, 2016
  8. Offline

    ArsenArsen

    @bwfcwalshy use a skull. And set the owner to the player which did it.
     
  9. Offline

    MarinD99

    @ArsenArsen I generally like the premise of your idea, but it also seems to me like you're overcomplicating things. Maybe I'm wrong, but wouldn't using skulls (and defining their values, their owners and so on) store an equal amount of data(if not larger) as using a HashMap? Also, a lot of block breaks would mean more explosions, and more explosions would mean more block change renders. I'm not entirely sure how well this would act on a server.
     
    I Al Istannen likes this.
  10. Offline

    I Al Istannen

    @bwfcwalshy @ArsenArsen
    I would agree with @MarinD99
    Adding the UUID to a map is blazingly fast (hash and stuff). Removing too. You will need to be quite creative to make that the bottleneck.

    I would go for "Premature optimization is the root of all evil" and try the map. If it impacts the performance, implement other solutions.
     
  11. Offline

    ArsenArsen

    @I Al Istannen he asked for a map less solution, I gave him one =)
     
    Last edited: Jul 29, 2016
    I Al Istannen likes this.
  12. @I Al Istannen @ArsenArsen Yeah I think Map will have to be the way to go, this is probably more time and memory consuming than a Map, just was wondering if there was a better way than the Map :p
     
    I Al Istannen likes this.
  13. Offline

    ArsenArsen

    @MarinD99 It is possible that I am. I like overcomplicating stuff :) Just look at anything I made.
     
  14. @ArsenArsen If you don't over complicate your doing it wrong!
     
Thread Status:
Not open for further replies.

Share This Page