我想知道我是否可以在数组内有一个数组?我想不出办法来解释它。
if (numOfPlayers >= 2) {
this.config.getString("Tribute_one_spawn");
String[] onecoords = this.config.getString("Tribute_one_spawn").split(",");
Player Tribute_one = (Player)this.Playing.get(0);
World w = p.getWorld();
double x = Double.parseDouble(onecoords[0]);
double y = Double.parseDouble(onecoords[1]);
double z = Double.parseDouble(onecoords[2]);
Location oneloc = new Location(w, x, y, z);
Tribute_one.teleport(oneloc);
this.Frozen.add(Tribute_one);
Tribute_one.setFoodLevel(20);
this.config.getString("Tribute_two_spawn");
String[] twocoords = this.config.getString("Tribute_two_spawn").split(",");
Player Tribute_two = (Player)this.Playing.get(1);
World twow = p.getWorld();
double twox = Double.parseDouble(twocoords[0]);
double twoy = Double.parseDouble(twocoords[1]);
double twoz = Double.parseDouble(twocoords[2]);
Location twoloc = new Location(twow, twox, twoy, twoz);
Tribute_two.teleport(twoloc);
this.Frozen.add(Tribute_two);
Tribute_two.setFoodLevel(20);
}
if (numOfPlayers() >= 3) {
this.config.getString("Tribute_three_spawn");
String[] coords = this.config.getString("Tribute_three_spawn").split(",");
Player Tribute_three = (Player)this.Playing.get(2);
World w = p.getWorld();
double x = Double.parseDouble(coords[0]);
double y = Double.parseDouble(coords[1]);
double z = Double.parseDouble(coords[2]);
Location loc = new Location(w, x, y, z);
Tribute_three.teleport(loc);
this.Frozen.add(Tribute_three);
Tribute_three.setFoodLevel(20);
}
如您所见,我必须在 if else 阶梯中为每个玩家创建一个新数组。除了制作 48 个 if 语句之外,还有一种方法可以更改 coords 数组的变量名称,以将其放入一个 for 循环中,其中计数器递增数组的名称。嗯,这是一种令人困惑的解释方式,但这是我能做的最好的。