Skip to content

Commit

Permalink
Implemented issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Reldeam committed Feb 10, 2022
1 parent 495507c commit 2911151
Showing 1 changed file with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package online.meinkraft.customvillagertrades.trade;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -110,7 +111,7 @@ public void refreshTrades(Villager villager, Player player) {
List<CustomTrade> validCustomTrades;
try {
if(plugin.forgetInvalidCustomTrades()) {
validCustomTrades = getValidTrades(villager, villagerData, true);
validCustomTrades = getValidTrades(villager, villagerData, false, true);
}
else {
validCustomTrades = new ArrayList<>();
Expand Down Expand Up @@ -182,7 +183,14 @@ public void refreshTrades(Villager villager) {
refreshTrades(villager, null);
}

public List<CustomTrade> getValidTrades(Villager villager, VillagerData villagerData, boolean ingoreDuplicates) throws VillagerNotMerchantException {


public List<CustomTrade> getValidTrades(
Villager villager,
VillagerData villagerData,
boolean strictLevel,
boolean ingoreDuplicates
) throws VillagerNotMerchantException {

List<CustomTrade> validTrades = new ArrayList<>();

Expand All @@ -209,13 +217,26 @@ public List<CustomTrade> getValidTrades(Villager villager, VillagerData villager
}

// trader must have the right level(s)
// if strictLevels (default is true) then they must have the exact
// level requirement
if(
levels.size() > 0 &&
strictLevel &&
!levels.contains(villager.getVillagerLevel())
) {
continue;
}

// if not strictLevel (default is true) then villager must have at
// least the level of the minimum level in levels
if(
levels.size() > 0 &&
!strictLevel &&
villager.getVillagerLevel() < Collections.min(levels)
) {
continue;
}

// trader must be of the right type(s)
if(
villagerTypes.size() > 0 &&
Expand Down Expand Up @@ -255,6 +276,14 @@ public List<CustomTrade> getValidTrades(Villager villager, VillagerData villager

}

public List<CustomTrade> getValidTrades(
Villager villager,
VillagerData villagerData,
boolean ingoreDuplicates
) throws VillagerNotMerchantException {
return getValidTrades(villager, villagerData, true, ingoreDuplicates);
}

public List<CustomTrade> getValidTrades(Villager villager, VillagerData villagerData) throws VillagerNotMerchantException {
return getValidTrades(villager, villagerData, false);
}
Expand Down

0 comments on commit 2911151

Please sign in to comment.