Using external classes in command method

Discussion in 'Plugin Development' started by kag359six, Jul 11, 2012.

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

    kag359six

    In the following code I made a seperate class that has functions for create buildings, and when i use it in my onCommand method it doesn't create the building. I have tested the code in the other class already in a different onCommand method and it works, but when the code is put in a different class it doesnt work. Anyone know why or how to get it to work? Any suggestion would be helpful.

    Code:
    package com.gmail.kag359six.MinecraftPlugin;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
     
    public class SuperStructures implements CommandExecutor {
     
        private MinecraftPlugin plugin;
        private Structures s;
     
        public SuperStructures(MinecraftPlugin plugin) {
         
            this.plugin = plugin;
         
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[]arg) {
         
            if(cmd.getName().equalsIgnoreCase("createstructure")) {
             
                Player player = sender.getServer().getPlayer(sender.getName());
                Block b = player.getTargetBlock(null, 100);
                org.bukkit.Location loc = b.getLocation();
                World world = loc.getWorld();
             
                int posX = loc.getBlockX();
             
                int posY = loc.getBlockY();
     
                int posZ = loc.getBlockZ();
             
                s = new Structures(13, 25, 13, sender, world);
             
                s.createWallFront(posX, posY, posZ);
                s.createWallRight(posX, posY, posZ);
                s.createWallBack(posX, posY, posZ);
                s.createWallLeft(posX, posY, posZ);
                s.createRoof(posX, posY, posZ);
                s.createFloors(posX, posY, posZ);
                s.createFrontDoor(posX, posY, posZ);
             
             
                return true;
             
            }
         
            else {
             
                return false;
             
            }
         
        }
     
    }
     
  2. I dont see the problem, is there an problem?
     
  3. Offline

    kag359six

    There is no error, but the "s.create" code isnt running. none of the Structures functions are running. Although the command IS registered by Minecraft so its not the command.
     
  4. can you add some debug statements around it to verify its called?
     
  5. Offline

    kag359six

    Interesting... The methods are apparantely running. It sends the debug messages. But the meat of the code isnt running nor is it giving errors... Do you think if I showed the Structures class it would help you see issues?
     
  6. yes, I think the bug is located there then, if its not at the onCommand()
     
  7. Offline

    kag359six

    heres a piece of the Structures class

    Code:
    package com.gmail.kag359six.MinecraftPlugin;
     
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.CommandSender;
     
    public class Structures {
       
        private int length;
        private int width;
        private int height;
       
        private int newYpos = 0;
        private int newZpos = 0;
        private int newXpos = 0;
       
        private CommandSender sender;
        private World world;
       
        public Structures(int x, int y, int z, CommandSender commander, World world) {
            length = z;
            width = x;
            height = y;
           
            this.sender = commander;
            this.world = world;
            sender.sendMessage("Structures class initiated");
        }
       
        public void createWallFront(int posX, int posY, int posZ) {
           
            sender.sendMessage("front wall method should be running");
            for(int x = posX; x < width; x++) {
                if(x % 2 == 0) {
                   
                    int inc = 2;
                    for(int y = posY; y < height; y+= inc) {
                       
                        if(y > posY) {
                           
                            inc = 1;
                           
                        }
                       
                        Block blockToChange = world.getBlockAt(x,y,posZ);
                        blockToChange.setTypeId(45);
                       
                    }
                   
                    int incr = 1;
                   
                    for(int y = posY; y < height; y++) {
                       
                        sender.sendMessage("" + incr);
                        if(y == posY + incr) {
                           
                            Block blockToChange = world.getBlockAt(x,y,posZ);
                            blockToChange.setTypeId(20);
                            if(y == posY + 1) {
                               
                                incr += 4;
                               
                            }
                           
                            else {
                               
                                incr += 4;
                               
                            }
     
                           
                        }
                       
                        newYpos  = y;
                       
                    }
                   
                    for(int y = newYpos; y < height; y++) {
                       
                       
                       
                        Block blockToChange = world.getBlockAt(x,y,posZ);
                        blockToChange.setTypeId(45);
                       
                       
                    }
                   
     
                   
                   
     
                }
                else {
                    for(int y = posY; y < height; y++) {
                       
                    if(y > posY + 45) {
                           
                            x = posX + width / 4;
                           
                        }
                        Block blockToChange = world.getBlockAt(x,y,posZ);
                        blockToChange.setTypeId(45);
     
                    }
     
                }
               
                newXpos = x;
            }
           
        }
     
  8. I see this
    for(int x = posX; x < width; x++)
    width is just something like 5 (if I am correct)
    posX can be some random world cordinate, so the player need to be standing on an x cordinate of 5 or lower to let it work?

    I think this problem is located on more spots
     
    kag359six likes this.
  9. Offline

    kag359six

    You know what I think your right. I meant to put something like (x < posX + width). Let me change it everywhere and ill get back to you.

    thanks a bunch i got it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
Thread Status:
Not open for further replies.

Share This Page