Skip to content

Commit

Permalink
Merge pull request #2 from saydov/master
Browse files Browse the repository at this point in the history
Refactoring code x2 and added ``gradle workflows``
  • Loading branch information
mynameisvar authored Dec 3, 2024
2 parents 3d5c6cc + 6012f11 commit 11d5af8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 24 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Build with Gradle Wrapper
run: ./gradlew build

# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
#
# - name: Setup Gradle
# uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
# with:
# gradle-version: '8.9'
#
# - name: Build with Gradle 8.9
# run: gradle build

dependency-submission:

runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
16 changes: 4 additions & 12 deletions src/main/java/dev/var/entity/api/FakePlayerApiCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@
@UtilityClass
public class FakePlayerApiCreator {

public @NotNull FakePlayerApi fastSimpleApi(final @NotNull JavaPlugin javaPlugin) {
return SimpleFakePlayerApi.Fabric.fabric()
.javaPlugin(javaPlugin)
.fakePlayerEntities(new ObjectOpenHashSet<>())
.build()
.createApi();
public @NotNull FakePlayerApi apiWithFastHashSet(final @NotNull JavaPlugin javaPlugin) {
return SimpleFakePlayerApi.create(javaPlugin, new ObjectOpenHashSet<>());
}

public @NotNull FakePlayerApi javaSimpleApi(final @NotNull JavaPlugin javaPlugin) {
return SimpleFakePlayerApi.Fabric.fabric()
.javaPlugin(javaPlugin)
.fakePlayerEntities(new HashSet<>())
.build()
.createApi();
public @NotNull FakePlayerApi apiWithHashSet(final @NotNull JavaPlugin javaPlugin) {
return SimpleFakePlayerApi.create(javaPlugin, new HashSet<>());
}

}
18 changes: 7 additions & 11 deletions src/main/java/dev/var/entity/api/SimpleFakePlayerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.*;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
Expand All @@ -15,6 +16,12 @@
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class SimpleFakePlayerApi implements FakePlayerApi {

@Contract(value = "_, _ -> new", pure = true)
public static @NotNull FakePlayerApi create(@NotNull JavaPlugin javaPlugin,
@NotNull Set<FakePlayerEntity> fakePlayerEntities) {
return new SimpleFakePlayerApi(javaPlugin, fakePlayerEntities);
}

private final JavaPlugin javaPlugin;
private final Set<FakePlayerEntity> fakePlayerEntities;

Expand Down Expand Up @@ -66,15 +73,4 @@ public void destroy() {
fakePlayerEntity.getViewers().forEach(fakePlayerEntity::remove));
}

@Builder(builderMethodName = "fabric", toBuilder = true)
public static class Fabric {

private final JavaPlugin javaPlugin;
private final Set<FakePlayerEntity> fakePlayerEntities;

public @NotNull SimpleFakePlayerApi createApi() {
return new SimpleFakePlayerApi(javaPlugin, fakePlayerEntities);
}
}

}
3 changes: 2 additions & 1 deletion src/main/java/dev/var/entity/plugin/FakeEntityApiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;

@SuppressWarnings("unused")
public final class FakeEntityApiPlugin extends JavaPlugin {

private Location testFakePlayerLocation;
Expand All @@ -21,7 +22,7 @@ public void onLoad() {

@Override
public void onEnable() {
fakePlayerApi = FakePlayerApiCreator.fastSimpleApi(this);
fakePlayerApi = FakePlayerApiCreator.apiWithFastHashSet(this);
fakePlayerApi.init();

// todo loading fake players from config
Expand Down

0 comments on commit 11d5af8

Please sign in to comment.