Skip to content

Commit ee2f4f4

Browse files
committed
Feedback, Messages, Permissions
Final touches~ Added command and GUI feedback, now the player will hear sounds in the GUI and see messages for the commands and GUI. Added Messages to hold enum values of messages that can be changed in locale.yml. Added basic permissions for each of the commands. Forced everything I could think of that needs to use these new things to use these new things. Fixed issue where having an advancement with no namespace throws an exception. It no longer does that, it just ignores the invalid advancement. Edited prefixes.yml to reflect "real" prefixes people might use. Update version to v1.0.0
1 parent c8c0d22 commit ee2f4f4

22 files changed

+341
-80
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ADHDMC</groupId>
88
<artifactId>SimplePrefixes</artifactId>
9-
<version>dev</version>
9+
<version>v1.0.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimplePrefixes</name>

src/main/java/adhdmc/simpleprefixes/SimplePrefixes.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import adhdmc.simpleprefixes.command.CommandHandler;
44
import adhdmc.simpleprefixes.command.subcommand.*;
55
import adhdmc.simpleprefixes.config.Config;
6+
import adhdmc.simpleprefixes.config.Locale;
7+
import adhdmc.simpleprefixes.config.PrefixConfig;
68
import adhdmc.simpleprefixes.dependency.PAPIExpansion;
79
import adhdmc.simpleprefixes.gui.chest.listener.PrefixMenuListener;
810
import adhdmc.simpleprefixes.util.Prefix;
@@ -25,15 +27,10 @@ public void onEnable() {
2527
plugin = this;
2628
miniMessage = MiniMessage.miniMessage();
2729
logger = getPlugin().getLogger();
28-
logger.info("SimplePrefixes has set up plugin, mini-message, and logger.");
2930
configSetup();
30-
logger.info("SimplePrefixes has passed the config setup.");
3131
new PAPIExpansion(this).register();
32-
logger.info("SimplePrefixes has registered the PAPI Extension.");
3332
registerCommands();
34-
logger.info("SimplePrefixes has registered the commands.");
3533
Bukkit.getPluginManager().registerEvents(new PrefixMenuListener(), this);
36-
logger.info("SimplePrefixes has registered the event.");
3734
}
3835

3936
@Override
@@ -43,15 +40,14 @@ public void onDisable() {
4340

4441
public static Plugin getPlugin() { return plugin; }
4542
public static MiniMessage getMiniMessage() { return miniMessage; }
46-
47-
public static Logger getPrefixLogger() {
48-
return logger;
49-
}
43+
public static Logger getPrefixLogger() { return logger; }
5044

5145

5246
public static void configSetup() {
5347
plugin.saveDefaultConfig();
48+
Locale.getInstance().reloadLocale();
5449
Config.loadConfig();
50+
PrefixConfig.getInstance().reloadPrefixConfig();
5551
PrefixUtil.getInstance().loadSaveHandler();
5652
Prefix.populatePrefixes();
5753
}

src/main/java/adhdmc/simpleprefixes/command/CommandHandler.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package adhdmc.simpleprefixes.command;
22

3+
import adhdmc.simpleprefixes.util.Message;
4+
import adhdmc.simpleprefixes.util.Permission;
35
import net.kyori.adventure.text.minimessage.MiniMessage;
46
import org.bukkit.command.Command;
57
import org.bukkit.command.CommandExecutor;
@@ -27,18 +29,25 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
2729
if (subcommandList.containsKey(subcommand)) {
2830
subcommandList.get(subcommand).execute(sender, Arrays.copyOfRange(args, 1, args.length));
2931
} else {
30-
// TODO: Configurable message, message enum.
31-
sender.sendRichMessage("<red>PLACEHOLDER: NO COMMAND");
32+
sender.sendMessage(Message.INVALID_COMMAND.getParsedMessage(null));
3233
}
3334
return true;
3435
}
3536

3637
@Override
3738
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
3839
if (args.length == 0) return new ArrayList<>();
39-
if (args.length == 1) return new ArrayList<>(subcommandList.keySet());
40+
if (args.length == 1) {
41+
List<String> list = new ArrayList<>();
42+
for (String cmd : subcommandList.keySet()) {
43+
if (sender.hasPermission(Permission.valueOf(cmd.toUpperCase()).get()) && cmd.contains(args[0])) list.add(cmd);
44+
}
45+
return list;
46+
}
4047
String subcommand = args[0].toLowerCase();
41-
if (subcommandList.containsKey(subcommand)) return subcommandList.get(subcommand).getSubcommandArguments(sender, args);
48+
if (subcommandList.containsKey(subcommand) && sender.hasPermission(Permission.valueOf(subcommand.toUpperCase()).get())) {
49+
return subcommandList.get(subcommand).getSubcommandArguments(sender, args);
50+
}
4251
return new ArrayList<>();
4352
}
4453
}

