/[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 3238 by torben, Wed May 31 08:56:00 2017 UTC revision 3239 by torben, Wed Jul 18 07:59:05 2018 UTC
# Line 7  import java.io.InputStreamReader; Line 7  import java.io.InputStreamReader;
7    
8  import org.bukkit.ChatColor;  import org.bukkit.ChatColor;
9  import org.bukkit.Location;  import org.bukkit.Location;
10    import org.bukkit.Material;
11  import org.bukkit.World;  import org.bukkit.World;
12  import org.bukkit.command.Command;  import org.bukkit.command.Command;
13  import org.bukkit.command.CommandExecutor;  import org.bukkit.command.CommandExecutor;
# Line 17  import org.bukkit.plugin.Plugin; Line 18  import org.bukkit.plugin.Plugin;
18  public class TemplateCommand implements CommandExecutor {  public class TemplateCommand implements CommandExecutor {
19    
20    
         class Pair {  
                 public int id;  
                 public int subId;  
   
                 public Pair (int i, int s) {  
                         id = i;  
                         subId = s;  
                 }  
   
         }  
21    
22          Plugin plugin;          Plugin plugin;
23    
# Line 59  public class TemplateCommand implements Line 50  public class TemplateCommand implements
50                          return true;                          return true;
51                  }                        }      
52    
53                  Pair[][][] template;                  Material[][][] template;
54    
55                  try {                  try {
56                          template = parseFile(templateFile);                          template = parseFile(templateFile);
# Line 82  public class TemplateCommand implements Line 73  public class TemplateCommand implements
73    
74    
75    
76          Pair[][][] parseFile(File templateFile) throws Exception {          Material[][][] parseFile(File templateFile) throws Exception {
77    
78    
79                  int lines = 0;                  int lines = 0;
# Line 111  public class TemplateCommand implements Line 102  public class TemplateCommand implements
102                          int ysize = Integer.parseInt(dimensions[1]);                          int ysize = Integer.parseInt(dimensions[1]);
103                          int zsize = Integer.parseInt(dimensions[2]);                          int zsize = Integer.parseInt(dimensions[2]);
104                    
105                          Pair[][][] array = new Pair[xsize][ysize][zsize];                          Material[][][] array = new Material[xsize][ysize][zsize];
106                    
107                          int x = 0;                          int x = 0;
108                          int y = 0;                          int y = 0;
# Line 137  public class TemplateCommand implements Line 128  public class TemplateCommand implements
128                                  }                                  }
129                    
130                                  for (int i=0; i<elements.length; i++) {                                  for (int i=0; i<elements.length; i++) {
                                         int val = 0;  
                                         int subval = 0;  
131                                                                                    
132                                          String element[] = elements[i].trim().split("\\.");                                          String element[] = elements[i].trim().split("\\.");
133                    
134                                                                                    
135                                            Material m;
136                                          try {                                                                            try {                                  
137                                                  val = Integer.parseInt( element[0] );                                                  m = Material.valueOf(element[0]);
138                                          } catch (Exception e) {                                          } catch (Exception e) {
139                                                  throw new Exception( "Template: invalid value on line " + lines + ": " + element[0] );                                                  throw new Exception( "Template: invalid material on line " + lines + ": " + element[0] );
140                                          }                                          }
141                                                                                    
142                                          if (val < -1 || val>255) {  
143                                                  throw new Exception( "Template: invalid value on line " + lines + ": " + val );                                          array[x][y][i] = m;
                                         }  
                                           
                                         if (element.length == 2) {  
                                                 try {                                    
                                                         subval = Integer.parseInt( element[1] );  
                                                 } catch (Exception e) {  
                                                         throw new Exception( "Template: invalid value on line " + lines + ": " + element[1] );  
                                                 }  
                                         }  
                                                                           
                                         array[x][y][i] = new Pair(val,subval);  
144                                  }                                  }
145                    
146                                  x++;                                  x++;
# Line 186  public class TemplateCommand implements Line 165  public class TemplateCommand implements
165    
166          }          }
167    
168          void buildTemplate(Location loc, Pair[][][] template, int pass) {          void buildTemplate(Location loc, Material[][][] template, int pass) {
169    
170                                    
171                  World world = loc.getWorld();                  World world = loc.getWorld();
# Line 222  public class TemplateCommand implements Line 201  public class TemplateCommand implements
201                                          }                                          }
202    
203    
204                                          int type = template[i][j][k].id;  
                                         byte data = (byte) template[i][j][k].subId;  
205                                                                                    
206                                          if (type == -1) {                                          Material mat = template[i][j][k];
                                                 continue;  
                                         }  
207    
208                                          //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)  );
209    
210                                            //TODO: rewrite this to build a Set<Material> of skipped matterials
211                                          if (pass == 1) {                                          if (pass == 1) {
212                                                  if ( type == 50 || type == 75 || type == 76) //torch / redstone torch                                                                                                    
213                                                    if ( mat == Material.TORCH || mat == Material.REDSTONE_TORCH || mat == Material.REDSTONE_WALL_TORCH) //torch / redstone torch                                                  
214                                                          continue;                                                          continue;
215                                                  if (type == 64 || type==71) //door / irondoor                                                  
216                                                    if (mat == Material.ACACIA_DOOR || mat == Material.BIRCH_DOOR || mat == Material.DARK_OAK_DOOR ) //door / irondoor
217                                                          continue;                                                          continue;
218                                                  if (type == 68) // sign                                                  
219                                                    if (mat == Material.SIGN) // sign
220                                                          continue;                                                          continue;
221                                                  if (type == 65) // ladder                                                  if (mat == Material.LADDER) // ladder
222                                                          continue;                                                          continue;
223                                                  if (type == 67) // steps                                                  if (mat == Material.OAK_STAIRS) //TODO: need to take all star variants into account
224                                                          continue;                                                                                                        continue;                                              
225                                          }                                          }
226                                                                                    
227                                          world.getBlockAt(x, y, z).setTypeIdAndData(type, data, true);  
228                                            world.getBlockAt(x, y, z).setType(mat);
229                                                                                    
230                                  }                                  }
231                          }                          }

Legend:
Removed from v.3238  
changed lines
  Added in v.3239

  ViewVC Help
Powered by ViewVC 1.1.20