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

    user_43347

    Yes, the (2, 0, 0) means (x, y, z), its how much to add on each axis. There is also a subtract function.
    Sure there is some boolean errors and arguments errors in there, but it would run fine.
    Edit: A command listener isn't even required, what he is doing is fine.
     
  2. Offline

    KaiBB

    Watch the GTOTechnology tutorials I told you about.
     
  3. Offline

    Pirogun

    Ok Well I think I am going to go with steaks4uce because i never used a commandlistener
     
  4. Offline

    nickrak

    You don't need a commandlistener unless you want a separate class to handle text commands. If you are handling all text commands in the plugin class itself, you can just implement the onCommand function.

    Based on the previous discussion, I believe you are missing or have an incomplete plugin.yml.
     
    Pirogun and steaks4uce like this.
  5. Offline

    user_43347

    Thanks for explaining it!
     
    Pirogun likes this.
  6. Offline

    Chiller

    But you still need to register the command...

    I also have a great theory on how he should make the actual house!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  7. Offline

    user_43347

    In the plugin.yml, yes, of course. But a command listener is not needed.
    Just get every block between two points?
     
  8. Offline

    Chiller

    That wouldn't be a house then...
     
  9. Offline

    nickrak

    fill every block between two points, as mentioned before, then move the points one block diagonally towards each other and replace all with air.
     
  10. Offline

    user_43347

    Exactly my point, thanks for the backup :p
     
  11. Offline

    Chiller

    Now you didn't say that, now did you :p
     
  12. Offline

    user_43347

    Actually, yes, I did.
     
  13. Offline

    Chiller

    YOU only said "Just get every block between two points?".
     
  14. Offline

    Pirogun

    Well it failed for me and I have no errors and the plugin makes sense:
    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 loc1 = player.getLocation().add(4, 1, 0);
                        Location loc2 = player.getLocation().add(4, 0, -1);
                        Location loc3 = player.getLocation().add(4, 0, -2);
                        Location loc4 = player.getLocation().add(4, 1, -2);
                        Location loc5 = player.getLocation().add(4, 2, -2);
                        Location loc6 = player.getLocation().add(4, 3, -1);
                        Location loc7 = player.getLocation().add(4, 3, 0);
                        Location loc8 = player.getLocation().add(4, 3, 1);
                        Location loc9 = player.getLocation().add(4, 3, 2);
                        Location loc10 = player.getLocation().add(4, 2, 2);
                        Location loc11 = player.getLocation().add(4, 1, 2);
                        Location loc12 = player.getLocation().add(4, 2, -1);
                        Location loc13 = player.getLocation().add(4, 2, 1);
                        Location loc14 = player.getLocation().add(4, 1, 1);
                        //Placing the blocks down
                        loc1.getBlock().setType(Material.WOODEN_DOOR);
                        loc2.getBlock().setType(Material.WOOD);
                        loc3.getBlock().setType(Material.LOG);
                        loc4.getBlock().setType(Material.LOG);
                        loc5.getBlock().setType(Material.LOG);
                        loc6.getBlock().setType(Material.LOG);
                        loc7.getBlock().setType(Material.LOG);
                        loc8.getBlock().setType(Material.LOG);
                        loc9.getBlock().setType(Material.LOG);
                        loc10.getBlock().setType(Material.LOG);
                        loc11.getBlock().setType(Material.LOG);
                        loc12.getBlock().setType(Material.WOOD);
                        loc13.getBlock().setType(Material.WOOD);
                        loc14.getBlock().setType(Material.WOOD);
                        //The Front side of the House
                        Location loc15 = player.getLocation().add(5, 4, 0);
                        Location loc16 = player.getLocation().add(6, 4, 0);
                        Location loc17 = player.getLocation().add(7, 4, 0);
                        Location loc18 = player.getLocation().add(5, 4, -1);
                        Location loc19 = player.getLocation().add(6, 4, -1);
                        Location loc20 = player.getLocation().add(7, 4, -1);
                        Location loc21 = player.getLocation().add(5, 4, 1);
                        Location loc22 = player.getLocation().add(6, 4, 1);
                        Location loc23 = player.getLocation().add(7, 4, 1);
                        //Roof^
                        Location loc24 = player.getLocation().add(5, 1, -2);
                        Location loc25 = player.getLocation().add(6, 1, -2);
                        Location loc26 = player.getLocation().add(7, 1, -2);
                        Location loc27 = player.getLocation().add(5, 2, -2);
                        Location loc28 = player.getLocation().add(6, 2, -2);
                        Location loc29 = player.getLocation().add(7, 2, -2);
                        Location loc30 = player.getLocation().add(5, 3, -2);
                        Location loc31 = player.getLocation().add(6, 3, -2);
                        Location loc32 = player.getLocation().add(7, 3, -2);
                        //Left Side of the House^
                        Location loc47 = player.getLocation().add(5, 1, 2);
                        Location loc48 = player.getLocation().add(6, 1, 2);
                        Location loc49 = player.getLocation().add(7, 1, 2);
                        Location loc50 = player.getLocation().add(5, 2, 2);
                        Location loc51 = player.getLocation().add(6, 2, 2);
                        Location loc52 = player.getLocation().add(7, 2, 2);
                        Location loc53 = player.getLocation().add(5, 3, 2);
                        Location loc54 = player.getLocation().add(6, 3, 2);
                        Location loc55 = player.getLocation().add(7, 3, 2);
                        //Right Side of the House
                        Location loc33 = player.getLocation().add(8, 3, -2);
                        Location loc34 = player.getLocation().add(8, 3, -1);
                        Location loc35 = player.getLocation().add(8, 3, 0);
                        Location loc36 = player.getLocation().add(8, 3, 1);
                        Location loc37 = player.getLocation().add(8, 3, 2);
                        Location loc38 = player.getLocation().add(8, 2, -2);
                        Location loc39 = player.getLocation().add(8, 2, -1);
                        Location loc40 = player.getLocation().add(8, 2, 0);
                        Location loc41 = player.getLocation().add(8, 2, 1);
                        Location loc42 = player.getLocation().add(8, 2, 2);
                        Location loc43 = player.getLocation().add(8, 1, -2);
                        Location loc44 = player.getLocation().add(8, 1, -1);
                        Location loc45 = player.getLocation().add(8, 1, 0);
                        Location loc46 = player.getLocation().add(8, 1, 1);
                        Location loc56 = player.getLocation().add(8, 1, 2);
    
                        //the Backside of the house
                        //Placing the blocks
                        loc15.getBlock().setType(Material.STEP);
                        loc16.getBlock().setType(Material.STEP);
                        loc17.getBlock().setType(Material.STEP);
                        loc18.getBlock().setType(Material.STEP);
                        loc19.getBlock().setType(Material.STEP);
                        loc20.getBlock().setType(Material.STEP);
                        loc21.getBlock().setType(Material.STEP);
                        loc22.getBlock().setType(Material.STEP);
                        loc23.getBlock().setType(Material.STEP);
                        //Roof^
                        loc24.getBlock().setType(Material.WOOD);
                        loc25.getBlock().setType(Material.GLASS);
                        loc26.getBlock().setType(Material.LOG);
                        loc27.getBlock().setType(Material.WOOD);
                        loc28.getBlock().setType(Material.GLASS);
                        loc29.getBlock().setType(Material.LOG);
                        loc30.getBlock().setType(Material.WOOD);
                        loc31.getBlock().setType(Material.GLASS);
                        loc32.getBlock().setType(Material.LOG);
                        //Left side of the House ^
                        loc47.getBlock().setType(Material.WOOD);
                        loc48.getBlock().setType(Material.GLASS);
                        loc49.getBlock().setType(Material.LOG);
                        loc50.getBlock().setType(Material.WOOD);
                        loc51.getBlock().setType(Material.GLASS);
                        loc52.getBlock().setType(Material.LOG);
                        loc53.getBlock().setType(Material.WOOD);
                        loc54.getBlock().setType(Material.GLASS);
                        loc55.getBlock().setType(Material.LOG);
                        //Right side of the House
                        loc33.getBlock().setType(Material.LOG);
                        loc34.getBlock().setType(Material.LOG);
                        loc35.getBlock().setType(Material.LOG);
                        loc36.getBlock().setType(Material.LOG);
                        loc37.getBlock().setType(Material.LOG);
                        loc38.getBlock().setType(Material.LOG);
                        loc39.getBlock().setType(Material.GLASS);
                        loc40.getBlock().setType(Material.GLASS);
                        loc41.getBlock().setType(Material.GLASS);
                        loc42.getBlock().setType(Material.LOG);
                        loc43.getBlock().setType(Material.LOG);
                        loc44.getBlock().setType(Material.WOOD);
                        loc45.getBlock().setType(Material.WOOD);
                        loc46.getBlock().setType(Material.WOOD);
                        loc56.getBlock().setType(Material.LOG);
                        //The Backside of the house
     
                    }else{
                        player.sendMessage(ChatColor.RED + "ERROR, NOT ENOUGH PERMISSIONS");
                    }
                }
                return false;
            }
            return win;
        }
    }
    
    Plugin.yml
    Code:
    name: House
    main: me.pirogun.House.House
    author: Pirogun
    version: 1.0
    commands:
        house:
            description: motd
            permission: house.house
        house build:
            description: build a house
            permission: house.build
    
     
  15. Offline

    Chiller

    Just letting you know you don't need to register HOUSE BUILD only HOUSE
     
  16. Offline

    nickrak

    Wow... just wow... For loops exist to so you don't have to do that all by hand...
     
  17. Offline

    Chiller

    And you could also use steaks theory and then change the SPECIAL blocks (doors)
     
  18. Offline

    Pirogun

    So I need to fix the plugin.yml
     
  19. Offline

    user_43347

    STOP! FOR THE SAKE OF PROGRAMMING!
    Like @nickrak said, loop through each block, which will require some math and code, but in the end, makes it work correctly, functions easier, less code, and don't make me want to rip my eyes out :p

    Also, change your plugin.yml to this and try it again.
    Code:
    name: House
    main: me.pirogun.House.House
    author: Pirogun
    version: 1.0
    commands:
        house:
            description: motd
            permission: house.house
            usage: /house
        build:
            description: build a house
            permission: house.build
            usage: /build
     
  20. Offline

    Pirogun

    But I am fine with this so How do I make this work

    All that happened was /house appeared

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  21. Offline

    user_43347

    No, this is not fine. You sir, need to learn correct Java before you touch another IDE.
     
  22. Offline

    nickrak

    People will be unwilling to help you if you don't write readable code. That 185 line post you made could be rewritten in probably around 50 lines. And in that state we would be able to assist in debugging it, but when you manually place blocks in arbitrary locations it is much more difficult for someone to debug... a loop we can read the conditions and see the house, with your arbitrary numbers we see spagetti-code and lose interest immediately. If you expect help you need to write somewhat readable code (nobody's perfect), but turning down a simple suggestion to make your code bearable to read is unacceptable if you expect to receive assistance from any developer worth salt.
     
  23. Offline

    Pirogun

    How can I fix it
     
  24. Offline

    nickrak

    http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html

    Read over this article about for-loops.

    HINT:

    Code:
    //Wall
            int offsetX = 0;
            int offsetZ = 0;
    
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    world.getBlock(offsetX + i, j, offsetZ).setType(Material.WOOD);
                }
            }
     
    r3Fuze likes this.
  25. Offline

    Pirogun

    //Wall? What is this?
     
  26. Offline

    nickrak

    // is the comment prefix.

    http://docs.oracle.com/javase/tutorial/java/index.html
    Read this site... please.

    I understand that some plugin developers (successful and aspiring), know java more or less than others, but this is getting kinda silly. Not knowing what a comment is is one of those things... it's a sign... you're not ready to develop a plugin. I'm sure its painful trying to piece together a working plugin without knowing what our suggestions are, and it's equally painful for us to make first-semester java suggestions (comment, for-loop, etc) and have to explain what they are.

    The link that I've provided you above, is a fantastic resource for leaning java. Please take advantage of it. If you have any questions about it, google it, somebody has asked it before.

    Take the time to learn java and it will serve you well. Patch-working a plugin together that you don't understand will just make your life a living hell if anyone decides to adopt it because debugging will be significantly harder if you don't understand why it worked in the first place.

    TL;DR: Open link. Learn java. Save the collective sanity of all involved in this thread.
     
  27. Offline

    Pirogun

    If I use multiple materials Would I use multiple loops?
    Such as if I use logs I would write a similar for loop

    P.S. I am learning all of my Java from Sam:
    http://workbench.cadenhead.org/book/java-6-21-days/
    http://workbench.cadenhead.org/book/java-6-24-hours/
     
Thread Status:
Not open for further replies.

Share This Page