-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixes #148 * add brightness command * fix brightness command NPE * fix visibility distance * add brightness command to help
- Loading branch information
1 parent
961c735
commit 029c783
Showing
11 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/de/oliver/fancyholograms/commands/hologram/BrightnessCMD.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package de.oliver.fancyholograms.commands.hologram; | ||
|
||
import de.oliver.fancyholograms.FancyHolograms; | ||
import de.oliver.fancyholograms.api.data.DisplayHologramData; | ||
import de.oliver.fancyholograms.api.hologram.Hologram; | ||
import de.oliver.fancyholograms.commands.Subcommand; | ||
import de.oliver.fancyholograms.util.NumberHelper; | ||
import de.oliver.fancylib.MessageHelper; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Display; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class BrightnessCMD implements Subcommand { | ||
|
||
@Override | ||
public List<String> tabcompletion(@NotNull CommandSender player, @Nullable Hologram hologram, @NotNull String[] args) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @NotNull String[] args) { | ||
if (!(hologram.getData() instanceof DisplayHologramData displayData)) { | ||
MessageHelper.error(player, "This command can only be used on display holograms"); | ||
return false; | ||
} | ||
|
||
if(args.length < 5) { | ||
MessageHelper.error(player, "You must provide a brightness type and value."); | ||
return false; | ||
} | ||
|
||
final var brightnessType = args[3]; | ||
|
||
if(!brightnessType.equalsIgnoreCase("block") && !brightnessType.equalsIgnoreCase("sky")) { | ||
MessageHelper.error(player, "Invalid brightness type, valid options are BLOCK or SKY"); | ||
return false; | ||
} | ||
|
||
final var parsedNumber = NumberHelper.parseInt(args[4]); | ||
|
||
if(parsedNumber.isEmpty()) { | ||
MessageHelper.error(player, "Invalid brightness value."); | ||
return false; | ||
} | ||
|
||
final var brightnessValue = parsedNumber.get(); | ||
|
||
if(brightnessValue < 0 || brightnessValue > 15) { | ||
MessageHelper.error(player, "Invalid brightness value, must be between 0 and 15"); | ||
return false; | ||
} | ||
|
||
final var currentBrightness = displayData.getBrightness(); | ||
final var blockBrightness = brightnessType.equalsIgnoreCase("block") ? brightnessValue : | ||
currentBrightness == null ? 0 : currentBrightness.getBlockLight(); | ||
final var skyBrightness = brightnessType.equalsIgnoreCase("sky") ? brightnessValue : | ||
currentBrightness == null ? 0 : currentBrightness.getSkyLight(); | ||
|
||
displayData.setBrightness(new Display.Brightness(blockBrightness, skyBrightness)); | ||
|
||
if (FancyHolograms.get().getHologramConfiguration().isSaveOnChangedEnabled()) { | ||
FancyHolograms.get().getHologramStorage().save(hologram); | ||
} | ||
|
||
MessageHelper.success(player, "Changed " + brightnessType.toLowerCase() + " brightness to " + brightnessValue); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters