Merge remote-tracking branch 'origin/update/1.19'

# Conflicts:
#	gradle.properties
#	patches/api/0003-Add-SoundEvent.patch
#	patches/server/0001-Build-changes.patch
#	patches/server/0003-Add-SoundEvent.patch
#	patches/server/0005-Add-origin-location-to-EntityDamageByBlockEvent.patch
#	patches/server/0011-Add-BlockDropResourcesEvent.patch
This commit is contained in:
Lexi
2022-06-22 02:05:18 -04:00
37 changed files with 1129 additions and 1503 deletions

View File

@@ -9,37 +9,37 @@ jobs:
strategy:
matrix:
java: [16]
java: [17]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
- name: Cache gradle
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/jdks
~/.gradle/native
~/.gradle/wrapper
key: ${{ runner.os }}-parchment-2-${{ hashFiles('**/*.gradle*', 'gradle/**', 'gradle.properties') }}
restore-keys: ${{ runner.os }}-parchment-2
- name: Cache gradle
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/jdks
~/.gradle/native
~/.gradle/wrapper
key: ${{ runner.os }}-parchment-2-${{ hashFiles('**/*.gradle*', 'gradle/**', 'gradle.properties') }}
restore-keys: ${{ runner.os }}-parchment-2
- name: Patch Parchment
run: |
git config --global user.email "no-reply@github.com"
git config --global user.name "GitHub Actions"
./gradlew applyPatches
./gradlew paperclipJar
- name: Patch Parchment
run: |
git config --global user.email "no-reply@github.com"
git config --global user.name "GitHub Actions"
./gradlew applyPatches
./gradlew createReobfPaperclipJar
- uses: actions/upload-artifact@v2
with:
name: Parchment-PR${{ github.event.pull_request.number }}-JDK${{ matrix.java }}
path: build/libs/Parchment-*.jar
- uses: actions/upload-artifact@v2
with:
name: Parchment-PR${{ github.event.pull_request.number }}-JDK${{ matrix.java }}
path: build/libs/parchment-paperclip-*-reobf.jar

View File

@@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
java: [16]
java: [17]
fail-fast: true
steps:
@@ -37,9 +37,9 @@ jobs:
git config --global user.email "no-reply@github.com"
git config --global user.name "GitHub Actions"
./gradlew applyPatches
./gradlew paperclipJar
./gradlew createReobfPaperclipJar
- uses: actions/upload-artifact@v2
with:
name: Parchment-JDK${{ matrix.java }}
path: build/libs/Parchment-*.jar
path: build/libs/parchment-paperclip-*-reobf.jar

6
.gitignore vendored
View File

@@ -45,8 +45,10 @@ out/
# other stuff
run/
Parchment-Server
Parchment-API
/Parchment-Server/
/parchment-server/
/Parchment-API/
/parchment-api/
# Compiled class file
*.class

View File

@@ -1,41 +0,0 @@
import java.util.Locale
import java.net.URI
plugins {
`maven-publish`
}
java {
withSourcesJar()
withJavadocJar()
}
dependencies {
val annotations = "org.jetbrains:annotations:21.0.1"
compileOnly(annotations)
testCompileOnly(annotations)
}
configure<PublishingExtension> {
publications.create<MavenPublication>("maven") {
from(components["java"])
groupId = project.group as String?
artifactId = "Parchment-Common"
version = "1.17-R0.1-SNAPSHOT"
pom {
name.set(project.name)
description.set("Common annotations for Parchment and other software")
}
}
repositories {
maven {
credentials {
username = properties["edenusr"] as String?
password = properties["edenpwd"] as String?
}
url = URI.create("https://sonatype.projecteden.gg/repository/maven-snapshots/")
}
}
}

View File

@@ -1,17 +0,0 @@
package me.lexikiq;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
/**
* Represents an object that has a {@link UUID}
*/
public interface HasUniqueId extends OptionalUniqueId {
/**
* Returns a unique and persistent id for this object
*
* @return unique id
*/
@NotNull UUID getUniqueId(); // named getUniqueId to maintain compatibility with Bukkit
}

View File

@@ -1,17 +0,0 @@
package me.lexikiq;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
/**
* Represents an object that may have a {@link UUID}
*/
public interface OptionalUniqueId {
/**
* Returns a unique and persistent id for this object which may be null
*
* @return unique id or null
*/
@Nullable UUID getUniqueId(); // named getUniqueId to maintain compatibility with Bukkit
}

View File

