Skip to content

Commit 9c34134

Browse files
committed
Create item edit package and move to them item lore, flag, name.
1 parent 34aa32c commit 9c34134

File tree

10 files changed

+160
-75
lines changed

10 files changed

+160
-75
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/ItemFlagCommand.java renamed to eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/itemedit/ItemFlagCommand.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.eternalcode.core.feature.essentials.item;
1+
package com.eternalcode.core.feature.essentials.item.itemedit;
22

33
import com.eternalcode.annotations.scan.command.DescriptionDocs;
44
import com.eternalcode.core.injector.annotations.Inject;
@@ -43,13 +43,14 @@ void execute(@Context Player player, @Arg ItemFlag flag) {
4343

4444
if (meta.hasItemFlag(flag)) {
4545
meta.removeItemFlags(flag);
46-
this.noticeService.player(player.getUniqueId(), translation -> translation.item().itemFlagRemovedMessage(), formatter);
46+
this.noticeService.player(player.getUniqueId(),
47+
translation -> translation.itemEdit().itemFlagRemovedMessage(), formatter);
4748
return;
4849
}
4950

5051
meta.addItemFlags(flag);
5152
hand.setItemMeta(meta);
52-
this.noticeService.player(player.getUniqueId(), translation -> translation.item().itemFlagAddedMessage(), formatter);
53+
this.noticeService.player(player.getUniqueId(), translation -> translation.itemEdit().itemFlagAddedMessage(), formatter);
5354
}
5455

5556
@Execute(name = "clear")
@@ -65,7 +66,7 @@ void clear(@Context Player player) {
6566

6667
meta.removeItemFlags(ItemFlag.values());
6768
hand.setItemMeta(meta);
68-
this.noticeService.player(player.getUniqueId(), translation -> translation.item().itemFlagClearedMessage());
69+
this.noticeService.player(player.getUniqueId(), translation -> translation.itemEdit().itemFlagClearedMessage());
6970
}
7071

7172
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/lore/ItemLoreArgument.java renamed to eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/itemedit/ItemLoreArgument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.eternalcode.core.feature.essentials.item.lore;
1+
package com.eternalcode.core.feature.essentials.item.itemedit;
22

33
import com.eternalcode.core.bridge.litecommand.argument.AbstractViewerArgument;
44
import com.eternalcode.core.injector.annotations.Inject;

eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/lore/ItemLoreCommand.java renamed to eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/itemedit/ItemLoreCommand.java

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
package com.eternalcode.core.feature.essentials.item.lore;
1+
package com.eternalcode.core.feature.essentials.item.itemedit;
22

