Skip to content

Commit

Permalink
Added Item Configuration, Bump Version
Browse files Browse the repository at this point in the history
Added item configuration for whitelist / blacklisting items for Issue #27

Tested and Confirmed on 1.21
  • Loading branch information
Peashooter101 committed Jul 17, 2024
1 parent 35ec569 commit c7078b4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>simplexity</groupId>
<artifactId>VillagerInfo</artifactId>
<version>4.0.1</version>
<version>4.1.0</version>
<packaging>jar</packaging>

<name>VillagerInfo</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public static VillConfig getInstance() {
private final HashMap<Material, Color> poiBlockHighlightColorsMap = new HashMap<>();
String error = ServerMessage.CONFIGURATION_ERROR_PREFIX.getMessage();

private boolean isWhitelist;
private Set<Material> itemSet = new HashSet<>();

private final Logger logger = VillagerInfo.getInstance().getVillagerInfoLogger();

public void reloadVillConfig(FileConfiguration config) {
Expand All @@ -38,6 +41,7 @@ public void reloadVillConfig(FileConfiguration config) {
reloadHighlightTime(config);
reloadToggles(config);
reloadColors(config);
reloadItemList(config);
}

public void reloadSound(FileConfiguration config) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -147,4 +164,8 @@ public float getConfiguredSoundVolume() {
public Map<Material, Color> getPoiBlockHighlightColorsMap() {
return Collections.unmodifiableMap(poiBlockHighlightColorsMap);
}

public boolean isValidItem(Material material) {
return itemSet.contains(material) == isWhitelist;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []

0 comments on commit c7078b4

Please sign in to comment.