From a438c3978c39b4f6d7f61b701efac27eb143c20b Mon Sep 17 00:00:00 2001 From: Blackdigits Date: Wed, 5 Feb 2020 23:44:37 +0700 Subject: [PATCH] add biome condition usage: - 'biome{name=SWAMP}' --- .../droptable/condition/BiomeCondition.java | 24 +++++++++++++++++++ .../mmocore/api/load/DefaultMMOLoader.java | 4 ++++ 2 files changed, 28 insertions(+) create mode 100644 src/main/java/net/Indyuce/mmocore/api/droptable/condition/BiomeCondition.java diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/BiomeCondition.java b/src/main/java/net/Indyuce/mmocore/api/droptable/condition/BiomeCondition.java new file mode 100644 index 00000000..fa7bd8c7 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/api/droptable/condition/BiomeCondition.java @@ -0,0 +1,24 @@ +package net.Indyuce.mmocore.api.droptable.condition; + +import net.Indyuce.mmocore.api.load.MMOLineConfig; +import org.bukkit.block.Biome; + +import java.util.Arrays; +import java.util.List; + +public class BiomeCondition extends Condition { + private final List names; + + public BiomeCondition(MMOLineConfig config) { + super(config); + + config.validate("name"); + names = Arrays.asList(config.getString("name").split("\\,")); + } + + @Override + public boolean isMet(ConditionInstance entity) { + Biome currentBiome = entity.getEntity().getLocation().getBlock().getBiome(); + return names.contains(currentBiome.name()); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index 37fd86fa..aba7b405 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.api.load; +import net.Indyuce.mmocore.api.droptable.condition.BiomeCondition; import org.bukkit.configuration.ConfigurationSection; import net.Indyuce.mmocore.api.droptable.condition.Condition; @@ -105,6 +106,9 @@ public class DefaultMMOLoader implements MMOLoader { if (config.getKey().equals("world")) return new WorldCondition(config); + if (config.getKey().equals("biome")) + return new BiomeCondition(config); + return null; }