-
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.
Add converter api and DecentHolograms converter (#173)
* 🔥 Test converter * 🔥 Working on a more advanced api * Rename * 🔥 Add dev-friendly interface for converters * 🔥 Working `DecentHolograms` converter * 🔥 Warn with --processIcons and remove #ICON lines * 🔥 Complete DecentHolograms converter.
- Loading branch information
Showing
12 changed files
with
640 additions
and
13 deletions.
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
80 changes: 80 additions & 0 deletions
80
src/main/java/de/oliver/fancyholograms/commands/hologram/TranslateCommand.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,80 @@ | ||
package de.oliver.fancyholograms.commands.hologram; | ||
|
||
import com.google.common.primitives.Floats; | ||
import de.oliver.fancyholograms.FancyHolograms; | ||
import de.oliver.fancyholograms.api.hologram.Hologram; | ||
import de.oliver.fancyholograms.api.data.DisplayHologramData; | ||
import de.oliver.fancyholograms.api.events.HologramUpdateEvent; | ||
import de.oliver.fancyholograms.commands.HologramCMD; | ||
import de.oliver.fancyholograms.commands.Subcommand; | ||
import de.oliver.fancylib.MessageHelper; | ||
import org.bukkit.command.CommandSender; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.joml.Vector3f; | ||
|
||
import java.util.List; | ||
|
||
public class TranslateCommand 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 (!(player.hasPermission("fancyholograms.hologram.edit.translate"))) { | ||
MessageHelper.error(player, "You don't have the required permission to change the translation of a hologram"); | ||
return false; | ||
} | ||
|
||
final var translateX = Floats.tryParse(args[3]); | ||
final var translateY = args.length >= 6 ? Floats.tryParse(args[4]) : translateX; | ||
final var translateZ = args.length >= 6 ? Floats.tryParse(args[5]) : translateX; | ||
|
||
if (translateX == null || translateY == null || translateZ == null) { | ||
MessageHelper.error(player, "Could not parse translation"); | ||
return false; | ||
} | ||
|
||
if (!(hologram.getData() instanceof DisplayHologramData displayData)) { | ||
MessageHelper.error(player, "This command can only be used on display holograms"); | ||
return false; | ||
} | ||
|
||
if (Float.compare(translateX, displayData.getTranslation().x()) == 0 && | ||
Float.compare(translateY, displayData.getTranslation().y()) == 0 && | ||
Float.compare(translateZ, displayData.getTranslation().z()) == 0) { | ||
MessageHelper.warning(player, "This hologram is already at this translation"); | ||
return false; | ||
} | ||
|
||
final var copied = displayData.copy(displayData.getName()); | ||
copied.setTranslation(new Vector3f(translateX, translateY, translateZ)); | ||
|
||
if (!HologramCMD.callModificationEvent(hologram, player, copied, HologramUpdateEvent.HologramModification.TRANSLATION)) { | ||
return false; | ||
} | ||
|
||
if (Float.compare(copied.getTranslation().x(), displayData.getTranslation().x()) == 0 && | ||
Float.compare(copied.getTranslation().y(), displayData.getTranslation().y()) == 0 && | ||
Float.compare(copied.getTranslation().z(), displayData.getTranslation().z()) == 0) { | ||
MessageHelper.warning(player, "This hologram is already at this translation"); | ||
return false; | ||
} | ||
|
||
displayData.setTranslation(new Vector3f( | ||
copied.getTranslation().x(), | ||
copied.getTranslation().y(), | ||
copied.getTranslation().z())); | ||
|
||
if (FancyHolograms.get().getHologramConfiguration().isSaveOnChangedEnabled()) { | ||
FancyHolograms.get().getHologramStorage().save(hologram); | ||
} | ||
|
||
MessageHelper.success(player, "Changed translation to " + translateX + ", " + translateY + ", " + translateZ); | ||
return true; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/de/oliver/fancyholograms/storage/converter/ConverterTarget.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,57 @@ | ||
package de.oliver.fancyholograms.storage.converter; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class ConverterTarget { | ||
private final @NotNull Pattern hologramIdRegex; | ||
|
||
public ConverterTarget(@NotNull Pattern matching) { | ||
this.hologramIdRegex = matching; | ||
} | ||
|
||
public @NotNull Pattern getRegex() { | ||
return hologramIdRegex; | ||
} | ||
|
||
public boolean matches(@NotNull String hologramId) { | ||
return hologramIdRegex.asMatchPredicate().test(hologramId); | ||
} | ||
|
||
private static final ConverterTarget ALL = new ConverterTarget(Pattern.compile(".*")); | ||
public static @NotNull ConverterTarget all() { | ||
return ALL; | ||
} | ||
|
||
public static @NotNull ConverterTarget ofAll(@NotNull String first, @NotNull String... others) { | ||
StringBuilder builder = new StringBuilder(first); | ||
|
||
if (others.length > 0) { | ||
builder.append("|"); | ||
} | ||
|
||
builder.append(String.join("|", others)); | ||
|
||
return new ConverterTarget(Pattern.compile(builder.toString())); | ||
} | ||
|
||
public static @NotNull ConverterTarget ofSingle(@NotNull String match) { | ||
return new ConverterTarget(Pattern.compile(match)); | ||
} | ||
|
||
public static @Nullable ConverterTarget ofStringNullable(@NotNull String match) { | ||
|
||
if (match.equalsIgnoreCase("*")) { | ||
return all(); | ||
} | ||
|
||
try { | ||
return new ConverterTarget(Pattern.compile(match)); | ||
} catch (Exception ignored) { | ||
return null; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.