Skip to content

Commit

Permalink
Add placeholder expansion and add return statements
Browse files Browse the repository at this point in the history
  • Loading branch information
RhythmicSys committed Jan 21, 2023
1 parent 6e69fca commit 3005d0e
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -70,5 +74,11 @@
<version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
4 changes: 4 additions & 0 deletions src/main/java/adhdmc/simplenicks/SimpleNicks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/adhdmc/simplenicks/util/SNExpansion.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 2 additions & 2 deletions src/main/java/adhdmc/simplenicks/util/SNMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public enum SNMessage {
NICK_RESET_SELF("<prefix><green>Reset your own nickname!"),
NICK_RESET_OTHER("<prefix><green>Reset <username>'s nickname."),
NICK_RESET_BY_OTHER("<prefix><gray>Your nickname was reset by <username>"),
NICK_SAVE_SUCCESS("<prefix><green>Success! <nickname> saved for future use"),
NICK_SAVE_SUCCESS("<prefix><green>Success! The nickname <nickname><reset><green> has been saved for future use"),
NICK_SAVE_FAILURE("<prefix><gray>Failed to save current username."),
NICK_SAVE_FAILURE_TOO_MANY("<prefix><gray>You have too many saved usernames, please remove some with /nick delete <nickname>"),
NICK_DELETE_SUCCESS("<prefix><nickname><gray> successfully removed from your saved names"),
NICK_DELETE_SUCCESS("<prefix><gray>The nickname <nickname><reset><gray> has been successfully removed from your saved names"),
NICK_DELETE_FAILURE("<prefix><gray>Failed to delete given username."),
//other
VERSION("<prefix> Version: " + SimpleNicks.getInstance().getDescription().getVersion()),
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 3005d0e

Please sign in to comment.