Skip to content

Commit 66982e6

Browse files
authored
Merge pull request #18 from ADHDMC/enum-declaration-done-right
Code cleanup, make sure merges worked properly, fix enum declarations
2 parents 8cd756c + a74f55f commit 66982e6

15 files changed

Lines changed: 286 additions & 256 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.0</version>
9+
<version>2.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>VillagerInfo</name>

src/main/java/adhdmc/villagerinfo/Commands/CommandHandler.java

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

33
import adhdmc.villagerinfo.Config.ConfigValidator;
4+
import adhdmc.villagerinfo.Config.Message;
45
import adhdmc.villagerinfo.VillagerInfo;
56
import net.kyori.adventure.text.minimessage.MiniMessage;
67
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
@@ -14,8 +15,7 @@
1415
public class CommandHandler implements CommandExecutor, TabExecutor {
1516

1617
public static HashMap<String, SubCommand> subcommandList = new HashMap<>();
17-
Map<ConfigValidator.Message, String> msgs = ConfigValidator.getLocaleMap();
18-
MiniMessage mM = MiniMessage.miniMessage();
18+
MiniMessage miniMessage = VillagerInfo.getMiniMessage();
1919

2020
//TY Peashooter101
2121
@Override
@@ -32,14 +32,14 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
3232
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
3333
//Checking for arguments
3434
if (args.length == 0) {
35-
String url = VillagerInfo.plugin.getDescription().getWebsite();
36-
String version = VillagerInfo.plugin.getDescription().getVersion();
35+
String url = VillagerInfo.getInstance().getDescription().getWebsite();
36+
String version = VillagerInfo.getInstance().getDescription().getVersion();
3737
List<String> authors = new ArrayList<>();
38-
for (String authorName : VillagerInfo.plugin.getDescription().getAuthors()) {
38+
for (String authorName : VillagerInfo.getInstance().getDescription().getAuthors()) {
3939
authors.add(String.format("<gold> %s </gold>", authorName));
4040
}
4141
String authorsString = String.join(" | ", authors);
42-
sender.sendMessage(mM.deserialize(
42+
sender.sendMessage(miniMessage.deserialize(
4343
"<green><click:open_url:'<url>'><hover:show_text:'<gray>Click here to visit the GitHub!'>VillagerInfo | Version:<version> </hover></click>\nAuthors: <authors>",
4444
Placeholder.parsed("version", version),
4545
Placeholder.parsed("authors", authorsString),
@@ -53,7 +53,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
5353
if (subcommandList.containsKey(command)) {
5454
subcommandList.get(command).execute(sender, Arrays.copyOfRange(args, 1, args.length));
5555
} else {
56-
sender.sendMessage(mM.deserialize(msgs.get(ConfigValidator.Message.NO_COMMAND)));
56+
sender.sendMessage(miniMessage.deserialize(Message.NO_COMMAND.getMessage()));
5757
}
5858
return true;
5959
}

src/main/java/adhdmc/villagerinfo/Commands/SubCommands/HelpCommand.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package adhdmc.villagerinfo.Commands.SubCommands;
22

33
import adhdmc.villagerinfo.Commands.SubCommand;
4-
import adhdmc.villagerinfo.Config.ConfigValidator;
5-
import adhdmc.villagerinfo.Config.ConfigValidator.Message;
4+
import adhdmc.villagerinfo.Config.Message;
5+
import adhdmc.villagerinfo.Config.Perms;
66
import adhdmc.villagerinfo.VillagerInfo;
77
import net.kyori.adventure.text.minimessage.MiniMessage;
88
import org.bukkit.command.CommandSender;
99

1010
import java.util.List;
11-
import java.util.Map;
1211

1312
public class HelpCommand extends SubCommand {
1413

@@ -18,17 +17,16 @@ public HelpCommand() {
1817

1918
@Override
2019
public void execute(CommandSender sender, String[] args) {
21-
Map<Message, String> msgs = ConfigValidator.getLocaleMap();
22-
MiniMessage mM = MiniMessage.miniMessage();
20+
MiniMessage miniMessage = VillagerInfo.getMiniMessage();
2321

24-
if (sender.hasPermission(VillagerInfo.usePermission)) {
25-
sender.sendMessage(mM.deserialize(msgs.get(Message.PREFIX)));
26-
sender.sendMessage(mM.deserialize(msgs.get(Message.HELP_MAIN)));
27-
sender.sendMessage(mM.deserialize(msgs.get(Message.HELP_TOGGLE)));
28-
sender.sendMessage(mM.deserialize(msgs.get(Message.HELP_RELOAD)));
22+
if (sender.hasPermission(Perms.USE.getPerm())) {
23+
sender.sendMessage(miniMessage.deserialize(Message.PREFIX.getMessage()));
24+
sender.sendMessage(miniMessage.deserialize(Message.HELP_MAIN.getMessage()));
25+
sender.sendMessage(miniMessage.deserialize(Message.HELP_TOGGLE.getMessage()));
26+
sender.sendMessage(miniMessage.deserialize(Message.HELP_RELOAD.getMessage()));
2927
return;
3028
}
31-
sender.sendMessage(mM.deserialize(msgs.get(Message.NO_PERMISSION)));
29+
sender.sendMessage(miniMessage.deserialize(Message.NO_PERMISSION.getMessage()));
3230
}
3331

3432
@Override
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package adhdmc.villagerinfo.Commands.SubCommands;
2+
3+
import adhdmc.villagerinfo.Commands.SubCommand;
4+
import org.bukkit.command.CommandSender;
5+
6+
import java.util.List;
7+
8+
public class InventoryCommand extends SubCommand {
9+
10+
11+
public InventoryCommand() {
12+
super("inv", "gets the inventory of the specified villager", "/vill inv <UUID>");
13+
}
14+
15+
16+
@Override
17+
public void execute(CommandSender sender, String[] args) {
18+
19+
}
20+
21+
@Override
22+
public List<String> getSubcommandArguments(CommandSender sender, String[] args) {
23+
return null;
24+
}
25+
}

src/main/java/adhdmc/villagerinfo/Commands/SubCommands/ReloadCommand.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import adhdmc.villagerinfo.Commands.SubCommand;
44
import adhdmc.villagerinfo.Config.ConfigValidator;
5-
import adhdmc.villagerinfo.Config.ConfigValidator.Message;
5+
import adhdmc.villagerinfo.Config.Message;
6+
import adhdmc.villagerinfo.Config.Perms;
67
import adhdmc.villagerinfo.VillagerInfo;
78
import net.kyori.adventure.text.minimessage.MiniMessage;
89
import org.bukkit.command.CommandSender;
910
import org.bukkit.entity.Player;
1011

1112
import java.util.List;
12-
import java.util.Map;
1313

1414
public class ReloadCommand extends SubCommand {
1515

@@ -20,15 +20,14 @@ public ReloadCommand() {
2020

2121
@Override
2222
public void execute(CommandSender sender, String[] args) {
23-
Map<Message, String> msgs = ConfigValidator.getLocaleMap();
24-
MiniMessage mM = MiniMessage.miniMessage();
25-
if (!(sender instanceof Player) || sender.hasPermission(VillagerInfo.reloadCommandPermission)) {
26-
VillagerInfo.plugin.reloadConfig();
27-
VillagerInfo.localeConfig.reloadConfig();
23+
MiniMessage miniMessage = VillagerInfo.getMiniMessage();
24+
if (!(sender instanceof Player) || sender.hasPermission(Perms.RELOAD.getPerm())) {
25+
VillagerInfo.getInstance().reloadConfig();
26+
VillagerInfo.getLocaleConfig().reloadConfig();
2827
ConfigValidator.configValidator();
29-
sender.sendMessage(mM.deserialize(msgs.get(Message.CONFIG_RELOADED)));
28+
sender.sendMessage(miniMessage.deserialize(Message.CONFIG_RELOADED.getMessage()));
3029
} else {
31-
sender.sendMessage(mM.deserialize(msgs.get(Message.NO_PERMISSION)));
30+
sender.sendMessage(miniMessage.deserialize((Message.NO_PERMISSION.getMessage())));
3231
}
3332
}
3433

src/main/java/adhdmc/villagerinfo/Commands/SubCommands/ToggleCommand.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package adhdmc.villagerinfo.Commands.SubCommands;
22

33
import adhdmc.villagerinfo.Commands.SubCommand;
4-
import adhdmc.villagerinfo.Config.ConfigValidator;
5-
import adhdmc.villagerinfo.Config.ConfigValidator.Message;
4+
import adhdmc.villagerinfo.Config.Message;
5+
import adhdmc.villagerinfo.Config.Perms;
66
import adhdmc.villagerinfo.VillagerInfo;
77
import net.kyori.adventure.text.minimessage.MiniMessage;
88
import org.bukkit.command.CommandSender;
@@ -11,33 +11,31 @@
1111
import org.bukkit.persistence.PersistentDataType;
1212

1313
import java.util.List;
14-
import java.util.Map;
1514

1615
public class ToggleCommand extends SubCommand {
17-
Map<Message, String> msgs = ConfigValidator.getLocaleMap();
1816

17+
MiniMessage miniMessage = VillagerInfo.getMiniMessage();
1918
public ToggleCommand() {
2019
super("toggle", "Toggles villager info on and off", "/vill toggle");
2120
}
2221

2322
@Override
2423
public void execute(CommandSender sender, String[] args) {
25-
MiniMessage mM = MiniMessage.miniMessage();
2624
if (!(sender instanceof Player)) {
27-
sender.sendMessage(mM.deserialize(msgs.get(Message.NOT_A_PLAYER)));
25+
sender.sendMessage(miniMessage.deserialize(Message.NOT_A_PLAYER.getMessage()));
2826
return;
2927
}
30-
if (!(sender.hasPermission(VillagerInfo.toggleCommandPermission))) {
31-
sender.sendMessage(mM.deserialize(msgs.get(Message.NO_PERMISSION)));
28+
if (!(sender.hasPermission(Perms.TOGGLE.getPerm()))) {
29+
sender.sendMessage(miniMessage.deserialize(Message.NO_PERMISSION.getMessage()));
3230
return;
3331
}
3432
if (toggleSetting((Player) sender)) {
35-
sender.sendMessage(mM.deserialize(msgs.get(Message.PREFIX))
36-
.append(mM.deserialize(msgs.get(Message.TOGGLE_ON))));
33+
sender.sendMessage(miniMessage.deserialize(Message.PREFIX.getMessage())
34+
.append(miniMessage.deserialize(Message.TOGGLE_ON.getMessage())));
3735
return;
3836
}
39-
sender.sendMessage(mM.deserialize(msgs.get(Message.PREFIX))
40-
.append(mM.deserialize(msgs.get(Message.TOGGLE_OFF))));
37+
sender.sendMessage(miniMessage.deserialize(Message.PREFIX.getMessage())
38+
.append(miniMessage.deserialize(Message.TOGGLE_OFF.getMessage())));
4139
}
4240

4341
private boolean toggleSetting(Player player) {

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

Lines changed: 5 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -10,164 +10,28 @@
1010
import java.util.Map;
1111

1212
public class ConfigValidator {
13-
public enum Message {
14-
// General
15-
PREFIX, TOGGLE_ON, TOGGLE_OFF, NO_PERMISSION,
16-
NO_COMMAND, CONFIG_RELOADED, HELP_MAIN, HELP_TOGGLE,
17-
HELP_RELOAD, NOT_A_PLAYER,
1813

19-
// Villager Info
20-
VILLAGER_PROFESSION, VILLAGER_JOBSITE, VILLAGER_LAST_WORKED,
21-
VILLAGER_RESTOCKS, VILLAGER_HOME, VILLAGER_SLEPT,
22-
VILLAGER_INVENTORY, INVENTORY_CONTENTS, PLAYER_REPUTATION,
23-
24-
// Fillers
25-
NONE, NEVER, EMPTY,
26-
27-
// Time
28-
HOUR, MINUTE, SECOND, AGO,
29-
30-
// Location
31-
LOCATION_X, LOCATION_Y, LOCATION_Z
32-
}
33-
34-
public enum ToggleSetting {
35-
// Information Toggles
36-
PROFESSION, JOB_SITE, LAST_WORKED, BED_LOCATION, LAST_SLEPT,
37-
INVENTORY, RESTOCKS, REPUTATION, HIGHLIGHT_WORKSTATION, SOUND_TOGGLE,
38-
}
39-
40-
private static final HashMap<Message, String> localeMap = new HashMap<>();
41-
private static final HashMap<ToggleSetting, Boolean> toggleSettings = new HashMap<>();
4214
public static Sound configSound = null;
4315
public static int configTime = 0;
4416

4517

4618
public static void configValidator() {
4719
configSound = null;
4820
configTime = 0;
49-
FileConfiguration config = VillagerInfo.plugin.getConfig();
21+
FileConfiguration config = VillagerInfo.getInstance().getConfig();
5022
try {
5123
configSound = Sound.valueOf(config.getString("sound", "BLOCK_AMETHYST_BLOCK_BREAK").toUpperCase(Locale.ROOT));
5224
} catch (IllegalArgumentException | NullPointerException e) {
53-
VillagerInfo.plugin.getLogger().warning("Configuration Error: " + configSound + " is not a valid sound! Please supply a valid sound");
25+
VillagerInfo.getInstance().getLogger().warning("Configuration Error: " + configSound + " is not a valid sound! Please supply a valid sound");
5426
configSound = Sound.BLOCK_AMETHYST_BLOCK_BREAK;
5527
}
5628
if (config.getInt("highlight-time", 10) <= 0) {
57-
VillagerInfo.plugin.getLogger().warning("Configuration Error: Invalid highlight time. If you would like to disable this feature, please set 'highlight-workstation' to 'false'. Otherwise please use an integer greater than zero. Setting value to 10s");
29+
VillagerInfo.getInstance().getLogger().warning("Configuration Error: Invalid highlight time. If you would like to disable this feature, please set 'highlight-workstation' to 'false'. Otherwise please use an integer greater than zero. Setting value to 10s");
5830
configTime = 10;
5931
} else {
6032
configTime = config.getInt("highlight-time");
6133
}
62-
loadToggleMap();
63-
loadLocaleMap();
64-
}
65-
66-
private static void loadToggleMap() {
67-
toggleSettings.clear();
68-
FileConfiguration config = VillagerInfo.plugin.getConfig();
69-
toggleSettings.put(ToggleSetting.PROFESSION,
70-
config.getBoolean("profession", true));
71-
toggleSettings.put(ToggleSetting.JOB_SITE,
72-
config.getBoolean("job-site", true));
73-
toggleSettings.put(ToggleSetting.LAST_WORKED,
74-
config.getBoolean("last-worked", true));
75-
toggleSettings.put(ToggleSetting.BED_LOCATION,
76-
config.getBoolean("bed-location", true));
77-
toggleSettings.put(ToggleSetting.LAST_SLEPT,
78-
config.getBoolean("last-slept", true));
79-
toggleSettings.put(ToggleSetting.INVENTORY,
80-
config.getBoolean("inventory", true));
81-
toggleSettings.put(ToggleSetting.RESTOCKS,
82-
config.getBoolean("restocks", true));
83-
toggleSettings.put(ToggleSetting.REPUTATION,
84-
config.getBoolean("reputation", true));
85-
toggleSettings.put(ToggleSetting.HIGHLIGHT_WORKSTATION,
86-
config.getBoolean("highlight-workstation", true));
87-
toggleSettings.put(ToggleSetting.SOUND_TOGGLE,
88-
config.getBoolean("sound-toggle", true));
34+
ToggleSetting.reloadToggles();
35+
Message.reloadLocale();
8936
}
90-
91-
private static void loadLocaleMap() {
92-
localeMap.clear();
93-
FileConfiguration locale = VillagerInfo.localeConfig.getlocaleConfig();
94-
// General
95-
localeMap.put(Message.PREFIX,
96-
locale.getString("prefix", "<#3256a8><bold>[</bold><#4dd5ff>Villager Info<#3256a8><bold>]<reset>"));
97-
localeMap.put(Message.TOGGLE_ON,
98-
locale.getString("toggle-on", "<green> Villager Info Toggled <u>ON"));
99-
localeMap.put(Message.TOGGLE_OFF,
100-
locale.getString("toggle-off", "<red> Villager Info Toggled <u>OFF"));
101-
localeMap.put(Message.NO_PERMISSION,
102-
locale.getString("no-permission", "<red>You don't have permission to use this command!"));
103-
104-
// Commands
105-
localeMap.put(Message.NO_COMMAND,
106-
locale.getString("no-command", "<red>No subcommand by that name!"));
107-
localeMap.put(Message.CONFIG_RELOADED,
108-
locale.getString("config-reloaded", "<gold>VillagerInfo Config Reloaded!"));
109-
localeMap.put(Message.HELP_MAIN,
110-
locale.getString("help-main", "<#4dd5ff> • How to use Villager Info\n<grey>Shift-right-click a villager while toggle is on to have a villager's information displayed"));
111-
localeMap.put(Message.HELP_TOGGLE,
112-
locale.getString("help-toggle", "<#4dd5ff> • /vill toggle\n<grey>Toggles the ability to receive villager information on or off."));
113-
localeMap.put(Message.HELP_RELOAD,
114-
locale.getString("help-reload", "<#4dd5ff> • /vill reload\n<grey>Reloads the plugin, applies config values"));
115-
localeMap.put(Message.NOT_A_PLAYER,
116-
locale.getString("not-a-player", "<red>Sorry, you must be a player to use this command"));
117-
118-
// Villager Info
119-
localeMap.put(Message.VILLAGER_PROFESSION,
120-
locale.getString("villager-profession", "<green>PROFESSION:\n<aqua> • <profession>"));
121-
localeMap.put(Message.VILLAGER_JOBSITE,
122-
locale.getString("villager-jobsite-msg", "<green>JOB SITE:\n<aqua> • <jobsitelocation>"));
123-
localeMap.put(Message.VILLAGER_LAST_WORKED,
124-
locale.getString("villager-last-worked-msg", "<green>LAST WORKED AT WORKSTATION:\n<aqua> • <worktime>"));
125-
localeMap.put(Message.VILLAGER_RESTOCKS,
126-
locale.getString("villager-num-restocks-msg", "<green>RESTOCKS TODAY:\n<aqua> • <restockcount>"));
127-
localeMap.put(Message.VILLAGER_HOME,
128-
locale.getString("villager-home-msg", "<green>HOME:\n<aqua> • <homelocation>"));
129-
localeMap.put(Message.VILLAGER_SLEPT,
130-
locale.getString("villager-slept-msg", "<green>LAST SLEPT:\n<aqua> • <sleeptime>"));
131-
localeMap.put(Message.VILLAGER_INVENTORY,
132-
locale.getString("villager-inventory-msg", "<green>VILLAGER INVENTORY:<aqua> <contents>"));
133-
localeMap.put(Message.INVENTORY_CONTENTS,
134-
locale.getString("inventory-contents-msg", "\n • <item> (<amount>)"));
135-
localeMap.put(Message.PLAYER_REPUTATION,
136-
locale.getString("player-reputation-msg", "<green>PLAYER REPUTATION:\n<reputation>"));
137-
138-
// Fillers
139-
localeMap.put(Message.NONE,
140-
locale.getString("none-msg", "<grey>NONE"));
141-
localeMap.put(Message.NEVER,
142-
locale.getString("never-msg", "<grey>NEVER"));
143-
localeMap.put(Message.EMPTY,
144-
locale.getString("empty-msg", "\n • <grey>EMPTY"));
145-
146-
// Time
147-
localeMap.put(Message.HOUR,
148-
locale.getString("hour", "h, "));
149-
localeMap.put(Message.MINUTE,
150-
locale.getString("minute", "m, "));
151-
localeMap.put(Message.SECOND,
152-
locale.getString("second", "s"));
153-
localeMap.put(Message.AGO,
154-
locale.getString("ago", " Ago"));
155-
156-
// Location
157-
localeMap.put(Message.LOCATION_X,
158-
locale.getString("location-x", "<int>x, "));
159-
localeMap.put(Message.LOCATION_Y,
160-
locale.getString("location-y", "<int>y, "));
161-
localeMap.put(Message.LOCATION_Z,
162-
locale.getString("location-z", "<int>z"));
163-
}
164-
165-
public static Map<Message, String> getLocaleMap() {
166-
return Collections.unmodifiableMap(localeMap);
167-
}
168-
169-
public static Map<ToggleSetting, Boolean> getToggleSettings() {
170-
return Collections.unmodifiableMap(toggleSettings);
171-
}
172-
17337
}

0 commit comments

Comments
 (0)