@@ -3,8 +3,8 @@ import io.papermc.paperweight.util.constants.*
plugins {
java
`maven-publish`
id("com.github.johnrengelman.shadow") version "7.1.0" apply false
id("io.papermc.paperweight.patcher") version "1.2.0"
id("com.github.johnrengelman.shadow") version "7.1.2" apply false
id("io.papermc.paperweight.patcher") version "1.3.7"
}
repositories {
@@ -15,9 +15,9 @@ repositories {
}
dependencies {
remapper("net.fabricmc:tiny-remapper:0.6.0:fat")
decompiler("net.minecraftforge:forgeflower:1.5.498.12")
paperclip("io.papermc:paperclip:2.0.1")
remapper("net.fabricmc:tiny-remapper:0.8.2:fat")
decompiler("net.minecraftforge:forgeflower:1.5.605.7")
paperclip("io.papermc:paperclip:3.0.2")
}
allprojects {
@@ -26,15 +26,15 @@ allprojects {
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(16))
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}
subprojects {
tasks.withType<JavaCompile>().configureEach {
tasks.withType<JavaCompile> {
options.encoding = Charsets.UTF_8.name()
options.release.set(16)
options.release.set(17)
}
tasks.withType<Javadoc> {
options.encoding = Charsets.UTF_8.name()
@@ -46,11 +46,16 @@ subprojects {
repositories {
mavenCentral()
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://sonatype.projecteden.gg/repository/maven-public/")
}
dependencies {
implementation("gg.projecteden:eden-interfaces:2.1.0-SNAPSHOT")
}
}
paperweight {
serverProject.set(project(":Parchment-Server"))
serverProject.set(project(":parchment-server"))
remapRepo.set("https://maven.fabricmc.net/")
decompileRepo.set("https://files.minecraftforge.net/maven/")
@@ -58,10 +63,10 @@ paperweight {
usePaperUpstream(providers.gradleProperty("paperRef")) {
withPaperPatcher {
apiPatchDir.set(layout.projectDirectory.dir("patches/api"))
apiOutputDir.set(layout.projectDirectory.dir("Parchment-API"))
apiOutputDir.set(layout.projectDirectory.dir("parchment-api"))
serverPatchDir.set(layout.projectDirectory.dir("patches/server"))
serverOutputDir.set(layout.projectDirectory.dir("Parchment-Server"))
serverOutputDir.set(layout.projectDirectory.dir("parchment-server"))
}
}
}
@@ -71,16 +76,16 @@ paperweight {
//
tasks.generateDevelopmentBundle {
apiCoordinates.set("me.lexikiq:parchment-api")
apiCoordinates.set("gg.projecteden.parchment:parchment-api")
mojangApiCoordinates.set("io.papermc.paper:paper-mojangapi")
libraryRepositories.set(
listOf(
"https://repo.maven.apache.org/maven2/",
"https://libraries.minecraft.net/",
"https://papermc.io/repo/repository/maven-public/",
"https://maven.quiltmc.org/repository/release/",
"https://sonatype.projecteden.gg/repository/maven-public/"
)
listOf(
"https://repo.maven.apache.org/maven2/",
"https://libraries.minecraft.net/",
"https://papermc.io/repo/repository/maven-public/",
"https://maven.quiltmc.org/repository/release/",
"https://sonatype.projecteden.gg/repository/maven-public/"
)
)
}

53
createUpstreamCommit.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/usr/bin/env bash
# requires curl & jq
# borrowed from https://github.com/PurpurMC/Purpur which is licensed under the MIT license
# createUpstreamCommit --paper HASH
# flag: --paper HASH - the commit hash to use for comparing commits between paper (PaperMC/Paper/compare/HASH...HEAD)
function getCommits() {
echo "$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/"$1"/compare/"$2"...HEAD | jq -r '.commits[] | "'"$1"'@\(.sha[:7]) \(.commit.message | split("\r\n")[0] | split("\n")[0])"')"
}
(
set -e
PS1="$"
paperHash=""
TEMP=$(getopt --long paper: -o "" -- "$@")
eval set -- "$TEMP"
while true; do
case "$1" in
--paper)
paperHash="$2"
shift 2
;;
*)
break
;;
esac
done
paper=""
updated=""
logsuffix=""
# Paper updates
if [ -n "$paperHash" ]; then
paper=$(getCommits "PaperMC/Paper" "$paperHash")
# Updates found
if [ -n "$paper" ]; then
updated="Paper"
logsuffix="$logsuffix\n\nPaper Changes:\n$paper"
fi
fi
disclaimer="Upstream has released updates that appear to apply and compile correctly"
log="Updated Upstream ($updated)\n\n${disclaimer}${logsuffix}"
echo -e "$log" | git commit -a -F -
) || exit 1

View File

@@ -1,9 +1,9 @@
group = me.lexikiq
version = 1.17.1-R0.1-SNAPSHOT
group = gg.projecteden.parchment
version = 1.19-R0.1-SNAPSHOT
mcVersion = 1.17.1
paperRef = 6625db387ea9fe5296a6c6f984975b387c3089f0
mcVersion = 1.19
paperRef = ed9cf5ca087991f38d9926665f268dece213a1e6
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.vfs.watch=false
org.gradle.vfs.watch=false

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -1,18 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: lexikiq <noellekiq@gmail.com>
Date: Fri, 2 Jul 2021 01:33:12 -0400
Subject: [PATCH] Build changes
diff --git a/build.gradle.kts b/build.gradle.kts
index 689d470ebe2c7e25e4c87f6127978d1d283e55b5..2715c109829dbdb93de12b06652988f5cd3353c5 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -39,6 +39,7 @@ dependencies {
apiAndDocs("net.kyori:adventure-text-serializer-plain")
api("org.apache.logging.log4j:log4j-api:2.14.1") // Paper
api("org.slf4j:slf4j-api:1.7.30") // Paper
+ api(project(":Parchment-Common")) // Parchment
implementation("org.ow2.asm:asm:9.1")
implementation("org.ow2.asm:asm-commons:9.1")

View File

@@ -0,0 +1,394 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: lexikiq <noellekiq@gmail.com>
Date: Sat, 19 Jun 2021 22:55:10 -0400
Subject: [PATCH] Add SoundEvent
diff --git a/src/main/java/gg/projecteden/parchment/event/sound/SoundEvent.java b/src/main/java/gg/projecteden/parchment/event/sound/SoundEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..e612cecc89b060a9c0fc882754e45c0409febb9d
--- /dev/null
+++ b/src/main/java/gg/projecteden/parchment/event/sound/SoundEvent.java
@@ -0,0 +1,382 @@
+package gg.projecteden.parchment.event.sound;
+
+import gg.projecteden.parchment.OptionalHumanEntity;
+import net.kyori.adventure.sound.Sound;
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.Event;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+
+/**
+ * Called when a sound is sent to a player.
+ * Cancelling this event will prevent the packet from sending.
+ */
+public final class SoundEvent extends Event implements Cancellable, OptionalHumanEntity {
+ private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(SoundEvent.class);
+
+ private static final org.bukkit.event.HandlerList handlers = new org.bukkit.event.HandlerList();
+ public static final @NotNull Function<Sound, Double> DEFAULT_DISTANCE_FUNCTION = event -> event.volume() > 1.0F ? (double) (16.0F * event.volume()) : 16.0D;
+ public static final @NotNull Function<SoundEvent, List<Player>> DEFAULT_RECIPIENTS_FUNCTION = new WrappedRecipientsFunction(event -> {
+ final double distance = event.calculateDistance();
+ final Location loc = event.getEmitter().location();
+ return loc.getWorld().getPlayers().stream()
+ .filter(player -> {
+ Location pl = player.getLocation();
+ double x = loc.getX() - pl.getX();
+ double y = loc.getY() - pl.getY();
+ double z = loc.getZ() - pl.getZ();
+ return x * x + y * y + z * z < distance * distance;
+ })
+ .toList();
+ });
+
+ private @Nullable HumanEntity except;
+ private @NotNull Function<@NotNull Sound, @NotNull Double> distanceFunction;
+ private @NotNull Function<@NotNull SoundEvent, @NotNull List<@NotNull Player>> recipientsFunction;
+ private @NotNull Sound sound;
+ private @NotNull Emitter emitter;
+ private boolean cancelled;
+ private long seed;
+ private @Nullable BiFunction<@NotNull SoundEvent, @NotNull Player, @Nullable Sound> soundOverrideFunction;
+ private @Nullable BiFunction<@NotNull SoundEvent, @NotNull Player, @Nullable Emitter> emitterOverrideFunction;
+
+ public SoundEvent(@Nullable HumanEntity except, @NotNull Sound sound, @NotNull Emitter emitter, long seed, @Nullable Function<Sound, Double> distanceFunction, @Nullable Function<SoundEvent, List<Player>> recipientsFunction) {
+ super(true);
+ this.except = except;
+ this.sound = Objects.requireNonNull(sound, "sound cannot be null");
+ this.emitter = Objects.requireNonNull(emitter, "emitter cannot be null");
+ this.seed = seed;
+ this.distanceFunction = Objects.requireNonNullElse(distanceFunction, DEFAULT_DISTANCE_FUNCTION);
+ this.recipientsFunction = wrapRecipientsFunction(Objects.requireNonNullElse(recipientsFunction, DEFAULT_RECIPIENTS_FUNCTION));
+ }
+
+ /**
+ * Gets the player that <b>won't</b> be receiving this sound.
+ *
+ * @return player excluded from receiving this sound
+ * @deprecated use {@link #getException()} for more clarity
+ */
+ @Override
+ @Deprecated
+ public @Nullable HumanEntity getPlayer() {
+ return getException();
+ }
+
+ /**
+ * Gets the player that <b>won't</b> be receiving this sound.
+ *
+ * @return player excluded from receiving this sound
+ */
+ public @Nullable HumanEntity getException() {
+ return except;
+ }
+
+ /**
+ * Sets the player that <b>won't</b> be receiving this sound.
+ *
+ * @param except player excluded from receiving this sound
+ */
+ public void setException(@Nullable HumanEntity except) {
+ this.except = except;
+ }
+
+ /**
+ * Gets the sound that will be sent.
+ *
+ * @return sound that will be sent
+ */
+ public @NotNull Sound getSound() {
+ return sound;
+ }
+
+ /**
+ * Sets the sound that will be sent.
+ *
+ * @param sound sound that will be sent
+ */
+ public void setSound(@NotNull Sound sound) {
+ this.sound = Objects.requireNonNull(sound, "sound cannot be null");
+ }
+
+ /**
+ * Gets the emitter which determines how and where the sound will be played from.
+ *
+ * @return emitter which determines how and where the sound will be played from
+ */
+ public @NotNull Emitter getEmitter() {
+ return emitter;
+ }
+
+ /**
+ * Sets the emitter which determines how and where the sound will be played from.
+ *
+ * @param emitter emitter which determines how and where the sound will be played from
+ */
+ public void setEmitter(@NotNull Emitter emitter) {
+ this.emitter = Objects.requireNonNull(emitter, "emitter cannot be null");
+ }
+
+ /**
+ * Gets the seed used to generate the sound.
+ *
+ * @return seed used to generate the sound
+ */
+ public long getSeed() {
+ return seed;
+ }
+
+ /**
+ * Sets the seed used to generate the sound.
+ *
+ * @param seed seed used to generate the sound
+ */
+ public void setSeed(long seed) {
+ this.seed = seed;
+ }
+
+ /**
+ * Calculates the distance of the sound.
+ * <p>
+ * The distance value is dynamically calculated using a
+ * {@link Function Function&lt;SoundEvent, Double&gt;}.
+ * In vanilla Minecraft, the default function is {@link #DEFAULT_DISTANCE_FUNCTION}
+ * ({@code event -> event.getVolume() > 1.0F ? (double) (16.0F * event.getVolume()) : 16.0D}).
+ * </p>
+ * This is used by the vanilla implementation of {@link #calculateRecipients()}, though custom
+ * implementations won't always use this method.
+ *
+ * @return calculated distance
+ * @see #getDistanceFunction()
+ * @see #setDistanceFunction(Function)
+ */
+ public double calculateDistance() {
+ return distanceFunction.apply(sound);
+ }
+
+ /**
+ * Gets the function that calculates the distance of the sound.
+ *
+ * @return distance function
+ * @see #calculateDistance()
+ * @see #setDistanceFunction(Function)
+ */
+ public @NotNull Function<@NotNull Sound, @NotNull Double> getDistanceFunction() {
+ return distanceFunction;
+ }
+
+ /**
+ * Sets the function that calculates the distance of the sound.
+ *
+ * @param distanceFunction distance function
+ * @see #calculateDistance()
+ * @see #getDistanceFunction()
+ */
+ public void setDistanceFunction(@NotNull Function<@NotNull Sound, @NotNull Double> distanceFunction) {
+ this.distanceFunction = Objects.requireNonNull(distanceFunction, "distanceFunction cannot be null");
+ }
+
+ /**
+ * Determines which players will receive this sound packet.
+ *
+ * @return immutable list of players
+ * @see #getRecipientsFunction()
+ * @see #setRecipientsFunction(Function)
+ */
+ public @NotNull List<Player> calculateRecipients() {
+ return recipientsFunction.apply(this);
+ }
+
+ /**
+ * Gets the function that determines which players will receive the sound packet.
+ *
+ * @return recipients function
+ * @see #calculateRecipients()
+ * @see #setRecipientsFunction(Function)
+ */
+ public @NotNull Function<@NotNull SoundEvent, @NotNull List<@NotNull Player>> getRecipientsFunction() {
+ return recipientsFunction;
+ }
+
+ /**
+ * Sets the function that determines which players will receive the sound packet.
+ * <p>
+ * This function does not need to query {@link #getException()} as this is done automatically.
+ *
+ * @param recipientsFunction recipients function
+ * @see #calculateRecipients()
+ * @see #getRecipientsFunction()
+ */
+ public void setRecipientsFunction(@NotNull Function<@NotNull SoundEvent, @NotNull List<@NotNull Player>> recipientsFunction) {
+ this.recipientsFunction = wrapRecipientsFunction(Objects.requireNonNull(recipientsFunction, "recipientsFunction cannot be null"));
+ }
+
+ /**
+ * Gets the function that overrides what {@link Sound} is sent to a {@link Player}.
+ *
+ * @return sound override function (or {@code null} if not overridden)
+ */
+ public @Nullable BiFunction<@NotNull SoundEvent, @NotNull Player, @Nullable Sound> getSoundOverrideFunction() {
+ return soundOverrideFunction;
+ }
+
+ /**
+ * Sets the function that overrides what {@link Sound} is sent to a {@link Player}.
+ *
+ * @param soundOverrideFunction function which accepts a sound event and a player and returns
+ * a sound (or {@code null} if the default sound should be used)
+ */
+ public void setSoundOverrideFunction(@Nullable BiFunction<@NotNull SoundEvent, @NotNull Player, @Nullable Sound> soundOverrideFunction) {
+ this.soundOverrideFunction = soundOverrideFunction;
+ }
+
+ /**
+ * Calculates the sound that will be sent to a {@link Player}.
+ *
+ * @param player player to calculate the sound for
+ * @return sound that will be sent to the player
+ */
+ public @NotNull Sound calculateSound(@NotNull Player player) {
+ if (soundOverrideFunction != null) {
+ try {
+ Sound override = soundOverrideFunction.apply(this, player);
+ if (override != null) {
+ return override;
+ }
+ } catch (Throwable e) {
+ LOGGER.error("Error while overriding sound for player " + player.getName(), e);
+ }
+ }
+ return sound;
+ }
+
+ /**
+ * Gets the function that overrides what {@link Emitter} is used when playing this sound to a
+ * {@link Player}.
+ *
+ * @return emitter override function (or {@code null} if not overridden)
+ */
+ public @Nullable BiFunction<@NotNull SoundEvent, @NotNull Player, @Nullable Emitter> getEmitterOverrideFunction() {
+ return emitterOverrideFunction;
+ }
+
+ /**
+ * Sets the function that overrides what {@link Emitter} is used when playing this sound to a
+ * {@link Player}.
+ *
+ * @param emitterOverrideFunction function which accepts a sound event and a player and returns
+ * an emitter
+ * (or {@code null} if the default emitter should be used)
+ */
+ public void setEmitterOverrideFunction(@Nullable BiFunction<@NotNull SoundEvent, @NotNull Player, @Nullable Emitter> emitterOverrideFunction) {
+ this.emitterOverrideFunction = emitterOverrideFunction;
+ }
+
+ /**
+ * Calculates the emitter that will be used when playing this sound to a {@link Player}.
+ *
+ * @param player player to calculate the emitter for
+ * @return emitter that will be used when playing the sound to the player
+ */
+ public @NotNull Emitter calculateEmitter(@NotNull Player player) {
+ if (emitterOverrideFunction != null) {
+ try {
+ Emitter override = emitterOverrideFunction.apply(this, player);
+ if (override != null) {
+ return override;
+ }
+ } catch (Throwable e) {
+ LOGGER.error("Error while overriding emitter for player " + player.getName(), e);
+ }
+ }
+ return emitter;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancelled) {
+ this.cancelled = cancelled;
+ }
+
+ @NotNull
+ public static org.bukkit.event.HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ @Override
+ public @NotNull org.bukkit.event.HandlerList getHandlers() {
+ return handlers;
+ }
+
+ private record WrappedRecipientsFunction(@NotNull Function<SoundEvent, List<Player>> wrapped) implements Function<SoundEvent, List<Player>> {
+ @Override
+ public List<Player> apply(SoundEvent event) {
+ List<Player> recipients = wrapped.apply(event);
+ HumanEntity except = event.getException();
+ if (except != null) {
+ List<Player> filteredRecipients = new ArrayList<>(recipients.size());
+ for (Player player : recipients) {
+ if (!player.getUniqueId().equals(except.getUniqueId()))
+ filteredRecipients.add(player);
+ }
+ return filteredRecipients;
+ }
+ return recipients;
+ }
+ }
+
+ @NotNull
+ private static Function<SoundEvent, List<Player>> wrapRecipientsFunction(@NotNull Function<SoundEvent, List<Player>> recipientsFunction) {
+ if (recipientsFunction instanceof WrappedRecipientsFunction)
+ return recipientsFunction;
+ else
+ return new WrappedRecipientsFunction(recipientsFunction);
+ }
+
+ /**
+ * The class which determines where a sound will emit from.
+ */
+ public sealed interface Emitter permits EntityEmitter, LocationEmitter {
+ /**
+ * Gets the location at which the sound will be played.
+ *
+ * @return sound's location
+ */
+ @NotNull
+ Location location();
+ }
+
+ /**
+ * An emitter which plays a sound from an entity.
+ *
+ * @param entity the entity from which the sound will be played
+ */
+ public record EntityEmitter(@NotNull Entity entity) implements Emitter {
+ @Override
+ public @NotNull Location location() {
+ return entity.getLocation();
+ }
+ }
+
+ /**
+ * An emitter which plays a sound from a location.
+ *
+ * @param location the location from which the sound will be played
+ */
+ public record LocationEmitter(@NotNull Location location) implements Emitter {
+ }
+}

View File

@@ -4,13 +4,13 @@ Date: Thu, 13 May 2021 23:55:02 -0400
Subject: [PATCH] Add PlayerUseRespawnAnchorEvent
diff --git a/src/main/java/me/lexikiq/event/player/PlayerUseRespawnAnchorEvent.java b/src/main/java/me/lexikiq/event/player/PlayerUseRespawnAnchorEvent.java
diff --git a/src/main/java/gg/projecteden/parchment/event/player/PlayerUseRespawnAnchorEvent.java b/src/main/java/gg/projecteden/parchment/event/player/PlayerUseRespawnAnchorEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..fcf552bb84a10794dda178b337768efe4781facd
index 0000000000000000000000000000000000000000..c2dfb2e8dfe6462b12c2425225d2f7a66a53de8b
--- /dev/null
+++ b/src/main/java/me/lexikiq/event/player/PlayerUseRespawnAnchorEvent.java
+++ b/src/main/java/gg/projecteden/parchment/event/player/PlayerUseRespawnAnchorEvent.java
@@ -0,0 +1,117 @@
+package me.lexikiq.event.player;
+package gg.projecteden.parchment.event.player;
+
+import com.google.common.base.Preconditions;
+import org.bukkit.block.Block;

View File

@@ -1,721 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: lexikiq <noellekiq@gmail.com>
Date: Sat, 19 Jun 2021 22:55:10 -0400
Subject: [PATCH] Add SoundEvent
diff --git a/src/main/java/me/lexikiq/event/sound/EntitySoundEvent.java b/src/main/java/me/lexikiq/event/sound/EntitySoundEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..19c9f7af91402d5f966915ebc80d76ab9ac92872
--- /dev/null
+++ b/src/main/java/me/lexikiq/event/sound/EntitySoundEvent.java
@@ -0,0 +1,67 @@
+package me.lexikiq.event.sound;
+
+import org.apache.commons.lang.Validate;
+import org.bukkit.Sound;
+import org.bukkit.SoundCategory;
+import org.bukkit.World;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Called when an entity sound is sent to a player.
+ * Cancelling this event will prevent the packet from sending.
+ * <p>
+ * This type of sound represents one that will follow the {@link #getOrigin() originating} entity.
+ */
+public class EntitySoundEvent extends NamedSoundEvent {
+ private @NotNull Entity origin;
+
+ @Deprecated
+ public EntitySoundEvent(@Nullable HumanEntity except, @NotNull Entity origin, @NotNull Sound sound, @NotNull SoundCategory category, float volume, float pitch) {
+ this(except, origin, sound, category, volume, pitch, null, null);
+ }
+
+ public EntitySoundEvent(@Nullable HumanEntity except, @NotNull Entity origin, @NotNull Sound sound, @NotNull SoundCategory category, float volume, float pitch, @Nullable Function<SoundEvent, Double> distanceFunction, @Nullable Function<SoundEvent, List<Player>> recipientsFunction) {
+ super(except, sound, category, volume, pitch, distanceFunction, recipientsFunction);
+ this.origin = Objects.requireNonNull(origin, "origin cannot be null");
+ }
+
+ /**
+ * Gets the entity that the sound is originating from.
+ *
+ * @return originating entity
+ */
+ public @NotNull Entity getOrigin() {
+ return origin;
+ }
+
+ /**
+ * Sets the entity that the sound will originate from.
+ *
+ * @param origin originating entity
+ */
+ public void setOrigin(@NotNull Entity origin) {
+ Validate.notNull(origin, "origin cannot be null");
+ if (!this.origin.getWorld().equals(origin.getWorld()))
+ throw new IllegalArgumentException("Entity must be in same world as originating location");
+ this.origin = origin;
+ }
+
+ @Override
+ public @NotNull World getWorld() {
+ return origin.getWorld();
+ }
+
+ @Override
+ public @NotNull Vector getPosition() {
+ return origin.getLocation().toVector();
+ }
+}
diff --git a/src/main/java/me/lexikiq/event/sound/LocationCustomSoundEvent.java b/src/main/java/me/lexikiq/event/sound/LocationCustomSoundEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..9d7f3656c55a0bb7a8258a0418954563f8730551
--- /dev/null
+++ b/src/main/java/me/lexikiq/event/sound/LocationCustomSoundEvent.java
@@ -0,0 +1,139 @@
+package me.lexikiq.event.sound;
+
+import me.lexikiq.HasLocation;
+import org.apache.commons.lang.Validate;
+import org.bukkit.Keyed;
+import org.bukkit.Location;
+import org.bukkit.NamespacedKey;
+import org.bukkit.SoundCategory;
+import org.bukkit.World;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Called when a sound not available in {@link org.bukkit.Sound} is sent to a player from a
+ * {@link Location}. Cancelling this event will prevent the packet from sending.
+ */
+public class LocationCustomSoundEvent extends SoundEvent implements Keyed, HasLocation {
+ private @NotNull World world;
+ private @NotNull Vector vector;
+ private @NotNull NamespacedKey key;
+
+ @Deprecated
+ public LocationCustomSoundEvent(@Nullable HumanEntity except,
+ @NotNull World world,
+ @NotNull Vector vector,
+ @NotNull NamespacedKey key,
+ @NotNull SoundCategory category,
+ float volume,
+ float pitch) {
+ this(except, world, vector, key, category, volume, pitch, null, null);
+ }
+
+ @Deprecated
+ public LocationCustomSoundEvent(@Nullable HumanEntity except,
+ @NotNull Location location,
+ @NotNull NamespacedKey key,
+ @NotNull SoundCategory category,
+ float volume,
+ float pitch) {
+ this(except, location, key, category, volume, pitch, null, null);
+ }
+
+ public LocationCustomSoundEvent(@Nullable HumanEntity except,
+ @NotNull World world,
+ @NotNull Vector vector,
+ @NotNull NamespacedKey key,
+ @NotNull SoundCategory category,
+ float volume,
+ float pitch,
+ @Nullable Function<SoundEvent, Double> distanceFunction,
+ @Nullable Function<SoundEvent, List<Player>> recipientsFunction) {
+ super(except, category, volume, pitch, distanceFunction, recipientsFunction);
+ this.world = Objects.requireNonNull(world, "world cannot be null");
+ this.vector = Objects.requireNonNull(vector, "vector cannot be null");
+ this.key = Objects.requireNonNull(key, "key cannot be null");
+ }
+
+ public LocationCustomSoundEvent(@Nullable HumanEntity except,
+ @NotNull Location location,
+ @NotNull NamespacedKey key,
+ @NotNull SoundCategory category,
+ float volume,
+ float pitch,
+ @Nullable Function<SoundEvent, Double> distanceFunction,
+ @Nullable Function<SoundEvent, List<Player>> recipientsFunction) {
+ this(except, checkNotNull(location, "location").getWorld(), location.toVector(), key, category, volume, pitch, distanceFunction, recipientsFunction);
+ }
+
+ @Override
+ public @NotNull Vector getPosition() {
+ return vector;
+ }
+
+ /**
+ * Sets the position of the sound.
+ *
+ * @param position position in the world
+ */
+ public void setPosition(@NotNull Vector position) {
+ this.vector = Objects.requireNonNull(position, "position cannot be null");
+ }
+
+ /**
+ * Sets the position of the sound.
+ *
+ * @param vector position in the world
+ * @deprecated use {@link #setPosition(Vector)} instead
+ */
+ @Deprecated
+ public void setVector(@NotNull Vector vector) {
+ setPosition(vector);
+ }
+
+ /**
+ * Gets the resource pack key of the sound.
+ *
+ * @return asset key
+ */
+ public @NotNull NamespacedKey getKey() {
+ return key;
+ }
+
+ // boilerplate
+
+ /**
+ * Sets the resource pack key of the sound.
+ *
+ * @param key asset key
+ */
+ public void setKey(@NotNull NamespacedKey key) {
+ this.key = Objects.requireNonNull(key, "key cannot be null");
+ }
+
+ @Override
+ public @NotNull World getWorld() {
+ return world;
+ }
+
+ /**
+ * Sets the world in which the sound is played.
+ * <p>
+ * This may not have an effect if the {@link #getRecipientsFunction()} has been modified.
+ *
+ * @param world world to play the sound in
+ */
+ public void setWorld(@NotNull World world) {
+ this.world = Objects.requireNonNull(world, "world cannot be null");
+ }
+}
diff --git a/src/main/java/me/lexikiq/event/sound/LocationNamedSoundEvent.java b/src/main/java/me/lexikiq/event/sound/LocationNamedSoundEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..7f42c904362107c55cc5877eab1b513bcdf34571
--- /dev/null
+++ b/src/main/java/me/lexikiq/event/sound/LocationNamedSoundEvent.java
@@ -0,0 +1,112 @@
+package me.lexikiq.event.sound;
+
+import me.lexikiq.HasLocation;
+import org.bukkit.Location;
+import org.bukkit.Sound;
+import org.bukkit.SoundCategory;
+import org.bukkit.World;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Called when a sound available in {@link Sound} is sent to a {@link Location}.
+ * Cancelling this event will prevent the packet from sending.
+ */
+public class LocationNamedSoundEvent extends NamedSoundEvent implements HasLocation {
+ private @NotNull World world;
+ private @NotNull Vector vector;
+
+ @Deprecated
+ public LocationNamedSoundEvent(@Nullable HumanEntity except,
+ @NotNull World world,
+ @NotNull Vector vector,
+ @NotNull Sound sound,
+ @NotNull SoundCategory category,
+ float volume,
+ float pitch) {
+ this(except, world, vector, sound, category, volume, pitch, null, null);
+ }
+
+ @Deprecated
+ public LocationNamedSoundEvent(@Nullable HumanEntity except,
+ @NotNull Location location,
+ @NotNull Sound sound,
+ @NotNull SoundCategory category,
+ float volume,
+ float pitch) {
+ this(except, location, sound, category, volume, pitch, null, null);
+ }
+
+ public LocationNamedSoundEvent(@Nullable HumanEntity except,
+ @NotNull World world,
+ @NotNull Vector vector,
+ @NotNull Sound sound,
+ @NotNull SoundCategory category,
+ float volume,
+ float pitch,
+ @Nullable Function<SoundEvent, Double> distanceFunction,
+ @Nullable Function<SoundEvent, List<Player>> recipientsFunction) {
+ super(except, sound, category, volume, pitch, distanceFunction, recipientsFunction);
+ this.world = Objects.requireNonNull(world, "world cannot be null");
+ this.vector = Objects.requireNonNull(vector, "vector cannot be null");
+ }
+
+ public LocationNamedSoundEvent(@Nullable HumanEntity except,
+ @NotNull Location location,
+ @NotNull Sound sound,
+ @NotNull SoundCategory category,
+ float volume,
+ float pitch,
+ @Nullable Function<SoundEvent, Double> distanceFunction,
+ @Nullable Function<SoundEvent, List<Player>> recipientsFunction) {
+ this(except, Objects.requireNonNull(location, "location cannot be null").getWorld(), location.toVector(), sound, category, volume, pitch, distanceFunction, recipientsFunction);
+ }
+
+ @Override
+ public @NotNull Vector getPosition() {
+ return vector;
+ }
+
+ /**
+ * Sets the position of the sound.
+ *
+ * @param position position in the world
+ */
+ public void setPosition(@NotNull Vector position) {
+ this.vector = Objects.requireNonNull(position, "position cannot be null");
+ }
+
+ /**
+ * Sets the position of the sound.
+ *
+ * @param vector position in the world
+ * @deprecated use {@link #setPosition(Vector)} instead
+ */
+ @Deprecated
+ public void setVector(@NotNull Vector vector) {
+ setPosition(vector);
+ }
+
+ @Override
+ public @NotNull World getWorld() {
+ return world;
+ }
+
+ /**
+ * Sets the world in which the sound is played.
+ * <p>
+ * This may not have an effect if the {@link #getRecipientsFunction()} has been modified.
+ *
+ * @param world world to play the sound in
+ */
+ public void setWorld(@NotNull World world) {
+ this.world = Objects.requireNonNull(world, "world cannot be null");
+ }
+}
diff --git a/src/main/java/me/lexikiq/event/sound/NamedSoundEvent.java b/src/main/java/me/lexikiq/event/sound/NamedSoundEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..3ca767cfeb7fc0982830e49cde6bb0e87075c3f9
--- /dev/null
+++ b/src/main/java/me/lexikiq/event/sound/NamedSoundEvent.java
@@ -0,0 +1,54 @@
+package me.lexikiq.event.sound;
+
+import org.apache.commons.lang.Validate;
+import org.bukkit.Sound;
+import org.bukkit.SoundCategory;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Called when a sound available in {@link Sound} is sent to a player.
+ * Cancelling this event will prevent the packet from sending.
+ */
+public abstract class NamedSoundEvent extends SoundEvent {
+ private @NotNull Sound sound;
+
+
+ @Deprecated
+ protected NamedSoundEvent(@Nullable HumanEntity except, @NotNull Sound sound, @NotNull SoundCategory category, float volume, float pitch) {
+ super(except, category, volume, pitch);
+ this.sound = Objects.requireNonNull(sound, "sound cannot be null");
+ }
+
+ public NamedSoundEvent(@Nullable HumanEntity except, @NotNull Sound sound, @NotNull SoundCategory category, float volume, float pitch, @Nullable Function<SoundEvent, Double> distanceFunction, @Nullable Function<SoundEvent, List<Player>> recipientsFunction) {
+ super(except, category, volume, pitch, distanceFunction, recipientsFunction);
+ this.sound = Objects.requireNonNull(sound, "sound cannot be null");
+ }
+
+ // boilerplate
+
+ /**
+ * Gets the sound being played.
+ *
+ * @return sound to play
+ */
+ public @NotNull Sound getSound() {
+ return sound;
+ }
+
+ /**
+ * Sets the sound to be played.
+ *
+ * @param sound sound to play
+ */
+ public void setSound(@NotNull Sound sound) {
+ this.sound = Objects.requireNonNull(sound, "sound cannot be null");
+ }
+}
diff --git a/src/main/java/me/lexikiq/event/sound/SoundEvent.java b/src/main/java/me/lexikiq/event/sound/SoundEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..6cc614b9e1b187f43433d13624d74672c97c2174
--- /dev/null
+++ b/src/main/java/me/lexikiq/event/sound/SoundEvent.java
@@ -0,0 +1,313 @@
+package me.lexikiq.event.sound;
+
+import me.lexikiq.OptionalHumanEntity;
+import org.apache.commons.lang.Validate;
+import org.bukkit.Location;
+import org.bukkit.SoundCategory;
+import org.bukkit.World;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.Event;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Called when a sound is sent to a player.
+ * Cancelling this event will prevent the packet from sending.
+ */
+// TODO 1.18: use sealed class
+public abstract class SoundEvent extends Event implements Cancellable, OptionalHumanEntity {
+
+ private static final org.bukkit.event.HandlerList handlers = new org.bukkit.event.HandlerList();
+ public static final @NotNull Function<SoundEvent, Double> DEFAULT_DISTANCE_FUNCTION = event -> event.getVolume() > 1.0F ? (double) (16.0F * event.getVolume()) : 16.0D;
+ public static final @NotNull Function<SoundEvent, List<Player>> DEFAULT_RECIPIENTS_FUNCTION = new WrappedRecipientsFunction(event -> {
+ final double distance = event.calculateDistance();
+ return event.getWorld().getPlayers().stream()
+ .filter(player -> {
+ Location pl = player.getLocation();
+ Vector sv = event.getPosition();
+ double x = sv.getX() - pl.getX();
+ double y = sv.getY() - pl.getY();
+ double z = sv.getZ() - pl.getZ();
+ return x * x + y * y + z * z < distance * distance;
+ })
+ .toList();
+ });
+
+ private @Nullable HumanEntity except;
+ private @NotNull Function<@NotNull SoundEvent, @NotNull Double> distanceFunction;
+ private @NotNull Function<@NotNull SoundEvent, @NotNull List<@NotNull Player>> recipientsFunction;
+ // <end to-do>
+ private @NotNull SoundCategory category;
+ private float volume;
+ private float pitch;
+ private boolean cancelled;
+
+ @Deprecated
+ protected SoundEvent(@Nullable HumanEntity except, @NotNull SoundCategory category, float volume, float pitch) {
+ this(except, category, volume, pitch, null, null);
+ }
+
+ protected SoundEvent(@Nullable HumanEntity except, @NotNull SoundCategory category, float volume, float pitch, @Nullable Function<SoundEvent, Double> distanceFunction, @Nullable Function<SoundEvent, List<Player>> recipientsFunction) {
+ super(true);
+ this.except = except;
+ this.category = Objects.requireNonNull(category, "category cannot be null");
+ this.volume = volume;
+ this.pitch = pitch;
+ this.distanceFunction = Objects.requireNonNullElse(distanceFunction, DEFAULT_DISTANCE_FUNCTION);
+ this.recipientsFunction = wrapRecipientsFunction(Objects.requireNonNullElse(recipientsFunction, DEFAULT_RECIPIENTS_FUNCTION));
+ }
+
+ /**
+ * Gets the player that <b>won't</b> be receiving this sound.
+ *
+ * @return player excluded from receiving this sound
+ * @deprecated use {@link #getException()} for more clarity
+ */
+ @Override
+ @Deprecated
+ public @Nullable HumanEntity getPlayer() {
+ return getException();
+ }
+
+ /**
+ * Gets the player that <b>won't</b> be receiving this sound.
+ *
+ * @return player excluded from receiving this sound
+ */
+ public @Nullable HumanEntity getException() {
+ return except;
+ }
+
+ /**
+ * Sets the player that <b>won't</b> be receiving this sound.
+ *
+ * @param except player excluded from receiving this sound
+ */
+ public void setException(@Nullable HumanEntity except) {
+ this.except = except;
+ }
+
+ /**
+ * Gets the category of sounds this will be played with.
+ *
+ * @return category of sounds
+ */
+ public @NotNull SoundCategory getCategory() {
+ return category;
+ }
+
+ /**
+ * Sets the category of sounds this will be played with.
+ *
+ * @param category category of sounds
+ */
+ public void setCategory(@NotNull SoundCategory category) {
+ this.category = Objects.requireNonNull(category, "category cannot be null");
+ }
+
+ /**
+ * Gets the volume of the sound to be played. Should be non-negative.
+ *
+ * @return sound volume
+ */
+ public float getVolume() {
+ return volume;
+ }
+
+ /**
+ * Sets the volume of the sound to be played. Must be non-negative.
+ *
+ * @param volume sound volume
+ */
+ public void setVolume(float volume) {
+ Validate.isTrue(volume >= 0, "volume should be non-negative");
+ this.volume = volume;
+ }
+
+ /**
+ * Gets the pitch of the sound to be played. Should be within the range [0,2].
+ *
+ * @return sound pitch
+ */
+ public float getPitch() {
+ return pitch;
+ }
+
+ /**
+ * Sets the pitch of the sound to be played. Must be within the range [0,2].
+ *
+ * @param pitch sound pitch
+ */
+ public void setPitch(float pitch) {
+ Validate.isTrue(pitch >= 0 && pitch <= 2, "pitch should be within range [0,2]");
+ this.pitch = pitch;
+ }
+
+ /**
+ * Calculates the distance of the sound.
+ * <p>
+ * The distance value is dynamically calculated using a
+ * {@link Function Function&lt;SoundEvent, Double&gt;}.
+ * In vanilla Minecraft, the default function is {@link #DEFAULT_DISTANCE_FUNCTION}
+ * ({@code event -> event.getVolume() > 1.0F ? (double) (16.0F * event.getVolume()) : 16.0D}).
+ * </p>
+ * This is used by the vanilla implementation of {@link #calculateRecipients()}, though custom
+ * implementations won't always use this method.
+ *
+ * @return calculated distance
+ * @see #getDistanceFunction()
+ * @see #setDistanceFunction(Function)
+ */
+ public double calculateDistance() {
+ return distanceFunction.apply(this);
+ }
+
+ /**
+ * Gets the function that calculates the distance of the sound.
+ *
+ * @return distance function
+ * @see #calculateDistance()
+ * @see #setDistanceFunction(Function)
+ */
+ public @NotNull Function<@NotNull SoundEvent, @NotNull Double> getDistanceFunction() {
+ return distanceFunction;
+ }
+
+ /**
+ * Sets the function that calculates the distance of the sound.
+ *
+ * @param distanceFunction distance function
+ * @see #calculateDistance()
+ * @see #getDistanceFunction()
+ */
+ public void setDistanceFunction(@NotNull Function<@NotNull SoundEvent, @NotNull Double> distanceFunction) {
+ this.distanceFunction = Objects.requireNonNull(distanceFunction, "distanceFunction cannot be null");
+ }
+
+ /**
+ * Determines which players will receive this sound packet.
+ *
+ * @return immutable list of players
+ * @see #getRecipientsFunction()
+ * @see #setRecipientsFunction(Function)
+ */
+ public @NotNull List<Player> calculateRecipients() {
+ return recipientsFunction.apply(this);
+ }
+
+ /**
+ * Gets the function that determines which players will receive the sound packet.
+ *
+ * @return recipients function
+ * @see #calculateRecipients()
+ * @see #setRecipientsFunction(Function)
+ */
+ public @NotNull Function<@NotNull SoundEvent, @NotNull List<@NotNull Player>> getRecipientsFunction() {
+ return recipientsFunction;
+ }
+
+ /**
+ * Sets the function that determines which players will receive the sound packet.
+ * <p>
+ * This function does not need to query {@link #getException()} as this is done automatically.
+ *
+ * @param recipientsFunction recipients function
+ * @see #calculateRecipients()
+ * @see #getRecipientsFunction()
+ */
+ public void setRecipientsFunction(@NotNull Function<@NotNull SoundEvent, @NotNull List<@NotNull Player>> recipientsFunction) {
+ this.recipientsFunction = wrapRecipientsFunction(Objects.requireNonNull(recipientsFunction, "recipientsFunction cannot be null"));
+ }
+
+ /**
+ * Gets the world in which the sound is being played.
+ *
+ * @return sound's world
+ */
+ @NotNull
+ public abstract World getWorld();
+
+ /**
+ * Gets the position at which the sound is being played.
+ *
+ * @return sound's position
+ */
+ @NotNull
+ public abstract Vector getPosition();
+
+ /**
+ * Gets the position at which the sound is being played.
+ *
+ * @return sound's position
+ * @deprecated use {@link #getPosition()} instead for clarity
+ */
+ @Deprecated
+ @NotNull
+ public Vector getVector() {
+ return getPosition();
+ }
+
+ /**
+ * Gets the location of the sound being played.
+ *
+ * @return copy of sound location
+ * @see #getPosition()
+ */
+ public @NotNull Location getLocation() {
+ Vector pos = getPosition();
+ return new Location(getWorld(), pos.getX(), pos.getY(), pos.getZ());
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancelled) {
+ this.cancelled = cancelled;
+ }
+
+ @NotNull
+ public static org.bukkit.event.HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ @Override
+ public @NotNull org.bukkit.event.HandlerList getHandlers() {
+ return handlers;
+ }
+
+ private record WrappedRecipientsFunction(@NotNull Function<SoundEvent, List<Player>> wrapped) implements Function<SoundEvent, List<Player>> {
+ @Override
+ public List<Player> apply(SoundEvent event) {
+ List<Player> recipients = wrapped.apply(event);
+ HumanEntity except = event.getException();
+ if (except != null) {
+ List<Player> filteredRecipients = new ArrayList<>(recipients.size());
+ for (Player player : recipients) {
+ if (!player.getUniqueId().equals(except.getUniqueId()))
+ filteredRecipients.add(player);
+ }
+ return filteredRecipients;
+ }
+ return recipients;
+ }
+ }
+
+ @NotNull
+ private static Function<SoundEvent, List<Player>> wrapRecipientsFunction(@NotNull Function<SoundEvent, List<Player>> recipientsFunction) {
+ if (recipientsFunction instanceof WrappedRecipientsFunction)
+ return recipientsFunction;
+ else
+ return new WrappedRecipientsFunction(recipientsFunction);
+ }
+}

View File

@@ -6,7 +6,7 @@ Subject: [PATCH] Expanded Adventure support
Adds support for Adventure in a few places where it was previously missing.
diff --git a/src/main/java/org/bukkit/ChatColor.java b/src/main/java/org/bukkit/ChatColor.java
index 4594701d77c5d0f744bece871b98d9f6f73eb5a7..136f87f6cd2f3a56cfa645084fd6446a20f2e88e 100644
index f6eb30f53dad684f156102cf7147b2f00c82c71e..1b4e9840f0e829be533ad0bd1c918489642245c2 100644
--- a/src/main/java/org/bukkit/ChatColor.java
+++ b/src/main/java/org/bukkit/ChatColor.java
@@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
@@ -120,10 +120,10 @@ index 4594701d77c5d0f744bece871b98d9f6f73eb5a7..136f87f6cd2f3a56cfa645084fd6446a
* Gets the char value associated with this color
*
diff --git a/src/main/java/org/bukkit/Color.java b/src/main/java/org/bukkit/Color.java
index deae003b7e9a96bbf1c0167d3e1d864e61b07f82..53afcd97fc34bceff741ee118f63226781f9c895 100644
index d2f8f5a8e49f60422b6a41e51248a6710251d61b..40b09a861ba365b126c2b28bb7f18c8fb8b3e5b5 100644
--- a/src/main/java/org/bukkit/Color.java
+++ b/src/main/java/org/bukkit/Color.java
@@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
@@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
* but subject to change.
*/
@SerializableAs("Color")
@@ -132,7 +132,7 @@ index deae003b7e9a96bbf1c0167d3e1d864e61b07f82..53afcd97fc34bceff741ee118f632267
private static final int BIT_MASK = 0xff;
/**
@@ -242,6 +242,13 @@ public final class Color implements ConfigurationSerializable {
@@ -244,6 +244,13 @@ public final class Color implements ConfigurationSerializable {
return getRed() << 16 | getGreen() << 8 | getBlue() << 0;
}
@@ -188,28 +188,3 @@ index bd213cabddd8752e609544f24cfba95405726155..7e89cadecde96f9c2394446669dc4d98
/**
* Gets the DyeColor with the given wool data value.
*
diff --git a/src/main/java/org/bukkit/Keyed.java b/src/main/java/org/bukkit/Keyed.java
index 32c92621c2c15eec14c50965f5ecda00c46e6c80..3876a03ab9df9a0aef7a5c05a38b39b07a6dd285 100644
--- a/src/main/java/org/bukkit/Keyed.java
+++ b/src/main/java/org/bukkit/Keyed.java
@@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull;
/**
* Represents an object which has a {@link NamespacedKey} attached to it.
*/
-public interface Keyed {
+public interface Keyed extends net.kyori.adventure.key.Keyed { // Parchment
/**
* Return the namespaced identifier for this object.
@@ -14,4 +14,11 @@ public interface Keyed {
*/
@NotNull
NamespacedKey getKey();
+
+ // Parchment start
+ @Override
+ default net.kyori.adventure.key.@org.checkerframework.checker.nullness.qual.NonNull Key key() {
+ return getKey();
+ }
+ // Parchment end
}

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Add UnsafeValues#canPlaceItemOn
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 014c9984018ad5e51a26228a137e1ba4eb3e80c8..5606c09f62b7ad0cf33bb507d71830581114afd4 100644
index 4fcafddf3792b66c618f91e04d102f374de565a8..716d5371c0ceb5b97c7008a6ac0c7ddf58b01a9f 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -218,4 +218,17 @@ public interface UnsafeValues {
@@ -243,4 +243,17 @@ public interface UnsafeValues {
*/
boolean isCollidable(@org.jetbrains.annotations.NotNull Material material);
// Paper end
@@ -23,6 +23,6 @@ index 014c9984018ad5e51a26228a137e1ba4eb3e80c8..5606c09f62b7ad0cf33bb507d7183058
+ * @param face cardinal direction
+ * @return if the item can be placed
+ */
+ java.util.concurrent.CompletableFuture<Boolean> canPlaceItemOn(@org.jetbrains.annotations.NotNull ItemStack item, @org.jetbrains.annotations.Nullable me.lexikiq.OptionalHumanEntity player, @org.jetbrains.annotations.NotNull org.bukkit.block.Block block, @org.jetbrains.annotations.NotNull org.bukkit.block.BlockFace face);
+ java.util.concurrent.CompletableFuture<Boolean> canPlaceItemOn(@org.jetbrains.annotations.NotNull ItemStack item, @org.jetbrains.annotations.Nullable gg.projecteden.parchment.OptionalHumanEntity player, @org.jetbrains.annotations.NotNull org.bukkit.block.Block block, @org.jetbrains.annotations.NotNull org.bukkit.block.BlockFace face);
+ // Parchment end
}

View File

@@ -5,13 +5,13 @@ Subject: [PATCH] Expose NMS ordinals
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 5606c09f62b7ad0cf33bb507d71830581114afd4..91ce90be864c20cab92525693d37b07f94d978af 100644
index 716d5371c0ceb5b97c7008a6ac0c7ddf58b01a9f..16a332a6f8dad6a2758fd2bf3ab37637b9f26711 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -230,5 +230,12 @@ public interface UnsafeValues {
@@ -255,5 +255,12 @@ public interface UnsafeValues {
* @return if the item can be placed
*/
java.util.concurrent.CompletableFuture<Boolean> canPlaceItemOn(@org.jetbrains.annotations.NotNull ItemStack item, @org.jetbrains.annotations.Nullable me.lexikiq.OptionalHumanEntity player, @org.jetbrains.annotations.NotNull org.bukkit.block.Block block, @org.jetbrains.annotations.NotNull org.bukkit.block.BlockFace face);
java.util.concurrent.CompletableFuture<Boolean> canPlaceItemOn(@org.jetbrains.annotations.NotNull ItemStack item, @org.jetbrains.annotations.Nullable gg.projecteden.parchment.OptionalHumanEntity player, @org.jetbrains.annotations.NotNull org.bukkit.block.Block block, @org.jetbrains.annotations.NotNull org.bukkit.block.BlockFace face);
+
+ /**
+ * Gets the ID/ordinal of an entity according to NMS.

View File

@@ -5,12 +5,12 @@ Subject: [PATCH] Expose MCUtil Executors
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index c34cfba8f9ed7e9dbd0b6b8ffef9fba46abff046..451ea2c118b661725047f344c91814668d25cea5 100644
index 30b49aed62fa67276e8964922ea3f84458d854bb..c78ca045a0a7fa651a34f76c802bb82cd6ac4d13 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -1837,4 +1837,20 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@NotNull
io.papermc.paper.datapack.DatapackManager getDatapackManager();
@@ -2065,4 +2065,20 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
@NotNull org.bukkit.potion.PotionBrewer getPotionBrewer();
// Paper end
+
+ // Parchment start

View File

@@ -7,13 +7,13 @@ Adds an event which allows plugin developers
to easily get the items being dropped by any
block instead of only blocks broken by players.
diff --git a/src/main/java/me/lexikiq/event/block/BlockDropResourcesEvent.java b/src/main/java/me/lexikiq/event/block/BlockDropResourcesEvent.java
diff --git a/src/main/java/gg/projecteden/parchment/event/block/BlockDropResourcesEvent.java b/src/main/java/gg/projecteden/parchment/event/block/BlockDropResourcesEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..5ac4994b3e530f7e7636dddfdf24dec12e74ebf7
index 0000000000000000000000000000000000000000..1547d962e9c27411915a34efe0db0c3dff99c6e5
--- /dev/null
+++ b/src/main/java/me/lexikiq/event/block/BlockDropResourcesEvent.java
+++ b/src/main/java/gg/projecteden/parchment/event/block/BlockDropResourcesEvent.java
@@ -0,0 +1,45 @@
+package me.lexikiq.event.block;
+package gg.projecteden.parchment.event.block;
+
+import org.bukkit.block.Block;
+import org.bukkit.event.HandlerList;

View File

@@ -7,13 +7,13 @@ Temporary API to get the result of smelting an item in a (type of) furnace.
Will eventually (hopefully) be replaced by a more extensive Paper PR with support for all recipes.
diff --git a/src/main/java/me/lexikiq/inventory/RecipeType.java b/src/main/java/me/lexikiq/inventory/RecipeType.java
diff --git a/src/main/java/gg/projecteden/parchment/inventory/RecipeType.java b/src/main/java/gg/projecteden/parchment/inventory/RecipeType.java
new file mode 100644
index 0000000000000000000000000000000000000000..f8f707483bf08142cdaf6c6ff9b1241832e9134f
index 0000000000000000000000000000000000000000..28c01caa9d6379046f6af6612719b40459a89d17
--- /dev/null
+++ b/src/main/java/me/lexikiq/inventory/RecipeType.java
+++ b/src/main/java/gg/projecteden/parchment/inventory/RecipeType.java
@@ -0,0 +1,50 @@
+package me.lexikiq.inventory;
+package gg.projecteden.parchment.inventory;
+
+/**
+ * A type of crafting recipe.
@@ -64,10 +64,10 @@ index 0000000000000000000000000000000000000000..f8f707483bf08142cdaf6c6ff9b12418
+ }
+}
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index 4f673e9123145dc78564dc3eef0edf75795dafc2..85902538dae4a76ee79bc2d9921f2b4ec9f3c30d 100644
index 7ad1cabe05277c1f3238da6e121c35d8a9f0d952..2fd4f6a97a5964e187ee06a66d48e7e6021155d4 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -3764,6 +3764,36 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -3909,6 +3909,36 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@Nullable
public DragonBattle getEnderDragonBattle();
@@ -80,17 +80,17 @@ index 4f673e9123145dc78564dc3eef0edf75795dafc2..85902538dae4a76ee79bc2d9921f2b4e
+ */
+ @Nullable
+ default ItemStack smeltItem(@NotNull ItemStack toSmelt) {
+ return smeltItem(toSmelt, me.lexikiq.inventory.RecipeType.SMELTING);
+ return smeltItem(toSmelt, gg.projecteden.parchment.inventory.RecipeType.SMELTING);
+ }
+
+ /**
+ * Returns the item that will result from smelting the input item, if applicable.
+ * <p>
+ * Applicable values for {@code recipeType} are
+ * {@link me.lexikiq.inventory.RecipeType#SMELTING SMELTING},
+ * {@link me.lexikiq.inventory.RecipeType#BLASTING BLASTING},
+ * {@link me.lexikiq.inventory.RecipeType#SMOKING SMOKING},
+ * and {@link me.lexikiq.inventory.RecipeType#CAMPFIRE_COOKING CAMPFIRE_COOKING}.
+ * {@link gg.projecteden.parchment.inventory.RecipeType#SMELTING SMELTING},
+ * {@link gg.projecteden.parchment.inventory.RecipeType#BLASTING BLASTING},
+ * {@link gg.projecteden.parchment.inventory.RecipeType#SMOKING SMOKING},
+ * and {@link gg.projecteden.parchment.inventory.RecipeType#CAMPFIRE_COOKING CAMPFIRE_COOKING}.
+ * An {@link IllegalArgumentException} will be thrown if another value is supplied.
+ *
+ * @param toSmelt the item to simulate smelting
@@ -98,7 +98,7 @@ index 4f673e9123145dc78564dc3eef0edf75795dafc2..85902538dae4a76ee79bc2d9921f2b4e
+ * @return the resulting item, or null
+ */
+ @Nullable
+ ItemStack smeltItem(@NotNull ItemStack toSmelt, me.lexikiq.inventory.@NotNull RecipeType recipeType);
+ ItemStack smeltItem(@NotNull ItemStack toSmelt, gg.projecteden.parchment.inventory.@NotNull RecipeType recipeType);
+ // Parchment end
+
/**

View File

@@ -5,21 +5,21 @@ Subject: [PATCH] Build changes
diff --git a/build.gradle.kts b/build.gradle.kts
index c236fe5dc388f8bc0a929f1de04af94c63514208..9fa28ef9ebcae299f7839f9341ab1da80660f61f 100644
index 68b8f275f9c9e77a949ca29749a05b469bcdb910..82d6922ca22eee74de2140789787e6e5da51378c 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -13,8 +13,8 @@ plugins {
@@ -9,8 +9,8 @@ plugins {
}
dependencies {
- implementation(project(":Paper-API"))
- implementation(project(":Paper-MojangAPI"))
+ implementation(project(":Parchment-API")) // Parchment
+ implementation("io.papermc.paper:paper-mojangapi:1.17.1-R0.1-SNAPSHOT") // Parchment
- implementation(project(":paper-api"))
- implementation(project(":paper-mojangapi"))
+ implementation(project(":parchment-api")) // Parchment
+ implementation("io.papermc.paper:paper-mojangapi:1.18.1-R0.1-SNAPSHOT") // Parchment
// Paper start
implementation("org.jline:jline-terminal-jansi:3.21.0")
implementation("net.minecrell:terminalconsoleappender:1.3.0")
@@ -66,7 +66,7 @@ tasks.jar {
@@ -64,7 +64,7 @@ tasks.jar {
attributes(
"Main-Class" to "org.bukkit.craftbukkit.Main",
"Implementation-Title" to "CraftBukkit",
@@ -28,11 +28,13 @@ index c236fe5dc388f8bc0a929f1de04af94c63514208..9fa28ef9ebcae299f7839f9341ab1da8
"Implementation-Vendor" to date, // Paper
"Specification-Title" to "Bukkit",
"Specification-Version" to project.version,
@@ -88,6 +88,26 @@ publishing {
classifier = null
}
artifact(tasks.shadowJar)
+ // Parchment start
@@ -81,7 +81,27 @@ tasks.jar {
publishing {
publications.create<MavenPublication>("maven") {
- artifact(tasks.shadowJar)
+ // Parchment start
+ artifact(tasks.reobfJar)
+ groupId = project.group as String?
+ artifactId = "parchment"
+ version = project.version as String?
@@ -55,26 +57,17 @@ index c236fe5dc388f8bc0a929f1de04af94c63514208..9fa28ef9ebcae299f7839f9341ab1da8
}
}
@@ -132,7 +152,7 @@ tasks.shadowJar {
// Needed for Paperclip's install to maven local feature
from(generatePom) {
- into("META-INF/maven/io.papermc.paper/paper")
+ into("META-INF/maven/${project.group}/${project.name.toLowerCase(Locale.ENGLISH)}") // Parchment
rename { "pom.xml" }
}
@@ -193,7 +213,7 @@ tasks.test {
fun TaskContainer.registerRunTask(
name: String, block: JavaExec.() -> Unit
@@ -152,7 +172,7 @@ fun TaskContainer.registerRunTask(
name: String,
block: JavaExec.() -> Unit
): TaskProvider<JavaExec> = register<JavaExec>(name) {
- group = "paper"
+ group = "paperweight" // Parchment
mainClass.set("org.bukkit.craftbukkit.Main")
standardInput = System.`in`
workingDir = rootProject.layout.projectDirectory.dir(
providers.gradleProperty("runWorkDir").forUseAtConfigurationTime().orElse("run")
workingDir = rootProject.layout.projectDirectory
diff --git a/src/main/java/com/destroystokyo/paper/Metrics.java b/src/main/java/com/destroystokyo/paper/Metrics.java
index 218f5bafeed8551b55b91c7fccaf6935c8b631ca..52126870f1fc15a9ddce4452673b236ea692860f 100644
index 7b1843e16745ca8db2244e17490d291401f22679..c340575e9c2a114f2165b74feb4481975821811c 100644
--- a/src/main/java/com/destroystokyo/paper/Metrics.java
+++ b/src/main/java/com/destroystokyo/paper/Metrics.java
@@ -73,7 +73,7 @@ public class Metrics {
@@ -87,7 +80,7 @@ index 218f5bafeed8551b55b91c7fccaf6935c8b631ca..52126870f1fc15a9ddce4452673b236e
/**
diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
index ece77f5ea4b14bbed7c070131b3251ea86764538..71bf426f7fb58fff6739bb1332d1286db810d434 100644
index bf42969859545a8a520923ef1836ffa4a5cc24a0..2532e265c5dade55f71c34fcab6d1e74bbb58a87 100644
--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
@@ -31,8 +31,8 @@ public class PaperVersionFetcher implements VersionFetcher {
@@ -111,10 +104,10 @@ index ece77f5ea4b14bbed7c070131b3251ea86764538..71bf426f7fb58fff6739bb1332d1286d
org.bukkit.Bukkit.getLogger().warning("Version: " + org.bukkit.Bukkit.getBukkitVersion());
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 8091a901106a1085da9dfd8627dadcbe50f00872..50ebf237f85b789efdcba76aff2e5e6b8d2d74c6 100644
index 32dc0cd20a4dd8fc02be1f7ba3d727db826dbe5d..d48ac4df6f9cde9ccdc068010e977206dd838eaf 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1729,7 +1729,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1654,7 +1654,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@DontObfuscate
public String getServerModName() {
@@ -124,10 +117,10 @@ index 8091a901106a1085da9dfd8627dadcbe50f00872..50ebf237f85b789efdcba76aff2e5e6b
public SystemReport fillSystemReport(SystemReport details) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 99a94898316b0601f55b333c15a9926eae24f8a2..8890fe4c8d11934328e20087ecadb76858d9e028 100644
index f1e5ccfbcd08a73ac3aba9a1cb7b414faef81f9e..f4847a8671bd21f78af598faacea5c763669ddbc 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -251,7 +251,7 @@ import javax.annotation.Nullable; // Paper
@@ -243,7 +243,7 @@ import javax.annotation.Nullable; // Paper
import javax.annotation.Nonnull; // Paper
public final class CraftServer implements Server {
@@ -137,10 +130,10 @@ index 99a94898316b0601f55b333c15a9926eae24f8a2..8890fe4c8d11934328e20087ecadb768
private final String bukkitVersion = Versioning.getBukkitVersion();
private final Logger logger = Logger.getLogger("Minecraft");
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
index 22e9dd17f62103c5061435099ce96a3d70d54808..3344a9f976c0eaf88c62831ed8ec4952b400cca1 100644
index fbd604602024522bdd73aa1bde6fe2ccec63e442..2d1f2739e698eb53677d5ecc8a3a74feda7b86e4 100644
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
@@ -269,7 +269,7 @@ public class Main {
@@ -270,7 +270,7 @@ public class Main {
if (buildDate.before(deadline.getTime())) {
// Paper start - This is some stupid bullshit
System.err.println("*** Warning, you've not updated in a while! ***");
@@ -150,7 +143,7 @@ index 22e9dd17f62103c5061435099ce96a3d70d54808..3344a9f976c0eaf88c62831ed8ec4952
//Thread.sleep(TimeUnit.SECONDS.toMillis(20));
// Paper End
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Versioning.java b/src/main/java/org/bukkit/craftbukkit/util/Versioning.java
index 774556a62eb240da42e84db4502e2ed43495be17..fbba763d909c4636174e79c680745b83c41409bb 100644
index 774556a62eb240da42e84db4502e2ed43495be17..6f1b3fa6ebeabc7596034663ed06686fd3892267 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/Versioning.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/Versioning.java
@@ -11,7 +11,7 @@ public final class Versioning {
@@ -158,15 +151,15 @@ index 774556a62eb240da42e84db4502e2ed43495be17..fbba763d909c4636174e79c680745b83
String result = "Unknown-Version";
- InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/io.papermc.paper/paper-api/pom.properties");
+ InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/me.lexikiq/parchment-api/pom.properties");
+ InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/gg.projecteden.parchment/parchment-api/pom.properties");
Properties properties = new Properties();
if (stream != null) {
diff --git a/src/main/java/org/spigotmc/WatchdogThread.java b/src/main/java/org/spigotmc/WatchdogThread.java
index bee38307494188800886a1622fed229b88dbd8f1..104d9f4fcad6d5895a1f4e3cd1966dccc4530da7 100644
index d568fc92d03c313a782796cc720a1ebb1a5ad8be..024d8884ac8a7d2322a7db2901b7ecff31a0154a 100644
--- a/src/main/java/org/spigotmc/WatchdogThread.java
+++ b/src/main/java/org/spigotmc/WatchdogThread.java
@@ -163,7 +163,7 @@ public class WatchdogThread extends Thread
@@ -162,7 +162,7 @@ public class WatchdogThread extends Thread
log.log( Level.SEVERE, "\t If this is the case, consider increasing timeout-time in spigot.yml but note that this will replace the crash with LARGE lag spikes" );
log.log( Level.SEVERE, "If you are unsure or still think this is a Paper bug, please report this to https://github.com/PaperMC/Paper/issues" );
log.log( Level.SEVERE, "Be sure to include ALL relevant console errors and Minecraft crash reports" );

View File

@@ -5,15 +5,15 @@ Subject: [PATCH] Temporary Access Transformers
diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java
index 8e6df16568c0dab482e10ad1b38920d77f6e684f..dbcf8a2138c55aa1ef32bbad92fb555f2acc79cd 100644
index 8f3b9b8784f0d7b137a1ad87655ee8bad801b59d..5153ae98bd80697a0e8bc71e5484c1f4f2817fe2 100644
--- a/src/main/java/net/minecraft/world/item/BlockItem.java
+++ b/src/main/java/net/minecraft/world/item/BlockItem.java
@@ -191,7 +191,7 @@ public class BlockItem extends Item {
@@ -205,7 +205,7 @@ public class BlockItem extends Item {
}).orElse(state);
}
- protected boolean canPlace(BlockPlaceContext context, BlockState state) {
+ public boolean canPlace(BlockPlaceContext context, BlockState state) { // Parchment
Player entityhuman = context.getPlayer();
CollisionContext voxelshapecollision = entityhuman == null ? CollisionContext.empty() : CollisionContext.of((Entity) entityhuman);
CollisionContext voxelshapecollision = entityhuman == null ? CollisionContext.empty() : CollisionContext.of(entityhuman);
// CraftBukkit start - store default return

View File

@@ -4,142 +4,273 @@ Date: Sat, 19 Jun 2021 16:30:39 -0400
Subject: [PATCH] Add SoundEvent
diff --git a/src/main/java/gg/projecteden/parchment/event/sound/ParchmentSoundEvent.java b/src/main/java/gg/projecteden/parchment/event/sound/ParchmentSoundEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..44245b61f64e4e2eb21ac4f5e540aa9a583bfcfe
--- /dev/null
+++ b/src/main/java/gg/projecteden/parchment/event/sound/ParchmentSoundEvent.java
@@ -0,0 +1,28 @@
+package gg.projecteden.parchment.event.sound;
+
+import io.papermc.paper.adventure.PaperAdventure;
+import net.kyori.adventure.sound.Sound;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.level.Level;
+import org.bukkit.Location;
+
+import java.util.Optional;
+import java.util.function.Function;
+
+public class ParchmentSoundEvent {
+ public static final Function<Sound, Double> DISTANCE_FUNCTION = sound -> {
+ Optional<SoundEvent> soundEvent = PaperAdventure.asVanillaSound(sound.name());
+ if (soundEvent.isPresent())
+ return Double.valueOf(soundEvent.get().getRange(sound.volume()));
+ return gg.projecteden.parchment.event.sound.SoundEvent.DEFAULT_DISTANCE_FUNCTION.apply(sound);
+ };
+
+ public static gg.projecteden.parchment.event.sound.SoundEvent.Emitter createEmitter(Level level, double x, double y, double z) {
+ return new gg.projecteden.parchment.event.sound.SoundEvent.LocationEmitter(new Location(level.getWorld(), x, y, z));
+ }
+
+ public static gg.projecteden.parchment.event.sound.SoundEvent.Emitter createEmitter(Entity entity) {
+ return new gg.projecteden.parchment.event.sound.SoundEvent.EntityEmitter(entity.getBukkitEntity());
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
index 3f25a9b1a74cfa0c9a4d0379ecda109d99f33db3..b954cda43afbfd367f7f8f436dca65f900706ccb 100644
--- a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
@@ -302,6 +302,32 @@ public final class PaperAdventure {
return asVanilla(source);
}
+ // Parchment start
+ public static Sound.Source asAdventure(final SoundSource source) {
+ return switch (source) {
+ case MASTER -> Sound.Source.MASTER;
+ case MUSIC -> Sound.Source.MUSIC;
+ case RECORDS -> Sound.Source.RECORD;
+ case WEATHER -> Sound.Source.WEATHER;
+ case BLOCKS -> Sound.Source.BLOCK;
+ case HOSTILE -> Sound.Source.HOSTILE;
+ case NEUTRAL -> Sound.Source.NEUTRAL;
+ case PLAYERS -> Sound.Source.PLAYER;
+ case AMBIENT -> Sound.Source.AMBIENT;
+ case VOICE -> Sound.Source.VOICE;
+ };
+ }
+
+ public static java.util.Optional<net.minecraft.sounds.SoundEvent> asVanillaSound(final Key key) {
+ return net.minecraft.core.Registry.SOUND_EVENT.getOptional(asVanilla(key));
+ }
+
+ @SuppressWarnings("PatternValidation")
+ public static Key asAdventure(final ResourceLocation key) {
+ return Key.key(key.getNamespace(), key.getPath());
+ }
+ // Parchment end
+
// NBT
public static @Nullable BinaryTagHolder asBinaryTagHolder(final @Nullable CompoundTag tag) {
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index a002713686e66faf0d18662586a7a236c27ca7d2..14fc9abcba864620148dcdab921a5d95f98a9391 100644
index 2b9669df574cf95c2643344a66ad18b213bd9cd7..ce354a3bd5deea844f86c89d555b438c50de31b8 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1495,12 +1495,12 @@ public class ServerLevel extends Level implements WorldGenLevel {
@@ -1541,12 +1541,40 @@ public class ServerLevel extends Level implements WorldGenLevel {
@Override
public void playSound(@Nullable Player except, double x, double y, double z, SoundEvent sound, SoundSource category, float volume, float pitch) {
- this.server.getPlayerList().broadcast(except, x, y, z, volume > 1.0F ? (double) (16.0F * volume) : 16.0D, this.dimension(), new ClientboundSoundPacket(sound, category, x, y, z, volume, pitch));
+ CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(except == null ? null : except.getBukkitEntity(), getWorld(), new org.bukkit.util.Vector(x, y, z), org.bukkit.craftbukkit.CraftSound.getBukkit(sound), org.bukkit.SoundCategory.valueOf(category.name()), volume, pitch, null, null)); // Parchment
public void playSeededSound(@Nullable Player except, double x, double y, double z, SoundEvent sound, SoundSource category, float volume, float pitch, long seed) {
- this.server.getPlayerList().broadcast(except, x, y, z, (double) sound.getRange(volume), this.dimension(), new ClientboundSoundPacket(sound, category, x, y, z, volume, pitch, seed));
+ // Parchment start - sound event
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
+ except == null ? null : except.getBukkitEntity(),
+ net.kyori.adventure.sound.Sound.sound(
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(sound.getLocation()),
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(category),
+ volume,
+ pitch
+ ),
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(this, x, y, z),
+ seed,
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.DISTANCE_FUNCTION,
+ null
+ ));
+ // Parchment end
}
@Override
public void playSound(@Nullable Player except, Entity entity, SoundEvent sound, SoundSource category, float volume, float pitch) {
- this.server.getPlayerList().broadcast(except, entity.getX(), entity.getY(), entity.getZ(), volume > 1.0F ? (double) (16.0F * volume) : 16.0D, this.dimension(), new ClientboundSoundEntityPacket(sound, category, entity, volume, pitch));
+ CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.EntitySoundEvent(except == null ? null : except.getBukkitEntity(), entity.getBukkitEntity(), org.bukkit.craftbukkit.CraftSound.getBukkit(sound), org.bukkit.SoundCategory.valueOf(category.name()), volume, pitch, null, null)); // Parchment
public void playSeededSound(@Nullable Player except, Entity entity, SoundEvent sound, SoundSource category, float volume, float pitch, long seed) {
- this.server.getPlayerList().broadcast(except, entity.getX(), entity.getY(), entity.getZ(), (double) sound.getRange(volume), this.dimension(), new ClientboundSoundEntityPacket(sound, category, entity, volume, pitch, seed));
+ // Parchment start - sound event
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
+ except == null ? null : except.getBukkitEntity(),
+ net.kyori.adventure.sound.Sound.sound(
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(sound.getLocation()),
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(category),
+ volume,
+ pitch
+ ),
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(entity),
+ seed,
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.DISTANCE_FUNCTION,
+ null
+ ));
+ // Parchment end
}
@Override
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 78fda0c982810b8b881a87099f355247566e513a..1ec20f19c8d6a606f608e0293eaf5f8f764b3b92 100644
index 353463084d90eb684717e65c56da52cd25a1e375..e7fb384822966c149777148792723f7f36681f76 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -2174,7 +2174,13 @@ public class ServerPlayer extends Player {
@@ -2227,7 +2227,19 @@ public class ServerPlayer extends Player {
@Override
public void playNotifySound(SoundEvent event, SoundSource category, float volume, float pitch) {
- this.connection.send(new ClientboundSoundPacket(event, category, this.getX(), this.getY(), this.getZ(), volume, pitch));
+ // Parchment start
+ List<org.bukkit.entity.Player> recipients = java.util.Collections.singletonList(getBukkitEntity());
+ org.bukkit.Location location = getBukkitEntity().getLocation();
+ org.bukkit.Sound sound = org.bukkit.craftbukkit.CraftSound.getBukkit(event);
+ org.bukkit.SoundCategory bukkitCategory = org.bukkit.SoundCategory.valueOf(category.name());
+ CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(null, location, sound, bukkitCategory, volume, pitch, $ -> 0d, $ -> recipients));
- this.connection.send(new ClientboundSoundPacket(event, category, this.getX(), this.getY(), this.getZ(), volume, pitch, this.random.nextLong()));
+ // Parchment start - sound event
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
+ null,
+ net.kyori.adventure.sound.Sound.sound(
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(event.getLocation()),
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(category),
+ volume,
+ pitch
+ ),
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(level, getX(), getY(), getZ()),
+ this.random.nextLong(), sound -> 0d, soundEvent -> java.util.Collections.singletonList(getBukkitEntity())
+ ));
+ // Parchment end
}
@Override
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 46e6e68f78d07c04cd2f4d477dca7a06313c20e9..f7d9316645ba94089a867c6348caaf77756c44f6 100644
index 20cdfdb3b9351f74e89bc45b3ab972384165659a..aaef762c95584103937955413629aa11f7cf2bd0 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -965,7 +965,7 @@ public abstract class PlayerList {
@@ -977,7 +977,7 @@ public abstract class PlayerList {
if (flag2 && !isLocAltered) {
BlockState data = worldserver1.getBlockState(blockposition);
worldserver1.setBlock(blockposition, data.setValue(RespawnAnchorBlock.CHARGE, data.getValue(RespawnAnchorBlock.CHARGE) - 1), 3);
- entityplayer1.connection.send(new ClientboundSoundPacket(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, (double) location.getX(), (double) location.getY(), (double) location.getZ(), 1.0F, 1.0F));
+ entityplayer1.playNotifySound(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, 1.0F, 1.0F); // Parchment
worldserver1.setBlock(blockposition, data.setValue(net.minecraft.world.level.block.RespawnAnchorBlock.CHARGE, data.getValue(net.minecraft.world.level.block.RespawnAnchorBlock.CHARGE) - 1), 3);
- entityplayer1.connection.send(new ClientboundSoundPacket(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, (double) location.getX(), (double) location.getY(), (double) location.getZ(), 1.0F, 1.0F, worldserver1.getRandom().nextLong()));
+ entityplayer1.playNotifySound(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, 1.0F, 1.0F); // Parchment - use existing play sound method
// Paper end
}
// Added from changeDimension
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index 94e76e295dbd0f3bac4b30a3e7338cd56a971207..e951db59902fafa41832f73bab4086b63fe76f46 100644
index cd9cbfa5ef94994b3f7f2ecdde843620e7e6c071..bc6bdc8752718777ac698cfda2a0e7f35fcf9896 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -1832,7 +1832,14 @@ public abstract class Player extends LivingEntity {
@@ -1898,7 +1898,21 @@ public abstract class Player extends LivingEntity {
private static void sendSoundEffect(Player fromEntity, double x, double y, double z, SoundEvent soundEffect, SoundSource soundCategory, float volume, float pitch) {
fromEntity.level.playSound(fromEntity, x, y, z, soundEffect, soundCategory, volume, pitch); // This will not send the effect to the entity himself
if (fromEntity instanceof ServerPlayer) {
- ((ServerPlayer) fromEntity).connection.send(new ClientboundSoundPacket(soundEffect, soundCategory, x, y, z, volume, pitch));
+ // Parchment start
+ List<org.bukkit.entity.Player> recipients = java.util.Collections.singletonList(((net.minecraft.server.level.ServerPlayer) fromEntity).getBukkitEntity());
+ org.bukkit.World world = fromEntity.level.getWorld();
+ org.bukkit.util.Vector vector = new org.bukkit.util.Vector(x, y, z);
+ org.bukkit.Sound sound = org.bukkit.craftbukkit.CraftSound.getBukkit(soundEffect);
+ org.bukkit.SoundCategory category = org.bukkit.SoundCategory.valueOf(soundCategory.name());
+ CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(null, world, vector, sound, category, volume, pitch, event -> 0d, event -> recipients));
- ((ServerPlayer) fromEntity).connection.send(new net.minecraft.network.protocol.game.ClientboundSoundPacket(soundEffect, soundCategory, x, y, z, volume, pitch, fromEntity.random.nextLong()));
+ // Parchment start - sound event
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
+ null,
+ net.kyori.adventure.sound.Sound.sound(
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(soundEffect.getLocation()),
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(soundCategory),
+ volume,
+ pitch
+ ),
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(fromEntity.level, x, y, z),
+ fromEntity.random.nextLong(),
+ sound -> 0d,
+ soundEvent -> java.util.Collections.singletonList(((ServerPlayer) fromEntity).getBukkitEntity())
+ ));
+ // Parchment end
}
}
// Paper end
diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java
index a79ba23ecf887ecbb6e095140f019ebb6fd0a6f7..5112edc5e68a386e9bb16ac0ec9d998e7df06f3c 100644
index 6a0a1731fd6804eb69d3641213712d31bce085b2..81819d12e0becde85b6d66f3b3ffedde847a72f6 100644
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
@@ -27,7 +27,7 @@ import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
-import net.minecraft.network.protocol.game.ClientboundSoundPacket;
+//import net.minecraft.network.protocol.game.ClientboundSoundPacket; // Parchment
import net.minecraft.server.level.ServerBossEvent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@@ -537,7 +537,7 @@ public class Raid {
@@ -526,7 +526,7 @@ public class Raid {
float f = 13.0F;
boolean flag = true;
Collection<ServerPlayer> collection = this.raidEvent.getPlayers();
- long i = this.random.nextLong();
+ //long i = this.random.nextLong(); // Parchment - remove redundant variable
Iterator iterator = this.level.players().iterator();
while (iterator.hasNext()) {
@@ -538,7 +538,7 @@ public class Raid {
double d2 = vec3d.z + 13.0D / d0 * (vec3d1.z - vec3d.z);
if (d0 <= 64.0D || collection.contains(entityplayer)) {
- entityplayer.connection.send(new ClientboundSoundPacket(SoundEvents.RAID_HORN, SoundSource.NEUTRAL, d1, entityplayer.getY(), d2, 64.0F, 1.0F));
+ entityplayer.playNotifySound(SoundEvents.RAID_HORN, SoundSource.NEUTRAL, 64.0F, 1.0F); // Parchment
- entityplayer.connection.send(new ClientboundSoundPacket(SoundEvents.RAID_HORN, SoundSource.NEUTRAL, d1, entityplayer.getY(), d2, 64.0F, 1.0F, i));
+ entityplayer.playNotifySound(SoundEvents.RAID_HORN, SoundSource.NEUTRAL, 64.0F, 1.0F); // Parchment - use existing play sound method
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index ea01507f96d81c6fbcfeb65902017bbc332de650..b774a27eb4d11cd1bef807193a6df6012dde3794 100644
index 1d8ec0f85ec42f2dcd9405df83b526ae1c59de6f..5204590757f5f0890f72e915d30a8c52497090a3 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1888,4 +1888,41 @@ public class CraftEventFactory {
@@ -2,7 +2,6 @@ package org.bukkit.craftbukkit.event;
import com.google.common.base.Function;
import com.google.common.base.Functions;
-import com.google.common.collect.Lists;
import com.mojang.datafixers.util.Either;
import java.net.InetAddress;
import java.util.ArrayList;
@@ -1919,4 +1918,52 @@ public class CraftEventFactory {
return event.callEvent();
}
// Paper end
+
+ // Parchment start
+ private static net.minecraft.network.protocol.Packet<net.minecraft.network.protocol.game.ClientGamePacketListener> handleSoundEvent(me.lexikiq.event.sound.SoundEvent _event) {
+ if (!_event.callEvent()) {
+ return null;
+ }
+ float volume = _event.getVolume();
+ float pitch = _event.getPitch();
+ net.minecraft.sounds.SoundSource source = net.minecraft.sounds.SoundSource.valueOf(_event.getCategory().name());
+
+ if (_event instanceof me.lexikiq.event.sound.NamedSoundEvent namedSoundEvent) {
+ net.minecraft.sounds.SoundEvent sound = org.bukkit.craftbukkit.CraftSound.getSoundEffect(namedSoundEvent.getSound());
+
+ if (_event instanceof me.lexikiq.event.sound.LocationNamedSoundEvent event) {
+ org.bukkit.util.Vector pos = event.getPosition();
+ return new net.minecraft.network.protocol.game.ClientboundSoundPacket(sound, source, pos.getX(), pos.getY(), pos.getZ(), volume, pitch);
+ } else if (_event instanceof me.lexikiq.event.sound.EntitySoundEvent event) {
+ return new net.minecraft.network.protocol.game.ClientboundSoundEntityPacket(sound, source, ((CraftEntity) event.getOrigin()).getHandle(), volume, pitch);
+ private static net.minecraft.network.protocol.@org.jetbrains.annotations.NotNull Packet<net.minecraft.network.protocol.game.ClientGamePacketListener> handleSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event, CraftPlayer recipient) {
+ // init variables
+ net.kyori.adventure.sound.Sound sound = event.calculateSound(recipient);
+ gg.projecteden.parchment.event.sound.SoundEvent.Emitter emitter = event.calculateEmitter(recipient);
+ net.minecraft.sounds.SoundSource source = io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source());
+ float volume = sound.volume();
+ float pitch = sound.pitch();
+ long seed = event.getSeed();
+ java.util.Optional<net.minecraft.sounds.SoundEvent> soundEvent = io.papermc.paper.adventure.PaperAdventure.asVanillaSound(sound.name());
+ // handle vanilla sounds
+ if (soundEvent.isPresent()) {
+ if (emitter instanceof gg.projecteden.parchment.event.sound.SoundEvent.EntityEmitter entityEmitter)
+ return new net.minecraft.network.protocol.game.ClientboundSoundEntityPacket(soundEvent.get(), source, ((CraftEntity) entityEmitter.entity()).getHandle(), volume, pitch, seed);
+ else if (emitter instanceof gg.projecteden.parchment.event.sound.SoundEvent.LocationEmitter locationEmitter) {
+ Location loc = locationEmitter.location();
+ return new net.minecraft.network.protocol.game.ClientboundSoundPacket(soundEvent.get(), source, loc.getX(), loc.getY(), loc.getZ(), volume, pitch, seed);
+ }
+ } else if (_event instanceof me.lexikiq.event.sound.LocationCustomSoundEvent event) {
+ org.bukkit.util.Vector pos = event.getPosition();
+ return new net.minecraft.network.protocol.game.ClientboundCustomSoundPacket(CraftNamespacedKey.toMinecraft(event.getKey()), source, org.bukkit.craftbukkit.util.CraftVector.toNMS(pos), volume, pitch);
+ else
+ throw new IllegalArgumentException("Unknown emitter type: " + emitter.getClass().getName());
+ }
+ // handle custom sounds
+ else {
+ // warn if trying to use EntityEmitter with custom sound
+ if (emitter instanceof gg.projecteden.parchment.event.sound.SoundEvent.EntityEmitter)
+ org.slf4j.LoggerFactory.getLogger("SoundEvent").warn("Sound event is using a custom sound ({}) which cannot be used with EntityEmitter. Falling back to playing at the entity's location.", sound.name().asString());
+ Vec3 pos = org.bukkit.craftbukkit.util.CraftVector.toNMS(emitter.location().toVector());
+ return new net.minecraft.network.protocol.game.ClientboundCustomSoundPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.name()), source, pos, volume, pitch, seed);
+ }
+ throw new IllegalArgumentException("Unknown sound event: " + _event.getClass().getName());
+ }
+
+ public static void playSoundEvent(me.lexikiq.event.sound.SoundEvent event) {
+ public static void playSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event) {
+ org.apache.commons.lang3.Validate.notNull(event, "event");
+ java.util.concurrent.CompletableFuture.supplyAsync(() -> handleSoundEvent(event), net.minecraft.server.MCUtil.asyncExecutor).handleAsync((packet, throwable) -> {
+ if (packet != null)
+ event.calculateRecipients().forEach(recipient -> ((org.bukkit.craftbukkit.entity.CraftPlayer) recipient).getHandle().connection.send(packet));
+ else if (throwable != null)
+ org.slf4j.LoggerFactory.getLogger("SoundEvent").error("Error while handling sound event", throwable);
+ return null;
+ }, net.minecraft.server.MCUtil.asyncExecutor);
+ net.minecraft.server.MCUtil.asyncExecutor.execute(() -> {
+ if (!event.callEvent())
+ return;
+ try {
+ for (Player _player : event.calculateRecipients()) {
+ CraftPlayer player = (CraftPlayer) _player;
+ player.getHandle().connection.send(handleSoundEvent(event, player));
+ }
+ } catch (Throwable e) {
+ org.slf4j.LoggerFactory.getLogger("SoundEvent").error("Error playing sound event", e);
+ }
+ });
+ }
+ // Parchment end
}

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Add PlayerUseRespawnAnchorEvent
diff --git a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
index 0a5d563700c9f806139001181f01fa9d0111f792..88439b8f82a97a9763dadfc6c9dbaf0912ab3eb7 100644
index 491ad2098e982f3c947fcae6f258f0b1aa44a562..7d33dae2617991bce244ad906df7053c22e3f515 100644
--- a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
@@ -52,33 +52,51 @@ public class RespawnAnchorBlock extends Block {
@@ -51,23 +51,48 @@ public class RespawnAnchorBlock extends Block {
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
ItemStack itemStack = player.getItemInHand(hand);
@@ -16,30 +16,33 @@ index 0a5d563700c9f806139001181f01fa9d0111f792..88439b8f82a97a9763dadfc6c9dbaf09
+ // Parchment start -- PlayerUseRespawnAnchorEvent
+ org.bukkit.entity.Player bukkitPlayer = player.getBukkitEntity() instanceof org.bukkit.entity.Player ? (org.bukkit.entity.Player) player.getBukkitEntity() : null;
+ org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
+ me.lexikiq.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult result;
+ gg.projecteden.parchment.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult result;
+ // Parchment end
if (hand == InteractionHand.MAIN_HAND && !isRespawnFuel(itemStack) && isRespawnFuel(player.getItemInHand(InteractionHand.OFF_HAND))) {
return InteractionResult.PASS;
} else if (isRespawnFuel(itemStack) && canBeCharged(state)) {
+ result = me.lexikiq.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.CHARGE;
+ // Parchment start -- PlayerUseRespawnAnchorEvent
+ result = gg.projecteden.parchment.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.CHARGE;
+ } else if (state.getValue(CHARGE) == 0) {
+ result = me.lexikiq.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.NOTHING;
+ result = gg.projecteden.parchment.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.NOTHING;
+ } else if (!canSetSpawn(world) && !world.isClientSide) {
+ result = me.lexikiq.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.EXPLODE;
+ result = gg.projecteden.parchment.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.EXPLODE;
+ } else if (!world.isClientSide) {
+ result = me.lexikiq.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.SET_SPAWN;
+ result = gg.projecteden.parchment.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.SET_SPAWN;
+ } else {
+ return InteractionResult.SUCCESS;
+ }
+
+ if (bukkitPlayer != null) {
+ me.lexikiq.event.player.PlayerUseRespawnAnchorEvent event = new me.lexikiq.event.player.PlayerUseRespawnAnchorEvent(bukkitPlayer, block, result);
+ gg.projecteden.parchment.event.player.PlayerUseRespawnAnchorEvent event = new gg.projecteden.parchment.event.player.PlayerUseRespawnAnchorEvent(bukkitPlayer, block, result);
+ event.callEvent();
+ result = event.getResult();
+ }
+
+ if (result == me.lexikiq.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.NOTHING) {
+ if (result == gg.projecteden.parchment.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.NOTHING) {
+ return InteractionResult.PASS;
+ } else if (result == me.lexikiq.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.CHARGE) {
+ } else if (result == gg.projecteden.parchment.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.CHARGE) {
+ // Parchment end
charge(world, pos, state);
if (!player.getAbilities().instabuild) {
itemStack.shrink(1);
@@ -54,25 +57,19 @@ index 0a5d563700c9f806139001181f01fa9d0111f792..88439b8f82a97a9763dadfc6c9dbaf09
- }
-
- return InteractionResult.sidedSuccess(world.isClientSide);
+ } else if (result == me.lexikiq.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.EXPLODE) {
+ // Parchment start -- PlayerUseRespawnAnchorEvent
+ } else if (result == gg.projecteden.parchment.event.player.PlayerUseRespawnAnchorEvent.RespawnAnchorResult.EXPLODE) {
+ this.explode(state, world, pos);
+ return InteractionResult.CONSUME;
+ // Parchment end
} else {
- if (!world.isClientSide) {
- ServerPlayer serverPlayer = (ServerPlayer)player;
- if (serverPlayer.getRespawnDimension() != world.dimension() || !pos.equals(serverPlayer.getRespawnPosition())) {
- serverPlayer.setRespawnPosition(world.dimension(), pos, 0.0F, false, true, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.RESPAWN_ANCHOR); // Paper - PlayerSetSpawnEvent
- world.playSound((Player)null, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, SoundEvents.RESPAWN_ANCHOR_SET_SPAWN, SoundSource.BLOCKS, 1.0F, 1.0F);
- return InteractionResult.SUCCESS;
- }
+ ServerPlayer serverPlayer = (ServerPlayer)player;
+ if (serverPlayer.getRespawnDimension() != world.dimension() || !pos.equals(serverPlayer.getRespawnPosition())) {
+ serverPlayer.setRespawnPosition(world.dimension(), pos, 0.0F, false, true, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.RESPAWN_ANCHOR); // Paper - PlayerSetSpawnEvent
+ world.playSound((Player)null, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, SoundEvents.RESPAWN_ANCHOR_SET_SPAWN, SoundSource.BLOCKS, 1.0F, 1.0F);
+ return InteractionResult.SUCCESS;
if (!world.isClientSide) {
ServerPlayer serverPlayer = (ServerPlayer)player;
@@ -82,7 +107,6 @@ public class RespawnAnchorBlock extends Block {
// Paper end
}
}
-
+ // Parchment end
return InteractionResult.CONSUME;
}
}

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Add origin location to EntityDamageByBlockEvent
diff --git a/src/main/java/net/minecraft/world/damagesource/BadRespawnPointDamage.java b/src/main/java/net/minecraft/world/damagesource/BadRespawnPointDamage.java
index f5a18fb39eb69b2a9842d3f96aa1cd6a8dff6d9b..456d93305f524da6142bad320edb817b27c6c1e6 100644
index 968c915cc494bb3c57169b7b3640002c3a4a8810..0c2b2cb4be57b11d748d13a0ec24b7470619267f 100644
--- a/src/main/java/net/minecraft/world/damagesource/BadRespawnPointDamage.java
+++ b/src/main/java/net/minecraft/world/damagesource/BadRespawnPointDamage.java
@@ -9,12 +9,20 @@ import net.minecraft.network.chat.TranslatableComponent;
@@ -7,12 +7,20 @@ import net.minecraft.network.chat.HoverEvent;
import net.minecraft.world.entity.LivingEntity;
public class BadRespawnPointDamage extends DamageSource {
@@ -28,9 +28,9 @@ index f5a18fb39eb69b2a9842d3f96aa1cd6a8dff6d9b..456d93305f524da6142bad320edb817b
+
@Override
public Component getLocalizedDeathMessage(LivingEntity entity) {
Component component = ComponentUtils.wrapInSquareBrackets(new TranslatableComponent("death.attack.badRespawnPoint.link")).withStyle((style) -> {
Component component = ComponentUtils.wrapInSquareBrackets(Component.translatable("death.attack.badRespawnPoint.link")).withStyle((style) -> {
diff --git a/src/main/java/net/minecraft/world/damagesource/DamageSource.java b/src/main/java/net/minecraft/world/damagesource/DamageSource.java
index a828cad27fcd39f8bfbaefa97052a2a3b6650ee7..52cce7422c2a99e3de37f87ac704151682578718 100644
index 67bce77093dcc126098731047447da2031e3388d..051cf78fe9f7700e1f639c804f35903c8079eae9 100644
--- a/src/main/java/net/minecraft/world/damagesource/DamageSource.java
+++ b/src/main/java/net/minecraft/world/damagesource/DamageSource.java
@@ -77,6 +77,18 @@ public class DamageSource {
@@ -52,7 +52,7 @@ index a828cad27fcd39f8bfbaefa97052a2a3b6650ee7..52cce7422c2a99e3de37f87ac7041516
public static DamageSource sting(LivingEntity attacker) {
return new EntityDamageSource("sting", attacker);
@@ -127,17 +139,24 @@ public class DamageSource {
@@ -127,7 +139,7 @@ public class DamageSource {
}
public static DamageSource explosion(@Nullable Explosion explosion) {
@@ -61,7 +61,8 @@ index a828cad27fcd39f8bfbaefa97052a2a3b6650ee7..52cce7422c2a99e3de37f87ac7041516
}
public static DamageSource explosion(@Nullable LivingEntity attacker) {
return attacker != null ? (new EntityDamageSource("explosion.player", attacker)).setScalesWithDifficulty().setExplosion() : (new DamageSource("explosion")).setScalesWithDifficulty().setExplosion();
@@ -138,10 +150,17 @@ public class DamageSource {
return (new EntityDamageSource("sonic_boom", attacker)).bypassArmor().bypassEnchantments().setMagic();
}
+ @Deprecated // Parchment
@@ -79,27 +80,31 @@ index a828cad27fcd39f8bfbaefa97052a2a3b6650ee7..52cce7422c2a99e3de37f87ac7041516
return "DamageSource (" + this.msgId + ")";
}
diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
index 29aa428e019681af8d6b0020c12b18660ff6af6c..9b2276555e0d52996cb84cc6ca492263e6905780 100644
index 219877901fb5fc6401646253d6e5d7bd8416ffe1..caffd9b78d370019e98c9049a121c7d3734372e6 100644
--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
@@ -101,10 +101,11 @@ public class EnderDragon extends Mob implements Enemy {
@@ -98,7 +98,7 @@ public class EnderDragon extends Mob implements Enemy {
private final Node[] nodes = new Node[24];
private final int[] nodeAdjacency = new int[24];
private final BinaryHeap openSet = new BinaryHeap();
- private Explosion explosionSource = new Explosion(null, this, null, null, Double.NaN, Double.NaN, Double.NaN, Float.NaN, true, Explosion.BlockInteraction.DESTROY); // CraftBukkit - reusable source for CraftTNTPrimed.getSource()
+ private Explosion explosionSource; // Parchment - moved into constructor to fix null world
+ private Explosion explosionSource;// = new Explosion(null, this, null, null, Double.NaN, Double.NaN, Double.NaN, Float.NaN, true, Explosion.BlockInteraction.DESTROY); // CraftBukkit - reusable source for CraftTNTPrimed.getSource() // Parchment - moved into constructor to fix null world
// Paper start - add var for save custom podium
@Nullable
private BlockPos podium;
@@ -106,6 +106,7 @@ public class EnderDragon extends Mob implements Enemy {
public EnderDragon(EntityType<? extends EnderDragon> entitytypes, Level world) {
super(EntityType.ENDER_DRAGON, world);
+ explosionSource = new Explosion(world, this, null, null, Double.NaN, Double.NaN, Double.NaN, Float.NaN, true, Explosion.BlockInteraction.DESTROY); // CraftBukkit - reusable source for CraftTNTPrimed.getSource() // Parchment - fix null world
+ explosionSource = new Explosion(world, this, null, null, Double.NaN, Double.NaN, Double.NaN, Float.NaN, true, Explosion.BlockInteraction.DESTROY); // Parchment - fix null world
this.subEntities = new EnderDragonPart[]{this.head, this.neck, this.body, this.tail1, this.tail2, this.tail3, this.wing1, this.wing2};
this.setHealth(this.getMaxHealth());
this.noPhysics = true;
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index 132140e00865fcf84ebe03ffcbc2f30ac11a0b35..8245ec990c7a37839b0eedbcdbf834df2b421e61 100644
index 01477e7240f9e33d08d416a7d40ee10f3e5d4abf..e8e1501f31b27d2e4448475db46f98304874575f 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -453,6 +453,13 @@ public class Explosion {
@@ -474,6 +474,13 @@ public class Explosion {
return this.toBlow;
}
@@ -114,10 +119,10 @@ index 132140e00865fcf84ebe03ffcbc2f30ac11a0b35..8245ec990c7a37839b0eedbcdbf834df
NONE, BREAK, DESTROY;
diff --git a/src/main/java/net/minecraft/world/level/block/BedBlock.java b/src/main/java/net/minecraft/world/level/block/BedBlock.java
index e3ff04fe21761db65fb03c5e58ecd5823f0507c6..943857d58d68628d3a79d2d687006a4fb89b75f3 100644
index 654a859a37bf991c7a7fa8a44a3d20f8feb223db..52e6c9ea22273759ea9a827125bf561a62272ad9 100644
--- a/src/main/java/net/minecraft/world/level/block/BedBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BedBlock.java
@@ -146,7 +146,10 @@ public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock
@@ -145,7 +145,10 @@ public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock
world.removeBlock(blockposition1, false);
}
@@ -130,10 +135,10 @@ index e3ff04fe21761db65fb03c5e58ecd5823f0507c6..943857d58d68628d3a79d2d687006a4f
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
index 88439b8f82a97a9763dadfc6c9dbaf0912ab3eb7..73a9b765b58bb547712c014c8b9086535b3cf6fa 100644
index 6be6adf73dc48ebbac22fe2a9be635f675f18cb1..e814c791137da2a10f4d4dd65f201fc220399975 100644
--- a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
@@ -138,7 +138,10 @@ public class RespawnAnchorBlock extends Block {
@@ -148,7 +148,10 @@ public class RespawnAnchorBlock extends Block {
return pos.equals(explodedPos) && bl2 ? Optional.of(Blocks.WATER.getExplosionResistance()) : super.getBlockExplosionResistance(explosion, world, pos, blockState, fluidState);
}
};
@@ -146,10 +151,10 @@ index 88439b8f82a97a9763dadfc6c9dbaf0912ab3eb7..73a9b765b58bb547712c014c8b908653
public static boolean canSetSpawn(Level world) {
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index b774a27eb4d11cd1bef807193a6df6012dde3794..911c0dd8a5863ae93dbd82fd3d6aafc267994081 100644
index 1547cd54b805e46ebcf8d7a910533f29537c2c55..de6ec4c6d59d1b9fa203b0d373452e466a89e1ec 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -961,7 +961,7 @@ public class CraftEventFactory {
@@ -968,7 +968,7 @@ public class CraftEventFactory {
CraftEventFactory.entityDamage = null;
EntityDamageEvent event;
if (damager == null) {
@@ -158,21 +163,21 @@ index b774a27eb4d11cd1bef807193a6df6012dde3794..911c0dd8a5863ae93dbd82fd3d6aafc2
} else if (entity instanceof EnderDragon && /*PAIL FIXME ((EntityEnderDragon) entity).target == damager*/ false) {
event = new EntityDamageEvent(entity.getBukkitEntity(), DamageCause.ENTITY_EXPLOSION, modifiers, modifierFunctions);
} else {
@@ -997,7 +997,7 @@ public class CraftEventFactory {
@@ -1008,7 +1008,7 @@ public class CraftEventFactory {
return CraftEventFactory.callEntityDamageEvent(damager, entity, cause, modifiers, modifierFunctions, cancelled, source.isCritical()); // Paper - add critical damage API
} else if (source == DamageSource.OUT_OF_WORLD) {
- EntityDamageEvent event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, modifiers, modifierFunctions);
+ EntityDamageEvent event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, entity.getBukkitEntity().getLocation(), modifiers, modifierFunctions); // Parchment
+ EntityDamageEvent event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, entity.getBukkitEntity().getLocation(), modifiers, modifierFunctions); // Parchment - add location
event.setCancelled(cancelled);
CraftEventFactory.callEvent(event);
if (!event.isCancelled()) {
@@ -1005,7 +1005,7 @@ public class CraftEventFactory {
@@ -1018,7 +1018,7 @@ public class CraftEventFactory {
}
return event;
} else if (source == DamageSource.LAVA) {
- EntityDamageEvent event = (new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.LAVA, modifiers, modifierFunctions));
+ EntityDamageEvent event = (new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.LAVA, entity.getBukkitEntity().getLocation().toBlockLocation(), modifiers, modifierFunctions)); // Parchment
- EntityDamageEvent event = (new EntityDamageByBlockEvent(CraftEventFactory.blockDamage, entity.getBukkitEntity(), DamageCause.LAVA, modifiers, modifierFunctions));
+ EntityDamageEvent event = (new EntityDamageByBlockEvent(CraftEventFactory.blockDamage, entity.getBukkitEntity(), DamageCause.LAVA, entity.getBukkitEntity().getLocation().toBlockLocation(), modifiers, modifierFunctions)); // Parchment - add location
event.setCancelled(cancelled);
CraftEventFactory.callEvent(event);
if (!event.isCancelled()) {
Block damager = CraftEventFactory.blockDamage;

View File

@@ -5,16 +5,16 @@ Subject: [PATCH] Add UnsafeValues#canPlaceItemOn
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
index 424f3a9a645d57ad43c52932f5b388b5f146b9f0..a50eb7ba668ba4410c7a7fee629bdac958734311 100644
index 88abd2d3a9626501b1800ee754b98c6c29c75fb9..0507e40c97567fc379ebe4d0b001af16922ddb3e 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -559,6 +559,55 @@ public final class CraftMagicNumbers implements UnsafeValues {
@@ -606,6 +606,55 @@ public final class CraftMagicNumbers implements UnsafeValues {
}
// Paper end
+ // Parchment start
+ @Override
+ public java.util.concurrent.CompletableFuture<Boolean> canPlaceItemOn(ItemStack item, me.lexikiq.OptionalHumanEntity player, org.bukkit.block.Block block, org.bukkit.block.BlockFace face) {
+ public java.util.concurrent.CompletableFuture<Boolean> canPlaceItemOn(ItemStack item, gg.projecteden.parchment.OptionalHumanEntity player, org.bukkit.block.Block block, org.bukkit.block.BlockFace face) {
+ org.apache.commons.lang3.Validate.notNull(item, "item");
+ org.apache.commons.lang3.Validate.notNull(block, "block");
+ org.apache.commons.lang3.Validate.notNull(face, "face");

View File

@@ -5,32 +5,32 @@ Subject: [PATCH] Expose EntityType Ordinals
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
index 1c446dba5de89698397041ee38a2e1a00bec8a56..d12e936920c03cafd18f6c9a509c85c31ab7ba45 100644
index ac0f0a4da4282c13f6e1f37710cb615d66b8ef2c..aa98cea349a3929cbb29fa01962ae98d9136cda7 100644
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -149,6 +149,8 @@ import org.apache.logging.log4j.Logger;
@@ -154,6 +154,8 @@ import org.slf4j.Logger;
public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
+ private static int ordinal = 0; // Parchment
+ private static final java.util.Map<EntityType, Integer> ordinals = new java.util.HashMap<>(); // Parchment
private static final Logger LOGGER = LogManager.getLogger();
private static final Logger LOGGER = LogUtils.getLogger();
public static final String ENTITY_TAG = "EntityTag";
private static final float MAGIC_HORSE_WIDTH = 1.3964844F;
@@ -283,9 +285,31 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
private final Holder.Reference<EntityType<?>> builtInRegistryHolder;
@@ -294,9 +296,31 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
private final EntityDimensions dimensions;
private static <T extends Entity> EntityType<T> register(String id, EntityType.Builder type) { // CraftBukkit - decompile error
- return (EntityType) Registry.register((Registry) Registry.ENTITY_TYPE, id, (Object) type.build(id));
- return (EntityType) Registry.register(Registry.ENTITY_TYPE, id, (EntityType<T>) type.build(id)); // CraftBukkit - decompile error
+ // Parchment start
+ EntityType build = type.build(id);
+ ordinals.put(build, ordinal);
+ ordinal += 1;
+ return (EntityType) Registry.register((Registry) Registry.ENTITY_TYPE, id, (Object) build);
+ return (EntityType) Registry.register(Registry.ENTITY_TYPE, id, (EntityType<T>) build);
}
+ public int ordinal() {
+ return ordinals.get(this);
+ return ordinals.get(this); // CraftBukkit - decompile error
+ }
+
+ @Override
@@ -51,10 +51,10 @@ index 1c446dba5de89698397041ee38a2e1a00bec8a56..d12e936920c03cafd18f6c9a509c85c3
return Registry.ENTITY_TYPE.getKey(type);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
index a50eb7ba668ba4410c7a7fee629bdac958734311..00a8ded3ae58b00f2c833953908f1d43765f4557 100644
index ee4d1e3f0be4ac94bb03263425b2acfa97a85c0d..840017182f0c75af07bd461d59fc340b3c304b8a 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -606,6 +606,18 @@ public final class CraftMagicNumbers implements UnsafeValues {
@@ -653,6 +653,18 @@ public final class CraftMagicNumbers implements UnsafeValues {
final net.minecraft.world.item.context.BlockPlaceContext ctx = context;
return future.completeAsync(() -> blockItem.canPlace(ctx, blockState), net.minecraft.server.MCUtil.MAIN_EXECUTOR);
}

View File

@@ -5,19 +5,19 @@ Subject: [PATCH] Add Player#setGameProfile
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index 266d676118e17af48e21370211c015898eba9691..16bc55fb8efbbda971b704446a07e9f732c1dfa5 100644
index bc6bdc8752718777ac698cfda2a0e7f35fcf9896..05584d344c9f7d6d89bb8fbdfa254c1dca91b590 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -1451,6 +1451,12 @@ public abstract class Player extends LivingEntity {
@@ -1511,6 +1511,12 @@ public abstract class Player extends LivingEntity {
return this.gameProfile;
}
+ // Parchment start
+ // Parchment start | TODO: rename to match getter
+ public void setProfile(GameProfile gameProfile) {
+ this.gameProfile = gameProfile;
+ }
+ // Parchment end
+
public Inventory getInventory() {
return this.inventory;
}
@Nullable
public ProfilePublicKey getProfilePublicKey() {
return this.profilePublicKey;

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Expose MCUtil Executors
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 9f5bbb9e684ec11bc979ca2ece4eb73da0e3d1e8..9b92bd247f8752515830d1dea13f0137ae1621e1 100644
index f4847a8671bd21f78af598faacea5c763669ddbc..97e60454716eacdfa4420efff2596b7f99d2bfd6 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2720,4 +2720,16 @@ public final class CraftServer implements Server {
@@ -2869,4 +2869,16 @@ public final class CraftServer implements Server {
}
// Paper end

View File

@@ -6,20 +6,12 @@ Subject: [PATCH] Fix missing CraftMetaSkull serializedProfile
Plugins (ab)using NMS may change the "profile" field using reflections instead of the "setProfile" method, especially if they are targeted towards old Minecraft versions. This fixes the potential discrepancies and NPEs.
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
index 7cacc61fed0c610845c67894d1cc68e44f5e46fe..18feaf0152b67b18989ca03fbb74194db489081e 100644
index 292ae4a68093b7d939a755e1062cee57da186ab1..4afa90cb68aa31820abce6ab051de405daef6562 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
@@ -78,6 +78,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
@Override
void serializeInternal(final Map<String, Tag> internalTags) {
if (this.profile != null) {
+ refreshSerializedProfile(); // Parchment -- fix NPEs from plugins abusing NMS
internalTags.put(SKULL_PROFILE.NBT, serializedProfile);
}
}
@@ -91,6 +92,11 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
}
// Paper end
@@ -80,6 +80,11 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
private void setProfile(GameProfile profile) {
this.profile = profile;
+ // Parchment start -- fix NPEs from plugins abusing NMS
+ refreshSerializedProfile();
@@ -29,7 +21,7 @@ index 7cacc61fed0c610845c67894d1cc68e44f5e46fe..18feaf0152b67b18989ca03fbb74194d
this.serializedProfile = (profile == null) ? null : NbtUtils.writeGameProfile(new CompoundTag(), profile);
}
@@ -99,6 +105,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
@@ -88,6 +93,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
super.applyToItem(tag);
if (this.profile != null) {
@@ -37,7 +29,7 @@ index 7cacc61fed0c610845c67894d1cc68e44f5e46fe..18feaf0152b67b18989ca03fbb74194d
// SPIGOT-6558: Set initial textures
tag.put(SKULL_OWNER.NBT, serializedProfile);
// Fill in textures
@@ -234,6 +241,8 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
@@ -243,6 +249,8 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
if (meta instanceof CraftMetaSkull) {
CraftMetaSkull that = (CraftMetaSkull) meta;

View File

@@ -8,19 +8,19 @@ to easily get the items being dropped by any
block instead of only blocks broken by players.
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
index 8c30e28b97ac7e8b54322c903e0b75ee8135620b..4ca85a02a1eb46b5958aae55946c67cefb85f461 100644
index 224ce424b9a22548212ac157ec273c6dd80d6cfb..f33a8f7e46f9d88137de509e22d73edea3804cbe 100644
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
@@ -306,7 +306,7 @@ public class Block extends BlockBehaviour implements ItemLike {
@@ -308,7 +308,7 @@ public class Block extends BlockBehaviour implements ItemLike {
ServerLevel worldserver = lootContext.getLevel();
BlockPos blockposition = new BlockPos((Vec3) lootContext.getParameter(LootContextParams.ORIGIN));
- state.getDrops(lootContext).forEach((itemstack) -> {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(worldserver, blockposition, state.getDrops(lootContext)).forEach((itemstack) -> { // Parchment
Block.popResource((Level) worldserver, blockposition, itemstack);
Block.popResource(worldserver, blockposition, itemstack);
});
state.spawnAfterBreak(worldserver, blockposition, ItemStack.EMPTY);
@@ -314,7 +314,7 @@ public class Block extends BlockBehaviour implements ItemLike {
state.spawnAfterBreak(worldserver, blockposition, ItemStack.EMPTY, true);
@@ -316,7 +316,7 @@ public class Block extends BlockBehaviour implements ItemLike {
public static void dropResources(BlockState state, Level world, BlockPos pos) {
if (world instanceof ServerLevel) {
@@ -28,17 +28,17 @@ index 8c30e28b97ac7e8b54322c903e0b75ee8135620b..4ca85a02a1eb46b5958aae55946c67ce
+ org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(world, pos, Block.getDrops(state, (ServerLevel) world, pos, (BlockEntity) null)).forEach((itemstack) -> { // Parchment
Block.popResource(world, pos, itemstack);
});
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY);
@@ -324,7 +324,7 @@ public class Block extends BlockBehaviour implements ItemLike {
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY, true);
@@ -326,7 +326,7 @@ public class Block extends BlockBehaviour implements ItemLike {
public static void dropResources(BlockState state, LevelAccessor world, BlockPos pos, @Nullable BlockEntity blockEntity) {
if (world instanceof ServerLevel) {
- Block.getDrops(state, (ServerLevel) world, pos, blockEntity).forEach((itemstack) -> {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(world, pos, Block.getDrops(state, (ServerLevel) world, pos, blockEntity)).forEach((itemstack) -> { // Parchment
Block.popResource((Level) ((ServerLevel) world), pos, itemstack);
Block.popResource((ServerLevel) world, pos, itemstack);
});
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY);
@@ -351,7 +351,7 @@ public class Block extends BlockBehaviour implements ItemLike {
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY, true);
@@ -353,7 +353,7 @@ public class Block extends BlockBehaviour implements ItemLike {
public static void dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, Entity entity, ItemStack stack) {
if (world instanceof ServerLevel) {
@@ -46,20 +46,28 @@ index 8c30e28b97ac7e8b54322c903e0b75ee8135620b..4ca85a02a1eb46b5958aae55946c67ce
+ org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(world, pos, Block.getDrops(state, (ServerLevel) world, pos, blockEntity, entity, stack)).forEach((itemstack1) -> { // Parchment
Block.popResource(world, pos, itemstack1);
});
state.spawnAfterBreak((ServerLevel) world, pos, stack);
state.spawnAfterBreak((ServerLevel) world, pos, stack, true);
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 911c0dd8a5863ae93dbd82fd3d6aafc267994081..7aafe7cd3a8dae6b8f7b662049bf48bc6d698789 100644
index de6ec4c6d59d1b9fa203b0d373452e466a89e1ec..6ff4c2cc4e49796e947dc70db1eff475e0eeaa3b 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1924,5 +1924,11 @@ public class CraftEventFactory {
return null;
}, net.minecraft.server.MCUtil.asyncExecutor);
@@ -1965,5 +1965,19 @@ public class CraftEventFactory {
}
});
}
+
+ public static List<ItemStack> callBlockDropResourcesEvent(LevelAccessor world, BlockPos pos, List<ItemStack> items) {
+ me.lexikiq.event.block.BlockDropResourcesEvent event = new me.lexikiq.event.block.BlockDropResourcesEvent(CraftBlock.at(world, pos), items.stream().map(CraftItemStack::asBukkitCopy).collect(Collectors.toCollection(ArrayList::new)));
+ List<org.bukkit.inventory.ItemStack> bukkitItems = new ArrayList<>(items.size());
+ for (ItemStack item : items) {
+ bukkitItems.add(CraftItemStack.asBukkitCopy(item));
+ }
+ gg.projecteden.parchment.event.block.BlockDropResourcesEvent event = new gg.projecteden.parchment.event.block.BlockDropResourcesEvent(CraftBlock.at(world, pos), bukkitItems);
+ event.callEvent();
+ return event.getResources().stream().map(CraftItemStack::asNMSCopy).collect(Collectors.toList());
+ items = new ArrayList<>(bukkitItems.size());
+ for (org.bukkit.inventory.ItemStack item : bukkitItems) {
+ items.add(CraftItemStack.asNMSCopy(item));
+ }
+ return items;
+ }
// Parchment end
}

View File

@@ -7,13 +7,13 @@ Temporary API to get the result of smelting an item in a (type of) furnace.
Will eventually (hopefully) be replaced by a more extensive Paper PR with support for all recipes.
diff --git a/src/main/java/me/lexikiq/inventory/CraftRecipeType.java b/src/main/java/me/lexikiq/inventory/CraftRecipeType.java
diff --git a/src/main/java/gg/projecteden/parchment/inventory/CraftRecipeType.java b/src/main/java/gg/projecteden/parchment/inventory/CraftRecipeType.java
new file mode 100644
index 0000000000000000000000000000000000000000..6a28791b12c309661e79e0e6a8f7a9ec8fd706a3
index 0000000000000000000000000000000000000000..5549da2a0b0790699abff627148a6b15ca37febf
--- /dev/null
+++ b/src/main/java/me/lexikiq/inventory/CraftRecipeType.java
+++ b/src/main/java/gg/projecteden/parchment/inventory/CraftRecipeType.java
@@ -0,0 +1,44 @@
+package me.lexikiq.inventory;
+package gg.projecteden.parchment.inventory;
+
+import net.minecraft.world.item.crafting.AbstractCookingRecipe;
+
@@ -57,13 +57,13 @@ index 0000000000000000000000000000000000000000..6a28791b12c309661e79e0e6a8f7a9ec
+ }
+ }
+}
diff --git a/src/main/java/me/lexikiq/inventory/SingletonContainer.java b/src/main/java/me/lexikiq/inventory/SingletonContainer.java
diff --git a/src/main/java/gg/projecteden/parchment/inventory/SingletonContainer.java b/src/main/java/gg/projecteden/parchment/inventory/SingletonContainer.java
new file mode 100644
index 0000000000000000000000000000000000000000..e6d1e8faafe3fec48df51e5a25acef56a8428db3
index 0000000000000000000000000000000000000000..e7114e456f818d7bdd4081620f4b9b9376679145
--- /dev/null
+++ b/src/main/java/me/lexikiq/inventory/SingletonContainer.java
+++ b/src/main/java/gg/projecteden/parchment/inventory/SingletonContainer.java
@@ -0,0 +1,151 @@
+package me.lexikiq.inventory;
+package gg.projecteden.parchment.inventory;
+
+import com.google.common.base.Preconditions;
+import net.minecraft.world.Container;
@@ -215,18 +215,18 @@ index 0000000000000000000000000000000000000000..e6d1e8faafe3fec48df51e5a25acef56
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 858e29ad77aee8a1b7797c2d82902abbfd662da2..cd98817b0dca964a5cbaa6c19169f37d0bee6682 100644
index 25e56be9055c5c432e1180d45341f4e9d9fcb7ca..4e8dbefb953a8ca09dda1e195591c10ebd9b0243 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -2162,4 +2162,11 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@@ -2321,4 +2321,11 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return this.adventure$pointers;
}
// Paper end
+
+ // Parchment start
+ @Override
+ public ItemStack smeltItem(ItemStack toSmelt, me.lexikiq.inventory.RecipeType recipeType) {
+ return world.getRecipeManager().getRecipeFor(me.lexikiq.inventory.CraftRecipeType.asCookingRecipe(recipeType), new me.lexikiq.inventory.SingletonContainer(toSmelt), world).map(recipe -> recipe.getResultItem().getBukkitStack()).orElse(null);
+ public ItemStack smeltItem(ItemStack toSmelt, gg.projecteden.parchment.inventory.RecipeType recipeType) {
+ return world.getRecipeManager().getRecipeFor(gg.projecteden.parchment.inventory.CraftRecipeType.asCookingRecipe(recipeType), new gg.projecteden.parchment.inventory.SingletonContainer(toSmelt), world).map(recipe -> recipe.getResultItem().getBukkitStack()).orElse(null);
+ }
+ // Parchment end
}

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Disable sleep status announcements
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 933b577dd582d1624cbd587b726e96fc9cfef68a..d92740433c908f54b724b9d0ce37f51e228c4dcc 100644
index 782be663520c27fccb58484ec56cc94def38f136..e33d731d4689963fa9c5b2feef24a6b7b202988b 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -994,7 +994,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
@@ -918,7 +918,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
}
private void announceSleepStatus() {
@@ -16,4 +16,4 @@ index 933b577dd582d1624cbd587b726e96fc9cfef68a..d92740433c908f54b724b9d0ce37f51e
+ if (false && this.canSleepThroughNights()) {
if (!this.getServer().isSingleplayer() || this.getServer().isPublished()) {
int i = this.getGameRules().getInt(GameRules.RULE_PLAYERS_SLEEPING_PERCENTAGE);
TranslatableComponent chatmessage;
MutableComponent ichatmutablecomponent;

View File

@@ -0,0 +1,31 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lexi <lexi@qixils.dev>
Date: Fri, 17 Jun 2022 14:36:42 -0400
Subject: [PATCH] Add config for ticking TIME_SINCE_REST
diff --git a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
index 32f0cd29d1198fe320d10ccfe0b02f8632ac12aa..7154ca5d729f44a7cbd0d47f23c10f44c0aef6b3 100644
--- a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
+++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
@@ -252,6 +252,7 @@ public class WorldConfiguration extends ConfigurationPart {
}
public boolean disablePlayerCrits = false;
+ public boolean tickTimeSinceSleep = true; // Parchment
public boolean nerfPigmenFromNetherPortals = false;
public PillagerPatrols pillagerPatrols;
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index 05584d344c9f7d6d89bb8fbdfa254c1dca91b590..aea543059600f093b96df985468a61da048acdb6 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -293,7 +293,7 @@ public abstract class Player extends LivingEntity {
this.awardStat(Stats.CROUCH_TIME);
}
- if (!this.isSleeping()) {
+ if (!this.isSleeping() && this.level.paperConfig().entities.behavior.tickTimeSinceSleep) { // Parchment
this.awardStat(Stats.TIME_SINCE_REST);
}
}

View File

@@ -5,6 +5,6 @@ pluginManagement {
}
}
rootProject.name = "Parchment"
rootProject.name = "parchment"
include("Parchment-Common", "Parchment-API", "Parchment-Server")
include("parchment-api", "parchment-server")