|
| 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 | +} |
0 commit comments