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

Discussion in 'Plugin Development' started by jersogamer, Jul 13, 2018.

Thread Status:
Not open for further replies.
  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
  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

  8. Offline

    jersogamer

    I'm not understanding what is hapenning : (

    @MightyOne I already try this, and it didn't work
    Code:
    @SuppressWarnings({ "deprecation", "unlikely-arg-type" })
        @EventHandler
        public void place(BlockPlaceEvent placevent) {
            Player jugador = placevent.getPlayer();
            if(placevent.getBlock() != null && placevent.getBlock().equals(Material.GOLD_PLATE)) {
                Location localidad = placevent.getBlock().getLocation();
                jugador.sendBlockChange(localidad, Material.AIR, (byte) 0);
            }
           
       
           
        }
    Also I already change the value of "Material.Air" into "0(Zero)"
     
    Last edited: Jul 16, 2018
  9. Offline

    MightyOne

    @jersogamer
    You missed that one important part.
     
  10. Offline

    jersogamer

    I have no idea how to do that
     
  11. Offline

    MightyOne

  12. Offline

    jersogamer

    Sorry, I tried it, but I couldn't do it, I read that page like 5 times and I didn't get it, the problem here is that I don't know how to add that into my code, and I already looked for the answer in the forum, but I have the same problem, I don't know how to implement that in my code.
     
  13. Offline

    KarimAKL

    @jersogamer Try like this:
    Code:Java
    1. @EventHandler
    2. public void place(BlockPlaceEvent placevent) {
    3. Player jugador = placevent.getPlayer();
    4. if(placevent.getBlock() != null && placevent.getBlock().equals(Material.GOLD_PLATE)) {
    5. Location localidad = placevent.getBlock().getLocation();
    6. new BukkitRunnable() {
    7. public void run() {
    8. jugador.sendBlockChange(localidad, Material.AIR, (byte) 0);
    9. }
    10. }.runTaskLater(plugin, 1);
    11. }
    12. }
     
  14. Offline

    jersogamer

    I tried it, but It didn't work, also I had to add many things to my code, 'cause there were many warnings.

    Code:
    @SuppressWarnings("unlikely-arg-type")
        @EventHandler
        public void place(BlockPlaceEvent placevent)  {
            final Player jugador = placevent.getPlayer();
            if(placevent.getBlock() != null && placevent.getBlock().equals(Material.GOLD_PLATE)) {
                final Location localidad = placevent.getBlock().getLocation();
                new BukkitRunnable() {
                    @SuppressWarnings("deprecation")
                    public void run() {
                        jugador.sendBlockChange(localidad, Material.AIR, (byte) 0);   
                    }
                }.runTaskLater(plugin, 1);
            }
            
     
  15. Offline

    KarimAKL

    @jersogamer Did you remember to import after that? Also change "plugin" in the "runTaskLater(plugin, 1)" to a instance of your main class. (the one that extends JavaPlugin) Of course that only applies if "plugin" isn't already a instance of your main class. If you did these things already then i don't have a clue as i'm pretty new.

    I really hope i used the correct names for what to do, anyway hope this helps. :7
     
Thread Status:
Not open for further replies.

Share This Page