Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Random;
import java.util.Set;

import online.meinkraft.customvillagertrades.trade.CustomTradeManager;
import online.meinkraft.customvillagertrades.villager.VillagerData;
Expand Down Expand Up @@ -36,6 +37,8 @@ public void onVillagerAcquireTrade(VillagerAcquireTradeEvent event) {

Villager villager = (Villager) event.getEntity();

Set<String> tagSet = villager.getScoreboardTags(); // [Cruxien]: Potential addition to allow exceptions to the Disabled Vanilla Professions.

// don't allow nitwits or villagers with no profession to acquire trades
if(
villager.getProfession().equals(Villager.Profession.NONE) ||
Expand Down Expand Up @@ -63,7 +66,7 @@ public void onVillagerAcquireTrade(VillagerAcquireTradeEvent event) {
// don't allow villager to acquire vanilla trade if they are disabled
if(
!plugin.isVanillaTradesAllowed() ||
plugin.isVanillaTradesDisabledForProfession(villager.getProfession())
(plugin.isVanillaTradesDisabledForProfession(villager.getProfession()) && !tagSet.contains("cvt_trade_override"))
) {
event.setCancelled(true);
}
Expand All @@ -75,9 +78,11 @@ public void onVillagerAcquireTrade(VillagerAcquireTradeEvent event) {
if(trade != null) {
// chance of not getting the trade (if vanilla trades aren't disabled)
if(
plugin.isVanillaTradesAllowed() &&
(plugin.isVanillaTradesAllowed() &&
!plugin.isVanillaTradesDisabledForProfession(villager.getProfession()) &&
rand.nextDouble() > trade.getChance()
rand.nextDouble() > trade.getChance()) ||
tagSet.contains("cvt_trade_override") // [Cruxien] Overrides those conditions if it has the tag.
// Allows admins to include "cvt_trade_override" in the tags to allow mapmakers to use villager codes with custom trades without the plugin mistaking them for normal ones
) {
// keep vanilla trade
event.setRecipe(event.getRecipe());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import org.bukkit.Location;
import org.bukkit.World;
Expand Down Expand Up @@ -98,6 +99,7 @@ public void removeCustomTrade(Villager villager, CustomTrade trade) {
public void refreshTrades(Villager villager, Player player) {

Merchant merchant = (Merchant) villager;
Set<String> tagSet = villager.getScoreboardTags(); // [Cruxien]: Potential addition to allow exceptions to the Disabled Vanilla Professions.

VillagerManager villagerManager = plugin.getVillagerManager();
VillagerData villagerData = villagerManager.loadVillagerData(villager);
Expand Down Expand Up @@ -169,14 +171,17 @@ public void refreshTrades(Villager villager, Player player) {
}
else if(
plugin.isVanillaTradesAllowed() &&
!plugin.isVanillaTradesDisabledForProfession(villager.getProfession())
(!plugin.isVanillaTradesDisabledForProfession(villager.getProfession()) || (plugin.isVanillaTradesDisabledForProfession(villager.getProfession()) && tagSet.contains("cvt_trade_override"))) // [Cruxien]: Potential addition to allow exceptions to the Disabled Vanilla Professions.
) {
newRecipes.add(oldRecipes.get(index));
}
}

merchant.setRecipes(newRecipes);
villagerManager.saveVillagerData(villagerData);
if (!tagSet.contains("cvt_trade_override")) { // [Cruxien]: Hopefully allows the individual villager to bypass this entirely and use the trades already in its data
merchant.setRecipes(newRecipes);
villagerManager.saveVillagerData(villagerData);
}


}

Expand Down