From 3005d0ed400daf32a419218f60c426a30f1c63b9 Mon Sep 17 00:00:00 2001 From: RhythmicSys Date: Sat, 21 Jan 2023 15:26:53 -0800 Subject: [PATCH] Add placeholder expansion and add return statements --- pom.xml | 10 ++++++ .../java/adhdmc/simplenicks/SimpleNicks.java | 4 +++ .../commands/subcommands/Delete.java | 1 + .../commands/subcommands/Save.java | 1 + .../adhdmc/simplenicks/util/SNExpansion.java | 31 +++++++++++++++++++ .../adhdmc/simplenicks/util/SNMessage.java | 4 +-- src/main/resources/plugin.yml | 2 ++ 7 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/main/java/adhdmc/simplenicks/util/SNExpansion.java diff --git a/pom.xml b/pom.xml index 1a45b9f..232e715 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,10 @@ sonatype https://oss.sonatype.org/content/groups/public/ + + placeholderapi + https://repo.extendedclip.com/content/repositories/placeholderapi/ + @@ -70,5 +74,11 @@ 1.19.2-R0.1-SNAPSHOT provided + + me.clip + placeholderapi + 2.11.2 + provided + diff --git a/src/main/java/adhdmc/simplenicks/SimpleNicks.java b/src/main/java/adhdmc/simplenicks/SimpleNicks.java index 2cd1481..d87ea39 100644 --- a/src/main/java/adhdmc/simplenicks/SimpleNicks.java +++ b/src/main/java/adhdmc/simplenicks/SimpleNicks.java @@ -7,6 +7,7 @@ import adhdmc.simplenicks.config.Locale; import adhdmc.simplenicks.listener.LoginListener; import adhdmc.simplenicks.util.NickHandler; +import adhdmc.simplenicks.util.SNExpansion; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -39,6 +40,9 @@ public void onEnable() { this.saveDefaultConfig(); Config.getInstance().setConfigDefaults(); this.getCommand("nick").setExecutor(new CommandHandler()); + if (this.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) { + new SNExpansion().register(); + } instance.getServer().getPluginManager().registerEvents(new LoginListener(), this); configReload(); } diff --git a/src/main/java/adhdmc/simplenicks/commands/subcommands/Delete.java b/src/main/java/adhdmc/simplenicks/commands/subcommands/Delete.java index 7e21f3a..e6ac934 100644 --- a/src/main/java/adhdmc/simplenicks/commands/subcommands/Delete.java +++ b/src/main/java/adhdmc/simplenicks/commands/subcommands/Delete.java @@ -29,6 +29,7 @@ public void execute(CommandSender sender, String[] args) { String nickname = NickHandler.getInstance().getNickname(player); if (!NickHandler.getInstance().deleteNickname(player, nickname)) { player.sendMessage(miniMessage.deserialize(SNMessage.NICK_DELETE_FAILURE.getMessage(), Placeholder.parsed("prefix", SNMessage.PREFIX.getMessage()))); + return; } player.sendMessage(miniMessage.deserialize(SNMessage.NICK_DELETE_SUCCESS.getMessage(), Placeholder.parsed("prefix", SNMessage.PREFIX.getMessage()), Placeholder.parsed("nickname", nickname))); } diff --git a/src/main/java/adhdmc/simplenicks/commands/subcommands/Save.java b/src/main/java/adhdmc/simplenicks/commands/subcommands/Save.java index 3ced833..20ae6c6 100644 --- a/src/main/java/adhdmc/simplenicks/commands/subcommands/Save.java +++ b/src/main/java/adhdmc/simplenicks/commands/subcommands/Save.java @@ -34,6 +34,7 @@ public void execute(CommandSender sender, String[] args) { String nickname = NickHandler.getInstance().getNickname(player); if (!NickHandler.getInstance().saveNickname(player, nickname)) { player.sendMessage(miniMessage.deserialize(SNMessage.NICK_SAVE_FAILURE.getMessage(), Placeholder.parsed("prefix", SNMessage.PREFIX.getMessage()))); + return; } player.sendMessage(miniMessage.deserialize(SNMessage.NICK_SAVE_SUCCESS.getMessage(), Placeholder.parsed("prefix", SNMessage.PREFIX.getMessage()), Placeholder.parsed("nickname", nickname))); } diff --git a/src/main/java/adhdmc/simplenicks/util/SNExpansion.java b/src/main/java/adhdmc/simplenicks/util/SNExpansion.java new file mode 100644 index 0000000..6a8c34c --- /dev/null +++ b/src/main/java/adhdmc/simplenicks/util/SNExpansion.java @@ -0,0 +1,31 @@ +package adhdmc.simplenicks.util; + +import adhdmc.simplenicks.SimpleNicks; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; + +public class SNExpansion extends PlaceholderExpansion { + @Override + public @NotNull String getIdentifier() { + return "simplenicks"; + } + + @Override + public @NotNull String getAuthor() { + return SimpleNicks.getInstance().getDescription().getAuthors().toString(); + } + + @Override + public @NotNull String getVersion() { + return SimpleNicks.getInstance().getDescription().getVersion(); + } + + @Override + public String onRequest(OfflinePlayer player, @NotNull String params) { + if (params.equalsIgnoreCase("mininick")) { + return NickHandler.getInstance().getNickname(player); + } + return null; + } +} diff --git a/src/main/java/adhdmc/simplenicks/util/SNMessage.java b/src/main/java/adhdmc/simplenicks/util/SNMessage.java index 27d6a4e..bd524d0 100644 --- a/src/main/java/adhdmc/simplenicks/util/SNMessage.java +++ b/src/main/java/adhdmc/simplenicks/util/SNMessage.java @@ -24,10 +24,10 @@ public enum SNMessage { NICK_RESET_SELF("Reset your own nickname!"), NICK_RESET_OTHER("Reset 's nickname."), NICK_RESET_BY_OTHER("Your nickname was reset by "), - NICK_SAVE_SUCCESS("Success! saved for future use"), + NICK_SAVE_SUCCESS("Success! The nickname has been saved for future use"), NICK_SAVE_FAILURE("Failed to save current username."), NICK_SAVE_FAILURE_TOO_MANY("You have too many saved usernames, please remove some with /nick delete "), - NICK_DELETE_SUCCESS(" successfully removed from your saved names"), + NICK_DELETE_SUCCESS("The nickname has been successfully removed from your saved names"), NICK_DELETE_FAILURE("Failed to delete given username."), //other VERSION(" Version: " + SimpleNicks.getInstance().getDescription().getVersion()), diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fa6dc83..964b3d0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,6 +3,8 @@ version: '${project.version}' main: adhdmc.simplenicks.SimpleNicks authors: ['Rhythmic', 'Peashooter101'] api-version: 1.19 +softdepend: + - PlaceholderAPI commands: nick: description: "Base command for SimpleNicks, Admin permission required to alter other's names."