Schematics Queue

Discussion in 'Plugin Development' started by Fl1pzta, Jul 16, 2013.

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

    Fl1pzta

    For some reason the schematics aren't rotating. I think I may have seen one rotated. Sometimes they don't paste even remotely relative to the origin either. Although I must say it has yet to paste outside of kingdom's dimensions.

    Code:java
    1. public class BuildingQueue {
    2. private final Main main;
    3. private final int clock;
    4. private List<Queue> queues;
    5. private BukkitTask task;
    6. public BuildingQueue(Main main) {
    7. //Called from main class to start the queue
    8. this.main = main;
    9. this.queues = new ArrayList<Queue>();
    10. File file = new File(main.getDataFolder() + "/config.yml");
    11. this.clock = Config.getInt(file, "queue-clock")*1200; //In minutes
    12. start_();
    13. }
    14. void start_(){
    15. task=main.getServer().getScheduler().runTaskTimerAsynchronously(main, new Runnable() {
    16. public void run() {
    17. //If a queue is present.
    18. if(queues.size()>0){
    19. Queue nextQueue = queues.get(0);
    20. try {
    21. loadArea(nextQueue.getBName(),nextQueue.getPName(),nextQueue.getLoc(),nextQueue.getDirection());
    22. } catch (MaxChangedBlocksException e) {
    23. // TODO Auto-generated catch block
    24. e.printStackTrace();
    25. } catch (DataException e) {
    26. // TODO Auto-generated catch block
    27. e.printStackTrace();
    28. } catch (IOException e) {
    29. // TODO Auto-generated catch block
    30. e.printStackTrace();
    31. }
    32. //After area is loaded remove from queue list.
    33. queues.remove(0);
    34. }
    35.  
    36. }}, 0L, clock);
    37. }
    38. @SuppressWarnings("unused")
    39. private void loadArea(String name, String pname,Location loc,BlockFace direction)
    40. throws DataException, IOException, MaxChangedBlocksException
    41. {
    42. // convert bukkit loc to wedit vector
    43. Vector origin = BukkitUtil.toVector(loc);
    44. File file = new File(main.we.getDataFolder()+"/schematics/"+name+".schematic");
    45. EditSession es = new EditSession(new BukkitWorld(main.getWorld()), Integer.MAX_VALUE);
    46. // load schematic
    47. CuboidClipboard cc = SchematicFormat.MCEDIT.load(file);
    48. int height = cc.getHeight();
    49. int x1,x2,y1,y2,z1,z2;
    50. //Check all sides again,store dimensions of building
    51. y1 = (int)loc.getY();
    52. y2 =(int)loc.getY()+height;
    53. x1 = (int)loc.getX();
    54. z1 = (int)loc.getZ();
    55. //rotate clipboard if when added to queue player was facing specific direction
    56. if(direction ==BlockFace.NORTH){
    57. x2 = x1-cc.getWidth();
    58. z2 = z1+cc.getLength();
    59. }
    60. if(direction ==BlockFace.SOUTH){
    61. cc.rotate2D(180);
    62. x2 = x1+cc.getWidth();
    63. z2 = z1-cc.getLength();
    64. }
    65. if(direction ==BlockFace.EAST){
    66. cc.rotate2D(90);
    67. x2=x1-cc.getLength();
    68. z2=z1-cc.getWidth();
    69. }else{
    70. cc.rotate2D(270);
    71. x2=x1+cc.getLength();
    72. z2=z1+cc.getWidth();
    73. }
    74. //paste clipboard relative to origin(should be right in front of where the player created the queue)
    75. cc.paste(es, origin, true, true);
    76. Player player = Bukkit.getPlayer(pname);
    77. if(player.isOnline()){
    78. player.sendMessage(ChatColor.GREEN + "Your " + name + " building has been placed.");
    79. }
    80. }
    81. //Add queue to queue list unless player already has queue
    82. public boolean addQueue(Queue queue){
    83. boolean bool = true;
    84. for(Queue newQueue:queues){
    85. if(newQueue.getPName().equals(queue.getPName())){
    86. bool = false;
    87. break;
    88. }
    89. }
    90. if(bool == true){
    91. queues.add(queue);
    92. }
    93. return bool;
    94. }
    95. }


    Code:java
    1. public class BuilderAxeHandler {
    2. //Handles woodenaxe with custom display name of Builder's Axe
    3. public static final BlockFace[] axis = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
    4. private final Main main;
    5. public BuilderAxeHandler(Main main, PlayerInteractEvent e){
    6. Player player = e.getPlayer();
    7. this.main = main;
    8. Member user = main.getMember(player.getName());
    9. //world is flat, schematics can only be pasted from ground level(sometimes the paste a few blocks //up, no idea why.)
    10. if((int)player.getLocation().getY()!=21){
    11. player.sendMessage("not at ground level");
    12. return;
    13. }
    14. //Just a few checks for my plugin
    15. if(user==null){
    16. player.sendMessage("Your user file doesn't exist");
    17. return;
    18. }
    19. if(!(user.getRank().equals("king"))){
    20. player.sendMessage("not a king");
    21. return;
    22. }
    23. Kingdom kingdom = main.getKingdom(player.getLocation());
    24. if(kingdom==null||(!(kingdom==user.getKingdom()))){
    25. player.sendMessage("Kingdom was not found.");
    26. return;
    27. }
    28. player.sendMessage("passed the checks");
    29. //ItemMenu API IGNORE
    30. //Get Selection IGNORE
    31. //Check if they can build this
    32. try {
    33. if(loadArea("dirthouse",player,kingdom)){
    34. player.sendMessage(ChatColor.GREEN + "Building has been added to the queue.");
    35. }else{
    36. player.sendMessage("Building is out of bounds of kingdom area.");
    37. }
    38. } catch (MaxChangedBlocksException | DataException | IOException e1) {
    39. // TODO Auto-generated catch block
    40. e1.printStackTrace();
    41. }
    42. }
    43. public BlockFace getDirection(float yaw){
    44. return axis[Math.round(yaw / 90f) & 0x3];
    45. }
    46. @SuppressWarnings("unused")
    47. //Looks duplicate but is necessary for checking if dimensions exceed another cuboid(Kingdom)
    48. public boolean loadArea(String name, Player player, Kingdom kingdom)
    49. throws DataException, IOException, MaxChangedBlocksException
    50. {
    51. Location loc = player.getLocation();
    52. loc.setX((int)loc.getX());
    53. loc.setY(22);
    54. loc.setZ((int)loc.getZ());
    55. BlockFace direction =getDirection(loc.getYaw());
    56. player.sendMessage(direction+"");
    57. Vector origin = BukkitUtil.toVector(loc);
    58. File file = new File(main.we.getDataFolder()+"/schematics/"+name+".schematic");
    59. EditSession es = new EditSession(new BukkitWorld(main.getWorld()), Integer.MAX_VALUE);
    60. CuboidClipboard cc = SchematicFormat.MCEDIT.load(file);
    61. cc.setOrigin(origin);
    62. int height = cc.getHeight();
    63. int x1,x2,y1,y2,z1,z2;
    64.  
    65. y1 = 22;
    66. y2 =y1+height;
    67. x1 = (int)loc.getX();
    68. z1 = (int)loc.getZ();
    69. if(direction ==BlockFace.NORTH){
    70. x2 = x1-cc.getWidth();
    71. z2 = z1+cc.getLength();
    72. }
    73. if(direction ==BlockFace.SOUTH){
    74. cc.rotate2D(180);
    75. x2 = x1+cc.getWidth();
    76. z2 = z1-cc.getLength();
    77. }
    78. if(direction ==BlockFace.EAST){
    79. cc.rotate2D(90);
    80. x2=x1-cc.getLength();
    81. z2=z1-cc.getWidth();
    82. }else{
    83. cc.rotate2D(270);
    84. x2=x1+cc.getLength();
    85. z2=z1+cc.getWidth();
    86. }
    87. int minx = Math.min(x1, x2);
    88. int maxx = Math.max(x1, x2);
    89. int minz = Math.min(z1, z2);
    90. int maxz = Math.max(z1, z2);
    91.  
    92. Kingdom getkingdom = main.getKingdom(new Location(main.getWorld(),minx,22,minz));
    93. if(getkingdom!=kingdom){
    94. return false;
    95. }
    96. getkingdom = main.getKingdom(new Location(main.getWorld(),minx,22,maxz));
    97. if(getkingdom!=kingdom){
    98. return false;
    99. }
    100. getkingdom = main.getKingdom(new Location(main.getWorld(),maxx,22,minz));
    101. if(getkingdom!=kingdom){
    102. return false;
    103. }
    104. getkingdom = main.getKingdom(new Location(main.getWorld(),maxx,22,maxz));
    105. if(getkingdom!=kingdom){
    106. return false;
    107. }
    108. Queue newQueue = new Queue(name, player.getName(), loc, direction);
    109. if(!main.queue.addQueue(newQueue)){
    110. player.sendMessage(ChatColor.RED + "Queue could not be added.");
    111. return false;
    112. }
    113. return true;
    114.  
    115. }
    116. }

    Code:java
    1. public class Queue {
    2. private final String bname,pname;
    3. private final Location loc;
    4. private final BlockFace direction;
    5. public Queue(String buildingname,String playername,Location location,BlockFace direction){
    6. this.bname = buildingname;
    7. this.pname = playername;
    8. this.loc = location;
    9. this.direction = direction;
    10. }
    11. public Location getLoc(){
    12. return loc;
    13. }
    14. public String getBName(){
    15. return bname;
    16. }
    17. public String getPName(){
    18. return pname;
    19. }
    20. public BlockFace getDirection(){
    21. return direction;
    22. }
    23. }
    24.  


    So, any idea why the schematics aren't rotating, or pasting relative to the origin(where the player first defined in BuilderAxeHandler??
     
Thread Status:
Not open for further replies.

Share This Page