Skip to content

Commit

Permalink
Merge pull request #18 from ADHDMC/enum-declaration-done-right
Browse files Browse the repository at this point in the history
Code cleanup, make sure merges worked properly, fix enum declarations
  • Loading branch information
RhythmicSys authored Oct 6, 2022
2 parents 8cd756c + a74f55f commit 66982e6
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 256 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.0</version>
<version>2.1</version>
<packaging>jar</packaging>

<name>VillagerInfo</name>
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/adhdmc/villagerinfo/Commands/CommandHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package adhdmc.villagerinfo.Commands;

import adhdmc.villagerinfo.Config.ConfigValidator;
import adhdmc.villagerinfo.Config.Message;
import adhdmc.villagerinfo.VillagerInfo;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
Expand All @@ -14,8 +15,7 @@
public class CommandHandler implements CommandExecutor, TabExecutor {

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

//TY Peashooter101
@Override
Expand All @@ -32,14 +32,14 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
//Checking for arguments
if (args.length == 0) {
String url = VillagerInfo.plugin.getDescription().getWebsite();
String version = VillagerInfo.plugin.getDescription().getVersion();
String url = VillagerInfo.getInstance().getDescription().getWebsite();
String version = VillagerInfo.getInstance().getDescription().getVersion();
List<String> authors = new ArrayList<>();
for (String authorName : VillagerInfo.plugin.getDescription().getAuthors()) {
for (String authorName : VillagerInfo.getInstance().getDescription().getAuthors()) {
authors.add(String.format("<gold> %s </gold>", authorName));
}
String authorsString = String.join(" | ", authors);
sender.sendMessage(mM.deserialize(
sender.sendMessage(miniMessage.deserialize(
"<green><click:open_url:'<url>'><hover:show_text:'<gray>Click here to visit the GitHub!'>VillagerInfo | Version:<version> </hover></click>\nAuthors: <authors>",
Placeholder.parsed("version", version),
Placeholder.parsed("authors", authorsString),
Expand All @@ -53,7 +53,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (subcommandList.containsKey(command)) {
subcommandList.get(command).execute(sender, Arrays.copyOfRange(args, 1, args.length));
} else {
sender.sendMessage(mM.deserialize(msgs.get(ConfigValidator.Message.NO_COMMAND)));
sender.sendMessage(miniMessage.deserialize(Message.NO_COMMAND.getMessage()));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package adhdmc.villagerinfo.Commands.SubCommands;

import adhdmc.villagerinfo.Commands.SubCommand;
import adhdmc.villagerinfo.Config.ConfigValidator;
import adhdmc.villagerinfo.Config.ConfigValidator.Message;
import adhdmc.villagerinfo.Config.Message;
import adhdmc.villagerinfo.Config.Perms;
import adhdmc.villagerinfo.VillagerInfo;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.CommandSender;

import java.util.List;
import java.util.Map;

public class HelpCommand extends SubCommand {

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

@Override
public void execute(CommandSender sender, String[] args) {
Map<Message, String> msgs = ConfigValidator.getLocaleMap();
MiniMessage mM = MiniMessage.miniMessage();
MiniMessage miniMessage = VillagerInfo.getMiniMessage();

if (sender.hasPermission(VillagerInfo.usePermission)) {
sender.sendMessage(mM.deserialize(msgs.get(Message.PREFIX)));
sender.sendMessage(mM.deserialize(msgs.get(Message.HELP_MAIN)));
sender.sendMessage(mM.deserialize(msgs.get(Message.HELP_TOGGLE)));
sender.sendMessage(mM.deserialize(msgs.get(Message.HELP_RELOAD)));
if (sender.hasPermission(Perms.USE.getPerm())) {
sender.sendMessage(miniMessage.deserialize(Message.PREFIX.getMessage()));
sender.sendMessage(miniMessage.deserialize(Message.HELP_MAIN.getMessage()));
sender.sendMessage(miniMessage.deserialize(Message.HELP_TOGGLE.getMessage()));
sender.sendMessage(miniMessage.deserialize(Message.HELP_RELOAD.getMessage()));
return;
}
sender.sendMessage(mM.deserialize(msgs.get(Message.NO_PERMISSION)));
sender.sendMessage(miniMessage.deserialize(Message.NO_PERMISSION.getMessage()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package adhdmc.villagerinfo.Commands.SubCommands;

import adhdmc.villagerinfo.Commands.SubCommand;
import org.bukkit.command.CommandSender;

import java.util.List;

public class InventoryCommand extends SubCommand {


public InventoryCommand() {
super("inv", "gets the inventory of the specified villager", "/vill inv <UUID>");
}


@Override
public void execute(CommandSender sender, String[] args) {

}

@Override
public List<String> getSubcommandArguments(CommandSender sender, String[] args) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import adhdmc.villagerinfo.Commands.SubCommand;
import adhdmc.villagerinfo.Config.ConfigValidator;
import adhdmc.villagerinfo.Config.ConfigValidator.Message;
import adhdmc.villagerinfo.Config.Message;
import adhdmc.villagerinfo.Config.Perms;
import adhdmc.villagerinfo.VillagerInfo;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;
import java.util.Map;

public class ReloadCommand extends SubCommand {

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

@Override
public void execute(CommandSender sender, String[] args) {
Map<Message, String> msgs = ConfigValidator.getLocaleMap();
MiniMessage mM = MiniMessage.miniMessage();
if (!(sender instanceof Player) || sender.hasPermission(VillagerInfo.reloadCommandPermission)) {
VillagerInfo.plugin.reloadConfig();
VillagerInfo.localeConfig.reloadConfig();
MiniMessage miniMessage = VillagerInfo.getMiniMessage();
if (!(sender instanceof Player) || sender.hasPermission(Perms.RELOAD.getPerm())) {
VillagerInfo.getInstance().reloadConfig();
VillagerInfo.getLocaleConfig().reloadConfig();
ConfigValidator.configValidator();
sender.sendMessage(mM.deserialize(msgs.get(Message.CONFIG_RELOADED)));
sender.sendMessage(miniMessage.deserialize(Message.CONFIG_RELOADED.getMessage()));
} else {
sender.sendMessage(mM.deserialize(msgs.get(Message.NO_PERMISSION)));
sender.sendMessage(miniMessage.deserialize((Message.NO_PERMISSION.getMessage())));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package adhdmc.villagerinfo.Commands.SubCommands;

import adhdmc.villagerinfo.Commands.SubCommand;
import adhdmc.villagerinfo.Config.ConfigValidator;
import adhdmc.villagerinfo.Config.ConfigValidator.Message;
import adhdmc.villagerinfo.Config.Message;
import adhdmc.villagerinfo.Config.Perms;
import adhdmc.villagerinfo.VillagerInfo;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.CommandSender;
Expand All @@ -11,33 +11,31 @@
import org.bukkit.persistence.PersistentDataType;

import java.util.List;
import java.util.Map;

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

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

@Override
public void execute(CommandSender sender, String[] args) {
MiniMessage mM = MiniMessage.miniMessage();
if (!(sender instanceof Player)) {
sender.sendMessage(mM.deserialize(msgs.get(Message.NOT_A_PLAYER)));
sender.sendMessage(miniMessage.deserialize(Message.NOT_A_PLAYER.getMessage()));
return;
}
if (!(sender.hasPermission(VillagerInfo.toggleCommandPermission))) {
sender.sendMessage(mM.deserialize(msgs.get(Message.NO_PERMISSION)));
if (!(sender.hasPermission(Perms.TOGGLE.getPerm()))) {
sender.sendMessage(miniMessage.deserialize(Message.NO_PERMISSION.getMessage()));
return;
}
if (toggleSetting((Player) sender)) {
sender.sendMessage(mM.deserialize(msgs.get(Message.PREFIX))
.append(mM.deserialize(msgs.get(Message.TOGGLE_ON))));
sender.sendMessage(miniMessage.deserialize(Message.PREFIX.getMessage())
.append(miniMessage.deserialize(Message.TOGGLE_ON.getMessage())));
return;
}
sender.sendMessage(mM.deserialize(msgs.get(Message.PREFIX))
.append(mM.deserialize(msgs.get(Message.TOGGLE_OFF))));
sender.sendMessage(miniMessage.deserialize(Message.PREFIX.getMessage())
.append(miniMessage.deserialize(Message.TOGGLE_OFF.getMessage())));
}

private boolean toggleSetting(Player player) {
Expand Down
146 changes: 5 additions & 141 deletions src/main/java/adhdmc/villagerinfo/Config/ConfigValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,164 +10,28 @@
import java.util.Map;

public class ConfigValidator {
public enum Message {
// General
PREFIX, TOGGLE_ON, TOGGLE_OFF, NO_PERMISSION,
NO_COMMAND, CONFIG_RELOADED, HELP_MAIN, HELP_TOGGLE,
HELP_RELOAD, NOT_A_PLAYER,

// Villager Info
VILLAGER_PROFESSION, VILLAGER_JOBSITE, VILLAGER_LAST_WORKED,
VILLAGER_RESTOCKS, VILLAGER_HOME, VILLAGER_SLEPT,
VILLAGER_INVENTORY, INVENTORY_CONTENTS, PLAYER_REPUTATION,

// Fillers
NONE, NEVER, EMPTY,

// Time
HOUR, MINUTE, SECOND, AGO,

// Location
LOCATION_X, LOCATION_Y, LOCATION_Z
}

public enum ToggleSetting {
// Information Toggles
PROFESSION, JOB_SITE, LAST_WORKED, BED_LOCATION, LAST_SLEPT,
INVENTORY, RESTOCKS, REPUTATION, HIGHLIGHT_WORKSTATION, SOUND_TOGGLE,
}

private static final HashMap<Message, String> localeMap = new HashMap<>();
private static final HashMap<ToggleSetting, Boolean> toggleSettings = new HashMap<>();
public static Sound configSound = null;
public static int configTime = 0;


public static void configValidator() {
configSound = null;
configTime = 0;
FileConfiguration config = VillagerInfo.plugin.getConfig();
FileConfiguration config = VillagerInfo.getInstance().getConfig();
try {
configSound = Sound.valueOf(config.getString("sound", "BLOCK_AMETHYST_BLOCK_BREAK").toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException | NullPointerException e) {
VillagerInfo.plugin.getLogger().warning("Configuration Error: " + configSound + " is not a valid sound! Please supply a valid sound");
VillagerInfo.getInstance().getLogger().warning("Configuration Error: " + configSound + " is not a valid sound! Please supply a valid sound");
configSound = Sound.BLOCK_AMETHYST_BLOCK_BREAK;
}
if (config.getInt("highlight-time", 10) <= 0) {
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");
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");
configTime = 10;
} else {
configTime = config.getInt("highlight-time");
}
loadToggleMap();
loadLocaleMap();
}

private static void loadToggleMap() {
toggleSettings.clear();
FileConfiguration config = VillagerInfo.plugin.getConfig();
toggleSettings.put(ToggleSetting.PROFESSION,
config.getBoolean("profession", true));
toggleSettings.put(ToggleSetting.JOB_SITE,
config.getBoolean("job-site", true));
toggleSettings.put(ToggleSetting.LAST_WORKED,
config.getBoolean("last-worked", true));
toggleSettings.put(ToggleSetting.BED_LOCATION,
config.getBoolean("bed-location", true));
toggleSettings.put(ToggleSetting.LAST_SLEPT,
config.getBoolean("last-slept", true));
toggleSettings.put(ToggleSetting.INVENTORY,
config.getBoolean("inventory", true));
toggleSettings.put(ToggleSetting.RESTOCKS,
config.getBoolean("restocks", true));
toggleSettings.put(ToggleSetting.REPUTATION,
config.getBoolean("reputation", true));
toggleSettings.put(ToggleSetting.HIGHLIGHT_WORKSTATION,
config.getBoolean("highlight-workstation", true));
toggleSettings.put(ToggleSetting.SOUND_TOGGLE,
config.getBoolean("sound-toggle", true));
ToggleSetting.reloadToggles();
Message.reloadLocale();
}

private static void loadLocaleMap() {
localeMap.clear();
FileConfiguration locale = VillagerInfo.localeConfig.getlocaleConfig();
// General
localeMap.put(Message.PREFIX,
locale.getString("prefix", "<#3256a8><bold>[</bold><#4dd5ff>Villager Info<#3256a8><bold>]<reset>"));
localeMap.put(Message.TOGGLE_ON,
locale.getString("toggle-on", "<green> Villager Info Toggled <u>ON"));
localeMap.put(Message.TOGGLE_OFF,
locale.getString("toggle-off", "<red> Villager Info Toggled <u>OFF"));
localeMap.put(Message.NO_PERMISSION,
locale.getString("no-permission", "<red>You don't have permission to use this command!"));

// Commands
localeMap.put(Message.NO_COMMAND,
locale.getString("no-command", "<red>No subcommand by that name!"));
localeMap.put(Message.CONFIG_RELOADED,
locale.getString("config-reloaded", "<gold>VillagerInfo Config Reloaded!"));
localeMap.put(Message.HELP_MAIN,
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"));
localeMap.put(Message.HELP_TOGGLE,
locale.getString("help-toggle", "<#4dd5ff> • /vill toggle\n<grey>Toggles the ability to receive villager information on or off."));
localeMap.put(Message.HELP_RELOAD,
locale.getString("help-reload", "<#4dd5ff> • /vill reload\n<grey>Reloads the plugin, applies config values"));
localeMap.put(Message.NOT_A_PLAYER,
locale.getString("not-a-player", "<red>Sorry, you must be a player to use this command"));

// Villager Info
localeMap.put(Message.VILLAGER_PROFESSION,
locale.getString("villager-profession", "<green>PROFESSION:\n<aqua> • <profession>"));
localeMap.put(Message.VILLAGER_JOBSITE,
locale.getString("villager-jobsite-msg", "<green>JOB SITE:\n<aqua> • <jobsitelocation>"));
localeMap.put(Message.VILLAGER_LAST_WORKED,
locale.getString("villager-last-worked-msg", "<green>LAST WORKED AT WORKSTATION:\n<aqua> • <worktime>"));
localeMap.put(Message.VILLAGER_RESTOCKS,
locale.getString("villager-num-restocks-msg", "<green>RESTOCKS TODAY:\n<aqua> • <restockcount>"));
localeMap.put(Message.VILLAGER_HOME,
locale.getString("villager-home-msg", "<green>HOME:\n<aqua> • <homelocation>"));
localeMap.put(Message.VILLAGER_SLEPT,
locale.getString("villager-slept-msg", "<green>LAST SLEPT:\n<aqua> • <sleeptime>"));
localeMap.put(Message.VILLAGER_INVENTORY,
locale.getString("villager-inventory-msg", "<green>VILLAGER INVENTORY:<aqua> <contents>"));
localeMap.put(Message.INVENTORY_CONTENTS,
locale.getString("inventory-contents-msg", "\n • <item> (<amount>)"));
localeMap.put(Message.PLAYER_REPUTATION,
locale.getString("player-reputation-msg", "<green>PLAYER REPUTATION:\n<reputation>"));

// Fillers
localeMap.put(Message.NONE,
locale.getString("none-msg", "<grey>NONE"));
localeMap.put(Message.NEVER,
locale.getString("never-msg", "<grey>NEVER"));
localeMap.put(Message.EMPTY,
locale.getString("empty-msg", "\n • <grey>EMPTY"));

// Time
localeMap.put(Message.HOUR,
locale.getString("hour", "h, "));
localeMap.put(Message.MINUTE,
locale.getString("minute", "m, "));
localeMap.put(Message.SECOND,
locale.getString("second", "s"));
localeMap.put(Message.AGO,
locale.getString("ago", " Ago"));

// Location
localeMap.put(Message.LOCATION_X,
locale.getString("location-x", "<int>x, "));
localeMap.put(Message.LOCATION_Y,
locale.getString("location-y", "<int>y, "));
localeMap.put(Message.LOCATION_Z,
locale.getString("location-z", "<int>z"));
}

public static Map<Message, String> getLocaleMap() {
return Collections.unmodifiableMap(localeMap);
}

public static Map<ToggleSetting, Boolean> getToggleSettings() {
return Collections.unmodifiableMap(toggleSettings);
}

}
Loading

0 comments on commit 66982e6

Please sign in to comment.