Solved Please delete this thread.

Discussion in 'Spigot Plugin Development' started by Pr0_fAssEr, Jun 11, 2016.

Thread Status:
Not open for further replies.
  1. I'm trying to make a plugin that when players place blocks it will disappear after 5 seconds.
    Now the problem is that if i place a block and than i logout, if there is no players online than the block will not disappear.

    Here's my code:
    Code (Text):
        public void place(final BlockPlaceEvent e) {
            if (e.getPlayer().getGameMode() == GameMode.CREATIVE)
            if (e.getBlockReplacedState().getType().name().contains("WATER")
                    || e.getBlockReplacedState().getType().name().contains("LAVA")) {
                e.getPlayer().sendMessage(Main.getPrefix() + ChatColor.RED + "You can't build on water/lava!");
            final Block b = e.getBlock();
            playerBlock.put(b, e.getPlayer());
            Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), new Runnable() {
                public void run() {
                    if (b == null)
                    if(Bukkit.getOnlinePlayers().size() > 0) {
                        for (Player ps : Bukkit.getOnlinePlayers()) {
                            ps.playEffect(b.getLocation(), Effect.STEP_SOUND,
                    Bukkit.broadcastMessage("test - " + b.getType());
            }, 20 * 5);
    #1 Pr0_fAssEr, Jun 11, 2016
    Last edited: Jun 11, 2016
  2. I believe this would be an error due to the fact that the chunk the block is found in isn't loaded if all players are logged out.
  3. can you fix it?
  4. You've got bigger problems, like storing the player instance. Just keep a cache of UUID -> Block data (e.g. an object which holds the block + placement time) and remove it when it's expired.
    • Agree Agree x 1
  5. #1 Load the chunk where the block is located if not loaded.
    #2 Set air or whatever you do.
    #3 Unload chunk of no players nearby.?
  6. I changed it to arraylist, but it doesn't fix my problem.
Thread Status:
Not open for further replies.