Skip to content

Commit

Permalink
Adds option to see how long until a baby villager will grow up
Browse files Browse the repository at this point in the history
  • Loading branch information
RhythmicSys committed Oct 12, 2022
1 parent 66982e6 commit 5f289b4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
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>ADHDMC</groupId>
<artifactId>VillagerInfo</artifactId>
<version>2.1</version>
<version>2.2</version>
<packaging>jar</packaging>

<name>VillagerInfo</name>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/adhdmc/villagerinfo/Config/Defaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void localeDefaults() {

public static void configDefaults() {
FileConfiguration config = VillagerInfo.getInstance().getConfig();
config.addDefault("baby-age", true);
config.addDefault("profession", true);
config.addDefault("job-site", true);
config.addDefault("last-worked", true);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/adhdmc/villagerinfo/Config/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum Message {
NOT_A_PLAYER("<red>Sorry, you must be a player to use this command"),

// Villager Info
VILLAGER_AGE("<green>TIME UNTIL ADULT: \n<aqua> • <age>"),
VILLAGER_PROFESSION("<green>PROFESSION:\n<aqua> • <profession>"),
VILLAGER_JOBSITE("<green>JOB SITE:\n<aqua> • <jobsitelocation>"),
VILLAGER_LAST_WORKED("<green>LAST WORKED AT WORKSTATION:\n<aqua> • <worktime>"),
Expand Down Expand Up @@ -59,6 +60,7 @@ public static void reloadLocale() {
HELP_RELOAD.setMessage(locale.getString("help-reload", "<#4dd5ff> • /vill reload\n<grey>Reloads the plugin, applies config values"));
NOT_A_PLAYER.setMessage(locale.getString("not-a-player", "<red>Sorry, you must be a player to use this command"));
// Villager Info
VILLAGER_AGE.setMessage(locale.getString("villager-age", "<green>TIME UNTIL ADULT: \n<aqua> • <age>"));
VILLAGER_PROFESSION.setMessage(locale.getString("villager-profession", "<green>PROFESSION:\n<aqua> • <profession>"));
VILLAGER_JOBSITE.setMessage(locale.getString("villager-jobsite-msg", "<green>JOB SITE:\n<aqua> • <jobsitelocation>"));
VILLAGER_LAST_WORKED.setMessage(locale.getString("villager-last-worked-msg", "<green>LAST WORKED AT WORKSTATION:\n<aqua> • <worktime>"));
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/adhdmc/villagerinfo/Config/ToggleSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.configuration.file.FileConfiguration;

public enum ToggleSetting {
BABY_AGE(true),
PROFESSION(true),
JOB_SITE(true),
LAST_WORKED(true),
Expand All @@ -23,6 +24,7 @@ public enum ToggleSetting {

public static void reloadToggles() {
FileConfiguration config = VillagerInfo.getInstance().getConfig();
BABY_AGE.setEnabled(config.getBoolean("baby-age", true));
PROFESSION.setEnabled(config.getBoolean("profession", true));
JOB_SITE.setEnabled(config.getBoolean("job-site", true));
LAST_WORKED.setEnabled(config.getBoolean("last-worked", true));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package adhdmc.villagerinfo.VillagerHandling;

import adhdmc.villagerinfo.Config.ConfigValidator;
import adhdmc.villagerinfo.Config.Message;
import adhdmc.villagerinfo.Config.Perms;
import adhdmc.villagerinfo.Config.ToggleSetting;
Expand All @@ -25,7 +24,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;

public class VillagerHandler implements Listener {
Expand Down Expand Up @@ -65,6 +63,10 @@ public void onVillagerClick(PlayerInteractEntityEvent event) {
boolean hasWorkSite = villager.getMemory(MemoryKey.JOB_SITE) != null;
boolean hasBed = villager.getMemory(MemoryKey.HOME) != null;
boolean isAdult = villager.isAdult();
//time until adult
if (ToggleSetting.BABY_AGE.isEnabled() && !isAdult) {
messageList.add(villagerTimeTillAdult(villager));
}
//profession
if (ToggleSetting.PROFESSION.isEnabled() && isAdult) {
messageList.add(villagerProfession(villager));
Expand Down Expand Up @@ -111,6 +113,16 @@ public void onVillagerClick(PlayerInteractEntityEvent event) {
}
}

private Component villagerTimeTillAdult(Villager villager) {
Component timeTillAdultFinal;
long villAge = villager.getAge();
villAge = villAge * -1;
VillagerInfo.getInstance().getLogger().info("" + villAge);
String timeCalc = timeMath(villAge);
timeTillAdultFinal = miniMessage.deserialize(Message.VILLAGER_AGE.getMessage(), Placeholder.unparsed("age", timeCalc));
return timeTillAdultFinal;
}

private Component villagerProfession(Villager villager) {
Component professionFinal;
String villagerProfessionString = villager.getProfession().toString();
Expand Down Expand Up @@ -149,7 +161,7 @@ private Component villagerLastWorked(Villager villager) {
Placeholder.parsed("worktime", Message.NEVER.getMessage()));
} else {
Long timeSinceWorked = villager.getWorld().getGameTime() - lastWorked;
String formattedTime = timeMath(timeSinceWorked);
String formattedTime = timeMath(timeSinceWorked) + Message.AGO.getMessage();
villagerLastWorkedFinal = miniMessage.deserialize(Message.VILLAGER_LAST_WORKED.getMessage(),
Placeholder.unparsed("worktime", formattedTime));
}
Expand Down Expand Up @@ -183,7 +195,7 @@ private Component villagerLastSlept(Villager villager) {
Placeholder.parsed("sleeptime", Message.NEVER.getMessage()));
} else {
Long timeSinceSlept = villager.getWorld().getGameTime() - lastSlept;
String formattedTime = timeMath(timeSinceSlept);
String formattedTime = timeMath(timeSinceSlept) + Message.AGO.getMessage() ;
villagerLastSleptFinal = miniMessage.deserialize(Message.VILLAGER_SLEPT.getMessage(),
Placeholder.unparsed("sleeptime", formattedTime));
}
Expand Down Expand Up @@ -252,10 +264,8 @@ private String timeMath(Long mathTime) {
if (mathTimeC > 0) mathResult += mathTimeC + Message.MINUTE.getMessage();
if (mathTimeD > 0) mathResult += mathTimeD + Message.SECOND.getMessage();
if (mathResult.isEmpty()) {
mathResult += "0" + Message.SECOND.getMessage() + Message.AGO.getMessage();
return mathResult;
mathResult += "0" + Message.SECOND.getMessage();
}
mathResult += Message.AGO.getMessage();
return mathResult;
}
}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#Information Toggles
#True to enable the information to display when requested, false for it not to display
baby-age: true
profession: true
job-site: true
last-worked: true
Expand Down

0 comments on commit 5f289b4

Please sign in to comment.