Am I doing something wrong, I'm trying to set the block a player is holding in his hand Code (Text): @EventHandler public void onBlockPlace(BlockPlaceEvent event){ Bukkit.broadcastMessage("3"); dataManager dm = new dataManager(pl); FileConfiguration data = dm.getData(); Player p = event.getPlayer(); if(data.getStringList("SneakyAdmins.players").contains(p.getName())){ Bukkit.broadcastMessage("4"); event.setCancelled(true); Block b = event.getBlock(); b.getLocation().getBlock().setType(p.getItemInHand().getType()); } }
I believe the reason is that since the event was cancelled, after the event finishes the server sets the block back to air. The way around this would be to schedule a task for 1 tick later that changes the block to your desired type.
I'm trying to cancel it so that it doesn't make a sound when placing. Is there another event that I could use?
Sorry I misunderstood you I am now trying Code (Text): @EventHandler public void onBlockPlace(BlockPlaceEvent event){ Bukkit.broadcastMessage("3"); dataManager dm = new dataManager(pl); FileConfiguration data = dm.getData(); Player p = event.getPlayer(); if(data.getStringList("SneakyAdmins.players").contains(p.getName())){ Bukkit.broadcastMessage("4"); event.setCancelled(true); Block b = event.getBlock(); Location loc = new Location(b.getWorld(), b.getX(), b.getY(), b.getZ()); HashMap<String, BukkitRunnable> task = new HashMap<String, BukkitRunnable>(); task.put(p.getName(), new BukkitRunnable(){ int i = 1; public void run() { i--; if(i == 0) loc.getBlock().setType(p.getItemInHand().getType()); } }); task.get(p.getName()).runTaskTimer(pl, 1, 1); } } But it still playing the sound
It will still play the sound for the person who placed the block, because that is client side. Have you checked to see if other players still hear the sound? Edit: Also, I wouldn't use a task timer, the code as you have it will run the task every tick for the rest of time