Permalink
Browse files

Added Biome as a filter for CustomDrops.

  • Loading branch information...
me4502 committed Apr 25, 2017
1 parent 5e04acf commit 03d4d52b675fd131ecd1298a2c0813aa8bdf31a2
@@ -4,6 +4,7 @@
import com.sk89q.craftbook.mechanics.drops.rewards.DropReward;
import com.sk89q.craftbook.util.ItemUtil;
import com.sk89q.craftbook.util.TernaryState;
+import org.bukkit.block.Biome;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
@@ -22,7 +23,10 @@
// WorldGuard Integration
private List<String> regions;
+
+ // Requirements
private List<ItemStack> items;
+ private Biome biome;
public CustomDropDefinition(String name, List<DropItemStack> drops, List<DropReward> extraRewards, TernaryState silkTouch) {
this.drops = drops.toArray(new DropItemStack[drops.size()]);
@@ -51,6 +55,14 @@ public void setRegions(List<String> regions) {
}
}
+ public Biome getBiome() {
+ return this.biome;
+ }
+
+ public void setBiome(Biome biome) {
+ this.biome = biome;
+ }
+
public List<ItemStack> getItems() {
return this.items;
}
@@ -12,6 +12,7 @@
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.GameMode;
import org.bukkit.Material;
+import org.bukkit.block.Biome;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb;
@@ -64,6 +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<DropItemStack> drops = new ArrayList<DropItemStack>();
@@ -131,6 +133,14 @@ 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!");
+ }
+ }
definitions.add(def);
}
}
@@ -153,6 +163,9 @@ 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());
+ }
int i = 0;
for(DropItemStack stack : def.getDrops()) {
@@ -223,6 +236,12 @@ public void onBlockBreak(BlockBreakEvent event) {
return;
}
+ if (def.getBiome() != null) {
+ if (!event.getBlock().getBiome().equals(def.getBiome())) {
+ return;
+ }
+ }
+
if (def.getItems() != null) {
boolean found = false;
@@ -286,6 +305,12 @@ public void onEntityDeath(EntityDeathEvent event) {
return;
}
+ if (def.getBiome() != null) {
+ if (!event.getEntity().getLocation().getBlock().getBiome().equals(def.getBiome())) {
+ return;
+ }
+ }
+
Player killer = event.getEntity().getKiller();
if (def.getItems() != null) {

0 comments on commit 03d4d52

Please sign in to comment.