/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/TemplateCommand.java
ViewVC logotype

Diff of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/TemplateCommand.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1746 by torben, Sun Mar 18 11:14:51 2012 UTC revision 1750 by torben, Sun Mar 18 14:36:49 2012 UTC
# Line 3  package dk.thoerup.bukkit.hoeruputils; Line 3  package dk.thoerup.bukkit.hoeruputils;
3  import java.io.BufferedReader;  import java.io.BufferedReader;
4  import java.io.File;  import java.io.File;
5  import java.io.FileInputStream;  import java.io.FileInputStream;
 import java.io.IOException;  
6  import java.io.InputStreamReader;  import java.io.InputStreamReader;
7    
8  import org.bukkit.ChatColor;  import org.bukkit.ChatColor;
# Line 18  import org.bukkit.plugin.Plugin; Line 17  import org.bukkit.plugin.Plugin;
17  public class TemplateCommand implements CommandExecutor {  public class TemplateCommand implements CommandExecutor {
18    
19    
20          /*class Pair {          class Pair {
21                  public int id;                  public int id;
22                  public int subId;                  public int subId;
23    
# Line 27  public class TemplateCommand implements Line 26  public class TemplateCommand implements
26                          subId = s;                          subId = s;
27                  }                  }
28    
29          }*/          }
30    
31          Plugin plugin;          Plugin plugin;
32    
# Line 60  public class TemplateCommand implements Line 59  public class TemplateCommand implements
59                          return true;                          return true;
60                  }                        }      
61    
62                  int[][][] template;                  Pair[][][] template;
63    
64                  try {                  try {
65                          template = parseFile(templateFile);                          template = parseFile(templateFile);
# Line 74  public class TemplateCommand implements Line 73  public class TemplateCommand implements
73                          return true;                          return true;
74                  }                  }
75    
76                  buildTemplate( player.getLocation(),  template);                  buildTemplate( player.getLocation(),  template, 1);
77                    buildTemplate( player.getLocation(),  template, 2);
78    
79                  return false;                  return false;
80          }          }
# Line 82  public class TemplateCommand implements Line 82  public class TemplateCommand implements
82    
83    
84    
85          int[][][] parseFile(File templateFile) throws Exception {          Pair[][][] parseFile(File templateFile) throws Exception {
86    
87    
88                  int lines = 0;                  int lines = 0;
# Line 107  public class TemplateCommand implements Line 107  public class TemplateCommand implements
107                  int ysize = Integer.parseInt(dimensions[1]);                  int ysize = Integer.parseInt(dimensions[1]);
108                  int zsize = Integer.parseInt(dimensions[2]);                  int zsize = Integer.parseInt(dimensions[2]);
109    
110                  int[][][] array = new int[xsize][ysize][zsize];                  Pair[][][] array = new Pair[xsize][ysize][zsize];
111    
112                  int x = 0;                  int x = 0;
113                  int y = 0;                  int y = 0;
# Line 129  public class TemplateCommand implements Line 129  public class TemplateCommand implements
129                          }                          }
130    
131                          for (int i=0; i<elements.length; i++) {                          for (int i=0; i<elements.length; i++) {
132                                  try {                                  int val = 0;
133                                          String element = elements[i].trim();                                  int subval = 0;
134                                          int val = Integer.parseInt( element );                                  
135                                    String element[] = elements[i].trim().split("\\.");
136                                          if (val < 0 || val>255) {  
137                                                  throw new Exception( "Template: invalid value on line " + lines + ": " + val );                                  
138                                          }                                  try {                                  
139                                          array[x][y][i] = val;                                          val = Integer.parseInt( element[0] );
   
140                                  } catch (Exception e) {                                  } catch (Exception e) {
141                                          throw new Exception( "Template: invalid value on line " + lines + ": " + elements[i] );                                          throw new Exception( "Template: invalid value on line " + lines + ": " + element[0] );
142                                    }
143                                    
144                                    if (val < 0 || val>255) {
145                                            throw new Exception( "Template: invalid value on line " + lines + ": " + val );
146                                  }                                  }
147                                    
148                                    if (element.length == 2) {
149                                            try {                                  
150                                                    subval = Integer.parseInt( element[1] );
151                                            } catch (Exception e) {
152                                                    throw new Exception( "Template: invalid value on line " + lines + ": " + element[1] );
153                                            }
154                                    }
155                                                                    
156                                    array[x][y][i] = new Pair(val,subval);
157                          }                          }
158    
159                          x++;                          x++;
# Line 163  public class TemplateCommand implements Line 176  public class TemplateCommand implements
176    
177          }          }
178    
179          void buildTemplate(Location loc, int[][][] template) {          void buildTemplate(Location loc, Pair[][][] template, int pass) {
180                  World world = loc.getWorld();                  World world = loc.getWorld();
181                  for (int i=0; i<template.length; i++ ) {                  for (int i=0; i<template.length; i++ ) {
182                          for (int j=0; j<template[0].length; j++) {                          for (int j=0; j<template[0].length; j++) {
# Line 171  public class TemplateCommand implements Line 184  public class TemplateCommand implements
184                                          int x = loc.getBlockX() + i + 1;                                          int x = loc.getBlockX() + i + 1;
185                                          int y = loc.getBlockY() + j;                                          int y = loc.getBlockY() + j;
186                                          int z = loc.getBlockZ() + k;                                          int z = loc.getBlockZ() + k;
187                                            
188                                            if (y >= 255) {
189                                                    continue;
190                                            }
191    
192                                          int type = template[i][j][k];                                          int type = template[i][j][k].id;
193                                            byte data = (byte) template[i][j][k].subId;
194    
195                                          //plugin.getLogger().info(  String.format(  "Setting typeid at %d,%d,%d  to %d", x,y,z, type)  );                                          //plugin.getLogger().info(  String.format(  "Setting typeid at %d,%d,%d  to %d", x,y,z, type)  );
196    
197                                          world.getBlockAt(x, y, z).setTypeId( type  );                                          if (pass == 1) {
198                                                    if ( type == 50 || type == 75 || type == 76) //torch / redstone torch                                                  
199                                                            continue;
200                                                    if (type == 64 || type==71) //door / irondoor
201                                                            continue;
202                                                    if (type == 68) // sign
203                                                            continue;
204                                            }
205                                            
206                                            world.getBlockAt(x, y, z).setTypeIdAndData(type, data, true);
207                                            
208                                  }                                  }
209                          }                          }
210                  }                  }

Legend:
Removed from v.1746  
changed lines
  Added in v.1750

  ViewVC Help
Powered by ViewVC 1.1.20