Skip to content

Commit 575fde2

Browse files
committed
Add 'conversion time', fix sound not working
1 parent c8326c7 commit 575fde2

8 files changed

Lines changed: 79 additions & 8 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ADHDMC</groupId>
88
<artifactId>VillagerInfo</artifactId>
9-
<version>2.3</version>
9+
<version>2.4</version>
1010
<packaging>jar</packaging>
1111

1212
<name>VillagerInfo</name>

src/main/java/adhdmc/villagerinfo/Config/ConfigValidator.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
public class ConfigValidator {
1313

14-
public static Sound configSound = null;
15-
public static int configTime = 0;
14+
private static Sound configSound = null;
15+
private static int configTime = 0;
16+
private static float soundVolume = 0;
17+
private static float soundPitch = 0;
1618

1719

1820
public static void configValidator() {
1921
configSound = null;
2022
configTime = 0;
23+
soundVolume = 0;
24+
soundPitch = 0;
2125
FileConfiguration config = VillagerInfo.getInstance().getConfig();
2226
try {
2327
configSound = Sound.valueOf(config.getString("sound", "BLOCK_AMETHYST_BLOCK_BREAK").toUpperCase(Locale.ROOT));
@@ -31,7 +35,37 @@ public static void configValidator() {
3135
} else {
3236
configTime = config.getInt("highlight-time");
3337
}
38+
if (0 < config.getDouble("sound-volume") && config.getDouble("sound-volume") < 2) {
39+
soundVolume = (float) config.getDouble("sound-volume");
40+
} else {
41+
VillagerInfo.getInstance().getLogger().warning("Configuration Error: 'sound-volume' must be between 0.0 and 2.0. " +
42+
"Setting to 0.5 until a valid number is provided");
43+
soundVolume = 0.5F;
44+
}
45+
if (0 < config.getDouble("sound-pitch") && config.getDouble("sound-pitch") < 2) {
46+
soundPitch = (float) config.getDouble("sound-pitch");
47+
} else {
48+
VillagerInfo.getInstance().getLogger().warning("Configuration Error: 'sound-pitch' must be between 0.0 and 2.0. " +
49+
"Setting to 1.5 until a valid number is provided");
50+
soundPitch = 1.5F;
51+
}
3452
ToggleSetting.reloadToggles();
3553
Message.reloadLocale();
3654
}
55+
56+
public static float getSoundPitch() {
57+
return soundPitch;
58+
}
59+
60+
public static float getSoundVolume() {
61+
return soundVolume;
62+
}
63+
64+
public static int getConfigTime() {
65+
return configTime;
66+
}
67+
68+
public static Sound getConfigSound() {
69+
return configSound;
70+
}
3771
}

src/main/java/adhdmc/villagerinfo/Config/Defaults.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public static void localeDefaults() {
1717
locale.addDefault("help-toggle", "<#4dd5ff> • /vill toggle\n<grey>Toggles the ability to receive villager information on or off.");
1818
locale.addDefault("help-reload", "<#4dd5ff> • /vill reload\n<grey>Reloads the plugin, applies config values");
1919
locale.addDefault("not-a-player", "<red>Sorry, you must be a player to use this command");
20+
locale.addDefault("zombie-villager-conversion-time", "<green>TIME UNTIL CONVERTED: \n<aqua> • <time>");
21+
locale.addDefault("villager-age", "<green>TIME UNTIL ADULT: \n<aqua> • <age>");
2022
locale.addDefault("villager-profession", "<green>PROFESSION:\n<aqua> • <profession>");
2123
locale.addDefault("villager-jobsite-msg", "<green>JOB SITE:\n<aqua> • <jobsitelocation>");
2224
locale.addDefault("villager-last-worked-msg", "<green>LAST WORKED AT WORKSTATION:\n<aqua> • <worktime>");
@@ -29,6 +31,7 @@ public static void localeDefaults() {
2931
locale.addDefault("none-msg", "<grey>NONE");
3032
locale.addDefault("never-msg", "<grey>NEVER");
3133
locale.addDefault("empty-msg", "\n • <grey>EMPTY");
34+
locale.addDefault("no-information", "<grey>No information to display on this villager");
3235
locale.addDefault("hour", "h, ");
3336
locale.addDefault("minute", "m, ");
3437
locale.addDefault("second", "s");
@@ -41,6 +44,7 @@ public static void localeDefaults() {
4144
public static void configDefaults() {
4245
FileConfiguration config = VillagerInfo.getInstance().getConfig();
4346
config.addDefault("baby-age", true);
47+
config.addDefault("zombie-conversion", true);
4448
config.addDefault("profession", true);
4549
config.addDefault("job-site", true);
4650
config.addDefault("last-worked", true);
@@ -52,6 +56,8 @@ public static void configDefaults() {
5256
config.addDefault("highlight-workstation", true);
5357
config.addDefault("sound-toggle", true);
5458
config.addDefault("sound", "BLOCK_AMETHYST_BLOCK_BREAK");
59+
config.addDefault("sound-volume", 0.5);
60+
config.addDefault("sound-pitch", 1.5);
5561
config.addDefault("highlight-time", 10);
5662
}
5763

src/main/java/adhdmc/villagerinfo/Config/Message.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public enum Message {
1717
NOT_A_PLAYER("<red>Sorry, you must be a player to use this command"),
1818

1919
// Villager Info
20+
ZOMBIE_VILLAGER_CONVERSION_TIME("<green>TIME UNTIL CONVERTED: \n<aqua> • <time>"),
2021
VILLAGER_AGE("<green>TIME UNTIL ADULT: \n<aqua> • <age>"),
2122
VILLAGER_PROFESSION("<green>PROFESSION:\n<aqua> • <profession>"),
2223
VILLAGER_JOBSITE("<green>JOB SITE:\n<aqua> • <jobsitelocation>"),
@@ -30,6 +31,7 @@ public enum Message {
3031

3132
// Fillers
3233
NONE("<grey>NONE"), NEVER("<grey>NEVER"), EMPTY("\n • <grey>EMPTY"),
34+
NO_INFORMATION("<grey>No information to display on this villager"),
3335

3436
// Time
3537
HOUR("h, "), MINUTE("m, "), SECOND("s"), AGO(" Ago"),
@@ -60,6 +62,7 @@ public static void reloadLocale() {
6062
HELP_RELOAD.setMessage(locale.getString("help-reload", "<#4dd5ff> • /vill reload\n<grey>Reloads the plugin, applies config values"));
6163
NOT_A_PLAYER.setMessage(locale.getString("not-a-player", "<red>Sorry, you must be a player to use this command"));
6264
// Villager Info
65+
ZOMBIE_VILLAGER_CONVERSION_TIME.setMessage(locale.getString("zombie-villager-conversion-time", "<green>TIME UNTIL CONVERTED: \n<aqua> • <time>"));
6366
VILLAGER_AGE.setMessage(locale.getString("villager-age", "<green>TIME UNTIL ADULT: \n<aqua> • <age>"));
6467
VILLAGER_PROFESSION.setMessage(locale.getString("villager-profession", "<green>PROFESSION:\n<aqua> • <profession>"));
6568
VILLAGER_JOBSITE.setMessage(locale.getString("villager-jobsite-msg", "<green>JOB SITE:\n<aqua> • <jobsitelocation>"));
@@ -74,6 +77,8 @@ public static void reloadLocale() {
7477
NONE.setMessage(locale.getString("none-msg", "<grey>NONE"));
7578
NEVER.setMessage(locale.getString("never-msg", "<grey>NEVER"));
7679
EMPTY.setMessage(locale.getString("empty-msg", "\n • <grey>EMPTY"));
80+
NO_INFORMATION.setMessage(locale.getString("no-information", "<grey>No information to display on this villager"));
81+
7782
// Time
7883
HOUR.setMessage(locale.getString("hour", "h, "));
7984
MINUTE.setMessage(locale.getString("minute", "m, "));

src/main/java/adhdmc/villagerinfo/Config/ToggleSetting.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
public enum ToggleSetting {
77
BABY_AGE(true),
8+
ZOMBIE_CONVERSION(true),
89
PROFESSION(true),
910
JOB_SITE(true),
1011
LAST_WORKED(true),
@@ -25,6 +26,7 @@ public enum ToggleSetting {
2526
public static void reloadToggles() {
2627
FileConfiguration config = VillagerInfo.getInstance().getConfig();
2728
BABY_AGE.setEnabled(config.getBoolean("baby-age", true));
29+
ZOMBIE_CONVERSION.setEnabled(config.getBoolean("zombie-conversion", true));
2830
PROFESSION.setEnabled(config.getBoolean("profession", true));
2931
JOB_SITE.setEnabled(config.getBoolean("job-site", true));
3032
LAST_WORKED.setEnabled(config.getBoolean("last-worked", true));

src/main/java/adhdmc/villagerinfo/VillagerHandling/HighlightHandling.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static void villagerJobsiteHighlight(PersistentDataContainer villPDC, UUI
3535
killFallingBlock(villUUID);
3636
villPDC.set(VillagerInfo.HIGHLIGHT_STATUS, PersistentDataType.BYTE, (byte)0);
3737
VILLAGER_PDC.put(villUUID, villPDC);
38-
}, 20L * ConfigValidator.configTime);
38+
}, 20L * ConfigValidator.getConfigTime());
3939
}
4040

4141
/**

src/main/java/adhdmc/villagerinfo/VillagerHandling/VillagerHandler.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package adhdmc.villagerinfo.VillagerHandling;
22

3+
import adhdmc.villagerinfo.Config.ConfigValidator;
34
import adhdmc.villagerinfo.Config.Message;
45
import adhdmc.villagerinfo.Config.Perms;
56
import adhdmc.villagerinfo.Config.ToggleSetting;
@@ -120,7 +121,12 @@ private void processVillager(Player player, Villager villager) {
120121
}
121122
//Messages
122123
Component prefix = miniMessage.deserialize(Message.PREFIX.getMessage());
124+
player.playSound(player.getLocation(), ConfigValidator.getConfigSound(), ConfigValidator.getSoundVolume(), ConfigValidator.getSoundPitch());
123125
player.sendMessage(prefix);
126+
if (messageList.size() == 0) {
127+
player.sendMessage(miniMessage.deserialize(Message.NO_INFORMATION.getMessage()));
128+
return;
129+
}
124130
for (Component component : messageList) {
125131
player.sendMessage(component);
126132
}
@@ -129,27 +135,38 @@ private void processVillager(Player player, Villager villager) {
129135
private void processZombieVillager(Player player, ZombieVillager zombieVillager) {
130136
ArrayList<Component> messageList = new ArrayList<>();
131137
boolean isAdult = zombieVillager.isAdult();
132-
//time until adult
133-
if (ToggleSetting.BABY_AGE.isEnabled() && !isAdult) {
134-
messageList.add(timeTillAdult(zombieVillager));
135-
}
136138
//profession
137139
if (ToggleSetting.PROFESSION.isEnabled() && isAdult) {
138140
messageList.add(villagerProfession(zombieVillager.getVillagerProfession()));
139141
}
142+
//time until converted
143+
if (ToggleSetting.ZOMBIE_CONVERSION.isEnabled() && zombieVillager.isConverting()) {
144+
messageList.add(timeTillConverted(zombieVillager));
145+
}
140146
//reputation
141147
// TODO: wait for Reputation API to be added for Zombie Villagers or use PDC to calculate reputation NBT by hand
142148
//if (ToggleSetting.REPUTATION.isEnabled()) {
143149
// messageList.add(villagerPlayerReputation(zombieVillager.getReputation(player.getUniqueId())));
144150
//}
145151
//Messages
146152
Component prefix = miniMessage.deserialize(Message.PREFIX.getMessage());
153+
player.playSound(player.getLocation(), ConfigValidator.getConfigSound(), ConfigValidator.getSoundVolume(), ConfigValidator.getSoundPitch());
147154
player.sendMessage(prefix);
155+
if (messageList.size() == 0) {
156+
player.sendMessage(miniMessage.deserialize(Message.NO_INFORMATION.getMessage()));
157+
return;
158+
}
148159
for (Component component : messageList) {
149160
player.sendMessage(component);
150161
}
151162
}
152163

164+
private Component timeTillConverted(ZombieVillager zombieVillager){
165+
long converstionTime = zombieVillager.getConversionTime();
166+
String timeCalc = timeMath(converstionTime);
167+
return miniMessage.deserialize(Message.ZOMBIE_VILLAGER_CONVERSION_TIME.getMessage(), Placeholder.unparsed("time", timeCalc));
168+
}
169+
153170
/**
154171
* Checks and returns formatted 'time till adult' message component
155172
* @param ageable Clicked Villager
@@ -159,6 +176,9 @@ private Component timeTillAdult(Ageable ageable) {
159176
Component timeTillAdultFinal;
160177
long age = ageable.getAge();
161178
age = age * -1;
179+
if (age == 0) {
180+
return null;
181+
}
162182
String timeCalc = timeMath(age);
163183
timeTillAdultFinal = miniMessage.deserialize(Message.VILLAGER_AGE.getMessage(), Placeholder.unparsed("age", timeCalc));
164184
return timeTillAdultFinal;

src/main/resources/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#Information Toggles
44
#True to enable the information to display when requested, false for it not to display
55
baby-age: true
6+
zombie-conversion: true
67
profession: true
78
job-site: true
89
last-worked: true
@@ -14,6 +15,9 @@ reputation: true
1415
highlight-workstation: true
1516
sound-toggle: true
1617
#Sound must be from this list https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html
18+
#Volume and pitch can range from 0.0-2.0
1719
sound: BLOCK_AMETHYST_BLOCK_BREAK
20+
sound-volume: 0.5
21+
sound-pitch: 1.5
1822
#Length of time to highlight the villager's workstation (if enabled)
1923
highlight-time: 10

0 commit comments

Comments
 (0)