src/main/java/adhdmc/simpleprefixes/command/SubCommand.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package adhdmc.simpleprefixes.command;
22

3+
import adhdmc.simpleprefixes.util.Permission;
34
import org.bukkit.command.CommandSender;
45

56
import java.util.List;
@@ -9,11 +10,13 @@ public abstract class SubCommand {
910
private final String name;
1011
private final String description;
1112
private final String syntax;
13+
private final Permission permission;
1214

13-
public SubCommand(String name, String description, String syntax) {
15+
public SubCommand(String name, String description, String syntax, Permission permission) {
1416
this.name = name;
1517
this.description = description;
1618
this.syntax = syntax;
19+
this.permission = permission;
1720
}
1821

1922
public String getName() {
@@ -28,6 +31,8 @@ public String getSyntax() {
2831
return syntax;
2932
}
3033

34+
public String getPermission() { return permission.get(); }
35+
3136
public abstract void execute(CommandSender sender, String[] args);
3237

3338
public abstract List<String> getSubcommandArguments(CommandSender sender, String[] args);

src/main/java/adhdmc/simpleprefixes/command/subcommand/GuiCommand.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import adhdmc.simpleprefixes.command.SubCommand;
44
import adhdmc.simpleprefixes.gui.chest.PrefixMenu;
5+
import adhdmc.simpleprefixes.util.Message;
6+
import adhdmc.simpleprefixes.util.Permission;
57
import org.bukkit.command.CommandSender;
68
import org.bukkit.entity.Player;
79

@@ -10,14 +12,17 @@
1012

1113
public class GuiCommand extends SubCommand {
1214
public GuiCommand() {
13-
super("gui", "Opens the GUI menu for prefixes!", "/sp gui");
15+
super("gui", "Opens the GUI menu for prefixes!", "/sp gui", Permission.GUI);
1416
}
1517

1618
@Override
1719
public void execute(CommandSender sender, String[] args) {
1820
if (!(sender instanceof Player player)) {
19-
// TODO: Configurable message, message enum.
20-
sender.sendRichMessage("<red>PLACEHOLDER: YOU ARE NOT A PLAYER");
21+
sender.sendMessage(Message.INVALID_NOT_PLAYER.getParsedMessage(null));
22+
return;
23+
}
24+
if (!player.hasPermission(Permission.GUI.get())) {
25+
player.sendMessage(Message.INVALID_PERMISSION.getParsedMessage(player));
2126
return;
2227
}
2328
player.openInventory(PrefixMenu.getInstance().generatePrefixMenu(player, 1));

src/main/java/adhdmc/simpleprefixes/command/subcommand/InfoCommand.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import adhdmc.simpleprefixes.SimplePrefixes;
44
import adhdmc.simpleprefixes.command.SubCommand;
5+
import adhdmc.simpleprefixes.util.Message;
6+
import adhdmc.simpleprefixes.util.Permission;
57
import adhdmc.simpleprefixes.util.Prefix;
68
import net.kyori.adventure.text.Component;
79
import net.kyori.adventure.text.minimessage.MiniMessage;
@@ -14,15 +16,18 @@
1416
public class InfoCommand extends SubCommand {
1517

1618
public InfoCommand() {
17-
super("info", "Displays information about the given prefix.", "/sp info <id>");
19+
super("info", "Displays information about the given prefix.", "/sp info <id>", Permission.INFO);
1820
}
1921

2022
@Override
2123
public void execute(CommandSender sender, String[] args) {
2224
Prefix prefix = Prefix.getPrefix(args[0]);
2325
if (prefix == null) {
24-
// TODO: Configurable message, message enum.
25-
sender.sendRichMessage("<red>PLACEHOLDER: NOT VALID ID");
26+
sender.sendMessage(Message.INVALID_PREFIX_ID.getParsedMessage(null));
27+
return;
28+
}
29+
if (!sender.hasPermission(Permission.INFO.get())) {
30+
sender.sendMessage(Message.INVALID_PERMISSION.getParsedMessage(null));
2631
return;
2732
}
2833
sender.sendMessage(buildInfoString(prefix));

src/main/java/adhdmc/simpleprefixes/command/subcommand/ReloadCommand.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,30 @@
22

33
import adhdmc.simpleprefixes.SimplePrefixes;
44
import adhdmc.simpleprefixes.command.SubCommand;
5+
import adhdmc.simpleprefixes.util.Message;
6+
import adhdmc.simpleprefixes.util.Permission;
57
import org.bukkit.command.CommandSender;
68

79
import java.util.ArrayList;
810
import java.util.List;
911

1012
public class ReloadCommand extends SubCommand {
1113
public ReloadCommand() {
12-
super("reload", "Reloads the configuration.", "/sp reload");
14+
super("reload", "Reloads the configuration.", "/sp reload", Permission.RELOAD);
1315
}
1416

1517
@Override
1618
public void execute(CommandSender sender, String[] args) {
1719
if (!sender.hasPermission("simpleprefixes.reload")) {
18-
// TODO: NO PERMISSION ERROR
20+
sender.sendMessage(Message.INVALID_PERMISSION.getParsedMessage(null));
21+
return;
22+
}
23+
if (!sender.hasPermission(Permission.RELOAD.get())) {
24+
sender.sendMessage(Message.INVALID_PERMISSION.getParsedMessage(null));
1925
return;
2026
}
2127
SimplePrefixes.configSetup();
22-
sender.sendRichMessage("<green>PLACEHOLDER: RELOADED");
28+
sender.sendMessage(Message.SUCCESS_RELOAD.getParsedMessage(null));
2329
}
2430

2531
@Override

src/main/java/adhdmc/simpleprefixes/command/subcommand/ResetCommand.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package adhdmc.simpleprefixes.command.subcommand;
22

33
import adhdmc.simpleprefixes.command.SubCommand;
4+
import adhdmc.simpleprefixes.util.Message;
5+
import adhdmc.simpleprefixes.util.Permission;
46
import adhdmc.simpleprefixes.util.PrefixUtil;
57
import org.bukkit.command.CommandSender;
68
import org.bukkit.entity.Player;
@@ -11,19 +13,21 @@
1113
public class ResetCommand extends SubCommand {
1214

1315
public ResetCommand() {
14-
super("reset", "Resets your prefix to default", "/sp reset");
16+
super("reset", "Resets your prefix to default", "/sp reset", Permission.RESET);
1517
}
1618

1719
@Override
1820
public void execute(CommandSender sender, String[] args) {
1921
if (!(sender instanceof Player player)) {
20-
// TODO: Configurable message, message enum.
21-
sender.sendRichMessage("<red>PLACEHOLDER: YOU ARE NOT A PLAYER");
22+
sender.sendMessage(Message.INVALID_NOT_PLAYER.getParsedMessage(null));
23+
return;
24+
}
25+
if (!player.hasPermission(Permission.RESET.get())) {
26+
player.sendMessage(Message.INVALID_PERMISSION.getParsedMessage(player));
2227
return;
2328
}
2429
PrefixUtil.getInstance().setPrefix(player, null);
25-
// TODO: Configurable message, message enum.
26-
sender.sendRichMessage("<green>PLACEHOLDER: RESET PREFIX");
30+
player.sendMessage(Message.SUCCESS_RESET.getParsedMessage(player));
2731
}
2832

2933
@Override

src/main/java/adhdmc/simpleprefixes/command/subcommand/SetCommand.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package adhdmc.simpleprefixes.command.subcommand;
22

33
import adhdmc.simpleprefixes.command.SubCommand;
4-
import adhdmc.simpleprefixes.util.Prefix;
5-
import adhdmc.simpleprefixes.util.PrefixUtil;
6-
import adhdmc.simpleprefixes.util.RequirementUtil;
4+
import adhdmc.simpleprefixes.util.*;
75
import org.bukkit.command.CommandSender;
86
import org.bukkit.entity.Player;
97

@@ -13,30 +11,30 @@
1311

1412
public class SetCommand extends SubCommand {
1513
public SetCommand() {
16-
super("set", "Sets the user's prefix to the given ID", "/sp set <id>");
14+
super("set", "Sets the user's prefix to the given ID", "/sp set <id>", Permission.SET);
1715
}
1816

1917
@Override
2018
public void execute(CommandSender sender, String[] args) {
2119
Prefix prefix = Prefix.getPrefix(args[0]);
2220
if (prefix == null) {
23-
// TODO: Configurable message, message enum.
24-
sender.sendRichMessage("<red>PLACEHOLDER: NOT VALID ID");
21+
sender.sendMessage(Message.INVALID_PREFIX_ID.getParsedMessage(null));
2522
return;
2623
}
2724
if (!(sender instanceof Player player)) {
28-
// TODO: Configurable message, message enum.
29-
sender.sendRichMessage("<red>PLACEHOLDER: YOU ARE NOT A PLAYER");
25+
sender.sendMessage(Message.INVALID_NOT_PLAYER.getParsedMessage(null));
26+
return;
27+
}
28+
if (!player.hasPermission(Permission.SET.get())) {
29+
player.sendMessage(Message.INVALID_PERMISSION.getParsedMessage(player));
3030
return;
3131
}
3232
if (!RequirementUtil.getInstance().isEarnedPrefix(player, args[0])) {
33-
// TODO: Configurable message, message enum.
34-
sender.sendRichMessage("<red>PLACEHOLDER: REQUIREMENTS NOT MET");
33+
player.sendMessage(Message.INVALID_REQUIREMENTS.getParsedMessage(player));
3534
return;
3635
}
3736
PrefixUtil.getInstance().setPrefix(player, args[0]);
38-
// TODO: Configurable message, message enum.
39-
sender.sendRichMessage("<green>PLACEHOLDER: SET PREFIX TO PREFIX " + prefix.displayName + " (ID: " + prefix.prefixId + ") → " + prefix.prefix);
37+
player.sendMessage(Message.SUCCESS_SET.getParsedMessage(player));
4038
}
4139

4240
@Override

src/main/java/adhdmc/simpleprefixes/config/Config.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package adhdmc.simpleprefixes.config;
22

33
import adhdmc.simpleprefixes.SimplePrefixes;
4+
import adhdmc.simpleprefixes.util.Message;
45
import org.bukkit.configuration.file.FileConfiguration;
56

67
public class Config {
@@ -15,8 +16,7 @@ public static void loadConfig() {
1516
try {
1617
savingType = SAVING_TYPE.valueOf(config.getString("saving-type", "pdc").toUpperCase());
1718
} catch (IllegalArgumentException e) {
18-
// TODO: Make message configurable.
19-
SimplePrefixes.getPlugin().getLogger().warning("Configuration option saving-type is not a valid configuration!");
19+
SimplePrefixes.getPlugin().getLogger().warning(Message.LOGGER_INVALID_CONFIG_SAVING_TYPE.getMessage());
2020
}
2121
defaultPrefix = config.getString("default-prefix", defaultPrefix);
2222
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package adhdmc.simpleprefixes.config;
2+
3+
import adhdmc.simpleprefixes.SimplePrefixes;
4+
import adhdmc.simpleprefixes.util.Message;
5+
import org.bukkit.configuration.InvalidConfigurationException;
6+
import org.bukkit.configuration.file.FileConfiguration;
7+
import org.bukkit.configuration.file.YamlConfiguration;
8+
9+
import java.io.File;
10+
import java.io.IOException;
11+
import java.util.Set;
12+
13+
public class Locale {
14+
15+
private static Locale instance;
16+
17+
private final String fileName = "locale.yml";
18+
private final File dataFile = new File(SimplePrefixes.getPlugin().getDataFolder(), fileName);
19+
private final FileConfiguration locale = new YamlConfiguration();
20+
21+
private Locale() {
22+
if (!dataFile.exists()) SimplePrefixes.getPlugin().saveResource(fileName, false);
23+
reloadLocale();
24+
}
25+
26+
public static Locale getInstance() {
27+
if (instance == null) instance = new Locale();
28+
return instance;
29+
}
30+
31+
public FileConfiguration getLocale() { return locale; }
32+
33+
public void reloadLocale() {
34+
try { locale.load(dataFile); }
35+
catch (IOException | InvalidConfigurationException e) { e.printStackTrace(); }
36+
Set<String> keys = locale.getKeys(false);
37+
for (String key : keys) {
38+
try {
39+
Message message = Message.valueOf(key);
40+
message.setMessage(locale.getString(key, message.getMessage()));
41+
} catch (IllegalArgumentException e) {
42+
SimplePrefixes.getPrefixLogger().warning(Message.LOGGER_INVALID_LOCALE_KEY + key);
43+
}
44+
}
45+
}
46+
47+
}

0 commit comments

Comments
 (0)