Skip to content

Commit

Permalink
fix: introduce @ignore and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Sep 16, 2024
1 parent 5be230b commit 38b1987
Show file tree
Hide file tree
Showing 33 changed files with 101 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import org.allaymc.api.i18n.LangCode;
import org.allaymc.api.i18n.MayContainTrKey;
import org.allaymc.api.network.PacketReceiver;
import org.allaymc.api.world.chunk.ChunkLoader;
import org.cloudburstmc.protocol.bedrock.BedrockServerSession;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;

import javax.crypto.SecretKey;
import java.util.UUID;

/**
* Allay Project 2023/10/14
* EntityPlayerNetworkComponent is the component that manages network related things of a player.
*
* @author daoge_cmd
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
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.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.block.type.BlockLootTable;
import org.allaymc.server.component.annotation.ComponentIdentifier;
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;
Expand All @@ -38,8 +37,8 @@
*/
public class BlockBaseComponentImpl implements BlockBaseComponent {

@ComponentIdentifier
public static final Identifier IDENTIFIER = new Identifier("minecraft:block_base_component");
@Identifier
public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:block_base_component");

@Manager
protected ComponentManager manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +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.ComponentIdentifier;
import org.allaymc.server.component.annotation.Identifier;

/**
* Allay Project 2023/9/15
Expand All @@ -24,8 +23,8 @@
@Slf4j
@RequiredArgsConstructor
public class BlockEntityHolderComponentImpl<T extends BlockEntity> implements BlockEntityHolderComponent<T> {
@ComponentIdentifier
public static final Identifier IDENTIFIER = new Identifier("minecraft:block_entity_holder_component");
@Identifier
public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:block_entity_holder_component");

@Getter
protected final BlockEntityType<T> blockEntityType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
import org.allaymc.api.block.type.BlockType;
import org.allaymc.api.math.voxelshape.VoxelShape;
import org.allaymc.api.registry.Registries;
import org.allaymc.api.utils.Identifier;
import org.allaymc.server.component.annotation.ComponentIdentifier;
import org.allaymc.server.component.annotation.Identifier;
import org.allaymc.server.datastruct.collections.nb.Int2ObjectNonBlockingMap;
import org.apache.commons.lang3.function.TriFunction;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

Expand All @@ -26,8 +24,8 @@
*/
public class BlockStateDataComponentImpl implements BlockStateDataComponent {

@ComponentIdentifier
public static final Identifier IDENTIFIER = new Identifier("minecraft:block_state_data_component");
@Identifier
public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:block_state_data_component");

protected static final BlockStateDataComponentImpl DEFAULT = BlockStateDataComponentImpl.ofGlobalStatic(BlockStateData.DEFAULT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +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.ComponentIdentifier;
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;
Expand All @@ -26,8 +25,8 @@
* @author daoge_cmd
*/
public class BlockEntityBaseComponentImpl implements BlockEntityBaseComponent {
@ComponentIdentifier
public static final Identifier IDENTIFIER = new Identifier("minecraft:block_entity_base_component");
@Identifier
public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:block_entity_base_component");

@Manager
protected ComponentManager manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
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.ComponentIdentifier;
import org.allaymc.server.component.annotation.Identifier;
import org.allaymc.server.component.annotation.Dependency;
import org.cloudburstmc.nbt.NbtType;
import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType;
Expand All @@ -30,8 +29,8 @@
* @author daoge_cmd
*/
public class BlockEntityContainerHolderComponentImpl implements BlockEntityContainerHolderComponent {
@ComponentIdentifier
protected static final Identifier IDENTIFIER = new Identifier("minecraft:block_entity_inventory_holder_component");
@Identifier
protected static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:block_entity_inventory_holder_component");

@Dependency
protected BlockEntityBaseComponent baseComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.lang.annotation.Target;

/**
* Allay Project 2023/10/14
*
* @author daoge_cmd
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* If so, the injector will try to find the corresponding component instance through inheritance relationships (if identifier is empty) or through identifier (if identifier is not empty), and inject it into the field.
* <p>
* The scope of dependency lookup is limited by the list of components provided to the injector, and if the dependency is not found, will throw {@link ComponentInjectException}
* <p>
* Allay Project 2023/3/4
*
* @author daoge_cmd
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import java.lang.annotation.Target;

/**
* Allay Project 2023/6/23
*
* @author daoge_cmd
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ComponentIdentifier {
public @interface Identifier {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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.METHOD)
public @interface Ignore {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.lang.annotation.Target;

/**
* Allay Project 2023/5/6
*
* @author daoge_cmd
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.lang.annotation.Target;

/**
* Allay Project 2023/9/23
*
* @author daoge_cmd
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import org.allaymc.api.eventbus.event.Event;
import org.allaymc.api.utils.Identifier;
import org.allaymc.api.utils.exception.ComponentInjectException;
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.component.annotation.*;
import org.allaymc.server.component.interfaces.ComponentProvider;
import org.allaymc.server.eventbus.AllayEventBus;
import org.allaymc.server.utils.ComponentClassCacheUtils;
Expand Down Expand Up @@ -163,8 +160,10 @@ protected Class<T> buildClass() {
var componentFieldName = componentFieldNameMapping.get(provider);
try {
var methodImpl = provider.getComponentClass().getMethod(methodShouldBeInject.getName(), methodShouldBeInject.getParameterTypes());
//This method must be a default method, and the component implementation doesn't override it
//So that we don't need to handle it, as it has a default implementation
// This method is annotated with @Ignore, which means that it won't be used as a method impl, so we skip it
if (methodImpl.isAnnotationPresent(Ignore.class)) continue;
// This method must be a default method, and the component implementation doesn't override it
// So that we don't need to handle it, as it has a default implementation
if (methodImpl.equals(methodShouldBeInject)) continue;

if (methodDelegation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import lombok.SneakyThrows;
import org.allaymc.api.component.interfaces.Component;
import org.allaymc.api.component.interfaces.ComponentInitInfo;
import org.allaymc.api.utils.Identifier;
import org.allaymc.server.component.annotation.ComponentIdentifier;
import org.allaymc.server.component.annotation.Identifier;

import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -34,8 +33,8 @@ static <T extends Component> ComponentProvider<T> ofSingleton(T singleton) {
return of((info) -> singleton, singleton.getClass());
}

static <P extends Component> Map<Identifier, ComponentProvider<? extends P>> toMap(List<ComponentProvider<? extends P>> componentProviders) {
var map = new HashMap<Identifier, ComponentProvider<? extends P>>();
static <P extends Component> Map<org.allaymc.api.utils.Identifier, ComponentProvider<? extends P>> toMap(List<ComponentProvider<? extends P>> componentProviders) {
var map = new HashMap<org.allaymc.api.utils.Identifier, ComponentProvider<? extends P>>();
componentProviders.forEach(componentProvider -> {
var id = componentProvider.findComponentIdentifier();
if (map.containsKey(id))
Expand All @@ -46,8 +45,8 @@ static <P extends Component> Map<Identifier, ComponentProvider<? extends P>> toM
}

@SneakyThrows
static Identifier findComponentIdentifier(Class<?> clazz) {
Identifier identifier = null;
static org.allaymc.api.utils.Identifier findComponentIdentifier(Class<?> clazz) {
org.allaymc.api.utils.Identifier identifier = null;
while (identifier == null) {
identifier = findComponentIdentifierInCertainClass(clazz);
if (identifier == null) clazz = clazz.getSuperclass();
Expand All @@ -57,11 +56,11 @@ static Identifier findComponentIdentifier(Class<?> clazz) {
}

@SneakyThrows
static Identifier findComponentIdentifierInCertainClass(Class<?> clazz) {
static org.allaymc.api.utils.Identifier findComponentIdentifierInCertainClass(Class<?> clazz) {
for (var field : clazz.getDeclaredFields()) {
if (field.isAnnotationPresent(ComponentIdentifier.class) && Identifier.class == field.getType() && isStatic(field.getModifiers())) {
if (field.isAnnotationPresent(Identifier.class) && org.allaymc.api.utils.Identifier.class == field.getType() && isStatic(field.getModifiers())) {
field.setAccessible(true);
return (Identifier) field.get(null);
return (org.allaymc.api.utils.Identifier) field.get(null);
}
}
return null;
Expand All @@ -72,7 +71,7 @@ static Identifier findComponentIdentifierInCertainClass(Class<?> clazz) {
Class<?> getComponentClass();

@SneakyThrows
default Identifier findComponentIdentifier() {
default org.allaymc.api.utils.Identifier findComponentIdentifier() {
return findComponentIdentifier(getComponentClass());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
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.ComponentIdentifier;
import org.allaymc.server.component.annotation.Identifier;
import org.allaymc.server.component.annotation.ComponentedObject;
import org.allaymc.server.component.annotation.Manager;
import org.allaymc.server.entity.component.event.CEntityAttributeChangeEvent;
Expand All @@ -33,8 +32,8 @@
@Slf4j
public class EntityAttributeComponentImpl implements EntityAttributeComponent {

@ComponentIdentifier
public static final Identifier IDENTIFIER = new Identifier("minecraft:entity_attribute_component");
@Identifier
public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:entity_attribute_component");

protected final Map<AttributeType, Attribute> attributes = new EnumMap<>(AttributeType.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.allaymc.api.perm.DefaultPermissions;
import org.allaymc.api.perm.tree.PermTree;
import org.allaymc.api.server.Server;
import org.allaymc.api.utils.Identifier;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.world.Dimension;
import org.allaymc.api.world.World;
Expand Down Expand Up @@ -72,8 +71,8 @@
@Slf4j
public class EntityBaseComponentImpl implements EntityBaseComponent {

@ComponentIdentifier
public static final Identifier IDENTIFIER = new Identifier("minecraft:entity_base_component");
@Identifier
public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:entity_base_component");

public static final int DEFAULT_DEAD_TIMER = 20;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
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.ComponentIdentifier;
import org.allaymc.server.component.annotation.Identifier;
import org.allaymc.server.component.annotation.ComponentedObject;
import org.allaymc.server.entity.component.event.CEntityDieEvent;
import org.jetbrains.annotations.UnmodifiableView;
Expand All @@ -25,8 +24,8 @@
*/
public class EntityContainerHolderComponentImpl extends BaseContainerHolder implements EntityContainerHolderComponent {

@ComponentIdentifier
protected static final Identifier IDENTIFIER = new Identifier("minecraft:entity_inventory_holder_component");
@Identifier
protected static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:entity_inventory_holder_component");

@ComponentedObject
protected static Entity thisEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
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.ComponentIdentifier;
import org.allaymc.server.component.annotation.Identifier;
import org.allaymc.server.component.annotation.ComponentedObject;
import org.allaymc.server.component.annotation.Dependency;
import org.allaymc.server.component.annotation.Manager;
Expand All @@ -24,16 +23,15 @@
import org.allaymc.server.entity.component.event.CEntityTryDamageEvent;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType;
import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket;
import org.joml.Vector3f;

/**
* Allay Project 2024/1/12
*
* @author daoge_cmd
*/
public class EntityDamageComponentImpl implements EntityDamageComponent {
@ComponentIdentifier
public static final Identifier IDENTIFIER = new Identifier("minecraft:entity_damage_component");
@Identifier
public static final org.allaymc.api.utils.Identifier IDENTIFIER = new org.allaymc.api.utils.Identifier("minecraft:entity_damage_component");

@Dependency
protected EntityBaseComponent baseComponent;
Expand Down
Loading

0 comments on commit 38b1987

Please sign in to comment.