33
import com.eternalcode.annotations.scan.command.DescriptionDocs;
44
import com.eternalcode.commons.adventure.AdventureUtil;
55
import com.eternalcode.core.injector.annotations.Inject;
66
import com.eternalcode.core.notice.NoticeService;
7-
import com.eternalcode.commons.adventure.AdventureUtil;
87
import dev.rollczi.litecommands.annotations.argument.Arg;
98
import dev.rollczi.litecommands.annotations.context.Context;
109
import dev.rollczi.litecommands.annotations.join.Join;
1110
import dev.rollczi.litecommands.annotations.execute.Execute;
1211
import dev.rollczi.litecommands.annotations.permission.Permission;
1312
import dev.rollczi.litecommands.annotations.command.Command;
1413
import net.kyori.adventure.text.minimessage.MiniMessage;
14+
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
1515
import org.bukkit.Material;
1616
import org.bukkit.entity.Player;
1717
import org.bukkit.inventory.ItemStack;
@@ -40,53 +40,79 @@ void execute(@Context Player player, @Arg(ItemLoreArgument.KEY) int line, @Join
4040

4141
if (itemStack == null) {
4242
this.noticeService.player(player.getUniqueId(), translation -> translation.argument().noItem());
43-
4443
return;
4544
}
4645

4746
ItemMeta itemMeta = itemStack.getItemMeta();
4847

4948
List<String> lore = itemMeta.getLore();
50-
5149
lore = lore == null ? new ArrayList<>() : new ArrayList<>(lore);
5250

53-
if (text.equals("none")) {
54-
lore.remove(line);
51+
while (lore.size() <= line) {
52+
lore.add("");
5553
}
56-
else {
57-
// fill list
58-
while (lore.size() <= line) {
59-
lore.add("");
60-
}
6154

62-
lore.set(line, AdventureUtil.SECTION_SERIALIZER.serialize(AdventureUtil.resetItalic(this.miniMessage.deserialize(text))));
63-
}
55+
// Serialize using GsonComponentSerializer for modern Minecraft versions
56+
String json = GsonComponentSerializer.gson().serialize(
57+
AdventureUtil.resetItalic(this.miniMessage.deserialize(text))
58+
);
59+
lore.set(line, json);
6460

6561
itemMeta.setLore(lore);
6662
itemStack.setItemMeta(itemMeta);
6763

6864
this.noticeService.create()
69-
.notice(translation -> translation.item().itemChangeLoreMessage())
65+
.notice(translation -> translation.itemEdit().itemChangeLoreMessage())
7066
.placeholder("{ITEM_LORE}", text)
7167
.player(player.getUniqueId())
7268
.send();
7369
}
7470

71+
@Execute(name = "remove")
72+
@DescriptionDocs(description = "Removes a specific line of lore from the item in hand", arguments = "<line>")
73+
void remove(@Context Player player, @Arg(ItemLoreArgument.KEY) int line) {
74+
ItemStack itemStack = this.validateItemFromMainHand(player);
75+
76+
if (itemStack == null) {
77+
this.noticeService.player(player.getUniqueId(), translation -> translation.argument().noItem());
78+
return;
79+
}
80+
81+
ItemMeta itemMeta = itemStack.getItemMeta();
82+
List<String> lore = itemMeta.getLore();
83+
84+
if (lore == null || lore.isEmpty()) {
85+
this.noticeService.player(player.getUniqueId(), translation -> translation.itemEdit().noLore());
86+
return;
87+
}
88+
89+
if (line < 0 || line >= lore.size()) {
90+
this.noticeService.player(player.getUniqueId(), translation -> translation.itemEdit().invalidLoreLine());
91+
return;
92+
}
93+
94+
lore.remove(line);
95+
itemMeta.setLore(lore);
96+
itemStack.setItemMeta(itemMeta);
97+
98+
this.noticeService.player(player.getUniqueId(), translation -> translation.itemEdit().itemLoreLineRemoved());
99+
}
100+
75101
@Execute(name = "clear")
76-
@DescriptionDocs(description = "Clears lore of item in hand")
102+
@DescriptionDocs(description = "Clears all lore from the item in hand")
77103
void clear(@Context Player player) {
78104
ItemStack itemStack = this.validateItemFromMainHand(player);
79105

80106
if (itemStack == null) {
107+
this.noticeService.player(player.getUniqueId(), translation -> translation.argument().noItem());
81108
return;
82109
}
83110

84111
ItemMeta itemMeta = itemStack.getItemMeta();
85-
86112
itemMeta.setLore(new ArrayList<>());
87113
itemStack.setItemMeta(itemMeta);
88114

89-
this.noticeService.player(player.getUniqueId(), translation -> translation.item().itemClearLoreMessage());
115+
this.noticeService.player(player.getUniqueId(), translation -> translation.itemEdit().itemClearLoreMessage());
90116
}
91117

92118
private ItemStack validateItemFromMainHand(Player player) {
@@ -98,5 +124,4 @@ private ItemStack validateItemFromMainHand(Player player) {
98124

99125
return itemStack;
100126
}
101-
102127
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/ItemNameCommand.java renamed to eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/itemedit/ItemNameCommand.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package com.eternalcode.core.feature.essentials.item;
1+
package com.eternalcode.core.feature.essentials.item.itemedit;
22

33
import com.eternalcode.annotations.scan.command.DescriptionDocs;
44
import com.eternalcode.commons.adventure.AdventureUtil;
55
import com.eternalcode.core.injector.annotations.Inject;
66
import com.eternalcode.core.notice.NoticeService;
7-
import com.eternalcode.commons.adventure.AdventureUtil;
87
import dev.rollczi.litecommands.annotations.context.Context;
98
import dev.rollczi.litecommands.annotations.join.Join;
109
import dev.rollczi.litecommands.annotations.execute.Execute;
@@ -48,7 +47,7 @@ void execute(@Context Player player, @Join String name) {
4847
itemStack.setItemMeta(itemMeta);
4948

5049
this.noticeService.create()
51-
.notice(translation -> translation.item().itemChangeNameMessage())
50+
.notice(translation -> translation.itemEdit().itemChangeNameMessage())
5251
.placeholder("{ITEM_NAME}", name)
5352
.player(player.getUniqueId())
5453
.send();
@@ -68,7 +67,7 @@ void clear(@Context Player player) {
6867
itemMeta.setDisplayName(null);
6968
itemStack.setItemMeta(itemMeta);
7069

71-
this.noticeService.player(player.getUniqueId(), translation -> translation.item().itemClearNameMessage());
70+
this.noticeService.player(player.getUniqueId(), translation -> translation.itemEdit().itemClearNameMessage());
7271
}
7372

7473
private ItemStack validateItemFromMainHand(Player player) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.eternalcode.core.feature.essentials.item.itemedit.messages;
2+
3+
import com.eternalcode.multification.notice.Notice;
4+
import lombok.Getter;
5+
import lombok.experimental.Accessors;
6+
import net.dzikoysk.cdn.entity.Contextual;
7+
import net.dzikoysk.cdn.entity.Description;
8+
9+
@Getter
10+
@Accessors(fluent = true)
11+
@Contextual
12+
public class ENItemEditMessages implements ItemEditMessages {
13+
14+
@Description("# {ITEM_NAME} - New item name")
15+
public Notice itemChangeNameMessage = Notice.chat("<green>► <white>Name changed to: <green>{ITEM_NAME}");
16+
17+
@Description(" ")
18+
public Notice itemClearNameMessage = Notice.chat("<green>► <white>Item name cleared!");
19+
20+
@Description({" ", "# {ITEM_LORE} - New item lore"})
21+
public Notice itemChangeLoreMessage = Notice.chat("<green>► <white>Lore changed to: <green>{ITEM_LORE}");
22+
23+
@Description(" ")
24+
public Notice itemClearLoreMessage = Notice.chat("<green>► <white>Item lore cleared!");
25+
26+
@Description({" ", "# {LINE} - Line number removed"})
27+
public Notice itemLoreLineRemoved = Notice.chat("<green>► <white>Removed lore line: <green>{LINE}");
28+
29+
@Description({" ", "# {ITEM_FLAG} - Flag name"})
30+
public Notice itemFlagRemovedMessage = Notice.chat("<green>► <white>Removed item flag: <green>{ITEM_FLAG}");
31+
public Notice itemFlagAddedMessage = Notice.chat("<green>► <white>Added item flag: <green>{ITEM_FLAG}");
32+
33+
@Description(" ")
34+
public Notice itemFlagClearedMessage = Notice.chat("<green>► <white>All item flags cleared!");
35+
36+
@Description(" ")
37+
public Notice noLore = Notice.chat("<red>✖ <white>This item has no lore!");
38+
39+
@Description(" ")
40+
public Notice invalidLoreLine = Notice.chat("<red>✖ <white>Invalid lore line number!");
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.eternalcode.core.feature.essentials.item.itemedit.messages;
2+
3+
import com.eternalcode.multification.notice.Notice;
4+
5+
public interface ItemEditMessages {
6+
// Item name
7+
Notice itemChangeNameMessage();
8+
Notice itemClearNameMessage();
9+
10+
// Item lore
11+
Notice itemChangeLoreMessage();
12+
Notice itemClearLoreMessage();
13+
Notice itemLoreLineRemoved();
14+
15+
// Item flags
16+
Notice itemFlagRemovedMessage();
17+
Notice itemFlagAddedMessage();
18+
Notice itemFlagClearedMessage();
19+
20+
// Validation
21+
Notice noLore();
22+
Notice invalidLoreLine();
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.eternalcode.core.feature.essentials.item.itemedit.messages;
2+
3+
import com.eternalcode.multification.notice.Notice;
4+
import lombok.Getter;
5+
import lombok.experimental.Accessors;
6+
import net.dzikoysk.cdn.entity.Contextual;
7+
import net.dzikoysk.cdn.entity.Description;
8+
9+
@Getter
10+
@Accessors(fluent = true)
11+
@Contextual
12+
public class PLItemEditMessages implements ItemEditMessages {
13+
14+
@Description("# {ITEM_NAME} - Nowa nazwa przedmiotu")
15+
public Notice itemChangeNameMessage = Notice.chat("<green>► <white>Nowa nazwa przedmiotu: <green>{ITEM_NAME}");
16+
17+
@Description(" ")
18+
public Notice itemClearNameMessage = Notice.chat("<green>► <white>Wyczyszczono nazwę przedmiotu!");
19+
20+
@Description({" ", "# {ITEM_LORE} - Nowa linia opisu"})
21+
public Notice itemChangeLoreMessage = Notice.chat("<green>► <white>Zmieniono linię opisu na: <green>{ITEM_LORE}");
22+
23+
@Description(" ")
24+
public Notice itemClearLoreMessage = Notice.chat("<green>► <white>Wyczyszczono wszystkie linie opisu!");
25+
26+
@Description({" ", "# {LINE} - Numer linii usuniętej"})
27+
public Notice itemLoreLineRemoved = Notice.chat("<green>► <white>Usunięto linię opisu (numer): <green>{LINE}");
28+
29+
@Description({" ", "# {ITEM_FLAG} - Nazwa flagi"})
30+
public Notice itemFlagRemovedMessage = Notice.chat("<green>► <white>Usunięto flagę przedmiotu: <green>{ITEM_FLAG}");
31+
public Notice itemFlagAddedMessage = Notice.chat("<green>► <white>Dodano flagę przedmiotu: <green>{ITEM_FLAG}");
32+
33+
@Description(" ")
34+
public Notice itemFlagClearedMessage = Notice.chat("<green>► <white>Wyczyszczono wszystkie flagi przedmiotu!");
35+
36+
@Description(" ")
37+
public Notice noLore = Notice.chat("<red>✖ <white>Ten przedmiot nie ma opisu!");
38+
39+
@Description(" ")
40+
public Notice invalidLoreLine = Notice.chat("<red>✖ <white>Nieprawidłowy numer linii opisu!");
41+
}

eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.eternalcode.core.feature.adminchat.messages.AdminChatMessages;
66
import com.eternalcode.core.feature.afk.messages.AfkMessages;
77
import com.eternalcode.core.feature.automessage.messages.AutoMessageMessages;
8+
import com.eternalcode.core.feature.essentials.item.itemedit.messages.ItemEditMessages;
89
import com.eternalcode.core.feature.helpop.messages.HelpOpSection;
910
import com.eternalcode.core.feature.home.messages.HomeMessages;
1011
import com.eternalcode.core.feature.jail.messages.JailMessages;
@@ -158,18 +159,6 @@ interface PlayerSection {
158159
}
159160

160161
interface ItemSection {
161-
// item name & lore
162-
Notice itemClearNameMessage();
163-
Notice itemClearLoreMessage();
164-
165-
Notice itemChangeNameMessage();
166-
Notice itemChangeLoreMessage();
167-
168-
// item flags
169-
Notice itemFlagRemovedMessage();
170-
Notice itemFlagAddedMessage();
171-
Notice itemFlagClearedMessage();
172-
173162
// give
174163
Notice giveReceived();
175164
Notice giveGiven();
@@ -235,6 +224,8 @@ interface ContainerSection {
235224
SetSlotMessages setSlot();
236225
// item section
237226
ItemSection item();
227+
// itemedit
228+
ItemEditMessages itemEdit();
238229
// time and weather
239230
TimeAndWeatherMessages timeAndWeather();
240231
// language section

eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -464,25 +464,6 @@ public static class ENPlayerSection implements PlayerSection {
464464
@Getter
465465
@Contextual
466466
public static class ENItemSection implements ItemSection {
467-
@Description("# {ITEM_NAME} - New item name")
468-
public Notice itemChangeNameMessage = Notice.chat("<green>► <white>Name has been changed to: <green>{ITEM_NAME}");
469-
470-
@Description(" ")
471-
public Notice itemClearNameMessage = Notice.chat("<green>► <white>Name has been cleared!");
472-
473-
@Description({" ", "# {ITEM_LORE} - New item lore"})
474-
public Notice itemChangeLoreMessage = Notice.chat("<green>► <white>Lore has been changed to: <green>{ITEM_LORE}");
475-
476-
@Description(" ")
477-
public Notice itemClearLoreMessage = Notice.chat("<green>► <white>Lore has been cleared!");
478-
479-
@Description({" ", "# {ITEM_FLAG} - Flag name"})
480-
public Notice itemFlagRemovedMessage = Notice.chat("<green>► <white>Flag <green>{ITEM_FLAG} <white>has been removed!");
481-
public Notice itemFlagAddedMessage = Notice.chat("<green>► <white>Flag <green>{ITEM_FLAG} <white>has been added!");
482-
483-
@Description(" ")
484-
public Notice itemFlagClearedMessage = Notice.chat("<green>► <white>Flags have been cleared!");
485-
486467
@Description({" ", "# {ITEM} - Name of received item"})
487468
public Notice giveReceived = Notice.chat("<green>► <white>You have received: <green>{ITEM}");
488469

@@ -507,7 +488,6 @@ public static class ENItemSection implements ItemSection {
507488
public Notice enchantedMessageBy = Notice.chat("<green>► <white>Administrator <green>{PLAYER} <white>enchanted your item!");
508489
}
509490

510-
511491
@Description({" ", "# Messages sent on time and weather change."})
512492
public ENTimeAndWeatherMessages timeAndWeather = new ENTimeAndWeatherMessages();
513493

eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,22 +480,6 @@ public static class PLPlayerSection implements PlayerSection {
480480
@Getter
481481
@Contextual
482482
public static class PLItemSection implements ItemSection {
483-
@Description("# {ITEM_NAME} - Nowa nazwa itemu")
484-
public Notice itemChangeNameMessage = Notice.chat("<green>► <white>Nowa nazwa itemu: <green>{ITEM_NAME}");
485-
@Description(" ")
486-
public Notice itemClearNameMessage = Notice.chat("<green>► <white>Wyczyszczono nazwę itemu!");
487-
488-
@Description({" ", "# {ITEM_LORE} - Nowe linia opisu"})
489-
public Notice itemChangeLoreMessage = Notice.chat("<green>► <white>Nowa linia opisu: <green>{ITEM_LORE}");
490-
@Description(" ")
491-
public Notice itemClearLoreMessage = Notice.chat("<green>► <white>Wyczyszczono linie opisu!");
492-
493-
@Description({" ", "# {ITEM_FLAG} - Nowa flaga itemu"})
494-
public Notice itemFlagRemovedMessage = Notice.chat("<green>► <white>Usunięto flagę: <green>{ITEM_FLAG}");
495-
public Notice itemFlagAddedMessage = Notice.chat("<green>► <white>Dodano flagę: <green>{ITEM_FLAG}");
496-
@Description(" ")
497-
public Notice itemFlagClearedMessage = Notice.chat("<green>► <white>Wyczyszczono flagi!");
498-
499483
@Description({" ", "# {ITEM} - Nazwa otrzymanego itemu"})
500484
public Notice giveReceived = Notice.chat("<green>► <white>Otrzymałeś: <green>{ITEM}");
501485

0 commit comments

Comments
 (0)