Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions module-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<artifactId>feathercore-shared</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,39 @@

package ru.feathercore.moduleapi;

import com.google.common.base.Preconditions;
import lombok.*;
import lombok.experimental.FieldDefaults;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

/**
* An abstract implementation of {@link ModuleLoader<M>} sufficient for all operations it requires.
*
* @param <M> super-type of all modules managed
* @param <M> super-type of modules which this module-loader can manage
*/
@ToString
@EqualsAndHashCode
@FieldDefaults(level = AccessLevel.PROTECTED, makeFinal = true)
public abstract class AbstractModuleLoader<M extends Module> implements ModuleLoader<M> {

@NonNull Collection<M> modules, modulesView;
@NonNull Set<M> modules, modulesView;

public AbstractModuleLoader(@NonNull final Collection<M> modules) {
this.modules = modules;
modulesView = Collections.unmodifiableCollection(modules);
/**
* Creates new instance of module loader using the given set for storage of modules.
*
* @param modulesSet set which will be used for storage of loaded modules
*
* @throws IllegalArgumentException if the given set is non-empty
*/
public AbstractModuleLoader(@NonNull final Set<M> modulesSet) {
Preconditions.checkArgument(modulesSet.isEmpty(), "modulesSet should be empty");

this.modules = modulesSet;
modulesView = Collections.unmodifiableSet(modulesSet);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Loader of {@link Module modules} which uses {@link ModuleInitializer initializers} for this purpose.
*
* @param <M> super-type of all modules managed
* @param <M> super-type of modules which this module-loader can manage
*/
public interface ModuleLoader<M extends Module> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2019 Feather Core
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ru.feathercore.moduleapi;

import lombok.NonNull;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
* Simple module loader based on {@link AbstractModuleLoader}.
* It provides shorthand constructors for most commons use-cases.
*
* @param <M> super-type of modules which this module-loader can manage
*/
public class SimpleModuleLoader<M extends Module> extends AbstractModuleLoader<M> {

/**
* Creates new instance of module loader using the given set for storage of modules.
*
* @param modulesSet set which will be used for storage of loaded modules
*
* @throws IllegalArgumentException if the given set is non-empty
*/
public SimpleModuleLoader(@NonNull final Set<M> modulesSet) {
super(modulesSet);
}

/**
* Creates new instance of module loader enabling concurrency support if needed.
*
* @param concurrent {@code true} if the module loader should allow concurrent operations
* and {@code false} otherwise
*/
public SimpleModuleLoader(final boolean concurrent) {
this(concurrent ? ConcurrentHashMap.newKeySet() : new HashSet<>());
}

/**
* Creates new instance of module loader enabling concurrency support.
*/
public SimpleModuleLoader() {
this(true);
}
}
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<module>eventbus</module>
<module>module-api</module>
<module>protocol</module>
<module>server</module>
</modules>

<repositories>
Expand All @@ -61,6 +62,10 @@
<name>Minecraft Libraries</name>
<url>https://libraries.minecraft.net</url>
</repository>
<repository>
<id>sonatype-snapshot-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>

<build>
Expand Down Expand Up @@ -107,6 +112,11 @@
<artifactId>feathercore-protocol</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>feathercore-server</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Hamcrest should be above any possible JUnit dependencies -->
<dependency>
<groupId>org.hamcrest</groupId>
Expand All @@ -123,7 +133,7 @@
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId>
<version>1.13-SNAPSHOT</version>
<version>1.14-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
17 changes: 17 additions & 0 deletions protocol/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,22 @@
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2019 Feather Core
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.feathercore.protocol.annotation;

import java.lang.annotation.*;

/**
* Annotation used for creation of {@link org.feathercore.protocol.packet.PacketType}
* from the class containing the annotation.
* <ul>
* <li>When present on the class, it should normally be of type {@link org.feathercore.protocol.packet.Packet}</li>
* <li>When present on the method or constructor, it should be the default factory for the packet
* and its containing class should normally be of type {@link org.feathercore.protocol.packet.Packet}</li>
* </ul>.
*/
@Documented
@Target({ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface PacketFactory {

/**
* Retrieves the ID which should be used for creation of {@link org.feathercore.protocol.packet.PacketType}.
*
* @return ID which should be used for creation of {@link org.feathercore.protocol.packet.PacketType}
int value();
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2019 Feather Core
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.feathercore.protocol.annotation;

import java.lang.annotation.*;

/**
* Annotation used for creation of {@link org.feathercore.protocol.packet.PacketType}
* from the class annotated with it.
*
* @apiNote This is an alternative to {@link PacketFactory} - they cannot be used at the same time.
*/
@Documented
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface PacketId {
/**
* ID of a packet which this class represents.
*
* @return ID of the packet which this class represents
*/
int value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
package org.feathercore.protocol.minecraft.packet.handshake.client;

import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.annotation.PacketId;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.feathercore.protocol.packet.ConnectionState;
import org.jetbrains.annotations.NotNull;

/**
* Created by k.shandurenko on 09/04/2019
*/
@PacketId(HandshakePacketClientHandshake.ID)
public class HandshakePacketClientHandshake implements MinecraftPacket {

public static final int ID = 0x00;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.annotation.PacketId;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.jetbrains.annotations.NotNull;

Expand All @@ -32,6 +33,7 @@
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PROTECTED)
@PacketId(LoginPacketClientEncryptionResponse.ID)
public class LoginPacketClientEncryptionResponse implements MinecraftPacket {

public static final int ID = 0x01;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.annotation.PacketId;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.jetbrains.annotations.NotNull;

Expand All @@ -33,6 +34,7 @@
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PROTECTED)
@PacketId(LoginPacketClientLoginStart.ID)
public class LoginPacketClientLoginStart implements MinecraftPacket {

public static final int ID = 0x00;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import lombok.experimental.FieldDefaults;
import net.md_5.bungee.api.chat.BaseComponent;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.annotation.PacketId;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.jetbrains.annotations.NotNull;

Expand All @@ -33,6 +34,7 @@
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PROTECTED)
@PacketId(LoginPacketServerDisconnect.ID)
public class LoginPacketServerDisconnect implements MinecraftPacket {

public static final int ID = 0x00;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.annotation.PacketId;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.jetbrains.annotations.NotNull;

Expand All @@ -32,6 +33,7 @@
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PROTECTED)
@PacketId(LoginPacketServerEnableCompression.ID)
public class LoginPacketServerEnableCompression implements MinecraftPacket {

public static final int ID = 0x03;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.annotation.PacketId;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.feathercore.protocol.encrypt.CryptManager;
import org.jetbrains.annotations.NotNull;
Expand All @@ -35,6 +36,7 @@
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PROTECTED)
@PacketId(LoginPacketServerEncryptionRequest.ID)
public class LoginPacketServerEncryptionRequest implements MinecraftPacket {

public static final int ID = 0x01;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.annotation.PacketId;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.jetbrains.annotations.NotNull;

Expand All @@ -35,6 +36,7 @@
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PROTECTED)
@PacketId(LoginPacketServerLoginSuccess.ID)
public class LoginPacketServerLoginSuccess implements MinecraftPacket {

public static final int ID = 0x02;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.feathercore.protocol.Buffer;
import org.feathercore.protocol.annotation.PacketId;
import org.feathercore.protocol.minecraft.packet.MinecraftPacket;
import org.jetbrains.annotations.NotNull;

Expand All @@ -32,6 +33,7 @@
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PROTECTED)
@PacketId(StatusPacketClientPing.ID)
public class StatusPacketClientPing implements MinecraftPacket {

public static final int ID = 0x01;
Expand Down
Loading