Merge branch 'development'

This commit is contained in:
Christian Koop 2023-05-07 15:19:08 +02:00
commit 880d9d36e0
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
194 changed files with 4205 additions and 1723 deletions

10
.github/FUNDING.yml vendored
View File

@ -1,12 +1,2 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: songoda
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: [ 'https://songoda.com/songoda+' ]

View File

@ -0,0 +1,23 @@
name: Prepare Workspace
description: Prepares the workspace for compilation
inputs:
maven_username:
required: false
description: The username to use for the Maven server
maven_password:
required: false
description: The password to use for the Maven server
runs:
using: composite
steps:
- uses: songoda/GH-Commons/.github/actions/setup_workspace@master
with:
maven_username: ${{ inputs.maven_username }}
maven_password: ${{ inputs.maven_password }}
- uses: SpraxDev/Action-SpigotMC@v4
with:
versions: 1.18.1, 1.18.2, 1.19, 1.19.2, 1.19.3, 1.19.4
remapped: true

13
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: maven
directory: /
target-branch: development
schedule:
interval: monthly
- package-ecosystem: github-actions
directory: /
target-branch: development
schedule:
interval: monthly

94
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,94 @@
name: Build
on:
push:
branches: [ master, development, development-v3 ]
tags:
- 'v*'
pull_request:
types: [ opened, synchronize, reopened ]
permissions: read-all
env:
DEPLOYMENT_POM_PATH: ./Core/dependency-reduced-pom.xml
DEPLOYMENT_ARTIFACT_DIR: ./Core/target
DEPLOYMENT_ARTIFACT_SELECTOR: SongodaCore-*.jar
jobs:
Tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Prepare Workspace
uses: ./.github/actions/setup_project_workspace
- name: Run tests
run: mvn -B clean test
Build:
name: Build + Deploy
runs-on: ubuntu-latest
needs: [ Tests ]
steps:
- uses: actions/checkout@v2
- name: Prepare Workspace
uses: ./.github/actions/setup_project_workspace
with:
maven_username: ${{ secrets.MAVEN_REPO_USERNAME }}
maven_password: ${{ secrets.MAVEN_REPO_PASSWORD }}
- name: Set project version
uses: songoda/GH-Commons/.github/actions/maven_set_project_version@master
with:
append_snapshot: ${{ github.ref_type == 'tag' && 'false' || 'true' }}
version: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
increment_version: ${{ github.ref_type == 'tag' && '' || 'patch' }}
- name: Build with Maven
run: mvn -B -Duser.name="GitHub Actions on $GITHUB_REPOSITORY (id=$GITHUB_RUN_ID)" -DskipTests clean package
- name: Sign jar archives
uses: songoda/GH-Commons/.github/actions/sign_jars@master
with:
jar_file_selector: ${{ env.DEPLOYMENT_ARTIFACT_DIR }}/${{ env.DEPLOYMENT_ARTIFACT_SELECTOR }}
keystore_gpg_encrypted: ${{ secrets.JARSIGNER_KEYSTORE_ENCRYPTED }}
keystore_gpg_password: ${{ secrets.JARSIGNER_KEYSTORE_ENCRYPTED_PASSWORD }}
keystore_password: ${{ secrets.JARSIGNER_KEYSTORE_PASSWORD }}
- name: 'Upload Build Artifacts'
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}
path: ${{ env.DEPLOYMENT_ARTIFACT_DIR }}/${{ env.DEPLOYMENT_ARTIFACT_SELECTOR }}
- name: Deploy to Maven repo
uses: songoda/GH-Commons/.github/actions/maven_deploy@master
with:
repository_url: ${{ secrets.MAVEN_REPO_URL_RELEASES }}
repository_url_snapshots: ${{ secrets.MAVEN_REPO_URL_SNAPSHOTS }}
maven_pom_path: ${{ env.DEPLOYMENT_POM_PATH }}
maven_out_dir: ${{ env.DEPLOYMENT_ARTIFACT_DIR }}
- name: Deploy parent pom.xml to Maven repo
uses: songoda/GH-Commons/.github/actions/maven_deploy@master
with:
repository_url: ${{ secrets.MAVEN_REPO_URL_RELEASES }}
repository_url_snapshots: ${{ secrets.MAVEN_REPO_URL_SNAPSHOTS }}
only_deploy_pom: true
maven_out_dir: ${{ env.DEPLOYMENT_ARTIFACT_DIR }}
discord_webhook:
name: Send Discord Webhook
runs-on: ubuntu-latest
needs: [ Tests, Build ]
if: ${{ always() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development' || github.ref_type == 'tag') }}
steps:
- uses: actions/checkout@v2
- name: Notify Webhook
uses: songoda/GH-Commons/.github/actions/discord_send_job_results@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
webhook_url: ${{ secrets.DISCORD_BUILD_STATUS_WEBHOOK }}

36
.github/workflows/codeql.yml vendored Normal file
View File

@ -0,0 +1,36 @@
name: CodeQL
on:
push:
branches: [ master, development ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master, development ]
schedule:
- cron: 30 18 * * 4
permissions:
actions: read
contents: read
security-events: write
jobs:
Analyze:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: java
- name: Prepare Workspace
uses: ./.github/actions/setup_project_workspace
- name: Build with Maven
run: mvn -B -DskipTests clean package
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

View File

@ -1,61 +0,0 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Build SongodaCore
on:
push:
branches: [ master, development ]
pull_request:
types: [ opened, synchronize, reopened ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
# Checkout project files
- uses: actions/checkout@v2
# Setup Java
- uses: actions/setup-java@v2
with:
java-version: 17
distribution: adopt
cache: maven
# Build remapped Spigot versions
- uses: SpraxDev/Action-SpigotMC@v4
with:
versions: 1.18, 1.18.2, 1.19, 1.19.2, 1.19.3, 1.19.4
remapped: true
# Build project
- name: Build with Maven
run: 'mvn -B -Duser.name="GitHub Runner on $GITHUB_REPOSITORY (id=$GITHUB_RUN_ID)" clean package'
# Upload build artifacts
- name: 'Upload Build Artifact: SongodaCore-*.jar'
uses: actions/upload-artifact@v2
with:
name: SongodaCore-artifacts
path: ./Core/target/SongodaCore-*.jar
##
# Discord Webhook
# TODO: Extract into external Action for better reusability (and readability)
##
- name: 'Discord Webhook (Success)'
if: ${{ success() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development') }}
continue-on-error: true
run: |
curl -X POST --data "{\"content\":null,\"embeds\":[{\"title\":\"Build succeeded!\",\"description\":\"The build with the ID #$GITHUB_RUN_NUMBER has succeeded!\",\"url\":\"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID\",\"color\":5490477,\"fields\":[{\"name\":\"Branch\",\"value\":\"$GITHUB_REF\",\"inline\":true}],\"author\":{\"name\":\"$GITHUB_REPOSITORY\",\"url\":\"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY\",\"icon_url\":\"$GITHUB_SERVER_URL/songoda.png\"},\"footer\":{\"text\":\"Initiated by $GITHUB_ACTOR\",\"icon_url\":\"$GITHUB_SERVER_URL/$GITHUB_ACTOR.png\"}}],\"username\":\"OctoAgent\",\"avatar_url\":\"https://github.githubassets.com/images/modules/logos_page/Octocat.png\"}" --header 'Content-Type: application/json' $DISCORD_WEBHOOK
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_BUILD_STATUS_WEBHOOK }}
- name: 'Discord Webhook (Failure)'
if: ${{ failure() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development') }}
continue-on-error: true
run: |
curl -X POST --data "{\"content\":null,\"embeds\":[{\"title\":\"Build failed!\",\"description\":\"The build with the ID #$GITHUB_RUN_NUMBER has failed!\",\"url\":\"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID\",\"color\":15611419,\"fields\":[{\"name\":\"Branch\",\"value\":\"$GITHUB_REF\",\"inline\":true}],\"author\":{\"name\":\"$GITHUB_REPOSITORY\",\"url\":\"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY\",\"icon_url\":\"$GITHUB_SERVER_URL/songoda.png\"},\"footer\":{\"text\":\"Initiated by $GITHUB_ACTOR\",\"icon_url\":\"$GITHUB_SERVER_URL/$GITHUB_ACTOR.png\"}}],\"username\":\"OctoAgent\",\"avatar_url\":\"https://github.githubassets.com/images/modules/logos_page/Octocat.png\"}" --header "Content-Type:application/json" $DISCORD_WEBHOOK
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_BUILD_STATUS_WEBHOOK }}

View File

@ -2,47 +2,43 @@ name: SonarCloud
on:
push:
branches: [ master, development ]
branches: [ master, development, development-v3 ]
pull_request:
types: [ opened, synchronize, reopened ]
permissions: read-all
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_PROJECT_KEY: songoda_SongodaCore
jobs:
build:
name: Build
Analyze:
runs-on: ubuntu-latest
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
steps:
# Checkout project files
- uses: actions/checkout@v2
- uses: actions/checkout@v3
if: ${{ env.SONAR_TOKEN != null }}
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
fetch-depth: 0
# Setup Java
- uses: actions/setup-java@v2
- name: Prepare Workspace
if: ${{ env.SONAR_TOKEN != null }}
with:
java-version: 17
distribution: adopt
cache: maven
uses: ./.github/actions/setup_project_workspace
# Cache
- name: 'Cache: SonarCloud'
if: ${{ env.SONAR_TOKEN != null }}
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
# Build remapped Spigot versions
- uses: SpraxDev/Action-SpigotMC@v4
with:
versions: 1.18, 1.18.2, 1.19, 1.19.2, 1.19.3, 1.19.4
remapped: true
- name: Analyze project
if: ${{ env.SONAR_TOKEN != null }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=songoda_SongodaCore
run: >
mvn -B \
verify \
org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
"-Dsonar.projectKey=$SONAR_PROJECT_KEY"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -7,18 +7,16 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-Compatibility</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18-R0.1-SNAPSHOT</version>
<version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

View File

@ -1,7 +1,7 @@
package com.songoda.core.compatibility;
/**
* @deprecated Usage is highly discouraged use NMSManager instead
* @deprecated Usage is highly discouraged use com.songoda.core.nms.Nms#getImplementations() instead
*/
@Deprecated
public enum ClassMapping {

View File

@ -5,6 +5,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Contract;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -1548,6 +1549,7 @@ public enum CompatibleMaterial {
*
* @return LegacyMaterial or null if none found
*/
@Contract("_, !null -> !null")
public static CompatibleMaterial getMaterial(String name, CompatibleMaterial def) {
return name == null ? def : lookupMap.getOrDefault(name.toUpperCase(), def);
}

View File

@ -6,7 +6,7 @@ import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method;
/**
* @deprecated Usage is highly discouraged use NMSManager instead
* @deprecated Usage is highly discouraged use com.songoda.core.nms.Nms#getImplementations() instead
*/
@Deprecated
public enum MethodMapping {

View File

@ -6,26 +6,27 @@ import org.bukkit.Bukkit;
public enum ServerVersion {
UNKNOWN, V1_7, V1_8, V1_9, V1_10, V1_11, V1_12, V1_13, V1_14, V1_15, V1_16, V1_17, V1_18, V1_19, V1_20, V1_21;
private final static String serverPackagePath;
private final static String serverPackageVersion;
private final static String serverReleaseVersion;
private final static ServerVersion serverVersion;
private final static boolean isMocked;
static {
String srvPackage = Bukkit.getServer().getClass().getPackage().getName();
isMocked = srvPackage.equals("be.seeseemelk.mockbukkit");
if (Bukkit.getServer() != null) {
String srvPackage = Bukkit.getServer().getClass().getPackage().getName();
isMocked = srvPackage.equals("be.seeseemelk.mockbukkit");
if (isMocked) {
String packageVersionShard = "v" + Bukkit.getServer().getBukkitVersion().replace('.', '_') + "_R0";
serverPackagePath = "org.bukkit.craftbukkit." + packageVersionShard;
serverPackageVersion = packageVersionShard;
serverReleaseVersion = "0";
if (isMocked) {
serverPackageVersion = "v" + Bukkit.getServer().getBukkitVersion().replace('.', '_') + "_R0";
serverReleaseVersion = "0";
} else {
serverPackageVersion = srvPackage.substring(srvPackage.lastIndexOf('.') + 1);
serverReleaseVersion = serverPackageVersion.indexOf('R') != -1 ? serverPackageVersion.substring(serverPackageVersion.indexOf('R') + 1) : "";
}
} else {
serverPackagePath = srvPackage;
serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
serverReleaseVersion = serverPackageVersion.indexOf('R') != -1 ? serverPackageVersion.substring(serverPackageVersion.indexOf('R') + 1) : "";
serverPackageVersion = "Bukkit-not-initialized";
serverReleaseVersion = "Bukkit-not-initialized";
isMocked = false;
}
serverVersion = getVersion();
@ -42,18 +43,34 @@ public enum ServerVersion {
}
public boolean isLessThan(ServerVersion other) {
if (serverVersion == UNKNOWN) {
return false;
}
return this.ordinal() < other.ordinal();
}
public boolean isAtOrBelow(ServerVersion other) {
if (serverVersion == UNKNOWN && other != UNKNOWN) {
return false;
}
return this.ordinal() <= other.ordinal();
}
public boolean isGreaterThan(ServerVersion other) {
if (serverVersion == UNKNOWN) {
return false;
}
return this.ordinal() > other.ordinal();
}
public boolean isAtLeast(ServerVersion other) {
if (serverVersion == UNKNOWN && other != UNKNOWN) {
return false;
}
return this.ordinal() >= other.ordinal();
}
@ -78,18 +95,34 @@ public enum ServerVersion {
}
public static boolean isServerVersionAbove(ServerVersion version) {
if (serverVersion == UNKNOWN) {
return false;
}
return serverVersion.ordinal() > version.ordinal();
}
public static boolean isServerVersionAtLeast(ServerVersion version) {
if (serverVersion == UNKNOWN && version != UNKNOWN) {
return false;
}
return serverVersion.ordinal() >= version.ordinal();
}
public static boolean isServerVersionAtOrBelow(ServerVersion version) {
if (serverVersion == UNKNOWN && version != UNKNOWN) {
return false;
}
return serverVersion.ordinal() <= version.ordinal();
}
public static boolean isServerVersionBelow(ServerVersion version) {
if (serverVersion == UNKNOWN) {
return false;
}
return serverVersion.ordinal() < version.ordinal();
}
}

View File

@ -1,32 +0,0 @@
package com.songoda.core.compatibility.bukkit;
import be.seeseemelk.mockbukkit.MockBukkit;
import com.songoda.core.compatibility.CompatibleSound;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class CompatibleSoundTest {
@BeforeEach
void setUp() {
MockBukkit.mock();
}
@AfterEach
void tearDown() {
MockBukkit.unmock();
}
@Test
@Disabled("CompatibleSound class needs some work beforehand")
void getSound() {
for (CompatibleSound compatibleSound : CompatibleSound.values()) {
assertNotNull(compatibleSound.getSound());
// compatibleSound.usesCompatibility()
}
}
}

View File

@ -7,27 +7,37 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore</artifactId>
<packaging>jar</packaging>
<build>
<finalName>SongodaCore-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<groupId>de.m3y.maven</groupId>
<artifactId>inject-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>inject</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${java.release}</release>
<injections>
<injection>
<value>${project.version}</value>
<pointCut>com.songoda.core.SongodaCoreConstants.getCoreVersion</pointCut>
</injection>
</injections>
</configuration>
</plugin>
@ -63,7 +73,19 @@
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<useDependencyReducedPomInJar>true</useDependencyReducedPomInJar>
<artifactSet>
<includes>
<include>com.songoda:*</include>
<include>com.zaxxer:HikariCP</include>
<include>de.tr7zw:item-nbt-api</include>
<include>net.kyori:*</include>
<include>org.apache.commons:commons-lang3</include>
<include>org.apache.commons:commons-text</include>
<include>org.yaml:snakeyaml</include>
</includes>
</artifactSet>
<relocations>
<relocation>
@ -76,21 +98,30 @@
<shadedPattern>com.songoda.core.third_party.de.tr7zw.nbtapi</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>com.songoda.core.third_party.net.kyori</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>com.songoda.core.third_party.org.apache.commons</shadedPattern>
</relocation>
<relocation>
<pattern>org.yaml.snakeyaml</pattern>
<shadedPattern>com.songoda.core.third_party.org.yaml.snakeyaml</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<includes>
<include>com.songoda:*</include>
<include>com.zaxxer:HikariCP</include>
<include>org.apache.commons:commons-text</include>
<include>org.apache.commons:commons-lang3</include>
<include>de.tr7zw:item-nbt-api</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>**/*.class</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
@ -114,7 +145,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.17</version>
<version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@ -125,6 +156,13 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
@ -132,148 +170,33 @@
<scope>compile</scope>
</dependency>
<!-- Need to include all NMS modules here -->
<!-- Note when adding a new module: include the class in NmsManager -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_8_R1</artifactId>
<version>${project.version}</version>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_8_R2</artifactId>
<version>${project.version}</version>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_8_R3</artifactId>
<version>${project.version}</version>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.33</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_9_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_9_R2</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_10_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_11_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_12_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_13_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_13_R2</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_14_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_15_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_16_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_16_R2</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_16_R3</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_17_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_18_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_18_R2</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_19_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_19_R1v2</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_19_R2</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-v1_19_R3</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<!-- End NMS -->
<!-- Start Plugin Hooks -->
<dependency>
@ -448,47 +371,5 @@
<scope>provided</scope>
</dependency>
<!-- End Plugin Hooks -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.23.1</version>
</dependency>
</dependencies>
</project>

View File

@ -44,27 +44,36 @@ import java.util.logging.Level;
import java.util.logging.Logger;
public class SongodaCore {
private final static Logger logger = Logger.getLogger("SongodaCore");
private static final Logger logger = Logger.getLogger(SongodaCoreConstants.getProjectName());
/**
* Whenever we make a major change to the core GUI, updater,
* or other function used by the core, increment this number
*
* @deprecated The Core's version should be used instead as it uses Semantic Versioning
*/
private final static int coreRevision = 9;
@Deprecated
private static final int coreRevision = 9;
/**
* @since coreRevision 6
* @deprecated Is being replaced by {@link SongodaCoreConstants#getCoreVersion()} which is automatically kept up to date.
*/
private final static String coreVersion = "2.6.21";
@Deprecated
private static final String coreVersion = SongodaCoreConstants.getCoreVersion();
/**
* This is specific to the website api
*
* @deprecated Seems useless and will probably be removed in the near future
*/
private final static int updaterVersion = 1;
@Deprecated
private static final int updaterVersion = 1;
private final static Set<PluginInfo> registeredPlugins = new HashSet<>();
private static final Set<PluginInfo> registeredPlugins = new HashSet<>();
private static SongodaCore INSTANCE = null;
private JavaPlugin piggybackedPlugin;
private CommandManager commandManager;
private EventListener loginListener;
@ -76,7 +85,7 @@ public class SongodaCore {
}
public static void registerPlugin(JavaPlugin plugin, int pluginID, CompatibleMaterial icon) {
registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name(), coreVersion);
registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name(), SongodaCoreConstants.getCoreVersion());
}
public static void registerPlugin(JavaPlugin plugin, int pluginID, String icon) {
@ -91,13 +100,23 @@ public class SongodaCore {
try {
// test to see if we're up-to-date
int otherVersion;
int ownVersion;
try {
otherVersion = (int) clazz.getMethod("getCoreVersion").invoke(null);
otherVersion = (int) clazz.getMethod("getCoreMajorVersion").invoke(null);
ownVersion = getCoreMajorVersion();
} catch (Exception ignore) {
otherVersion = -1;
try {
otherVersion = (int) clazz.getMethod("getCoreVersion").invoke(null);
} catch (Exception ignore2) {
otherVersion = -1;
}
ownVersion = getCoreVersion();
}
if (otherVersion >= getCoreVersion()) {
if (otherVersion >= ownVersion) {
// use the active service
// assuming that the other is greater than R6 if we get here ;)
clazz.getMethod("registerPlugin", JavaPlugin.class, int.class, String.class, String.class).invoke(null, plugin, pluginID, icon, coreVersion);
@ -221,6 +240,10 @@ public class SongodaCore {
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> update(info), 60L));
}
/**
* @deprecated Seems useless and will probably be replaced in the near future
*/
@Deprecated
private void update(PluginInfo plugin) {
try {
URL url = new URL("https://update.songoda.com/index.php?plugin=" + plugin.getSongodaId()
@ -266,20 +289,45 @@ public class SongodaCore {
return new ArrayList<>(registeredPlugins);
}
public static String getVersion() {
return SongodaCoreConstants.getCoreVersion();
}
/**
* @deprecated Use {@link #getCoreMajorVersion()} instead, but careful, coreRevision is at 9 while major version is at 2
*/
@Deprecated
public static int getCoreVersion() {
return coreRevision;
}
/**
* @deprecated Use {@link #getVersion()} instead
*/
@Deprecated
public static String getCoreLibraryVersion() {
return coreVersion;
return SongodaCoreConstants.getCoreVersion();
}
public static int getCoreMajorVersion() {
String fullVersion = getVersion();
if (fullVersion.contains(".")) {
return Integer.parseInt(fullVersion.substring(0, fullVersion.indexOf(".")));
}
return -1;
}
/**
* @deprecated Seems useless and will probably be removed in the near future
*/
@Deprecated
public static int getUpdaterVersion() {
return updaterVersion;
}
public static String getPrefix() {
return "[SongodaCore] ";
return "[" + SongodaCoreConstants.getProjectName() + "] ";
}
public static Logger getLogger() {

View File

@ -0,0 +1,26 @@
package com.songoda.core;
/**
* Some return values in this class are automatically replaced by a maven plugin after the project has been compiled.
* This allows for properties to be defined at one place without relying on a text file
* that needs to be inside the final jar (might get lost when this lib is shaded into other projects).
* <p>
* <b>!! Manually changing the values in this class has to be considered a breaking change. !!</b>
*/
public class SongodaCoreConstants {
private SongodaCoreConstants() {
throw new IllegalStateException("Utility class");
}
public static String getCoreVersion() {
return "UNKNOWN_VESION";
}
public static String getProjectName() {
return "SongodaCore";
}
public static String getGitHubProjectUrl() {
return "https://github.com/craftaro/SongodaCore";
}
}

View File

@ -8,7 +8,7 @@ import com.songoda.core.utils.SongodaAuth;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
@ -25,7 +25,6 @@ public abstract class SongodaPlugin extends JavaPlugin {
protected Config config = new Config(this);
protected long dataLoadDelay = 20L;
protected ConsoleCommandSender console = Bukkit.getConsoleSender();
private boolean emergencyStop = false;
static {
@ -91,6 +90,8 @@ public abstract class SongodaPlugin extends JavaPlugin {
return;
}
CommandSender console = Bukkit.getConsoleSender();
// Check plugin access, don't load plugin if user don't have access
if (!SongodaAuth.isAuthorized(true)) {
String pluginName = getDescription().getName();
@ -110,7 +111,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
ChatColor.YELLOW + "UUID: " + serverUuid + "\n" +
ChatColor.YELLOW + "IP: " + externalIP + "\n" +
ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
this.console.sendMessage(message);
console.sendMessage(message);
}).start();
emergencyStop();
@ -125,15 +126,19 @@ public abstract class SongodaPlugin extends JavaPlugin {
ChatColor.GREEN, "Enabling", ChatColor.GRAY));
try {
locale = Locale.loadDefaultLocale(this, "en_US");
this.locale = Locale.loadDefaultLocale(this, "en_US");
// plugin setup
onPluginEnable();
// Load Data.
Bukkit.getScheduler().runTaskLater(this, this::onDataLoad, dataLoadDelay);
if (this.emergencyStop) {
return;
}
if (emergencyStop) {
// Load Data.
Bukkit.getScheduler().runTaskLater(this, this::onDataLoad, this.dataLoadDelay);
if (this.emergencyStop) {
console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
console.sendMessage(" ");
return;
@ -156,10 +161,12 @@ public abstract class SongodaPlugin extends JavaPlugin {
@Override
public final void onDisable() {
if (emergencyStop) {
if (this.emergencyStop) {
return;
}
CommandSender console = Bukkit.getConsoleSender();
console.sendMessage(" "); // blank line to separate chatter
console.sendMessage(ChatColor.GREEN + "=============================");
console.sendMessage(String.format("%s%s %s by %sCraftaro <3!", ChatColor.GRAY,
@ -173,12 +180,8 @@ public abstract class SongodaPlugin extends JavaPlugin {
console.sendMessage(" "); // blank line to separate chatter
}
public ConsoleCommandSender getConsole() {
return console;
}
public Locale getLocale() {
return locale;
return this.locale;
}
/**
@ -191,13 +194,13 @@ public abstract class SongodaPlugin extends JavaPlugin {
* @return true if the locale exists and was loaded successfully
*/
public boolean setLocale(String localeName, boolean reload) {
if (locale != null && locale.getName().equals(localeName)) {
return !reload || locale.reloadMessages();
if (this.locale != null && this.locale.getName().equals(localeName)) {
return !reload || this.locale.reloadMessages();
}
Locale l = Locale.loadLocale(this, localeName);
if (l != null) {
locale = l;
this.locale = l;
return true;
}
@ -242,7 +245,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
}
protected void emergencyStop() {
emergencyStop = true;
this.emergencyStop = true;
Bukkit.getPluginManager().disablePlugin(this);
}
@ -255,10 +258,10 @@ public abstract class SongodaPlugin extends JavaPlugin {
protected void criticalErrorOnPluginStartup(Throwable th) {
Bukkit.getLogger().log(Level.SEVERE,
String.format(
"Unexpected error while loading %s v%s c%s: Disabling plugin!",
"Unexpected error while loading %s v%s (core v%s): Disabling plugin!",
getDescription().getName(),
getDescription().getVersion(),
SongodaCore.getCoreLibraryVersion()
SongodaCore.getVersion()
), th);
emergencyStop();

View File

@ -5,7 +5,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.songoda.core.compatibility.ClassMapping;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.Nms;
import com.songoda.core.utils.TextUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -13,7 +13,6 @@ import org.bukkit.entity.Player;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
@ -228,7 +227,7 @@ public class ChatMessage {
Object packet;
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_19)) {
packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)), mc_PacketPlayOutChat_new_1_19_0 ? 1 : false);
}else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) {
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) {
packet = mc_PacketPlayOutChat_new.newInstance(
mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)),
mc_chatMessageType_Chat.get(null),
@ -237,8 +236,8 @@ public class ChatMessage {
packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)));
}
NmsManager.getPlayer().sendPacket((Player) sender, packet);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Nms.getImplementations().getPlayer().sendPacket((Player) sender, packet);
} catch (ReflectiveOperationException | IllegalArgumentException ex) {
Bukkit.getLogger().log(Level.WARNING, "Problem preparing raw chat packets (disabling further packets)", ex);
enabled = false;
}

View File

@ -2,7 +2,7 @@ package com.songoda.core.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.methods.Clickable;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.Nms;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.anvil.CustomAnvil;
import org.bukkit.entity.Player;
@ -125,7 +125,7 @@ public class AnvilGui extends Gui {
@Override
protected void createInventory() {
AnvilCore nms = NmsManager.getAnvil();
AnvilCore nms = Nms.getImplementations().getAnvil();
if (nms != null) {
anvil = nms.createAnvil(player, new GuiHolder(guiManager, this));

View File

@ -1,19 +1,16 @@
package com.songoda.core.hooks.protection;
import com.plotsquared.core.PlotAPI;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class PlotSquaredProtection extends Protection {
PlotSquared plotSquared;
public PlotSquaredProtection(Plugin plugin) {
super(plugin);
plotSquared = PlotSquared.get();
}
@Override
@ -23,21 +20,51 @@ public class PlotSquaredProtection extends Protection {
@Override
public boolean isEnabled() {
return plotSquared != null;
return Bukkit.getPluginManager().isPluginEnabled("PlotSquared");
}
@Override
public boolean canPlace(Player player, Location location) {
return plotSquared.getPlotAreaManager().getApplicablePlotArea(com.plotsquared.core.location.Location.at(location.getWorld().getName(), (int) location.getX(), (int) location.getY(), (int) location.getZ())).getPlots().stream().anyMatch(p -> p.isAdded(player.getUniqueId()));
return isPlayerAddedAtPlotLocation(player, location);
}
@Override
public boolean canBreak(Player player, Location location) {
return plotSquared.getPlotAreaManager().getApplicablePlotArea(com.plotsquared.core.location.Location.at(location.getWorld().getName(), (int) location.getX(), (int) location.getY(), (int) location.getZ())).getPlots().stream().anyMatch(p -> p.isAdded(player.getUniqueId()));
return isPlayerAddedAtPlotLocation(player, location);
}
@Override
public boolean canInteract(Player player, Location location) {
return plotSquared.getPlotAreaManager().getApplicablePlotArea(com.plotsquared.core.location.Location.at(location.getWorld().getName(), (int) location.getX(), (int) location.getY(), (int) location.getZ())).getPlots().stream().anyMatch(p -> p.isAdded(player.getUniqueId()));
return isPlayerAddedAtPlotLocation(player, location);
}
private boolean isPlayerAddedAtPlotLocation(Player player, Location location) {
PlotArea plotArea = getApplicablePlotArea(location);
if (plotArea == null) {
return true;
}
for (Plot p : plotArea.getPlots()) {
if (p.isAdded(player.getUniqueId())) {
return true;
}
}
return false;
}
private PlotArea getApplicablePlotArea(Location location) {
return PlotSquared.get()
.getPlotAreaManager()
.getApplicablePlotArea(getPlotSquaredLocation(location));
}
private com.plotsquared.core.location.Location getPlotSquaredLocation(Location location) {
return com.plotsquared.core.location.Location.at(
location.getWorld().getName(),
(int) location.getX(),
(int) location.getY(),
(int) location.getZ()
);
}
}

View File

@ -0,0 +1,9 @@
package com.songoda.core.http;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public interface HttpClient {
@NotNull HttpResponse get(String url) throws IOException;
}

View File

@ -0,0 +1,11 @@
package com.songoda.core.http;
import java.io.IOException;
public interface HttpResponse {
int getResponseCode() throws IOException;
byte[] getBody() throws IOException;
String getBodyAsString() throws IOException;
}

View File

@ -0,0 +1,54 @@
package com.songoda.core.http;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
public class HttpResponseImpl implements HttpResponse, AutoCloseable {
protected final HttpURLConnection connection;
protected byte[] body;
HttpResponseImpl(HttpURLConnection connection) throws IOException {
this.connection = connection;
this.connection.connect();
}
public int getResponseCode() throws IOException {
int statusCode = this.connection.getResponseCode();
if (statusCode == -1) {
throw new IOException("HTTP Status Code is -1");
}
return statusCode;
}
public byte[] getBody() throws IOException {
if (this.body == null) {
try (InputStream in = this.connection.getInputStream();
InputStream err = this.connection.getErrorStream()) {
if (err != null) {
this.body = IOUtils.toByteArray(err);
} else {
this.body = IOUtils.toByteArray(in);
}
}
}
return this.body;
}
public String getBodyAsString() throws IOException {
return new String(getBody(), StandardCharsets.UTF_8);
}
@Override
public void close() throws Exception {
this.connection.disconnect();
}
}

View File

@ -0,0 +1,31 @@
package com.songoda.core.http;
import com.songoda.core.SongodaCoreConstants;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
public class SimpleHttpClient implements HttpClient {
private static final String USER_AGENT = generateUserAgent();
public @NotNull HttpResponse get(String url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setInstanceFollowRedirects(true);
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
connection.setRequestProperty("User-Agent", USER_AGENT);
return new HttpResponseImpl(connection);
}
private static String generateUserAgent() {
String projectName = SongodaCoreConstants.getProjectName();
String version = SongodaCoreConstants.getCoreVersion();
String projectUrl = SongodaCoreConstants.getGitHubProjectUrl();
return projectName + "/" + version + " (+" + projectUrl + ")";
}
}

View File

@ -0,0 +1,15 @@
package com.songoda.core.http;
import java.io.IOException;
public class UnexpectedHttpStatusException extends IOException {
public final int responseCode;
public final String url;
public UnexpectedHttpStatusException(int responseCode, String url) {
super("Got HTTP Status Code " + responseCode + ": " + url);
this.responseCode = responseCode;
this.url = url;
}
}

View File

@ -101,7 +101,10 @@ public class DropUtils {
Bukkit.getScheduler().runTask(SongodaCore.getHijackedPlugin(), () -> {
for (String command : commands) {
if (entity.getKiller() != null) {
command = command.replace("%player%", entity.getKiller().getName().replace("%x%", String.valueOf((int)entity.getLocation().getX())).replace("%y%", String.valueOf((int)entity.getLocation().getY())).replace("%z%", String.valueOf((int)entity.getLocation().getZ())));
command = command.replace("%player%", entity.getKiller().getName()
.replace("%x%", String.valueOf((int) entity.getLocation().getX()))
.replace("%y%", String.valueOf((int) entity.getLocation().getY()))
.replace("%z%", String.valueOf((int) entity.getLocation().getZ())));
}
if (!command.contains("%player%")) {

View File

@ -12,10 +12,10 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -166,7 +166,7 @@ public class LootManager {
try {
Gson gson = new Gson();
JsonReader reader = new JsonReader(new FileReader(file.getPath()));
JsonReader reader = new JsonReader(Files.newBufferedReader(file.toPath()));
Lootable lootable = gson.fromJson(reader, Lootable.class);
@ -195,7 +195,7 @@ public class LootManager {
continue;
}
try (Writer writer = new FileWriter(file.getPath())) {
try (Writer writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
gson.toJson(lootable, writer);
}

View File

@ -1,5 +1,7 @@
package com.songoda.core.math;
import com.songoda.core.SongodaCoreConstants;
import java.util.HashMap;
import java.util.Map;
@ -7,7 +9,7 @@ public class MathUtils {
private static final Map<String, Double> cache = new HashMap<>();
public static double eval(String toParse) {
return eval(toParse, "SongodaCore Eval Engine");
return eval(toParse, SongodaCoreConstants.getProjectName() + " Eval Engine");
}
public static double eval(String toParse, String warningMessage) {

View File

@ -0,0 +1,22 @@
package com.songoda.core.nms;
import com.songoda.core.compatibility.ServerVersion;
public class Nms {
protected static NmsImplementations impl;
/**
* @return The implementations for the current server version
*/
public static NmsImplementations getImplementations() throws UnsupportedServerVersionException {
if (impl == null) {
try {
impl = (NmsImplementations) Class.forName("com.songoda.core.nms." + ServerVersion.getServerVersionString() + ".NmsImplementationsImpl").getConstructors()[0].newInstance();
} catch (ReflectiveOperationException ex) {
throw new UnsupportedServerVersionException(ex);
}
}
return impl;
}
}

View File

@ -3,192 +3,51 @@ package com.songoda.core.nms;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.bukkit.Bukkit;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @deprecated Use {@link Nms} instead.
*/
@Deprecated
public class NmsManager {
private static final String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName();
private static final String serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
private static final String bukkitVersion = Bukkit.getServer().getBukkitVersion().split("-")[0];
private static final NMSPlayer player;
private static final AnvilCore anvil;
private static final NBTCore nbt;
private static final WorldCore world;
static {
switch (serverPackageVersion) {
case "v1_8_R1":
player = new com.songoda.core.nms.v1_8_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_8_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_8_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_8_R1.world.WorldCoreImpl();
break;
case "v1_8_R2":
player = new com.songoda.core.nms.v1_8_R2.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_8_R2.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_8_R2.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_8_R2.world.WorldCoreImpl();
break;
case "v1_8_R3":
player = new com.songoda.core.nms.v1_8_R3.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_8_R3.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_8_R3.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_8_R3.world.WorldCoreImpl();
break;
case "v1_9_R1":
player = new com.songoda.core.nms.v1_9_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_9_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_9_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_9_R1.world.WorldCoreImpl();
break;
case "v1_9_R2":
player = new com.songoda.core.nms.v1_9_R2.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_9_R2.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_9_R2.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_9_R2.world.WorldCoreImpl();
break;
case "v1_10_R1":
player = new com.songoda.core.nms.v1_10_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_10_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_10_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_10_R1.world.WorldCoreImpl();
break;
case "v1_11_R1":
player = new com.songoda.core.nms.v1_11_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_11_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_11_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_11_R1.world.WorldCoreImpl();
break;
case "v1_12_R1":
player = new com.songoda.core.nms.v1_12_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_12_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_12_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_12_R1.world.WorldCoreImpl();
break;
case "v1_13_R1":
player = new com.songoda.core.nms.v1_13_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_13_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_13_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_13_R1.world.WorldCoreImpl();
break;
case "v1_13_R2":
player = new com.songoda.core.nms.v1_13_R2.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_13_R2.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_13_R2.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_13_R2.world.WorldCoreImpl();
break;
case "v1_14_R1":
player = new com.songoda.core.nms.v1_14_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_14_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_14_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_14_R1.world.WorldCoreImpl();
break;
case "v1_15_R1":
player = new com.songoda.core.nms.v1_15_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_15_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_15_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_15_R1.world.WorldCoreImpl();
break;
case "v1_16_R1":
player = new com.songoda.core.nms.v1_16_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_16_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_16_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_16_R1.world.WorldCoreImpl();
break;
case "v1_16_R2":
player = new com.songoda.core.nms.v1_16_R2.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_16_R2.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_16_R2.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_16_R2.world.WorldCoreImpl();
break;
case "v1_16_R3":
player = new com.songoda.core.nms.v1_16_R3.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_16_R3.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_16_R3.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_16_R3.world.WorldCoreImpl();
break;
case "v1_17_R1":
player = new com.songoda.core.nms.v1_17_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_17_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_17_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_17_R1.world.WorldCoreImpl();
break;
case "v1_18_R1":
player = new com.songoda.core.nms.v1_18_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_18_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_18_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_18_R1.world.WorldCoreImpl();
break;
case "v1_18_R2":
player = new com.songoda.core.nms.v1_18_R2.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_18_R2.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_18_R2.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_18_R2.world.WorldCoreImpl();
break;
case "v1_19_R1":
if (bukkitVersion.endsWith(".0") || bukkitVersion.equals("1.19")) {
player = new com.songoda.core.nms.v1_19_R1.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_19_R1.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_19_R1.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_19_R1.world.WorldCoreImpl();
} else {
player = new com.songoda.core.nms.v1_19_R1v2.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_19_R1v2.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_19_R1v2.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_19_R1v2.world.WorldCoreImpl();
}
break;
case "v1_19_R2":
player = new com.songoda.core.nms.v1_19_R2.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_19_R2.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_19_R2.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_19_R2.world.WorldCoreImpl();
break;
case "v1_19_R3":
player = new com.songoda.core.nms.v1_19_R3.entity.NMSPlayerImpl();
anvil = new com.songoda.core.nms.v1_19_R3.anvil.AnvilCore();
nbt = new com.songoda.core.nms.v1_19_R3.nbt.NBTCoreImpl();
world = new com.songoda.core.nms.v1_19_R3.world.WorldCoreImpl();
break;
default:
Logger.getLogger(NmsManager.class.getName()).log(Level.SEVERE, "Failed to load NMS for this server version: version {0} not found", serverPackageVersion);
player = null;
anvil = null;
nbt = null;
world = null;
break;
}
}
@Deprecated
public static NMSPlayer getPlayer() {
return player;
return Nms.getImplementations().getPlayer();
}
@Deprecated
public static AnvilCore getAnvil() {
return anvil;
return Nms.getImplementations().getAnvil();
}
@Deprecated
public static boolean hasAnvil() {
return anvil != null;
return getAnvil() != null;
}
@Deprecated
public static NBTCore getNbt() {
return nbt;
return Nms.getImplementations().getNbt();
}
@Deprecated
public static boolean hasNbt() {
return nbt != null;
return getNbt() != null;
}
@Deprecated
public static WorldCore getWorld() {
return world;
return Nms.getImplementations().getWorld();
}
@Deprecated
public static boolean hasWorld() {
return world != null;
return getWorld() != null;
}
@Deprecated
public static NmsWorldBorder getWorldBorder() {
return Nms.getImplementations().getWorldBorder();
}
}

View File

@ -0,0 +1,17 @@
package com.songoda.core.nms;
import com.songoda.core.compatibility.ServerVersion;
public class UnsupportedServerVersionException extends RuntimeException {
public UnsupportedServerVersionException() {
this(null);
}
public UnsupportedServerVersionException(Throwable cause) {
this("Your sever version (" + ServerVersion.getServerVersionString() + "; " + ServerVersion.getServerVersion().name() + ") is not fully supported", null);
}
protected UnsupportedServerVersionException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -4,7 +4,6 @@ import com.songoda.core.compatibility.ClassMapping;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.MethodMapping;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.nms.NmsManager;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
@ -343,7 +342,8 @@ public class BlockUtils {
*
* @param loc The Location of the container
*
* @deprecated Broken in/since Spigot 1.19.4! Use {@link com.songoda.core.nms.world.WorldCore#updateAdjacentComparators(Block)} on {@link NmsManager#getWorld()} instead
* @deprecated Use {@link com.songoda.core.nms.world.WorldCore#updateAdjacentComparators(Block)}
* via {@link com.songoda.core.nms.Nms#getImplementations()} instead.
*/
@Deprecated
public static void updateAdjacentComparators(Location loc) {
@ -406,7 +406,11 @@ public class BlockUtils {
* <p>
* The chunk must be loaded and players must relog if they have the
* chunk loaded in order to use this method.
*
* @deprecated Use {@link com.songoda.core.nms.world.SWorld#setBlockFast(int, int, int, Material)}
* via {@link com.songoda.core.nms.Nms#getImplementations()} instead.
*/
@Deprecated
public static void setBlockFast(World world, int x, int y, int z, Material material, byte data) {
try {
// Cache reflection
@ -451,6 +455,11 @@ public class BlockUtils {
}
}
/**
* @deprecated Use {@link com.songoda.core.nms.world.SWorld#setBlockFast(int, int, int, Material)}
* via {@link com.songoda.core.nms.Nms#getImplementations()} instead.
*/
@Deprecated
public static void setBlockFast(World world, int x, int y, int z, CompatibleMaterial material, byte data) {
setBlockFast(world, x, y, z, material.getBlockMaterial(), data);
}
@ -476,8 +485,7 @@ public class BlockUtils {
return false;
}
return block.getData() >= (mat == CompatibleMaterial.BEETROOTS
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
return block.getData() >= (mat == CompatibleMaterial.BEETROOTS || mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
}
/**
@ -526,8 +534,7 @@ public class BlockUtils {
return -1;
}
return (mat == CompatibleMaterial.BEETROOTS
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
return (mat == CompatibleMaterial.BEETROOTS || mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
}
/**

View File

@ -3,7 +3,7 @@ package com.songoda.core.world;
import com.songoda.core.compatibility.CompatibleHand;
import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.Nms;
import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@ -18,12 +18,12 @@ public class SItemStack {
public SItemStack(ItemStack item) {
this.item = item;
this.sItem = NmsManager.getWorld().getItemStack(item);
this.sItem = Nms.getImplementations().getWorld().getItemStack(item);
}
public SItemStack(CompatibleHand hand, Player player) {
this.item = hand.getItem(player);
this.sItem = NmsManager.getWorld().getItemStack(item);
this.sItem = Nms.getImplementations().getWorld().getItemStack(item);
}
public ItemStack addDamage(Player player, int damage) {
@ -49,7 +49,7 @@ public class SItemStack {
int durability;
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11)
? NmsManager.getNbt().of(item).has("Unbreakable")
? Nms.getImplementations().getNbt().of(item).has("Unbreakable")
: item.getItemMeta().isUnbreakable()) {
return item;
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {

View File

@ -2,7 +2,7 @@ package com.songoda.core.world;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.hooks.EntityStackerManager;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.Nms;
import com.songoda.core.nms.world.SpawnedEntity;
import com.songoda.core.utils.EntityUtils;
import org.bukkit.Location;
@ -20,7 +20,7 @@ public class SSpawner {
public SSpawner(Location location) {
this.location = location;
this.sSpawner = NmsManager.getWorld().getSpawner(location);
this.sSpawner = Nms.getImplementations().getWorld().getSpawner(location);
}
public SSpawner(CreatureSpawner spawner) {

View File

@ -1,7 +1,7 @@
package com.songoda.core.world;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.Nms;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
@ -15,7 +15,7 @@ public class SWorld {
public SWorld(World world) {
this.world = world;
this.sWorld = NmsManager.getWorld().getWorld(world);
this.sWorld = Nms.getImplementations().getWorld().getWorld(world);
}
public Entity[] getEntitiesFromChunk(int x, int z) {

View File

@ -3,7 +3,7 @@ package com.songoda.core.world;
import com.songoda.core.compatibility.ClassMapping;
import com.songoda.core.compatibility.MethodMapping;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.Nms;
import com.songoda.core.utils.NMSUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -12,6 +12,10 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* @deprecated Use {@link com.songoda.core.nms.world.NmsWorldBorder} via {@link Nms#getImplementations()} instead.
*/
@Deprecated
public class SWorldBorder {
private static Class<?> packetPlayOutWorldBorderEnumClass;
private static Class<?> worldBorderClass;
@ -81,18 +85,22 @@ public class SWorldBorder {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17)) {
Object packet = clientboundInitializeBorderPacketConstructor.newInstance(worldBorder);
NmsManager.getPlayer().sendPacket(player, packet);
Nms.getImplementations().getPlayer().sendPacket(player, packet);
} else {
@SuppressWarnings({"unchecked", "rawtypes"})
Object packet = packetPlayOutWorldBorderConstructor.newInstance(worldBorder,
Enum.valueOf((Class<? extends Enum>) packetPlayOutWorldBorderEnumClass, "INITIALIZE"));
NmsManager.getPlayer().sendPacket(player, packet);
Nms.getImplementations().getPlayer().sendPacket(player, packet);
}
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException ex) {
ex.printStackTrace();
}
}
/**
* @deprecated Use {@link com.songoda.core.nms.world.NmsWorldBorder.BorderColor} instead.
*/
@Deprecated
public enum Color {
Blue, Green, Red
}

View File

@ -0,0 +1,36 @@
package com.songoda.core;
import org.junit.jupiter.api.Test;
import org.opentest4j.TestSkippedException;
import java.util.Objects;
import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SongodaCoreConstantsTest {
// Pattern is from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
private static final Pattern VERSION_PATTERN = Pattern.compile("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
@Test
void getCoreVersion() {
if (!Objects.equals(System.getenv("TESTS_RUN_WITH_MAVEN"), "true")) {
throw new TestSkippedException("Skipping test because it requires the TESTS_RUN_WITH_MAVEN environment variable to be set to true");
}
String coreVersion = SongodaCoreConstants.getCoreVersion();
assertTrue(VERSION_PATTERN.matcher(coreVersion).matches(), "Version string is not a valid semver string: " + coreVersion);
}
@Test
void getProjectName() {
assertFalse(SongodaCoreConstants.getProjectName().isEmpty());
}
@Test
void getGitHubProjectUrl() {
assertFalse(SongodaCoreConstants.getGitHubProjectUrl().isEmpty());
}
}

View File

@ -1,86 +0,0 @@
package com.songoda.core.compatibility.material;
import be.seeseemelk.mockbukkit.MockBukkit;
import com.songoda.core.compatibility.CompatibleMaterial;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
class CompatibleMaterialTest {
@BeforeEach
void setUp() {
MockBukkit.mock();
}
@AfterEach
void tearDown() {
MockBukkit.unmock();
}
@Test
void getMaterialForNull() {
assertNull(CompatibleMaterial.getMaterial((Material) null));
assertNull(CompatibleMaterial.getMaterial((ItemStack) null));
}
@Test
void getMaterialForAllBukkitMaterials() {
Map<CompatibleMaterial, Material> returnedMaterials = new HashMap<>(Material.values().length);
for (Material bukkitMaterial : Material.values()) {
CompatibleMaterial compatibleMaterial = CompatibleMaterial.getMaterial(bukkitMaterial);
if (bukkitMaterial.name().startsWith("LEGACY_")) {
assertNull(compatibleMaterial);
continue;
}
assertNotNull(compatibleMaterial, () -> "Could not get an CompatibleMaterial for Material." + bukkitMaterial.name());
assertEquals(bukkitMaterial, compatibleMaterial.getMaterial());
assertEquals(compatibleMaterial, CompatibleMaterial.getMaterial(bukkitMaterial.name()));
assertFalse(returnedMaterials.containsKey(compatibleMaterial),
() -> String.format("Assertion failed when converting Material.%s to CompatibleMaterial.%s: " +
"CompatibleMaterial.%1$s has already been returned for Material.%3$s previously",
bukkitMaterial.name(),
compatibleMaterial.name(),
returnedMaterials.get(compatibleMaterial).name()
));
assertEquals(bukkitMaterial.isAir(), compatibleMaterial.isAir(), getMaterialPropertyAssertionError(compatibleMaterial, "Air"));
assertEquals(bukkitMaterial.isBlock(), compatibleMaterial.isBlock(), getMaterialPropertyAssertionError(compatibleMaterial, "Block"));
assertEquals(bukkitMaterial.isBurnable(), compatibleMaterial.isBurnable(), getMaterialPropertyAssertionError(compatibleMaterial, "Burnable"));
assertEquals(bukkitMaterial.isEdible(), compatibleMaterial.isEdible(), getMaterialPropertyAssertionError(compatibleMaterial, "Edible"));
assertEquals(bukkitMaterial.isFlammable(), compatibleMaterial.isFlammable(), getMaterialPropertyAssertionError(compatibleMaterial, "Flammable"));
assertEquals(bukkitMaterial.isFuel(), compatibleMaterial.isFuel(), getMaterialPropertyAssertionError(compatibleMaterial, "Fuel"));
assertEquals(bukkitMaterial.isInteractable(), compatibleMaterial.isInteractable(), getMaterialPropertyAssertionError(compatibleMaterial, "Interactable"));
assertEquals(bukkitMaterial.isItem(), compatibleMaterial.isItem(), getMaterialPropertyAssertionError(compatibleMaterial, "Item"));
assertEquals(bukkitMaterial.isOccluding(), compatibleMaterial.isOccluding(), getMaterialPropertyAssertionError(compatibleMaterial, "Occluding"));
assertEquals(bukkitMaterial.isSolid(), compatibleMaterial.isSolid(), getMaterialPropertyAssertionError(compatibleMaterial, "Solid"));
assertEquals(bukkitMaterial.isTransparent(), compatibleMaterial.isTransparent(), getMaterialPropertyAssertionError(compatibleMaterial, "Transparent"));
assertFalse(compatibleMaterial.usesCompatibility());
assertFalse(compatibleMaterial.usesData());
assertEquals(-1, compatibleMaterial.getData());
ItemStack compatibleItem = compatibleMaterial.getItem();
assertEquals(bukkitMaterial, compatibleItem.getType());
assertEquals(compatibleMaterial, CompatibleMaterial.getMaterial(compatibleItem));
returnedMaterials.put(compatibleMaterial, bukkitMaterial);
}
}
private Supplier<String> getMaterialPropertyAssertionError(CompatibleMaterial compatibleMaterial, String propertyName) {
return () -> String.format("Expected CompatibleMaterial.%s to be '%s'", compatibleMaterial.name(), propertyName);
}
}

View File

@ -0,0 +1,22 @@
package com.songoda.core.http;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedList;
import java.util.List;
public class MockHttpClient implements HttpClient {
public HttpResponse returnValue;
public List<String> callsOnGet = new LinkedList<>();
public MockHttpClient(HttpResponse returnValue) {
this.returnValue = returnValue;
}
@Override
public @NotNull HttpResponse get(String url) {
this.callsOnGet.add(url);
return this.returnValue;
}
}

View File

@ -0,0 +1,25 @@
package com.songoda.core.http;
import java.nio.charset.StandardCharsets;
public class MockHttpResponse implements HttpResponse {
public int responseCode;
public byte[] body;
public MockHttpResponse(int responseCode, byte[] body) {
this.responseCode = responseCode;
this.body = body;
}
public int getResponseCode() {
return this.responseCode;
}
public byte[] getBody() {
return this.body;
}
public String getBodyAsString() {
return new String(getBody(), StandardCharsets.UTF_8);
}
}

View File

@ -1,127 +0,0 @@
package com.songoda.core.input;
import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.MockPlugin;
import be.seeseemelk.mockbukkit.ServerMock;
import be.seeseemelk.mockbukkit.entity.PlayerMock;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Disabled("BukkitMock seems to cause some troubles here, skipping for now")
class ChatPromptTest {
private final String inputMsg = "&eInput-Message";
private ServerMock server;
private MockPlugin plugin;
private PlayerMock player;
@BeforeEach
void setUp() {
this.server = MockBukkit.mock();
this.plugin = MockBukkit.createMockPlugin();
this.player = this.server.addPlayer();
}
@AfterEach
void tearDown() {
MockBukkit.unmock();
}
@Test
void showPrompt() throws InterruptedException {
List<String> chatInputs = new ArrayList<>(1);
ChatPrompt.showPrompt(this.plugin, this.player, event -> {
assertEquals(this.player, event.getPlayer());
chatInputs.add(event.getMessage());
});
this.player.chat(this.inputMsg);
Thread.sleep(1000);
// this.server.getScheduler().waitAsyncTasksFinished() // does not wait for async events
String playerReceivedMsg = this.player.nextMessage();
assertNotNull(playerReceivedMsg);
assertTrue(playerReceivedMsg.endsWith(this.inputMsg));
assertEquals(1, chatInputs.size());
assertEquals(this.inputMsg, chatInputs.get(0));
}
/* FIXME: Something is still running in the background and prevents the test from finishing */
@Disabled("Scheduling mock seems bugged, skipping for now")
@Test
void showPromptWithTimeout() {
AtomicBoolean calledOnClose = new AtomicBoolean(false);
ChatPrompt.showPrompt(this.plugin, this.player, event -> {
})
.setOnClose(() -> calledOnClose.set(true))
.setTimeOut(this.player, 40);
this.server.getScheduler().performTicks(40);
String playerReceivedMsg = this.player.nextMessage();
assertNotNull(playerReceivedMsg);
assertTrue(playerReceivedMsg.contains("timed out"));
this.server.getScheduler().performOneTick();
assertTrue(calledOnClose.get());
}
@Test
void cancelPrompt() {
AtomicBoolean calledOnCancel = new AtomicBoolean(false);
AtomicBoolean calledHandler = new AtomicBoolean(false);
ChatPrompt prompt = ChatPrompt.showPrompt(plugin, player, (event) -> calledHandler.set(true));
prompt.setOnCancel(() -> calledOnCancel.set(true));
this.server.dispatchCommand(player, "cancel");
// this.player.chat("/cancel");
// Thread.sleep(1000);
// this.server.getScheduler().waitAsyncTasksFinished() // does not wait for async events
System.out.println(this.player.nextMessage());
// assertTrue(player.nextMessage().endsWith("/cancel"));
assertTrue(calledOnCancel.get());
assertFalse(calledHandler.get());
}
@Test
void isRegistered() {
assertFalse(ChatPrompt.isRegistered(this.player));
ChatPrompt.showPrompt(this.plugin, this.player, (event) -> {
});
assertTrue(ChatPrompt.isRegistered(this.player));
}
@Test
void unregister() {
assertFalse(ChatPrompt.unregister(this.player));
ChatPrompt.showPrompt(this.plugin, this.player, (event) -> {
});
assertTrue(ChatPrompt.unregister(this.player));
assertFalse(ChatPrompt.unregister(this.player));
}
}

View File

@ -2,16 +2,19 @@ package com.songoda.core.math;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
class MathUtilsTest {
private final String warningMessage = "MathTest";
private final String warningMessageExpectedStart = warningMessage + " ";
private final String warningMessageExpectedStart = this.warningMessage + " ";
@Test
void eval() {
assertEquals(0, MathUtils.eval("0"));
assertEquals(10, MathUtils.eval("10"));
assertEquals(0.0, MathUtils.eval("0.0"));
assertEquals(10.5, MathUtils.eval("10.5"));
assertEquals(10.5 + 4, MathUtils.eval("10.5 + 4"));
assertEquals(10.5 - 5, MathUtils.eval("10.5 - 5"));
assertEquals(10 * 4, MathUtils.eval("10 * 4"));
@ -33,28 +36,28 @@ class MathUtilsTest {
@Test
void evalWithCommaAsDecimalSeparator() {
Exception ex = assertThrowsExactly(RuntimeException.class, () -> MathUtils.eval("1,0", warningMessage));
Exception ex = assertThrowsExactly(RuntimeException.class, () -> MathUtils.eval("1,0", this.warningMessage));
assertTrue(ex.getMessage().startsWith(warningMessageExpectedStart),
() -> "'" + ex.getMessage() + "' does not start with '" + warningMessageExpectedStart + "'");
assertTrue(ex.getMessage().startsWith(this.warningMessageExpectedStart),
() -> "'" + ex.getMessage() + "' does not start with '" + this.warningMessageExpectedStart + "'");
assertTrue(ex.getMessage().contains("Unexpected: "));
}
@Test
void evalWithUnsupportedSyntax() {
Exception ex = assertThrowsExactly(RuntimeException.class, () -> MathUtils.eval("!2", warningMessage));
Exception ex = assertThrowsExactly(RuntimeException.class, () -> MathUtils.eval("!2", this.warningMessage));
assertTrue(ex.getMessage().startsWith(warningMessageExpectedStart),
() -> "'" + ex.getMessage() + "' does not start with '" + warningMessageExpectedStart + "'");
assertTrue(ex.getMessage().startsWith(this.warningMessageExpectedStart),
() -> "'" + ex.getMessage() + "' does not start with '" + this.warningMessageExpectedStart + "'");
assertTrue(ex.getMessage().contains("Unexpected: "));
}
@Test
void evalWithUnsupportedFunction() {
Exception ex = assertThrowsExactly(RuntimeException.class, () -> MathUtils.eval("acos(90)", warningMessage));
Exception ex = assertThrowsExactly(RuntimeException.class, () -> MathUtils.eval("acos(90)", this.warningMessage));
assertTrue(ex.getMessage().startsWith(warningMessageExpectedStart),
() -> "'" + ex.getMessage() + "' does not start with '" + warningMessageExpectedStart + "'");
assertTrue(ex.getMessage().startsWith(this.warningMessageExpectedStart),
() -> "'" + ex.getMessage() + "' does not start with '" + this.warningMessageExpectedStart + "'");
assertTrue(ex.getMessage().contains("Unknown function: "));
}
}

View File

@ -1,9 +1,10 @@
package com.songoda.core.utils;
import be.seeseemelk.mockbukkit.WorldMock;
import org.bukkit.Location;
import org.bukkit.World;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -13,12 +14,20 @@ class LocationUtilsTest {
void isLocationMatching() {
assertTrue(LocationUtils.isLocationMatching(
new Location(null, 10, 20, 30),
new Location(new WorldMock(), 10.25, 20.5, 30.75)
new Location(Mockito.mock(World.class), 10.25, 20.5, 30.75)
));
assertTrue(LocationUtils.isLocationMatching(
new Location(null, 10, 20, 30),
new Location(null, 10.25, 20.5, 30.75)
));
assertFalse(LocationUtils.isLocationMatching(
new Location(null, 10, 20, 30),
new Location(new WorldMock(), -10.25, 20.5, 30.75)
new Location(Mockito.mock(World.class), -10.25, 20.5, 30.75)
));
assertFalse(LocationUtils.isLocationMatching(
new Location(Mockito.mock(World.class), 10, 20, 30),
new Location(null, -10.25, 20.5, 30.75)
));
}

View File

@ -1,134 +1,143 @@
package com.songoda.core.utils;
import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
import be.seeseemelk.mockbukkit.entity.PlayerMock;
import org.bukkit.Material;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.bukkit.inventory.PlayerInventory;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
class PlayerUtilsTest {
private ServerMock server;
@Test
void sendMessages_Array() {
Player player = Mockito.mock(Player.class);
PlayerUtils.sendMessages(player, "First message", "Second message");
@BeforeEach
void setUp() {
this.server = MockBukkit.mock();
}
@AfterEach
void tearDown() {
MockBukkit.unmock();
this.server = null;
InOrder playerInOrder = Mockito.inOrder(player);
playerInOrder.verify(player).sendMessage("First message");
playerInOrder.verify(player).sendMessage("Second message");
playerInOrder.verify(player, Mockito.never()).sendMessage(Mockito.anyString());
}
@Test
void sendMessages() {
String[] messages = new String[] {"First message", "Second message"};
void sendMessages_List() {
Player player = Mockito.mock(Player.class);
PlayerUtils.sendMessages(player, Arrays.asList("First message", "Second message"));
PlayerMock player = this.server.addPlayer();
PlayerUtils.sendMessages(player, messages);
PlayerUtils.sendMessages(player, Arrays.asList(messages));
for (int i = 0; i < 2; ++i) {
assertEquals(messages[0], player.nextMessage());
assertEquals(messages[1], player.nextMessage());
}
assertNull(player.nextMessage());
InOrder playerInOrder = Mockito.inOrder(player);
playerInOrder.verify(player).sendMessage("First message");
playerInOrder.verify(player).sendMessage("Second message");
playerInOrder.verify(player, Mockito.never()).sendMessage(Mockito.anyString());
}
@Disabled("Player#hidePlayer can currently not be mocked")
@Test
void getVisiblePlayerNames() {
PlayerMock player = this.server.addPlayer("BasePlayer");
PlayerMock visiblePlayer = this.server.addPlayer("VisiblePlayer");
PlayerMock hiddenPlayer = this.server.addPlayer("HiddenPlayer");
Player player = createMockPlayer("BasePlayer");
Player visiblePlayer = createMockPlayer("VisiblePlayer");
Player hiddenPlayer = createMockPlayer("HiddenPlayer");
player.hidePlayer(MockBukkit.createMockPlugin(), hiddenPlayer);
List<String> result;
try (MockedStatic<Bukkit> server = Mockito.mockStatic(Bukkit.class)) {
server.when(Bukkit::getOnlinePlayers).thenReturn(Arrays.asList(player, visiblePlayer, hiddenPlayer));
List<String> result = PlayerUtils.getVisiblePlayerNames(player, null);
assertTrue(result.contains(visiblePlayer.getName()));
assertFalse(result.contains(hiddenPlayer.getName()));
assertFalse(result.contains(player.getName()));
Mockito.when(player.canSee(hiddenPlayer)).thenReturn(false);
Mockito.when(player.canSee(visiblePlayer)).thenReturn(true);
assertEquals(0, PlayerUtils.getVisiblePlayerNames(player, "_").size());
assertEquals(0, PlayerUtils.getVisiblePlayerNames(player, "_").size());
result = PlayerUtils.getVisiblePlayerNames(player, null);
}
assertTrue(result.contains("VisiblePlayer"));
assertEquals(1, result.size());
}
@Disabled("Player#hidePlayer can currently not be mocked")
@Test
void getVisiblePlayerDisplayNames() {
PlayerMock player = this.server.addPlayer("BasePlayer");
PlayerMock visiblePlayer = this.server.addPlayer("VisiblePlayer");
PlayerMock hiddenPlayer = this.server.addPlayer("HiddenPlayer");
Player player = createMockPlayer("BasePlayer");
Player visiblePlayer = createMockPlayer("VisiblePlayer", "VisibleDisplayName");
Player hiddenPlayer = createMockPlayer("HiddenPlayer");
player.setDisplayName("Base");
visiblePlayer.setDisplayName("Visible");
hiddenPlayer.setDisplayName("Hidden");
List<String> result;
try (MockedStatic<Bukkit> server = Mockito.mockStatic(Bukkit.class)) {
server.when(Bukkit::getOnlinePlayers).thenReturn(Arrays.asList(player, visiblePlayer, hiddenPlayer));
player.hidePlayer(MockBukkit.createMockPlugin(), hiddenPlayer);
Mockito.when(player.canSee(hiddenPlayer)).thenReturn(false);
Mockito.when(player.canSee(visiblePlayer)).thenReturn(true);
List<String> result = PlayerUtils.getVisiblePlayerDisplayNames(player, null);
assertTrue(result.contains(visiblePlayer.getDisplayName()));
assertFalse(result.contains(hiddenPlayer.getDisplayName()));
assertFalse(result.contains(player.getDisplayName()));
assertEquals(0, PlayerUtils.getVisiblePlayerDisplayNames(player, "A").size());
assertEquals(0, PlayerUtils.getVisiblePlayerDisplayNames(player, "_").size());
result = PlayerUtils.getVisiblePlayerDisplayNames(player, null);
}
assertTrue(result.contains("VisibleDisplayName"));
assertEquals(1, result.size());
}
@Disabled("Player#hidePlayer can currently not be mocked")
@Test
void getVisiblePlayers() {
PlayerMock player = this.server.addPlayer("BasePlayer");
PlayerMock visiblePlayer = this.server.addPlayer("VisiblePlayer");
PlayerMock hiddenPlayer = this.server.addPlayer("HiddenPlayer");
Player player = createMockPlayer("BasePlayer");
Player visiblePlayer = createMockPlayer("VisiblePlayer");
Player hiddenPlayer = createMockPlayer("HiddenPlayer");
player.hidePlayer(MockBukkit.createMockPlugin(), hiddenPlayer);
Mockito.when(player.canSee(hiddenPlayer)).thenReturn(false);
Mockito.when(player.canSee(visiblePlayer)).thenReturn(true);
List<Player> result;
try (MockedStatic<Bukkit> server = Mockito.mockStatic(Bukkit.class)) {
server.when(Bukkit::getOnlinePlayers).thenReturn(Arrays.asList(player, visiblePlayer, hiddenPlayer));
assertEquals(0, PlayerUtils.getVisiblePlayers(player, "_").size());
result = PlayerUtils.getVisiblePlayers(player, null);
}
List<Player> result = PlayerUtils.getVisiblePlayers(player, null);
assertTrue(result.contains(visiblePlayer));
assertFalse(result.contains(hiddenPlayer));
assertFalse(result.contains(player));
assertEquals(0, PlayerUtils.getVisiblePlayers(player, "_").size());
assertEquals(1, result.size());
}
@Test
void getAllPlayers() {
PlayerMock basePlayer = this.server.addPlayer("BasePlayer");
this.server.addPlayer("Player_1");
this.server.addPlayer("Player_2");
this.server.addPlayer("Player3");
Player basePlayer = createMockPlayer("BasePlayer");
Player player1 = createMockPlayer("Player_1");
Player player2 = createMockPlayer("Player_2");
Player player3 = createMockPlayer("Player3");
List<String> result = PlayerUtils.getAllPlayers(basePlayer, "");
assertEquals(3, result.size());
assertFalse(result.contains(basePlayer.getName()));
try (MockedStatic<Bukkit> server = Mockito.mockStatic(Bukkit.class)) {
server.when(Bukkit::getOnlinePlayers).thenReturn(Arrays.asList(basePlayer, player1, player2, player3));
assertTrue(PlayerUtils.getAllPlayers(basePlayer, "_").isEmpty());
assertEquals(0, PlayerUtils.getAllPlayers(basePlayer, "Player_").size());
assertEquals(0, PlayerUtils.getVisiblePlayers(basePlayer, "_").size());
List<String> result = PlayerUtils.getAllPlayers(basePlayer, "");
assertFalse(result.contains(basePlayer.getName()));
assertEquals(3, result.size());
assertEquals(0, PlayerUtils.getAllPlayers(basePlayer, "_").size());
assertEquals(0, PlayerUtils.getAllPlayers(basePlayer, "Player_").size());
}
}
@Disabled("Disabled for now as the implementations seems to be faulty")
@Test
void getAllPlayersDisplay() {
PlayerMock basePlayer = this.server.addPlayer("BasePlayer");
this.server.addPlayer("Player_1");
this.server.addPlayer("Player_2");
this.server.addPlayer("Player3");
Player basePlayer = createMockPlayer("BasePlayer");
createMockPlayer("Player_1");
createMockPlayer("Player_2");
createMockPlayer("Player3");
List<String> result = PlayerUtils.getAllPlayersDisplay(basePlayer, "");
assertEquals(3, result.size());
@ -141,13 +150,9 @@ class PlayerUtilsTest {
@Disabled("Disabled for now as the implementations seems to be faulty")
@Test
void findPlayer() {
Player p3 = this.server.addPlayer("Player");
Player p1 = this.server.addPlayer("Player_1");
Player p2 = this.server.addPlayer("_Player_2");
p1.setDisplayName("p1");
p2.setDisplayName("p2");
p3.setDisplayName("p3");
Player p3 = createMockPlayer("Player", "p3");
Player p1 = createMockPlayer("Player_1", "p1");
Player p2 = createMockPlayer("_Player_2", "p2");
assertEquals(p1, PlayerUtils.findPlayer("Player_"));
assertEquals(p2, PlayerUtils.findPlayer("_Play"));
@ -160,73 +165,185 @@ class PlayerUtilsTest {
}
@Test
void getRandomPlayer() {
assertNull(PlayerUtils.getRandomPlayer());
for (int i = 0; i < 10; ++i) {
this.server.addPlayer(String.valueOf(i));
void getRandomPlayer_NoneOnline() {
try (MockedStatic<Bukkit> server = Mockito.mockStatic(Bukkit.class)) {
server.when(Bukkit::getOnlinePlayers).thenReturn(Collections.emptyList());
assertNull(PlayerUtils.getRandomPlayer());
}
}
Set<Player> returnedPlayers = new HashSet<>();
for (int i = 0; i < 50; ++i) {
if (returnedPlayers.size() >= 5) {
break;
@Test
void getRandomPlayer() {
try (MockedStatic<Bukkit> server = Mockito.mockStatic(Bukkit.class)) {
List<Player> players = new ArrayList<>(10);
for (int i = 0; i < 10; ++i) {
Player player = createMockPlayer("Player_" + i);
players.add(player);
}
returnedPlayers.add(PlayerUtils.getRandomPlayer());
}
server.when(Bukkit::getOnlinePlayers).thenReturn(players);
assertTrue(returnedPlayers.size() >= 5);
Set<Player> returnedPlayers = new HashSet<>();
for (int i = 0; i < 50; ++i) {
if (returnedPlayers.size() >= 5) {
break;
}
returnedPlayers.add(PlayerUtils.getRandomPlayer());
}
assertTrue(returnedPlayers.size() >= 5);
}
}
@Test
void giveItem() {
Player player = this.server.addPlayer();
PlayerInventory inventory = Mockito.mock(PlayerInventory.class);
InOrder inventoryInOrder = Mockito.inOrder(inventory);
PlayerUtils.giveItem(player, new ItemStack(Material.STONE));
assertTrue(player.getInventory().contains(Material.STONE, 1));
Player player = createMockPlayer("Player");
Mockito.when(player.getInventory()).thenReturn(inventory);
Mockito.when(player.isOnline()).thenReturn(true);
PlayerUtils.giveItem(player, new ItemStack(Material.GRASS_BLOCK), new ItemStack(Material.GRASS_BLOCK));
assertTrue(player.getInventory().contains(Material.GRASS_BLOCK, 2));
ItemStack itemToAdd = Mockito.mock(ItemStack.class);
PlayerUtils.giveItem(player, Arrays.asList(new ItemStack(Material.WHEAT_SEEDS), new ItemStack(Material.WHEAT_SEEDS)));
assertTrue(player.getInventory().contains(Material.WHEAT_SEEDS, 2));
PlayerUtils.giveItem(player, itemToAdd);
inventoryInOrder.verify(inventory).addItem(itemToAdd);
inventoryInOrder.verify(inventory, Mockito.never()).addItem(Mockito.any());
}
@Test
void giveItemOnFullInventory() {
PlayerMock player = this.server.addPlayer();
void giveItem_Array() {
PlayerInventory inventory = Mockito.mock(PlayerInventory.class);
InOrder inventoryInOrder = Mockito.inOrder(inventory);
fillInventory(player);
Player player = createMockPlayer("Player");
Mockito.when(player.getInventory()).thenReturn(inventory);
Mockito.when(player.isOnline()).thenReturn(true);
int entityCount = this.server.getEntities().size();
PlayerUtils.giveItem(player, new ItemStack(Material.STONE));
assertEquals(entityCount + 1, this.server.getEntities().size());
ItemStack[] itemsToAdd = new ItemStack[] {Mockito.mock(ItemStack.class), Mockito.mock(ItemStack.class)};
entityCount = this.server.getEntities().size();
PlayerUtils.giveItem(player, new ItemStack(Material.GRASS_BLOCK), new ItemStack(Material.GRASS_BLOCK));
assertEquals(entityCount + 2, this.server.getEntities().size());
PlayerUtils.giveItem(player, itemsToAdd);
inventoryInOrder.verify(inventory).addItem(itemsToAdd);
inventoryInOrder.verify(inventory, Mockito.never()).addItem(Mockito.any());
}
entityCount = this.server.getEntities().size();
PlayerUtils.giveItem(player, Arrays.asList(new ItemStack(Material.WHEAT_SEEDS), new ItemStack(Material.WHEAT_SEEDS), new ItemStack(Material.WHEAT_SEEDS)));
assertEquals(entityCount + 3, this.server.getEntities().size());
@Test
void giveItem_List() {
PlayerInventory inventory = Mockito.mock(PlayerInventory.class);
InOrder inventoryInOrder = Mockito.inOrder(inventory);
Player player = createMockPlayer("Player");
Mockito.when(player.getInventory()).thenReturn(inventory);
Mockito.when(player.isOnline()).thenReturn(true);
ItemStack[] itemsToAdd = new ItemStack[] {Mockito.mock(ItemStack.class), Mockito.mock(ItemStack.class)};
PlayerUtils.giveItem(player, Arrays.asList(itemsToAdd));
inventoryInOrder.verify(inventory).addItem(itemsToAdd);
inventoryInOrder.verify(inventory, Mockito.never()).addItem(Mockito.any());
}
@Test
void giveItem_FullInventory() {
ItemStack itemToAdd = Mockito.mock(ItemStack.class);
PlayerInventory inventory = Mockito.mock(PlayerInventory.class);
Mockito.when(inventory.addItem(itemToAdd)).thenReturn(new HashMap<Integer, ItemStack>() {{
put(0, itemToAdd);
}});
InOrder inventoryInOrder = Mockito.inOrder(inventory);
Player player = createMockPlayer("Player");
Mockito.when(player.getInventory()).thenReturn(inventory);
Mockito.when(player.isOnline()).thenReturn(true);
World world = Mockito.mock(World.class);
InOrder worldInOrder = Mockito.inOrder(world);
Mockito.when(player.getWorld()).thenReturn(world);
PlayerUtils.giveItem(player, itemToAdd);
inventoryInOrder.verify(inventory).addItem(itemToAdd);
inventoryInOrder.verify(inventory, Mockito.never()).addItem(Mockito.any());
worldInOrder.verify(world).dropItemNaturally(Mockito.any(), Mockito.eq(itemToAdd));
worldInOrder.verify(world, Mockito.never()).dropItemNaturally(Mockito.any(), Mockito.any());
}
@Test
void giveItem_FullInventory_Array() {
ItemStack[] itemsToAdd = new ItemStack[] {Mockito.mock(ItemStack.class), Mockito.mock(ItemStack.class)};
PlayerInventory inventory = Mockito.mock(PlayerInventory.class);
Mockito.when(inventory.addItem(Mockito.any())).thenReturn(new HashMap<Integer, ItemStack>() {{
put(0, itemsToAdd[0]);
put(1, itemsToAdd[1]);
}});
InOrder inventoryInOrder = Mockito.inOrder(inventory);
Player player = createMockPlayer("Player");
Mockito.when(player.getInventory()).thenReturn(inventory);
Mockito.when(player.isOnline()).thenReturn(true);
World world = Mockito.mock(World.class);
InOrder worldInOrder = Mockito.inOrder(world);
Mockito.when(player.getWorld()).thenReturn(world);
PlayerUtils.giveItem(player, itemsToAdd);
inventoryInOrder.verify(inventory).addItem(itemsToAdd);
inventoryInOrder.verify(inventory, Mockito.never()).addItem(Mockito.any());
worldInOrder.verify(world).dropItemNaturally(Mockito.any(), Mockito.eq(itemsToAdd[0]));
worldInOrder.verify(world).dropItemNaturally(Mockito.any(), Mockito.eq(itemsToAdd[1]));
worldInOrder.verify(world, Mockito.never()).dropItemNaturally(Mockito.any(), Mockito.any());
}
@Test
void giveItem_FullInventory_List() {
ItemStack[] itemsToAdd = new ItemStack[] {Mockito.mock(ItemStack.class), Mockito.mock(ItemStack.class)};
PlayerInventory inventory = Mockito.mock(PlayerInventory.class);
Mockito.when(inventory.addItem(Mockito.any())).thenReturn(new HashMap<Integer, ItemStack>() {{
put(0, itemsToAdd[0]);
put(1, itemsToAdd[1]);
}});
InOrder inventoryInOrder = Mockito.inOrder(inventory);
Player player = createMockPlayer("Player");
Mockito.when(player.getInventory()).thenReturn(inventory);
Mockito.when(player.isOnline()).thenReturn(true);
World world = Mockito.mock(World.class);
InOrder worldInOrder = Mockito.inOrder(world);
Mockito.when(player.getWorld()).thenReturn(world);
PlayerUtils.giveItem(player, Arrays.asList(itemsToAdd));
inventoryInOrder.verify(inventory).addItem(itemsToAdd);
inventoryInOrder.verify(inventory, Mockito.never()).addItem(Mockito.any());
worldInOrder.verify(world).dropItemNaturally(Mockito.any(), Mockito.eq(itemsToAdd[0]));
worldInOrder.verify(world).dropItemNaturally(Mockito.any(), Mockito.eq(itemsToAdd[1]));
worldInOrder.verify(world, Mockito.never()).dropItemNaturally(Mockito.any(), Mockito.any());
}
@Disabled("Test is incomplete")
@Test
void getNumberFromPermission() {
Player player = this.server.addPlayer();
Player player = createMockPlayer("Player");
assertEquals(-1, PlayerUtils.getNumberFromPermission(player, "example.plugin.feature", -1));
}
private void fillInventory(Player player) {
ItemStack[] contents = new ItemStack[player.getInventory().getContents().length];
private Player createMockPlayer(String name) {
return createMockPlayer(name, name);
}
for (int i = 0; i < contents.length; ++i) {
contents[i] = new ItemStack(Material.BARRIER);
}
private Player createMockPlayer(String name, String displayName) {
Player player = Mockito.mock(Player.class);
Mockito.when(player.getName()).thenReturn(name);
Mockito.when(player.getDisplayName()).thenReturn(displayName);
player.getInventory().setContents(contents);
return player;
}
}

View File

@ -7,18 +7,17 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-API</artifactId>
<packaging>jar</packaging>
<dependencies>
<!--suppress VulnerableLibrariesLocal -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.17</version>
<artifactId>spigot-api</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@ -26,6 +25,7 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,20 @@
package com.songoda.core.nms;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
public interface NmsImplementations {
@NotNull NMSPlayer getPlayer();
@NotNull WorldCore getWorld();
@NotNull NmsWorldBorder getWorldBorder();
@NotNull AnvilCore getAnvil();
@NotNull NBTCore getNbt();
}

View File

@ -0,0 +1,12 @@
package com.songoda.core.nms.world;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public interface NmsWorldBorder {
void send(Player player, BorderColor color, double size, Location center);
enum BorderColor {
BLUE, GREEN, RED
}
}

View File

@ -1,9 +1,20 @@
package com.songoda.core.nms.world;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import java.util.List;
public interface SWorld {
List<LivingEntity> getLivingEntities();
/**
* Set a block to a certain type by updating the block directly in the NMS chunk.
* <br>
* The chunk must be loaded and players must relog if they have the chunk loaded in order to use this method.
* (F3+A is not enough)
*/
// TODO: Check if FabledSkyBlock *really* needs this method and if it can be removed.
// Would make thinks less complicated and I kinda cannot imagine it being *that* much faster to be worth it?
void setBlockFast(int x, int y, int z, Material material);
}

View File

@ -7,8 +7,13 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public interface WorldCore {
/**
* @deprecated Use {@link #getSpawner(Location)} instead
*/
@Deprecated
SSpawner getSpawner(CreatureSpawner spawner);
SSpawner getSpawner(Location location);
@ -29,7 +34,7 @@ public interface WorldCore {
*/
void randomTickChunk(Chunk bukkitChunk, int tickAmount) throws ReflectiveOperationException;
void updateAdjacentComparators(Block bukkitBlock);
void updateAdjacentComparators(@NotNull Block bukkitBlock);
/**
* Ticks all inactive spawners in a specific chunk ignoring the minimum required players within a specific range.<br>

View File

@ -7,12 +7,10 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_10_R1</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -26,12 +24,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package com.songoda.core.nms.v1_10_R1;
import com.songoda.core.nms.NmsImplementations;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.v1_10_R1.entity.NMSPlayerImpl;
import com.songoda.core.nms.v1_10_R1.nbt.NBTCoreImpl;
import com.songoda.core.nms.v1_10_R1.world.NmsWorldBorderImpl;
import com.songoda.core.nms.v1_10_R1.world.WorldCoreImpl;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
private final AnvilCore anvil;
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
this.anvil = new com.songoda.core.nms.v1_10_R1.anvil.AnvilCore();
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;
}
@Override
public @NotNull WorldCore getWorld() {
return this.world;
}
@Override
public @NotNull NmsWorldBorder getWorldBorder() {
return this.worldBorder;
}
@Override
public @NotNull AnvilCore getAnvil() {
return this.anvil;
}
@Override
public @NotNull NBTCore getNbt() {
return this.nbt;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.core.nms.v1_10_R1.world;
import com.songoda.core.nms.world.NmsWorldBorder;
import net.minecraft.server.v1_10_R1.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_10_R1.WorldBorder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NmsWorldBorderImpl implements NmsWorldBorder {
@Override
public void send(Player player, BorderColor color, double size, @NotNull Location center) {
Objects.requireNonNull(center.getWorld());
WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.setSize(size);
worldBorder.setWarningTime(0);
worldBorder.setWarningDistance(0);
if (color == BorderColor.GREEN) {
worldBorder.transitionSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) {
worldBorder.transitionSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
}
}

View File

@ -1,17 +1,35 @@
package com.songoda.core.nms.v1_10_R1.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_10_R1.Chunk;
import net.minecraft.server.v1_10_R1.WorldServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
public SWorldImpl() {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
return new ArrayList<>();
return new ArrayList<>(); // FIXME
}
@Override
public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
}
}

View File

@ -18,9 +18,11 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_10_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_10_R1.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class WorldCoreImpl implements WorldCore {
@Override
@ -40,7 +42,7 @@ public class WorldCoreImpl implements WorldCore {
@Override
public SWorld getWorld(World world) {
return new SWorldImpl();
return new SWorldImpl(world);
}
@Override
@ -89,12 +91,12 @@ public class WorldCoreImpl implements WorldCore {
}
@Override
public void updateAdjacentComparators(org.bukkit.block.Block bukkitBlock) {
public void updateAdjacentComparators(@NotNull org.bukkit.block.Block bukkitBlock) {
CraftBlock craftBlock = (CraftBlock) bukkitBlock;
CraftChunk craftChunk = (CraftChunk) bukkitBlock.getChunk();
net.minecraft.server.v1_10_R1.World nmsWorld = craftChunk.getHandle().getWorld();
WorldServer serverLevel = ((CraftWorld) craftBlock.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(craftBlock.getX(), craftBlock.getY(), craftBlock.getZ());
nmsWorld.updateAdjacentComparators(blockPosition, CraftMagicNumbers.getBlock(craftBlock));
BlockPosition blockPos = new BlockPosition(craftBlock.getX(), craftBlock.getY(), craftBlock.getZ());
Block nmsBlock = CraftMagicNumbers.getBlock(bukkitBlock.getType());
serverLevel.updateAdjacentComparators(blockPos, nmsBlock);
}
}

View File

@ -7,12 +7,10 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_11_R1</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -26,12 +24,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package com.songoda.core.nms.v1_11_R1;
import com.songoda.core.nms.NmsImplementations;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.v1_11_R1.entity.NMSPlayerImpl;
import com.songoda.core.nms.v1_11_R1.nbt.NBTCoreImpl;
import com.songoda.core.nms.v1_11_R1.world.NmsWorldBorderImpl;
import com.songoda.core.nms.v1_11_R1.world.WorldCoreImpl;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
private final AnvilCore anvil;
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
this.anvil = new com.songoda.core.nms.v1_11_R1.anvil.AnvilCore();
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;
}
@Override
public @NotNull WorldCore getWorld() {
return this.world;
}
@Override
public @NotNull NmsWorldBorder getWorldBorder() {
return this.worldBorder;
}
@Override
public @NotNull AnvilCore getAnvil() {
return this.anvil;
}
@Override
public @NotNull NBTCore getNbt() {
return this.nbt;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.core.nms.v1_11_R1.world;
import com.songoda.core.nms.world.NmsWorldBorder;
import net.minecraft.server.v1_11_R1.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_11_R1.WorldBorder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NmsWorldBorderImpl implements NmsWorldBorder {
@Override
public void send(Player player, BorderColor color, double size, @NotNull Location center) {
Objects.requireNonNull(center.getWorld());
WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.setSize(size);
worldBorder.setWarningTime(0);
worldBorder.setWarningDistance(0);
if (color == BorderColor.GREEN) {
worldBorder.transitionSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) {
worldBorder.transitionSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
}
}

View File

@ -1,17 +1,35 @@
package com.songoda.core.nms.v1_11_R1.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.Chunk;
import net.minecraft.server.v1_11_R1.WorldServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
public SWorldImpl() {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
return new ArrayList<>();
return new ArrayList<>(); // FIXME
}
@Override
public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
}
}

View File

@ -18,9 +18,11 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_11_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_11_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_11_R1.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class WorldCoreImpl implements WorldCore {
@Override
@ -40,7 +42,7 @@ public class WorldCoreImpl implements WorldCore {
@Override
public SWorld getWorld(World world) {
return new SWorldImpl();
return new SWorldImpl(world);
}
@Override
@ -89,12 +91,12 @@ public class WorldCoreImpl implements WorldCore {
}
@Override
public void updateAdjacentComparators(org.bukkit.block.Block bukkitBlock) {
public void updateAdjacentComparators(@NotNull org.bukkit.block.Block bukkitBlock) {
CraftBlock craftBlock = (CraftBlock) bukkitBlock;
CraftChunk craftChunk = (CraftChunk) bukkitBlock.getChunk();
net.minecraft.server.v1_11_R1.World nmsWorld = craftChunk.getHandle().getWorld();
WorldServer serverLevel = ((CraftWorld) craftBlock.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(craftBlock.getX(), craftBlock.getY(), craftBlock.getZ());
nmsWorld.updateAdjacentComparators(blockPosition, CraftMagicNumbers.getBlock(craftBlock));
BlockPosition blockPos = new BlockPosition(craftBlock.getX(), craftBlock.getY(), craftBlock.getZ());
Block nmsBlock = CraftMagicNumbers.getBlock(bukkitBlock.getType());
serverLevel.updateAdjacentComparators(blockPos, nmsBlock);
}
}

View File

@ -7,12 +7,10 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_12_R1</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -26,12 +24,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package com.songoda.core.nms.v1_12_R1;
import com.songoda.core.nms.NmsImplementations;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.v1_12_R1.entity.NMSPlayerImpl;
import com.songoda.core.nms.v1_12_R1.nbt.NBTCoreImpl;
import com.songoda.core.nms.v1_12_R1.world.NmsWorldBorderImpl;
import com.songoda.core.nms.v1_12_R1.world.WorldCoreImpl;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
private final AnvilCore anvil;
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
this.anvil = new com.songoda.core.nms.v1_12_R1.anvil.AnvilCore();
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;
}
@Override
public @NotNull WorldCore getWorld() {
return this.world;
}
@Override
public @NotNull NmsWorldBorder getWorldBorder() {
return this.worldBorder;
}
@Override
public @NotNull AnvilCore getAnvil() {
return this.anvil;
}
@Override
public @NotNull NBTCore getNbt() {
return this.nbt;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.core.nms.v1_12_R1.world;
import com.songoda.core.nms.world.NmsWorldBorder;
import net.minecraft.server.v1_12_R1.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_12_R1.WorldBorder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NmsWorldBorderImpl implements NmsWorldBorder {
@Override
public void send(Player player, BorderColor color, double size, @NotNull Location center) {
Objects.requireNonNull(center.getWorld());
WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.setSize(size);
worldBorder.setWarningTime(0);
worldBorder.setWarningDistance(0);
if (color == BorderColor.GREEN) {
worldBorder.transitionSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) {
worldBorder.transitionSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
}
}

View File

@ -1,17 +1,35 @@
package com.songoda.core.nms.v1_12_R1.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.v1_12_R1.Block;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.Chunk;
import net.minecraft.server.v1_12_R1.WorldServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
public SWorldImpl() {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
return new ArrayList<>();
return new ArrayList<>(); // FIXME
}
@Override
public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), Block.getByCombinedId(0));
}
}

View File

@ -18,9 +18,11 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_12_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_12_R1.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class WorldCoreImpl implements WorldCore {
@Override
@ -40,7 +42,7 @@ public class WorldCoreImpl implements WorldCore {
@Override
public SWorld getWorld(World world) {
return new SWorldImpl();
return new SWorldImpl(world);
}
@Override
@ -89,12 +91,12 @@ public class WorldCoreImpl implements WorldCore {
}
@Override
public void updateAdjacentComparators(org.bukkit.block.Block bukkitBlock) {
public void updateAdjacentComparators(@NotNull org.bukkit.block.Block bukkitBlock) {
CraftBlock craftBlock = (CraftBlock) bukkitBlock;
CraftChunk craftChunk = (CraftChunk) bukkitBlock.getChunk();
net.minecraft.server.v1_12_R1.World nmsWorld = craftChunk.getHandle().getWorld();
WorldServer serverLevel = ((CraftWorld) craftBlock.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(craftBlock.getX(), craftBlock.getY(), craftBlock.getZ());
nmsWorld.updateAdjacentComparators(blockPosition, CraftMagicNumbers.getBlock(craftBlock));
BlockPosition blockPos = new BlockPosition(craftBlock.getX(), craftBlock.getY(), craftBlock.getZ());
Block nmsBlock = CraftMagicNumbers.getBlock(bukkitBlock.getType());
serverLevel.updateAdjacentComparators(blockPos, nmsBlock);
}
}

View File

@ -7,12 +7,10 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_13_R1</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -26,12 +24,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package com.songoda.core.nms.v1_13_R1;
import com.songoda.core.nms.NmsImplementations;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.v1_13_R1.entity.NMSPlayerImpl;
import com.songoda.core.nms.v1_13_R1.nbt.NBTCoreImpl;
import com.songoda.core.nms.v1_13_R1.world.NmsWorldBorderImpl;
import com.songoda.core.nms.v1_13_R1.world.WorldCoreImpl;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
private final AnvilCore anvil;
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
this.anvil = new com.songoda.core.nms.v1_13_R1.anvil.AnvilCore();
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;
}
@Override
public @NotNull WorldCore getWorld() {
return this.world;
}
@Override
public @NotNull NmsWorldBorder getWorldBorder() {
return this.worldBorder;
}
@Override
public @NotNull AnvilCore getAnvil() {
return this.anvil;
}
@Override
public @NotNull NBTCore getNbt() {
return this.nbt;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.core.nms.v1_13_R1.world;
import com.songoda.core.nms.world.NmsWorldBorder;
import net.minecraft.server.v1_13_R1.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_13_R1.WorldBorder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NmsWorldBorderImpl implements NmsWorldBorder {
@Override
public void send(Player player, BorderColor color, double size, @NotNull Location center) {
Objects.requireNonNull(center.getWorld());
WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.setSize(size);
worldBorder.setWarningTime(0);
worldBorder.setWarningDistance(0);
if (color == BorderColor.GREEN) {
worldBorder.transitionSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) {
worldBorder.transitionSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
}
}

View File

@ -1,17 +1,37 @@
package com.songoda.core.nms.v1_13_R1.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.v1_13_R1.BlockPosition;
import net.minecraft.server.v1_13_R1.Chunk;
import net.minecraft.server.v1_13_R1.IBlockData;
import net.minecraft.server.v1_13_R1.WorldServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_13_R1.block.data.CraftBlockData;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
public SWorldImpl() {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
return new ArrayList<>();
return new ArrayList<>(); // FIXME
}
@Override
public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
levelChunk.a(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
}
}

View File

@ -21,6 +21,7 @@ import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_13_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_13_R1.block.CraftBlock;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class WorldCoreImpl implements WorldCore {
@Override
@ -40,7 +41,7 @@ public class WorldCoreImpl implements WorldCore {
@Override
public SWorld getWorld(World world) {
return new SWorldImpl();
return new SWorldImpl(world);
}
@Override
@ -93,11 +94,10 @@ public class WorldCoreImpl implements WorldCore {
}
@Override
public void updateAdjacentComparators(Block bukkitBlock) {
public void updateAdjacentComparators(@NotNull Block bukkitBlock) {
CraftBlock craftBlock = (CraftBlock) bukkitBlock;
CraftChunk craftChunk = (CraftChunk) bukkitBlock.getChunk();
WorldServer serverLevel = craftBlock.getCraftWorld().getHandle();
net.minecraft.server.v1_13_R1.World nmsWorld = craftChunk.getHandle().getWorld();
nmsWorld.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
serverLevel.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
}
}

View File

@ -7,12 +7,10 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_13_R2</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -26,12 +24,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package com.songoda.core.nms.v1_13_R2;
import com.songoda.core.nms.NmsImplementations;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.v1_13_R2.entity.NMSPlayerImpl;
import com.songoda.core.nms.v1_13_R2.nbt.NBTCoreImpl;
import com.songoda.core.nms.v1_13_R2.world.NmsWorldBorderImpl;
import com.songoda.core.nms.v1_13_R2.world.WorldCoreImpl;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
private final AnvilCore anvil;
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
this.anvil = new com.songoda.core.nms.v1_13_R2.anvil.AnvilCore();
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;
}
@Override
public @NotNull WorldCore getWorld() {
return this.world;
}
@Override
public @NotNull NmsWorldBorder getWorldBorder() {
return this.worldBorder;
}
@Override
public @NotNull AnvilCore getAnvil() {
return this.anvil;
}
@Override
public @NotNull NBTCore getNbt() {
return this.nbt;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.core.nms.v1_13_R2.world;
import com.songoda.core.nms.world.NmsWorldBorder;
import net.minecraft.server.v1_13_R2.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_13_R2.WorldBorder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NmsWorldBorderImpl implements NmsWorldBorder {
@Override
public void send(Player player, BorderColor color, double size, @NotNull Location center) {
Objects.requireNonNull(center.getWorld());
WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.setSize(size);
worldBorder.setWarningTime(0);
worldBorder.setWarningDistance(0);
if (color == BorderColor.GREEN) {
worldBorder.transitionSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) {
worldBorder.transitionSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
}
}

View File

@ -1,17 +1,37 @@
package com.songoda.core.nms.v1_13_R2.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.v1_13_R2.BlockPosition;
import net.minecraft.server.v1_13_R2.Chunk;
import net.minecraft.server.v1_13_R2.IBlockData;
import net.minecraft.server.v1_13_R2.WorldServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_13_R2.block.data.CraftBlockData;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
public SWorldImpl() {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
return new ArrayList<>();
return new ArrayList<>(); // FIXME
}
@Override
public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
}
}

View File

@ -21,6 +21,7 @@ import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_13_R2.CraftChunk;
import org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class WorldCoreImpl implements WorldCore {
@Override
@ -40,7 +41,7 @@ public class WorldCoreImpl implements WorldCore {
@Override
public SWorld getWorld(World world) {
return new SWorldImpl();
return new SWorldImpl(world);
}
@Override
@ -100,11 +101,10 @@ public class WorldCoreImpl implements WorldCore {
}
@Override
public void updateAdjacentComparators(Block bukkitBlock) {
public void updateAdjacentComparators(@NotNull Block bukkitBlock) {
CraftBlock craftBlock = (CraftBlock) bukkitBlock;
CraftChunk craftChunk = (CraftChunk) bukkitBlock.getChunk();
WorldServer serverLevel = craftBlock.getCraftWorld().getHandle();
net.minecraft.server.v1_13_R2.World nmsWorld = craftChunk.getHandle().getWorld();
nmsWorld.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
serverLevel.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
}
}

View File

@ -7,12 +7,10 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_14_R1</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -26,12 +24,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package com.songoda.core.nms.v1_14_R1;
import com.songoda.core.nms.NmsImplementations;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.v1_14_R1.entity.NMSPlayerImpl;
import com.songoda.core.nms.v1_14_R1.nbt.NBTCoreImpl;
import com.songoda.core.nms.v1_14_R1.world.NmsWorldBorderImpl;
import com.songoda.core.nms.v1_14_R1.world.WorldCoreImpl;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
private final AnvilCore anvil;
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
this.anvil = new com.songoda.core.nms.v1_14_R1.anvil.AnvilCore();
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;
}
@Override
public @NotNull WorldCore getWorld() {
return this.world;
}
@Override
public @NotNull NmsWorldBorder getWorldBorder() {
return this.worldBorder;
}
@Override
public @NotNull AnvilCore getAnvil() {
return this.anvil;
}
@Override
public @NotNull NBTCore getNbt() {
return this.nbt;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.core.nms.v1_14_R1.world;
import com.songoda.core.nms.world.NmsWorldBorder;
import net.minecraft.server.v1_14_R1.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_14_R1.WorldBorder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NmsWorldBorderImpl implements NmsWorldBorder {
@Override
public void send(Player player, BorderColor color, double size, @NotNull Location center) {
Objects.requireNonNull(center.getWorld());
WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.setSize(size);
worldBorder.setWarningTime(0);
worldBorder.setWarningDistance(0);
if (color == BorderColor.GREEN) {
worldBorder.transitionSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) {
worldBorder.transitionSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
}
}

View File

@ -1,17 +1,37 @@
package com.songoda.core.nms.v1_14_R1.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.v1_14_R1.BlockPosition;
import net.minecraft.server.v1_14_R1.Chunk;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
public SWorldImpl() {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
return new ArrayList<>();
return new ArrayList<>(); // FIXME
}
@Override
public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
}
}

View File

@ -23,6 +23,7 @@ import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_14_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class WorldCoreImpl implements WorldCore {
@Override
@ -42,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
@Override
public SWorld getWorld(World world) {
return new SWorldImpl();
return new SWorldImpl(world);
}
@Override
@ -97,11 +98,10 @@ public class WorldCoreImpl implements WorldCore {
}
@Override
public void updateAdjacentComparators(Block bukkitBlock) {
public void updateAdjacentComparators(@NotNull Block bukkitBlock) {
CraftBlock craftBlock = (CraftBlock) bukkitBlock;
CraftChunk craftChunk = (CraftChunk) bukkitBlock.getChunk();
WorldServer serverLevel = craftBlock.getCraftWorld().getHandle();
net.minecraft.server.v1_14_R1.World nmsWorld = craftChunk.getHandle().getWorld();
nmsWorld.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
serverLevel.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
}
}

View File

@ -7,12 +7,11 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_15_R1</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -26,12 +25,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package com.songoda.core.nms.v1_15_R1;
import com.songoda.core.nms.NmsImplementations;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.v1_15_R1.entity.NMSPlayerImpl;
import com.songoda.core.nms.v1_15_R1.nbt.NBTCoreImpl;
import com.songoda.core.nms.v1_15_R1.world.NmsWorldBorderImpl;
import com.songoda.core.nms.v1_15_R1.world.WorldCoreImpl;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
private final AnvilCore anvil;
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
this.anvil = new com.songoda.core.nms.v1_15_R1.anvil.AnvilCore();
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;
}
@Override
public @NotNull WorldCore getWorld() {
return this.world;
}
@Override
public @NotNull NmsWorldBorder getWorldBorder() {
return this.worldBorder;
}
@Override
public @NotNull AnvilCore getAnvil() {
return this.anvil;
}
@Override
public @NotNull NBTCore getNbt() {
return this.nbt;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.core.nms.v1_15_R1.world;
import com.songoda.core.nms.world.NmsWorldBorder;
import net.minecraft.server.v1_15_R1.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_15_R1.WorldBorder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NmsWorldBorderImpl implements NmsWorldBorder {
@Override
public void send(Player player, BorderColor color, double size, @NotNull Location center) {
Objects.requireNonNull(center.getWorld());
WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.setSize(size);
worldBorder.setWarningTime(0);
worldBorder.setWarningDistance(0);
if (color == BorderColor.GREEN) {
worldBorder.transitionSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) {
worldBorder.transitionSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
}
}

View File

@ -1,17 +1,37 @@
package com.songoda.core.nms.v1_15_R1.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.v1_15_R1.BlockPosition;
import net.minecraft.server.v1_15_R1.Chunk;
import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.WorldServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
public SWorldImpl() {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
return new ArrayList<>();
return new ArrayList<>(); // FIXME
}
@Override
public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
}
}

View File

@ -23,6 +23,7 @@ import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class WorldCoreImpl implements WorldCore {
@Override
@ -42,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
@Override
public SWorld getWorld(World world) {
return new SWorldImpl();
return new SWorldImpl(world);
}
@Override
@ -100,11 +101,10 @@ public class WorldCoreImpl implements WorldCore {
}
@Override
public void updateAdjacentComparators(Block bukkitBlock) {
public void updateAdjacentComparators(@NotNull Block bukkitBlock) {
CraftBlock craftBlock = (CraftBlock) bukkitBlock;
CraftChunk craftChunk = (CraftChunk) bukkitBlock.getChunk();
WorldServer serverLevel = craftBlock.getCraftWorld().getHandle();
net.minecraft.server.v1_15_R1.World nmsWorld = craftChunk.getHandle().getWorld();
nmsWorld.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
serverLevel.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
}
}

View File

@ -7,12 +7,10 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_16_R1</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -26,12 +24,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package com.songoda.core.nms.v1_16_R1;
import com.songoda.core.nms.NmsImplementations;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.v1_16_R1.entity.NMSPlayerImpl;
import com.songoda.core.nms.v1_16_R1.nbt.NBTCoreImpl;
import com.songoda.core.nms.v1_16_R1.world.NmsWorldBorderImpl;
import com.songoda.core.nms.v1_16_R1.world.WorldCoreImpl;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
private final AnvilCore anvil;
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
this.anvil = new com.songoda.core.nms.v1_16_R1.anvil.AnvilCore();
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;
}
@Override
public @NotNull WorldCore getWorld() {
return this.world;
}
@Override
public @NotNull NmsWorldBorder getWorldBorder() {
return this.worldBorder;
}
@Override
public @NotNull AnvilCore getAnvil() {
return this.anvil;
}
@Override
public @NotNull NBTCore getNbt() {
return this.nbt;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.core.nms.v1_16_R1.world;
import com.songoda.core.nms.world.NmsWorldBorder;
import net.minecraft.server.v1_16_R1.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_16_R1.WorldBorder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NmsWorldBorderImpl implements NmsWorldBorder {
@Override
public void send(Player player, BorderColor color, double size, @NotNull Location center) {
Objects.requireNonNull(center.getWorld());
WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.setSize(size);
worldBorder.setWarningTime(0);
worldBorder.setWarningDistance(0);
if (color == BorderColor.GREEN) {
worldBorder.transitionSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) {
worldBorder.transitionSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
}
}

View File

@ -1,17 +1,37 @@
package com.songoda.core.nms.v1_16_R1.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.v1_16_R1.BlockPosition;
import net.minecraft.server.v1_16_R1.Chunk;
import net.minecraft.server.v1_16_R1.IBlockData;
import net.minecraft.server.v1_16_R1.WorldServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R1.block.data.CraftBlockData;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
public SWorldImpl() {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
return new ArrayList<>();
return new ArrayList<>(); // FIXME
}
@Override
public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
}
}

View File

@ -23,6 +23,7 @@ import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_16_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_16_R1.block.CraftBlock;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class WorldCoreImpl implements WorldCore {
@Override
@ -42,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
@Override
public SWorld getWorld(World world) {
return new SWorldImpl();
return new SWorldImpl(world);
}
@Override
@ -101,11 +102,10 @@ public class WorldCoreImpl implements WorldCore {
}
@Override
public void updateAdjacentComparators(Block bukkitBlock) {
public void updateAdjacentComparators(@NotNull Block bukkitBlock) {
CraftBlock craftBlock = (CraftBlock) bukkitBlock;
CraftChunk craftChunk = (CraftChunk) bukkitBlock.getChunk();
WorldServer serverLevel = craftBlock.getCraftWorld().getHandle();
net.minecraft.server.v1_16_R1.World nmsWorld = craftChunk.getHandle().getWorld();
nmsWorld.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
serverLevel.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
}
}

View File

@ -7,12 +7,10 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_16_R2</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -26,12 +24,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package com.songoda.core.nms.v1_16_R2;
import com.songoda.core.nms.NmsImplementations;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.v1_16_R2.entity.NMSPlayerImpl;
import com.songoda.core.nms.v1_16_R2.nbt.NBTCoreImpl;
import com.songoda.core.nms.v1_16_R2.world.NmsWorldBorderImpl;
import com.songoda.core.nms.v1_16_R2.world.WorldCoreImpl;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
private final AnvilCore anvil;
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
this.anvil = new com.songoda.core.nms.v1_16_R2.anvil.AnvilCore();
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;
}
@Override
public @NotNull WorldCore getWorld() {
return this.world;
}
@Override
public @NotNull NmsWorldBorder getWorldBorder() {
return this.worldBorder;
}
@Override
public @NotNull AnvilCore getAnvil() {
return this.anvil;
}
@Override
public @NotNull NBTCore getNbt() {
return this.nbt;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.core.nms.v1_16_R2.world;
import com.songoda.core.nms.world.NmsWorldBorder;
import net.minecraft.server.v1_16_R2.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_16_R2.WorldBorder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NmsWorldBorderImpl implements NmsWorldBorder {
@Override
public void send(Player player, BorderColor color, double size, @NotNull Location center) {
Objects.requireNonNull(center.getWorld());
WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.setSize(size);
worldBorder.setWarningTime(0);
worldBorder.setWarningDistance(0);
if (color == BorderColor.GREEN) {
worldBorder.transitionSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) {
worldBorder.transitionSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
}
}

View File

@ -1,17 +1,37 @@
package com.songoda.core.nms.v1_16_R2.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.v1_16_R2.BlockPosition;
import net.minecraft.server.v1_16_R2.Chunk;
import net.minecraft.server.v1_16_R2.IBlockData;
import net.minecraft.server.v1_16_R2.WorldServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R2.block.data.CraftBlockData;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
public SWorldImpl() {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
return new ArrayList<>();
return new ArrayList<>(); // FIXME
}
@Override
public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
}
}

View File

@ -23,6 +23,7 @@ import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_16_R2.CraftChunk;
import org.bukkit.craftbukkit.v1_16_R2.block.CraftBlock;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class WorldCoreImpl implements WorldCore {
@Override
@ -42,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
@Override
public SWorld getWorld(World world) {
return new SWorldImpl();
return new SWorldImpl(world);
}
@Override
@ -101,11 +102,10 @@ public class WorldCoreImpl implements WorldCore {
}
@Override
public void updateAdjacentComparators(Block bukkitBlock) {
public void updateAdjacentComparators(@NotNull Block bukkitBlock) {
CraftBlock craftBlock = (CraftBlock) bukkitBlock;
CraftChunk craftChunk = (CraftChunk) bukkitBlock.getChunk();
WorldServer serverLevel = craftBlock.getCraftWorld().getHandle();
net.minecraft.server.v1_16_R2.World nmsWorld = craftChunk.getHandle().getWorld();
nmsWorld.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
serverLevel.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
}
}

View File

@ -7,12 +7,10 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_16_R3</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -26,12 +24,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package com.songoda.core.nms.v1_16_R3;
import com.songoda.core.nms.NmsImplementations;
import com.songoda.core.nms.anvil.AnvilCore;
import com.songoda.core.nms.entity.NMSPlayer;
import com.songoda.core.nms.nbt.NBTCore;
import com.songoda.core.nms.v1_16_R3.entity.NMSPlayerImpl;
import com.songoda.core.nms.v1_16_R3.nbt.NBTCoreImpl;
import com.songoda.core.nms.v1_16_R3.world.NmsWorldBorderImpl;
import com.songoda.core.nms.v1_16_R3.world.WorldCoreImpl;
import com.songoda.core.nms.world.NmsWorldBorder;
import com.songoda.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
private final AnvilCore anvil;
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
this.anvil = new com.songoda.core.nms.v1_16_R3.anvil.AnvilCore();
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;
}
@Override
public @NotNull WorldCore getWorld() {
return this.world;
}
@Override
public @NotNull NmsWorldBorder getWorldBorder() {
return this.worldBorder;
}
@Override
public @NotNull AnvilCore getAnvil() {
return this.anvil;
}
@Override
public @NotNull NBTCore getNbt() {
return this.nbt;
}
}

View File

@ -0,0 +1,35 @@
package com.songoda.core.nms.v1_16_R3.world;
import com.songoda.core.nms.world.NmsWorldBorder;
import net.minecraft.server.v1_16_R3.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_16_R3.WorldBorder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class NmsWorldBorderImpl implements NmsWorldBorder {
@Override
public void send(Player player, BorderColor color, double size, @NotNull Location center) {
Objects.requireNonNull(center.getWorld());
WorldBorder worldBorder = new WorldBorder();
worldBorder.world = ((CraftWorld) center.getWorld()).getHandle();
worldBorder.setCenter(center.getX(), center.getZ());
worldBorder.setSize(size);
worldBorder.setWarningTime(0);
worldBorder.setWarningDistance(0);
if (color == BorderColor.GREEN) {
worldBorder.transitionSizeBetween(size - 0.1D, size, Long.MAX_VALUE);
} else if (color == BorderColor.RED) {
worldBorder.transitionSizeBetween(size, size - 1.0D, Long.MAX_VALUE);
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
}
}

View File

@ -1,17 +1,37 @@
package com.songoda.core.nms.v1_16_R3.world;
import com.songoda.core.nms.world.SWorld;
import net.minecraft.server.v1_16_R3.BlockPosition;
import net.minecraft.server.v1_16_R3.Chunk;
import net.minecraft.server.v1_16_R3.IBlockData;
import net.minecraft.server.v1_16_R3.WorldServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
public class SWorldImpl implements SWorld {
public SWorldImpl() {
private final World world;
public SWorldImpl(World world) {
this.world = world;
}
@Override
public List<LivingEntity> getLivingEntities() {
return new ArrayList<>();
return new ArrayList<>(); // FIXME
}
@Override
public void setBlockFast(int x, int y, int z, Material material) {
WorldServer serverLevel = ((CraftWorld) this.world).getHandle();
Chunk levelChunk = serverLevel.getChunkIfLoaded(x >> 4, z >> 4);
IBlockData blockState = ((CraftBlockData) material.createBlockData()).getState();
levelChunk.setType(new BlockPosition(x & 0xF, y, z & 0xF), blockState, true);
}
}

View File

@ -23,6 +23,7 @@ import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.v1_16_R3.CraftChunk;
import org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class WorldCoreImpl implements WorldCore {
@Override
@ -42,7 +43,7 @@ public class WorldCoreImpl implements WorldCore {
@Override
public SWorld getWorld(World world) {
return new SWorldImpl();
return new SWorldImpl(world);
}
@Override
@ -102,11 +103,10 @@ public class WorldCoreImpl implements WorldCore {
}
@Override
public void updateAdjacentComparators(Block bukkitBlock) {
public void updateAdjacentComparators(@NotNull Block bukkitBlock) {
CraftBlock craftBlock = (CraftBlock) bukkitBlock;
CraftChunk craftChunk = (CraftChunk) bukkitBlock.getChunk();
WorldServer serverLevel = craftBlock.getCraftWorld().getHandle();
net.minecraft.server.v1_16_R3.World nmsWorld = craftChunk.getHandle().getWorld();
nmsWorld.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
serverLevel.updateAdjacentComparators(craftBlock.getPosition(), craftBlock.getNMS().getBlock());
}
}

View File

@ -7,18 +7,16 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.21</version>
<version>2.6.22</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>SongodaCore-NMS-v1_17_R1</artifactId>
<properties>
<java.version>16</java.version>
<java.release>16</java.release>
</properties>
<artifactId>SongodaCore-NMS-v1_17_R1</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
@ -31,12 +29,14 @@
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-NMS-API</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SongodaCore-Compatibility</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

Some files were not shown because too many files have changed in this diff Show More