generated from ArtformGames/TemplateSinglePlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Finished placeholders and commands
- Loading branch information
Showing
8 changed files
with
135 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 50 additions & 15 deletions
65
src/main/java/com/artformgames/plugin/usersuffix/command/UserSuffixCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,76 @@ | ||
package com.artformgames.plugin.usersuffix.command; | ||
|
||
import cc.carm.lib.easyplugin.utils.ColorParser; | ||
import com.artformgames.core.ArtCore; | ||
import com.artformgames.plugin.usersuffix.conf.PluginConfig; | ||
import com.artformgames.plugin.usersuffix.conf.PluginMessages; | ||
import com.artformgames.plugin.usersuffix.user.SuffixAccount; | ||
import dev.rollczi.litecommands.annotations.argument.Arg; | ||
import dev.rollczi.litecommands.annotations.command.Command; | ||
import dev.rollczi.litecommands.annotations.context.Context; | ||
import dev.rollczi.litecommands.annotations.execute.Execute; | ||
import dev.rollczi.litecommands.annotations.optional.OptionalArg; | ||
import dev.rollczi.litecommands.annotations.join.Join; | ||
import dev.rollczi.litecommands.annotations.permission.Permission; | ||
import me.clip.placeholderapi.PlaceholderAPI; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
@Command(name = "usersuffix", aliases = "suffix") | ||
@Permission("usersuffix.use") | ||
public class UserSuffixCommands { | ||
|
||
@Execute | ||
void set(@Context Player player, @Arg String suffix, @OptionalArg String blanketColor) { | ||
|
||
@Execute(name = "clear") | ||
void clearSuffix(@Context Player player) { | ||
SuffixAccount account = ArtCore.getHandler(player, SuffixAccount.class); | ||
account.setContent(null); | ||
account.setColor(null); | ||
PluginMessages.CLEARED.send(player); | ||
} | ||
|
||
public static boolean setSuffix(SuffixAccount data, Player player, String color, String suffixText) { | ||
String suffix = color + suffixText + color; | ||
if (!SuffixAccount.validColor(color)) { | ||
PluginMessages.INVALID_COLOR_CODE.send(player); | ||
} else if (suffixText.contains("&")) { | ||
|
||
@Execute(name = "content") | ||
void setContent(@Context Player player, @Join String content) { | ||
if (content.contains("&")) { | ||
PluginMessages.CONTAIN_COLOR_CODE.send(player); | ||
} else if (suffixText.length() > PluginConfig.MAX_LENGTH.getNotNull()) { | ||
return; | ||
} | ||
|
||
if (content.contains(" ")) { | ||
PluginMessages.NO_SPACE.send(player); | ||
return; | ||
} | ||
|
||
if (content.length() > PluginConfig.MAX_LENGTH.getNotNull()) { | ||
PluginMessages.TOO_LONG.send(player, PluginConfig.MAX_LENGTH.getNotNull()); | ||
} else { | ||
data.setSuffix(suffixText, ChatColor.getByChar(color)); | ||
PluginMessages.SUCCESS.send(player, PlaceholderAPI.setPlaceholders(player, "%artessentials_suffix%")); | ||
return; | ||
} | ||
|
||
if (content.isBlank()) { | ||
PluginMessages.TOO_SHORT.send(player); | ||
return; | ||
} | ||
|
||
SuffixAccount account = ArtCore.getHandler(player, SuffixAccount.class); | ||
account.setContent(content.isBlank() ? null : content); | ||
PluginMessages.SUCCESS.send(player, account.getSuffix()); | ||
} | ||
|
||
|
||
@Execute(name = "color") | ||
void setBracketsColor(@Context Player player, @Arg ChatColor color) { | ||
if (!color.isColor() || !PluginConfig.ALLOWED_COLORS.contains(color)) { | ||
PluginMessages.INVALID_COLOR_CODE.send(player); | ||
String colors = PluginConfig.ALLOWED_COLORS.copy().stream() | ||
.map(c -> "&" + c.getChar() + c.name()) | ||
.collect(Collectors.joining(", ")); | ||
player.sendMessage(ColorParser.parse(colors)); | ||
return; | ||
} | ||
|
||
return true; | ||
SuffixAccount account = ArtCore.getHandler(player, SuffixAccount.class); | ||
account.setColor(color); | ||
PluginMessages.SUCCESS.send(player, account.getSuffix()); | ||
} | ||
|
||
} |
35 changes: 25 additions & 10 deletions
35
src/main/java/com/artformgames/plugin/usersuffix/conf/PluginConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,47 @@ | ||
package com.artformgames.plugin.usersuffix.conf; | ||
|
||
import cc.carm.lib.configuration.core.ConfigurationRoot; | ||
import cc.carm.lib.configuration.core.Configuration; | ||
import cc.carm.lib.configuration.core.annotation.HeaderComment; | ||
import cc.carm.lib.configuration.core.value.ConfigValue; | ||
import cc.carm.lib.configuration.core.value.type.ConfiguredList; | ||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue; | ||
import org.bukkit.ChatColor; | ||
|
||
public class PluginConfig extends ConfigurationRoot { | ||
public interface PluginConfig extends Configuration { | ||
|
||
public static final ConfiguredValue<Boolean> DEBUG = ConfiguredValue.of(Boolean.class, false); | ||
ConfiguredValue<Boolean> DEBUG = ConfiguredValue.of(false); | ||
|
||
@HeaderComment({ | ||
"Check update settings", | ||
"This option is used by the plug-in to determine whether to check for updates.", | ||
"If you do not want the plug-in to check for updates and prompt you, you can choose to close.", | ||
"Checking for updates is an asynchronous operation that will never affect performance and user experience." | ||
}) | ||
public static final ConfiguredValue<Boolean> CHECK_UPDATE = ConfiguredValue.of(Boolean.class, true); | ||
|
||
@HeaderComment("Suffix weight in LuckPerms") | ||
public static final ConfigValue<Integer> WEIGHT = ConfiguredValue.of(Integer.class, 1); | ||
ConfiguredValue<Boolean> CHECK_UPDATE = ConfiguredValue.of(true); | ||
|
||
@HeaderComment({"Suffix format. The `%(suffix)` will be replaced with the suffix content."}) | ||
public static final ConfigValue<String> FORMAT = ConfiguredValue.of(String.class, " %(color)[%(suffix)%(color)]"); | ||
ConfigValue<String> FORMAT = ConfiguredValue.of(" %(color)[%(suffix)%(color)]"); | ||
|
||
@HeaderComment("The default color for the suffix format section.") | ||
public static final ConfigValue<String> DEFAULT_COLOR = ConfiguredValue.of(String.class, "&7"); | ||
ConfigValue<ChatColor> DEFAULT_COLOR = ConfiguredValue.builderOf(ChatColor.class).fromString() | ||
.parseValue(c -> ChatColor.valueOf(c.toUpperCase())).serializeValue(ChatColor::name) | ||
.defaults(ChatColor.GRAY).build(); | ||
|
||
@HeaderComment("Allowed colors for the suffix format section.") | ||
ConfiguredList<ChatColor> ALLOWED_COLORS = ConfiguredList.builderOf(ChatColor.class).fromString() | ||
.parseValue(c -> ChatColor.valueOf(c.toUpperCase())).serializeValue(ChatColor::name) | ||
.defaults( | ||
ChatColor.BLACK, ChatColor.DARK_BLUE, | ||
ChatColor.DARK_GREEN, ChatColor.DARK_AQUA, | ||
ChatColor.DARK_RED, ChatColor.DARK_PURPLE, | ||
ChatColor.GOLD, ChatColor.GRAY, | ||
ChatColor.DARK_GRAY, ChatColor.BLUE, | ||
ChatColor.GREEN, ChatColor.AQUA, | ||
ChatColor.RED, ChatColor.LIGHT_PURPLE, | ||
ChatColor.YELLOW, ChatColor.WHITE | ||
).build(); | ||
|
||
@HeaderComment("Maximum length of the suffix (excluding color symbols)") | ||
public static final ConfigValue<Integer> MAX_LENGTH = ConfiguredValue.of(Integer.class, 8); | ||
ConfigValue<Integer> MAX_LENGTH = ConfiguredValue.of(8); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/com/artformgames/plugin/usersuffix/hooker/SuffixPlaceholder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.artformgames.plugin.usersuffix.hooker; | ||
|
||
import cc.carm.lib.easyplugin.papi.EasyPlaceholder; | ||
import com.artformgames.core.ArtCore; | ||
import com.artformgames.plugin.usersuffix.user.SuffixAccount; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.jetbrains.annotations.NotNull; | ||
import panda.std.function.TriFunction; | ||
|
||
import java.util.Optional; | ||
|
||
public class SuffixPlaceholder extends EasyPlaceholder { | ||
|
||
public SuffixPlaceholder(@NotNull JavaPlugin plugin, @NotNull String rootIdentifier) { | ||
super(plugin, rootIdentifier); | ||
handleSuffix("suffix", (player, account, args) -> account.getSuffix()); | ||
handleSuffix("content", ((player, account, args) -> Optional.ofNullable(account.getContent()).orElse(""))); | ||
handleSuffix("color", ((player, account, args) -> account.getColorCode())); | ||
} | ||
|
||
protected void handleSuffix(String id, TriFunction<Player, SuffixAccount, String[], String> handler) { | ||
handle(id, (player, args) -> { | ||
if (!(player instanceof Player onlinePlayer)) return "Offline"; | ||
SuffixAccount account = ArtCore.getHandler(onlinePlayer, SuffixAccount.class); | ||
return handler.apply(onlinePlayer, account, args); | ||
}); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters