mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-24 17:39:30 +00:00
改进不死图腾
This commit is contained in:
@@ -8,6 +8,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -26,6 +26,7 @@ public class ComponentTypes {
|
||||
public static final Object CUSTOM_DATA = getComponentType(ComponentKeys.CUSTOM_DATA);
|
||||
public static final Object PROFILE = getComponentType(ComponentKeys.PROFILE);
|
||||
public static final Object DYED_COLOR = getComponentType(ComponentKeys.DYED_COLOR);
|
||||
public static final Object DEATH_PROTECTION = getComponentType(ComponentKeys.DEATH_PROTECTION);
|
||||
|
||||
private ComponentTypes() {}
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.command.feature;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
|
||||
import net.momirealms.craftengine.bukkit.util.MaterialUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.PlayerUtils;
|
||||
import net.momirealms.craftengine.core.item.CustomItem;
|
||||
import net.momirealms.craftengine.core.item.*;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
|
||||
import net.momirealms.craftengine.core.plugin.command.FlagKeys;
|
||||
import net.momirealms.craftengine.core.plugin.locale.MessageConstants;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -23,9 +25,13 @@ import org.incendo.cloud.bukkit.parser.NamespacedKeyParser;
|
||||
import org.incendo.cloud.bukkit.parser.selector.MultiplePlayerSelectorParser;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.StringParser;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class TotemAnimationCommand extends BukkitCommandFeature<CommandSender> {
|
||||
@@ -45,18 +51,38 @@ public class TotemAnimationCommand extends BukkitCommandFeature<CommandSender> {
|
||||
return CompletableFuture.completedFuture(plugin().itemManager().cachedTotemSuggestions());
|
||||
}
|
||||
}))
|
||||
.flag(CommandFlag.builder("sound_event").withComponent(NamespacedKeyParser.namespacedKeyParser()).build())
|
||||
.flag(CommandFlag.builder("sound_location").withComponent(NamespacedKeyParser.namespacedKeyParser()).build())
|
||||
.handler(context -> {
|
||||
NamespacedKey namespacedKey = context.get("id");
|
||||
Key key = Key.of(namespacedKey.namespace(), namespacedKey.value());
|
||||
CustomItem<ItemStack> item = plugin().itemManager().getCustomItem(key).orElse(null);
|
||||
if (item == null || MaterialUtils.getMaterial(item.material()) != Material.TOTEM_OF_UNDYING) {
|
||||
CustomItem<ItemStack> customItem = plugin().itemManager().getCustomItem(key).orElse(null);
|
||||
if (customItem == null || (!VersionHelper.isOrAbove1_21_2() && customItem.material().equals(ItemKeys.TOTEM_OF_UNDYING))) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_TOTEM_NOT_TOTEM, Component.text(key.toString()));
|
||||
return;
|
||||
}
|
||||
ItemStack totem = item.buildItemStack();
|
||||
Item<ItemStack> item = customItem.buildItem(ItemBuildContext.EMPTY);
|
||||
if (VersionHelper.isOrAbove1_21_2()) {
|
||||
if (context.flags().contains("sound_location")) {
|
||||
String soundResourceLocation = context.flags().getValue("sound_location").get().toString();
|
||||
if (soundResourceLocation != null) {
|
||||
item.setComponent(ComponentTypes.DEATH_PROTECTION, Map.of("death_effects", List.of(Map.of("type", "play_sound", "sound", Map.of(
|
||||
"sound_id", soundResourceLocation
|
||||
)))));
|
||||
}
|
||||
} else if (context.flags().contains("sound_event")) {
|
||||
String soundEvent = context.flags().getValue("sound_event").get().toString();
|
||||
if (soundEvent != null) {
|
||||
item.setComponent(ComponentTypes.DEATH_PROTECTION, Map.of("death_effects", List.of(Map.of("type", "play_sound", "sound", soundEvent))));
|
||||
}
|
||||
} else {
|
||||
item.setComponent(ComponentTypes.DEATH_PROTECTION, Map.of());
|
||||
}
|
||||
}
|
||||
ItemStack totemItem = item.load();
|
||||
MultiplePlayerSelector selector = context.get("players");
|
||||
for (Player player : selector.values()) {
|
||||
PlayerUtils.sendTotemAnimation(player, totem);
|
||||
PlayerUtils.sendTotemAnimation(player, totemItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,4 +23,5 @@ public class ComponentKeys {
|
||||
public static final Key CUSTOM_DATA = Key.of("minecraft", "custom_data");
|
||||
public static final Key PROFILE = Key.of("minecraft", "profile");
|
||||
public static final Key DYED_COLOR = Key.of("minecraft", "dyed_color");
|
||||
public static final Key DEATH_PROTECTION = Key.of("minecraft", "death_protection");
|
||||
}
|
||||
|
||||
@@ -5,11 +5,9 @@ import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigExce
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import software.amazon.awssdk.services.s3.endpoints.internal.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class LegacyItemModel {
|
||||
private final List<ModelGeneration> modelsToGenerate;
|
||||
|
||||
@@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user