diff --git a/pom.xml b/pom.xml
index 1327166..ae24563 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
simplexity
VillagerInfo
- 4.0.1
+ 4.1.0
jar
VillagerInfo
diff --git a/src/main/java/simplexity/villagerinfo/configurations/functionality/VillConfig.java b/src/main/java/simplexity/villagerinfo/configurations/functionality/VillConfig.java
index e8dde6e..b451ed2 100644
--- a/src/main/java/simplexity/villagerinfo/configurations/functionality/VillConfig.java
+++ b/src/main/java/simplexity/villagerinfo/configurations/functionality/VillConfig.java
@@ -29,6 +29,9 @@ public static VillConfig getInstance() {
private final HashMap poiBlockHighlightColorsMap = new HashMap<>();
String error = ServerMessage.CONFIGURATION_ERROR_PREFIX.getMessage();
+ private boolean isWhitelist;
+ private Set itemSet = new HashSet<>();
+
private final Logger logger = VillagerInfo.getInstance().getVillagerInfoLogger();
public void reloadVillConfig(FileConfiguration config) {
@@ -38,6 +41,7 @@ public void reloadVillConfig(FileConfiguration config) {
reloadHighlightTime(config);
reloadToggles(config);
reloadColors(config);
+ reloadItemList(config);
}
public void reloadSound(FileConfiguration config) {
@@ -128,6 +132,19 @@ public void reloadColors(FileConfiguration config) {
}
}
+ public void reloadItemList(FileConfiguration config) {
+ isWhitelist = config.getBoolean("whitelist", false);
+ for (String item : config.getStringList("items")) {
+ Material material = Material.getMaterial(item);
+ if (material != null) {
+ itemSet.add(material);
+ continue;
+ }
+ Logger logger = VillagerInfo.getInstance().getVillagerInfoLogger();
+ logger.warning("Invalid material in item list: " + item);
+ }
+ }
+
public Sound getConfiguredSound() {
return configuredSound;
}
@@ -147,4 +164,8 @@ public float getConfiguredSoundVolume() {
public Map getPoiBlockHighlightColorsMap() {
return Collections.unmodifiableMap(poiBlockHighlightColorsMap);
}
+
+ public boolean isValidItem(Material material) {
+ return itemSet.contains(material) == isWhitelist;
+ }
}
diff --git a/src/main/java/simplexity/villagerinfo/interaction/listeners/PlayerInteractEntityListener.java b/src/main/java/simplexity/villagerinfo/interaction/listeners/PlayerInteractEntityListener.java
index 9fb617f..067dc2e 100644
--- a/src/main/java/simplexity/villagerinfo/interaction/listeners/PlayerInteractEntityListener.java
+++ b/src/main/java/simplexity/villagerinfo/interaction/listeners/PlayerInteractEntityListener.java
@@ -1,5 +1,6 @@
package simplexity.villagerinfo.interaction.listeners;
+import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.entity.ZombieVillager;
@@ -9,6 +10,7 @@
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import simplexity.villagerinfo.configurations.functionality.ConfigToggle;
+import simplexity.villagerinfo.configurations.functionality.VillConfig;
import simplexity.villagerinfo.interaction.logic.HighlightLogic;
import simplexity.villagerinfo.interaction.logic.OutputLogic;
import simplexity.villagerinfo.interaction.logic.SoundLogic;
@@ -21,6 +23,8 @@ public class PlayerInteractEntityListener implements Listener {
public void onVillagerInteract(PlayerInteractEntityEvent interactEntityEvent) {
if (interactEntityEvent.getHand().equals(EquipmentSlot.OFF_HAND)) return;
Player player = interactEntityEvent.getPlayer();
+ Material material = player.getEquipment().getItemInMainHand().getType();
+ if (!VillConfig.getInstance().isValidItem(material)) return;
if (!player.isSneaking()) return;
if (!((interactEntityEvent.getRightClicked() instanceof Villager) || (interactEntityEvent.getRightClicked() instanceof ZombieVillager)))
return;
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 7d82391..4ebd30f 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -40,3 +40,8 @@ workstation-highlight-color:
"BARREL": [153, 76, 0]
"LOOM": [255, 255, 255]
"STONECUTTER": [32, 32, 32]
+
+# Item Blacklist / Whitelist
+# Defaults to no items blacklisted.
+whitelist: false
+items: []
\ No newline at end of file