Skip to content

Commit

Permalink
Adicionado tag <prefix> #1
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Sep 26, 2024
2 parents fdaf768 + dece6db commit a0ebf79
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
Expand Down Expand Up @@ -62,6 +63,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import java.util.UUID;
Expand Down Expand Up @@ -202,33 +204,38 @@ private void initTagResolvers() {
File configFile = new File(plugin.getDataFolder(), "color-scheme.yml");
if (!configFile.exists()) {
try {
Files.copy(plugin.getJavaPlugin().getResource("color-scheme.yml"), configFile.toPath());
Files.copy(Objects.requireNonNull(plugin.getJavaPlugin().getResource("color-scheme.yml")), configFile.toPath());
} catch (IOException e) {
plugin.logger().warn("Failed to copy color-scheme.yml to plugin folder!", e);
}
}

FileConfiguration colorSchemeYaml = YamlConfiguration.loadConfiguration(configFile);
ConfigurationSection colorSchemeSection = colorSchemeYaml.getConfigurationSection("color-scheme");
if (colorSchemeSection == null) {
tagResolvers = new TagResolver[0];
return;
}

List<TagResolver> resolvers = new ArrayList<>();
resolvers.add(TagResolver.standard());
resolvers.add(TagResolver.resolver("color_scheme", (argumentQueue, context) -> {
if (!argumentQueue.hasNext()) {
return null;
}
Tag.Argument argument = argumentQueue.pop();
String code = argument.value();
String hex = colorSchemeSection.getString(code, "#ffffff");
TextColor textColor = TextColor.fromHexString(hex);
if (textColor == null) {
return null;
}
Log.debug("Registered color scheme " + code + " with hex " + hex);
return Tag.styling(textColor);
}));

if (colorSchemeSection != null) {
resolvers.add(TagResolver.resolver("color_scheme", (argumentQueue, context) -> {
if (!argumentQueue.hasNext()) {
return null;
}
Tag.Argument argument = argumentQueue.pop();
String code = argument.value();
String hex = colorSchemeSection.getString(code, "#ffffff");
TextColor textColor = TextColor.fromHexString(hex);
if (textColor == null) {
return null;
}
Log.debug("Registered color scheme " + code + " with hex " + hex);
return Tag.styling(textColor);
}));
}

String prefix = colorSchemeYaml.getString("prefix", "<dark_gray>[<lime>[Loja]</dark_gray><reset>");
resolvers.add(TagResolver.resolver("prefix", (argumentQueue, context) -> Tag.inserting(MiniMessage.miniMessage().deserialize(prefix))));

this.tagResolvers = resolvers.toArray(new TagResolver[0]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ public class SimpleShopControlPanel implements ShopControlPanel {
.hoverEvent(HoverEvent.showText(hoverText))
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, clickCommand)));
}

// Freeze
if (plugin.perm().hasPermission(sender, "quickshop.other.freeze")
|| (plugin.perm().hasPermission(sender, "quickshop.togglefreeze")
&& shop.playerAuthorize(sender.getUniqueId(), BuiltInShopPermission.SET_SHOPTYPE))) {

final Component text = plugin.text().of(sender, "controlpanel.freeze").forLocale();
String path = shop.isFrozen() ? "controlpanel.unfreeze" : "controlpanel.freeze";
final Component text = plugin.text().of(sender, path).forLocale();
final Component hoverText = plugin.text().of(sender, "controlpanel.freeze-hover").forLocale();
final String clickCommand = MsgUtil.fillArgs("/{0} {1} {2}", plugin.getMainCommand(), plugin.getCommandPrefix("silentfreeze"), shop.getRuntimeRandomUniqueId().toString());
components.add(text
Expand Down

0 comments on commit a0ebf79

Please sign in to comment.