Skip to content

Commit

Permalink
Fixed config issue with kill messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Jul 15, 2024
1 parent a3e79e5 commit ceaf74d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum CosmeticsLocale implements IDataAccessor {
FIREWORKS_MATERIAL("KILL-EFFECTS.FIREWORKS.MATERIAL", DataType.STRING, "FIREWORK_ROCKET"),
DEFAULT_MESSAGE("KILL_MESSAGES.DEFAULT.DISPLAY_NAME", DataType.STRING, "&7Default"),
DEFAULT_MESSAGE_MATERIAL("KILL_MESSAGES.DEFAULT.MATERIAL", DataType.STRING, "BARRIER"),
DEFAULT_MESSAGE_DESCRIPTION("KILL_MESSAGES.DEFAULT.DESCRIPTION", DataType.STRING_LIST, "&7Default kill message."),
DEFAULT_MESSAGE_DESCRIPTION("KILL_MESSAGES.DEFAULT.DESCRIPTION", DataType.STRING_LIST, "&7Default kill message.", " "),
DEFAULT_MESSAGE_SLOT("KILL_MESSAGES.DEFAULT.SLOT", DataType.INT, "10"),
DEFAULT_MESSAGE_MESSAGES("KILL_MESSAGES.DEFAULT.MESSAGES", DataType.STRING_LIST, "&c☠ <player> &7was killed by \uD83D\uDDE1 <killer>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public enum MenusLocale implements IDataAccessor {
KILL_EFFECTS_SIZE("SETTINGS.KILL-EFFECTS.SIZE", DataType.INT, "27"),
KILL_EFFECTS_FILTER("SETTINGS.KILL-EFFECTS.FILTER-TYPE", "FILL, BORDER, NONE", DataType.STRING, "FILL"),
KILL_EFFECTS_SELECTED_LORE("SETTINGS.KILL-EFFECTS.SELECTED.LORE", DataType.STRING_LIST,
" ", "&cClick to unselect"),
" ", "&eCurrently Selected"),
KILL_EFFECTS_UNSELECTED_LORE("SETTINGS.KILL-EFFECTS.UNSELECTED.LORE", DataType.STRING_LIST,
" ", "&aClick to select"),
KILL_EFFECTS_NO_PERMISSION_LORE("SETTINGS.KILL-EFFECTS.NO-PERMISSION.LORE", DataType.STRING_LIST,
Expand Down Expand Up @@ -348,7 +348,22 @@ public enum MenusLocale implements IDataAccessor {
KILL_MESSAGES_SLOT("SETTINGS.COSMETICS.KILL-MESSAGES.SLOT", DataType.INT, "11"),
KILL_MESSAGES_NAME("SETTINGS.COSMETICS.KILL-MESSAGES.NAME", DataType.STRING, "&bKill Messages"),
KILL_MESSAGES_MATERIAL("SETTINGS.COSMETICS.KILL-MESSAGES.MATERIAL", DataType.STRING, "BOOK"),
KILL_MESSAGES_LORE("SETTINGS.COSMETICS.KILL-MESSAGES.LORE", DataType.STRING_LIST, "&7View all available kill messages", " ", "&aClick to open");
KILL_MESSAGES_LORE("SETTINGS.COSMETICS.KILL-MESSAGES.LORE", DataType.STRING_LIST, "&7View all available kill messages", " ", "&aClick to open"),
KILL_MESSAGES_SELECTED_LORE("SETTINGS.KILL-MESSAGES.SELECTED.LORE", DataType.STRING_LIST,
"<description> ",
"<messages>",
" ",
"&eCurrently Selected"),
KILL_MESSAGES_UNSELECTED_LORE("SETTINGS.KILL-MESSAGES.UNSELECTED.LORE", DataType.STRING_LIST,
"<description> ",
"<messages>",
" ",
"&aClick to select"),
KILL_MESSAGES_NO_PERMISSION_LORE("SETTINGS.KILL-MESSAGES.NO-PERMISSION.LORE", DataType.STRING_LIST,
"<description> ",
"<messages>",
" ",
"&cNo permission");

private final String path;
private final String comment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import dev.lrxh.neptune.configs.impl.MenusLocale;
import dev.lrxh.neptune.cosmetics.impl.KillMessagePackage;
import dev.lrxh.neptune.profile.Profile;
import dev.lrxh.neptune.providers.clickable.Replacement;
import dev.lrxh.neptune.utils.ItemBuilder;
import dev.lrxh.neptune.utils.ItemUtils;
import dev.lrxh.neptune.utils.menu.Button;
import lombok.AllArgsConstructor;
import org.bukkit.entity.Player;
Expand All @@ -25,14 +27,16 @@ public ItemStack getButtonItem(Player player) {
List<String> lore;

if (player.hasPermission(killMessagePackage.permission())) {
lore = selected ? MenusLocale.KILL_EFFECTS_SELECTED_LORE.getStringList() : MenusLocale.KILL_EFFECTS_UNSELECTED_LORE.getStringList();
lore = selected ? MenusLocale.KILL_MESSAGES_SELECTED_LORE.getStringList() : MenusLocale.KILL_MESSAGES_UNSELECTED_LORE.getStringList();
} else {
lore = MenusLocale.KILL_EFFECTS_NO_PERMISSION_LORE.getStringList();
lore = MenusLocale.KILL_MESSAGES_NO_PERMISSION_LORE.getStringList();
}

return new ItemBuilder(killMessagePackage.getMaterial()).name(killMessagePackage.getDisplayName()
.replace("<selected>", selected ? CosmeticsLocale.SELECTED_DISPLAY_NAME.getString() : ""))
.lore(lore)
.lore(ItemUtils.getLore(lore,
new Replacement("<description>", killMessagePackage.getDescription()),
new Replacement("<messages>", killMessagePackage.getMessages())))
.clearFlags()
.build();
}
Expand Down
16 changes: 13 additions & 3 deletions Plugin/src/main/java/dev/lrxh/neptune/utils/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,29 @@ public List<ItemStack> deserialize(String base64) {
return items;
}

@SuppressWarnings("unchecked")
public List<String> getLore(List<String> lore, Replacement... replacements) {
List<String> newLore = new ArrayList<>();

lore.forEach(line -> {
for (String line : lore) {
boolean skip = false;
for (Replacement replacement : replacements) {
if (replacement.getReplacement() instanceof String) {
line = line.replaceAll(replacement.getPlaceholder(), (String) replacement.getReplacement());
}else if (replacement.getReplacement() instanceof List<?>) {
if(line.contains(replacement.getPlaceholder())) {
List<String> replacementList = (List<String>) replacement.getReplacement();
for (String replacementLine : replacementList) {
newLore.add(line.replaceAll(replacement.getPlaceholder(), replacementLine));
}
skip = true;
}
} else if (replacement.getReplacement() instanceof Integer) {
line = line.replaceAll(replacement.getPlaceholder(), String.valueOf(replacement.getReplacement()));
}
}
newLore.add(line);
});
if(!skip) newLore.add(line);
}
return newLore;
}

Expand Down

0 comments on commit ceaf74d

Please sign in to comment.