Permalink
Browse files

Make it a list rather than single one.

  • Loading branch information...
me4502 committed Apr 25, 2017
1 parent 03d4d52 commit 14c2a865aad6cbc2b143204b3828759fb8ed04e2
@@ -26,7 +26,7 @@
// Requirements
private List<ItemStack> items;
- private Biome biome;
+ private List<Biome> biomes;
public CustomDropDefinition(String name, List<DropItemStack> drops, List<DropReward> extraRewards, TernaryState silkTouch) {
this.drops = drops.toArray(new DropItemStack[drops.size()]);
@@ -55,12 +55,12 @@ public void setRegions(List<String> regions) {
}
}
- public Biome getBiome() {
- return this.biome;
+ public List<Biome> getBiomes() {
+ return this.biomes;
}
- public void setBiome(Biome biome) {
- this.biome = biome;
+ public void setBiomes(List<Biome> biomes) {
+ this.biomes = biomes;
}
public List<ItemStack> getItems() {
@@ -65,7 +65,7 @@ public boolean load() {
TernaryState silkTouch = TernaryState.getFromString(config.getString("custom-drops." + key + ".silk-touch", "none"));
List<String> regions = config.getStringList("custom-drops." + key + ".regions", null);
List<String> requiredItems = config.getStringList("custom-drops." + key + ".required-items", null);
- String biomeString = config.getString("custom-drops." + key + ".biome", null);
+ List<String> biomeStrings = config.getStringList("custom-drops." + key + ".biomes", null);
List<DropItemStack> drops = new ArrayList<DropItemStack>();
@@ -133,13 +133,17 @@ public boolean load() {
}
def.setItems(items);
}
- if (biomeString != null) {
- try {
- Biome biome = Biome.valueOf(biomeString);
- def.setBiome(biome);
- } catch (IllegalArgumentException e) {
- CraftBookPlugin.logger().warning("Tried to assign invalid biome " + biomeString + " to custom drop!");
+ if (biomeStrings != null) {
+ List<Biome> biomes = new ArrayList<Biome>();
+ for (String biomeString : biomeStrings) {
+ try {
+ Biome biome = Biome.valueOf(biomeString);
+ biomes.add(biome);
+ } catch (IllegalArgumentException e) {
+ CraftBookPlugin.logger().warning("Tried to assign invalid biome " + biomeString + " to custom drop!");
+ }
}
+ def.setBiomes(biomes);
}
definitions.add(def);
}
@@ -163,8 +167,12 @@ public void save() {
}
config.setProperty("custom-drops." + def.getName() + ".required-items", itemsList);
}
- if (def.getBiome() != null) {
- config.setProperty("custom-drops." + def.getName() + ".biome", def.getBiome());
+ if (def.getBiomes() != null) {
+ List<String> biomeStringList = new ArrayList<String>();
+ for (Biome biome : def.getBiomes()) {
+ biomeStringList.add(biome.name());
+ }
+ config.setProperty("custom-drops." + def.getName() + ".biomes", biomeStringList);
}
int i = 0;
@@ -236,8 +244,17 @@ public void onBlockBreak(BlockBreakEvent event) {
return;
}
- if (def.getBiome() != null) {
- if (!event.getBlock().getBiome().equals(def.getBiome())) {
+ if (def.getBiomes() != null) {
+ boolean found = false;
+
+ for (Biome biome : def.getBiomes()) {
+ if (event.getBlock().getBiome().equals(biome)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
return;
}
}
@@ -305,8 +322,17 @@ public void onEntityDeath(EntityDeathEvent event) {
return;
}
- if (def.getBiome() != null) {
- if (!event.getEntity().getLocation().getBlock().getBiome().equals(def.getBiome())) {
+ if (def.getBiomes() != null) {
+ boolean found = false;
+
+ for (Biome biome : def.getBiomes()) {
+ if (event.getEntity().getLocation().getBlock().getBiome().equals(biome)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
return;
}
}

0 comments on commit 14c2a86

Please sign in to comment.