Skip to content

Commit

Permalink
Add configuration for wandering trader drop
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisTestUser committed Jan 27, 2023
1 parent 71a4770 commit 86114fb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
Expand Down
3 changes: 3 additions & 0 deletions docs/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ placeholder:

```yml
miscellaneous:
# Percent chance of the wandering trader would drop a book.
trader-drop-chance: 0.1
# Maximum number of ongoing large raids permitted at any point in time. Set to 0 for no limit.
max-raids: 0
# Whether ringing of bell will outline every single raider in the raid, regardless of distance
Expand Down Expand Up @@ -325,6 +327,7 @@ placeholder:
not-in-range-string: Not In Range
miscellaneous:
trader-drop-chance: 0.1
max-raids: 0
bell-outline-raiders:
normal-raid: false
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/solarrabbit/largeraids/LargeRaids.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void onEnable() {
bossbarCreator.init(this);
getServer().getPluginManager().registerEvents(bossbarCreator, this);
BookGenerator bookGen = new BookGenerator(this.getResource("traderbook.yml"));
getServer().getPluginManager().registerEvents(new TraderBookListener(bookGen), this);
getServer().getPluginManager().registerEvents(new TraderBookListener(bookGen, this), this);

// Additional listeners for custom mobs
mobManagers = new MobManagers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
import org.bukkit.configuration.ConfigurationSection;

public class MiscConfig {
private final double traderDropChance;
private final int maxRaids;
private final boolean shouldBellOutlineNormal;
private final boolean shouldBellOutlineLarge;
private final int bellOutlineDuration;

public MiscConfig(ConfigurationSection config) {
traderDropChance = config.getDouble("trader-drop-chance");
maxRaids = config.getInt("max-raids");
ConfigurationSection bellOutlineConfig = config.getConfigurationSection("bell-outline-raiders");
shouldBellOutlineNormal = bellOutlineConfig.getBoolean("normal-raid");
shouldBellOutlineLarge = bellOutlineConfig.getBoolean("large-raid");
bellOutlineDuration = bellOutlineConfig.getInt("duration");
}

public double getTraderDropChance() {
return traderDropChance;
}

public int getMaxRaid() {
return maxRaids;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;

import com.solarrabbit.largeraids.LargeRaids;

public class TraderBookListener implements Listener {
private static final double DROP_CHANCE = 0.1f;
private final BookGenerator bookGen;
private final LargeRaids plugin;

public TraderBookListener(BookGenerator bookGen) {
public TraderBookListener(BookGenerator bookGen, LargeRaids plugin) {
this.bookGen = bookGen;
this.plugin = plugin;
}

@EventHandler
Expand All @@ -24,6 +27,6 @@ public void onTraderDeath(EntityDeathEvent evt) {
}

private boolean hasDrop() {
return Math.random() <= DROP_CHANCE;
return Math.random() < plugin.getMiscConfig().getTraderDropChance();
}
}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ placeholder:
not-in-range-string: Not In Range

miscellaneous:
trader-drop-chance: 0.1
max-raids: 0
bell-outline-raiders:
normal-raid: false
Expand Down

0 comments on commit 86114fb

Please sign in to comment.