Custom Object Overwrites Itself in For Loop

Discussion in 'Plugin Development' started by The_Roycester, Feb 1, 2019.

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

    The_Roycester

    I am attempting to make a plugin that gets the blocks of a cuboid and gets information about single block. I am trying to store the information of every block into a custom object called "blockinfo". I have a for loop to go through each block which creates an entry of a blockinfo object. The blockinfo object for that specific block is then added to an arraylist of blockinfo objects. The problem is the previous entries of the arraylist are being overwritten by the entry that is being currently added. If someone could help me so it just adds the objects in a list without being over written that would be awesome. Thanks in advance.

    Here is my code for my blockinfo object -
    Code:
    package me.akroyce25.mobshematics;
    
    import java.util.ArrayList;
    
    public class blockinfo {
    
        static String blockid;
        static String material;
        static Integer x;
        static Integer y;
        static Integer z;
        static Integer relativex;
        static Integer relativey;
        static Integer relativez;
       
        public blockinfo (String BlockID, String material, Integer x, Integer y, Integer z, Integer relativex, Integer relativey, Integer relativez) {
            blockinfo.blockid = BlockID;
            blockinfo.material = material;
            blockinfo.x = x;
            blockinfo.y = y;
            blockinfo.z = z;
            blockinfo.relativex = relativex;
            blockinfo.relativey = relativey;
            blockinfo.relativez = relativez;
        }
       
        static ArrayList<blockinfo> schematicblockinfo = new ArrayList<blockinfo>();
       
        //NOT SURE ABOUT THIS METHOD.
        public static blockinfo getBlockID(String blockid) {
            for (blockinfo b : schematicblockinfo) {
                if (blockinfo.getID() == blockid) {
                    return b;
                }
            }
            return null;
           
        }
    
        public static void createBlockID(String blockid) {
            blockinfo b = new blockinfo(blockid, "Stone", 0, 0, 0, 0, 0, 0);
                schematicblockinfo.add(b);
        }
       
       
        public static String getID() {
            return blockid;
        }
       
        public String getMaterial() {
            return material;
        }
       
        public Integer getX() {
            return x;
        }
       
        public Integer getY() {
            return y;
        }
       
        public Integer getZ() {
            return z;
        }
       
        public Integer getRelativeX() {
            return relativex;
        }
       
        public Integer getRelativeY() {
            return relativey;
        }
       
        public Integer getRelativeZ() {
            return relativez;
        }
       
        public void setMaterial(String material) {
            blockinfo.material = material;
        }
       
        public void setX(Integer x) {
            blockinfo.x = x;
        }
       
        public void setY(Integer y) {
            blockinfo.y = y;
        }
       
        public void setZ(Integer z) {
            blockinfo.z = z;
        }
       
        public void setRelativeX(Integer x) {
            blockinfo.relativex = x;
        }
       
        public void setRelativeY(Integer y) {
            blockinfo.relativey = y;
        }
       
        public void setRelativeZ(Integer z) {
            blockinfo.relativez = z;
        }
       
        static void addBlockInfo(blockinfo b) {
            schematicblockinfo.add(b);
        }
    }
    
    Here is my code for my method that is creating the blockinfo objects -
    Code:
    package me.akroyce25.mobshematics.read_write;
    
    import java.util.ArrayList;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import me.akroyce25.mobshematics.blockinfo;
    import me.akroyce25.mobshematics.mobschematic;
    
    public class write implements Listener, CommandExecutor{
    
        static Integer x1;
        static Integer y1;
        static Integer z1;
        static Integer x2;
        static Integer y2;
        static Integer z2;
       
        static Integer length;
        static Integer width;
        static Integer height;
       
        static Integer bottomleftx;
        static Integer bottomy;
        static Integer bottomfrontz;
       
        static Integer upperrightx;
        static Integer uppery;
        static Integer upperbackz;
       
        @EventHandler
        public void onClick(PlayerInteractEvent e) {
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                x1 = e.getClickedBlock().getX();
                y1 = e.getClickedBlock().getY();
                z1 = e.getClickedBlock().getZ();
    
            }
            if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
                x2 = e.getClickedBlock().getX();
                y2 = e.getClickedBlock().getY();
                z2 = e.getClickedBlock().getZ();
    
            }
        }
       
        public static void createSchematicLength(String schematicname, Integer pos1x, Integer pos2x) {
            if(pos1x == pos2x) {
                length = 1;
            }
            if(pos1x != pos2x) {
                if((pos1x >= 0) && (pos2x >= 0)) {
                    if(pos1x > pos2x) {
                        length = (pos1x - pos2x) + 1;
                    }
                    if(pos2x > pos1x) {
                        length = (pos2x - pos1x) + 1;
                    }
                }
               
                if((pos1x >= 0) && (pos2x < 0)) {
                    if(pos1x > Math.abs(pos2x)) {
                        length = (pos1x - Math.abs(pos2x)) + 1;
                    }
                    if(pos1x < Math.abs(pos2x)) {
                        length = (Math.abs(pos2x) - pos1x) + 1;
                    }
                }
               
                if((pos1x < 0) && (pos2x >= 0)) {
                    if(Math.abs(pos1x) > pos2x) {
                        length = (Math.abs(pos1x) - pos2x) + 1;
                    }
                    if(pos2x > Math.abs(pos1x)) {
                        length = (pos2x - Math.abs(pos1x)) + 1;
                    }
                }
               
                if((pos1x < 0) && (pos2x < 0)) {
                    if(Math.abs(pos1x) > Math.abs(pos2x)) {
                         length = (Math.abs(pos1x) - Math.abs(pos2x)) + 1;
                    }
                    if(Math.abs(pos2x) > Math.abs(pos1x)) {
                        length = (Math.abs(pos2x) - Math.abs(pos1x)) + 1;
                    }
                }
            }
           
            mobschematic.getMobSchematic(schematicname).setSchematicLength(length);;
        }
    
        public static void createSchematicWidth(String schematicname, Integer pos1z, Integer pos2z) {
            if(pos1z == pos2z) {
                width = 1;
            }
            if(pos1z != pos2z) {
                if((pos1z >= 0) && (pos2z >= 0)) {
                    if(pos1z > pos2z) {
                        width = (pos1z - pos2z) + 1;
                    }
                    if(pos2z > pos1z) {
                        width = (pos2z - pos1z) + 1;
                    }
                }
               
                if((pos1z >= 0) && (pos2z < 0)) {
                    if(pos1z > Math.abs(pos2z)) {
                        width = (pos1z - Math.abs(pos2z)) + 1;
                    }
                    if(pos1z < Math.abs(pos2z)) {
                        width = (Math.abs(pos2z) - pos1z) + 1;
                    }
                }
               
                if((pos1z < 0) && (pos2z >= 0)) {
                    if(Math.abs(pos1z) > pos2z) {
                        width = (Math.abs(pos1z) - pos2z) + 1;
                    }
                    if(pos2z > Math.abs(pos1z)) {
                        width = (pos2z - Math.abs(pos1z)) + 1;
                    }
                }
               
                if((pos1z < 0) && (pos2z < 0)) {
                    if(Math.abs(pos1z) > Math.abs(pos2z)) {
                         width = (Math.abs(pos1z) - Math.abs(pos2z)) + 1;
                    }
                    if(Math.abs(pos2z) > Math.abs(pos1z)) {
                        width = (Math.abs(pos2z) - Math.abs(pos1z)) + 1;
                    }
                }
            }
           
            mobschematic.getMobSchematic(schematicname).setSchematicWidth(width);;
        }
    
        public static void createSchematicHeight(String schematicname, Integer pos1y, Integer pos2y) {
            if(pos1y == pos2y) {
                height = 1;
            }
            if(pos1y != pos2y) {
                if((pos1y >= 0) && (pos2y >= 0)) {
                    if(pos1y > pos2y) {
                        height = (pos1y - pos2y) + 1;
                    }
                    if(pos2y > pos1y) {
                        height = (pos2y - pos1y) + 1;
                    }
                }
               
                if((pos1y >= 0) && (pos2y < 0)) {
                    if(pos1y > Math.abs(pos2y)) {
                        height = (pos1y - Math.abs(pos2y)) + 1;
                    }
                    if(pos1y < Math.abs(pos2y)) {
                        height = (Math.abs(pos2y) - pos1y) + 1;
                    }
                }
               
                if((pos1y < 0) && (pos2y >= 0)) {
                    if(Math.abs(pos1y) > pos2y) {
                        height = (Math.abs(pos1y) - pos2y) + 1;
                    }
                    if(pos2y > Math.abs(pos1y)) {
                        height = (pos2y - Math.abs(pos1y)) + 1;
                    }
                }
               
                if((pos1y < 0) && (pos2y < 0)) {
                    if(Math.abs(pos1y) > Math.abs(pos2y)) {
                         height = (Math.abs(pos1y) - Math.abs(pos2y)) + 1;
                    }
                    if(Math.abs(pos2y) > Math.abs(pos1y)) {
                        height = (Math.abs(pos2y) - Math.abs(pos1y)) + 1;
                    }
                }
            }
           
            mobschematic.getMobSchematic(schematicname).setSchematicHeight(height);;
        }
       
        public static void setCornerX(Integer pos1x, Integer pos2x) {
            if(pos1x == pos2x) {
                bottomleftx = pos1x;
                upperrightx = pos2x;
            }
            if(pos1x != pos2x) {
                if((pos1x >= 0) && (pos2x >= 0)) {
                    if(pos1x > pos2x) {
                        bottomleftx = pos2x;
                        upperrightx = pos1x;
                    }
                    if(pos2x > pos1x) {
                        bottomleftx = pos1x;
                        upperrightx = pos2x;
                    }
                }
               
                if((pos1x >= 0) && (pos2x < 0)) {
                    if(pos1x > Math.abs(pos2x)) {
                        bottomleftx = pos2x;
                        upperrightx = pos1x;
                    }
                    if(pos1x < Math.abs(pos2x)) {
                        bottomleftx = pos2x;
                        upperrightx = pos1x;
                    }
                }
               
                if((pos1x < 0) && (pos2x >= 0)) {
                    if(Math.abs(pos1x) > pos2x) {
                        bottomleftx = pos1x;
                        upperrightx = pos2x;
                    }
                    if(pos2x > Math.abs(pos1x)) {
                        bottomleftx = pos1x;
                        upperrightx = pos2x;
                    }
                }
               
                if((pos1x < 0) && (pos2x < 0)) {
                    if(Math.abs(pos1x) > Math.abs(pos2x)) {
                        bottomleftx = pos2x;
                        upperrightx = pos1x;
                    }
                    if(Math.abs(pos2x) > Math.abs(pos1x)) {
                        bottomleftx = pos1x;
                        upperrightx = pos2x;
                    }
                }
            }
    
        }
       
        public static void setCornerY(Integer pos1y, Integer pos2y) {
            if(pos1y == pos2y) {
                bottomy = pos1y;
                uppery = pos2y;
            }
            if(pos1y != pos2y) {
                if((pos1y >= 0) && (pos2y >= 0)) {
                    if(pos1y > pos2y) {
                        bottomy = pos2y;
                        uppery = pos1y;
                    }
                    if(pos2y > pos1y) {
                        bottomy = pos1y;
                        uppery = pos2y;
                    }
                }
               
                if((pos1y >= 0) && (pos2y < 0)) {
                    if(pos1y > Math.abs(pos2y)) {
                        bottomy = pos2y;
                        uppery = pos1y;
                    }
                    if(pos1y < Math.abs(pos2y)) {
                        bottomy = pos2y;
                        uppery = pos1y;
                    }
                }
               
                if((pos1y < 0) && (pos2y >= 0)) {
                    if(Math.abs(pos1y) > pos2y) {
                        bottomy = pos1y;
                        uppery = pos2y;
                    }
                    if(pos2y > Math.abs(pos1y)) {
                        bottomy = pos1y;
                        uppery = pos2y;
                    }
                }
               
                if((pos1y < 0) && (pos2y < 0)) {
                    if(Math.abs(pos1y) > Math.abs(pos2y)) {
                        bottomy = pos2y;
                        uppery = pos1y;
                    }
                    if(Math.abs(pos2y) > Math.abs(pos1y)) {
                        bottomy = pos1y;
                        uppery = pos2y;
                    }
                }
            }
    
        }
       
        public static void setCornerZ(Integer pos1z, Integer pos2z) {
            if(pos1z == pos2z) {
                bottomfrontz = pos1z;
                upperbackz = pos2z;
            }
            if(pos1z != pos2z) {
                if((pos1z >= 0) && (pos2z >= 0)) {
                    if(pos1z > pos2z) {
                        bottomfrontz = pos2z;
                        upperbackz = pos1z;
                    }
                    if(pos2z > pos1z) {
                        bottomfrontz = pos1z;
                        upperbackz = pos2z;
                    }
                }
               
                if((pos1z >= 0) && (pos2z < 0)) {
                    if(pos1z > Math.abs(pos2z)) {
                        bottomfrontz = pos2z;
                        upperbackz = pos1z;
                    }
                    if(pos1z < Math.abs(pos2z)) {
                        bottomfrontz = pos2z;
                        upperbackz = pos1z;
                    }
                }
               
                if((pos1z < 0) && (pos2z >= 0)) {
                    if(Math.abs(pos1z) > pos2z) {
                        bottomfrontz = pos1z;
                        upperbackz = pos2z;
                    }
                    if(pos2z > Math.abs(pos1z)) {
                        bottomfrontz = pos1z;
                        upperbackz = pos2z;
                    }
                }
               
                if((pos1z < 0) && (pos2z < 0)) {
                    if(Math.abs(pos1z) > Math.abs(pos2z)) {
                        bottomfrontz = pos2z;
                        upperbackz = pos1z;
                    }
                    if(Math.abs(pos2z) > Math.abs(pos1z)) {
                        bottomfrontz = pos1z;
                        upperbackz = pos2z;
                    }
                }
            }
    
        }
       
        @SuppressWarnings("static-access")
        public static void getBlockInfo(Player player, String schematicname, Integer length, Integer width, Integer height, Integer posx, Integer posy, Integer posz) {
           
            player.sendMessage(posx.toString());
            player.sendMessage(posy.toString());
            player.sendMessage(posz.toString());
           
            Integer volume = length*width*height;
            Integer lengthcounter = 0;
            Integer widthcounter = 1;
            Integer heightcounter = 1;
            Integer posxc = posx;
            Integer posyc = posy;
            Integer poszc = posz;
            Integer blockx;
            ArrayList<String> materialsinorder = new ArrayList<String>();
            ArrayList<String> materialsused = new ArrayList<String>();
            ArrayList<blockinfo> bi = new ArrayList<blockinfo>();
           
            for(Integer i = 1; i <= volume; i++) {
                if(lengthcounter < length) {
                    blockx = posxc + lengthcounter;
                    Location blockloc = new Location(Bukkit.getWorld("world"), blockx, posyc + (heightcounter - 1), poszc + (widthcounter - 1));
               
                    if(!materialsused.contains(blockloc.getBlock().getType().toString())) {
                       
                        materialsused.add(blockloc.getBlock().getType().toString());
                       
                        player.sendMessage("Added " + blockloc.getBlock().getType().toString());
                    }
                   
                    player.sendMessage(blockloc.getBlock().getType().toString());
                    blockinfo bl = createBlockInfo(player, schematicname, i, blockloc.getBlock().getType().toString(), lengthcounter, (heightcounter - 1), (widthcounter - 1), blockx, posy + (heightcounter - 1), posz + (widthcounter - 1));
                    String material = bl.getMaterial();
                    materialsinorder.add(material);
                    bi.add(bl);
                    for(blockinfo b2 : bi) {
                        player.sendMessage(b2.getID());
                    }
                    lengthcounter++;
                }
                if((lengthcounter == length) && (widthcounter < width)) {
                    widthcounter++;
                    lengthcounter = 0;
                }
                if((lengthcounter == length) && (widthcounter == width) && (heightcounter < height)) {
                    widthcounter = 1;
                    lengthcounter = 0;
                    heightcounter++;
                }
                if((lengthcounter == length) && (widthcounter == width) && (heightcounter == height)) {
                   
                    player.sendMessage("schematiccreated");
                }
    
            }
    
           
            mobschematic.getMobSchematic(schematicname).setBlockInfo(bi);
            mobschematic.getMobSchematic(schematicname).setMaterialsUsed(materialsused);
            mobschematic.getMobSchematic(schematicname).setMaterialsInOrder(materialsinorder);
           
            for(blockinfo b2 : bi) {
                player.sendMessage(b2.getID());
            }
        }
    
        public static blockinfo createBlockInfo(Player player, String schematicname, Integer i, String material, Integer relativex, Integer relativey, Integer relativez, Integer x, Integer y, Integer z) {
            blockinfo b = new blockinfo(schematicname + "." + i, material, relativex, relativey, relativez, x, y, z);
            return b;
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(!(sender instanceof Player)) {
                sender.sendMessage("Must be a player.");
            }
            if(sender instanceof Player) {
                if(label.equalsIgnoreCase("createschematic")) {
                    mobschematic.createSchematic(args[0]);
                    createSchematicLength(args[0], x1, x2);
                    createSchematicWidth(args[0], z1, z2);
                    createSchematicHeight(args[0], y1, y2);
                    setCornerX(x1, x2);
                    setCornerY(y1, y2);
                    setCornerZ(z1, z2);
                    mobschematic.getMobSchematic(args[0]).setSchematicX(bottomleftx);
                    mobschematic.getMobSchematic(args[0]).setSchematicY(bottomy);
                    mobschematic.getMobSchematic(args[0]).setSchematicZ(bottomfrontz);
                    getBlockInfo(((Player) sender).getPlayer(), args[0], length, width, height, bottomleftx, bottomy, bottomfrontz);
                    sender.sendMessage("Createdschematic!");
                }
            }
            return false;
        }
    
    And here is my screenshot showing that the arraylist is overwritting itself -
    [​IMG]
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    The_Roycester

    I removed the static on some of my methods however it is still overwriting itself. Here is my code now:
    Code:
    package me.akroyce25.mobshematics.read_write;
    
    import java.util.ArrayList;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import me.akroyce25.mobshematics.blockinfo;
    import me.akroyce25.mobshematics.mobschematic;
    
    public class write implements Listener, CommandExecutor{
    
        public static Integer x1;
        public static Integer y1;
        public static Integer z1;
        public static Integer x2;
        public static Integer y2;
        public static Integer z2;
       
        public static Integer length;
        public static Integer width;
        public static Integer height;
       
        public static Integer bottomleftx;
        public static Integer bottomy;
        public static Integer bottomfrontz;
       
        public static Integer upperrightx;
        public static Integer uppery;
        public static Integer upperbackz;
       
        ArrayList<blockinfo> bi = new ArrayList<blockinfo>();
       
        @EventHandler
        public void onClick(PlayerInteractEvent e) {
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                x1 = e.getClickedBlock().getX();
                y1 = e.getClickedBlock().getY();
                z1 = e.getClickedBlock().getZ();
    
            }
            if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
                x2 = e.getClickedBlock().getX();
                y2 = e.getClickedBlock().getY();
                z2 = e.getClickedBlock().getZ();
    
            }
        }
       
        public void createSchematicLength(String schematicname, Integer pos1x, Integer pos2x) {
            if(pos1x == pos2x) {
                length = 1;
            }
            if(pos1x != pos2x) {
                if((pos1x >= 0) && (pos2x >= 0)) {
                    if(pos1x > pos2x) {
                        length = (pos1x - pos2x) + 1;
                    }
                    if(pos2x > pos1x) {
                        length = (pos2x - pos1x) + 1;
                    }
                }
               
                if((pos1x >= 0) && (pos2x < 0)) {
                    if(pos1x > Math.abs(pos2x)) {
                        length = (pos1x - Math.abs(pos2x)) + 1;
                    }
                    if(pos1x < Math.abs(pos2x)) {
                        length = (Math.abs(pos2x) - pos1x) + 1;
                    }
                }
               
                if((pos1x < 0) && (pos2x >= 0)) {
                    if(Math.abs(pos1x) > pos2x) {
                        length = (Math.abs(pos1x) - pos2x) + 1;
                    }
                    if(pos2x > Math.abs(pos1x)) {
                        length = (pos2x - Math.abs(pos1x)) + 1;
                    }
                }
               
                if((pos1x < 0) && (pos2x < 0)) {
                    if(Math.abs(pos1x) > Math.abs(pos2x)) {
                         length = (Math.abs(pos1x) - Math.abs(pos2x)) + 1;
                    }
                    if(Math.abs(pos2x) > Math.abs(pos1x)) {
                        length = (Math.abs(pos2x) - Math.abs(pos1x)) + 1;
                    }
                }
            }
           
            mobschematic.getMobSchematic(schematicname).setSchematicLength(length);;
        }
    
        public void createSchematicWidth(String schematicname, Integer pos1z, Integer pos2z) {
            if(pos1z == pos2z) {
                width = 1;
            }
            if(pos1z != pos2z) {
                if((pos1z >= 0) && (pos2z >= 0)) {
                    if(pos1z > pos2z) {
                        width = (pos1z - pos2z) + 1;
                    }
                    if(pos2z > pos1z) {
                        width = (pos2z - pos1z) + 1;
                    }
                }
               
                if((pos1z >= 0) && (pos2z < 0)) {
                    if(pos1z > Math.abs(pos2z)) {
                        width = (pos1z - Math.abs(pos2z)) + 1;
                    }
                    if(pos1z < Math.abs(pos2z)) {
                        width = (Math.abs(pos2z) - pos1z) + 1;
                    }
                }
               
                if((pos1z < 0) && (pos2z >= 0)) {
                    if(Math.abs(pos1z) > pos2z) {
                        width = (Math.abs(pos1z) - pos2z) + 1;
                    }
                    if(pos2z > Math.abs(pos1z)) {
                        width = (pos2z - Math.abs(pos1z)) + 1;
                    }
                }
               
                if((pos1z < 0) && (pos2z < 0)) {
                    if(Math.abs(pos1z) > Math.abs(pos2z)) {
                         width = (Math.abs(pos1z) - Math.abs(pos2z)) + 1;
                    }
                    if(Math.abs(pos2z) > Math.abs(pos1z)) {
                        width = (Math.abs(pos2z) - Math.abs(pos1z)) + 1;
                    }
                }
            }
           
            mobschematic.getMobSchematic(schematicname).setSchematicWidth(width);;
        }
    
        public void createSchematicHeight(String schematicname, Integer pos1y, Integer pos2y) {
            if(pos1y == pos2y) {
                height = 1;
            }
            if(pos1y != pos2y) {
                if((pos1y >= 0) && (pos2y >= 0)) {
                    if(pos1y > pos2y) {
                        height = (pos1y - pos2y) + 1;
                    }
                    if(pos2y > pos1y) {
                        height = (pos2y - pos1y) + 1;
                    }
                }
               
                if((pos1y >= 0) && (pos2y < 0)) {
                    if(pos1y > Math.abs(pos2y)) {
                        height = (pos1y - Math.abs(pos2y)) + 1;
                    }
                    if(pos1y < Math.abs(pos2y)) {
                        height = (Math.abs(pos2y) - pos1y) + 1;
                    }
                }
               
                if((pos1y < 0) && (pos2y >= 0)) {
                    if(Math.abs(pos1y) > pos2y) {
                        height = (Math.abs(pos1y) - pos2y) + 1;
                    }
                    if(pos2y > Math.abs(pos1y)) {
                        height = (pos2y - Math.abs(pos1y)) + 1;
                    }
                }
               
                if((pos1y < 0) && (pos2y < 0)) {
                    if(Math.abs(pos1y) > Math.abs(pos2y)) {
                         height = (Math.abs(pos1y) - Math.abs(pos2y)) + 1;
                    }
                    if(Math.abs(pos2y) > Math.abs(pos1y)) {
                        height = (Math.abs(pos2y) - Math.abs(pos1y)) + 1;
                    }
                }
            }
           
            mobschematic.getMobSchematic(schematicname).setSchematicHeight(height);;
        }
       
        public void setCornerX(Integer pos1x, Integer pos2x) {
            if(pos1x == pos2x) {
                bottomleftx = pos1x;
                upperrightx = pos2x;
            }
            if(pos1x != pos2x) {
                if((pos1x >= 0) && (pos2x >= 0)) {
                    if(pos1x > pos2x) {
                        bottomleftx = pos2x;
                        upperrightx = pos1x;
                    }
                    if(pos2x > pos1x) {
                        bottomleftx = pos1x;
                        upperrightx = pos2x;
                    }
                }
               
                if((pos1x >= 0) && (pos2x < 0)) {
                    if(pos1x > Math.abs(pos2x)) {
                        bottomleftx = pos2x;
                        upperrightx = pos1x;
                    }
                    if(pos1x < Math.abs(pos2x)) {
                        bottomleftx = pos2x;
                        upperrightx = pos1x;
                    }
                }
               
                if((pos1x < 0) && (pos2x >= 0)) {
                    if(Math.abs(pos1x) > pos2x) {
                        bottomleftx = pos1x;
                        upperrightx = pos2x;
                    }
                    if(pos2x > Math.abs(pos1x)) {
                        bottomleftx = pos1x;
                        upperrightx = pos2x;
                    }
                }
               
                if((pos1x < 0) && (pos2x < 0)) {
                    if(Math.abs(pos1x) > Math.abs(pos2x)) {
                        bottomleftx = pos2x;
                        upperrightx = pos1x;
                    }
                    if(Math.abs(pos2x) > Math.abs(pos1x)) {
                        bottomleftx = pos1x;
                        upperrightx = pos2x;
                    }
                }
            }
    
        }
       
        public void setCornerY(Integer pos1y, Integer pos2y) {
            if(pos1y == pos2y) {
                bottomy = pos1y;
                uppery = pos2y;
            }
            if(pos1y != pos2y) {
                if((pos1y >= 0) && (pos2y >= 0)) {
                    if(pos1y > pos2y) {
                        bottomy = pos2y;
                        uppery = pos1y;
                    }
                    if(pos2y > pos1y) {
                        bottomy = pos1y;
                        uppery = pos2y;
                    }
                }
               
                if((pos1y >= 0) && (pos2y < 0)) {
                    if(pos1y > Math.abs(pos2y)) {
                        bottomy = pos2y;
                        uppery = pos1y;
                    }
                    if(pos1y < Math.abs(pos2y)) {
                        bottomy = pos2y;
                        uppery = pos1y;
                    }
                }
               
                if((pos1y < 0) && (pos2y >= 0)) {
                    if(Math.abs(pos1y) > pos2y) {
                        bottomy = pos1y;
                        uppery = pos2y;
                    }
                    if(pos2y > Math.abs(pos1y)) {
                        bottomy = pos1y;
                        uppery = pos2y;
                    }
                }
               
                if((pos1y < 0) && (pos2y < 0)) {
                    if(Math.abs(pos1y) > Math.abs(pos2y)) {
                        bottomy = pos2y;
                        uppery = pos1y;
                    }
                    if(Math.abs(pos2y) > Math.abs(pos1y)) {
                        bottomy = pos1y;
                        uppery = pos2y;
                    }
                }
            }
    
        }
       
        public void setCornerZ(Integer pos1z, Integer pos2z) {
            if(pos1z == pos2z) {
                bottomfrontz = pos1z;
                upperbackz = pos2z;
            }
            if(pos1z != pos2z) {
                if((pos1z >= 0) && (pos2z >= 0)) {
                    if(pos1z > pos2z) {
                        bottomfrontz = pos2z;
                        upperbackz = pos1z;
                    }
                    if(pos2z > pos1z) {
                        bottomfrontz = pos1z;
                        upperbackz = pos2z;
                    }
                }
               
                if((pos1z >= 0) && (pos2z < 0)) {
                    if(pos1z > Math.abs(pos2z)) {
                        bottomfrontz = pos2z;
                        upperbackz = pos1z;
                    }
                    if(pos1z < Math.abs(pos2z)) {
                        bottomfrontz = pos2z;
                        upperbackz = pos1z;
                    }
                }
               
                if((pos1z < 0) && (pos2z >= 0)) {
                    if(Math.abs(pos1z) > pos2z) {
                        bottomfrontz = pos1z;
                        upperbackz = pos2z;
                    }
                    if(pos2z > Math.abs(pos1z)) {
                        bottomfrontz = pos1z;
                        upperbackz = pos2z;
                    }
                }
               
                if((pos1z < 0) && (pos2z < 0)) {
                    if(Math.abs(pos1z) > Math.abs(pos2z)) {
                        bottomfrontz = pos2z;
                        upperbackz = pos1z;
                    }
                    if(Math.abs(pos2z) > Math.abs(pos1z)) {
                        bottomfrontz = pos1z;
                        upperbackz = pos2z;
                    }
                }
            }
    
        }
       
        public void getBlockInfo(Player player, String schematicname, Integer length, Integer width, Integer height, Integer posx, Integer posy, Integer posz) {
           
            player.sendMessage(posx.toString());
            player.sendMessage(posy.toString());
            player.sendMessage(posz.toString());
           
            Integer volume = length*width*height;
            Integer lengthcounter = 0;
            Integer widthcounter = 1;
            Integer heightcounter = 1;
            Integer posxc = posx;
            Integer posyc = posy;
            Integer poszc = posz;
            Integer blockx;
            ArrayList<String> materialsinorder = new ArrayList<String>();
            ArrayList<String> materialsused = new ArrayList<String>();
           
            for(Integer i = 1; i <= volume; i++) {
                if(lengthcounter < length) {
                    blockx = posxc + lengthcounter;
                    Location blockloc = new Location(Bukkit.getWorld("world"), blockx, posyc + (heightcounter - 1), poszc + (widthcounter - 1));
               
                    if(!materialsused.contains(blockloc.getBlock().getType().toString())) {
                       
                        materialsused.add(blockloc.getBlock().getType().toString());
                       
                        player.sendMessage("Added " + blockloc.getBlock().getType().toString());
                    }
                   
                    player.sendMessage(blockloc.getBlock().getType().toString());
                    createBlockInfo(player, schematicname, i, blockloc.getBlock().getType().toString(), lengthcounter, (heightcounter - 1), (widthcounter - 1), blockx, posy + (heightcounter - 1), posz + (widthcounter - 1));
                    blockinfo bl = bi.get(i - 1);
                    String material = bl.getMaterial();
                    materialsinorder.add(material);
                    for(blockinfo b2 : bi) {
                        player.sendMessage(b2.getID());
                    }
                    lengthcounter++;
                }
                if((lengthcounter == length) && (widthcounter < width)) {
                    widthcounter++;
                    lengthcounter = 0;
                }
                if((lengthcounter == length) && (widthcounter == width) && (heightcounter < height)) {
                    widthcounter = 1;
                    lengthcounter = 0;
                    heightcounter++;
                }
                if((lengthcounter == length) && (widthcounter == width) && (heightcounter == height)) {
                   
                    player.sendMessage("schematiccreated");
                }
    
            }
    
           
            mobschematic.getMobSchematic(schematicname).setBlockInfo(bi);
            mobschematic.getMobSchematic(schematicname).setMaterialsUsed(materialsused);
            mobschematic.getMobSchematic(schematicname).setMaterialsInOrder(materialsinorder);
           
            for(blockinfo b2 : bi) {
                player.sendMessage(b2.getID());
            }
        }
    
        public void createBlockInfo(Player player, String schematicname, Integer i, String material, Integer relativex, Integer relativey, Integer relativez, Integer x, Integer y, Integer z) {
            blockinfo b = new blockinfo(schematicname + "." + i, material, relativex, relativey, relativez, x, y, z);
            bi.add(b);
            /*blockinfo.createBlockID(schematicname + "." + i);
            blockinfo b = blockinfo.getBlockID(schematicname + "." + i);
            b.setMaterial(material);
            b.setRelativeX(relativex);
            b.setRelativeY(relativey);
            b.setRelativeZ(relativez);
            b.setX(x);
            b.setY(y);
            b.setZ(z);*/
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(!(sender instanceof Player)) {
                sender.sendMessage("Must be a player.");
            }
            if(sender instanceof Player) {
                if(label.equalsIgnoreCase("createschematic")) {
                    mobschematic.createSchematic(args[0]);
                    createSchematicLength(args[0], x1, x2);
                    createSchematicWidth(args[0], z1, z2);
                    createSchematicHeight(args[0], y1, y2);
                    setCornerX(x1, x2);
                    setCornerY(y1, y2);
                    setCornerZ(z1, z2);
                    mobschematic.getMobSchematic(args[0]).setSchematicX(bottomleftx);
                    mobschematic.getMobSchematic(args[0]).setSchematicY(bottomy);
                    mobschematic.getMobSchematic(args[0]).setSchematicZ(bottomfrontz);
                    getBlockInfo(((Player) sender).getPlayer(), args[0], length, width, height, bottomleftx, bottomy, bottomfrontz);
                    sender.sendMessage("Createdschematic!");
                }
            }
            return false;
        }
    
    Here is my blockinfo object class:
    Code:
    package me.akroyce25.mobshematics;
    
    import java.util.ArrayList;
    
    public class blockinfo {
    
        static String blockid;
        static String material;
        static Integer x;
        static Integer y;
        static Integer z;
        static Integer relativex;
        static Integer relativey;
        static Integer relativez;
       
        public blockinfo (String BlockID, String material, Integer x, Integer y, Integer z, Integer relativex, Integer relativey, Integer relativez) {
            blockinfo.blockid = BlockID;
            blockinfo.material = material;
            blockinfo.x = x;
            blockinfo.y = y;
            blockinfo.z = z;
            blockinfo.relativex = relativex;
            blockinfo.relativey = relativey;
            blockinfo.relativez = relativez;
        }
       
        static ArrayList<blockinfo> schematicblockinfo = new ArrayList<blockinfo>();
       
        //NOT SURE ABOUT THIS METHOD.
        public static blockinfo getBlockID(String blockid) {
            for (blockinfo b : schematicblockinfo) {
                if (b.getID() == blockid) {
                    return b;
                }
            }
            return null;
           
        }
    
        public static void createBlockID(String blockid) {
            blockinfo b = new blockinfo(blockid, "Stone", 0, 0, 0, 0, 0, 0);
                schematicblockinfo.add(b);
        }
       
       
        public String getID() {
            return blockid;
        }
       
        public String getMaterial() {
            return material;
        }
       
        public Integer getX() {
            return x;
        }
       
        public Integer getY() {
            return y;
        }
       
        public Integer getZ() {
            return z;
        }
       
        public Integer getRelativeX() {
            return relativex;
        }
       
        public Integer getRelativeY() {
            return relativey;
        }
       
        public Integer getRelativeZ() {
            return relativez;
        }
       
        public void setMaterial(String material) {
            blockinfo.material = material;
        }
       
        public void setX(Integer x) {
            blockinfo.x = x;
        }
       
        public void setY(Integer y) {
            blockinfo.y = y;
        }
       
        public void setZ(Integer z) {
            blockinfo.z = z;
        }
       
        public void setRelativeX(Integer x) {
            blockinfo.relativex = x;
        }
       
        public void setRelativeY(Integer y) {
            blockinfo.relativey = y;
        }
       
        public void setRelativeZ(Integer z) {
            blockinfo.relativez = z;
        }
       
        static void addBlockInfo(blockinfo b) {
            schematicblockinfo.add(b);
        }
    }
    
    If you need anything else let me know.
     
  4. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page