diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 8932054ed..2dd525bf1 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -4,6 +4,17 @@ + + + diff --git a/api/src/main/java/org/allaymc/api/utils/Identifier.java b/api/src/main/java/org/allaymc/api/utils/Identifier.java index 431e2d5a6..90259f453 100644 --- a/api/src/main/java/org/allaymc/api/utils/Identifier.java +++ b/api/src/main/java/org/allaymc/api/utils/Identifier.java @@ -1,5 +1,10 @@ package org.allaymc.api.utils; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + import static org.allaymc.api.utils.AllayStringUtils.fastTwoPartSplit; import static org.allaymc.api.utils.IdentifierUtils.isNamespaceValid; import static org.allaymc.api.utils.IdentifierUtils.isPathValid; @@ -22,10 +27,12 @@ public Identifier(String id) { public Identifier(String namespace, String path) { this.namespace = namespace.isEmpty() ? DEFAULT_NAMESPACE : namespace; this.path = path; - if (!isNamespaceValid(this.namespace)) + if (!isNamespaceValid(this.namespace)) { throw new InvalidIdentifierException("Non [A-Za-z0-9_.-] character in namespace of location: " + this.namespace + NAMESPACE_SEPARATOR + this.path); - if (!isPathValid(this.path)) + } + if (!isPathValid(this.path)) { throw new InvalidIdentifierException("Non [A-Za-z0-9/._-] character in path of location: " + this.namespace + NAMESPACE_SEPARATOR + this.path); + } } public String toString() { @@ -36,8 +43,8 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (o instanceof Identifier lv) { - return this.namespace.equals(lv.namespace) && this.path.equals(lv.path); + if (o instanceof Identifier(String namespace1, String path1)) { + return this.namespace.equals(namespace1) && this.path.equals(path1); } return false; } @@ -46,8 +53,13 @@ public int hashCode() { return 31 * this.namespace.hashCode() + this.path.hashCode(); } + @SuppressWarnings("MethodDoesntCallSuperMethod") @Override public Identifier clone() { return new Identifier(namespace, path); } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + public @interface Component {} } diff --git a/server/src/main/java/org/allaymc/server/block/component/BlockBaseComponentImpl.java b/server/src/main/java/org/allaymc/server/block/component/BlockBaseComponentImpl.java index a1d5588c3..a25d504f7 100644 --- a/server/src/main/java/org/allaymc/server/block/component/BlockBaseComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/block/component/BlockBaseComponentImpl.java @@ -14,11 +14,11 @@ import org.allaymc.api.entity.interfaces.EntityPlayer; import org.allaymc.api.item.ItemStack; import org.allaymc.api.item.enchantment.type.EnchantmentTypes; +import org.allaymc.api.utils.Identifier; import org.allaymc.api.utils.Utils; import org.allaymc.api.world.Dimension; import org.allaymc.server.block.component.event.*; import org.allaymc.server.block.type.BlockLootTable; -import org.allaymc.server.component.annotation.Identifier; import org.allaymc.server.component.annotation.Manager; import org.allaymc.server.loottable.context.BreakBlockContext; import org.cloudburstmc.protocol.bedrock.data.GameType; @@ -32,8 +32,8 @@ */ public class BlockBaseComponentImpl implements BlockBaseComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:block_base_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:block_base_component"); @Manager protected ComponentManager manager; diff --git a/server/src/main/java/org/allaymc/server/block/component/BlockEntityHolderComponentImpl.java b/server/src/main/java/org/allaymc/server/block/component/BlockEntityHolderComponentImpl.java index ae7899247..51cc9f3a5 100644 --- a/server/src/main/java/org/allaymc/server/block/component/BlockEntityHolderComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/block/component/BlockEntityHolderComponentImpl.java @@ -8,12 +8,12 @@ import org.allaymc.api.blockentity.type.BlockEntityType; import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.math.position.Position3i; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.block.component.event.CBlockOnInteractEvent; import org.allaymc.server.block.component.event.CBlockOnNeighborUpdateEvent; import org.allaymc.server.block.component.event.CBlockOnPlaceEvent; import org.allaymc.server.block.component.event.CBlockOnReplaceEvent; import org.allaymc.server.blockentity.component.BlockEntityBaseComponentImpl; -import org.allaymc.server.component.annotation.Identifier; /** * @author daoge_cmd @@ -21,8 +21,8 @@ @Slf4j @RequiredArgsConstructor public class BlockEntityHolderComponentImpl implements BlockEntityHolderComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:block_entity_holder_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:block_entity_holder_component"); @Getter protected final BlockEntityType blockEntityType; diff --git a/server/src/main/java/org/allaymc/server/block/component/BlockStateDataComponentImpl.java b/server/src/main/java/org/allaymc/server/block/component/BlockStateDataComponentImpl.java index c03dc3419..5f1db15a7 100644 --- a/server/src/main/java/org/allaymc/server/block/component/BlockStateDataComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/block/component/BlockStateDataComponentImpl.java @@ -7,7 +7,7 @@ import org.allaymc.api.block.type.BlockType; import org.allaymc.api.math.voxelshape.VoxelShape; import org.allaymc.api.registry.Registries; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.datastruct.collections.nb.Int2ObjectNonBlockingMap; import org.apache.commons.lang3.function.TriFunction; @@ -22,8 +22,8 @@ */ public class BlockStateDataComponentImpl implements BlockStateDataComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:block_state_data_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:block_state_data_component"); protected static final BlockStateDataComponentImpl DEFAULT = BlockStateDataComponentImpl.ofGlobalStatic(BlockStateData.DEFAULT); diff --git a/server/src/main/java/org/allaymc/server/blockentity/component/BlockEntityBaseComponentImpl.java b/server/src/main/java/org/allaymc/server/blockentity/component/BlockEntityBaseComponentImpl.java index 9216deb0a..111c638ec 100644 --- a/server/src/main/java/org/allaymc/server/blockentity/component/BlockEntityBaseComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/blockentity/component/BlockEntityBaseComponentImpl.java @@ -8,13 +8,13 @@ import org.allaymc.api.component.interfaces.ComponentManager; import org.allaymc.api.math.position.Position3i; import org.allaymc.api.math.position.Position3ic; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.block.component.event.CBlockOnInteractEvent; import org.allaymc.server.block.component.event.CBlockOnNeighborUpdateEvent; import org.allaymc.server.block.component.event.CBlockOnPlaceEvent; import org.allaymc.server.block.component.event.CBlockOnReplaceEvent; import org.allaymc.server.blockentity.component.event.CBlockEntityLoadNBTEvent; import org.allaymc.server.blockentity.component.event.CBlockEntitySaveNBTEvent; -import org.allaymc.server.component.annotation.Identifier; import org.allaymc.server.component.annotation.Manager; import org.allaymc.server.component.annotation.OnInitFinish; import org.cloudburstmc.nbt.NbtMap; @@ -23,8 +23,8 @@ * @author daoge_cmd */ public class BlockEntityBaseComponentImpl implements BlockEntityBaseComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:block_entity_base_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:block_entity_base_component"); @Manager protected ComponentManager manager; diff --git a/server/src/main/java/org/allaymc/server/blockentity/component/BlockEntityContainerHolderComponentImpl.java b/server/src/main/java/org/allaymc/server/blockentity/component/BlockEntityContainerHolderComponentImpl.java index 239619b52..2e6861a4d 100644 --- a/server/src/main/java/org/allaymc/server/blockentity/component/BlockEntityContainerHolderComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/blockentity/component/BlockEntityContainerHolderComponentImpl.java @@ -9,12 +9,12 @@ import org.allaymc.api.container.impl.BlockContainer; import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.item.interfaces.ItemAirStack; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.block.component.event.CBlockOnInteractEvent; import org.allaymc.server.block.component.event.CBlockOnReplaceEvent; import org.allaymc.server.blockentity.component.event.CBlockEntityLoadNBTEvent; import org.allaymc.server.blockentity.component.event.CBlockEntitySaveNBTEvent; import org.allaymc.server.component.annotation.Dependency; -import org.allaymc.server.component.annotation.Identifier; import org.cloudburstmc.nbt.NbtType; import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType; import org.joml.Vector3f; @@ -27,8 +27,8 @@ * @author daoge_cmd */ public class BlockEntityContainerHolderComponentImpl implements BlockEntityContainerHolderComponent { - @Identifier - protected static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:block_entity_inventory_holder_component"); + @Identifier.Component + protected static final Identifier IDENTIFIER = new Identifier("minecraft:block_entity_inventory_holder_component"); @Dependency protected BlockEntityBaseComponent baseComponent; @@ -101,8 +101,8 @@ protected void onReplace(CBlockOnReplaceEvent event) { dimension.dropItem(itemStack, new Vector3f( pos.x() + rand.nextFloat(0.5f) + 0.25f, pos.y() + rand.nextFloat(0.5f) + 0.25f, - pos.z() + rand.nextFloat(0.5f) + 0.25f) - ); + pos.z() + rand.nextFloat(0.5f) + 0.25f + )); } container.clearAllSlots(); diff --git a/server/src/main/java/org/allaymc/server/component/annotation/Identifier.java b/server/src/main/java/org/allaymc/server/component/annotation/Identifier.java deleted file mode 100644 index c57112955..000000000 --- a/server/src/main/java/org/allaymc/server/component/annotation/Identifier.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.allaymc.server.component.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @author daoge_cmd - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface Identifier { -} diff --git a/server/src/main/java/org/allaymc/server/component/interfaces/ComponentProvider.java b/server/src/main/java/org/allaymc/server/component/interfaces/ComponentProvider.java index 6f14f68c6..af945246e 100644 --- a/server/src/main/java/org/allaymc/server/component/interfaces/ComponentProvider.java +++ b/server/src/main/java/org/allaymc/server/component/interfaces/ComponentProvider.java @@ -5,7 +5,7 @@ import lombok.SneakyThrows; import org.allaymc.api.component.interfaces.Component; import org.allaymc.api.component.interfaces.ComponentInitInfo; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; import java.util.HashMap; import java.util.List; @@ -31,20 +31,22 @@ static ComponentProvider ofSingleton(T singleton) { return of((info) -> singleton, singleton.getClass()); } - static

Map> toMap(List> componentProviders) { - var map = new HashMap>(); + static

Map> toMap(List> componentProviders) { + var map = new HashMap>(); componentProviders.forEach(componentProvider -> { var id = componentProvider.findComponentIdentifier(); - if (map.containsKey(id)) + if (map.containsKey(id)) { throw new IllegalArgumentException("Duplicate component: " + id); + } + map.put(id, componentProvider); }); return map; } @SneakyThrows - static org.allaymc.api.utils.Identifier findComponentIdentifier(Class clazz) { - org.allaymc.api.utils.Identifier identifier = null; + static Identifier findComponentIdentifier(Class clazz) { + Identifier identifier = null; while (identifier == null) { identifier = findComponentIdentifierInCertainClass(clazz); if (identifier == null) clazz = clazz.getSuperclass(); @@ -54,11 +56,11 @@ static org.allaymc.api.utils.Identifier findComponentIdentifier(Class clazz) } @SneakyThrows - static org.allaymc.api.utils.Identifier findComponentIdentifierInCertainClass(Class clazz) { + static Identifier findComponentIdentifierInCertainClass(Class clazz) { for (var field : clazz.getDeclaredFields()) { - if (field.isAnnotationPresent(Identifier.class) && org.allaymc.api.utils.Identifier.class == field.getType() && isStatic(field.getModifiers())) { + if (field.isAnnotationPresent(Identifier.Component.class) && Identifier.class == field.getType() && isStatic(field.getModifiers())) { field.setAccessible(true); - return (org.allaymc.api.utils.Identifier) field.get(null); + return (Identifier) field.get(null); } } return null; @@ -69,7 +71,7 @@ static org.allaymc.api.utils.Identifier findComponentIdentifierInCertainClass(Cl Class getComponentClass(); @SneakyThrows - default org.allaymc.api.utils.Identifier findComponentIdentifier() { + default Identifier findComponentIdentifier() { return findComponentIdentifier(getComponentClass()); } diff --git a/server/src/main/java/org/allaymc/server/entity/component/EntityAttributeComponentImpl.java b/server/src/main/java/org/allaymc/server/entity/component/EntityAttributeComponentImpl.java index 75b9574da..8b869b2a2 100644 --- a/server/src/main/java/org/allaymc/server/entity/component/EntityAttributeComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/entity/component/EntityAttributeComponentImpl.java @@ -8,8 +8,8 @@ import org.allaymc.api.entity.component.attribute.EntityAttributeComponent; import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.eventbus.event.entity.EntityHealthChangeEvent; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.annotation.ComponentedObject; -import org.allaymc.server.component.annotation.Identifier; import org.allaymc.server.component.annotation.Manager; import org.allaymc.server.entity.component.event.CEntityAttributeChangeEvent; import org.allaymc.server.entity.component.event.CEntityLoadNBTEvent; @@ -30,8 +30,8 @@ @Slf4j public class EntityAttributeComponentImpl implements EntityAttributeComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:entity_attribute_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:entity_attribute_component"); protected final Map attributes = new EnumMap<>(AttributeType.class); @@ -101,7 +101,7 @@ public Attribute getAttribute(AttributeType attributeType) { public void setAttributeValue(AttributeType attributeType, float value) { var attribute = this.attributes.get(attributeType); if (attribute == null) { - throw unsupportAttributeTypeException(attributeType); + throw unsupportedAttributeTypeException(attributeType); } attribute.setCurrentValue(value); manager.callEvent(CEntityAttributeChangeEvent.INSTANCE); @@ -111,7 +111,7 @@ public void setAttributeValue(AttributeType attributeType, float value) { public void setAttribute(Attribute attribute) { var attributeType = AttributeType.byKey(attribute.getKey()); if (!this.attributes.containsKey(attributeType)) { - throw unsupportAttributeTypeException(attributeType); + throw unsupportedAttributeTypeException(attributeType); } this.attributes.put(AttributeType.byKey(attribute.getKey()), attribute); manager.callEvent(CEntityAttributeChangeEvent.INSTANCE); @@ -121,7 +121,7 @@ public void setAttribute(Attribute attribute) { public float getAttributeValue(AttributeType attributeType) { var attribute = this.getAttribute(attributeType); if (attribute == null) { - throw unsupportAttributeTypeException(attributeType); + throw unsupportedAttributeTypeException(attributeType); } return attribute.getCurrentValue(); } @@ -131,7 +131,7 @@ public void setHealth(float value) { if (!supportHealth()) { // Check if health is supported by the entity here // To make sure that if health is not supported, event won't be called - throw unsupportAttributeTypeException(AttributeType.HEALTH); + throw unsupportedAttributeTypeException(AttributeType.HEALTH); } if (value > 0 && value < 1) { // Client will think he is dead if the health is less than 1 @@ -149,7 +149,7 @@ public void setHealth(float value) { setAttributeValue(AttributeType.HEALTH, event.getNewHealth()); } - protected IllegalArgumentException unsupportAttributeTypeException(AttributeType attributeType) { + protected IllegalArgumentException unsupportedAttributeTypeException(AttributeType attributeType) { return new IllegalArgumentException("Attribute type " + attributeType + " is not found in entity " + thisEntity.getEntityType().getIdentifier()); } } diff --git a/server/src/main/java/org/allaymc/server/entity/component/EntityBaseComponentImpl.java b/server/src/main/java/org/allaymc/server/entity/component/EntityBaseComponentImpl.java index 823442835..518b3894f 100644 --- a/server/src/main/java/org/allaymc/server/entity/component/EntityBaseComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/entity/component/EntityBaseComponentImpl.java @@ -24,9 +24,13 @@ import org.allaymc.api.permission.DefaultPermissions; import org.allaymc.api.permission.tree.PermissionTree; import org.allaymc.api.server.Server; +import org.allaymc.api.utils.Identifier; import org.allaymc.api.world.Dimension; import org.allaymc.api.world.chunk.Chunk; -import org.allaymc.server.component.annotation.*; +import org.allaymc.server.component.annotation.ComponentedObject; +import org.allaymc.server.component.annotation.Dependency; +import org.allaymc.server.component.annotation.Manager; +import org.allaymc.server.component.annotation.OnInitFinish; import org.allaymc.server.entity.component.event.*; import org.allaymc.server.world.chunk.AllayChunk; import org.cloudburstmc.math.vector.Vector2f; @@ -63,8 +67,8 @@ @Slf4j public class EntityBaseComponentImpl implements EntityBaseComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:entity_base_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:entity_base_component"); public static final int DEFAULT_DEAD_TIMER = 20; diff --git a/server/src/main/java/org/allaymc/server/entity/component/EntityContainerHolderComponentImpl.java b/server/src/main/java/org/allaymc/server/entity/component/EntityContainerHolderComponentImpl.java index 4510f4552..99a32e592 100644 --- a/server/src/main/java/org/allaymc/server/entity/component/EntityContainerHolderComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/entity/component/EntityContainerHolderComponentImpl.java @@ -7,9 +7,9 @@ import org.allaymc.api.entity.component.EntityContainerHolderComponent; import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.item.interfaces.ItemAirStack; +import org.allaymc.api.utils.Identifier; import org.allaymc.api.world.gamerule.GameRule; import org.allaymc.server.component.annotation.ComponentedObject; -import org.allaymc.server.component.annotation.Identifier; import org.allaymc.server.entity.component.event.CEntityDieEvent; import org.jetbrains.annotations.UnmodifiableView; import org.joml.Vector3f; @@ -22,8 +22,8 @@ */ public class EntityContainerHolderComponentImpl extends BaseContainerHolder implements EntityContainerHolderComponent { - @Identifier - protected static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:entity_inventory_holder_component"); + @Identifier.Component + protected static final Identifier IDENTIFIER = new Identifier("minecraft:entity_inventory_holder_component"); @ComponentedObject protected static Entity thisEntity; diff --git a/server/src/main/java/org/allaymc/server/entity/component/EntityDamageComponentImpl.java b/server/src/main/java/org/allaymc/server/entity/component/EntityDamageComponentImpl.java index 9edc274c4..000cff97a 100644 --- a/server/src/main/java/org/allaymc/server/entity/component/EntityDamageComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/entity/component/EntityDamageComponentImpl.java @@ -12,10 +12,10 @@ import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.eventbus.event.entity.EntityDamageEvent; import org.allaymc.api.item.enchantment.type.EnchantmentTypes; +import org.allaymc.api.utils.Identifier; import org.allaymc.api.world.gamerule.GameRule; import org.allaymc.server.component.annotation.ComponentedObject; import org.allaymc.server.component.annotation.Dependency; -import org.allaymc.server.component.annotation.Identifier; import org.allaymc.server.component.annotation.Manager; import org.allaymc.server.entity.component.event.*; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; @@ -25,8 +25,8 @@ * @author daoge_cmd */ public class EntityDamageComponentImpl implements EntityDamageComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:entity_damage_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:entity_damage_component"); @Dependency protected EntityBaseComponent baseComponent; diff --git a/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerContainerViewerComponentImpl.java b/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerContainerViewerComponentImpl.java index 3a422ea11..156996901 100644 --- a/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerContainerViewerComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerContainerViewerComponentImpl.java @@ -13,8 +13,8 @@ import org.allaymc.api.entity.component.player.EntityPlayerBaseComponent; import org.allaymc.api.entity.component.player.EntityPlayerNetworkComponent; import org.allaymc.api.math.MathUtils; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.annotation.Dependency; -import org.allaymc.server.component.annotation.Identifier; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType; import org.cloudburstmc.protocol.bedrock.data.inventory.FullContainerName; @@ -32,8 +32,8 @@ */ public class EntityPlayerContainerViewerComponentImpl implements EntityContainerViewerComponent { - @Identifier - protected static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:entity_inventory_viewer_component"); + @Identifier.Component + protected static final Identifier IDENTIFIER = new Identifier("minecraft:entity_inventory_viewer_component"); protected byte idCounter = 1; @Dependency @@ -167,7 +167,9 @@ public T getOpenedContainer(FullContainerType type) { } } - if (container == null) container = typeToContainer.get(type); + if (container == null) { + container = typeToContainer.get(type); + } return (T) container; } @@ -184,7 +186,9 @@ public T getOpenedContainerBySlotType(ContainerSlotType sl }; } - if (fullType == null) fullType = slotTypeToFullType.get(slotType); + if (fullType == null) { + fullType = slotTypeToFullType.get(slotType); + } return (T) getOpenedContainer(fullType); } diff --git a/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerNetworkComponentImpl.java b/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerNetworkComponentImpl.java index b9531e0ab..dca681b2a 100644 --- a/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerNetworkComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerNetworkComponentImpl.java @@ -23,12 +23,12 @@ import org.allaymc.api.pack.Pack; import org.allaymc.api.registry.Registries; import org.allaymc.api.server.Server; +import org.allaymc.api.utils.Identifier; import org.allaymc.api.utils.Utils; import org.allaymc.api.world.Dimension; import org.allaymc.server.AllayServer; import org.allaymc.server.component.annotation.ComponentedObject; import org.allaymc.server.component.annotation.Dependency; -import org.allaymc.server.component.annotation.Identifier; import org.allaymc.server.component.annotation.Manager; import org.allaymc.server.entity.component.event.CPlayerLoggedInEvent; import org.allaymc.server.network.processor.AllayPacketProcessorHolder; @@ -53,7 +53,10 @@ import org.joml.Vector3fc; import javax.crypto.SecretKey; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.TreeMap; +import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -66,8 +69,8 @@ @Slf4j public class EntityPlayerNetworkComponentImpl implements EntityPlayerNetworkComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:player_network_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:player_network_component"); protected final Server server = Server.getInstance(); diff --git a/server/src/main/java/org/allaymc/server/item/component/ItemBaseComponentImpl.java b/server/src/main/java/org/allaymc/server/item/component/ItemBaseComponentImpl.java index e9234b25b..47a62a3b5 100644 --- a/server/src/main/java/org/allaymc/server/item/component/ItemBaseComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/item/component/ItemBaseComponentImpl.java @@ -26,9 +26,13 @@ import org.allaymc.api.item.type.ItemType; import org.allaymc.api.item.type.ItemTypes; import org.allaymc.api.math.position.Position3i; +import org.allaymc.api.utils.Identifier; import org.allaymc.api.world.Dimension; import org.allaymc.server.block.type.InternalBlockTypeData; -import org.allaymc.server.component.annotation.*; +import org.allaymc.server.component.annotation.ComponentedObject; +import org.allaymc.server.component.annotation.Dependency; +import org.allaymc.server.component.annotation.Manager; +import org.allaymc.server.component.annotation.OnInitFinish; import org.allaymc.server.item.component.event.*; import org.allaymc.server.utils.ItemMetaBlockStateBiMap; import org.cloudburstmc.nbt.NbtMap; @@ -48,8 +52,8 @@ @Slf4j public class ItemBaseComponentImpl implements ItemBaseComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:item_base_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:item_base_component"); private static int STACK_NETWORK_ID_COUNTER = 1; @@ -144,7 +148,7 @@ public NbtMap saveExtraTag() { nbtBuilder.putList("ench", NbtType.COMPOUND, enchantmentNBT); } - //TODO: item lock type + // TODO: item lock type // Custom NBT content if (!customNBTContent.isEmpty()) nbtBuilder.put("CustomNBT", customNBTContent); diff --git a/server/src/main/java/org/allaymc/server/item/component/ItemDataComponentImpl.java b/server/src/main/java/org/allaymc/server/item/component/ItemDataComponentImpl.java index c9054bafe..8e383c5e3 100644 --- a/server/src/main/java/org/allaymc/server/item/component/ItemDataComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/item/component/ItemDataComponentImpl.java @@ -4,15 +4,15 @@ import lombok.Getter; import org.allaymc.api.item.component.data.ItemData; import org.allaymc.api.item.component.data.ItemDataComponent; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; /** * @author daoge_cmd */ @AllArgsConstructor public class ItemDataComponentImpl implements ItemDataComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:item_data_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:item_data_component"); protected static final ItemDataComponentImpl DEFAULT = new ItemDataComponentImpl(ItemData.DEFAULT); diff --git a/server/src/test/java/org/allaymc/server/block/component/TestComponentImpl.java b/server/src/test/java/org/allaymc/server/block/component/TestComponentImpl.java index 31a6cd960..fd83a6180 100644 --- a/server/src/test/java/org/allaymc/server/block/component/TestComponentImpl.java +++ b/server/src/test/java/org/allaymc/server/block/component/TestComponentImpl.java @@ -1,12 +1,12 @@ package org.allaymc.server.block.component; import org.allaymc.api.block.component.BlockComponent; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; /** * @author daoge_cmd */ public class TestComponentImpl implements TestComponent, BlockComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:test_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:test_component"); } diff --git a/server/src/test/java/org/allaymc/server/component/ComponentTest.java b/server/src/test/java/org/allaymc/server/component/ComponentTest.java index b58faef1f..95ff30e0f 100644 --- a/server/src/test/java/org/allaymc/server/component/ComponentTest.java +++ b/server/src/test/java/org/allaymc/server/component/ComponentTest.java @@ -3,7 +3,7 @@ import lombok.SneakyThrows; import org.allaymc.api.component.interfaces.ComponentInitInfo; import org.allaymc.api.component.interfaces.ComponentedObject; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.impl.*; import org.allaymc.server.component.injector.AllayComponentInjector; import org.allaymc.server.component.interfaces.*; @@ -106,8 +106,8 @@ public void testMethod() { public static class SimpleNameComponentV2 extends SimpleNameComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:name_component_2"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:name_component_2"); public SimpleNameComponentV2(String name) { super(name); diff --git a/server/src/test/java/org/allaymc/server/component/impl/SimpleAttackComponent.java b/server/src/test/java/org/allaymc/server/component/impl/SimpleAttackComponent.java index f8312fb23..6673d1172 100644 --- a/server/src/test/java/org/allaymc/server/component/impl/SimpleAttackComponent.java +++ b/server/src/test/java/org/allaymc/server/component/impl/SimpleAttackComponent.java @@ -1,7 +1,7 @@ package org.allaymc.server.component.impl; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.annotation.Dependency; -import org.allaymc.server.component.annotation.Identifier; import org.allaymc.server.component.interfaces.AttackComponent; import org.allaymc.server.component.interfaces.HealthComponent; @@ -9,8 +9,8 @@ * @author daoge_cmd */ public class SimpleAttackComponent implements AttackComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:attack_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:attack_component"); @Dependency protected HealthComponent healthComponent; diff --git a/server/src/test/java/org/allaymc/server/component/impl/SimpleHealthComponent.java b/server/src/test/java/org/allaymc/server/component/impl/SimpleHealthComponent.java index 05cea07e1..b1ae13fa6 100644 --- a/server/src/test/java/org/allaymc/server/component/impl/SimpleHealthComponent.java +++ b/server/src/test/java/org/allaymc/server/component/impl/SimpleHealthComponent.java @@ -1,14 +1,14 @@ package org.allaymc.server.component.impl; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.interfaces.HealthComponent; /** * @author daoge_cmd */ public class SimpleHealthComponent implements HealthComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:health_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:health_component"); protected final int maxHealth; protected int health; diff --git a/server/src/test/java/org/allaymc/server/component/impl/SimpleNameComponent.java b/server/src/test/java/org/allaymc/server/component/impl/SimpleNameComponent.java index b4a5f1be3..1a209dd29 100644 --- a/server/src/test/java/org/allaymc/server/component/impl/SimpleNameComponent.java +++ b/server/src/test/java/org/allaymc/server/component/impl/SimpleNameComponent.java @@ -1,14 +1,14 @@ package org.allaymc.server.component.impl; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.interfaces.NameComponent; /** * @author daoge_cmd */ public class SimpleNameComponent implements NameComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:name_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:name_component"); protected String name; diff --git a/server/src/test/java/org/allaymc/server/component/impl/SimpleTestAnonymousClassComponent.java b/server/src/test/java/org/allaymc/server/component/impl/SimpleTestAnonymousClassComponent.java index a517c54d0..381f665a9 100644 --- a/server/src/test/java/org/allaymc/server/component/impl/SimpleTestAnonymousClassComponent.java +++ b/server/src/test/java/org/allaymc/server/component/impl/SimpleTestAnonymousClassComponent.java @@ -1,12 +1,12 @@ package org.allaymc.server.component.impl; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.interfaces.TestAnonymousClassComponent; /** * @author daoge_cmd */ public class SimpleTestAnonymousClassComponent implements TestAnonymousClassComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:test_anonymous_class_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:test_anonymous_class_component"); } diff --git a/server/src/test/java/org/allaymc/server/component/impl/SimpleTestDependencyComponent.java b/server/src/test/java/org/allaymc/server/component/impl/SimpleTestDependencyComponent.java index 81752d418..6e9729e65 100644 --- a/server/src/test/java/org/allaymc/server/component/impl/SimpleTestDependencyComponent.java +++ b/server/src/test/java/org/allaymc/server/component/impl/SimpleTestDependencyComponent.java @@ -1,16 +1,16 @@ package org.allaymc.server.component.impl; import org.allaymc.api.component.interfaces.Component; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.annotation.Dependency; -import org.allaymc.server.component.annotation.Identifier; import org.allaymc.server.component.interfaces.TestDependencyComponent; /** * @author daoge_cmd */ public class SimpleTestDependencyComponent implements TestDependencyComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:test_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:test_component"); @Dependency(identifier = "minecraft:name_component") diff --git a/server/src/test/java/org/allaymc/server/component/impl/SimpleTestEventListenerComponent.java b/server/src/test/java/org/allaymc/server/component/impl/SimpleTestEventListenerComponent.java index 0fbb178f6..7a7d4eb56 100644 --- a/server/src/test/java/org/allaymc/server/component/impl/SimpleTestEventListenerComponent.java +++ b/server/src/test/java/org/allaymc/server/component/impl/SimpleTestEventListenerComponent.java @@ -1,7 +1,7 @@ package org.allaymc.server.component.impl; import org.allaymc.api.eventbus.EventHandler; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.event.TestEvent; import org.allaymc.server.component.interfaces.TestEventListenerComponent; @@ -9,8 +9,8 @@ * @author daoge_cmd */ public class SimpleTestEventListenerComponent implements TestEventListenerComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:test_event_listener_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:test_event_listener_component"); @EventHandler protected void testListener(TestEvent event) { diff --git a/server/src/test/java/org/allaymc/server/component/impl/SimpleTestEventTriggerComponent.java b/server/src/test/java/org/allaymc/server/component/impl/SimpleTestEventTriggerComponent.java index c8453d35a..bc49643ac 100644 --- a/server/src/test/java/org/allaymc/server/component/impl/SimpleTestEventTriggerComponent.java +++ b/server/src/test/java/org/allaymc/server/component/impl/SimpleTestEventTriggerComponent.java @@ -1,7 +1,7 @@ package org.allaymc.server.component.impl; import org.allaymc.api.component.interfaces.ComponentManager; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.annotation.Manager; import org.allaymc.server.component.event.TestEvent; import org.allaymc.server.component.interfaces.TestEventTriggerComponent; @@ -10,8 +10,8 @@ * @author daoge_cmd */ public class SimpleTestEventTriggerComponent implements TestEventTriggerComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:test_event_trigger_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:test_event_trigger_component"); @Manager protected ComponentManager manager; diff --git a/server/src/test/java/org/allaymc/server/component/impl/SimpleTestInitArgComponent.java b/server/src/test/java/org/allaymc/server/component/impl/SimpleTestInitArgComponent.java index eb3414c91..66f21486f 100644 --- a/server/src/test/java/org/allaymc/server/component/impl/SimpleTestInitArgComponent.java +++ b/server/src/test/java/org/allaymc/server/component/impl/SimpleTestInitArgComponent.java @@ -1,14 +1,14 @@ package org.allaymc.server.component.impl; -import org.allaymc.server.component.annotation.Identifier; +import org.allaymc.api.utils.Identifier; import org.allaymc.server.component.interfaces.TestInitArgComponent; /** * @author daoge_cmd */ public class SimpleTestInitArgComponent implements TestInitArgComponent { - @Identifier - public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:test_init_arg_component"); + @Identifier.Component + public static final Identifier IDENTIFIER = new Identifier("minecraft:test_init_arg_component"); protected final int data;