Explosive Mine / Replace a block and keep properties / Make a block invisible

Discussion in 'Plugin Development' started by jersogamer, Jul 13, 2018 at 8:22 AM.

  1. Offline

    jersogamer

    Well, first of all sorry if my english is not good. I used to play skywars and there they had a explosive mine, but what is it? well, they used a gold pressure plate so when the player put the mine it is visible for the player that put the mine, but for the other players it was invisible, so a player could walk along a bridge and step on a mine then the mine explodes. that's what I want to do. I already have the code for making the explosion.

    I think that they maybe change the mine into air, but the mine is like if it still were there.

    Goal: Make a code that when I put the mine it is visible for me, but not for other players.

    If someone is interested here's my code to make the explosion.

    Code:
    @EventHandler
        public void mina(PlayerInteractEvent eventmina) {
            FileConfiguration config = plugin.getConfig();
            if(eventmina.getAction() == Action.PHYSICAL) {
                Location location = eventmina.getClickedBlock().getLocation();
                if(eventmina.getClickedBlock().getType() == Material.GOLD_PLATE) {
                    Player player = eventmina.getPlayer();
                    player.getWorld().createExplosion(location, Float.valueOf(config.getString("config.mina-explosion")));
                    player.sendMessage(ChatColor.RED+"Pisaste una mina explosiva");
                    return;
                }
            }
        }
     
    Last edited: Jul 13, 2018 at 5:16 PM
  2. Offline

    MightyOne

    You can manipulate what block a player sees by using Player#sendBlockChange(). Everytime the block gets updated a player will see the original block again. Also if a chunk has to be loaded again.

    But by sending a block change into air to everyone 1 tick after the mine has been placed should work fine.
     
  3. Offline

    jersogamer

    I'm not really good at coding so I didn't understand too much, I know that it is bad to ask for a code, but could you explain me better or send me the code? please, sorry
     
  4. Offline

    KarimAKL

    @MightyOne What if the player uses F3 + A to reload chunks? Would that change it back to normal?
     
  5. Online

    timtower Ninja on the waves Moderator

    You can overcome that by using ProtocolLib to change the packets send to the player directly.
     
  6. Offline

    MightyOne

    @KarimAKL @timtower i just tested it out with a plugin i cannot debug right now xD.
    Either f3+a does not request all block information to be sent again by the server OR the ChunkLoadEvent gets triggered and you can refresh the fake blocks there. Sorry for the uncertainty.

    I think it's the former one
     
  7. Offline

    KarimAKL

Share This Page