Skip to content

Commit 662fbab

Browse files
committed
add glow sub-command for item and block displays
1 parent 782ad42 commit 662fbab

File tree

4 files changed

+140
-5
lines changed

4 files changed

+140
-5
lines changed

src/main/java/cloud/grabsky/displayentities/DisplayEntities.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import cloud.grabsky.displayentities.command.CommandDisplayClone;
3535
import cloud.grabsky.displayentities.command.CommandDisplayCreate;
3636
import cloud.grabsky.displayentities.command.CommandDisplayDelete;
37+
import cloud.grabsky.displayentities.command.CommandDisplayGlow;
3738
import cloud.grabsky.displayentities.command.CommandDisplayHeight;
3839
import cloud.grabsky.displayentities.command.CommandDisplayHelp;
3940
import cloud.grabsky.displayentities.command.CommandDisplayItem;
@@ -217,6 +218,7 @@ private void registerCommands(final @NotNull Lamp<BukkitCommandActor> lamp) {
217218
lamp.register(CommandDisplayBrightness.INSTANCE);
218219
lamp.register(CommandDisplayRotateX.INSTANCE);
219220
lamp.register(CommandDisplayRotateY.INSTANCE);
221+
lamp.register(CommandDisplayGlow.INSTANCE);
220222
// Editing (Block)
221223
lamp.register(CommandDisplayBlock.INSTANCE);
222224
// Editing (Item)

src/main/java/cloud/grabsky/displayentities/DisplayWrapper.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.bukkit.entity.Display;
3636
import org.bukkit.entity.Entity;
3737
import org.bukkit.entity.EntityType;
38-
import org.bukkit.entity.Interaction;
3938
import org.bukkit.entity.ItemDisplay;
4039
import org.bukkit.entity.TextDisplay;
4140
import org.bukkit.event.entity.CreatureSpawnEvent;
@@ -164,9 +163,16 @@ public <T extends DisplayWrapper> boolean is(final Class<T> type) {
164163
*/
165164
public static abstract non-sealed class Strict extends DisplayWrapper {
166165

167-
private Strict(final @NotNull Class<? extends Entity> type, @NotNull final String name, @NotNull final Entity entity) {
166+
private Strict(final @NotNull Class<? extends Display> type, @NotNull final String name, @NotNull final Display entity) {
168167
super(type, name, entity);
169168
}
169+
170+
@Override @SuppressWarnings("unchecked")
171+
public @NotNull Display entity() {
172+
return (Display) this.entity;
173+
}
174+
175+
170176
}
171177

172178
public static final class Text extends DisplayWrapper.Strict {
@@ -175,7 +181,7 @@ private Text(final @NotNull TextDisplay entity, final @NotNull String name) {
175181
super(TextDisplay.class, name, entity);
176182
}
177183

178-
@Override @SuppressWarnings("unchecked")
184+
@Override
179185
public @NotNull TextDisplay entity() {
180186
return (TextDisplay) this.entity;
181187
}
@@ -199,7 +205,7 @@ private Item(final @NotNull ItemDisplay entity, final @NotNull String name) {
199205
super(ItemDisplay.class, name, entity);
200206
}
201207

202-
@Override @SuppressWarnings("unchecked")
208+
@Override
203209
public @NotNull ItemDisplay entity() {
204210
return (ItemDisplay) this.entity;
205211
}
@@ -222,7 +228,7 @@ private Block(final @NotNull BlockDisplay entity, final @NotNull String name) {
222228
super(BlockDisplay.class, name, entity);
223229
}
224230

225-
@Override @SuppressWarnings("unchecked")
231+
@Override
226232
public @NotNull BlockDisplay entity() {
227233
return (BlockDisplay) this.entity;
228234
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* DisplayEntities (https://github.com/Grabsky/DisplayEntities)
3+
*
4+
* MIT License
5+
*
6+
* Copyright (c) 2025 Grabsky (michal.czopek.foss@proton.me)
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
package cloud.grabsky.displayentities.command;
27+
28+
import cloud.grabsky.displayentities.DisplayWrapper;
29+
import cloud.grabsky.displayentities.configuration.PluginConfiguration;
30+
import cloud.grabsky.displayentities.util.LombokExtensions;
31+
import org.bukkit.Color;
32+
import org.bukkit.entity.Player;
33+
import revxrsal.commands.annotation.Command;
34+
import revxrsal.commands.annotation.Dependency;
35+
import revxrsal.commands.bukkit.annotation.CommandPermission;
36+
37+
import org.jetbrains.annotations.NotNull;
38+
39+
import lombok.experimental.ExtensionMethod;
40+
41+
// NOTE: Glowing effect can technically be applied to any display entity, but is only visible on block and item displays.
42+
// That's the reason why command logic is duplicated for each "working" display type.
43+
@ExtensionMethod(LombokExtensions.class)
44+
public enum CommandDisplayGlow {
45+
INSTANCE; // SINGLETON
46+
47+
@Dependency
48+
private PluginConfiguration configuration;
49+
50+
51+
/* ITEM DISPLAY */
52+
53+
@Command("display edit <display> glow")
54+
@CommandPermission("displayentities.command.display.edit.glow")
55+
public String onItemDisplayGlow(
56+
final @NotNull Player sender,
57+
final @NotNull DisplayWrapper.Item display,
58+
final @NotNull Color color
59+
) {
60+
// Enabling glow state and updating value of the glow color override property of the display.
61+
display.entity().setGlowing(true);
62+
display.entity().setGlowColorOverride(color);
63+
// Sending success message to the sender.
64+
return configuration.messages().commandDisplayEditGlowColorChangeSuccess().repl("{color}", "#" + Integer.toHexString(color.asRGB()).toUpperCase());
65+
}
66+
67+
@Command("display edit <display> glow @none")
68+
@CommandPermission("displayentities.command.display.edit.glow")
69+
public String onItemDisplayGlow(
70+
final @NotNull Player sender,
71+
final @NotNull DisplayWrapper.Item display
72+
) {
73+
// Disabling glow state of the display.
74+
display.entity().setGlowing(false);
75+
// Sending success message to the sender.
76+
return configuration.messages().commandDisplayEditGlowDisabledSuccess();
77+
}
78+
79+
80+
/* BLOCK DISPLAY */
81+
82+
@Command("display edit <display> glow")
83+
@CommandPermission("displayentities.command.display.edit.glow")
84+
public String onBlockDisplayGlow(
85+
final @NotNull Player sender,
86+
final @NotNull DisplayWrapper.Block display,
87+
final @NotNull Color color
88+
) {
89+
// Enabling glow state and updating value of the glow color override property of the display.
90+
display.entity().setGlowing(true);
91+
display.entity().setGlowColorOverride(color);
92+
// Sending success message to the sender.
93+
return configuration.messages().commandDisplayEditGlowColorChangeSuccess().repl("{color}", "#" + Integer.toHexString(color.asRGB()).toUpperCase());
94+
}
95+
96+
@Command("display edit <display> glow @none")
97+
@CommandPermission("displayentities.command.display.edit.glow")
98+
public String onBlockDisplayGlow(
99+
final @NotNull Player sender,
100+
final @NotNull DisplayWrapper.Block display
101+
) {
102+
// Disabling glow state of the display.
103+
display.entity().setGlowing(false);
104+
// Sending success message to the sender.
105+
return configuration.messages().commandDisplayEditGlowDisabledSuccess();
106+
}
107+
108+
}

src/main/java/cloud/grabsky/displayentities/configuration/PluginConfiguration.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,15 @@ default LinkedHashMap<String, String> commandUsages() {
184184
put("display.edit.text_shadow", "<text_primary>/display edit <text_secondary>(display) <text_primary>text_shadow <text_secondary>(true | false)");
185185
put("display.edit.text_opacity", "<text_primary>/display edit <text_secondary>(display) <text_primary>text_opacity <text_secondary>(opacity)");
186186
put("display.edit.block", "<block_primary>/display edit <block_secondary>(display) <block_primary>block <block_secondary>(hand | type)");
187+
put("display.edit.block.glow", "<block_primary>/display edit <block_secondary>(display) <block_primary>glow <block_secondary>(@none | color)");
187188
put("display.edit.item", "<item_primary>/display edit <item_secondary>(display) <item_primary>item <item_secondary>(hand | type)");
188189
put("display.edit.transform", "<item_primary>/display edit <item_secondary>(display) <item_primary>transform <item_secondary>(transform)");
190+
put("display.edit.item.glow", "<item_primary>/display edit <item_secondary>(display) <item_primary>glow <item_secondary>(@none | color)");
189191
put("display.edit.width", "<interaction_primary>/display edit <interaction_secondary>(display) <interaction_primary>width <interaction_secondary>(width)");
190192
put("display.edit.height", "<interaction_primary>/display edit <interaction_secondary>(display) <interaction_primary>height <interaction_secondary>(height)");
191193
put("display.edit.response", "<interaction_primary>/display edit <interaction_secondary>(display) <interaction_primary>response <interaction_secondary>(true | false)");
194+
// Additional glow entry for in-game 'invalid-usage' message. The reason why it is needed is because the glow command only available for item and block displays.
195+
put("display.edit.glow", "<common_primary>/display edit <common_secondary>(display) <common_primary>glow <common_secondary>(@none | color)");
192196
}};
193197
}
194198

@@ -234,8 +238,10 @@ default List<String> commandDisplayHelpContents() {
234238
"<dark_gray>› <spec:messages.command_usages.display.edit.text_shadow>",
235239
"<dark_gray>› <spec:messages.command_usages.display.edit.text_opacity>",
236240
"<dark_gray>› <spec:messages.command_usages.display.edit.block>",
241+
"<dark_gray>› <spec:messages.command_usages.display.edit.block.glow>",
237242
"<dark_gray>› <spec:messages.command_usages.display.edit.item>",
238243
"<dark_gray>› <spec:messages.command_usages.display.edit.transform>",
244+
"<dark_gray>› <spec:messages.command_usages.display.edit.item.glow>",
239245
"<dark_gray>› <spec:messages.command_usages.display.edit.width>",
240246
"<dark_gray>› <spec:messages.command_usages.display.edit.height>",
241247
"<dark_gray>› <spec:messages.command_usages.display.edit.response>"
@@ -519,6 +525,19 @@ default String commandDisplayEditTransformSuccess() {
519525
return "<dark_gray>› <gray>Display transform has been set to <primary>{transform}<gray>.";
520526
}
521527

528+
// Display > Edit > Glow (Common)
529+
530+
@Order(56) @Key("command.display.edit.glow.color_change.success")
531+
@Comment("Display > Edit > Glow")
532+
default String commandDisplayEditGlowColorChangeSuccess() {
533+
return "<dark_gray>› <gray>Display glow color has been set to <primary>{color}<gray>.";
534+
}
535+
536+
@Order(57) @Key("command.display.edit.glow.disabled.success")
537+
default String commandDisplayEditGlowDisabledSuccess() {
538+
return "<dark_gray>› <gray>Display glow has been disabled.";
539+
}
540+
522541
}
523542

524543
/* IMPLEMENTED BY SPEC */

0 commit comments

Comments
 (0)