mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancyholograms v3: Refactor trait commands and add warning if using dev build
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
**ATTENTION**: v3 is still in development and contains breaking changes and potential bugs.
|
||||
Do not use this version in production at all, or you may lose data!!
|
||||
**ATTENTION**: v3 is still in development and contains breaking changes and potential bugs.
|
||||
Do not use this version in production at all, or you may lose data!
|
||||
Once migrated to v3, you cannot go back to v2 without losing all your holograms and configurations!
|
||||
|
||||
Commit hash: %COMMIT_HASH%
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
3.0.0-SNAPSHOT.6
|
||||
3.0.0-SNAPSHOT.7
|
||||
@@ -202,10 +202,6 @@ public final class HologramCMD extends Command {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if (args[2].equalsIgnoreCase("traits")) {
|
||||
return new TraitsCMD().tabcompletion(sender, hologram, args);
|
||||
}
|
||||
|
||||
// /holo edit [hologram] [option] {tab:contextual}
|
||||
if (args.length == 4) {
|
||||
final var suggestions = switch (args[2].toLowerCase(Locale.ROOT)) {
|
||||
@@ -354,9 +350,6 @@ public final class HologramCMD extends Command {
|
||||
}
|
||||
|
||||
return switch (action) {
|
||||
// hologram data
|
||||
case "traits" -> new TraitsCMD().run(player, hologram, args);
|
||||
|
||||
// display data
|
||||
case "moveto" -> new MoveToCMD().run(player, hologram, args);
|
||||
case "rotate" -> new RotateCMD().run(player, hologram, args);
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
package com.fancyinnovations.fancyholograms.commands.hologram;
|
||||
|
||||
import com.fancyinnovations.fancyholograms.api.FancyHolograms;
|
||||
import com.fancyinnovations.fancyholograms.api.hologram.Hologram;
|
||||
import com.fancyinnovations.fancyholograms.api.trait.HologramTraitRegistry;
|
||||
import com.fancyinnovations.fancyholograms.commands.Subcommand;
|
||||
import de.oliver.fancylib.MessageHelper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TraitsCMD implements Subcommand {
|
||||
|
||||
@Override
|
||||
public List<String> tabcompletion(@NotNull CommandSender player, @Nullable Hologram hologram, @NotNull String[] args) {
|
||||
if (args.length == 4) {
|
||||
return List.of("add", "remove");
|
||||
} else if (args.length == 5) {
|
||||
return FancyHolograms.get().getTraitRegistry().getTraits()
|
||||
.stream()
|
||||
.filter(ti -> !ti.isDefault())
|
||||
.filter(ti -> {
|
||||
if (args[3].equalsIgnoreCase("add")) {
|
||||
return !hologram.getData().getTraitTrait().isTraitAttached(ti.clazz());
|
||||
} else if (args[3].equalsIgnoreCase("remove")) {
|
||||
return hologram.getData().getTraitTrait().isTraitAttached(ti.clazz());
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.map(HologramTraitRegistry.TraitInfo::name)
|
||||
.toList();
|
||||
}
|
||||
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @NotNull String[] args) {
|
||||
if (!(player.hasPermission("fancyholograms.hologram.edit.traits"))) {
|
||||
MessageHelper.error(player, "You don't have the required permission to change traits of a hologram.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// /hologram edit <name> traits <add|remove> <trait name>
|
||||
|
||||
if (args.length < 5) {
|
||||
MessageHelper.error(player, "Usage: /hologram edit <name> traits <add|remove> <trait name>");
|
||||
return false;
|
||||
}
|
||||
|
||||
String action = args[3];
|
||||
String traitName = args[4];
|
||||
if (traitName == null || traitName.isEmpty()) {
|
||||
MessageHelper.error(player, "You must specify a trait name.");
|
||||
return false;
|
||||
}
|
||||
|
||||
HologramTraitRegistry.TraitInfo traitInfo = FancyHolograms.get().getTraitRegistry().getTrait(traitName);
|
||||
if (traitInfo == null) {
|
||||
MessageHelper.error(player, "Trait '" + traitName + "' does not exist.");
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (action.toLowerCase()) {
|
||||
case "add": {
|
||||
if (hologram.getData().getTraitTrait().isTraitAttached(traitInfo.clazz())) {
|
||||
MessageHelper.error(player, "Trait '" + traitName + "' is already attached to hologram '" + hologram.getData().getName() + "'.");
|
||||
return false;
|
||||
}
|
||||
|
||||
hologram.getData().getTraitTrait().addTrait(traitInfo.clazz());
|
||||
MessageHelper.success(player, "Trait '" + traitName + "' has been added to hologram '" + hologram.getData().getName() + "'.");
|
||||
return true;
|
||||
}
|
||||
case "remove": {
|
||||
if (!hologram.getData().getTraitTrait().isTraitAttached(traitInfo.clazz())) {
|
||||
MessageHelper.error(player, "Trait '" + traitName + "' is not attached to hologram '" + hologram.getData().getName() + "'.");
|
||||
return false;
|
||||
}
|
||||
|
||||
hologram.getData().getTraitTrait().removeTrait(traitInfo.clazz());
|
||||
MessageHelper.success(player, "Trait '" + traitName + "' has been removed from hologram '" + hologram.getData().getName() + "'.");
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
MessageHelper.error(player, "Invalid action. Use 'add' or 'remove'.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.fancyinnovations.fancyholograms.commands.lampCommands.hologram;
|
||||
|
||||
import com.fancyinnovations.fancyholograms.api.hologram.Hologram;
|
||||
import com.fancyinnovations.fancyholograms.api.trait.HologramTrait;
|
||||
import com.fancyinnovations.fancyholograms.api.trait.HologramTraitRegistry;
|
||||
import com.fancyinnovations.fancyholograms.api.trait.HologramTraitTrait;
|
||||
import com.fancyinnovations.fancyholograms.commands.lampCommands.suggestions.AttachedTraitsSuggestion;
|
||||
import com.fancyinnovations.fancyholograms.commands.lampCommands.suggestions.DetachedTraitsSuggestion;
|
||||
import com.fancyinnovations.fancyholograms.main.FancyHologramsPlugin;
|
||||
@@ -70,4 +72,30 @@ public final class TraitCMD {
|
||||
.replace("name", trait.name())
|
||||
.send(actor.sender());
|
||||
}
|
||||
|
||||
@Command("hologram-new edit <hologram> trait list")
|
||||
@Description("Lists all attached traits of a hologram")
|
||||
@CommandPermission("fancyholograms.commands.hologram.trait.list")
|
||||
public void list(
|
||||
final @NotNull BukkitCommandActor actor,
|
||||
final @NotNull Hologram hologram
|
||||
) {
|
||||
HologramTraitTrait traitTrait = hologram.getData().getTraitTrait();
|
||||
if (traitTrait.getTraits().isEmpty()) {
|
||||
translator.translate("commands.hologram.edit.trait.list.no_traits")
|
||||
.replace("hologram", hologram.getData().getName())
|
||||
.send(actor.sender());
|
||||
return;
|
||||
}
|
||||
|
||||
translator.translate("commands.hologram.edit.trait.list.header")
|
||||
.replace("hologram", hologram.getData().getName())
|
||||
.send(actor.sender());
|
||||
|
||||
for (HologramTrait trait : traitTrait.getTraits()) {
|
||||
translator.translate("commands.hologram.edit.trait.list.entry")
|
||||
.replace("name", trait.getName())
|
||||
.send(actor.sender());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,6 +212,17 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
|
||||
if (!configuration.areVersionNotificationsMuted()) {
|
||||
checkForNewerVersion();
|
||||
}
|
||||
if (versionConfig.isDevelopmentBuild()) {
|
||||
fancyLogger.warn("""
|
||||
|
||||
--------------------------------------------------
|
||||
You are using a development build of FancyHolograms.
|
||||
Please be aware that there might be bugs in this version.
|
||||
If you find any bugs, please report them on our discord server (https://discord.gg/ZUgYCEJUEx).
|
||||
Read more about the risks of using a development build here: https://docs.fancyinnovations.com/development-guidelines/versioning/#build
|
||||
--------------------------------------------------
|
||||
""");
|
||||
}
|
||||
|
||||
metrics.register();
|
||||
metrics.registerLegacy();
|
||||
|
||||
@@ -21,3 +21,7 @@ messages:
|
||||
detach:
|
||||
not_attached: "<dark_gray>› <gray>Hologram {warningColor}{hologram}<gray> does not have trait {warningColor}{name}<gray> attached."
|
||||
success: "<dark_gray>› <gray>Successfully detached trait {warningColor}{name}<gray> from hologram {warningColor}{hologram}<gray>."
|
||||
list:
|
||||
no_traits: "<dark_gray>› <gray>Hologram {warningColor}{hologram}<gray> does not have any traits attached."
|
||||
header: "<dark_gray>› <gray>Hologram {warningColor}{hologram}<gray> has the following traits attached:"
|
||||
entry: "<dark_gray>› <gray> - {warningColor}{name}<gray>"
|
||||
|
||||
Reference in New Issue
Block a user