mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-31 12:56:28 +00:00
Merge branch 'Xiao-MoMi:dev' into dev
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package net.momirealms.craftengine.bukkit.api.event;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurniture;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FurnitureAttemptBreakEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private final BukkitFurniture furniture;
|
||||
|
||||
public FurnitureAttemptBreakEvent(@NotNull Player player,
|
||||
@NotNull BukkitFurniture furniture) {
|
||||
super(player);
|
||||
this.furniture = furniture;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Player player() {
|
||||
return getPlayer();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BukkitFurniture furniture() {
|
||||
return this.furniture;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Location location() {
|
||||
return this.furniture.location();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
}
|
||||
@@ -347,7 +347,7 @@ public class BlockEventListener implements Listener {
|
||||
Block block = blocks.get(i);
|
||||
Location location = block.getLocation();
|
||||
BlockPos blockPos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
ImmutableBlockState state = manager.getImmutableBlockState(BlockStateUtils.blockDataToId(block.getBlockData()));
|
||||
ImmutableBlockState state = this.manager.getImmutableBlockState(BlockStateUtils.blockDataToId(block.getBlockData()));
|
||||
if (state != null && !state.isEmpty()) {
|
||||
WorldPosition position = new WorldPosition(world, Vec3d.atCenterOf(blockPos));
|
||||
ContextHolder.Builder builder = ContextHolder.builder()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.core.item.*;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
|
||||
import net.momirealms.craftengine.core.item.modifier.ItemDataModifier;
|
||||
@@ -10,7 +10,6 @@ import net.momirealms.craftengine.core.plugin.context.event.EventTrigger;
|
||||
import net.momirealms.craftengine.core.plugin.context.function.Function;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -19,22 +18,23 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
|
||||
private final Material material;
|
||||
private final Object item;
|
||||
private final Object clientItem;
|
||||
|
||||
public BukkitCustomItem(Holder<Key> id, Material material, Key materialKey, Key clientBoundMaterialKey,
|
||||
public BukkitCustomItem(Holder<Key> id, Object item, Object clientItem, Key materialKey, Key clientBoundMaterialKey,
|
||||
List<ItemBehavior> behaviors,
|
||||
List<ItemDataModifier<ItemStack>> modifiers, List<ItemDataModifier<ItemStack>> clientBoundModifiers,
|
||||
ItemSettings settings,
|
||||
Map<EventTrigger, List<Function<PlayerOptionalContext>>> events) {
|
||||
super(id, materialKey, clientBoundMaterialKey, behaviors, modifiers, clientBoundModifiers, settings, events);
|
||||
this.material = material;
|
||||
this.item = item;
|
||||
this.clientItem = clientItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack buildItemStack(ItemBuildContext context, int count) {
|
||||
ItemStack item = new ItemStack(this.material);
|
||||
ItemStack item = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(FastNMS.INSTANCE.constructor$ItemStack(this.item, count));
|
||||
Item<ItemStack> wrapped = BukkitCraftEngine.instance().itemManager().wrap(item);
|
||||
wrapped.count(count);
|
||||
for (ItemDataModifier<ItemStack> modifier : this.modifiers) {
|
||||
modifier.apply(wrapped, context);
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
|
||||
|
||||
@Override
|
||||
public Item<ItemStack> buildItem(ItemBuildContext context) {
|
||||
ItemStack item = new ItemStack(this.material);
|
||||
ItemStack item = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(FastNMS.INSTANCE.constructor$ItemStack(this.item, 1));
|
||||
Item<ItemStack> wrapped = BukkitCraftEngine.instance().itemManager().wrap(item);
|
||||
for (ItemDataModifier<ItemStack> modifier : dataModifiers()) {
|
||||
modifier.apply(wrapped, context);
|
||||
@@ -51,24 +51,33 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
|
||||
return BukkitCraftEngine.instance().itemManager().wrap(wrapped.load());
|
||||
}
|
||||
|
||||
public static Builder<ItemStack> builder(Material material) {
|
||||
return new BuilderImpl(material);
|
||||
public Object clientItem() {
|
||||
return clientItem;
|
||||
}
|
||||
|
||||
public Object item() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public static Builder<ItemStack> builder(Object item, Object clientBoundItem) {
|
||||
return new BuilderImpl(item, clientBoundItem);
|
||||
}
|
||||
|
||||
public static class BuilderImpl implements Builder<ItemStack> {
|
||||
private Holder<Key> id;
|
||||
private final Key materialKey;
|
||||
private final Material material;
|
||||
private Key clientBoundMaterialKey;
|
||||
private Key itemKey;
|
||||
private final Object item;
|
||||
private Key clientBoundItemKey;
|
||||
private final Object clientBoundItem;
|
||||
private final Map<EventTrigger, List<Function<PlayerOptionalContext>>> events = new EnumMap<>(EventTrigger.class);
|
||||
private final List<ItemBehavior> behaviors = new ArrayList<>(4);
|
||||
private final List<ItemDataModifier<ItemStack>> modifiers = new ArrayList<>(4);
|
||||
private final List<ItemDataModifier<ItemStack>> clientBoundModifiers = new ArrayList<>(4);
|
||||
private ItemSettings settings;
|
||||
|
||||
public BuilderImpl(Material material) {
|
||||
this.material = material;
|
||||
this.materialKey = KeyUtils.namespacedKey2Key(material.getKey());
|
||||
public BuilderImpl(Object item, Object clientBoundItem) {
|
||||
this.item = item;
|
||||
this.clientBoundItem = clientBoundItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,8 +87,14 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<ItemStack> clientBoundMaterial(Key clientBoundMaterialKey) {
|
||||
this.clientBoundMaterialKey = clientBoundMaterialKey;
|
||||
public Builder<ItemStack> clientBoundMaterial(Key clientBoundMaterial) {
|
||||
this.clientBoundItemKey = clientBoundMaterial;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<ItemStack> material(Key material) {
|
||||
this.itemKey = material;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -134,7 +149,7 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
|
||||
@Override
|
||||
public CustomItem<ItemStack> build() {
|
||||
this.modifiers.addAll(this.settings.modifiers());
|
||||
return new BukkitCustomItem(this.id, this.material, this.materialKey, this.clientBoundMaterialKey, List.copyOf(this.behaviors),
|
||||
return new BukkitCustomItem(this.id, this.item, this.clientBoundItem, this.itemKey, this.clientBoundItemKey, List.copyOf(this.behaviors),
|
||||
List.copyOf(this.modifiers), List.copyOf(this.clientBoundModifiers), this.settings, this.events);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBuiltInRegistries;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistries;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
|
||||
import net.momirealms.craftengine.bukkit.util.ItemUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
@@ -201,11 +202,18 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
|
||||
@Override
|
||||
protected CustomItem.Builder<ItemStack> createPlatformItemBuilder(Holder<Key> id, Key materialId, Key clientBoundMaterialId) {
|
||||
Material material = ResourceConfigUtils.requireNonNullOrThrow(Registry.MATERIAL.get(KeyUtils.toNamespacedKey(materialId)), () -> new LocalizedResourceConfigException("warning.config.item.invalid_material", materialId.toString()));
|
||||
if (!clientBoundMaterialId.equals(materialId)) {
|
||||
ResourceConfigUtils.requireNonNullOrThrow(Registry.MATERIAL.get(KeyUtils.toNamespacedKey(clientBoundMaterialId)), () -> new LocalizedResourceConfigException("warning.config.item.invalid_material", clientBoundMaterialId.toString()));
|
||||
Object item = FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(materialId));
|
||||
Object clientBoundItem = materialId == clientBoundMaterialId ? item : FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(clientBoundMaterialId));
|
||||
if (item == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.invalid_material", materialId.toString());
|
||||
}
|
||||
return BukkitCustomItem.builder(material).id(id).clientBoundMaterial(clientBoundMaterialId);
|
||||
if (clientBoundItem == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.invalid_material", clientBoundMaterialId.toString());
|
||||
}
|
||||
return BukkitCustomItem.builder(item, clientBoundItem)
|
||||
.id(id)
|
||||
.material(materialId)
|
||||
.clientBoundMaterial(clientBoundMaterialId);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.CustomItem;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
@@ -25,6 +26,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public class LegacyNetworkItemHandler implements NetworkItemHandler<ItemStack> {
|
||||
|
||||
@Override
|
||||
@@ -32,9 +34,9 @@ public class LegacyNetworkItemHandler implements NetworkItemHandler<ItemStack> {
|
||||
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
|
||||
boolean hasDifferentMaterial = false;
|
||||
if (optionalCustomItem.isPresent()) {
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
if (!customItem.material().equals(wrapped.vanillaId())) {
|
||||
wrapped = wrapped.transmuteCopy(customItem.material());
|
||||
BukkitCustomItem customItem = (BukkitCustomItem) optionalCustomItem.get();
|
||||
if (customItem.item() != FastNMS.INSTANCE.method$ItemStack$getItem(wrapped.getLiteralObject())) {
|
||||
wrapped = wrapped.unsafeTransmuteCopy(customItem.item(), wrapped.count());
|
||||
hasDifferentMaterial = true;
|
||||
}
|
||||
}
|
||||
@@ -61,10 +63,11 @@ public class LegacyNetworkItemHandler implements NetworkItemHandler<ItemStack> {
|
||||
if (!Config.interceptItem()) return Optional.empty();
|
||||
return new OtherItem(wrapped, false).process();
|
||||
} else {
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
boolean hasDifferentMaterial = !wrapped.vanillaId().equals(customItem.clientBoundMaterial());
|
||||
BukkitCustomItem customItem = (BukkitCustomItem) optionalCustomItem.get();
|
||||
Object serverItem = FastNMS.INSTANCE.method$ItemStack$getItem(wrapped.getLiteralObject());
|
||||
boolean hasDifferentMaterial = serverItem == customItem.item() && serverItem != customItem.clientItem();
|
||||
if (hasDifferentMaterial) {
|
||||
wrapped = wrapped.transmuteCopy(customItem.clientBoundMaterial());
|
||||
wrapped = wrapped.unsafeTransmuteCopy(customItem.clientItem(), wrapped.count());
|
||||
}
|
||||
if (!customItem.hasClientBoundDataModifier()) {
|
||||
if (!Config.interceptItem() && !hasDifferentMaterial) return Optional.empty();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.*;
|
||||
import net.momirealms.craftengine.core.item.modifier.ArgumentModifier;
|
||||
@@ -33,9 +34,9 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
|
||||
boolean hasDifferentMaterial = false;
|
||||
if (optionalCustomItem.isPresent()) {
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
if (!customItem.material().equals(wrapped.vanillaId())) {
|
||||
wrapped = wrapped.transmuteCopy(customItem.material());
|
||||
BukkitCustomItem customItem = (BukkitCustomItem) optionalCustomItem.get();
|
||||
if (customItem.item() != FastNMS.INSTANCE.method$ItemStack$getItem(wrapped.getLiteralObject())) {
|
||||
wrapped = wrapped.unsafeTransmuteCopy(customItem.item(), wrapped.count());
|
||||
hasDifferentMaterial = true;
|
||||
}
|
||||
}
|
||||
@@ -64,10 +65,11 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
if (!Config.interceptItem()) return Optional.empty();
|
||||
return new OtherItem(wrapped, false).process();
|
||||
} else {
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
boolean hasDifferentMaterial = !wrapped.vanillaId().equals(customItem.clientBoundMaterial());
|
||||
BukkitCustomItem customItem = (BukkitCustomItem) optionalCustomItem.get();
|
||||
Object serverItem = FastNMS.INSTANCE.method$ItemStack$getItem(wrapped.getLiteralObject());
|
||||
boolean hasDifferentMaterial = serverItem == customItem.item() && serverItem != customItem.clientItem();
|
||||
if (hasDifferentMaterial) {
|
||||
wrapped = wrapped.transmuteCopy(customItem.clientBoundMaterial());
|
||||
wrapped = wrapped.unsafeTransmuteCopy(customItem.clientItem(), wrapped.count());
|
||||
}
|
||||
if (!customItem.hasClientBoundDataModifier()) {
|
||||
if (!Config.interceptItem() && !hasDifferentMaterial) return Optional.empty();
|
||||
|
||||
@@ -526,9 +526,16 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ComponentItemWrapper transmuteCopy(ComponentItemWrapper item1, Key item, int amount) {
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = FastNMS.INSTANCE.method$ItemStack$transmuteCopy(itemStack1, FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(item)), amount);
|
||||
protected ComponentItemWrapper transmuteCopy(ComponentItemWrapper item, Key newItem, int amount) {
|
||||
Object itemStack1 = item.getLiteralObject();
|
||||
Object itemStack2 = FastNMS.INSTANCE.method$ItemStack$transmuteCopy(itemStack1, FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(newItem)), amount);
|
||||
return new ComponentItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(itemStack2));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ComponentItemWrapper unsafeTransmuteCopy(ComponentItemWrapper item, Object newItem, int amount) {
|
||||
Object itemStack1 = item.getLiteralObject();
|
||||
Object itemStack2 = FastNMS.INSTANCE.method$ItemStack$transmuteCopy(itemStack1, newItem, amount);
|
||||
return new ComponentItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(itemStack2));
|
||||
}
|
||||
}
|
||||
@@ -308,7 +308,7 @@ public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
|
||||
@Override
|
||||
protected LegacyItemWrapper mergeCopy(LegacyItemWrapper item1, LegacyItemWrapper item2) {
|
||||
Object itemStack = ItemObject.copy(item2.getLiteralObject());
|
||||
ItemObject.setCustomDataTag(itemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject())));
|
||||
FastNMS.INSTANCE.method$ItemStack$setTag(itemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject())));
|
||||
// one more step than vanilla
|
||||
TagCompound.merge(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(itemStack), FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item2.getLiteralObject()), true, true);
|
||||
return new LegacyItemWrapper(new RtagItem(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(itemStack)));
|
||||
@@ -318,7 +318,7 @@ public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
|
||||
protected void merge(LegacyItemWrapper item1, LegacyItemWrapper item2) {
|
||||
// load previous changes on nms items
|
||||
item1.load();
|
||||
TagCompound.merge(ItemObject.getCustomDataTag(item1.getLiteralObject()), ItemObject.getCustomDataTag(item2.getLiteralObject()), true, true);
|
||||
TagCompound.merge(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject()), FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item2.getLiteralObject()), true, true);
|
||||
// update wrapped item
|
||||
item1.update();
|
||||
}
|
||||
@@ -326,7 +326,14 @@ public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
|
||||
@Override
|
||||
protected LegacyItemWrapper transmuteCopy(LegacyItemWrapper item, Key newItem, int amount) {
|
||||
Object newItemStack = FastNMS.INSTANCE.constructor$ItemStack(FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(newItem)), amount);
|
||||
ItemObject.setCustomDataTag(newItemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject())));
|
||||
FastNMS.INSTANCE.method$ItemStack$setTag(newItemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject())));
|
||||
return new LegacyItemWrapper(new RtagItem(ItemObject.asCraftMirror(newItemStack)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LegacyItemWrapper unsafeTransmuteCopy(LegacyItemWrapper item, Object newItem, int amount) {
|
||||
Object newItemStack = FastNMS.INSTANCE.constructor$ItemStack(newItem, amount);
|
||||
FastNMS.INSTANCE.method$ItemStack$setTag(newItemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject())));
|
||||
return new LegacyItemWrapper(new RtagItem(ItemObject.asCraftMirror(newItemStack)));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.item.listener;
|
||||
|
||||
import io.papermc.paper.event.block.CompostItemEvent;
|
||||
import net.momirealms.craftengine.bukkit.api.event.CustomBlockInteractEvent;
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
@@ -26,6 +27,7 @@ import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -35,13 +37,18 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.enchantment.EnchantItemEvent;
|
||||
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -404,7 +411,7 @@ public class ItemEventListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event.getEntityType() == EntityType.ITEM && event.getEntity() instanceof org.bukkit.entity.Item item) {
|
||||
if (event.getEntity() instanceof org.bukkit.entity.Item item) {
|
||||
Optional.ofNullable(this.plugin.itemManager().wrap(item.getItemStack()))
|
||||
.flatMap(Item::getCustomItem)
|
||||
.ifPresent(it -> {
|
||||
@@ -414,4 +421,34 @@ public class ItemEventListener implements Listener {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onEnchant(PrepareItemEnchantEvent event) {
|
||||
ItemStack itemToEnchant = event.getItem();
|
||||
Item<ItemStack> wrapped = this.plugin.itemManager().wrap(itemToEnchant);
|
||||
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
|
||||
if (optionalCustomItem.isEmpty()) return;
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
if (!customItem.settings().canEnchant()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onCompost(CompostItemEvent event) {
|
||||
ItemStack itemToCompost = event.getItem();
|
||||
Item<ItemStack> wrapped = this.plugin.itemManager().wrap(itemToCompost);
|
||||
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
|
||||
if (optionalCustomItem.isEmpty()) return;
|
||||
event.setWillRaiseLevel(RandomUtils.generateRandomFloat(0, 1) < optionalCustomItem.get().settings().compostProbability());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDragItem(InventoryClickEvent event) {
|
||||
// Player player = (Player) event.getWhoClicked();
|
||||
// plugin.scheduler().sync().runLater(() -> {
|
||||
// System.out.println(1);
|
||||
// player.updateInventory();
|
||||
// }, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.gui;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.NetworkReflections;
|
||||
@@ -69,7 +70,7 @@ public class BukkitGuiManager implements GuiManager, Listener {
|
||||
public void updateInventoryTitle(net.momirealms.craftengine.core.entity.player.Player player, Component component) {
|
||||
Object nmsPlayer = player.serverPlayer();
|
||||
try {
|
||||
Object containerMenu = CoreReflections.field$Player$containerMenu.get(nmsPlayer);
|
||||
Object containerMenu = FastNMS.INSTANCE.field$Player$containerMenu(nmsPlayer);
|
||||
int containerId = CoreReflections.field$AbstractContainerMenu$containerId.getInt(containerMenu);
|
||||
Object menuType = CoreReflections.field$AbstractContainerMenu$menuType.get(containerMenu);
|
||||
Object packet = NetworkReflections.constructor$ClientboundOpenScreenPacket.newInstance(containerId, menuType, ComponentUtils.adventureToMinecraft(component));
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.kyori.adventure.text.TranslationArgument;
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineFurniture;
|
||||
import net.momirealms.craftengine.bukkit.api.event.FurnitureBreakEvent;
|
||||
import net.momirealms.craftengine.bukkit.api.event.FurnitureInteractEvent;
|
||||
import net.momirealms.craftengine.bukkit.api.event.FurnitureAttemptBreakEvent;
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurniture;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurnitureManager;
|
||||
@@ -1539,9 +1540,14 @@ public class PacketConsumers {
|
||||
mainThreadTask = () -> {
|
||||
// todo 冒险模式破坏工具白名单
|
||||
if (serverPlayer.isAdventureMode() ||
|
||||
!furniture.isValid() ||
|
||||
!BukkitCraftEngine.instance().antiGrief().canBreak(platformPlayer, location)
|
||||
) return;
|
||||
!furniture.isValid()) return;
|
||||
|
||||
FurnitureAttemptBreakEvent preBreakEvent = new FurnitureAttemptBreakEvent(serverPlayer.platformPlayer(), furniture);
|
||||
if (EventUtils.fireAndCheckCancel(preBreakEvent))
|
||||
return;
|
||||
|
||||
if (!BukkitCraftEngine.instance().antiGrief().canBreak(platformPlayer, location))
|
||||
return;
|
||||
|
||||
FurnitureBreakEvent breakEvent = new FurnitureBreakEvent(serverPlayer.platformPlayer(), furniture);
|
||||
if (EventUtils.fireAndCheckCancel(breakEvent))
|
||||
@@ -2102,6 +2108,23 @@ public class PacketConsumers {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
Object friendlyBuf = FastNMS.INSTANCE.constructor$FriendlyByteBuf(buf);
|
||||
ItemStack itemStack = FastNMS.INSTANCE.method$FriendlyByteBuf$readItem(friendlyBuf);
|
||||
if (VersionHelper.isOrAbove1_21_5()) {
|
||||
Item<ItemStack> wrapped = BukkitItemManager.instance().wrap(itemStack);
|
||||
if (wrapped != null && wrapped.isCustomItem()) {
|
||||
Object containerMenu = FastNMS.INSTANCE.field$Player$containerMenu(serverPlayer.serverPlayer());
|
||||
if (containerMenu != null) {
|
||||
ItemStack carried = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(FastNMS.INSTANCE.method$AbstractContainerMenu$getCarried(containerMenu));
|
||||
if (ItemUtils.isEmpty(carried)) {
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
Object newFriendlyBuf = FastNMS.INSTANCE.constructor$FriendlyByteBuf(buf);
|
||||
FastNMS.INSTANCE.method$FriendlyByteBuf$writeItem(newFriendlyBuf, carried);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BukkitItemManager.instance().s2c(itemStack, serverPlayer).ifPresent((newItemStack) -> {
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
# This file contains some useful template data. If you have good ideas, you are welcome to contribute your template!
|
||||
|
||||
# These templates let you ditch the real custom_model_data on the server side.
|
||||
# Instead, we use client side components sent via packets to control how items look.
|
||||
templates#client_bound_model:
|
||||
default:item/client_bound_custom_model_data:
|
||||
custom-model-data: "${custom_model_data}"
|
||||
data:
|
||||
remove-components:
|
||||
- minecraft:custom_model_data
|
||||
client-bound-data:
|
||||
custom-model-data: "${custom_model_data}"
|
||||
default:item/client_bound_item_model:
|
||||
item-model: "${item_model}"
|
||||
data:
|
||||
remove-components:
|
||||
- minecraft:item_model
|
||||
client-bound-data:
|
||||
item-model: "${item_model}"
|
||||
|
||||
# blocks
|
||||
templates#models#block:
|
||||
# template: default:model/cube_all
|
||||
|
||||
@@ -429,6 +429,11 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
|
||||
return new AbstractItem<>(this.factory, this.factory.transmuteCopy(this.item, another, count));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item<I> unsafeTransmuteCopy(Object another, int count) {
|
||||
return new AbstractItem<>(this.factory, this.factory.unsafeTransmuteCopy(this.item, another, count));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public void merge(Item<I> another) {
|
||||
|
||||
@@ -478,6 +478,10 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
boolean value = TypeUtils.checkType(obj, Boolean.class);
|
||||
return new UnbreakableModifier<>(value);
|
||||
}, "unbreakable");
|
||||
registerDataType((obj) -> {
|
||||
int customModelData = ResourceConfigUtils.getAsInt(obj, "custom-model-data");
|
||||
return new CustomModelDataModifier<>(customModelData);
|
||||
}, "custom-model-data");
|
||||
registerDataType((obj) -> {
|
||||
Map<String, Object> data = MiscUtils.castToMap(obj, false);
|
||||
List<Enchantment> enchantments = new ArrayList<>();
|
||||
@@ -494,6 +498,14 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
String pattern = data.get("pattern").toString().toLowerCase(Locale.ENGLISH);
|
||||
return new TrimModifier<>(material, pattern);
|
||||
}, "trim");
|
||||
registerDataType((obj) -> {
|
||||
Map<String, Object> data = MiscUtils.castToMap(obj, false);
|
||||
Map<String, TextProvider> arguments = new HashMap<>();
|
||||
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||
arguments.put(entry.getKey(), TextProviders.fromString(entry.getValue().toString()));
|
||||
}
|
||||
return new ArgumentModifier<>(arguments);
|
||||
}, "args", "argument", "arguments");
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
registerDataType((obj) -> {
|
||||
Map<String, Object> data = MiscUtils.castToMap(obj, false);
|
||||
@@ -521,21 +533,15 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
String id = obj.toString();
|
||||
return new TooltipStyleModifier<>(Key.of(id));
|
||||
}, "tooltip-style");
|
||||
}
|
||||
if (VersionHelper.isOrAbove1_21_2()) {
|
||||
registerDataType((obj) -> {
|
||||
Map<String, Object> data = MiscUtils.castToMap(obj, false);
|
||||
return new EquippableModifier<>(EquipmentData.fromMap(data));
|
||||
}, "equippable");
|
||||
registerDataType((obj) -> {
|
||||
String id = obj.toString();
|
||||
return new ItemModelModifier<>(Key.of(id));
|
||||
}, "item-model");
|
||||
}
|
||||
registerDataType((obj) -> {
|
||||
Map<String, Object> data = MiscUtils.castToMap(obj, false);
|
||||
Map<String, TextProvider> arguments = new HashMap<>();
|
||||
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||
arguments.put(entry.getKey(), TextProviders.fromString(entry.getValue().toString()));
|
||||
}
|
||||
return new ArgumentModifier<>(arguments);
|
||||
}, "args", "argument", "arguments");
|
||||
}
|
||||
|
||||
protected void processModelRecursively(
|
||||
|
||||
@@ -56,6 +56,8 @@ public interface CustomItem<I> extends BuildableItem<I> {
|
||||
|
||||
Builder<I> clientBoundMaterial(Key clientBoundMaterialKey);
|
||||
|
||||
Builder<I> material(Key material);
|
||||
|
||||
Builder<I> dataModifier(ItemDataModifier<I> modifier);
|
||||
|
||||
Builder<I> dataModifiers(List<ItemDataModifier<I>> modifiers);
|
||||
|
||||
@@ -181,6 +181,8 @@ public interface Item<I> {
|
||||
|
||||
Item<I> transmuteCopy(Key another, int count);
|
||||
|
||||
Item<I> unsafeTransmuteCopy(Object another, int count);
|
||||
|
||||
void shrink(int amount);
|
||||
|
||||
default Item<I> transmuteCopy(Key another) {
|
||||
|
||||
@@ -196,4 +196,6 @@ public abstract class ItemFactory<W extends ItemWrapper<I>, I> {
|
||||
protected abstract void setNBTComponent(W item, Object type, Tag value);
|
||||
|
||||
protected abstract W transmuteCopy(W item, Key newItem, int amount);
|
||||
|
||||
protected abstract W unsafeTransmuteCopy(W item, Object newItem, int count);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ public class ItemSettings {
|
||||
Key consumeReplacement = null;
|
||||
Key craftRemainder = null;
|
||||
List<DamageSource> invulnerable = List.of();
|
||||
boolean canEnchant = true;
|
||||
float compostProbability= 0.5f;
|
||||
|
||||
private ItemSettings() {}
|
||||
|
||||
@@ -75,6 +77,8 @@ public class ItemSettings {
|
||||
newSettings.consumeReplacement = settings.consumeReplacement;
|
||||
newSettings.craftRemainder = settings.craftRemainder;
|
||||
newSettings.invulnerable = settings.invulnerable;
|
||||
newSettings.canEnchant = settings.canEnchant;
|
||||
newSettings.compostProbability = settings.compostProbability;
|
||||
return newSettings;
|
||||
}
|
||||
|
||||
@@ -118,6 +122,10 @@ public class ItemSettings {
|
||||
return dyeable;
|
||||
}
|
||||
|
||||
public boolean canEnchant() {
|
||||
return canEnchant;
|
||||
}
|
||||
|
||||
public List<AnvilRepairItem> repairItems() {
|
||||
return anvilRepairItems;
|
||||
}
|
||||
@@ -151,6 +159,10 @@ public class ItemSettings {
|
||||
return invulnerable;
|
||||
}
|
||||
|
||||
public float compostProbability() {
|
||||
return compostProbability;
|
||||
}
|
||||
|
||||
public ItemSettings repairItems(List<AnvilRepairItem> items) {
|
||||
this.anvilRepairItems = items;
|
||||
return this;
|
||||
@@ -166,11 +178,21 @@ public class ItemSettings {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemSettings compostProbability(float chance) {
|
||||
this.compostProbability = chance;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemSettings canRepair(boolean canRepair) {
|
||||
this.canRepair = canRepair;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemSettings canEnchant(boolean canEnchant) {
|
||||
this.canEnchant = canEnchant;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemSettings renameable(boolean renameable) {
|
||||
this.renameable = renameable;
|
||||
return this;
|
||||
@@ -241,6 +263,10 @@ public class ItemSettings {
|
||||
boolean bool = (boolean) value;
|
||||
return settings -> settings.canRepair(bool);
|
||||
}));
|
||||
registerFactory("enchantable", (value -> {
|
||||
boolean bool = (boolean) value;
|
||||
return settings -> settings.canEnchant(bool);
|
||||
}));
|
||||
registerFactory("renameable", (value -> {
|
||||
boolean bool = (boolean) value;
|
||||
return settings -> settings.renameable(bool);
|
||||
@@ -308,6 +334,10 @@ public class ItemSettings {
|
||||
Map<String, Object> args = MiscUtils.castToMap(value, false);
|
||||
return settings -> settings.helmet(new Helmet(SoundData.create(args.getOrDefault("equip-sound", "minecraft:intentionally_empty"), 1f, 1f)));
|
||||
}));
|
||||
registerFactory("compost-probability", (value -> {
|
||||
float chance = ResourceConfigUtils.getAsFloat(value, "compost-probability");
|
||||
return settings -> settings.compostProbability(chance);
|
||||
}));
|
||||
registerFactory("dyeable", (value -> {
|
||||
boolean bool = (boolean) value;
|
||||
return settings -> settings.dyeable(bool);
|
||||
|
||||
@@ -116,6 +116,10 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
|
||||
loadInternalList("models", "block/", VANILLA_MODELS::add);
|
||||
loadInternalList("models", "item/", VANILLA_MODELS::add);
|
||||
VANILLA_MODELS.add(Key.of("minecraft", "builtin/entity"));
|
||||
for (int i = 0; i < 256; i++) {
|
||||
VANILLA_TEXTURES.add(Key.of("minecraft", "font/unicode_page_" + String.format("%02x", i)));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadInternalData(String path, BiConsumer<Key, JsonObject> callback) {
|
||||
@@ -461,7 +465,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
Path configurationFolderPath = pack.configurationFolder();
|
||||
if (!Files.isDirectory(configurationFolderPath)) continue;
|
||||
try {
|
||||
Files.walkFileTree(configurationFolderPath, new SimpleFileVisitor<>() {
|
||||
Files.walkFileTree(configurationFolderPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public @NotNull FileVisitResult visitFile(@NotNull Path path, @NotNull BasicFileAttributes attrs) {
|
||||
if (Files.isRegularFile(path) && path.getFileName().toString().endsWith(".yml")) {
|
||||
@@ -628,7 +632,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
for (Path namespacePath : FileUtils.collectNamespaces(assetsPath)) {
|
||||
Path fontPath = namespacePath.resolve("font");
|
||||
if (Files.isDirectory(fontPath)) {
|
||||
Files.walkFileTree(fontPath, new SimpleFileVisitor<>() {
|
||||
Files.walkFileTree(fontPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public @NotNull FileVisitResult visitFile(@NotNull Path file, @NotNull BasicFileAttributes attrs) throws IOException {
|
||||
if (!isJsonFile(file)) return FileVisitResult.CONTINUE;
|
||||
@@ -654,7 +658,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
|
||||
Path itemsPath = namespacePath.resolve("items");
|
||||
if (Files.isDirectory(itemsPath)) {
|
||||
Files.walkFileTree(itemsPath, new SimpleFileVisitor<>() {
|
||||
Files.walkFileTree(itemsPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public @NotNull FileVisitResult visitFile(@NotNull Path file, @NotNull BasicFileAttributes attrs) throws IOException {
|
||||
if (!isJsonFile(file)) return FileVisitResult.CONTINUE;
|
||||
@@ -668,7 +672,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
|
||||
Path blockStatesPath = namespacePath.resolve("blockstates");
|
||||
if (Files.isDirectory(blockStatesPath)) {
|
||||
Files.walkFileTree(blockStatesPath, new SimpleFileVisitor<>() {
|
||||
Files.walkFileTree(blockStatesPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public @NotNull FileVisitResult visitFile(@NotNull Path file, @NotNull BasicFileAttributes attrs) throws IOException {
|
||||
if (!isJsonFile(file)) return FileVisitResult.CONTINUE;
|
||||
@@ -1447,7 +1451,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
.toList());
|
||||
for (Path sourceFolder : folders) {
|
||||
if (Files.exists(sourceFolder)) {
|
||||
Files.walkFileTree(sourceFolder, new SimpleFileVisitor<>() {
|
||||
Files.walkFileTree(sourceFolder, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public @NotNull FileVisitResult visitFile(@NotNull Path file, @NotNull BasicFileAttributes attrs) throws IOException {
|
||||
processRegularFile(file, attrs, sourceFolder, fs, conflictChecker, previousFiles);
|
||||
@@ -1500,7 +1504,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
long zipLastModified = Files.getLastModifiedTime(zipFile).toMillis();
|
||||
long zipSize = Files.size(zipFile);
|
||||
Path zipRoot = zipFs.getPath("/");
|
||||
Files.walkFileTree(zipRoot, new SimpleFileVisitor<>() {
|
||||
Files.walkFileTree(zipRoot, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public @NotNull FileVisitResult visitFile(@NotNull Path entry, @NotNull BasicFileAttributes entryAttrs) throws IOException {
|
||||
if (entryAttrs.isDirectory()) {
|
||||
|
||||
@@ -23,10 +23,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -163,7 +160,7 @@ public class TranslationManagerImpl implements TranslationManager {
|
||||
Map<String, CachedTranslation> previousTranslations = this.cachedTranslations;
|
||||
this.cachedTranslations = new HashMap<>();
|
||||
try {
|
||||
Files.walkFileTree(directory, new SimpleFileVisitor<>() {
|
||||
Files.walkFileTree(directory, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public @NotNull FileVisitResult visitFile(@NotNull Path path, @NotNull BasicFileAttributes attrs) {
|
||||
String fileName = path.getFileName().toString();
|
||||
|
||||
@@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.momirealms.craftengine.core.pack.ResourceLocation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileVisitOption;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Comparator;
|
||||
@@ -35,7 +36,7 @@ public class FileUtils {
|
||||
|
||||
public static void deleteDirectory(Path folder) throws IOException {
|
||||
if (!Files.exists(folder)) return;
|
||||
try (Stream<Path> walk = Files.walk(folder)) {
|
||||
try (Stream<Path> walk = Files.walk(folder, FileVisitOption.FOLLOW_LINKS)) {
|
||||
walk.sorted(Comparator.reverseOrder())
|
||||
.forEach(path -> {
|
||||
try {
|
||||
@@ -51,7 +52,7 @@ public class FileUtils {
|
||||
if (!Files.exists(configFolder)) {
|
||||
return List.of();
|
||||
}
|
||||
try (Stream<Path> stream = Files.walk(configFolder)) {
|
||||
try (Stream<Path> stream = Files.walk(configFolder, FileVisitOption.FOLLOW_LINKS)) {
|
||||
return stream.parallel()
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(path -> path.toString().endsWith(".yml"))
|
||||
|
||||
@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=0.0.56.7
|
||||
project_version=0.0.57.3
|
||||
config_version=37
|
||||
lang_version=16
|
||||
project_group=net.momirealms
|
||||
@@ -41,7 +41,7 @@ commons_io_version=2.18.0
|
||||
commons_imaging_version=1.0.0-alpha6
|
||||
commons_lang3_version=3.17.0
|
||||
sparrow_nbt_version=0.9.1
|
||||
sparrow_util_version=0.49.1
|
||||
sparrow_util_version=0.49.2
|
||||
fastutil_version=8.5.15
|
||||
netty_version=4.1.121.Final
|
||||
joml_version=1.10.8
|
||||
@@ -51,7 +51,7 @@ byte_buddy_version=1.17.5
|
||||
ahocorasick_version=0.6.3
|
||||
snake_yaml_version=2.4
|
||||
anti_grief_version=0.17
|
||||
nms_helper_version=0.67.10
|
||||
nms_helper_version=0.67.12
|
||||
evalex_version=3.5.0
|
||||
reactive_streams_version=1.0.4
|
||||
amazon_awssdk_version=2.31.23
|
||||
|
||||
Reference in New Issue
Block a user