Did I do Something Wrong? - Schematics and Objects

Discussion in 'Plugin Development' started by BajanAmerican, Dec 4, 2013.

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

    BajanAmerican

    If anyone could help, that would be great. I am making a custom "plots" plugin for my server and I am getting nothing from my code. Zero console output and everything. First, my object class:
    Code:java
    1. public class Plot {
    2. private int width;
    3. private int length;
    4. private int height;
    5. private String owner;
    6. private Location centerpoint;
    7. private boolean occupied;
    8.  
    9. public Plot(Location centerpoint, String owner, int width, int length, int height){
    10. this.width = width;
    11. this.length = length;
    12. this.height = height;
    13. this.owner = owner;
    14. this.centerpoint = centerpoint;
    15. }
    16.  
    17. public int getWidth(){
    18. return width;
    19. }
    20.  
    21. public int getLength(){
    22. return length;
    23. }
    24.  
    25. public int getHeight(){
    26. return height;
    27. }
    28.  
    29. public String getOwner(){
    30. return owner;
    31. }
    32.  
    33. public void setOwner(String name){
    34. this.owner = name;
    35. }
    36.  
    37. public Location getCenter(){
    38. return centerpoint;
    39. }
    40.  
    41. public void setCenter(Location name){
    42. this.centerpoint = name;
    43. }
    44.  
    45. public boolean isOccupied(){
    46. return occupied;
    47. }
    48.  
    49. public void setOccupied(boolean b){
    50. this.occupied = b;
    51. }
    52.  
    53.  
    54. }


    Pretty simple, basic object programming. My Manager:

    Code:java
    1. public class PlotManager{
    2.  
    3. List<Plot> plots;
    4.  
    5. public PlotManager(){
    6. this.plots = new ArrayList<Plot>();
    7. }
    8.  
    9. public List<Plot> getPlots(){
    10. return plots;
    11. }
    12. }


    The Methods in my main class (might be where the problem is but I dont know, there is no output from the console):

    Code:java
    1. public static void spawnBuilding(String fileLoc, Plot plot){
    2. File schem = new File(fileLoc);
    3. try {
    4. SchematicUtils.pasteSchematic(Bukkit.getWorld("plots"), new Location(Bukkit.getWorld("plots"), plot.getCenter().getBlockX(), plot.getCenter().getBlockY(), plot.getCenter().getBlockZ()), SchematicUtils.loadSchematic(schem));
    5. } catch (IOException e) {
    6. e.printStackTrace();
    7. }
    8. }
    9.  
    10. public static void generatePlot(Plot plot, Player player, Location loc){
    11. plot = new Plot(loc, player.getName(), 30, 256, 30);
    12. int xlength = plot.getWidth();
    13. int ylength = plot.getHeight();
    14. int zlength = plot.getLength();
    15.  
    16. int x_start = plot.getCenter().getBlockX();
    17. int y_start = plot.getCenter().getBlockY();
    18. int z_start = plot.getCenter().getBlockZ();
    19.  
    20.  
    21. int x_length = x_start + xlength;
    22. int y_length = y_start + ylength;
    23. int z_length = z_start + zlength;
    24.  
    25. for (int x_operate = x_start; x_operate <= x_length; x_operate++) {
    26. for (int y_operate = y_start; y_operate <= y_length; y_operate++) {
    27. for (int z_operate = z_start; z_operate <= z_length; z_operate++) {
    28. loc = new Location(Bukkit.getWorld("plots"), x_operate, y_operate, z_operate);
    29. spawnBuilding("plots.schematic", plot);
    30. plot.setOccupied(true);
    31. }
    32. }
    33. }
    34. }
    35.  
    36. public static boolean previousPlot(Plot plot){
    37. if(plot.isOccupied()){
    38. return true;
    39. }
    40. return false;
    41. }


    And finally, the commands:

    Code:java
    1. if(commandLabel.equalsIgnoreCase("plot") || commandLabel.equalsIgnoreCase("plots")){
    2. if(sender instanceof Player){
    3. Player player = (Player) sender;
    4. if(args.length == 0){
    5. player.sendMessage(ChatColor.DARK_PURPLE + "§l<><><>< " + ChatColor.GOLD + "§lPLOTS " + ChatColor.DARK_PURPLE + "§l><><><>\n" + ChatColor.YELLOW + "\nOwn Plot: " + ChatColor.BLUE + plotVal(player.getName()));
    6. } else if(args.length == 1){
    7. if(args[0].equalsIgnoreCase("add")){
    8. if(hasPlot.contains(player.getName())){
    9. player.sendMessage(ChatColor.AQUA + "[TheParkMC] " + ChatColor.DARK_RED + "You Already Own A Plot!");
    10. return true;
    11. } else {
    12. if(manager == null){
    13. manager = new PlotManager();
    14. }
    15. for(Plot pl : manager.getPlots()){
    16. if(previousPlot(pl)){
    17. Plot newPlot = new Plot(new Location(Bukkit.getWorld("plots"), pl.getCenter().getBlockX() + 33, pl.getCenter().getBlockY(), pl.getCenter().getBlockZ()), player.getName(), 30, 256, 30);
    18. generatePlot(newPlot, player, newPlot.getCenter());
    19. stringGivePlots(player.getName());
    20. player.teleport(newPlot.getCenter());
    21. player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "WELCOME TO YOUR OWN PERSONAL HUB!");
    22. player.setGameMode(GameMode.CREATIVE);
    23. player.getInventory().clear();
    24. } else if(!previousPlot(pl)){
    25. Plot newPlot = new Plot(new Location(Bukkit.getWorld("plots"), 65.5, 61, 11.5), player.getName(), 30, 256, 30);
    26. generatePlot(newPlot, player, newPlot.getCenter());
    27. stringGivePlots(player.getName());
    28. player.teleport(newPlot.getCenter());
    29. player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "WELCOME TO YOUR OWN PERSONAL HUB!");
    30. player.setGameMode(GameMode.CREATIVE);
    31. player.getInventory().clear();
    32. }
    33. }
    34. }
    35. } else if(args[0].equalsIgnoreCase("home")){
    36. for(Plot pl : manager.getPlots()){
    37. if(pl.getOwner().contains(player.getName()));
    38. player.teleport(pl.getCenter());
    39. player.getInventory().clear();
    40. player.setGameMode(GameMode.CREATIVE);
    41. }
    42. }
    43. }
    44. } else {
    45. sender.sendMessage("You Can Only Use This Command As A Player!");
    46. }
    47. }


    And yes, in my main class I do have the PlotManager Instance:

    Code:java
    1. PlotManager manager;


    The command /plot is fine; however, the command /plot add is not. Am I doing something wrong here? The schematic works because I tested it with another plugin and it is the same method. I got the method from this Thread in case any one is wondering: http://forums.bukkit.org/threads/pasting-loading-schematics.87129/

    Thank you for your help! :)
     
  2. Offline

    zeeveener

    Right after "if(args.length == 1)" add a test output. Example: "System.out.println("TEST");" If that doesn't get printed, the error occurs somewhere before the if. Otherwise, the error is within the if. Just move that test print around until you narrow down the field as to where your error occurs.

    Chances are, you have an if statement wrong and don't have any chat output before returning.
     
  3. Offline

    Rocoty

    The for-statement probably doesn't get executed, as the list is empty. I don't see anywhere in your code that you add plots to the list...
     
  4. Offline

    BajanAmerican

    zeeveener Rocoty
    I took both of your advises, I checked for the List being null, and I think it is. I added a new method in my PlotManager class to check if the List is null:
    Code:java
    1. public void addDefaultPlot(){
    2. if(plots == null){
    3. Plot plot = new Plot(new Location(Bukkit.getWorld("plots"), 65.5, 61, 11.5), "sdfag3asg", 30, 256, 30);
    4. plots.add(plot);
    5. }
    6. }


    Although, I do not know if that works because I am also getting nothing besides the phrase "SHOULD SHOW UP" when I put the test logger in the command.

    Code:java
    1. if(manager == null){
    2. manager = new PlotManager();
    3. }
    4. logger.info("SHOULD SHOW UP");
    5. if(manager.getPlots() == null){
    6. logger.info("HERE");
    7. manager.addDefaultPlot();
    8. logger.info("AFTER");
    9. }


    I am just checking if the list is null, and nothing happens after that. Is something wrong here? Thanks! :)
     
  5. Offline

    zeeveener

    A better solution would be to check if
    Code:java
    1. manager.getPlots().isEmpty();
     
  6. Offline

    Rocoty

    Why don't you try actually adding stuff to the list?............
     
Thread Status:
Not open for further replies.

Share This Page