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; |
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 |
|
|
26 |
subId = s; |
subId = s; |
27 |
} |
} |
28 |
|
|
29 |
}*/ |
} |
30 |
|
|
31 |
Plugin plugin; |
Plugin plugin; |
32 |
|
|
59 |
return true; |
return true; |
60 |
} |
} |
61 |
|
|
62 |
int[][][] template; |
Pair[][][] template; |
63 |
|
|
64 |
try { |
try { |
65 |
template = parseFile(templateFile); |
template = parseFile(templateFile); |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
int[][][] parseFile(File templateFile) throws Exception { |
Pair[][][] parseFile(File templateFile) throws Exception { |
85 |
|
|
86 |
|
|
87 |
int lines = 0; |
int lines = 0; |
106 |
int ysize = Integer.parseInt(dimensions[1]); |
int ysize = Integer.parseInt(dimensions[1]); |
107 |
int zsize = Integer.parseInt(dimensions[2]); |
int zsize = Integer.parseInt(dimensions[2]); |
108 |
|
|
109 |
int[][][] array = new int[xsize][ysize][zsize]; |
Pair[][][] array = new Pair[xsize][ysize][zsize]; |
110 |
|
|
111 |
int x = 0; |
int x = 0; |
112 |
int y = 0; |
int y = 0; |
128 |
} |
} |
129 |
|
|
130 |
for (int i=0; i<elements.length; i++) { |
for (int i=0; i<elements.length; i++) { |
131 |
try { |
int val = 0; |
132 |
String element = elements[i].trim(); |
int subval = 0; |
133 |
int val = Integer.parseInt( element ); |
|
134 |
|
String element[] = elements[i].trim().split("\\."); |
135 |
if (val < 0 || val>255) { |
|
136 |
throw new Exception( "Template: invalid value on line " + lines + ": " + val ); |
|
137 |
} |
try { |
138 |
array[x][y][i] = val; |
val = Integer.parseInt( element[0] ); |
|
|
|
139 |
} catch (Exception e) { |
} catch (Exception e) { |
140 |
throw new Exception( "Template: invalid value on line " + lines + ": " + elements[i] ); |
throw new Exception( "Template: invalid value on line " + lines + ": " + element[0] ); |
141 |
|
} |
142 |
|
|
143 |
|
if (val < 0 || val>255) { |
144 |
|
throw new Exception( "Template: invalid value on line " + lines + ": " + val ); |
145 |
} |
} |
146 |
|
|
147 |
|
if (element.length == 2) { |
148 |
|
try { |
149 |
|
subval = Integer.parseInt( element[1] ); |
150 |
|
} catch (Exception e) { |
151 |
|
throw new Exception( "Template: invalid value on line " + lines + ": " + element[1] ); |
152 |
|
} |
153 |
|
} |
154 |
|
|
155 |
|
array[x][y][i] = new Pair(val,subval); |
156 |
} |
} |
157 |
|
|
158 |
x++; |
x++; |
175 |
|
|
176 |
} |
} |
177 |
|
|
178 |
void buildTemplate(Location loc, int[][][] template) { |
void buildTemplate(Location loc, Pair[][][] template) { |
179 |
World world = loc.getWorld(); |
World world = loc.getWorld(); |
180 |
for (int i=0; i<template.length; i++ ) { |
for (int i=0; i<template.length; i++ ) { |
181 |
for (int j=0; j<template[0].length; j++) { |
for (int j=0; j<template[0].length; j++) { |
183 |
int x = loc.getBlockX() + i + 1; |
int x = loc.getBlockX() + i + 1; |
184 |
int y = loc.getBlockY() + j; |
int y = loc.getBlockY() + j; |
185 |
int z = loc.getBlockZ() + k; |
int z = loc.getBlockZ() + k; |
186 |
|
|
187 |
|
if (y >= 255) { |
188 |
|
continue; |
189 |
|
} |
190 |
|
|
191 |
int type = template[i][j][k]; |
int type = template[i][j][k].id; |
192 |
|
byte data = (byte) template[i][j][k].subId; |
193 |
|
|
194 |
//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) ); |
195 |
|
|
196 |
world.getBlockAt(x, y, z).setTypeId( type ); |
|
197 |
|
world.getBlockAt(x, y, z).setTypeIdAndData(type, data, true); |
198 |
} |
} |
199 |
} |
} |
200 |
} |
} |