Creating a block with a plugin.

Discussion in 'Plugin Development' started by Supermater228fedya, Apr 2, 2020.

Thread Status:
Not open for further replies.
  1. Sorry for the mistakes used by google translator. I just started creating plugins, so this question can be silly. I can talk for a long time about what I'm trying to do, or describe a specific situation, but I won’t.
    I have a coordinate and I need to put a block on it.
    I tried this setBlock (loc, Material.STONE); - does not work.
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Thank you, but it didn’t work for me, so I’ll say what I’m doing specifically. I am making a plugin similar to WorldGuard, here is the code:
    Code:
    package Klaster.main;
    import org.bukkit.Location;
    import org.bukkit.ChatColor;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import  org.bukkit.Material;
    public class Handler implements Listener{
        int x1 = 1;
        int y1 = 1;
        int z1 = 1;
        int x2 = 10;
        int y2 = 10;
        int z2 = 10;
        @EventHandler
        public void join(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            p.sendMessage(p.getName());
           
        }
        @EventHandler
        public void block(BlockBreakEvent e) {
             Player p = e.getPlayer();
             Block b = e.getBlock();
             p.sendMessage(ChatColor.AQUA + "Ты сломал "+ b.getX() + " "+ b.getY() + " "+ b.getZ()+ " "+ b.getType());
             if(b.getX() >= x1 && b.getY() >= y1 && 
             b.getZ() >= z1 && b.getX() <= x2 &&
             b.getY() <= y2 &&b.getZ() <= z2) {
            //If a person broke a block between coordinates 1 1 1 and 10 10 10, then this block must be put back
             Location loc = b.getLocation();
             p.sendMessage("Privated!");
             loc.getBlock().setType(Material.STONE);
             
             }
        }
       
    }
     
    Last edited by a moderator: Apr 2, 2020
  4. Online

    timtower Administrator Administrator Moderator

    @Supermater228fedya Did it get past the if statements then?
    And if you have the block already then you don't need to use the location anymore.
     
  5. Perhaps we did not understand each other a little. Yes, the action in the “if” takes place when the block is destroyed, and in this case, in place of this block, which is broken, and which is already air, I need to put this block again.
     
  6. Online

    timtower Administrator Administrator Moderator

  7. Thanks, but how? Still, I would like to know why loc.getBlock (). SetType does not work.
     
  8. Online

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page