Skip to content

Commit

Permalink
add extra feature, to append lore to duplicated items
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Aug 23, 2024
1 parent 8e43c31 commit a884f31
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import ch.jalu.configme.configurationdata.CommentsConfiguration;
import ch.jalu.configme.properties.Property;
import ch.jalu.configme.properties.PropertyInitializer;

import java.util.List;

import static ch.jalu.configme.properties.PropertyInitializer.newListProperty;
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;

public class ConfigKeys implements SettingsHolder {
Expand Down Expand Up @@ -51,7 +55,13 @@ public void registerComments(CommentsConfiguration conf) {
"If you turn this option off, no new uuids will be attached or checked",
"however previous vouchers will still not stack, obviously."
})
public static final Property<Boolean> dupe_protection = newProperty("settings.dupe-protection", false);
public static final Property<Boolean> dupe_protection = newProperty("settings.dupe-protection.enabled", false);

@Comment("This decides whether a line should be added to duplicated voucher lore to avoid scams.")
public static final Property<Boolean> dupe_protection_toggle_warning = newProperty("settings.dupe-protection.warning.enabled", false);

@Comment("The line to add to the lore of an item. This message supports PlaceholderAPI")
public static final Property<String> dupe_protection_warning = newProperty("settings.dupe-protection.warning.value", "&cThis item has been duplicated");

@Comment("Pick which locale you want to use if your server is in another language.")
public static final Property<String> locale_file = newProperty("settings.locale", "en-US");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.ryderbelserion.vital.paper.enums.Support;
import io.papermc.paper.persistence.PersistentDataContainerView;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -176,6 +177,39 @@ private void useVoucher(Player player, Voucher voucher, ItemStack item) {
}
});

if (this.config.getProperty(ConfigKeys.dupe_protection_toggle_warning)) {
List<String> lore = item.getLore(); //todo() deprecated, switch to minimessage

if (lore == null) lore = new ArrayList<>();

final String option = this.config.getProperty(ConfigKeys.dupe_protection_warning);

boolean hasLine = false;

for (String line : lore) {
final String cleanLine = ChatColor.stripColor(line); //todo() deprecated
final String cleanOption = ChatColor.stripColor(MsgUtils.color(option)); //todo() deprecated

if (cleanLine.equalsIgnoreCase(cleanOption)) {
hasLine = true;

break;
}
}

if (hasLine) return;

final List<String> finalLore = lore;

item.editMeta(itemMeta -> {
List<String> messages = new ArrayList<>(finalLore);

messages.add(Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(player, MsgUtils.color(option)) : MsgUtils.color(option));

itemMeta.setLore(messages); //todo() deprecated
});
}

return;
}
}
Expand Down

0 comments on commit a884f31

Please sign in to comment.