Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-09 21:10:05 +01:00
Biome clean up & fixes
Change BiomeType to an interface. Do not longer use invalid biomes of Bukkit Biome enum. Add a common unknown biome type.
Dieser Commit ist enthalten in:
Ursprung
2ed92dafad
Commit
e86dc2c90b
@ -1,43 +1,17 @@
|
|||||||
package com.sk89q.worldedit;
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
public class BiomeType {
|
public interface BiomeType {
|
||||||
|
|
||||||
private String name;
|
public static final BiomeType UNKNOWN = new BiomeType() {
|
||||||
|
public String getName() {
|
||||||
public BiomeType(String name) {
|
return "Unknown";
|
||||||
this.name = name;
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the player.
|
* Get the name of this biome type.
|
||||||
*
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName();
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the hash code.
|
|
||||||
*
|
|
||||||
* @return hash code
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return name.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if equal.
|
|
||||||
*
|
|
||||||
* @param other
|
|
||||||
* @return whether the other object is equivalent
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj instanceof BiomeType) {
|
|
||||||
return ((BiomeType) obj).name.equals(name);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
49
src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeType.java
Normale Datei
49
src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeType.java
Normale Datei
@ -0,0 +1,49 @@
|
|||||||
|
package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.bukkit.block.Biome;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.BiomeType;
|
||||||
|
|
||||||
|
public enum BukkitBiomeType implements BiomeType {
|
||||||
|
|
||||||
|
SWAMPLAND(Biome.SWAMPLAND),
|
||||||
|
FOREST(Biome.FOREST),
|
||||||
|
TAIGA(Biome.TAIGA),
|
||||||
|
DESERT(Biome.DESERT),
|
||||||
|
PLAINS(Biome.PLAINS),
|
||||||
|
HELL(Biome.HELL),
|
||||||
|
SKY(Biome.SKY),
|
||||||
|
RIVER(Biome.RIVER),
|
||||||
|
EXTREME_HILLS(Biome.EXTREME_HILLS),
|
||||||
|
OCEAN(Biome.OCEAN),
|
||||||
|
FROZEN_OCEAN(Biome.FROZEN_OCEAN),
|
||||||
|
FROZEN_RIVER(Biome.FROZEN_RIVER),
|
||||||
|
ICE_PLAINS(Biome.ICE_PLAINS),
|
||||||
|
ICE_MOUNTAINS(Biome.ICE_MOUNTAINS),
|
||||||
|
MUSHROOM_ISLAND(Biome.MUSHROOM_ISLAND),
|
||||||
|
MUSHROOM_SHORE(Biome.MUSHROOM_SHORE),
|
||||||
|
BEACH(Biome.BEACH),
|
||||||
|
DESERT_HILLS(Biome.DESERT_HILLS),
|
||||||
|
FOREST_HILLS(Biome.FOREST_HILLS),
|
||||||
|
TAIGA_HILLS(Biome.TAIGA_HILLS),
|
||||||
|
SMALL_MOUNTAINS(Biome.SMALL_MOUNTAINS),
|
||||||
|
JUNGLE(Biome.JUNGLE),
|
||||||
|
JUNGLE_HILLS(Biome.JUNGLE_HILLS);
|
||||||
|
|
||||||
|
private Biome bukkitBiome;
|
||||||
|
|
||||||
|
private BukkitBiomeType(Biome biome) {
|
||||||
|
this.bukkitBiome = biome;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name().toLowerCase(Locale.ENGLISH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Biome getBukkitBiome() {
|
||||||
|
return bukkitBiome;
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,9 @@
|
|||||||
package com.sk89q.worldedit.bukkit;
|
package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.bukkit.block.Biome;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.BiomeType;
|
import com.sk89q.worldedit.BiomeType;
|
||||||
import com.sk89q.worldedit.BiomeTypes;
|
import com.sk89q.worldedit.BiomeTypes;
|
||||||
import com.sk89q.worldedit.UnknownBiomeTypeException;
|
import com.sk89q.worldedit.UnknownBiomeTypeException;
|
||||||
@ -18,7 +16,7 @@ public class BukkitBiomeTypes implements BiomeTypes {
|
|||||||
@Override
|
@Override
|
||||||
public boolean has(String name) {
|
public boolean has(String name) {
|
||||||
try {
|
try {
|
||||||
Biome.valueOf(name.toUpperCase(Locale.ENGLISH));
|
BukkitBiomeType.valueOf(name.toUpperCase(Locale.ENGLISH));
|
||||||
return true;
|
return true;
|
||||||
} catch (IllegalArgumentException exc) {
|
} catch (IllegalArgumentException exc) {
|
||||||
return false;
|
return false;
|
||||||
@ -28,8 +26,7 @@ public class BukkitBiomeTypes implements BiomeTypes {
|
|||||||
@Override
|
@Override
|
||||||
public BiomeType get(String name) throws UnknownBiomeTypeException {
|
public BiomeType get(String name) throws UnknownBiomeTypeException {
|
||||||
try {
|
try {
|
||||||
Biome biome = Biome.valueOf(name.toUpperCase(Locale.ENGLISH));
|
return BukkitBiomeType.valueOf(name.toUpperCase(Locale.ENGLISH));
|
||||||
return new BiomeType(biome.name());
|
|
||||||
} catch (IllegalArgumentException exc) {
|
} catch (IllegalArgumentException exc) {
|
||||||
throw new UnknownBiomeTypeException(name);
|
throw new UnknownBiomeTypeException(name);
|
||||||
}
|
}
|
||||||
@ -37,11 +34,7 @@ public class BukkitBiomeTypes implements BiomeTypes {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BiomeType> all() {
|
public List<BiomeType> all() {
|
||||||
List<BiomeType> biomes = new ArrayList<BiomeType>();
|
return Arrays.<BiomeType>asList(BukkitBiomeType.values());
|
||||||
for (Biome biome : Biome.values()) {
|
|
||||||
biomes.add(new BiomeType(biome.name()));
|
|
||||||
}
|
|
||||||
return biomes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -214,18 +214,20 @@ public class BukkitWorld extends LocalWorld {
|
|||||||
*/
|
*/
|
||||||
public BiomeType getBiome(Vector2D pt) {
|
public BiomeType getBiome(Vector2D pt) {
|
||||||
Biome bukkitBiome = world.getBiome(pt.getBlockX(), pt.getBlockZ());
|
Biome bukkitBiome = world.getBiome(pt.getBlockX(), pt.getBlockZ());
|
||||||
return new BiomeType(bukkitBiome.name());
|
try {
|
||||||
|
return BukkitBiomeType.valueOf(bukkitBiome.name());
|
||||||
|
} catch (IllegalArgumentException exc) {
|
||||||
|
return BiomeType.UNKNOWN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBiome(Vector2D pt, BiomeType biome) {
|
public void setBiome(Vector2D pt, BiomeType biome) {
|
||||||
Biome bukkitBiome;
|
if (biome instanceof BukkitBiomeType) {
|
||||||
try {
|
Biome bukkitBiome;
|
||||||
bukkitBiome = Biome.valueOf(biome.getName().toUpperCase());
|
bukkitBiome = ((BukkitBiomeType) biome).getBukkitBiome();
|
||||||
} catch (IllegalArgumentException e) {
|
world.setBiome(pt.getBlockX(), pt.getBlockZ(), bukkitBiome);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
world.setBiome(pt.getBlockX(), pt.getBlockZ(), bukkitBiome);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,14 +23,18 @@ import org.spout.api.generator.biome.BiomeType;
|
|||||||
/**
|
/**
|
||||||
* @author zml2008
|
* @author zml2008
|
||||||
*/
|
*/
|
||||||
public class SpoutBiomeType extends com.sk89q.worldedit.BiomeType {
|
public class SpoutBiomeType implements com.sk89q.worldedit.BiomeType {
|
||||||
private final BiomeType type;
|
private final BiomeType type;
|
||||||
|
|
||||||
public SpoutBiomeType(BiomeType type) {
|
public SpoutBiomeType(BiomeType type) {
|
||||||
super(type.getName().toLowerCase().replace(" ", ""));
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return type.getName().toLowerCase().replace(" ", "");
|
||||||
|
}
|
||||||
|
|
||||||
public BiomeType getSpoutBiome() {
|
public BiomeType getSpoutBiome() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
@ -206,11 +206,12 @@ public class SpoutWorld extends LocalWorld {
|
|||||||
BiomeGenerator gen = (BiomeGenerator) world.getGenerator();
|
BiomeGenerator gen = (BiomeGenerator) world.getGenerator();
|
||||||
return new SpoutBiomeType(gen.getBiome(pt.getBlockX(), pt.getBlockZ(), world.getSeed()));
|
return new SpoutBiomeType(gen.getBiome(pt.getBlockX(), pt.getBlockZ(), world.getSeed()));
|
||||||
}
|
}
|
||||||
return new BiomeType("Unknown");
|
return BiomeType.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBiome(Vector2D pt, BiomeType biome) {
|
public void setBiome(Vector2D pt, BiomeType biome) {
|
||||||
if (world.getGenerator() instanceof BiomeGenerator) {
|
if (biome instanceof SpoutBiomeType &&
|
||||||
|
world.getGenerator() instanceof BiomeGenerator) {
|
||||||
BiomeGenerator gen = (BiomeGenerator) world.getGenerator();
|
BiomeGenerator gen = (BiomeGenerator) world.getGenerator();
|
||||||
gen.setBiome(new Vector3(pt.getBlockX(), 0, pt.getBlockZ()), ((SpoutBiomeType) biome).getSpoutBiome());
|
gen.setBiome(new Vector3(pt.getBlockX(), 0, pt.getBlockZ()), ((SpoutBiomeType) biome).getSpoutBiome());
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren