X,Y,Z and Block Placement

Discussion in 'Plugin Development' started by Pirogun, Dec 19, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Pirogun

    Ok So I posted a thread earlier, but I don't think it was fully understood of what I asked for. I will be clearer. I am developing a plugin in which the player types a command and a small house made of wood pops up. It is meerly, but a frame. It is 5 by 5 blocks and it is 3 blocks high on the outer walls but then is 4 blocks high in the middle 4 by 4 hollow area. I have setup everything in the plugin to work except for the house being placed. What line(s) of code would I use to get the player's postion then in front of them (3 to 5 blocks away) have the blocks be placed.

    P.S. Is there a source for all the code? Like an encyclopedia of bukkit code?
     
  2. Offline

    Chiller

    Location loc = Player.getLocation();
    Loc.setX(loc.getX() + 2);
    //loc = bottom corner of the house!
     
  3. Offline

    Pirogun

    So is the X a coordinate or the matireal or is (loc.getX(This) + 2); the matirial
     
  4. Offline

    Chiller

    Set the material at the loc.
     
  5. Offline

    Pirogun

    So Loc.setX(plank.getX() + 2)
     
  6. Offline

    Chiller

    Nonono... Your setting the loc to the blocks position! You want to set the blocks position to loc!
    Plank.setLocation(loc);
     
  7. Offline

    Pirogun

    Ok So I will if I want multiple blocks multiple Location loc1 or loc2 and so on
     
  8. Offline

    Chiller

    Im not on a computer right now but I made something like this and i only had to make one thing for each block...
     
  9. Offline

    Pirogun

    Ok Well I ll try thanks

    P.S. Where does everyone learn all this from
     
  10. Offline

    Chiller

    From here.
     
  11. Offline

    Pirogun

    Whoa Cool THANK YOU
     
  12. Offline

    Chiller

    Hahaha no problem...
     
  13. Offline

    Pirogun

    Wait Plank.setLocation(loc); give me an error saying: Plank cannot be resolved
     
  14. Offline

    Chiller

    Because you didn't make the variable plank... Instead do loc.getBlock.setTypeId(Material.PLANK);
     
  15. Offline

    Pirogun

  16. Offline

    Chiller

    Did that work?? Because you are now changing an AIR block to a PLANK block...
     
  17. Offline

    Pirogun

    getBlock can't be resolved
     
  18. Offline

    Chiller

    oops, loc.getBlock().setTypeId(Material.PLANK);
     
  19. Offline

    Pirogun

    Ok thanks
     
  20. Offline

    Chiller

    Does it work???
     
  21. Offline

    Pirogun

    is it getBlock or placeBlock because I tested it and it failed
     
  22. Offline

    Chiller

    It should be getBlock() because it gets he block at the defined loc and sets the typeId to plank?!
     
  23. Offline

    Pirogun

    Well I did it and nothing happened at all.

    Code:
    package me.pirogun.House;
    
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class House extends JavaPlugin {
    
        public static final Logger Log = Logger.getLogger("Minecraft");
    
        boolean win;
        Player player;
    
        @Override
        public void onEnable() {
    
            Log.info("[House] has been enabled");
        }
        @Override
        public void onDisable() {
    
            Log.info("[ServerInfo] has been disabled");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("house")) {
                win = false;
                Player player = (Player) sender;
                if(args.length == 0) {
                    if(player.hasPermission("house.house")){
    
                        player.sendMessage(ChatColor.AQUA + "House is used to make a small 5x5x4 house");
                        player.sendMessage(ChatColor.AQUA + "This plugin is only allowed to Admins and up");
                        win = false;
                    }else{
                        player.sendMessage(ChatColor.RED + "ERROR, NOT ENOUGH PERMISSIONS");
                    }
                }
                return false;
            }
            if (args.length == 1){
    
                if(cmd.getName().equalsIgnoreCase("build")) {
                    if(player.hasPermission("house.build")) {
    
                        player.sendMessage(ChatColor.GOLD + "w00t, Your house has been built");
                        Location loc = player.getLocation();
                        loc.setX(loc.getX() +2);
                        loc.getBlock().setType(Material.WOOD);
     
                    }else{
                        player.sendMessage(ChatColor.RED + "ERROR, NOT ENOUGH PERMISSIONS");
                    }
                }
                return false;
            }
            return win;
        }
    }
    
     
  24. Offline

    Chiller

    You don't even have a command listener...
     
  25. Offline

    Pirogun

    Well Ok course I knew that... What is that?
     
  26. Offline

    user_43347

    @Chiller, you're going about this wrong and it can be simplified.
    @Pirogun, try something like this...
    Code:
    Location loc = player.getLocation().add(x, y, z);
    loc.getBlock().setType(Material.BEDROCK);
    Which in your case would be something like...
    Code:
    Location loc = player.getLocation().add(2, 0, 0);
    loc.getBlock().setType(Material.WOOD);
     
  27. Offline

    Pirogun

    So then that means the block is placed 2 blocks away from you?
     
  28. Offline

    KaiBB

    Oh, I didn't see this. I shall delete my last post.
     
  29. Offline

    Chiller

    But yet he still needs a command listener...
     
  30. Offline

    Pirogun

    How do I adda command listener
     
Thread Status:
Not open for further replies.

Share This Page