Added bedrock metadata.
Stores: * A temporary island id. * The main biome of the island. * The shore biome of the island. * The temperature of the island. * The owner UUID of the island.
This commit is contained in:
parent
c9dd2a1c4b
commit
85dd6e6e3d
@ -0,0 +1,46 @@
|
||||
package ca.recrown.islandsurvivalcraft.islandbedrockmetadata;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class IslandBedrockMetadataHelper {
|
||||
World world;
|
||||
Plugin plugin;
|
||||
|
||||
public IslandBedrockMetadataHelper(Plugin owningPlugin, World world) {
|
||||
this.world = world;
|
||||
this.plugin = owningPlugin;
|
||||
}
|
||||
|
||||
public void setIslandBedrockMetadata(int worldX, int worldZ, IslandFixedMetadata metadata) {
|
||||
world.getBlockAt(worldX, 0, worldZ).setMetadata(metadata.getIslandMetadataType().toString(), metadata);
|
||||
}
|
||||
|
||||
public void setIslandBedrockMetadataPack(int worldX, int worldZ, IslandMetadataPack pack) {
|
||||
setIslandBedrockMetadata(worldX, worldZ, pack.mainBiomeMetadata);
|
||||
setIslandBedrockMetadata(worldX, worldZ, pack.shoreBiomeMetadata);
|
||||
setIslandBedrockMetadata(worldX, worldZ, pack.temperatureMetadata);
|
||||
setIslandBedrockMetadata(worldX, worldZ, pack.islandTIUDMetadata);
|
||||
setIslandBedrockMetadata(worldX, worldZ, pack.ownerMetadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the metadata stored in the bedrock at the given coordinates.
|
||||
* @param worldX The x coordinate of the world.
|
||||
* @param worldZ The z coordinate of the world.
|
||||
* @param type the type of island metadata to retrieve.
|
||||
* @return the island bedrock metadata at that location.
|
||||
*/
|
||||
public IslandFixedMetadata getIslandBedrockMetadata(int worldX, int worldZ, IslandMetadataType type) {
|
||||
List<MetadataValue> potential = world.getBlockAt(worldX, 0, worldZ).getMetadata(type.toString());
|
||||
for (MetadataValue metadataValue : potential) {
|
||||
if (metadataValue.getOwningPlugin().equals(plugin)) {
|
||||
return (IslandFixedMetadata) metadataValue;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No metadata was found for given type.");
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package ca.recrown.islandsurvivalcraft.islandbedrockmetadata;
|
||||
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public abstract class IslandFixedMetadata extends FixedMetadataValue {
|
||||
|
||||
public IslandFixedMetadata(Plugin owningPlugin, Object value) {
|
||||
super(owningPlugin, value);
|
||||
}
|
||||
|
||||
public abstract IslandMetadataType getIslandMetadataType();
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package ca.recrown.islandsurvivalcraft.islandbedrockmetadata;
|
||||
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class IslandMainBiomeMetadata extends IslandFixedMetadata {
|
||||
|
||||
public IslandMainBiomeMetadata(Plugin owningPlugin, Biome value) {
|
||||
super(owningPlugin, value);
|
||||
}
|
||||
|
||||
public Biome getMainBiome() {
|
||||
return (Biome) this.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IslandMetadataType getIslandMetadataType() {
|
||||
return IslandMetadataType.mainBiome;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package ca.recrown.islandsurvivalcraft.islandbedrockmetadata;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class IslandMetadataPack {
|
||||
public IslandMainBiomeMetadata mainBiomeMetadata;
|
||||
public IslandShoreBiomeMetadata shoreBiomeMetadata;
|
||||
public IslandTemperatureMetadata temperatureMetadata;
|
||||
public IslandTUIDMetadata islandTIUDMetadata;
|
||||
public IslandOwnerMetadata ownerMetadata;
|
||||
|
||||
public void setMainBiome(Biome biome, Plugin owningPlugin) {
|
||||
mainBiomeMetadata = new IslandMainBiomeMetadata(owningPlugin, biome);
|
||||
}
|
||||
public void setShoreBiome(Biome biome, Plugin owningPlugin) {
|
||||
shoreBiomeMetadata = new IslandShoreBiomeMetadata(owningPlugin, biome);
|
||||
}
|
||||
public void setTemperature(float temperature, Plugin owningPlugin) {
|
||||
temperatureMetadata = new IslandTemperatureMetadata(owningPlugin, temperature);
|
||||
}
|
||||
public void setTUID(String tiud, Plugin owningPlugin) {
|
||||
islandTIUDMetadata = new IslandTUIDMetadata(owningPlugin, tiud);
|
||||
}
|
||||
|
||||
public void setTUID(int worldX, int worldZ, Plugin owningPlugin) {
|
||||
setTUID((String.valueOf(worldX) + String.valueOf(worldZ)), owningPlugin);
|
||||
}
|
||||
public void setOwner(UUID uuid, Plugin owningPlugin) {
|
||||
ownerMetadata = new IslandOwnerMetadata(owningPlugin, uuid);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package ca.recrown.islandsurvivalcraft.islandbedrockmetadata;
|
||||
|
||||
public enum IslandMetadataType {
|
||||
mainBiome("main_biome"),
|
||||
shoreBiome("shore_biome"),
|
||||
temperature("temperature"),
|
||||
TIUD("temp_island_unique_id"),
|
||||
ownerUUID("owner_UUID");
|
||||
|
||||
private String key;
|
||||
private IslandMetadataType(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.key;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package ca.recrown.islandsurvivalcraft.islandbedrockmetadata;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class IslandOwnerMetadata extends IslandFixedMetadata {
|
||||
|
||||
public IslandOwnerMetadata(Plugin owningPlugin, UUID value) {
|
||||
super(owningPlugin, value);
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return (UUID) this.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IslandMetadataType getIslandMetadataType() {
|
||||
return IslandMetadataType.ownerUUID;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package ca.recrown.islandsurvivalcraft.islandbedrockmetadata;
|
||||
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class IslandShoreBiomeMetadata extends IslandFixedMetadata {
|
||||
|
||||
public IslandShoreBiomeMetadata(Plugin owningPlugin, Biome value) {
|
||||
super(owningPlugin, value);
|
||||
}
|
||||
|
||||
public Biome getShoreBiome() {
|
||||
return (Biome) this.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IslandMetadataType getIslandMetadataType() {
|
||||
return IslandMetadataType.shoreBiome;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package ca.recrown.islandsurvivalcraft.islandbedrockmetadata;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class IslandTUIDMetadata extends IslandFixedMetadata {
|
||||
|
||||
public IslandTUIDMetadata(Plugin owningPlugin, String value) {
|
||||
super(owningPlugin, value);
|
||||
}
|
||||
|
||||
public String getIUID() {
|
||||
return asString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IslandMetadataType getIslandMetadataType() {
|
||||
return IslandMetadataType.TIUD;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package ca.recrown.islandsurvivalcraft.islandbedrockmetadata;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class IslandTemperatureMetadata extends IslandFixedMetadata {
|
||||
|
||||
public IslandTemperatureMetadata(Plugin owningPlugin, Float value) {
|
||||
super(owningPlugin, value);
|
||||
}
|
||||
|
||||
public float getTemperature() {
|
||||
return ((Float) this.value()).floatValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IslandMetadataType getIslandMetadataType() {
|
||||
return IslandMetadataType.temperature;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user